David van Moolenbroek 534584945c IPC: use RMIB to handle kern.ipc sysctl subtree
With this patch, the IPC service is changed to use the new RMIB
facility to register and handle the "kern.ipc" sysctl subtree itself.
The subtree was previously handled by the MIB service directly.  This
change improves locality of handling: especially the
kern.ipc.sysvipc_info node has some peculiarities specific to the IPC
service and is therefore better handled there.  Also, since the IPC
service is essentially optional to the system, this rearrangement
yields a cleaner situation when the IPC service is not running: in
that case, the MIB service will expose a few basic kern.ipc nodes
indicating that no SysV IPC facilities are present.  Those nodes will
be overridden through RMIB when the IPC service is running.

It should be easier to add the remaining (from NetBSD) kern.ipc nodes
as well now.

Test88 is extended with a new subtest that verifies that sysctl-based
information retrieval for semaphore sets works as expected.

Change-Id: I6b7730e85305b64cfd8418c0cc56bde64b22c584
2016-06-18 12:47:24 +00:00

50 lines
985 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));
}
/*
* Copy over an ipc_perm structure to an ipc_perm_sysctl structure.
*/
void
prepare_mib_perm(struct ipc_perm_sysctl * perms, const struct ipc_perm * perm)
{
memset(perms, 0, sizeof(*perms));
perms->_key = perm->_key;
perms->uid = perm->uid;
perms->gid = perm->gid;
perms->cuid = perm->cuid;
perms->cgid = perm->cgid;
perms->mode = perm->mode;
perms->_seq = perm->_seq;
}