1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
#include "syslib.h"
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
pid_t
getepinfo(endpoint_t proc_ep, uid_t *uid, gid_t *gid)
{
message m;
int r;
memset(&m, 0, sizeof(m));
m.m_lsys_pm_getepinfo.endpt = proc_ep;
m.m_lsys_pm_getepinfo.groups = (vir_bytes)NULL;
m.m_lsys_pm_getepinfo.ngroups = 0;
if ((r = _taskcall(PM_PROC_NR, PM_GETEPINFO, &m)) < 0)
return r;
if (uid != NULL)
*uid = m.m_pm_lsys_getepinfo.euid;
if (gid != NULL)
*gid = m.m_pm_lsys_getepinfo.egid;
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
getsockcred(endpoint_t proc_ep, struct sockcred * sockcred, gid_t * groups,
int ngroups)
{
message m;
int r;
memset(&m, 0, sizeof(m));
m.m_lsys_pm_getepinfo.endpt = proc_ep;
m.m_lsys_pm_getepinfo.groups = (vir_bytes)groups;
m.m_lsys_pm_getepinfo.ngroups = ngroups;
if ((r = _taskcall(PM_PROC_NR, PM_GETEPINFO, &m)) < 0)
return r;
sockcred->sc_uid = m.m_pm_lsys_getepinfo.uid;
sockcred->sc_euid = m.m_pm_lsys_getepinfo.euid;
sockcred->sc_gid = m.m_pm_lsys_getepinfo.gid;
sockcred->sc_egid = m.m_pm_lsys_getepinfo.egid;
sockcred->sc_ngroups = m.m_pm_lsys_getepinfo.ngroups;
return OK;
}
|