]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
privsep: No longer need the chrootdir configure option.
authorRoy Marples <roy@marples.name>
Tue, 12 May 2020 10:23:03 +0000 (11:23 +0100)
committerRoy Marples <roy@marples.name>
Tue, 12 May 2020 10:23:03 +0000 (11:23 +0100)
As we work with an empty chroot directory.

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

index 1920880857dc4d8ff56eed6925719eed4154ae64..ec5361a6ac02808e7b642fbaad399de98ea738d3 100644 (file)
@@ -33,6 +33,3 @@ SED_STATUSARG=                -e 's:@STATUSARG@:${STATUSARG}:g'
 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'
index 98410a8f49d8547d4f22888020e9455d5f8eeed6..33fb494b58b1e48103264d080d378273ca797e7c 100755 (executable)
--- a/configure
+++ b/configure
@@ -13,7 +13,6 @@ IPV4LL=
 INET6=
 PRIVSEP=
 PRIVSEP_USER=
-PRIVSEP_CHROOT=
 ARC4RANDOM=
 CLOSEFROM=
 RBTREE=
@@ -72,7 +71,6 @@ for x do
        --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 @@ if [ "$PRIVSEP" = yes ]; then
 
        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
index 4188d6be8be7c61d0b0b9392d4a0483b2ee4f7a0..77b039f14d542f21a5aa290b161a95deeb0b6bdb 100644 (file)
@@ -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 @@ Use this
 .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,
index 7eb8109ad3089ab77c7bbb3bb91a5bd43cdb8047..c2d10617575559d978730bc061abd9c2f0940db0 100644 (file)
@@ -1848,9 +1848,6 @@ main(int argc, char **argv)
 #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 @@ main(int argc, char **argv)
                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;
index f9ad928712b047817c87168386cd30375a628a35..e0044c2276e7e3d24d02d8f94e345e97ba90452a 100644 (file)
@@ -193,7 +193,6 @@ struct dhcpcd_ctx {
 
 #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 */
index 329a3b2e4c32d10d97fe7a0c5a755fb91010412b..0cbf55ad7b02c75884f6186d07de66182b80b067 100644 (file)
@@ -158,7 +158,6 @@ const struct option cf_options[] = {
        {"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 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo,
 #define ARG_REQUIRED if (arg == NULL) goto arg_required
 
        switch(opt) {
-       case O_CHROOT: /* FALLTHROUGH */
        case 'f': /* FALLTHROUGH */
        case 'g': /* FALLTHROUGH */
        case 'n': /* FALLTHROUGH */
index 6f38b43d09548fbec26e48c966cfc53a264303f2..1d9e3343d5005edd8ab72f9e826da19d646a8681 100644 (file)
 #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[];
 
index f34100c0a1e11186de0a51f827820fd6a70665ac..8d7c372319351fab0339df33404103fef5501080 100644 (file)
@@ -81,6 +81,7 @@ int
 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 @@ ps_init(struct dhcpcd_ctx *ctx)
                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 @@ ps_dropprivs(struct dhcpcd_ctx *ctx, unsigned int flags)
        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__);
 
index 1caf58aca0c9737dca7ec7137b5a111e41fed4bc..186b6e05d435ae37131884545e6466ad96ea3d18 100644 (file)
@@ -270,8 +270,8 @@ make_env(struct dhcpcd_ctx *ctx, const struct interface *ifp,
                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)