2016-05-02 13:17:32 +00:00
|
|
|
diff -up dhcp-4.3.4/client/dhclient.8.capability dhcp-4.3.4/client/dhclient.8
|
|
|
|
--- dhcp-4.3.4/client/dhclient.8.capability 2016-04-29 12:19:40.657129322 +0200
|
|
|
|
+++ dhcp-4.3.4/client/dhclient.8 2016-04-29 12:19:40.715129297 +0200
|
|
|
|
@@ -134,6 +134,9 @@ dhclient - Dynamic Host Configuration Pr
|
2011-07-01 13:20:42 +00:00
|
|
|
.B -w
|
|
|
|
]
|
|
|
|
[
|
|
|
|
+.B -nc
|
|
|
|
+]
|
|
|
|
+[
|
|
|
|
.B -B
|
|
|
|
]
|
|
|
|
[
|
2016-05-02 13:17:32 +00:00
|
|
|
@@ -318,6 +321,32 @@ has been added or removed, so that the c
|
2011-07-01 13:20:42 +00:00
|
|
|
address on that interface.
|
|
|
|
|
|
|
|
.TP
|
|
|
|
+.BI \-nc
|
|
|
|
+Do not drop capabilities.
|
|
|
|
+
|
|
|
|
+Normally, if
|
|
|
|
+.B dhclient
|
|
|
|
+was compiled with libcap-ng support,
|
|
|
|
+.B dhclient
|
|
|
|
+drops most capabilities immediately upon startup. While more secure,
|
|
|
|
+this greatly restricts the additional actions that hooks in
|
|
|
|
+.B dhclient-script (8)
|
|
|
|
+can take. (For example, any daemons that
|
|
|
|
+.B dhclient-script (8)
|
|
|
|
+starts or restarts will inherit the restricted capabilities as well,
|
|
|
|
+which may interfere with their correct operation.) Thus, the
|
|
|
|
+.BI \-nc
|
|
|
|
+option can be used to prevent
|
|
|
|
+.B dhclient
|
|
|
|
+from dropping capabilities.
|
|
|
|
+
|
|
|
|
+The
|
|
|
|
+.BI \-nc
|
|
|
|
+option is ignored if
|
|
|
|
+.B dhclient
|
|
|
|
+was not compiled with libcap-ng support.
|
|
|
|
+
|
|
|
|
+.TP
|
|
|
|
.BI \-B
|
|
|
|
Set the BOOTP broadcast flag in request packets so servers will always
|
|
|
|
broadcast replies.
|
2016-05-02 13:17:32 +00:00
|
|
|
diff -up dhcp-4.3.4/client/dhclient.c.capability dhcp-4.3.4/client/dhclient.c
|
|
|
|
--- dhcp-4.3.4/client/dhclient.c.capability 2016-04-29 12:19:40.691129307 +0200
|
|
|
|
+++ dhcp-4.3.4/client/dhclient.c 2016-04-29 12:21:07.620091930 +0200
|
|
|
|
@@ -40,6 +40,10 @@
|
|
|
|
#include <isc/file.h>
|
2011-07-01 13:20:42 +00:00
|
|
|
#include <dns/result.h>
|
|
|
|
|
|
|
|
+#ifdef HAVE_LIBCAP_NG
|
|
|
|
+#include <cap-ng.h>
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
/*
|
|
|
|
* Defined in stdio.h when _GNU_SOURCE is set, but we don't want to define
|
|
|
|
* that when building ISC code.
|
2016-05-02 13:17:32 +00:00
|
|
|
@@ -237,6 +241,9 @@ main(int argc, char **argv) {
|
2011-07-01 13:20:42 +00:00
|
|
|
int timeout_arg = 0;
|
|
|
|
char *arg_conf = NULL;
|
|
|
|
int arg_conf_len = 0;
|
|
|
|
+#ifdef HAVE_LIBCAP_NG
|
|
|
|
+ int keep_capabilities = 0;
|
|
|
|
+#endif
|
|
|
|
|
|
|
|
/* Initialize client globals. */
|
|
|
|
memset(&default_duid, 0, sizeof(default_duid));
|
2016-05-02 13:17:32 +00:00
|
|
|
@@ -537,6 +544,10 @@ main(int argc, char **argv) {
|
2011-07-01 13:20:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dhclient_request_options = argv[i];
|
|
|
|
+ } else if (!strcmp(argv[i], "-nc")) {
|
|
|
|
+#ifdef HAVE_LIBCAP_NG
|
|
|
|
+ keep_capabilities = 1;
|
|
|
|
+#endif
|
|
|
|
} else if (argv[i][0] == '-') {
|
2016-05-02 13:17:32 +00:00
|
|
|
usage("Unknown command: %s", argv[i]);
|
2011-07-01 13:20:42 +00:00
|
|
|
} else if (interfaces_requested < 0) {
|
2016-05-02 13:17:32 +00:00
|
|
|
@@ -597,6 +608,19 @@ main(int argc, char **argv) {
|
2011-07-01 13:20:42 +00:00
|
|
|
path_dhclient_script = s;
|
|
|
|
}
|
|
|
|
|
|
|
|
+#ifdef HAVE_LIBCAP_NG
|
|
|
|
+ /* Drop capabilities */
|
|
|
|
+ if (!keep_capabilities) {
|
|
|
|
+ capng_clear(CAPNG_SELECT_CAPS);
|
|
|
|
+ capng_update(CAPNG_ADD, CAPNG_EFFECTIVE|CAPNG_PERMITTED,
|
|
|
|
+ CAP_DAC_OVERRIDE); // Drop this someday
|
|
|
|
+ capng_updatev(CAPNG_ADD, CAPNG_EFFECTIVE|CAPNG_PERMITTED,
|
|
|
|
+ CAP_NET_ADMIN, CAP_NET_RAW,
|
|
|
|
+ CAP_NET_BIND_SERVICE, CAP_SYS_ADMIN, -1);
|
|
|
|
+ capng_apply(CAPNG_SELECT_CAPS);
|
|
|
|
+ }
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
/* Set up the initial dhcp option universe. */
|
|
|
|
initialize_common_option_spaces();
|
|
|
|
|
2016-05-02 13:17:32 +00:00
|
|
|
diff -up dhcp-4.3.4/client/dhclient-script.8.capability dhcp-4.3.4/client/dhclient-script.8
|
|
|
|
--- dhcp-4.3.4/client/dhclient-script.8.capability 2016-04-29 12:19:40.668129317 +0200
|
|
|
|
+++ dhcp-4.3.4/client/dhclient-script.8 2016-04-29 12:19:40.717129296 +0200
|
2014-07-10 17:01:31 +00:00
|
|
|
@@ -243,6 +243,16 @@ repeatedly initialized to the values pro
|
|
|
|
the other. Assuming the information provided by both servers is
|
|
|
|
valid, this shouldn't cause any real problems, but it could be
|
|
|
|
confusing.
|
|
|
|
+.PP
|
|
|
|
+Normally, if dhclient was compiled with libcap-ng support,
|
|
|
|
+dhclient drops most capabilities immediately upon startup.
|
|
|
|
+While more secure, this greatly restricts the additional actions that
|
|
|
|
+hooks in dhclient-script can take. For example, any daemons that
|
|
|
|
+dhclient-script starts or restarts will inherit the restricted
|
|
|
|
+capabilities as well, which may interfere with their correct operation.
|
|
|
|
+Thus, the
|
|
|
|
+.BI \-nc
|
|
|
|
+option can be used to prevent dhclient from dropping capabilities.
|
|
|
|
.SH SEE ALSO
|
|
|
|
dhclient(8), dhcpd(8), dhcrelay(8), dhclient.conf(5) and
|
|
|
|
dhclient.leases(5).
|
2016-05-02 13:17:32 +00:00
|
|
|
diff -up dhcp-4.3.4/client/Makefile.am.capability dhcp-4.3.4/client/Makefile.am
|
|
|
|
--- dhcp-4.3.4/client/Makefile.am.capability 2016-04-29 12:19:40.652129324 +0200
|
|
|
|
+++ dhcp-4.3.4/client/Makefile.am 2016-04-29 12:19:40.717129296 +0200
|
|
|
|
@@ -13,7 +13,7 @@ dhclient_SOURCES = clparse.c dhclient.c
|
2014-07-10 17:01:31 +00:00
|
|
|
scripts/bsdos scripts/freebsd scripts/linux scripts/macos \
|
|
|
|
scripts/netbsd scripts/nextstep scripts/openbsd \
|
|
|
|
scripts/solaris scripts/openwrt
|
|
|
|
-dhclient_LDADD = ../common/libdhcp.a ../omapip/libomapi.la \
|
|
|
|
+dhclient_LDADD = ../common/libdhcp.a ../omapip/libomapi.la $(CAPNG_LDADD) \
|
2015-03-13 10:39:06 +00:00
|
|
|
$(BIND9_LIBDIR) -lirs-export -ldns-export -lisccfg-export -lisc-export
|
2014-07-10 17:01:31 +00:00
|
|
|
man_MANS = dhclient.8 dhclient-script.8 dhclient.conf.5 dhclient.leases.5
|
|
|
|
EXTRA_DIST = $(man_MANS)
|
2016-05-02 13:17:32 +00:00
|
|
|
diff -up dhcp-4.3.4/configure.ac.capability dhcp-4.3.4/configure.ac
|
|
|
|
--- dhcp-4.3.4/configure.ac.capability 2016-04-29 12:19:40.652129324 +0200
|
|
|
|
+++ dhcp-4.3.4/configure.ac 2016-04-29 12:19:40.717129296 +0200
|
|
|
|
@@ -585,6 +585,41 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]],
|
2011-07-01 13:20:42 +00:00
|
|
|
# Look for optional headers.
|
|
|
|
AC_CHECK_HEADERS(sys/socket.h net/if_dl.h net/if6.h regex.h)
|
|
|
|
|
|
|
|
+# look for capabilities library
|
|
|
|
+AC_ARG_WITH(libcap-ng,
|
|
|
|
+ [ --with-libcap-ng=[auto/yes/no] Add Libcap-ng support [default=auto]],,
|
|
|
|
+ with_libcap_ng=auto)
|
|
|
|
+
|
|
|
|
+# Check for Libcap-ng API
|
|
|
|
+#
|
|
|
|
+# libcap-ng detection
|
|
|
|
+if test x$with_libcap_ng = xno ; then
|
|
|
|
+ have_libcap_ng=no;
|
|
|
|
+else
|
|
|
|
+ # Start by checking for header file
|
|
|
|
+ AC_CHECK_HEADER(cap-ng.h, capng_headers=yes, capng_headers=no)
|
|
|
|
+
|
|
|
|
+ # See if we have libcap-ng library
|
|
|
|
+ AC_CHECK_LIB(cap-ng, capng_clear,
|
|
|
|
+ CAPNG_LDADD=-lcap-ng,)
|
|
|
|
+
|
|
|
|
+ # Check results are usable
|
|
|
|
+ if test x$with_libcap_ng = xyes -a x$CAPNG_LDADD = x ; then
|
|
|
|
+ AC_MSG_ERROR(libcap-ng support was requested and the library was not found)
|
|
|
|
+ fi
|
|
|
|
+ if test x$CAPNG_LDADD != x -a $capng_headers = no ; then
|
|
|
|
+ AC_MSG_ERROR(libcap-ng libraries found but headers are missing)
|
|
|
|
+ fi
|
|
|
|
+fi
|
|
|
|
+AC_SUBST(CAPNG_LDADD)
|
|
|
|
+AC_MSG_CHECKING(whether to use libcap-ng)
|
|
|
|
+if test x$CAPNG_LDADD != x ; then
|
|
|
|
+ AC_DEFINE(HAVE_LIBCAP_NG,1,[libcap-ng support])
|
|
|
|
+ AC_MSG_RESULT(yes)
|
|
|
|
+else
|
|
|
|
+ AC_MSG_RESULT(no)
|
|
|
|
+fi
|
|
|
|
+
|
|
|
|
# Solaris needs some libraries for functions
|
|
|
|
AC_SEARCH_LIBS(socket, [socket])
|
|
|
|
AC_SEARCH_LIBS(inet_ntoa, [nsl])
|
2016-05-02 13:17:32 +00:00
|
|
|
diff -up dhcp-4.3.4/relay/dhcrelay.c.capability dhcp-4.3.4/relay/dhcrelay.c
|
|
|
|
--- dhcp-4.3.4/relay/dhcrelay.c.capability 2016-04-29 12:19:40.694129306 +0200
|
|
|
|
+++ dhcp-4.3.4/relay/dhcrelay.c 2016-04-29 12:22:30.278056386 +0200
|
|
|
|
@@ -32,6 +32,11 @@
|
2011-07-01 13:20:42 +00:00
|
|
|
#include <sys/time.h>
|
2016-05-02 13:17:32 +00:00
|
|
|
#include <isc/file.h>
|
2011-07-01 13:20:42 +00:00
|
|
|
|
|
|
|
+#ifdef HAVE_LIBCAP_NG
|
|
|
|
+# include <cap-ng.h>
|
|
|
|
+ int keep_capabilities = 0;
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
TIME default_lease_time = 43200; /* 12 hours... */
|
|
|
|
TIME max_lease_time = 86400; /* 24 hours... */
|
|
|
|
struct tree_cache *global_options[256];
|
2016-05-02 13:17:32 +00:00
|
|
|
@@ -454,6 +459,10 @@ main(int argc, char **argv) {
|
|
|
|
usage(use_noarg, argv[i-1]);
|
2013-12-20 15:13:52 +00:00
|
|
|
dhcrelay_sub_id = argv[i];
|
2011-07-01 13:20:42 +00:00
|
|
|
#endif
|
|
|
|
+ } else if (!strcmp(argv[i], "-nc")) {
|
|
|
|
+#ifdef HAVE_LIBCAP_NG
|
|
|
|
+ keep_capabilities = 1;
|
|
|
|
+#endif
|
|
|
|
} else if (!strcmp(argv[i], "-pf")) {
|
|
|
|
if (++i == argc)
|
2016-05-02 13:17:32 +00:00
|
|
|
usage(use_noarg, argv[i-1]);
|
|
|
|
@@ -528,6 +537,17 @@ main(int argc, char **argv) {
|
2011-07-01 13:20:42 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
+#ifdef HAVE_LIBCAP_NG
|
|
|
|
+ /* Drop capabilities */
|
|
|
|
+ if (!keep_capabilities) {
|
|
|
|
+ capng_clear(CAPNG_SELECT_BOTH);
|
|
|
|
+ capng_updatev(CAPNG_ADD, CAPNG_EFFECTIVE|CAPNG_PERMITTED,
|
|
|
|
+ CAP_NET_RAW, CAP_NET_BIND_SERVICE, -1);
|
|
|
|
+ capng_apply(CAPNG_SELECT_BOTH);
|
2011-07-04 09:18:13 +00:00
|
|
|
+ log_info ("Dropped all unnecessary capabilities.");
|
2011-07-01 13:20:42 +00:00
|
|
|
+ }
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
if (!quiet) {
|
|
|
|
log_info("%s %s", message, PACKAGE_VERSION);
|
|
|
|
log_info(copyright);
|
2016-05-02 13:17:32 +00:00
|
|
|
@@ -680,6 +700,15 @@ main(int argc, char **argv) {
|
2013-12-20 15:13:52 +00:00
|
|
|
signal(SIGTERM, dhcp_signal_handler); /* kill */
|
2014-07-10 17:01:31 +00:00
|
|
|
#endif
|
2011-07-01 13:20:42 +00:00
|
|
|
|
|
|
|
+#ifdef HAVE_LIBCAP_NG
|
|
|
|
+ /* Drop all capabilities */
|
|
|
|
+ if (!keep_capabilities) {
|
|
|
|
+ capng_clear(CAPNG_SELECT_BOTH);
|
|
|
|
+ capng_apply(CAPNG_SELECT_BOTH);
|
2011-07-04 09:18:13 +00:00
|
|
|
+ log_info ("Dropped all capabilities.");
|
2011-07-01 13:20:42 +00:00
|
|
|
+ }
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
/* Start dispatching packets and timeouts... */
|
|
|
|
dispatch();
|
|
|
|
|
2016-05-02 13:17:32 +00:00
|
|
|
diff -up dhcp-4.3.4/relay/Makefile.am.capability dhcp-4.3.4/relay/Makefile.am
|
|
|
|
--- dhcp-4.3.4/relay/Makefile.am.capability 2016-04-29 12:19:40.653129323 +0200
|
|
|
|
+++ dhcp-4.3.4/relay/Makefile.am 2016-04-29 12:19:40.718129295 +0200
|
2014-07-10 17:01:31 +00:00
|
|
|
@@ -2,7 +2,7 @@ AM_CPPFLAGS = -DLOCALSTATEDIR='"@localst
|
|
|
|
|
|
|
|
sbin_PROGRAMS = dhcrelay
|
|
|
|
dhcrelay_SOURCES = dhcrelay.c
|
|
|
|
-dhcrelay_LDADD = ../common/libdhcp.a ../omapip/libomapi.la \
|
|
|
|
+dhcrelay_LDADD = ../common/libdhcp.a ../omapip/libomapi.la $(CAPNG_LDADD) \
|
2015-03-13 10:39:06 +00:00
|
|
|
$(BIND9_LIBDIR) -lirs-export -ldns-export -lisccfg-export -lisc-export
|
2014-07-10 17:01:31 +00:00
|
|
|
man_MANS = dhcrelay.8
|
|
|
|
EXTRA_DIST = $(man_MANS)
|