kernel: fix sanity check
[minix.git] / servers / ipc / utility.c
blob46a84f85bbe014a980c33f92acae4f1d2c448415
1 #include "inc.h"
3 int check_perm(struct ipc_perm *req, endpoint_t who, int mode)
5 int req_mode;
6 int cur_mode;
7 uid_t uid = getnuid(who);
8 gid_t gid = getngid(who);
10 mode &= 0666;
12 /* is root? */
13 if (uid == 0)
14 return 1;
16 if (uid == req->uid || uid == req->cuid) {
17 /* same user */
18 req_mode = (req->mode >> 6) & 0x7;
19 cur_mode = (mode >> 6) & 0x7;
20 } else if (gid == req->gid || gid == req->cgid) {
21 /* same group */
22 req_mode = (req->mode >> 3) & 0x7;
23 cur_mode = (mode >> 3) & 0x7;
24 } else {
25 /* other group */
26 req_mode = req->mode & 0x7;
27 cur_mode = mode & 0x7;
30 if (cur_mode && ((cur_mode & req_mode) == cur_mode))
31 return 1;
32 else
33 return 0;