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);
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);
/* Forward declaration */
struct rs_pci;
struct rusage;
+struct sockcred;
#define SYSTASK SYSTEM
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 */
#include <string.h>
#include <unistd.h>
-#include <sys/ucred.h>
+#include <sys/socket.h>
pid_t
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;
}
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;
+}
{
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);
}