changeset 5209:baab981d3929 draft

privsep: No longer need the chrootdir configure option. As we work with an empty chroot directory.
author Roy Marples <roy@marples.name>
date Tue, 12 May 2020 11:23:03 +0100
parents 6e53055c9989
children ad11ffaf9e03
files Makefile.inc configure src/dhcpcd.8.in src/dhcpcd.c src/dhcpcd.h src/if-options.c src/if-options.h src/privsep.c src/script.c
diffstat 9 files changed, 9 insertions(+), 60 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile.inc	Tue May 12 10:58:31 2020 +0100
+++ b/Makefile.inc	Tue May 12 11:23:03 2020 +0100
@@ -33,6 +33,3 @@
 SED_SCRIPT=		-e 's:@SCRIPT@:${SCRIPT}:g'
 SED_SYS=		-e 's:@SYSCONFDIR@:${SYSCONFDIR}:g'
 SED_DEFAULT_HOSTNAME=	-e 's:@DEFAULT_HOSTNAME@:${DEFAULT_HOSTNAME}:g'
-SED_CHROOT?=		-e 's:@CHDIR^@::g' -e 's:@CHDIR$$@::g' \
-	-e '/@CHDIR1@/d' -e '/@CHDIR2@/d'
-SED_PRIVSEP_USER=	-e 's:@PRIVSEP_USER@:${PRIVSEP_USER}:g'
--- a/configure	Tue May 12 10:58:31 2020 +0100
+++ b/configure	Tue May 12 11:23:03 2020 +0100
@@ -13,7 +13,6 @@
 INET6=
 PRIVSEP=
 PRIVSEP_USER=
-PRIVSEP_CHROOT=
 ARC4RANDOM=
 CLOSEFROM=
 RBTREE=
@@ -72,7 +71,6 @@
 	--disable-privsep) PRIVSEP=no;;
 	--enable-privsep) PRIVSEP=yes;;
 	--privsepuser) PRIVSEP_USER=$var;;
-	--chrootdir) PRIVSEP_CHROOT=$var;;
 	--prefix) PREFIX=$var;;
 	--sysconfdir) SYSCONFDIR=$var;;
 	--bindir|--sbindir) SBINDIR=$var;;
@@ -581,22 +579,9 @@
 
 	echo "CPPFLAGS+=	-DPRIVSEP" >>$CONFIG_MK
 	echo "PRIVSEP_USER?=	$PRIVSEP_USER" >>$CONFIG_MK
-	if [ -n "$PRIVSEP_CHROOT" ]; then
-		echo "PRIVSEP_CHROOT=	$PRIVSEP_CHROOT" >>$CONFIG_MK
-		cat <<EOF >>$CONFIG_MK
-SED_CHROOT=	-e 's:@CHDIR^@.*@CHDIR\$\$@:default of:g' \\
-	-e 's:@CHDIR1@:.Pa \${PRIVSEP_CHROOT} .:g' \\
-	-e 's:@CHDIR2@:A blank string chroots to the privileged separation users home directory.:g'
-EOF
-	fi
 	echo "#ifndef PRIVSEP_USER" >>$CONFIG_H
 	echo "#define PRIVSEP_USER		 \"$PRIVSEP_USER\"" >>$CONFIG_H
 	echo "#endif" >>$CONFIG_H
-	if [ -n "$PRIVSEP_CHROOT" ]; then
-		echo "#ifndef PRIVSEP_CHROOT" >>$CONFIG_H
-		echo "#define PRIVSEP_CHROOT	\"$PRIVSEP_CHROOT\"" >>$CONFIG_H
-		echo "#endif" >>$CONFIG_H
-	fi
 	echo "DHCPCD_SRCS+=	privsep.c privsep-root.c privsep-inet.c" \
 		>>$CONFIG_MK
 	if [ -z "$INET" ] || [ "$INET" = yes ]; then
--- a/src/dhcpcd.8.in	Tue May 12 10:58:31 2020 +0100
+++ b/src/dhcpcd.8.in	Tue May 12 11:23:03 2020 +0100
@@ -24,7 +24,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd April 30, 2020
+.Dd May 12, 2020
 .Dt DHCPCD 8
 .Os
 .Sh NAME
@@ -35,7 +35,6 @@
 .Op Fl 146ABbDdEGgHJKLMNPpqTV
 .Op Fl C , Fl Fl nohook Ar hook
 .Op Fl c , Fl Fl script Ar script
-.Op Fl Fl chroot Ar chroot
 .Op Fl e , Fl Fl env Ar value
 .Op Fl F , Fl Fl fqdn Ar FQDN
 .Op Fl f , Fl Fl config Ar file
@@ -263,15 +262,6 @@
 .Ar script
 instead of the default
 .Pa @SCRIPT@ .
-.It Fl Fl chroot Ar chroot
-.Xr chroot 3
-to the
-.Ar chroot
-directory rather than the
-@CHDIR^@privilege separation users home directory.@CHDIR$@
-@CHDIR1@
-@CHDIR2@
-The privilege separation user is @PRIVSEP_USER@.
 .It Fl D , Fl Fl duid
 Use a DHCP Unique Identifier.
 If a system UUID is available, that will be used to create a DUID-UUID,
--- a/src/dhcpcd.c	Tue May 12 10:58:31 2020 +0100
+++ b/src/dhcpcd.c	Tue May 12 11:23:03 2020 +0100
@@ -1848,9 +1848,6 @@
 #endif
 #ifdef PRIVSEP
 	ctx.ps_root_fd = ctx.ps_data_fd = -1;
