|
|
fad460 |
diff -up dhcp-4.2.2b1/client/dhclient.8.capability dhcp-4.2.2b1/client/dhclient.8
|
|
|
fad460 |
--- dhcp-4.2.2b1/client/dhclient.8.capability 2011-07-01 15:09:06.603784531 +0200
|
|
|
fad460 |
+++ dhcp-4.2.2b1/client/dhclient.8 2011-07-01 15:09:06.663783913 +0200
|
|
|
fad460 |
@@ -118,6 +118,9 @@ dhclient - Dynamic Host Configuration Pr
|
|
|
fad460 |
.B -w
|
|
|
fad460 |
]
|
|
|
fad460 |
[
|
|
|
fad460 |
+.B -nc
|
|
|
fad460 |
+]
|
|
|
fad460 |
+[
|
|
|
fad460 |
.B -B
|
|
|
fad460 |
]
|
|
|
fad460 |
[
|
|
|
fad460 |
@@ -296,6 +299,32 @@ has been added or removed, so that the c
|
|
|
fad460 |
address on that interface.
|
|
|
fad460 |
|
|
|
fad460 |
.TP
|
|
|
fad460 |
+.BI \-nc
|
|
|
fad460 |
+Do not drop capabilities.
|
|
|
fad460 |
+
|
|
|
fad460 |
+Normally, if
|
|
|
fad460 |
+.B dhclient
|
|
|
fad460 |
+was compiled with libcap-ng support,
|
|
|
fad460 |
+.B dhclient
|
|
|
fad460 |
+drops most capabilities immediately upon startup. While more secure,
|
|
|
fad460 |
+this greatly restricts the additional actions that hooks in
|
|
|
fad460 |
+.B dhclient-script (8)
|
|
|
fad460 |
+can take. (For example, any daemons that
|
|
|
fad460 |
+.B dhclient-script (8)
|
|
|
fad460 |
+starts or restarts will inherit the restricted capabilities as well,
|
|
|
fad460 |
+which may interfere with their correct operation.) Thus, the
|
|
|
fad460 |
+.BI \-nc
|
|
|
fad460 |
+option can be used to prevent
|
|
|
fad460 |
+.B dhclient
|
|
|
fad460 |
+from dropping capabilities.
|
|
|
fad460 |
+
|
|
|
fad460 |
+The
|
|
|
fad460 |
+.BI \-nc
|
|
|
fad460 |
+option is ignored if
|
|
|
fad460 |
+.B dhclient
|
|
|
fad460 |
+was not compiled with libcap-ng support.
|
|
|
fad460 |
+
|
|
|
fad460 |
+.TP
|
|
|
fad460 |
.BI \-B
|
|
|
fad460 |
Set the BOOTP broadcast flag in request packets so servers will always
|
|
|
fad460 |
broadcast replies.
|
|
|
fad460 |
diff -up dhcp-4.2.2b1/client/dhclient.c.capability dhcp-4.2.2b1/client/dhclient.c
|
|
|
fad460 |
--- dhcp-4.2.2b1/client/dhclient.c.capability 2011-07-01 15:09:06.644784107 +0200
|
|
|
fad460 |
+++ dhcp-4.2.2b1/client/dhclient.c 2011-07-01 15:09:06.664783903 +0200
|
|
|
fad460 |
@@ -39,6 +39,10 @@
|
|
|
fad460 |
#include <limits.h>
|
|
|
fad460 |
#include <dns/result.h>
|
|
|
fad460 |
|
|
|
fad460 |
+#ifdef HAVE_LIBCAP_NG
|
|
|
fad460 |
+#include <cap-ng.h>
|
|
|
fad460 |
+#endif
|
|
|
fad460 |
+
|
|
|
fad460 |
/*
|
|
|
fad460 |
* Defined in stdio.h when _GNU_SOURCE is set, but we don't want to define
|
|
|
fad460 |
* that when building ISC code.
|
|
|
fad460 |
@@ -141,6 +145,9 @@ main(int argc, char **argv) {
|
|
|
fad460 |
int timeout_arg = 0;
|
|
|
fad460 |
char *arg_conf = NULL;
|
|
|
fad460 |
int arg_conf_len = 0;
|
|
|
fad460 |
+#ifdef HAVE_LIBCAP_NG
|
|
|
fad460 |
+ int keep_capabilities = 0;
|
|
|
fad460 |
+#endif
|
|
|
fad460 |
|
|
|
fad460 |
/* Initialize client globals. */
|
|
|
fad460 |
memset(&default_duid, 0, sizeof(default_duid));
|
|
|
fad460 |
@@ -410,6 +417,10 @@ main(int argc, char **argv) {
|
|
|
fad460 |
}
|
|
|
fad460 |
|
|
|
fad460 |
dhclient_request_options = argv[i];
|
|
|
fad460 |
+ } else if (!strcmp(argv[i], "-nc")) {
|
|
|
fad460 |
+#ifdef HAVE_LIBCAP_NG
|
|
|
fad460 |
+ keep_capabilities = 1;
|
|
|
fad460 |
+#endif
|
|
|
fad460 |
} else if (argv[i][0] == '-') {
|
|
|
fad460 |
usage();
|
|
|
fad460 |
} else if (interfaces_requested < 0) {
|
|
|
fad460 |
@@ -458,6 +469,19 @@ main(int argc, char **argv) {
|
|
|
fad460 |
path_dhclient_script = s;
|
|
|
fad460 |
}
|
|
|
fad460 |
|
|
|
fad460 |
+#ifdef HAVE_LIBCAP_NG
|
|
|
fad460 |
+ /* Drop capabilities */
|
|
|
fad460 |
+ if (!keep_capabilities) {
|
|
|
fad460 |
+ capng_clear(CAPNG_SELECT_CAPS);
|
|
|
fad460 |
+ capng_update(CAPNG_ADD, CAPNG_EFFECTIVE|CAPNG_PERMITTED,
|
|
|
fad460 |
+ CAP_DAC_OVERRIDE); // Drop this someday
|
|
|
fad460 |
+ capng_updatev(CAPNG_ADD, CAPNG_EFFECTIVE|CAPNG_PERMITTED,
|
|
|
fad460 |
+ CAP_NET_ADMIN, CAP_NET_RAW,
|
|
|
fad460 |
+ CAP_NET_BIND_SERVICE, CAP_SYS_ADMIN, -1);
|
|
|
fad460 |
+ capng_apply(CAPNG_SELECT_CAPS);
|
|
|
fad460 |
+ }
|
|
|
fad460 |
+#endif
|
|
|
fad460 |
+
|
|
|
fad460 |
/* Set up the initial dhcp option universe. */
|
|
|
fad460 |
initialize_common_option_spaces();
|
|
|
fad460 |
|
|
|
fad460 |
diff -up dhcp-4.2.2b1/client/dhclient-script.8.capability dhcp-4.2.2b1/client/dhclient-script.8
|
|
|
fad460 |
--- dhcp-4.2.2b1/client/dhclient-script.8.capability 2011-07-01 15:09:06.604784521 +0200
|
|
|
fad460 |
+++ dhcp-4.2.2b1/client/dhclient-script.8 2011-07-01 15:09:06.666783883 +0200
|
|
|
fad460 |
@@ -239,6 +239,16 @@ repeatedly initialized to the values pro
|
|
|
fad460 |
the other. Assuming the information provided by both servers is
|
|
|
fad460 |
valid, this shouldn't cause any real problems, but it could be
|
|
|
fad460 |
confusing.
|
|
|
fad460 |
+.PP
|
|
|
fad460 |
+Normally, if dhclient was compiled with libcap-ng support,
|
|
|
fad460 |
+dhclient drops most capabilities immediately upon startup.
|
|
|
fad460 |
+While more secure, this greatly restricts the additional actions that
|
|
|
fad460 |
+hooks in dhclient-script can take. For example, any daemons that
|
|
|
fad460 |
+dhclient-script starts or restarts will inherit the restricted
|
|
|
fad460 |
+capabilities as well, which may interfere with their correct operation.
|
|
|
fad460 |
+Thus, the
|
|
|
fad460 |
+.BI \-nc
|
|
|
fad460 |
+option can be used to prevent dhclient from dropping capabilities.
|
|
|
fad460 |
.SH SEE ALSO
|
|
|
fad460 |
dhclient(8), dhcpd(8), dhcrelay(8), dhclient.conf(5) and
|
|
|
fad460 |
dhclient.leases(5).
|
|
|
fad460 |
diff -up dhcp-4.2.2b1/client/Makefile.am.capability dhcp-4.2.2b1/client/Makefile.am
|
|
|
fad460 |
--- dhcp-4.2.2b1/client/Makefile.am.capability 2011-07-01 15:09:06.526785327 +0200
|
|
|
fad460 |
+++ dhcp-4.2.2b1/client/Makefile.am 2011-07-01 15:09:06.667783873 +0200
|
|
|
fad460 |
@@ -5,7 +5,7 @@ dhclient_SOURCES = clparse.c dhclient.c
|
|
|
fad460 |
scripts/netbsd scripts/nextstep scripts/openbsd \
|
|
|
fad460 |
scripts/solaris scripts/openwrt
|
|
|
fad460 |
dhclient_LDADD = ../common/libdhcp.a ../omapip/libomapi.a \
|
|
|
fad460 |
- $(BIND9_LIBDIR) -ldns-export -lisc-export
|
|
|
fad460 |
+ $(BIND9_LIBDIR) -ldns-export -lisc-export $(CAPNG_LDADD)
|
|
|
fad460 |
man_MANS = dhclient.8 dhclient-script.8 dhclient.conf.5 dhclient.leases.5
|
|
|
fad460 |
EXTRA_DIST = $(man_MANS)
|
|
|
fad460 |
|
|
|
fad460 |
diff -up dhcp-4.2.2b1/configure.ac.capability dhcp-4.2.2b1/configure.ac
|
|
|
fad460 |
--- dhcp-4.2.2b1/configure.ac.capability 2011-07-01 15:09:06.527785317 +0200
|
|
|
fad460 |
+++ dhcp-4.2.2b1/configure.ac 2011-07-01 15:09:06.667783873 +0200
|
|
|
fad460 |
@@ -449,6 +449,41 @@ AC_TRY_LINK(
|
|
|
fad460 |
# Look for optional headers.
|
|
|
fad460 |
AC_CHECK_HEADERS(sys/socket.h net/if_dl.h net/if6.h regex.h)
|
|
|
fad460 |
|
|
|
fad460 |
+# look for capabilities library
|
|
|
fad460 |
+AC_ARG_WITH(libcap-ng,
|
|
|
fad460 |
+ [ --with-libcap-ng=[auto/yes/no] Add Libcap-ng support [default=auto]],,
|
|
|
fad460 |
+ with_libcap_ng=auto)
|
|
|
fad460 |
+
|
|
|
fad460 |
+# Check for Libcap-ng API
|
|
|
fad460 |
+#
|
|
|
fad460 |
+# libcap-ng detection
|
|
|
fad460 |
+if test x$with_libcap_ng = xno ; then
|
|
|
fad460 |
+ have_libcap_ng=no;
|
|
|
fad460 |
+else
|
|
|
fad460 |
+ # Start by checking for header file
|
|
|
fad460 |
+ AC_CHECK_HEADER(cap-ng.h, capng_headers=yes, capng_headers=no)
|
|
|
fad460 |
+
|
|
|
fad460 |
+ # See if we have libcap-ng library
|
|
|
fad460 |
+ AC_CHECK_LIB(cap-ng, capng_clear,
|
|
|
fad460 |
+ CAPNG_LDADD=-lcap-ng,)
|
|
|
fad460 |
+
|
|
|
fad460 |
+ # Check results are usable
|
|
|
fad460 |
+ if test x$with_libcap_ng = xyes -a x$CAPNG_LDADD = x ; then
|
|
|
fad460 |
+ AC_MSG_ERROR(libcap-ng support was requested and the library was not found)
|
|
|
fad460 |
+ fi
|
|
|
fad460 |
+ if test x$CAPNG_LDADD != x -a $capng_headers = no ; then
|
|
|
fad460 |
+ AC_MSG_ERROR(libcap-ng libraries found but headers are missing)
|
|
|
fad460 |
+ fi
|
|
|
fad460 |
+fi
|
|
|
fad460 |
+AC_SUBST(CAPNG_LDADD)
|
|
|
fad460 |
+AC_MSG_CHECKING(whether to use libcap-ng)
|
|
|
fad460 |
+if test x$CAPNG_LDADD != x ; then
|
|
|
fad460 |
+ AC_DEFINE(HAVE_LIBCAP_NG,1,[libcap-ng support])
|
|
|
fad460 |
+ AC_MSG_RESULT(yes)
|
|
|
fad460 |
+else
|
|
|
fad460 |
+ AC_MSG_RESULT(no)
|
|
|
fad460 |
+fi
|
|
|
fad460 |
+
|
|
|
fad460 |
# Solaris needs some libraries for functions
|
|
|
fad460 |
AC_SEARCH_LIBS(socket, [socket])
|
|
|
fad460 |
AC_SEARCH_LIBS(inet_ntoa, [nsl])
|
|
|
fad460 |
diff -up dhcp-4.2.2b1/relay/dhcrelay.c.capability dhcp-4.2.2b1/relay/dhcrelay.c
|
|
|
fad460 |
--- dhcp-4.2.2b1/relay/dhcrelay.c.capability 2011-07-01 15:09:06.626784295 +0200
|
|
|
fad460 |
+++ dhcp-4.2.2b1/relay/dhcrelay.c 2011-07-01 15:12:05.362223794 +0200
|
|
|
fad460 |
@@ -36,6 +36,11 @@
|
|
|
fad460 |
#include <syslog.h>
|
|
|
fad460 |
#include <sys/time.h>
|
|
|
fad460 |
|
|
|
fad460 |
+#ifdef HAVE_LIBCAP_NG
|
|
|
fad460 |
+# include <cap-ng.h>
|
|
|
fad460 |
+ int keep_capabilities = 0;
|
|
|
fad460 |
+#endif
|
|
|
fad460 |
+
|
|
|
fad460 |
TIME default_lease_time = 43200; /* 12 hours... */
|
|
|
fad460 |
TIME max_lease_time = 86400; /* 24 hours... */
|
|
|
fad460 |
struct tree_cache *global_options[256];
|
|
|
fad460 |
@@ -356,6 +361,10 @@ main(int argc, char **argv) {
|
|
|
fad460 |
sl->next = upstreams;
|
|
|
fad460 |
upstreams = sl;
|
|
|
fad460 |
#endif
|
|
|
fad460 |
+ } else if (!strcmp(argv[i], "-nc")) {
|
|
|
fad460 |
+#ifdef HAVE_LIBCAP_NG
|
|
|
fad460 |
+ keep_capabilities = 1;
|
|
|
fad460 |
+#endif
|
|
|
fad460 |
} else if (!strcmp(argv[i], "-pf")) {
|
|
|
fad460 |
if (++i == argc)
|
|
|
fad460 |
usage();
|
|
|
fad460 |
@@ -426,6 +435,17 @@ main(int argc, char **argv) {
|
|
|
fad460 |
#endif
|
|
|
fad460 |
}
|
|
|
fad460 |
|
|
|
fad460 |
+#ifdef HAVE_LIBCAP_NG
|
|
|
fad460 |
+ /* Drop capabilities */
|
|
|
fad460 |
+ if (!keep_capabilities) {
|
|
|
fad460 |
+ capng_clear(CAPNG_SELECT_BOTH);
|
|
|
fad460 |
+ capng_updatev(CAPNG_ADD, CAPNG_EFFECTIVE|CAPNG_PERMITTED,
|
|
|
fad460 |
+ CAP_NET_RAW, CAP_NET_BIND_SERVICE, -1);
|
|
|
fad460 |
+ capng_apply(CAPNG_SELECT_BOTH);
|
|
|
fad460 |
+ log_info ("Dropped all unnecessary capabilities.");
|
|
|
fad460 |
+ }
|
|
|
fad460 |
+#endif
|
|
|
fad460 |
+
|
|
|
fad460 |
if (!quiet) {
|
|
|
fad460 |
log_info("%s %s", message, PACKAGE_VERSION);
|
|
|
fad460 |
log_info(copyright);
|
|
|
fad460 |
@@ -573,6 +593,15 @@ main(int argc, char **argv) {
|
|
|
fad460 |
dhcpv6_packet_handler = do_packet6;
|
|
|
fad460 |
#endif
|
|
|
fad460 |
|
|
|
fad460 |
+#ifdef HAVE_LIBCAP_NG
|
|
|
fad460 |
+ /* Drop all capabilities */
|
|
|
fad460 |
+ if (!keep_capabilities) {
|
|
|
fad460 |
+ capng_clear(CAPNG_SELECT_BOTH);
|
|
|
fad460 |
+ capng_apply(CAPNG_SELECT_BOTH);
|
|
|
fad460 |
+ log_info ("Dropped all capabilities.");
|
|
|
fad460 |
+ }
|
|
|
fad460 |
+#endif
|
|
|
fad460 |
+
|
|
|
fad460 |
/* Start dispatching packets and timeouts... */
|
|
|
fad460 |
dispatch();
|
|
|
fad460 |
|
|
|
fad460 |
diff -up dhcp-4.2.2b1/relay/Makefile.am.capability dhcp-4.2.2b1/relay/Makefile.am
|
|
|
fad460 |
--- dhcp-4.2.2b1/relay/Makefile.am.capability 2011-07-01 15:09:06.546785121 +0200
|
|
|
fad460 |
+++ dhcp-4.2.2b1/relay/Makefile.am 2011-07-01 15:09:06.670783841 +0200
|
|
|
fad460 |
@@ -3,7 +3,7 @@ AM_CPPFLAGS = -DLOCALSTATEDIR='"@localst
|
|
|
fad460 |
sbin_PROGRAMS = dhcrelay
|
|
|
fad460 |
dhcrelay_SOURCES = dhcrelay.c
|
|
|
fad460 |
dhcrelay_LDADD = ../common/libdhcp.a ../omapip/libomapi.a \
|
|
|
fad460 |
- $(BIND9_LIBDIR) -ldns-export -lisc-export
|
|
|
fad460 |
+ $(BIND9_LIBDIR) -ldns-export -lisc-export $(CAPNG_LDADD)
|
|
|
fad460 |
man_MANS = dhcrelay.8
|
|
|
fad460 |
EXTRA_DIST = $(man_MANS)
|
|
|
fad460 |
|