add socket info for user and group for unix sockets in fstat.diff -r1.290 -r1.291 src/sys/kern/uipc_socket.c
(christos)
--- src/sys/kern/uipc_socket.c 2020/06/07 15:19:05 1.290
+++ src/sys/kern/uipc_socket.c 2020/08/26 22:54:30 1.291
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: uipc_socket.c,v 1.290 2020/06/07 15:19:05 maxv Exp $ */ | 1 | /* $NetBSD: uipc_socket.c,v 1.291 2020/08/26 22:54:30 christos Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 2002, 2007, 2008, 2009 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 2002, 2007, 2008, 2009 The NetBSD Foundation, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to The NetBSD Foundation | 7 | * This code is derived from software contributed to The NetBSD Foundation | |
8 | * by Jason R. Thorpe of Wasabi Systems, Inc, and by Andrew Doran. | 8 | * by Jason R. Thorpe of Wasabi Systems, Inc, and by Andrew Doran. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -61,27 +61,27 @@ | @@ -61,27 +61,27 @@ | |||
61 | * | 61 | * | |
62 | * @(#)uipc_socket.c 8.6 (Berkeley) 5/2/95 | 62 | * @(#)uipc_socket.c 8.6 (Berkeley) 5/2/95 | |
63 | */ | 63 | */ | |
64 | 64 | |||
65 | /* | 65 | /* | |
66 | * Socket operation routines. | 66 | * Socket operation routines. | |
67 | * | 67 | * | |
68 | * These routines are called by the routines in sys_socket.c or from a | 68 | * These routines are called by the routines in sys_socket.c or from a | |
69 | * system process, and implement the semantics of socket operations by | 69 | * system process, and implement the semantics of socket operations by | |
70 | * switching out to the protocol specific routines. | 70 | * switching out to the protocol specific routines. | |
71 | */ | 71 | */ | |
72 | 72 | |||
73 | #include <sys/cdefs.h> | 73 | #include <sys/cdefs.h> | |
74 | __KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.290 2020/06/07 15:19:05 maxv Exp $"); | 74 | __KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.291 2020/08/26 22:54:30 christos Exp $"); | |
75 | 75 | |||
76 | #ifdef _KERNEL_OPT | 76 | #ifdef _KERNEL_OPT | |
77 | #include "opt_compat_netbsd.h" | 77 | #include "opt_compat_netbsd.h" | |
78 | #include "opt_sock_counters.h" | 78 | #include "opt_sock_counters.h" | |
79 | #include "opt_sosend_loan.h" | 79 | #include "opt_sosend_loan.h" | |
80 | #include "opt_mbuftrace.h" | 80 | #include "opt_mbuftrace.h" | |
81 | #include "opt_somaxkva.h" | 81 | #include "opt_somaxkva.h" | |
82 | #include "opt_multiprocessor.h" /* XXX */ | 82 | #include "opt_multiprocessor.h" /* XXX */ | |
83 | #include "opt_sctp.h" | 83 | #include "opt_sctp.h" | |
84 | #endif | 84 | #endif | |
85 | 85 | |||
86 | #include <sys/param.h> | 86 | #include <sys/param.h> | |
87 | #include <sys/systm.h> | 87 | #include <sys/systm.h> | |
@@ -516,26 +516,27 @@ socreate(int dom, struct socket **aso, i | @@ -516,26 +516,27 @@ socreate(int dom, struct socket **aso, i | |||
516 | so = soget(true); | 516 | so = soget(true); | |
517 | so->so_type = type; | 517 | so->so_type = type; | |
518 | so->so_proto = prp; | 518 | so->so_proto = prp; | |
519 | so->so_send = sosend; | 519 | so->so_send = sosend; | |
520 | so->so_receive = soreceive; | 520 | so->so_receive = soreceive; | |
521 | so->so_options = sooptions; | 521 | so->so_options = sooptions; | |
522 | #ifdef MBUFTRACE | 522 | #ifdef MBUFTRACE | |
523 | so->so_rcv.sb_mowner = &prp->pr_domain->dom_mowner; | 523 | so->so_rcv.sb_mowner = &prp->pr_domain->dom_mowner; | |
524 | so->so_snd.sb_mowner = &prp->pr_domain->dom_mowner; | 524 | so->so_snd.sb_mowner = &prp->pr_domain->dom_mowner; | |
525 | so->so_mowner = &prp->pr_domain->dom_mowner; | 525 | so->so_mowner = &prp->pr_domain->dom_mowner; | |
526 | #endif | 526 | #endif | |
527 | uid = kauth_cred_geteuid(l->l_cred); | 527 | uid = kauth_cred_geteuid(l->l_cred); | |
528 | so->so_uidinfo = uid_find(uid); | 528 | so->so_uidinfo = uid_find(uid); | |
529 | so->so_egid = kauth_cred_getegid(l->l_cred); | |||
529 | so->so_cpid = l->l_proc->p_pid; | 530 | so->so_cpid = l->l_proc->p_pid; | |
530 | 531 | |||
531 | /* | 532 | /* | |
532 | * Lock assigned and taken during PCB attach, unless we share | 533 | * Lock assigned and taken during PCB attach, unless we share | |
533 | * the lock with another socket, e.g. socketpair(2) case. | 534 | * the lock with another socket, e.g. socketpair(2) case. | |
534 | */ | 535 | */ | |
535 | if (lockso) { | 536 | if (lockso) { | |
536 | lock = lockso->so_lock; | 537 | lock = lockso->so_lock; | |
537 | so->so_lock = lock; | 538 | so->so_lock = lock; | |
538 | mutex_obj_hold(lock); | 539 | mutex_obj_hold(lock); | |
539 | mutex_enter(lock); | 540 | mutex_enter(lock); | |
540 | } | 541 | } | |
541 | 542 |
--- src/sys/kern/uipc_socket2.c 2020/05/23 23:42:43 1.137
+++ src/sys/kern/uipc_socket2.c 2020/08/26 22:54:30 1.138
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: uipc_socket2.c,v 1.137 2020/05/23 23:42:43 ad Exp $ */ | 1 | /* $NetBSD: uipc_socket2.c,v 1.138 2020/08/26 22:54:30 christos Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2008 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 2008 The NetBSD Foundation, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that the following conditions | 8 | * modification, are permitted provided that the following conditions | |
9 | * are met: | 9 | * are met: | |
10 | * 1. Redistributions of source code must retain the above copyright | 10 | * 1. Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | 11 | * notice, this list of conditions and the following disclaimer. | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. | |
@@ -48,27 +48,27 @@ | @@ -48,27 +48,27 @@ | |||
48 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 48 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
49 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 49 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
50 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 50 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
51 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 51 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
52 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 52 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
53 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 53 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
54 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 54 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
55 | * SUCH DAMAGE. | 55 | * SUCH DAMAGE. | |
56 | * | 56 | * | |
57 | * @(#)uipc_socket2.c 8.2 (Berkeley) 2/14/95 | 57 | * @(#)uipc_socket2.c 8.2 (Berkeley) 2/14/95 | |
58 | */ | 58 | */ | |
59 | 59 | |||
60 | #include <sys/cdefs.h> | 60 | #include <sys/cdefs.h> | |
61 | __KERNEL_RCSID(0, "$NetBSD: uipc_socket2.c,v 1.137 2020/05/23 23:42:43 ad Exp $"); | 61 | __KERNEL_RCSID(0, "$NetBSD: uipc_socket2.c,v 1.138 2020/08/26 22:54:30 christos Exp $"); | |
62 | 62 | |||
63 | #ifdef _KERNEL_OPT | 63 | #ifdef _KERNEL_OPT | |
64 | #include "opt_ddb.h" | 64 | #include "opt_ddb.h" | |
65 | #include "opt_mbuftrace.h" | 65 | #include "opt_mbuftrace.h" | |
66 | #include "opt_sb_max.h" | 66 | #include "opt_sb_max.h" | |
67 | #endif | 67 | #endif | |
68 | 68 | |||
69 | #include <sys/param.h> | 69 | #include <sys/param.h> | |
70 | #include <sys/systm.h> | 70 | #include <sys/systm.h> | |
71 | #include <sys/proc.h> | 71 | #include <sys/proc.h> | |
72 | #include <sys/file.h> | 72 | #include <sys/file.h> | |
73 | #include <sys/buf.h> | 73 | #include <sys/buf.h> | |
74 | #include <sys/mbuf.h> | 74 | #include <sys/mbuf.h> | |
@@ -307,26 +307,27 @@ sonewconn(struct socket *head, bool sore | @@ -307,26 +307,27 @@ sonewconn(struct socket *head, bool sore | |||
307 | if ((so = soget(false)) == NULL) { | 307 | if ((so = soget(false)) == NULL) { | |
308 | return NULL; | 308 | return NULL; | |
309 | } | 309 | } | |
310 | so->so_type = head->so_type; | 310 | so->so_type = head->so_type; | |
311 | so->so_options = head->so_options & ~SO_ACCEPTCONN; | 311 | so->so_options = head->so_options & ~SO_ACCEPTCONN; | |
312 | so->so_linger = head->so_linger; | 312 | so->so_linger = head->so_linger; | |
313 | so->so_state = head->so_state | SS_NOFDREF; | 313 | so->so_state = head->so_state | SS_NOFDREF; | |
314 | so->so_proto = head->so_proto; | 314 | so->so_proto = head->so_proto; | |
315 | so->so_timeo = head->so_timeo; | 315 | so->so_timeo = head->so_timeo; | |
316 | so->so_pgid = head->so_pgid; | 316 | so->so_pgid = head->so_pgid; | |
317 | so->so_send = head->so_send; | 317 | so->so_send = head->so_send; | |
318 | so->so_receive = head->so_receive; | 318 | so->so_receive = head->so_receive; | |
319 | so->so_uidinfo = head->so_uidinfo; | 319 | so->so_uidinfo = head->so_uidinfo; | |
320 | so->so_egid = head->so_egid; | |||
320 | so->so_cpid = head->so_cpid; | 321 | so->so_cpid = head->so_cpid; | |
321 | 322 | |||
322 | /* | 323 | /* | |
323 | * Share the lock with the listening-socket, it may get unshared | 324 | * Share the lock with the listening-socket, it may get unshared | |
324 | * once the connection is complete. | 325 | * once the connection is complete. | |
325 | */ | 326 | */ | |
326 | mutex_obj_hold(head->so_lock); | 327 | mutex_obj_hold(head->so_lock); | |
327 | so->so_lock = head->so_lock; | 328 | so->so_lock = head->so_lock; | |
328 | 329 | |||
329 | /* | 330 | /* | |
330 | * Reserve the space for socket buffers. | 331 | * Reserve the space for socket buffers. | |
331 | */ | 332 | */ | |
332 | #ifdef MBUFTRACE | 333 | #ifdef MBUFTRACE |
--- src/sys/kern/uipc_usrreq.c 2020/04/21 21:42:47 1.198
+++ src/sys/kern/uipc_usrreq.c 2020/08/26 22:54:30 1.199
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: uipc_usrreq.c,v 1.198 2020/04/21 21:42:47 ad Exp $ */ | 1 | /* $NetBSD: uipc_usrreq.c,v 1.199 2020/08/26 22:54:30 christos Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 1998, 2000, 2004, 2008, 2009, 2020 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 1998, 2000, 2004, 2008, 2009, 2020 The NetBSD Foundation, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to The NetBSD Foundation | 7 | * This code is derived from software contributed to The NetBSD Foundation | |
8 | * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, | 8 | * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, | |
9 | * NASA Ames Research Center, and by Andrew Doran. | 9 | * NASA Ames Research Center, and by Andrew Doran. | |
10 | * | 10 | * | |
11 | * Redistribution and use in source and binary forms, with or without | 11 | * Redistribution and use in source and binary forms, with or without | |
12 | * modification, are permitted provided that the following conditions | 12 | * modification, are permitted provided that the following conditions | |
13 | * are met: | 13 | * are met: | |
14 | * 1. Redistributions of source code must retain the above copyright | 14 | * 1. Redistributions of source code must retain the above copyright | |
@@ -86,27 +86,27 @@ | @@ -86,27 +86,27 @@ | |||
86 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 86 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
87 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 87 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
88 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 88 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
89 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 89 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
90 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 90 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
91 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 91 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
92 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 92 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
93 | * SUCH DAMAGE. | 93 | * SUCH DAMAGE. | |
94 | * | 94 | * | |
95 | * @(#)uipc_usrreq.c 8.9 (Berkeley) 5/14/95 | 95 | * @(#)uipc_usrreq.c 8.9 (Berkeley) 5/14/95 | |
96 | */ | 96 | */ | |
97 | 97 | |||
98 | #include <sys/cdefs.h> | 98 | #include <sys/cdefs.h> | |
99 | __KERNEL_RCSID(0, "$NetBSD: uipc_usrreq.c,v 1.198 2020/04/21 21:42:47 ad Exp $"); | 99 | __KERNEL_RCSID(0, "$NetBSD: uipc_usrreq.c,v 1.199 2020/08/26 22:54:30 christos Exp $"); | |
100 | 100 | |||
101 | #ifdef _KERNEL_OPT | 101 | #ifdef _KERNEL_OPT | |
102 | #include "opt_compat_netbsd.h" | 102 | #include "opt_compat_netbsd.h" | |
103 | #endif | 103 | #endif | |
104 | 104 | |||
105 | #include <sys/param.h> | 105 | #include <sys/param.h> | |
106 | #include <sys/systm.h> | 106 | #include <sys/systm.h> | |
107 | #include <sys/proc.h> | 107 | #include <sys/proc.h> | |
108 | #include <sys/filedesc.h> | 108 | #include <sys/filedesc.h> | |
109 | #include <sys/domain.h> | 109 | #include <sys/domain.h> | |
110 | #include <sys/protosw.h> | 110 | #include <sys/protosw.h> | |
111 | #include <sys/socket.h> | 111 | #include <sys/socket.h> | |
112 | #include <sys/socketvar.h> | 112 | #include <sys/socketvar.h> | |
@@ -888,26 +888,28 @@ unp_stat(struct socket *so, struct stat | @@ -888,26 +888,28 @@ unp_stat(struct socket *so, struct stat | |||
888 | 888 | |||
889 | so2 = unp->unp_conn->unp_socket; | 889 | so2 = unp->unp_conn->unp_socket; | |
890 | KASSERT(solocked2(so, so2)); | 890 | KASSERT(solocked2(so, so2)); | |
891 | ub->st_blksize += so2->so_rcv.sb_cc; | 891 | ub->st_blksize += so2->so_rcv.sb_cc; | |
892 | break; | 892 | break; | |
893 | default: | 893 | default: | |
894 | break; | 894 | break; | |
895 | } | 895 | } | |
896 | ub->st_dev = NODEV; | 896 | ub->st_dev = NODEV; | |
897 | if (unp->unp_ino == 0) | 897 | if (unp->unp_ino == 0) | |
898 | unp->unp_ino = unp_ino++; | 898 | unp->unp_ino = unp_ino++; | |
899 | ub->st_atimespec = ub->st_mtimespec = ub->st_ctimespec = unp->unp_ctime; | 899 | ub->st_atimespec = ub->st_mtimespec = ub->st_ctimespec = unp->unp_ctime; | |
900 | ub->st_ino = unp->unp_ino; | 900 | ub->st_ino = unp->unp_ino; | |
901 | ub->st_uid = so->so_uidinfo->ui_uid; | |||
902 | ub->st_gid = so->so_egid; | |||
901 | return (0); | 903 | return (0); | |
902 | } | 904 | } | |
903 | 905 | |||
904 | static int | 906 | static int | |
905 | unp_peeraddr(struct socket *so, struct sockaddr *nam) | 907 | unp_peeraddr(struct socket *so, struct sockaddr *nam) | |
906 | { | 908 | { | |
907 | KASSERT(solocked(so)); | 909 | KASSERT(solocked(so)); | |
908 | KASSERT(sotounpcb(so) != NULL); | 910 | KASSERT(sotounpcb(so) != NULL); | |
909 | KASSERT(nam != NULL); | 911 | KASSERT(nam != NULL); | |
910 | 912 | |||
911 | unp_setaddr(so, nam, true); | 913 | unp_setaddr(so, nam, true); | |
912 | return 0; | 914 | return 0; | |
913 | } | 915 | } |