etc/services - sync with NetBSD-8
[minix.git] / minix / lib / libsys / getepinfo.c
blob16c825c414d6663cd178835c4153a6eca18e51fd
1 #include "syslib.h"
2 #include <string.h>
3 #include <unistd.h>
5 #include <sys/socket.h>
7 pid_t
8 getepinfo(endpoint_t proc_ep, uid_t *uid, gid_t *gid)
10 message m;
11 int r;
13 memset(&m, 0, sizeof(m));
14 m.m_lsys_pm_getepinfo.endpt = proc_ep;
15 m.m_lsys_pm_getepinfo.groups = (vir_bytes)NULL;
16 m.m_lsys_pm_getepinfo.ngroups = 0;
18 if ((r = _taskcall(PM_PROC_NR, PM_GETEPINFO, &m)) < 0)
19 return r;
21 if (uid != NULL)
22 *uid = m.m_pm_lsys_getepinfo.euid;
23 if (gid != NULL)
24 *gid = m.m_pm_lsys_getepinfo.egid;
25 return (pid_t) r;
28 pid_t
29 getnpid(endpoint_t proc_ep)
31 return getepinfo(proc_ep, NULL, NULL);
34 uid_t
35 getnuid(endpoint_t proc_ep)
37 uid_t uid;
38 int r;
40 if ((r = getepinfo(proc_ep, &uid, NULL)) < 0)
41 return (uid_t) r;
43 return uid;
46 gid_t
47 getngid(endpoint_t proc_ep)
49 gid_t gid;
50 int r;
52 if ((r = getepinfo(proc_ep, NULL, &gid)) < 0)
53 return (gid_t) r;
55 return gid;
58 int
59 getsockcred(endpoint_t proc_ep, struct sockcred * sockcred, gid_t * groups,
60 int ngroups)
62 message m;
63 int r;
65 memset(&m, 0, sizeof(m));
66 m.m_lsys_pm_getepinfo.endpt = proc_ep;
67 m.m_lsys_pm_getepinfo.groups = (vir_bytes)groups;
68 m.m_lsys_pm_getepinfo.ngroups = ngroups;
70 if ((r = _taskcall(PM_PROC_NR, PM_GETEPINFO, &m)) < 0)
71 return r;
73 sockcred->sc_uid = m.m_pm_lsys_getepinfo.uid;
74 sockcred->sc_euid = m.m_pm_lsys_getepinfo.euid;
75 sockcred->sc_gid = m.m_pm_lsys_getepinfo.gid;
76 sockcred->sc_egid = m.m_pm_lsys_getepinfo.egid;
77 sockcred->sc_ngroups = m.m_pm_lsys_getepinfo.ngroups;
79 return OK;