/* 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 */
*/
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 */
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 */
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;
}
-#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;
}
#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
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;
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 */
#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>
int minor;
int peer_minor;
int rc;
- struct ucred cred;
+ struct uucred cred;
#if DEBUG == 1
static int call_count = 0;
}
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;
}
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;
}
/* 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;
filp_id_t filps[OPEN_MAX];
int fds[OPEN_MAX];
int nfiledes;
- struct ucred cred;
+ struct uucred cred;
};
/*
/*
* Credentials.
*/
-struct ucred
-{
- pid_t pid;
- uid_t uid;
- gid_t gid;
-};
/* Userland's view of credentials. This should not change */
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_ */
void test_ucred(void)
{
- struct ucred credentials;
+ struct uucred credentials;
socklen_t ucred_length;
uid_t euid = geteuid();
gid_t egid = getegid();
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) {
&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");
}
*/
void test_xfer_client(void)
{
- struct ucred credentials;
+ struct uucred credentials;
socklen_t ucred_length;
struct timeval tv;
fd_set readfds;
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) {
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");
}
int rc;
int src;
int dst;
- struct ucred cred;
+ struct uucred cred;
struct cmsghdr *cmsg = NULL;
struct sockaddr_un addr;
struct iovec iov[3];
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");
}