From 89f95425746e0371c033260c2bc0ef176eba6a37 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 22 Aug 2018 11:43:32 +0200 Subject: setpriv: add --reset-env Clear environment in way like su(1), but PATH is set to hard-coded defaults and /etc/login.defs is not used at all (I guess we want to keep setpriv(1) simple). If you need anything more advanced than use env(1). Addresses: https://github.com/karelzak/util-linux/issues/325 Signed-off-by: Karel Zak --- sys-utils/setpriv.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) (limited to 'sys-utils/setpriv.c') diff --git a/sys-utils/setpriv.c b/sys-utils/setpriv.c index 564c56d48..eba5decab 100644 --- a/sys-utils/setpriv.c +++ b/sys-utils/setpriv.c @@ -39,6 +39,7 @@ #include "xalloc.h" #include "pathnames.h" #include "signames.h" +#include "env.h" #ifndef PR_SET_NO_NEW_PRIVS # define PR_SET_NO_NEW_PRIVS 38 @@ -56,6 +57,9 @@ #define SETPRIV_EXIT_PRIVERR 127 /* how we exit when we fail to set privs */ +/* The shell to set SHELL env.variable if none is given in the user's passwd entry. */ +#define DEFAULT_SHELL "/bin/sh" + static gid_t get_group(const char *s, const char *err); enum cap_type { @@ -85,6 +89,7 @@ struct privctx { keep_groups:1, /* keep groups */ clear_groups:1, /* remove groups */ init_groups:1, /* initialize groups */ + reset_env:1, /* reset environment */ have_securebits:1; /* remove groups */ /* uids and gids */ @@ -140,10 +145,13 @@ static void __attribute__((__noreturn__)) usage(void) fputs(_(" --init-groups initialize supplementary groups\n"), out); fputs(_(" --groups set supplementary groups by UID or name\n"), out); fputs(_(" --securebits set securebits\n"), out); + fputs(_(" --reset-env reset environment variables\n"), out); fputs(_(" --pdeathsig keep|clear|\n" " set or clear parent death signal\n"), out); fputs(_(" --selinux-label