2011-03-22 14:47:35 +01:00
|
|
|
#include <errno.h>
|
2013-04-18 11:07:44 +02:00
|
|
|
#include <lib.h>
|
|
|
|
#include <string.h>
|
2011-03-22 14:47:35 +01:00
|
|
|
#include <unistd.h>
|
|
|
|
|
2013-04-18 11:07:44 +02:00
|
|
|
#include <sys/ucred.h>
|
|
|
|
|
|
|
|
int
|
|
|
|
getnucred(endpoint_t proc_ep, struct uucred *ucred)
|
2011-03-22 14:47:35 +01:00
|
|
|
{
|
2013-04-18 11:07:44 +02:00
|
|
|
message m;
|
|
|
|
pid_t pid;
|
2011-03-22 14:47:35 +01:00
|
|
|
|
2013-04-18 11:07:44 +02:00
|
|
|
if (ucred == NULL) {
|
|
|
|
errno = EFAULT;
|
|
|
|
return -1;
|
|
|
|
}
|
2011-03-22 14:47:35 +01:00
|
|
|
|
2013-04-18 11:07:44 +02:00
|
|
|
m.m1_i1 = proc_ep; /* search for this process */
|
2011-03-22 14:47:35 +01:00
|
|
|
|
2013-04-18 11:07:44 +02:00
|
|
|
pid = _syscall(PM_PROC_NR, GETEPINFO, &m);
|
|
|
|
if (pid < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
2011-03-22 14:47:35 +01:00
|
|
|
|
2013-04-18 11:07:44 +02:00
|
|
|
/* Only two fields are used for now, so ensure the rest is zeroed out. */
|
|
|
|
memset(ucred, 0, sizeof(struct uucred));
|
|
|
|
ucred->cr_uid = m.PM_NUID;
|
|
|
|
ucred->cr_gid = m.PM_NGID;
|
2011-03-22 14:47:35 +01:00
|
|
|
|
2013-04-18 11:07:44 +02:00
|
|
|
return 0;
|
2011-03-22 14:47:35 +01:00
|
|
|
}
|