Remove building with NOCRYPTO option
[minix.git] / minix / servers / ipc / utility.c
blob41dda5db90a26bf80998d734c68073eb96048a0a
1 #include "inc.h"
3 int
4 check_perm(struct ipc_perm * req, endpoint_t who, int mode)
6 int req_mode;
7 uid_t uid;
8 gid_t gid;
10 uid = getnuid(who);
11 gid = getngid(who);
12 mode &= 0700;
14 /* Root is allowed to do anything. */
15 if (uid == 0)
16 return TRUE;
18 if (uid == req->uid || uid == req->cuid) {
19 /* Same user. */
20 req_mode = req->mode & 0700;
21 } else if (gid == req->gid || gid == req->cgid) {
22 /* Same group. */
23 req_mode = req->mode & 0070;
24 mode >>= 3;
25 } else {
26 /* Other user and group. */
27 req_mode = req->mode & 0007;
28 mode >>= 6;
31 return (mode && ((mode & req_mode) == mode));
35 * Copy over an ipc_perm structure to an ipc_perm_sysctl structure.
37 void
38 prepare_mib_perm(struct ipc_perm_sysctl * perms, const struct ipc_perm * perm)
41 memset(perms, 0, sizeof(*perms));
42 perms->_key = perm->_key;
43 perms->uid = perm->uid;
44 perms->gid = perm->gid;
45 perms->cuid = perm->cuid;
46 perms->cgid = perm->cgid;
47 perms->mode = perm->mode;
48 perms->_seq = perm->_seq;