phunix/minix/servers/ipc/utility.c
David van Moolenbroek 0baafa0ef4 IPC server: restyle
Closer to KNF, better coding practices, more similar to other
services, no more global variables, a few more comments, that
kind of stuff.  No major functional changes.

Change-Id: I6e8f53bfafd6f41e92031fba76c40a31d2107a8e
2016-01-16 14:03:55 +01:00

35 lines
696 B
C

#include "inc.h"
int
check_perm(struct ipc_perm * req, endpoint_t who, int mode)
{
int req_mode;
int cur_mode;
uid_t uid;
gid_t gid;
uid = getnuid(who);
gid = getngid(who);
mode &= 0666;
/* Root is allowed to do anything. */
if (uid == 0)
return 1;
if (uid == req->uid || uid == req->cuid) {
/* Same user. */
req_mode = (req->mode >> 6) & 0x7;
cur_mode = (mode >> 6) & 0x7;
} else if (gid == req->gid || gid == req->cgid) {
/* Same group. */
req_mode = (req->mode >> 3) & 0x7;
cur_mode = (mode >> 3) & 0x7;
} else {
/* Other user and group. */
req_mode = req->mode & 0x7;
cur_mode = mode & 0x7;
}
return (cur_mode && ((cur_mode & req_mode) == cur_mode));
}