Source-Changes-HG archive

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

[src/trunk]: src/sys/netinet abuse the mib instead of abusing the new pointer...



details:   https://anonhg.NetBSD.org/src/rev/05ab17bda48a
branches:  trunk
changeset: 548418:05ab17bda48a
user:      christos <christos%NetBSD.org@localhost>
date:      Thu Jun 26 17:32:22 2003 +0000

description:
abuse the mib instead of abusing the new pointer. Idea from simon burge.
It allows the tcp_sysctl_ident to run by non-super-users. No backwards
compatibility provided.

diffstat:

 sys/netinet/tcp_usrreq.c |  40 +++++++++++++++++++++-------------------
 sys/netinet/tcp_var.h    |   9 +--------
 2 files changed, 22 insertions(+), 27 deletions(-)

diffs (112 lines):

diff -r 8ace9b0d430c -r 05ab17bda48a sys/netinet/tcp_usrreq.c
--- a/sys/netinet/tcp_usrreq.c  Thu Jun 26 17:31:12 2003 +0000
+++ b/sys/netinet/tcp_usrreq.c  Thu Jun 26 17:32:22 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tcp_usrreq.c,v 1.77 2003/06/23 11:02:16 martin Exp $   */
+/*     $NetBSD: tcp_usrreq.c,v 1.78 2003/06/26 17:32:22 christos Exp $ */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -102,7 +102,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tcp_usrreq.c,v 1.77 2003/06/23 11:02:16 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_usrreq.c,v 1.78 2003/06/26 17:32:22 christos Exp $");
 
 #include "opt_inet.h"
 #include "opt_ipsec.h"
@@ -161,7 +161,7 @@
  */
 extern char *tcpstates[];
 
-static int tcp_sysctl_ident(void *, size_t *, void *, size_t);
+static int tcp_sysctl_ident(int *, u_int, void *, size_t *, void *, size_t);
 
 /*
  * Process a TCP user request for TCP tb.  If this is a send request
@@ -946,13 +946,14 @@
 {
        int error, saved_value = 0;
 
+       if (name[0] == TCPCTL_IDENT)
+               return tcp_sysctl_ident(&name[1], namelen - 1, oldp, oldlenp,
+                   newp, newlen);
+
        /* All sysctl names at this level are terminal. */
        if (namelen != 1)
                return (ENOTDIR);
 
-       if (name[0] == TCPCTL_IDENT)
-               return tcp_sysctl_ident(oldp, oldlenp, newp, newlen);
-
        if (name[0] < sizeof(tcp_ctlvars)/sizeof(tcp_ctlvars[0])
            && tcp_ctlvars[name[0]].valid) {
                if (tcp_ctlvars[name[0]].rdonly) {
@@ -985,29 +986,30 @@
 
 
 static int 
-tcp_sysctl_ident(void *oldp, size_t *oldlenp, void *newp, size_t newlen)
+tcp_sysctl_ident(int *name, u_int namelen, void *oldp, size_t *oldlenp,
+    void *newp, size_t newlen)
 {
-       struct sysctl_tcp_ident_args args;
-       struct socket *sockp;
        struct inpcb *inb;
+       struct in_addr laddr, raddr;
+       u_int lport, rport;
        uid_t uid;
        int error;
 
-       if (newlen != sizeof(args))
-               return EINVAL;
-       if (!newp)
-               return EFAULT;
        if (*oldlenp != sizeof(uid_t))
                return ENOMEM;
        if (!oldp || *oldlenp != sizeof(uid_t))
                return ENOMEM;
-       if ((error = copyin(newp, &args, newlen)) != 0)
-               return error;
-       
-       inb = in_pcblookup_connect(&tcbtable, args.raddr, args.rport,
-           args.laddr, args.lport);
+       if (namelen != 4)
+               return EINVAL;
+
+       raddr.s_addr = (uint32_t)name[0];
+       rport = (u_int)name[1];
+       laddr.s_addr = (uint32_t)name[2];
+       lport = (u_int)name[3];
+
+       inb = in_pcblookup_connect(&tcbtable, raddr, rport, laddr, lport);
        if (inb) {
-               sockp = inb->inp_socket;
+               struct socket *sockp = inb->inp_socket;
                if (sockp)
                        uid = sockp->so_uid;
                else
diff -r 8ace9b0d430c -r 05ab17bda48a sys/netinet/tcp_var.h
--- a/sys/netinet/tcp_var.h     Thu Jun 26 17:31:12 2003 +0000
+++ b/sys/netinet/tcp_var.h     Thu Jun 26 17:32:22 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tcp_var.h,v 1.98 2003/06/23 11:02:16 martin Exp $      */
+/*     $NetBSD: tcp_var.h,v 1.99 2003/06/26 17:32:23 christos Exp $    */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -626,13 +626,6 @@
        { "ident", CTLTYPE_STRUCT }, \
 }
 
-struct sysctl_tcp_ident_args {
-       struct in_addr raddr;
-       u_int rport;
-       struct in_addr laddr;
-       u_int lport;
-};
-
 #ifdef _KERNEL
 extern struct inpcbtable tcbtable;     /* head of queue of active tcpcb's */
 #ifdef INET6



Home | Main Index | Thread Index | Old Index