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
This commit is contained in:
parent
462713495a
commit
bfa518c7ec
|
|
@ -1398,8 +1398,10 @@ _ASSERT_MSG_SIZE(mess_lsys_pci_busc_get_bar);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
endpoint_t endpt;
|
endpoint_t endpt;
|
||||||
|
vir_bytes groups;
|
||||||
|
int ngroups;
|
||||||
|
|
||||||
uint8_t padding[52];
|
uint8_t padding[44];
|
||||||
} mess_lsys_pm_getepinfo;
|
} mess_lsys_pm_getepinfo;
|
||||||
_ASSERT_MSG_SIZE(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 {
|
typedef struct {
|
||||||
uid_t uid;
|
uid_t uid;
|
||||||
|
uid_t euid;
|
||||||
gid_t gid;
|
gid_t gid;
|
||||||
|
gid_t egid;
|
||||||
|
int ngroups;
|
||||||
|
|
||||||
uint8_t padding[48];
|
uint8_t padding[36];
|
||||||
} mess_pm_lsys_getepinfo;
|
} mess_pm_lsys_getepinfo;
|
||||||
_ASSERT_MSG_SIZE(mess_pm_lsys_getepinfo);
|
_ASSERT_MSG_SIZE(mess_pm_lsys_getepinfo);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
/* Forward declaration */
|
/* Forward declaration */
|
||||||
struct rs_pci;
|
struct rs_pci;
|
||||||
struct rusage;
|
struct rusage;
|
||||||
|
struct sockcred;
|
||||||
|
|
||||||
#define SYSTASK SYSTEM
|
#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);
|
pid_t getnpid(endpoint_t proc_ep);
|
||||||
uid_t getnuid(endpoint_t proc_ep);
|
uid_t getnuid(endpoint_t proc_ep);
|
||||||
gid_t getngid(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,
|
int socketpath(endpoint_t endpt, char *path, size_t size, int what, dev_t *dev,
|
||||||
ino_t *ino);
|
ino_t *ino);
|
||||||
#define SPATH_CHECK 0 /* check user permissions on socket path */
|
#define SPATH_CHECK 0 /* check user permissions on socket path */
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <sys/ucred.h>
|
#include <sys/socket.h>
|
||||||
|
|
||||||
pid_t
|
pid_t
|
||||||
getepinfo(endpoint_t proc_ep, uid_t *uid, gid_t *gid)
|
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));
|
memset(&m, 0, sizeof(m));
|
||||||
m.m_lsys_pm_getepinfo.endpt = proc_ep;
|
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)
|
if ((r = _taskcall(PM_PROC_NR, PM_GETEPINFO, &m)) < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
if (uid != NULL)
|
if (uid != NULL)
|
||||||
*uid = m.m_pm_lsys_getepinfo.uid;
|
*uid = m.m_pm_lsys_getepinfo.euid;
|
||||||
if (gid != NULL)
|
if (gid != NULL)
|
||||||
*gid = m.m_pm_lsys_getepinfo.gid;
|
*gid = m.m_pm_lsys_getepinfo.egid;
|
||||||
return (pid_t) r;
|
return (pid_t) r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -52,3 +54,27 @@ getngid(endpoint_t proc_ep)
|
||||||
|
|
||||||
return gid;
|
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;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -170,15 +170,25 @@ int do_getepinfo(void)
|
||||||
{
|
{
|
||||||
struct mproc *rmp;
|
struct mproc *rmp;
|
||||||
endpoint_t ep;
|
endpoint_t ep;
|
||||||
int slot;
|
int r, slot, ngroups;
|
||||||
|
|
||||||
ep = m_in.m_lsys_pm_getepinfo.endpt;
|
ep = m_in.m_lsys_pm_getepinfo.endpt;
|
||||||
if (pm_isokendpt(ep, &slot) != OK)
|
if (pm_isokendpt(ep, &slot) != OK)
|
||||||
return(ESRCH);
|
return(ESRCH);
|
||||||
|
|
||||||
rmp = &mproc[slot];
|
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);
|
return(rmp->mp_pid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user