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 */
|
||||
#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 NWIOSUDSSNDBUF _IOW('n', 93, size_t) /* SO_SNDBUF */
|
||||
#define NWIOGUDSRCVBUF _IOR('n', 94, size_t) /* SO_RCVBUF */
|
||||
|
|
|
@ -9,11 +9,11 @@
|
|||
*/
|
||||
int getpeereid(int sd, uid_t *euid, gid_t *egid) {
|
||||
int rc;
|
||||
struct ucred cred;
|
||||
struct uucred cred;
|
||||
socklen_t ucred_length;
|
||||
|
||||
/* Initialize Data Structures */
|
||||
ucred_length = sizeof(struct ucred);
|
||||
ucred_length = sizeof(struct uucred);
|
||||
memset(&cred, '\0', ucred_length);
|
||||
|
||||
/* 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);
|
||||
if (rc == 0) {
|
||||
/* Success - return the results */
|
||||
*euid = cred.uid;
|
||||
*egid = cred.gid;
|
||||
*euid = cred.cr_uid;
|
||||
*egid = cred.cr_gid;
|
||||
return 0;
|
||||
} else {
|
||||
/* 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)
|
||||
{
|
||||
struct ucred cred;
|
||||
struct uucred cred;
|
||||
|
||||
r= ioctl(sock, NWIOGUDSPEERCRED, &cred);
|
||||
if (r == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
getsockopt_copy(&cred, sizeof(struct ucred), option_value,
|
||||
getsockopt_copy(&cred, sizeof(struct uucred), option_value,
|
||||
option_len);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,28 +1,32 @@
|
|||
#include <lib.h>
|
||||
#include <errno.h>
|
||||
#include <sys/ucred.h>
|
||||
#include <lib.h>
|
||||
#include <string.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;
|
||||
pid_t pid;
|
||||
message m;
|
||||
pid_t pid;
|
||||
|
||||
if (ucred == NULL) {
|
||||
errno = EFAULT;
|
||||
return -1;
|
||||
}
|
||||
if (ucred == NULL) {
|
||||
errno = EFAULT;
|
||||
return -1;
|
||||
}
|
||||
|
||||
m.m1_i1 = proc_ep; /* search for this process */
|
||||
m.m1_i1 = proc_ep; /* search for this process */
|
||||
|
||||
pid = _syscall(PM_PROC_NR, GETEPINFO, &m);
|
||||
if (pid < 0) {
|
||||
return -1;
|
||||
}
|
||||
pid = _syscall(PM_PROC_NR, GETEPINFO, &m);
|
||||
if (pid < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
ucred->pid = pid;
|
||||
ucred->uid = m.PM_NUID;
|
||||
ucred->gid = m.PM_NGID;
|
||||
/* 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;
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -6,10 +6,10 @@ getnucred \- obtain the credentials that correspond to the given endpoint.
|
|||
#include <sys/socket.h>
|
||||
.in +5
|
||||
.ti -5
|
||||
#include <unistd.h>
|
||||
#include <sys/ucred.h>
|
||||
|
||||
.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
|
||||
.ft P
|
||||
.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)
|
||||
{
|
||||
message fs_m_in, fs_m_out;
|
||||
struct ucred ucred;
|
||||
struct uucred ucred;
|
||||
int rc, i;
|
||||
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.REQ_MODE = I_NAMED_PIPE;
|
||||
fs_m_in.REQ_DEV = NO_DEV;
|
||||
fs_m_in.REQ_UID = ucred.uid;
|
||||
fs_m_in.REQ_GID = ucred.gid;
|
||||
fs_m_in.REQ_UID = ucred.cr_uid;
|
||||
fs_m_in.REQ_GID = ucred.cr_gid;
|
||||
|
||||
/* Request a new inode on the pipe file system */
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <sys/select.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ucred.h>
|
||||
#include <limits.h>
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
|
|
|
@ -960,7 +960,7 @@ int do_getsockopt_peercred(message *dev_m_in, message *dev_m_out)
|
|||
int minor;
|
||||
int peer_minor;
|
||||
int rc;
|
||||
struct ucred cred;
|
||||
struct uucred cred;
|
||||
|
||||
#if DEBUG == 1
|
||||
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,
|
||||
(vir_bytes) 0, (vir_bytes) &cred, sizeof(struct ucred));
|
||||
(vir_bytes) 0, (vir_bytes) &cred, sizeof(struct uucred));
|
||||
|
||||
return rc ? EIO : OK;
|
||||
}
|
||||
|
@ -1352,10 +1352,10 @@ static int recv_cred(int minor, struct ancillary *data,
|
|||
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_type = SCM_CREDENTIALS;
|
||||
memcpy(CMSG_DATA(cmsg), &(data->cred), sizeof(struct ucred));
|
||||
memcpy(CMSG_DATA(cmsg), &(data->cred), sizeof(struct uucred));
|
||||
|
||||
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 */
|
||||
controllen_desired = controllen_needed +
|
||||
CMSG_LEN(sizeof(struct ucred));
|
||||
CMSG_LEN(sizeof(struct uucred));
|
||||
|
||||
if (controllen_needed > controllen_avail) {
|
||||
return EOVERFLOW;
|
||||
|
|
|
@ -26,7 +26,7 @@ struct ancillary {
|
|||
filp_id_t filps[OPEN_MAX];
|
||||
int fds[OPEN_MAX];
|
||||
int nfiledes;
|
||||
struct ucred cred;
|
||||
struct uucred cred;
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
|
@ -43,12 +43,6 @@
|
|||
/*
|
||||
* Credentials.
|
||||
*/
|
||||
struct ucred
|
||||
{
|
||||
pid_t pid;
|
||||
uid_t uid;
|
||||
gid_t gid;
|
||||
};
|
||||
|
||||
/* Userland's view of credentials. This should not change */
|
||||
struct uucred {
|
||||
|
@ -59,9 +53,9 @@ struct uucred {
|
|||
gid_t cr_groups[NGROUPS_MAX]; /* groups */
|
||||
};
|
||||
|
||||
#ifdef __minix
|
||||
#if defined(__minix)
|
||||
#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_ */
|
||||
|
|
|
@ -385,7 +385,7 @@ void test_socketpair(void)
|
|||
|
||||
void test_ucred(void)
|
||||
{
|
||||
struct ucred credentials;
|
||||
struct uucred credentials;
|
||||
socklen_t ucred_length;
|
||||
uid_t euid = geteuid();
|
||||
gid_t egid = getegid();
|
||||
|
@ -394,7 +394,7 @@ void test_ucred(void)
|
|||
|
||||
debug("Test credentials passing");
|
||||
|
||||
ucred_length = sizeof(struct ucred);
|
||||
ucred_length = sizeof(struct uucred);
|
||||
|
||||
rc = socketpair(PF_UNIX, SOCK_STREAM, 0, sv);
|
||||
if (rc == -1) {
|
||||
|
@ -406,18 +406,18 @@ void test_ucred(void)
|
|||
&ucred_length);
|
||||
if (rc == -1) {
|
||||
test_fail("getsockopt(SO_PEERCRED) failed");
|
||||
} else if (credentials.pid != getpid() ||
|
||||
credentials.uid != geteuid() ||
|
||||
credentials.gid != getegid()) {
|
||||
/* printf("%d=%d %d=%d %d=%d",credentials.pid, getpid(),
|
||||
credentials.uid, geteuid(), credentials.gid, getegid()); */
|
||||
} else if (credentials.cr_ngroups != 0 ||
|
||||
credentials.cr_uid != geteuid() ||
|
||||
credentials.cr_gid != getegid()) {
|
||||
/* printf("%d=%d %d=%d %d=%d",credentials.cr_ngroups, 0,
|
||||
credentials.cr_uid, geteuid(), credentials.cr_gid, getegid()); */
|
||||
test_fail("Credential passing gave us the wrong cred");
|
||||
}
|
||||
|
||||
rc = getpeereid(sv[0], &euid, &egid);
|
||||
if (rc == -1) {
|
||||
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");
|
||||
}
|
||||
|
||||
|
@ -1195,7 +1195,7 @@ void test_xfer_sighdlr(int sig)
|
|||
*/
|
||||
void test_xfer_client(void)
|
||||
{
|
||||
struct ucred credentials;
|
||||
struct uucred credentials;
|
||||
socklen_t ucred_length;
|
||||
struct timeval tv;
|
||||
fd_set readfds;
|
||||
|
@ -1208,7 +1208,7 @@ void test_xfer_client(void)
|
|||
|
||||
debug("[client] entering test_xfer_client()");
|
||||
errct = 0; /* reset error count */
|
||||
ucred_length = sizeof(struct ucred);
|
||||
ucred_length = sizeof(struct uucred);
|
||||
memset(&buf, '\0', sizeof(buf));
|
||||
|
||||
while (server_ready == 0) {
|
||||
|
@ -1296,10 +1296,10 @@ void test_xfer_client(void)
|
|||
|
||||
if (rc == -1) {
|
||||
test_fail("[client] getsockopt() failed");
|
||||
} else if (credentials.uid != geteuid() ||
|
||||
credentials.gid != getegid()) {
|
||||
printf("%d=%d=%d %d=%d=%d\n", credentials.uid, getuid(),
|
||||
geteuid(), credentials.gid, getgid(), getegid());
|
||||
} else if (credentials.cr_uid != geteuid() ||
|
||||
credentials.cr_gid != getegid()) {
|
||||
printf("%d=%d=%d %d=%d=%d\n", credentials.cr_uid, getuid(),
|
||||
geteuid(), credentials.cr_gid, getgid(), getegid());
|
||||
test_fail("[client] Credential passing gave us a bad UID/GID");
|
||||
}
|
||||
|
||||
|
@ -2106,7 +2106,7 @@ void test_scm_credentials(void)
|
|||
int rc;
|
||||
int src;
|
||||
int dst;
|
||||
struct ucred cred;
|
||||
struct uucred cred;
|
||||
struct cmsghdr *cmsg = NULL;
|
||||
struct sockaddr_un addr;
|
||||
struct iovec iov[3];
|
||||
|
@ -2233,20 +2233,20 @@ void test_scm_credentials(void)
|
|||
|
||||
debug("looking for credentials");
|
||||
|
||||
memset(&cred, '\0', sizeof(struct ucred));
|
||||
memset(&cred, '\0', sizeof(struct uucred));
|
||||
for (cmsg = CMSG_FIRSTHDR(&msg2); cmsg != NULL;
|
||||
cmsg = CMSG_NXTHDR(&msg2, cmsg)) {
|
||||
|
||||
if (cmsg->cmsg_level == SOL_SOCKET &&
|
||||
cmsg->cmsg_type == SCM_CREDENTIALS) {
|
||||
|
||||
memcpy(&cred, CMSG_DATA(cmsg), sizeof(struct ucred));
|
||||
memcpy(&cred, CMSG_DATA(cmsg), sizeof(struct uucred));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (cred.pid != getpid() || cred.uid != geteuid() ||
|
||||
cred.gid != getegid()) {
|
||||
if (cred.cr_ngroups != 0 || cred.cr_uid != geteuid() ||
|
||||
cred.cr_gid != getegid()) {
|
||||
|
||||
test_fail("did no receive the proper credentials");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue