Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern Handle LOCAL_PEERID for socketpair() connected sock...



details:   https://anonhg.NetBSD.org/src/rev/553f665cc580
branches:  trunk
changeset: 335957:553f665cc580
user:      christos <christos%NetBSD.org@localhost>
date:      Mon Feb 02 02:28:26 2015 +0000

description:
Handle LOCAL_PEERID for socketpair() connected sockets which connect through
connect2().
1. move the code that sets the peerid structure into connect1(). This
   handles so2.  The datagram code calls connect2 twice with flipped
   so arguments so both sockets get set.
2. in connect2 copy the peerid structure from so2 to so, so that that
   both stream sockets get set.

diffstat:

 sys/kern/uipc_usrreq.c |  34 +++++++++++++++++++++-------------
 1 files changed, 21 insertions(+), 13 deletions(-)

diffs (85 lines):

diff -r 7eabe3b06444 -r 553f665cc580 sys/kern/uipc_usrreq.c
--- a/sys/kern/uipc_usrreq.c    Mon Feb 02 02:01:06 2015 +0000
+++ b/sys/kern/uipc_usrreq.c    Mon Feb 02 02:28:26 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uipc_usrreq.c,v 1.172 2014/10/08 16:13:02 taca Exp $   */
+/*     $NetBSD: uipc_usrreq.c,v 1.173 2015/02/02 02:28:26 christos Exp $       */
 
 /*-
  * Copyright (c) 1998, 2000, 2004, 2008, 2009 The NetBSD Foundation, Inc.
@@ -96,7 +96,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uipc_usrreq.c,v 1.172 2014/10/08 16:13:02 taca Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_usrreq.c,v 1.173 2015/02/02 02:28:26 christos Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -1075,7 +1075,7 @@
 }
 
 static int
-unp_connect1(struct socket *so, struct socket *so2)
+unp_connect1(struct socket *so, struct socket *so2, struct lwp *l)
 {
        struct unpcb *unp = sotounpcb(so);
        struct unpcb *unp2;
@@ -1099,6 +1099,18 @@
 
        unp2 = sotounpcb(so2);
        unp->unp_conn = unp2;
+
+       if ((so->so_proto->pr_flags & PR_CONNREQUIRED) != 0) {
+               unp2->unp_connid.unp_pid = l->l_proc->p_pid;
+               unp2->unp_connid.unp_euid = kauth_cred_geteuid(l->l_cred);
+               unp2->unp_connid.unp_egid = kauth_cred_getegid(l->l_cred);
+               unp2->unp_flags |= UNP_EIDSVALID;
+               if (unp2->unp_flags & UNP_EIDSBIND) {
+                       unp->unp_connid = unp2->unp_connid;
+                       unp->unp_flags |= UNP_EIDSVALID;
+               }
+       }
+
        switch (so->so_type) {
 
        case SOCK_DGRAM:
@@ -1208,17 +1220,9 @@
                        unp3->unp_addrlen = unp2->unp_addrlen;
                }
                unp3->unp_flags = unp2->unp_flags;
-               unp3->unp_connid.unp_pid = l->l_proc->p_pid;
-               unp3->unp_connid.unp_euid = kauth_cred_geteuid(l->l_cred);
-               unp3->unp_connid.unp_egid = kauth_cred_getegid(l->l_cred);
-               unp3->unp_flags |= UNP_EIDSVALID;
-               if (unp2->unp_flags & UNP_EIDSBIND) {
-                       unp->unp_connid = unp2->unp_connid;
-                       unp->unp_flags |= UNP_EIDSVALID;
-               }
                so2 = so3;
        }
-       error = unp_connect1(so, so2);
+       error = unp_connect1(so, so2, l);
        if (error) {
                sounlock(so);
                goto bad;
@@ -1269,7 +1273,7 @@
 
        KASSERT(solocked2(so, so2));
 
-       error = unp_connect1(so, so2);
+       error = unp_connect1(so, so2, curlwp);
        if (error)
                return error;
 
@@ -1285,6 +1289,10 @@
        case SOCK_SEQPACKET: /* FALLTHROUGH */
        case SOCK_STREAM:
                unp2->unp_conn = unp;
+               if ((so->so_proto->pr_flags & PR_CONNREQUIRED) != 0) {
+                       unp->unp_connid = unp2->unp_connid;
+                       unp->unp_flags |= UNP_EIDSVALID;
+               }
                soisconnected(so);
                soisconnected(so2);
                break;



Home | Main Index | Thread Index | Old Index