libsys: various updates
- move system calls for use by services from libminlib into libsys; - move srv_fork(2) and srv_kill(2) from RS and into libsys; - replace getprocnr(2) with sef_self(3); - rename previous getnprocnr(2) to getprocnr(2); - clean up getepinfo(2); - change all libsys calls that used _syscall to use _taskcall, so as to avoid going through errno to pass errors; this is already how most calls work anyway, and many of the calls previously using _syscall were already assumed to return the actual error; - initialize request messages to zero, for future compatibility (note that this does not include PCI calls, which are in need of a much bigger overhaul, nor kernel calls); - clean up more of dead DS code as a side effect. Change-Id: I8788f54c68598fcf58e23486e270c2d749780ebb
This commit is contained in:
75
lib/libsys/getepinfo.c
Normal file
75
lib/libsys/getepinfo.c
Normal file
@@ -0,0 +1,75 @@
|
||||
#include "syslib.h"
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <sys/ucred.h>
|
||||
|
||||
static pid_t
|
||||
getepinfo(endpoint_t proc_ep, uid_t *uid, gid_t *gid)
|
||||
{
|
||||
message m;
|
||||
int r;
|
||||
|
||||
memset(&m, 0, sizeof(m));
|
||||
m.PM_GETEPINFO_ENDPT = proc_ep;
|
||||
|
||||
if ((r = _taskcall(PM_PROC_NR, GETEPINFO, &m)) < 0)
|
||||
return r;
|
||||
|
||||
if (uid != NULL)
|
||||
*uid = m.PM_GETEPINFO_UID;
|
||||
if (gid != NULL)
|
||||
*gid = m.PM_GETEPINFO_GID;
|
||||
return (pid_t) r;
|
||||
}
|
||||
|
||||
pid_t
|
||||
getnpid(endpoint_t proc_ep)
|
||||
{
|
||||
return getepinfo(proc_ep, NULL, NULL);
|
||||
}
|
||||
|
||||
uid_t
|
||||
getnuid(endpoint_t proc_ep)
|
||||
{
|
||||
uid_t uid;
|
||||
int r;
|
||||
|
||||
if ((r = getepinfo(proc_ep, &uid, NULL)) < 0)
|
||||
return (uid_t) r;
|
||||
|
||||
return uid;
|
||||
}
|
||||
|
||||
gid_t
|
||||
getngid(endpoint_t proc_ep)
|
||||
{
|
||||
gid_t gid;
|
||||
int r;
|
||||
|
||||
if ((r = getepinfo(proc_ep, NULL, &gid)) < 0)
|
||||
return (gid_t) r;
|
||||
|
||||
return gid;
|
||||
}
|
||||
|
||||
int
|
||||
getnucred(endpoint_t proc_ep, struct uucred *ucred)
|
||||
{
|
||||
uid_t uid;
|
||||
gid_t gid;
|
||||
int r;
|
||||
|
||||
if (ucred == NULL)
|
||||
return EFAULT;
|
||||
|
||||
if ((r = getepinfo(proc_ep, &uid, &gid)) < 0)
|
||||
return r;
|
||||
|
||||
/* Only two fields are used for now; ensure the rest is zeroed out. */
|
||||
memset(ucred, 0, sizeof(struct uucred));
|
||||
ucred->cr_uid = uid;
|
||||
ucred->cr_gid = gid;
|
||||
|
||||
return r;
|
||||
}
|
||||
Reference in New Issue
Block a user