cd8c86f
diff -up dhcp-4.1.1/client/dhclient.8.capability dhcp-4.1.1/client/dhclient.8
cd8c86f
--- dhcp-4.1.1/client/dhclient.8.capability	2010-02-03 11:19:39.854958099 -0500
cd8c86f
+++ dhcp-4.1.1/client/dhclient.8	2010-02-03 11:44:57.949895909 -0500
d44b399
@@ -105,6 +105,9 @@ relay
d44b399
 .B -n
d44b399
 ]
d44b399
 [
d44b399
+.B -nc
d44b399
+]
d44b399
+[
d44b399
 .B -nw
d44b399
 ]
d44b399
 [
cd8c86f
@@ -381,6 +381,32 @@ Do not configure any interfaces.  Most u
cd8c86f
 option.
cd8c86f
 
cd8c86f
 .TP
cd8c86f
+.BI \-nc
cd8c86f
+Do not drop capabilities.
cd8c86f
+
cd8c86f
+Normally, if
cd8c86f
+.B dhclient
cd8c86f
+was compiled with libcap-ng support,
cd8c86f
+.B dhclient
cd8c86f
+drops most capabilities immediately upon startup.  While more secure,
cd8c86f
+this greatly restricts the additional actions that hooks in
cd8c86f
+.B dhclient-script (8)
cd8c86f
+can take.  (For example, any daemons that 
cd8c86f
+.B dhclient-script (8)
cd8c86f
+starts or restarts will inherit the restricted capabilities as well,
cd8c86f
+which may interfere with their correct operation.)  Thus, the
cd8c86f
+.BI \-nc
cd8c86f
+option can be used to prevent
cd8c86f
+.B dhclient
cd8c86f
+from dropping capabilities.
cd8c86f
+
cd8c86f
+The
cd8c86f
+.BI \-nc
cd8c86f
+option is ignored if
cd8c86f
+.B dhclient
cd8c86f
+was not compiled with libcap-ng support.
cd8c86f
+
cd8c86f
+.TP
cd8c86f
 .BI \-nw
cd8c86f
 Become a daemon process immediately (nowait) rather than waiting until an IP
cd8c86f
 address has been acquired.
9538db2
diff -up dhcp-4.1.1/client/dhclient.c.capability dhcp-4.1.1/client/dhclient.c
cd8c86f
--- dhcp-4.1.1/client/dhclient.c.capability	2010-02-03 11:19:39.876957973 -0500
cd8c86f
+++ dhcp-4.1.1/client/dhclient.c	2010-02-03 11:46:14.665957658 -0500
3b84ae4
@@ -37,6 +37,9 @@
3b84ae4
 #include <sys/time.h>
3b84ae4
 #include <sys/wait.h>
3b84ae4
 #include <limits.h>
3b84ae4
+#ifdef HAVE_LIBCAP_NG
3b84ae4
+#include <cap-ng.h>
3b84ae4
+#endif
3b84ae4
 
3b84ae4
 /*
3b84ae4
  * Defined in stdio.h when _GNU_SOURCE is set, but we don't want to define
7985996
@@ -89,6 +92,9 @@ int wanted_ia_ta = 0;
7985996
 int wanted_ia_pd = 0;
7985996
 char *mockup_relay = NULL;
7985996
 int bootp_broadcast_always = 0;
7985996
+#ifdef HAVE_LIBCAP_NG
7985996
+static int keep_capabilities = 0;
7985996
+#endif
7985996
 
7985996
 extern u_int32_t default_requested_options[];
7985996
 
7985996
@@ -376,6 +382,10 @@ main(int argc, char **argv) {
7985996
 			}
7985996
 
7985996
 			dhclient_request_options = argv[i];
7985996
+		} else if (!strcmp(argv[i], "-nc")) {
cd8c86f
+#ifdef HAVE_LIBCAP_NG
7985996
+			keep_capabilities = 1;
7985996
+#endif
7985996
 		} else if (argv[i][0] == '-') {
7985996
 		    usage();
7985996
 		} else if (interfaces_requested < 0) {
7985996
@@ -424,6 +434,19 @@ main(int argc, char **argv) {
3b84ae4
 		path_dhclient_script = s;
3b84ae4
 	}
3b84ae4
 
3b84ae4
+#ifdef HAVE_LIBCAP_NG
3b84ae4
+	/* Drop capabilities */
7985996
+	if (!keep_capabilities) {
7985996
+		capng_clear(CAPNG_SELECT_CAPS);
7985996
+		capng_update(CAPNG_ADD, CAPNG_EFFECTIVE|CAPNG_PERMITTED,
7985996
+				CAP_DAC_OVERRIDE); // Drop this someday
7985996
+		capng_updatev(CAPNG_ADD, CAPNG_EFFECTIVE|CAPNG_PERMITTED,
7985996
+				CAP_NET_ADMIN, CAP_NET_RAW,
7985996
+				CAP_NET_BIND_SERVICE, CAP_SYS_ADMIN, -1);
7985996
+		capng_apply(CAPNG_SELECT_CAPS);
7985996
+	}
3b84ae4
+#endif
3b84ae4
+
3b84ae4
 	/* Set up the initial dhcp option universe. */
3b84ae4
 	initialize_common_option_spaces();
3b84ae4
 
9538db2
diff -up dhcp-4.1.1/client/Makefile.am.capability dhcp-4.1.1/client/Makefile.am
cd8c86f
--- dhcp-4.1.1/client/Makefile.am.capability	2008-11-18 17:33:22.000000000 -0500
cd8c86f
+++ dhcp-4.1.1/client/Makefile.am	2010-02-03 11:19:39.895958083 -0500
3b84ae4
@@ -5,7 +5,7 @@ dhclient_SOURCES = clparse.c dhclient.c 
3b84ae4
 		   scripts/netbsd scripts/nextstep scripts/openbsd \
3b84ae4
 		   scripts/solaris scripts/openwrt
3b84ae4
 dhclient_LDADD = ../common/libdhcp.a ../minires/libres.a \
3b84ae4
-		 ../omapip/libomapi.a ../dst/libdst.a
3b84ae4
+		 ../omapip/libomapi.a ../dst/libdst.a $(CAPNG_LDADD)
3b84ae4
 man_MANS = dhclient.8 dhclient-script.8 dhclient.conf.5 dhclient.leases.5
3b84ae4
 EXTRA_DIST = $(man_MANS)
3b84ae4
 
9538db2
diff -up dhcp-4.1.1/configure.ac.capability dhcp-4.1.1/configure.ac
cd8c86f
--- dhcp-4.1.1/configure.ac.capability	2010-02-03 11:19:39.806895971 -0500
cd8c86f
+++ dhcp-4.1.1/configure.ac	2010-02-03 11:19:39.895958083 -0500
7985996
@@ -419,6 +419,41 @@ AC_TRY_LINK(
3b84ae4
 # Look for optional headers.
3b84ae4
 AC_CHECK_HEADERS(sys/socket.h net/if_dl.h net/if6.h regex.h)
3b84ae4
 
3b84ae4
+# look for capabilities library
7985996
+AC_ARG_WITH(libcap-ng,
7985996
+    [  --with-libcap-ng=[auto/yes/no]  Add Libcap-ng support [default=auto]],,
7985996
+    with_libcap_ng=auto)
7985996
+
7985996
+# Check for Libcap-ng API
7985996
+#
7985996
+# libcap-ng detection
7985996
+if test x$with_libcap_ng = xno ; then
7985996
+    have_libcap_ng=no;
7985996
+else
7985996
+    # Start by checking for header file
7985996
+    AC_CHECK_HEADER(cap-ng.h, capng_headers=yes, capng_headers=no)
7985996
+
7985996
+    # See if we have libcap-ng library
7985996
+    AC_CHECK_LIB(cap-ng, capng_clear,
7985996
+                 CAPNG_LDADD=-lcap-ng,)
7985996
+
7985996
+    # Check results are usable
7985996
+    if test x$with_libcap_ng = xyes -a x$CAPNG_LDADD = x ; then
7985996
+       AC_MSG_ERROR(libcap-ng support was requested and the library was not found)
7985996
+    fi
7985996
+    if test x$CAPNG_LDADD != x -a $capng_headers = no ; then
7985996
+       AC_MSG_ERROR(libcap-ng libraries found but headers are missing)
7985996
+    fi
7985996
+fi
7985996
+AC_SUBST(CAPNG_LDADD)
7985996
+AC_MSG_CHECKING(whether to use libcap-ng)
7985996
+if test x$CAPNG_LDADD != x ; then
7985996
+    AC_DEFINE(HAVE_LIBCAP_NG,1,[libcap-ng support])
7985996
+    AC_MSG_RESULT(yes)
7985996
+else
7985996
+    AC_MSG_RESULT(no)
7985996
+fi
3b84ae4
+
3b84ae4
 # find an MD5 library
3b84ae4
 AC_SEARCH_LIBS(MD5_Init, [crypto])
3b84ae4
 AC_SEARCH_LIBS(MD5Init, [crypto])