-#ifdef PRIVSEP_CHROOT
-	ctx.ps_chroot = PRIVSEP_CHROOT;
-#endif
 	TAILQ_INIT(&ctx.ps_processes);
 #endif
 	rt_init(&ctx);
@@ -1916,19 +1913,6 @@
 		case 'V':
 			i = 2;
 			break;
-#ifdef PRIVSEP
-		case O_CHROOT:
-#ifdef PRIVSEP_CHROOT
-			if (*optarg == '\0' ||
-			    (((optarg[0] == '"' && optarg[1] == '"') ||
-			      (optarg[0] == '\'' && optarg[1] == '\'')) &&
-			     optarg[2] == '\0'))
-				ctx.ps_chroot = NULL;
-			else
-#endif
-				ctx.ps_chroot = optarg;
-			break;
-#endif
 		case '?':
 			if (ctx.options & DHCPCD_PRINT_PIDFILE)
 				continue;
--- a/src/dhcpcd.h	Tue May 12 10:58:31 2020 +0100
+++ b/src/dhcpcd.h	Tue May 12 11:23:03 2020 +0100
@@ -193,7 +193,6 @@
 
 #ifdef PRIVSEP
 	struct passwd *ps_user;	/* struct passwd for privsep user */
-	const char *ps_chroot;
 	pid_t ps_root_pid;
 	int ps_root_fd;		/* Privileged Actioneer commands */
 	int ps_data_fd;		/* Data from root spawned processes */
--- a/src/if-options.c	Tue May 12 10:58:31 2020 +0100
+++ b/src/if-options.c	Tue May 12 11:23:03 2020 +0100
@@ -158,7 +158,6 @@
 	{"inactive",        no_argument,       NULL, O_INACTIVE},
 	{"mudurl",          required_argument, NULL, O_MUDURL},
 	{"link_rcvbuf",     required_argument, NULL, O_LINK_RCVBUF},
-	{"chroot",          required_argument, NULL, O_CHROOT},
 	{NULL,              0,                 NULL, '\0'}
 };
 
@@ -660,7 +659,6 @@
 #define ARG_REQUIRED if (arg == NULL) goto arg_required
 
 	switch(opt) {
-	case O_CHROOT: /* FALLTHROUGH */
 	case 'f': /* FALLTHROUGH */
 	case 'g': /* FALLTHROUGH */
 	case 'n': /* FALLTHROUGH */
--- a/src/if-options.h	Tue May 12 10:58:31 2020 +0100
+++ b/src/if-options.h	Tue May 12 11:23:03 2020 +0100
@@ -180,7 +180,6 @@
 #define O_INACTIVE		O_BASE + 47
 #define O_MUDURL		O_BASE + 48
 #define O_MSUSERCLASS		O_BASE + 49
-#define O_CHROOT		O_BASE + 50
 
 extern const struct option cf_options[];
 
--- a/src/privsep.c	Tue May 12 10:58:31 2020 +0100
+++ b/src/privsep.c	Tue May 12 11:23:03 2020 +0100
@@ -81,6 +81,7 @@
 ps_init(struct dhcpcd_ctx *ctx)
 {
 	struct passwd *pw;
+	struct stat st;
 
 	errno = 0;
 	if ((ctx->ps_user = pw = getpwnam(PRIVSEP_USER)) == NULL) {
@@ -94,14 +95,10 @@
 		return -1;
 	}
 
-	if (ctx->ps_chroot == NULL)
-		ctx->ps_chroot = pw->pw_dir;
-
-	/* If we pickup the _dhcp user refuse the default directory */
-	if (*ctx->ps_chroot != '/') {
+	if (stat(pw->pw_dir, &st) == -1 || !S_ISDIR(st.st_mode)) {
 		ctx->options &= ~DHCPCD_PRIVSEP;
 		logerrx("refusing chroot: %s: %s",
-		    PRIVSEP_USER, ctx->ps_chroot);
+		    PRIVSEP_USER, pw->pw_dir);
 		errno = 0;
 		return -1;
 	}
@@ -116,9 +113,9 @@
 	struct passwd *pw = ctx->ps_user;
 
 	if (!(ctx->options & DHCPCD_FORKED))
-		logdebugx("chrooting to `%s'", ctx->ps_chroot);
-	if (chroot(ctx->ps_chroot) == -1)
-		logerr("%s: chroot `%s'", __func__, ctx->ps_chroot);
+		logdebugx("chrooting to `%s'", pw->pw_dir);
+	if (chroot(pw->pw_dir) == -1)
+		logerr("%s: chroot `%s'", __func__, pw->pw_dir);
 	if (chdir("/") == -1)
 		logerr("%s: chdir `/'", __func__);
 
--- a/src/script.c	Tue May 12 10:58:31 2020 +0100
+++ b/src/script.c	Tue May 12 11:23:03 2020 +0100
@@ -270,8 +270,8 @@
 		goto eexit;
 
 #ifdef PRIVSEP
-	if (ctx->options & DHCPCD_PRIVSEP && ctx->ps_chroot != NULL) {
-		if (efprintf(fp, "chroot=%s", ctx->ps_chroot) == -1)
+	if (ctx->options & DHCPCD_PRIVSEP && ctx->ps_user != NULL) {
+		if (efprintf(fp, "chroot=%s", ctx->ps_user->pw_dir) == -1)
 			goto eexit;
 	}
 	if (strcmp(reason, "CHROOT") == 0)