summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgreen <green@FreeBSD.org>1999-07-11 18:32:46 +0000
committergreen <green@FreeBSD.org>1999-07-11 18:32:46 +0000
commita9a930f77ff5e7ded8c34e21a382d206d58ee7cf (patch)
tree66df8a332ee0327a875f81bdf39de00687f239b7
parentc7285cff599c1a401d1c26faf50f32b276a23004 (diff)
downloadFreeBSD-src-a9a930f77ff5e7ded8c34e21a382d206d58ee7cf.zip
FreeBSD-src-a9a930f77ff5e7ded8c34e21a382d206d58ee7cf.tar.gz
Two new sysctls: net.inet.tcp.getcred and net.inet.udp.getcred. These take
a sockaddr_in[2] (local, then remote) and return a struct ucred. Example code for these is at: http://www.FreeBSD.org/~green/inetd_ident.patch http://www.FreeBSD.org/~green/freebsd4.c (for pidentd) Reviewed by: bde
-rw-r--r--sys/netinet/tcp_subr.c34
-rw-r--r--sys/netinet/tcp_timewait.c34
-rw-r--r--sys/netinet/udp_usrreq.c34
3 files changed, 99 insertions, 3 deletions
diff --git a/sys/netinet/tcp_subr.c b/sys/netinet/tcp_subr.c
index 2dcee7b..adc4ac9 100644
--- a/sys/netinet/tcp_subr.c
+++ b/sys/netinet/tcp_subr.c
@@ -31,7 +31,7 @@
* SUCH DAMAGE.
*
* @(#)tcp_subr.c 8.2 (Berkeley) 5/24/95
- * $Id: tcp_subr.c,v 1.55 1999/06/16 19:05:17 tegge Exp $
+ * $Id: tcp_subr.c,v 1.56 1999/07/05 08:46:55 msmith Exp $
*/
#include "opt_compat.h"
@@ -43,6 +43,7 @@
#include <sys/sysctl.h>
#include <sys/malloc.h>
#include <sys/mbuf.h>
+#include <sys/proc.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
#include <sys/protosw.h>
@@ -587,6 +588,37 @@ tcp_pcblist SYSCTL_HANDLER_ARGS
SYSCTL_PROC(_net_inet_tcp, TCPCTL_PCBLIST, pcblist, CTLFLAG_RD, 0, 0,
tcp_pcblist, "S,xtcpcb", "List of active TCP connections");
+static int
+tcp_getcred SYSCTL_HANDLER_ARGS
+{
+ struct sockaddr_in addrs[2];
+ struct inpcb *inp;
+ int error, s;
+
+ error = suser(req->p);
+ if (error)
+ return (error);
+ error = SYSCTL_IN(req, addrs, sizeof(addrs));
+ if (error)
+ return (error);
+ s = splnet();
+ inp = in_pcblookup_hash(&tcbinfo, addrs[1].sin_addr, addrs[1].sin_port,
+ addrs[0].sin_addr, addrs[0].sin_port, 0);
+ if (inp == NULL || inp->inp_socket == NULL ||
+ inp->inp_socket->so_cred == NULL) {
+ error = ENOENT;
+ goto out;
+ }
+ error = SYSCTL_OUT(req, inp->inp_socket->so_cred->pc_ucred,
+ sizeof(struct ucred));
+out:
+ splx(s);
+ return (error);
+}
+
+SYSCTL_PROC(_net_inet_tcp, OID_AUTO, getcred, CTLTYPE_OPAQUE|CTLFLAG_RW,
+ 0, 0, tcp_getcred, "S,ucred", "Get the ucred of a TCP connection");
+
void
tcp_ctlinput(cmd, sa, vip)
int cmd;
diff --git a/sys/netinet/tcp_timewait.c b/sys/netinet/tcp_timewait.c
index 2dcee7b..adc4ac9 100644
--- a/sys/netinet/tcp_timewait.c
+++ b/sys/netinet/tcp_timewait.c
@@ -31,7 +31,7 @@
* SUCH DAMAGE.
*
* @(#)tcp_subr.c 8.2 (Berkeley) 5/24/95
- * $Id: tcp_subr.c,v 1.55 1999/06/16 19:05:17 tegge Exp $
+ * $Id: tcp_subr.c,v 1.56 1999/07/05 08:46:55 msmith Exp $
*/
#include "opt_compat.h"
@@ -43,6 +43,7 @@
#include <sys/sysctl.h>
#include <sys/malloc.h>
#include <sys/mbuf.h>
+#include <sys/proc.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
#include <sys/protosw.h>
@@ -587,6 +588,37 @@ tcp_pcblist SYSCTL_HANDLER_ARGS
SYSCTL_PROC(_net_inet_tcp, TCPCTL_PCBLIST, pcblist, CTLFLAG_RD, 0, 0,
tcp_pcblist, "S,xtcpcb", "List of active TCP connections");
+static int
+tcp_getcred SYSCTL_HANDLER_ARGS
+{
+ struct sockaddr_in addrs[2];
+ struct inpcb *inp;
+ int error, s;
+
+ error = suser(req->p);
+ if (error)
+ return (error);
+ error = SYSCTL_IN(req, addrs, sizeof(addrs));
+ if (error)
+ return (error);
+ s = splnet();
+ inp = in_pcblookup_hash(&tcbinfo, addrs[1].sin_addr, addrs[1].sin_port,
+ addrs[0].sin_addr, addrs[0].sin_port, 0);
+ if (inp == NULL || inp->inp_socket == NULL ||
+ inp->inp_socket->so_cred == NULL) {
+ error = ENOENT;
+ goto out;
+ }
+ error = SYSCTL_OUT(req, inp->inp_socket->so_cred->pc_ucred,
+ sizeof(struct ucred));
+out:
+ splx(s);
+ return (error);
+}
+
+SYSCTL_PROC(_net_inet_tcp, OID_AUTO, getcred, CTLTYPE_OPAQUE|CTLFLAG_RW,
+ 0, 0, tcp_getcred, "S,ucred", "Get the ucred of a TCP connection");
+
void
tcp_ctlinput(cmd, sa, vip)
int cmd;
diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c
index fac3405..52da6ab 100644
--- a/sys/netinet/udp_usrreq.c
+++ b/sys/netinet/udp_usrreq.c
@@ -31,7 +31,7 @@
* SUCH DAMAGE.
*
* @(#)udp_usrreq.c 8.6 (Berkeley) 5/23/95
- * $Id: udp_usrreq.c,v 1.51 1999/05/03 23:57:32 billf Exp $
+ * $Id: udp_usrreq.c,v 1.52 1999/06/19 18:43:33 green Exp $
*/
#include <sys/param.h>
@@ -39,6 +39,7 @@
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/mbuf.h>
+#include <sys/proc.h>
#include <sys/protosw.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
@@ -452,6 +453,37 @@ SYSCTL_PROC(_net_inet_udp, UDPCTL_PCBLIST, pcblist, CTLFLAG_RD, 0, 0,
udp_pcblist, "S,xinpcb", "List of active UDP sockets");
static int
+udp_getcred SYSCTL_HANDLER_ARGS
+{
+ struct sockaddr_in addrs[2];
+ struct inpcb *inp;
+ int error, s;
+
+ error = suser(req->p);
+ if (error)
+ return (error);
+ error = SYSCTL_IN(req, addrs, sizeof(addrs));
+ if (error)
+ return (error);
+ s = splnet();
+ inp = in_pcblookup_hash(&udbinfo, addrs[1].sin_addr, addrs[1].sin_port,
+ addrs[0].sin_addr, addrs[0].sin_port, 1);
+ if (inp == NULL || inp->inp_socket == NULL ||
+ inp->inp_socket->so_cred == NULL) {
+ error = ENOENT;
+ goto out;
+ }
+ error = SYSCTL_OUT(req, inp->inp_socket->so_cred->pc_ucred,
+ sizeof(struct ucred));
+out:
+ splx(s);
+ return (error);
+}
+
+SYSCTL_PROC(_net_inet_udp, OID_AUTO, getcred, CTLTYPE_OPAQUE|CTLFLAG_RW,
+ 0, 0, udp_getcred, "S,ucred", "Get the ucred of a UDP connection");
+
+static int
udp_output(inp, m, addr, control, p)
register struct inpcb *inp;
register struct mbuf *m;
OpenPOWER on IntegriCloud