]> Zhao Yanbai Git Server - minix.git/commitdiff
struct uucred 23/923/2
authorLionel Sambuc <lionel@minix3.org>
Thu, 18 Apr 2013 09:07:44 +0000 (11:07 +0200)
committerLionel Sambuc <lionel@minix3.org>
Tue, 18 Feb 2014 10:25:01 +0000 (11:25 +0100)
Change-Id: Ia97cb6c38bb566be30d568a252ae7b76142a21dd

include/sys/ioc_net.h
lib/libc/net/minix/getpeereid.c
lib/libc/sys-minix/getsockopt.c
lib/libminlib/getnucred.c
man/man2/getnucred.2
servers/pfs/dev_uds.c
servers/pfs/inc.h
servers/pfs/uds.c
servers/pfs/uds.h
sys/sys/ucred.h
test/test56.c

index 12f4188a2aa0c341c6577fcbe107707be48a8210..4fe62c38ec7bdc0934eacf693b7619839abf6277 100644 (file)
@@ -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 */
index 6da016b263744087bfe2120b7db0ad4807ca1202..775256f8fb2818f8747823a15bc6a57d55feb118 100644 (file)
@@ -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 */
index c37b5dc365158a70b5e2aa21f17247bf514f65c5..16408bf498b36306b179f76a7bb14c99ab444d19 100644 (file)
@@ -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;
        }
index cbddc7bb9eeb4da560a2e1ef60f95d7aa935d87c..f95a1d56461781f901dd1785f2fb4a1d46ec3a4c 100644 (file)
@@ -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;
 }
index 0f989cec2e6efb22767b8c35bd2de9a39adeb1ab..31e317d469c5357de6b05e2315849ce9e5bb04da 100644 (file)
@@ -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
index cada761a5a4ef2648135c9f4a4e6e8bbc5cb7f0a..885e19440af812283da9d6c0b039cd65cbc6710f 100644 (file)
@@ -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 */
 
index 89a1801e45e7d2684309665c19087e3a7298706f..0aa5f05e46d638610c0fb24c7c2b321b17313a21 100644 (file)
@@ -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>
index 34b9d10064d07e89da688e2a3f5295d65a0b79da..9142a87bb8820c2ee4b966d52c8b2d598f9d8b5d 100644 (file)
@@ -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;
index 066a6462612e875fa297a4e11158244fc41e18e8..93b2ee347514d6a2faee7186203e5c993fd2cc72 100644 (file)
@@ -26,7 +26,7 @@ struct ancillary {
        filp_id_t filps[OPEN_MAX];
        int fds[OPEN_MAX];
        int nfiledes;
-       struct ucred cred;
+       struct uucred cred;
 };
 
 /*
index 3ab646258e9bfa8ad40ecc35f2acaa6d07d77feb..17ca57ce6f4b9fe492465721d22e2e3ff563ed4e 100644 (file)
 /*
  * 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_ */
index 0b1b3197aa3ba7c233eb200b34eaa8ed746aa5ad..af55d09fa025b6512354d8168cb080034bad4a76 100644 (file)
@@ -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");
        }