As we work with an empty chroot directory.
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'
INET6=
PRIVSEP=
PRIVSEP_USER=
-PRIVSEP_CHROOT=
ARC4RANDOM=
CLOSEFROM=
RBTREE=
--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;;
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
.\" 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
.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
.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,
#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);
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;
#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 */
{"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'}
};
#define ARG_REQUIRED if (arg == NULL) goto arg_required
switch(opt) {
- case O_CHROOT: /* FALLTHROUGH */
case 'f': /* FALLTHROUGH */
case 'g': /* FALLTHROUGH */
case 'n': /* FALLTHROUGH */
#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[];
ps_init(struct dhcpcd_ctx *ctx)
{
struct passwd *pw;
+ struct stat st;
errno = 0;
if ((ctx->ps_user = pw = getpwnam(PRIVSEP_USER)) == NULL) {
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;
}
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__);
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)