From: David van Moolenbroek Date: Tue, 12 Jul 2016 14:46:27 +0000 (+0000) Subject: PM/libsys: extend getepinfo, add getsockcred(3) X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/zpipe.c?a=commitdiff_plain;h=refs%2Fchanges%2F27%2F3427%2F1;p=minix.git PM/libsys: extend getepinfo, add getsockcred(3) The service-only getepinfo(2) PM call returns information about a given endpoint. This patch extends that call so that it returns enough information to allow correctly filling a sockcred structure. A new getsockcred(3) function is added to libsys to fill an actual sockcred structure with the obtained information. However, for the caller's convenience, the groups list is kept separate. Change-Id: I9f1a6d1a221c77eabaa3498ff4ec9a5fb922e4fd --- diff --git a/minix/include/minix/ipc.h b/minix/include/minix/ipc.h index 990bb3489..6ca59a3f5 100644 --- a/minix/include/minix/ipc.h +++ b/minix/include/minix/ipc.h @@ -1398,8 +1398,10 @@ _ASSERT_MSG_SIZE(mess_lsys_pci_busc_get_bar); typedef struct { endpoint_t endpt; + vir_bytes groups; + int ngroups; - uint8_t padding[52]; + uint8_t padding[44]; } mess_lsys_pm_getepinfo; _ASSERT_MSG_SIZE(mess_lsys_pm_getepinfo); @@ -1713,9 +1715,12 @@ _ASSERT_MSG_SIZE(mess_pm_lexec_exec_new); typedef struct { uid_t uid; + uid_t euid; gid_t gid; + gid_t egid; + int ngroups; - uint8_t padding[48]; + uint8_t padding[36]; } mess_pm_lsys_getepinfo; _ASSERT_MSG_SIZE(mess_pm_lsys_getepinfo); diff --git a/minix/include/minix/syslib.h b/minix/include/minix/syslib.h index 3f5717fdc..98f58cbd5 100644 --- a/minix/include/minix/syslib.h +++ b/minix/include/minix/syslib.h @@ -17,6 +17,7 @@ /* Forward declaration */ struct rs_pci; struct rusage; +struct sockcred; #define SYSTASK SYSTEM @@ -270,6 +271,8 @@ pid_t getepinfo(endpoint_t proc_ep, uid_t *uidp, gid_t *gidp); pid_t getnpid(endpoint_t proc_ep); uid_t getnuid(endpoint_t proc_ep); gid_t getngid(endpoint_t proc_ep); +int getsockcred(endpoint_t proc_ep, struct sockcred * sockcred, gid_t * groups, + int ngroups); int socketpath(endpoint_t endpt, char *path, size_t size, int what, dev_t *dev, ino_t *ino); #define SPATH_CHECK 0 /* check user permissions on socket path */ diff --git a/minix/lib/libsys/getepinfo.c b/minix/lib/libsys/getepinfo.c index ed5b83672..16c825c41 100644 --- a/minix/lib/libsys/getepinfo.c +++ b/minix/lib/libsys/getepinfo.c @@ -2,7 +2,7 @@ #include #include -#include +#include pid_t getepinfo(endpoint_t proc_ep, uid_t *uid, gid_t *gid) @@ -12,14 +12,16 @@ getepinfo(endpoint_t proc_ep, uid_t *uid, gid_t *gid) 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.uid; + *uid = m.m_pm_lsys_getepinfo.euid; if (gid != NULL) - *gid = m.m_pm_lsys_getepinfo.gid; + *gid = m.m_pm_lsys_getepinfo.egid; return (pid_t) r; } @@ -52,3 +54,27 @@ getngid(endpoint_t proc_ep) 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; +} diff --git a/minix/servers/pm/misc.c b/minix/servers/pm/misc.c index 4e1da51f8..8e11e08c1 100644 --- a/minix/servers/pm/misc.c +++ b/minix/servers/pm/misc.c @@ -170,15 +170,25 @@ int do_getepinfo(void) { struct mproc *rmp; endpoint_t ep; - int slot; + int r, slot, ngroups; ep = m_in.m_lsys_pm_getepinfo.endpt; if (pm_isokendpt(ep, &slot) != OK) return(ESRCH); - rmp = &mproc[slot]; - mp->mp_reply.m_pm_lsys_getepinfo.uid = rmp->mp_effuid; - mp->mp_reply.m_pm_lsys_getepinfo.gid = rmp->mp_effgid; + + mp->mp_reply.m_pm_lsys_getepinfo.uid = rmp->mp_realuid; + mp->mp_reply.m_pm_lsys_getepinfo.euid = rmp->mp_effuid; + mp->mp_reply.m_pm_lsys_getepinfo.gid = rmp->mp_realgid; + mp->mp_reply.m_pm_lsys_getepinfo.egid = rmp->mp_effgid; + mp->mp_reply.m_pm_lsys_getepinfo.ngroups = ngroups = rmp->mp_ngroups; + if (ngroups > m_in.m_lsys_pm_getepinfo.ngroups) + ngroups = m_in.m_lsys_pm_getepinfo.ngroups; + if (ngroups > 0) { + if ((r = sys_datacopy(SELF, (vir_bytes)rmp->mp_sgroups, who_e, + m_in.m_lsys_pm_getepinfo.groups, ngroups * sizeof(gid_t))) != OK) + return(r); + } return(rmp->mp_pid); }