Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 30 May 1999 11:39:51 -0400 (EDT)
From:      Brian Feldman <green@unixhelp.org>
To:        hackers@FreeBSD.org
Subject:   so_cred changes
Message-ID:  <Pine.BSF.4.10.9905301135220.10426-200000@janus.syracuse.net>

next in thread | raw e-mail | index | archive | help

[-- Attachment #1 --]
Here they all are! I bumped __FreeBSD_version so this can be detected outside
of the kernel (*cough* pidentd *cough*); this makes pidentd a lot simpler; I
am also going to write a sysctl interface for getting credential info soon,
so I'll reimplement identd then. Anyone for /usr/libexec/identd? :)

IPFW UID/GID support still works, but I'm cleaning up (Since I just broke it out
of so_cred changes, and it can USE the cleanup.)

Anyone for committing the so_cred changes? I've got the the pidentd changes
here, too.

 Brian Feldman                _ __ ___ ____  ___ ___ ___  
 green@unixhelp.org                _ __ ___ | _ ) __|   \ 
     FreeBSD: The Power to Serve!      _ __ | _ \ _ \ |) |
         http://www.freebsd.org           _ |___)___/___/ 

[-- Attachment #2 --]
--- src/sys/sys/socketvar.h.orig	Sat May 29 17:26:53 1999
+++ src/sys/sys/socketvar.h	Sun May 30 11:07:07 1999
@@ -105,7 +105,7 @@
 
 	void	(*so_upcall) __P((struct socket *, void *, int));
 	void	*so_upcallarg;
-	uid_t	so_uid;			/* who opened the socket */
+	struct pcred *so_cred;		/* user credentials */
 	/* NB: generation count must not be first; easiest to make it last. */
 	so_gen_t so_gencnt;		/* generation count */
 	void	*so_emuldata;		/* private data for emulators */
--- src/sys/kern/uipc_socket.c.orig	Sat May 29 17:26:59 1999
+++ src/sys/kern/uipc_socket.c	Sun May 30 10:52:32 1999
@@ -36,13 +36,14 @@
 
 #include <sys/param.h>
 #include <sys/systm.h>
-#include <sys/proc.h>
 #include <sys/fcntl.h>
 #include <sys/malloc.h>
 #include <sys/mbuf.h>
 #include <sys/domain.h>
 #include <sys/kernel.h>
+#include <sys/malloc.h>
 #include <sys/poll.h>
+#include <sys/proc.h>
 #include <sys/protosw.h>
 #include <sys/socket.h>
 #include <sys/socketvar.h>
@@ -124,8 +125,10 @@
 	TAILQ_INIT(&so->so_incomp);
 	TAILQ_INIT(&so->so_comp);
 	so->so_type = type;
-	if (p != 0)
-		so->so_uid = p->p_ucred->cr_uid;
+	if (p) {
+		so->so_cred = p->p_cred;
+		so->so_cred->p_refcnt++;
+	} else so->so_cred = NULL;
 	so->so_proto = prp;
 	error = (*prp->pr_usrreqs->pru_attach)(so, proto, p);
 	if (error) {
@@ -156,6 +159,10 @@
 	struct socket *so;
 {
 	so->so_gencnt = ++so_gencnt;
+	if (so->so_cred && --so->so_cred->p_refcnt == 0) {
+		crfree(so->so_cred->pc_ucred);
+		FREE(so->so_cred, M_SUBPROC);
+	}
 	zfreei(so->so_zone, so);
 }
 
--- src/sys/kern/uipc_socket2.c.orig	Sat May 29 17:27:05 1999
+++ src/sys/kern/uipc_socket2.c	Sun May 30 10:53:53 1999
@@ -213,7 +213,9 @@
 	so->so_state = head->so_state | SS_NOFDREF;
 	so->so_proto = head->so_proto;
 	so->so_timeo = head->so_timeo;
-	so->so_uid = head->so_uid;
+	so->so_cred = head->so_cred;
+	if (so->so_cred)
+		so->so_cred->p_refcnt++;
 	(void) soreserve(so, head->so_snd.sb_hiwat, head->so_rcv.sb_hiwat);
 
 	if ((*so->so_proto->pr_usrreqs->pru_attach)(so, 0, NULL)) {
@@ -915,7 +917,7 @@
 	xso->so_oobmark = so->so_oobmark;
 	sbtoxsockbuf(&so->so_snd, &xso->so_snd);
 	sbtoxsockbuf(&so->so_rcv, &xso->so_rcv);
-	xso->so_uid = so->so_uid;
+	xso->so_uid = so->so_cred ? so->so_cred->pc_ucred->cr_uid : -1;
 }
 
 /*
--- src/sys/netinet/in_pcb.c.orig	Sun May 30 10:54:09 1999
+++ src/sys/netinet/in_pcb.c	Sun May 30 11:03:19 1999
@@ -202,7 +202,7 @@
 				return (EACCES);
 			if (p && p->p_prison)
 				prison = 1;
-			if (so->so_uid &&
+			if (so->so_cred &&
 			    !IN_MULTICAST(ntohl(sin->sin_addr.s_addr))) {
 				t = in_pcblookup_local(inp->inp_pcbinfo,
 				    sin->sin_addr, lport, 
@@ -212,7 +212,9 @@
 				     ntohl(t->inp_laddr.s_addr) != INADDR_ANY ||
 				     (t->inp_socket->so_options &
 					 SO_REUSEPORT) == 0) &&
-				    (so->so_uid != t->inp_socket->so_uid))
+				    (t->inp_socket->so_cred) && 
+				    (so->so_cred->p_ruid !=
+					t->inp_socket->so_cred->p_ruid))
 					return (EADDRINUSE);
 			}
 			t = in_pcblookup_local(pcbinfo, sin->sin_addr,
--- src/sys/sys/param.h.orig	Sun May 30 11:31:18 1999
+++ src/sys/sys/param.h	Sun May 30 11:31:30 1999
@@ -46,7 +46,7 @@
 #define BSD4_3	1
 #define BSD4_4	1
 #undef __FreeBSD_version
-#define __FreeBSD_version 400005	/* Master, propagated to newvers */
+#define __FreeBSD_version 400006	/* Master, propagated to newvers */
 
 #ifndef NULL
 #define	NULL	0

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.10.9905301135220.10426-200000>