phunix/minix/servers/ipc/utility.c
David van Moolenbroek 56dc79cea0 IPC server: major fixes, test set for semaphores
- rewrite the semop(2) implementation so that it now conforms to the
  specification, including atomicity, support for blocking more than
  once, range checks, but also basic fairness support;
- fix permissions checking;
- fix missing time adjustments;
- fix off-by-one errors and other bugs;
- do not allocate dynamic memory for GETALL/SETALL;
- add test88, which properly tests the semaphore functionality.

Change-Id: I85f0d3408c0d6bba41cfb4c91a34c8b46b2a5959
2016-01-16 14:04:11 +01:00

33 lines
600 B
C

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