Source-Changes-HG archive

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

[src/trunk]: src/sys/net ifioctl: don't use super user priviledge unless it's...



details:   https://anonhg.NetBSD.org/src/rev/12e3afce78aa
branches:  trunk
changeset: 572623:12e3afce78aa
user:      yamt <yamt%NetBSD.org@localhost>
date:      Sun Jan 09 12:18:46 2005 +0000

description:
ifioctl: don't use super user priviledge unless it's needed.

diffstat:

 sys/net/if.c |  63 ++++++++++++++++++++++++++++++++++-------------------------
 1 files changed, 36 insertions(+), 27 deletions(-)

diffs (147 lines):

diff -r 5c3a8f0fc9a1 -r 12e3afce78aa sys/net/if.c
--- a/sys/net/if.c      Sun Jan 09 12:15:36 2005 +0000
+++ b/sys/net/if.c      Sun Jan 09 12:18:46 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if.c,v 1.150 2004/12/04 23:03:33 peter Exp $   */
+/*     $NetBSD: if.c,v 1.151 2005/01/09 12:18:46 yamt Exp $    */
 
 /*-
  * Copyright (c) 1999, 2000, 2001 The NetBSD Foundation, Inc.
@@ -97,7 +97,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.150 2004/12/04 23:03:33 peter Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.151 2005/01/09 12:18:46 yamt Exp $");
 
 #include "opt_inet.h"
 
@@ -1346,12 +1346,6 @@
        struct ifdatareq *ifdr;
        int s, error = 0;
        short oif_flags;
-       int prived_error;
-
-       if (p)
-               prived_error = suser(p->p_ucred, &p->p_acflag);
-       else
-               prived_error = 0;
 
        switch (cmd) {
 
@@ -1366,8 +1360,11 @@
        switch (cmd) {
        case SIOCIFCREATE:
        case SIOCIFDESTROY:
-               if (prived_error)
-                       return (prived_error);
+               if (p) {
+                       error = suser(p->p_ucred, &p->p_acflag);
+                       if (error)
+                               return error;
+               }
                return ((cmd == SIOCIFCREATE) ?
                        if_clone_create(ifr->ifr_name) :
                        if_clone_destroy(ifr->ifr_name));
@@ -1379,6 +1376,35 @@
        ifp = ifunit(ifr->ifr_name);
        if (ifp == 0)
                return (ENXIO);
+
+       switch (cmd) {
+       case SIOCSIFFLAGS:
+       case SIOCSIFCAP:
+       case SIOCSIFMETRIC:
+       case SIOCZIFDATA:
+       case SIOCSIFMTU:
+       case SIOCSIFPHYADDR:
+       case SIOCDIFPHYADDR:
+#ifdef INET6
+       case SIOCSIFPHYADDR_IN6:
+#endif
+       case SIOCSLIFPHYADDR:
+       case SIOCADDMULTI:
+       case SIOCDELMULTI:
+       case SIOCSIFMEDIA:
+       case SIOCSDRVSPEC:  
+       case SIOCS80211NWID:
+       case SIOCS80211NWKEY:
+       case SIOCS80211POWER:
+       case SIOCS80211BSSID:
+       case SIOCS80211CHANNEL:
+               if (p) {
+                       error = suser(p->p_ucred, &p->p_acflag);
+                       if (error)
+                               return error;
+               }
+       }
+
        oif_flags = ifp->if_flags;
        switch (cmd) {
 
@@ -1399,8 +1425,6 @@
                break;
 
        case SIOCSIFFLAGS:
-               if (prived_error != 0)
-                       return (prived_error);
                if (ifp->if_flags & IFF_UP && (ifr->ifr_flags & IFF_UP) == 0) {
                        s = splnet();
                        if_down(ifp);
@@ -1423,8 +1447,6 @@
                break;
 
        case SIOCSIFCAP:
-               if (prived_error != 0)
-                       return (prived_error);
                if ((ifcr->ifcr_capenable & ~ifp->if_capabilities) != 0)
                        return (EINVAL);
                if (ifp->if_ioctl == NULL)
@@ -1481,8 +1503,6 @@
                break;
 
        case SIOCSIFMETRIC:
-               if (prived_error != 0)
-                       return (prived_error);
                ifp->if_metric = ifr->ifr_metric;
                break;
 
@@ -1491,8 +1511,6 @@
                break;
 
        case SIOCZIFDATA:
-               if (prived_error != 0)
-                       return (prived_error);
                ifdr->ifdr_data = ifp->if_data;
                /*
                 * Assumes that the volatile counters that can be
@@ -1506,8 +1524,6 @@
        {
                u_long oldmtu = ifp->if_mtu;
 
-               if (prived_error)
-                       return (prived_error);
                if (ifp->if_ioctl == NULL)
                        return (EOPNOTSUPP);
                error = (*ifp->if_ioctl)(ifp, cmd, data);
@@ -1531,9 +1547,6 @@
        case SIOCADDMULTI:
        case SIOCDELMULTI:
        case SIOCSIFMEDIA:
-               if (prived_error != 0)
-                       return (prived_error);
-               /* FALLTHROUGH */
        case SIOCGIFPSRCADDR:
        case SIOCGIFPDSTADDR:
        case SIOCGLIFPHYADDR:
@@ -1549,10 +1562,6 @@
        case SIOCS80211POWER:
        case SIOCS80211BSSID:
        case SIOCS80211CHANNEL:
-               /* XXX:  need to pass proc pointer through to driver... */
-               if (prived_error != 0)
-                       return (prived_error);
-       /* FALLTHROUGH */
        default:
                if (so->so_proto == 0)
                        return (EOPNOTSUPP);



Home | Main Index | Thread Index | Old Index