struct uucred
Change-Id: Ia97cb6c38bb566be30d568a252ae7b76142a21dd
This commit is contained in:
parent
744378194d
commit
55dcce66c6
11 changed files with 63 additions and 64 deletions
|
@ -86,7 +86,7 @@ struct msg_control
|
||||||
|
|
||||||
/* setsockopt/setsockopt for unix domain sockets */
|
/* setsockopt/setsockopt for unix domain sockets */
|
||||||
#define NWIOGUDSSOTYPE _IOR('n', 90, int) /* SO_TYPE */
|
#define NWIOGUDSSOTYPE _IOR('n', 90, int) /* SO_TYPE */
|
||||||
#define NWIOGUDSPEERCRED _IOR('n', 91, struct ucred) /* SO_PEERCRED */
|
#define NWIOGUDSPEERCRED _IOR('n', 91, struct uucred) /* SO_PEERCRED */
|
||||||
#define NWIOGUDSSNDBUF _IOR('n', 92, size_t) /* SO_SNDBUF */
|
#define NWIOGUDSSNDBUF _IOR('n', 92, size_t) /* SO_SNDBUF */
|
||||||
#define NWIOSUDSSNDBUF _IOW('n', 93, size_t) /* SO_SNDBUF */
|
#define NWIOSUDSSNDBUF _IOW('n', 93, size_t) /* SO_SNDBUF */
|
||||||
#define NWIOGUDSRCVBUF _IOR('n', 94, size_t) /* SO_RCVBUF */
|
#define NWIOGUDSRCVBUF _IOR('n', 94, size_t) /* SO_RCVBUF */
|
||||||
|
|
|
@ -9,11 +9,11 @@
|
||||||
*/
|
*/
|
||||||
int getpeereid(int sd, uid_t *euid, gid_t *egid) {
|
int getpeereid(int sd, uid_t *euid, gid_t *egid) {
|
||||||
int rc;
|
int rc;
|
||||||
struct ucred cred;
|
struct uucred cred;
|
||||||
socklen_t ucred_length;
|
socklen_t ucred_length;
|
||||||
|
|
||||||
/* Initialize Data Structures */
|
/* Initialize Data Structures */
|
||||||
ucred_length = sizeof(struct ucred);
|
ucred_length = sizeof(struct uucred);
|
||||||
memset(&cred, '\0', ucred_length);
|
memset(&cred, '\0', ucred_length);
|
||||||
|
|
||||||
/* Validate Input Parameters */
|
/* Validate Input Parameters */
|
||||||
|
@ -26,8 +26,8 @@ int getpeereid(int sd, uid_t *euid, gid_t *egid) {
|
||||||
rc = getsockopt(sd, SOL_SOCKET, SO_PEERCRED, &cred, &ucred_length);
|
rc = getsockopt(sd, SOL_SOCKET, SO_PEERCRED, &cred, &ucred_length);
|
||||||
if (rc == 0) {
|
if (rc == 0) {
|
||||||
/* Success - return the results */
|
/* Success - return the results */
|
||||||
*euid = cred.uid;
|
*euid = cred.cr_uid;
|
||||||
*egid = cred.gid;
|
*egid = cred.cr_gid;
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
/* Failure - getsockopt takes care of setting errno */
|
/* Failure - getsockopt takes care of setting errno */
|
||||||
|
|
|
@ -217,14 +217,14 @@ static int _uds_getsockopt(int sock, int level, int option_name,
|
||||||
|
|
||||||
if (level == SOL_SOCKET && option_name == SO_PEERCRED)
|
if (level == SOL_SOCKET && option_name == SO_PEERCRED)
|
||||||
{
|
{
|
||||||
struct ucred cred;
|
struct uucred cred;
|
||||||
|
|
||||||
r= ioctl(sock, NWIOGUDSPEERCRED, &cred);
|
r= ioctl(sock, NWIOGUDSPEERCRED, &cred);
|
||||||
if (r == -1) {
|
if (r == -1) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
getsockopt_copy(&cred, sizeof(struct ucred), option_value,
|
getsockopt_copy(&cred, sizeof(struct uucred), option_value,
|
||||||
option_len);
|
option_len);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
#include <lib.h>
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <sys/ucred.h>
|
#include <lib.h>
|
||||||
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
int getnucred(endpoint_t proc_ep, struct ucred *ucred)
|
#include <sys/ucred.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
getnucred(endpoint_t proc_ep, struct uucred *ucred)
|
||||||
{
|
{
|
||||||
message m;
|
message m;
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
|
@ -20,9 +23,10 @@ int getnucred(endpoint_t proc_ep, struct ucred *ucred)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ucred->pid = pid;
|
/* Only two fields are used for now, so ensure the rest is zeroed out. */
|
||||||
ucred->uid = m.PM_NUID;
|
memset(ucred, 0, sizeof(struct uucred));
|
||||||
ucred->gid = m.PM_NGID;
|
ucred->cr_uid = m.PM_NUID;
|
||||||
|
ucred->cr_gid = m.PM_NGID;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,10 +6,10 @@ getnucred \- obtain the credentials that correspond to the given endpoint.
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
.in +5
|
.in +5
|
||||||
.ti -5
|
.ti -5
|
||||||
#include <unistd.h>
|
#include <sys/ucred.h>
|
||||||
|
|
||||||
.ti -5
|
.ti -5
|
||||||
int getnucred(endpoint_t \fIproc_ep\fP, struct ucred * \fIucred\fP);
|
int getnucred(endpoint_t \fIproc_ep\fP, struct uucred * \fIucred\fP);
|
||||||
.br
|
.br
|
||||||
.ft P
|
.ft P
|
||||||
.SH DESCRIPTION
|
.SH DESCRIPTION
|
||||||
|
|
|
@ -40,7 +40,7 @@ static int uds_perform_write(int minor, endpoint_t m_source, size_t
|
||||||
int uds_open(message *dev_m_in, message *dev_m_out)
|
int uds_open(message *dev_m_in, message *dev_m_out)
|
||||||
{
|
{
|
||||||
message fs_m_in, fs_m_out;
|
message fs_m_in, fs_m_out;
|
||||||
struct ucred ucred;
|
struct uucred ucred;
|
||||||
int rc, i;
|
int rc, i;
|
||||||
int minor;
|
int minor;
|
||||||
|
|
||||||
|
@ -178,8 +178,8 @@ int uds_open(message *dev_m_in, message *dev_m_out)
|
||||||
fs_m_in.m_type = REQ_NEWNODE;
|
fs_m_in.m_type = REQ_NEWNODE;
|
||||||
fs_m_in.REQ_MODE = I_NAMED_PIPE;
|
fs_m_in.REQ_MODE = I_NAMED_PIPE;
|
||||||
fs_m_in.REQ_DEV = NO_DEV;
|
fs_m_in.REQ_DEV = NO_DEV;
|
||||||
fs_m_in.REQ_UID = ucred.uid;
|
fs_m_in.REQ_UID = ucred.cr_uid;
|
||||||
fs_m_in.REQ_GID = ucred.gid;
|
fs_m_in.REQ_GID = ucred.cr_gid;
|
||||||
|
|
||||||
/* Request a new inode on the pipe file system */
|
/* Request a new inode on the pipe file system */
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include <sys/select.h>
|
#include <sys/select.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <sys/ucred.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
|
@ -960,7 +960,7 @@ int do_getsockopt_peercred(message *dev_m_in, message *dev_m_out)
|
||||||
int minor;
|
int minor;
|
||||||
int peer_minor;
|
int peer_minor;
|
||||||
int rc;
|
int rc;
|
||||||
struct ucred cred;
|
struct uucred cred;
|
||||||
|
|
||||||
#if DEBUG == 1
|
#if DEBUG == 1
|
||||||
static int call_count = 0;
|
static int call_count = 0;
|
||||||
|
@ -991,7 +991,7 @@ int do_getsockopt_peercred(message *dev_m_in, message *dev_m_out)
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = sys_safecopyto(VFS_PROC_NR, (cp_grant_id_t) dev_m_in->IO_GRANT,
|
rc = sys_safecopyto(VFS_PROC_NR, (cp_grant_id_t) dev_m_in->IO_GRANT,
|
||||||
(vir_bytes) 0, (vir_bytes) &cred, sizeof(struct ucred));
|
(vir_bytes) 0, (vir_bytes) &cred, sizeof(struct uucred));
|
||||||
|
|
||||||
return rc ? EIO : OK;
|
return rc ? EIO : OK;
|
||||||
}
|
}
|
||||||
|
@ -1352,10 +1352,10 @@ static int recv_cred(int minor, struct ancillary *data,
|
||||||
cmsg = CMSG_NXTHDR(&msghdr, cmsg);
|
cmsg = CMSG_NXTHDR(&msghdr, cmsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
cmsg->cmsg_len = CMSG_LEN(sizeof(struct ucred));
|
cmsg->cmsg_len = CMSG_LEN(sizeof(struct uucred));
|
||||||
cmsg->cmsg_level = SOL_SOCKET;
|
cmsg->cmsg_level = SOL_SOCKET;
|
||||||
cmsg->cmsg_type = SCM_CREDENTIALS;
|
cmsg->cmsg_type = SCM_CREDENTIALS;
|
||||||
memcpy(CMSG_DATA(cmsg), &(data->cred), sizeof(struct ucred));
|
memcpy(CMSG_DATA(cmsg), &(data->cred), sizeof(struct uucred));
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
@ -1481,7 +1481,7 @@ int do_recvmsg(message *dev_m_in, message *dev_m_out)
|
||||||
|
|
||||||
/* if there is room we also include credentials */
|
/* if there is room we also include credentials */
|
||||||
controllen_desired = controllen_needed +
|
controllen_desired = controllen_needed +
|
||||||
CMSG_LEN(sizeof(struct ucred));
|
CMSG_LEN(sizeof(struct uucred));
|
||||||
|
|
||||||
if (controllen_needed > controllen_avail) {
|
if (controllen_needed > controllen_avail) {
|
||||||
return EOVERFLOW;
|
return EOVERFLOW;
|
||||||
|
|
|
@ -26,7 +26,7 @@ struct ancillary {
|
||||||
filp_id_t filps[OPEN_MAX];
|
filp_id_t filps[OPEN_MAX];
|
||||||
int fds[OPEN_MAX];
|
int fds[OPEN_MAX];
|
||||||
int nfiledes;
|
int nfiledes;
|
||||||
struct ucred cred;
|
struct uucred cred;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -43,12 +43,6 @@
|
||||||
/*
|
/*
|
||||||
* Credentials.
|
* Credentials.
|
||||||
*/
|
*/
|
||||||
struct ucred
|
|
||||||
{
|
|
||||||
pid_t pid;
|
|
||||||
uid_t uid;
|
|
||||||
gid_t gid;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Userland's view of credentials. This should not change */
|
/* Userland's view of credentials. This should not change */
|
||||||
struct uucred {
|
struct uucred {
|
||||||
|
@ -59,9 +53,9 @@ struct uucred {
|
||||||
gid_t cr_groups[NGROUPS_MAX]; /* groups */
|
gid_t cr_groups[NGROUPS_MAX]; /* groups */
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef __minix
|
#if defined(__minix)
|
||||||
#include <minix/type.h>
|
#include <minix/type.h>
|
||||||
int getnucred(endpoint_t proc_ep, struct ucred *ucred);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
int getnucred(endpoint_t proc_ep, struct uucred *ucred);
|
||||||
|
#endif /* defined(__minix) */
|
||||||
#endif /* !_SYS_UCRED_H_ */
|
#endif /* !_SYS_UCRED_H_ */
|
||||||
|
|
|
@ -385,7 +385,7 @@ void test_socketpair(void)
|
||||||
|
|
||||||
void test_ucred(void)
|
void test_ucred(void)
|
||||||
{
|
{
|
||||||
struct ucred credentials;
|
struct uucred credentials;
|
||||||
socklen_t ucred_length;
|
socklen_t ucred_length;
|
||||||
uid_t euid = geteuid();
|
uid_t euid = geteuid();
|
||||||
gid_t egid = getegid();
|
gid_t egid = getegid();
|
||||||
|
@ -394,7 +394,7 @@ void test_ucred(void)
|
||||||
|
|
||||||
debug("Test credentials passing");
|
debug("Test credentials passing");
|
||||||
|
|
||||||
ucred_length = sizeof(struct ucred);
|
ucred_length = sizeof(struct uucred);
|
||||||
|
|
||||||
rc = socketpair(PF_UNIX, SOCK_STREAM, 0, sv);
|
rc = socketpair(PF_UNIX, SOCK_STREAM, 0, sv);
|
||||||
if (rc == -1) {
|
if (rc == -1) {
|
||||||
|
@ -406,18 +406,18 @@ void test_ucred(void)
|
||||||
&ucred_length);
|
&ucred_length);
|
||||||
if (rc == -1) {
|
if (rc == -1) {
|
||||||
test_fail("getsockopt(SO_PEERCRED) failed");
|
test_fail("getsockopt(SO_PEERCRED) failed");
|
||||||
} else if (credentials.pid != getpid() ||
|
} else if (credentials.cr_ngroups != 0 ||
|
||||||
credentials.uid != geteuid() ||
|
credentials.cr_uid != geteuid() ||
|
||||||
credentials.gid != getegid()) {
|
credentials.cr_gid != getegid()) {
|
||||||
/* printf("%d=%d %d=%d %d=%d",credentials.pid, getpid(),
|
/* printf("%d=%d %d=%d %d=%d",credentials.cr_ngroups, 0,
|
||||||
credentials.uid, geteuid(), credentials.gid, getegid()); */
|
credentials.cr_uid, geteuid(), credentials.cr_gid, getegid()); */
|
||||||
test_fail("Credential passing gave us the wrong cred");
|
test_fail("Credential passing gave us the wrong cred");
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = getpeereid(sv[0], &euid, &egid);
|
rc = getpeereid(sv[0], &euid, &egid);
|
||||||
if (rc == -1) {
|
if (rc == -1) {
|
||||||
test_fail("getpeereid(sv[0], &euid, &egid) failed");
|
test_fail("getpeereid(sv[0], &euid, &egid) failed");
|
||||||
} else if (credentials.uid != euid || credentials.gid != egid) {
|
} else if (credentials.cr_uid != euid || credentials.cr_gid != egid) {
|
||||||
test_fail("getpeereid() didn't give the correct euid/egid");
|
test_fail("getpeereid() didn't give the correct euid/egid");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1195,7 +1195,7 @@ void test_xfer_sighdlr(int sig)
|
||||||
*/
|
*/
|
||||||
void test_xfer_client(void)
|
void test_xfer_client(void)
|
||||||
{
|
{
|
||||||
struct ucred credentials;
|
struct uucred credentials;
|
||||||
socklen_t ucred_length;
|
socklen_t ucred_length;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
fd_set readfds;
|
fd_set readfds;
|
||||||
|
@ -1208,7 +1208,7 @@ void test_xfer_client(void)
|
||||||
|
|
||||||
debug("[client] entering test_xfer_client()");
|
debug("[client] entering test_xfer_client()");
|
||||||
errct = 0; /* reset error count */
|
errct = 0; /* reset error count */
|
||||||
ucred_length = sizeof(struct ucred);
|
ucred_length = sizeof(struct uucred);
|
||||||
memset(&buf, '\0', sizeof(buf));
|
memset(&buf, '\0', sizeof(buf));
|
||||||
|
|
||||||
while (server_ready == 0) {
|
while (server_ready == 0) {
|
||||||
|
@ -1296,10 +1296,10 @@ void test_xfer_client(void)
|
||||||
|
|
||||||
if (rc == -1) {
|
if (rc == -1) {
|
||||||
test_fail("[client] getsockopt() failed");
|
test_fail("[client] getsockopt() failed");
|
||||||
} else if (credentials.uid != geteuid() ||
|
} else if (credentials.cr_uid != geteuid() ||
|
||||||
credentials.gid != getegid()) {
|
credentials.cr_gid != getegid()) {
|
||||||
printf("%d=%d=%d %d=%d=%d\n", credentials.uid, getuid(),
|
printf("%d=%d=%d %d=%d=%d\n", credentials.cr_uid, getuid(),
|
||||||
geteuid(), credentials.gid, getgid(), getegid());
|
geteuid(), credentials.cr_gid, getgid(), getegid());
|
||||||
test_fail("[client] Credential passing gave us a bad UID/GID");
|
test_fail("[client] Credential passing gave us a bad UID/GID");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2106,7 +2106,7 @@ void test_scm_credentials(void)
|
||||||
int rc;
|
int rc;
|
||||||
int src;
|
int src;
|
||||||
int dst;
|
int dst;
|
||||||
struct ucred cred;
|
struct uucred cred;
|
||||||
struct cmsghdr *cmsg = NULL;
|
struct cmsghdr *cmsg = NULL;
|
||||||
struct sockaddr_un addr;
|
struct sockaddr_un addr;
|
||||||
struct iovec iov[3];
|
struct iovec iov[3];
|
||||||
|
@ -2233,20 +2233,20 @@ void test_scm_credentials(void)
|
||||||
|
|
||||||
debug("looking for credentials");
|
debug("looking for credentials");
|
||||||
|
|
||||||
memset(&cred, '\0', sizeof(struct ucred));
|
memset(&cred, '\0', sizeof(struct uucred));
|
||||||
for (cmsg = CMSG_FIRSTHDR(&msg2); cmsg != NULL;
|
for (cmsg = CMSG_FIRSTHDR(&msg2); cmsg != NULL;
|
||||||
cmsg = CMSG_NXTHDR(&msg2, cmsg)) {
|
cmsg = CMSG_NXTHDR(&msg2, cmsg)) {
|
||||||
|
|
||||||
if (cmsg->cmsg_level == SOL_SOCKET &&
|
if (cmsg->cmsg_level == SOL_SOCKET &&
|
||||||
cmsg->cmsg_type == SCM_CREDENTIALS) {
|
cmsg->cmsg_type == SCM_CREDENTIALS) {
|
||||||
|
|
||||||
memcpy(&cred, CMSG_DATA(cmsg), sizeof(struct ucred));
|
memcpy(&cred, CMSG_DATA(cmsg), sizeof(struct uucred));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cred.pid != getpid() || cred.uid != geteuid() ||
|
if (cred.cr_ngroups != 0 || cred.cr_uid != geteuid() ||
|
||||||
cred.gid != getegid()) {
|
cred.cr_gid != getegid()) {
|
||||||
|
|
||||||
test_fail("did no receive the proper credentials");
|
test_fail("did no receive the proper credentials");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue