File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -78,6 +78,9 @@ PLUGIN=y
7878# Enable EAP SRP-SHA1 authentication (requires libsrp)
7979#USE_SRP=y
8080
81+ # Use libcap (requires libcap)
82+ USE_LIBCAP=n
83+
8184# Use libutil
8285USE_LIBUTIL=y
8386
@@ -127,7 +130,12 @@ endif
127130
128131ifneq ($(wildcard $(shell $(CC) --print-sysroot)/usr/include/crypt.h),)
129132CFLAGS += -DHAVE_CRYPT_H=1
130- LIBS += -lcrypt
133+ LIBS += -lcrypt
134+ endif
135+
136+ ifdef USE_LIBCAP
137+ CFLAGS += -DUSE_CAP
138+ LIBS += -lcap
131139endif
132140
133141ifdef USE_LIBUTIL
Original file line number Diff line number Diff line change @@ -370,11 +370,10 @@ main(argc, argv)
370370 setlogmask (LOG_UPTO (LOG_DEBUG ));
371371
372372 /*
373- * Check that we are running as root .
373+ * Check that we are capable to admin the network .
374374 */
375- if (geteuid () != 0 ) {
376- option_error ("must be root to run %s, since it is not setuid-root" ,
377- argv [0 ]);
375+ if (!net_capable ()) {
376+ option_error ("must be net capable to run the %s" , argv [0 ]);
378377 exit (EXIT_NOT_ROOT );
379378 }
380379
Original file line number Diff line number Diff line change @@ -623,6 +623,7 @@ void sys_init __P((void)); /* Do system-dependent initialization */
623623void sys_cleanup __P ((void )); /* Restore system state before exiting */
624624int sys_check_options __P ((void )); /* Check options specified */
625625void sys_close __P ((void )); /* Clean up in a child before execing */
626+ int net_capable __P ((void )); /* Test for any access to the net management */
626627int ppp_available __P ((void )); /* Test whether ppp kernel support exists */
627628int get_pty __P ((int * , int * , char * , int ) ); /* Get pty master/slave */
628629int open_ppp_loopback __P ((void )); /* Open loopback for demand-dialling */
Original file line number Diff line number Diff line change 144144#include <sys/locks.h>
145145#endif
146146
147+ #ifdef USE_CAP
148+ #include <sys/types.h>
149+ #include <sys/capability.h>
150+ #endif /* USE_CAP */
151+
147152#ifdef INET6
148153#ifndef _LINUX_IN6_H
149154/*
@@ -2242,6 +2247,42 @@ ppp_registered(void)
22422247 return ret ;
22432248}
22442249
2250+ /***********************************************************
2251+ *
2252+ * net_capable - check for any access to the net management
2253+ */
2254+
2255+ int net_capable (void )
2256+ {
2257+ int ok = 0 ;
2258+ #ifdef USE_CAP
2259+ /*
2260+ * Check that we are capable to admin the network.
2261+ */
2262+ cap_t cap ;
2263+ cap_flag_value_t cap_flag_value ;
2264+ cap = cap_get_pid (getpid ());
2265+ if (cap != 0 ) {
2266+ if (cap_get_flag (cap , CAP_NET_RAW , CAP_EFFECTIVE , & cap_flag_value ) == 0 ) {
2267+ if (cap_flag_value == CAP_SET )
2268+ ok = 1 ;
2269+ }
2270+ if (cap_get_flag (cap , CAP_NET_RAW , CAP_PERMITTED , & cap_flag_value ) == 0 ) {
2271+ if (cap_flag_value == CAP_SET )
2272+ ok = 1 ;
2273+ }
2274+ }
2275+ #else /* USE_CAP */
2276+ /*
2277+ * Check that we are running as root.
2278+ */
2279+ if (geteuid () == 0 ) {
2280+ ok = 1 ;
2281+ }
2282+ #endif /* USE_CAP */
2283+ return ok ;
2284+ }
2285+
22452286/********************************************************************
22462287 *
22472288 * ppp_available - check whether the system has any ppp interfaces
You can’t perform that action at this time.
0 commit comments