8000 setpriv: follow /etc/login.defs for PATH · util-linux/util-linux@3b2899a · GitHub
[go: up one dir, main page]

Skip to content

Commit 3b2899a

Browse files
committed
setpriv: follow /etc/login.defs for PATH
The patch also cleans up the --reset-env description in the man page. Fixes: #3560 Signed-off-by: Karel Zak <kzak@redhat.com>
1 parent 08b3aa9 commit 3b2899a

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2175,7 +2175,7 @@ exe = executable(
21752175
'setpriv',
21762176
setpriv_sources,
21772177
include_directories : includes,
2178-
link_with : [lib_common],
2178+
link_with : [lib_common, logindefs_c],
21792179
dependencies : [lib_cap_ng],
21802180
install_dir : usrbin_exec_dir,
21812181
install : opt,

sys-utils/Makemodule.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,8 @@ usrbin_exec_PROGRAMS += setpriv
592592
MANPAGES += sys-utils/setpriv.1
593593
dist_noinst_DATA += sys-utils/setpriv.1.adoc
594594
setpriv_SOURCES = sys-utils/setpriv.c \
595-
lib/caputils.c
595+
lib/caputils.c \
596+
lib/logindefs.c
596597
dist_noinst_HEADERS += sys-utils/setpriv-landlock.h
597598
if HAVE_LINUX_LANDLOCK_H
598599
setpriv_SOURCES += sys-utils/setpriv-landlock.c

sys-utils/setpriv.1.adoc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,12 @@ Load raw BPF seccomp filter code from a file.
121121
Filters can for example be created with *enosys*.
122122

123123
*--reset-env*::
124-
Clears all the environment variables except *TERM*; initializes the environment variables *HOME*, *SHELL*, *USER*, *LOGNAME* according to the user's passwd entry; sets *PATH* to _/usr/local/bin:/bin:/usr/bin_ for a regular user and to _/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin_ for root.
124+
* clears all the environment variables except *TERM* environment variable
125+
* initializes the environment variables *HOME*, *SHELL*, *USER*, *LOGNAME* according to the user's passwd entry
126+
* the environment variable *SHELL* defaults to */bin/sh* if none is given in the user's passwd entry.
127+
* resets *PATH* senvironment variable according to setting in _/etc/login.defs_ (*ENV_PATH*, *ENV_SUPATH* or *ENV_ROOTPATH* variables), or defaults to _/usr/local/bin:/bin:/usr/bin_ for a regular user and to _/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin_ for root.
125128
+
126-
The environment variable *PATH* may be different on systems where _/bin_ and _/sbin_ are merged into _/usr_. The environment variable *SHELL* defaults to */bin/sh* if none is given in the user's passwd entry.
129+
The environment variable *PATH* may be different on systems where _/bin_ and _/sbin_ are merged into _/usr_.
127130

128131
include::man-common/help-version.adoc[]
129132

sys-utils/setpriv.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
#include "setpriv-landlock.h"
4747
#include "seccomp.h"
4848

49+
#include "logindefs.h"
50+
4951
#ifndef PR_SET_NO_NEW_PRIVS
5052
# define PR_SET_NO_NEW_PRIVS 38
5153
#endif
@@ -744,10 +746,7 @@ static void do_reset_environ(struct passwd *pw)
744746
xsetenv("USER", pw->pw_name, 1);
745747
xsetenv("LOGNAME", pw->pw_name, 1);
746748

747-
if (pw->pw_uid)
748-
xsetenv("PATH", _PATH_DEFPATH, 1);
749-
else
750-
xsetenv("PATH", _PATH_DEFPATH_ROOT, 1);
749+
logindefs_setenv_path(pw->pw_uid);
751750
}
752751

753752
static uid_t get_user(const char *s, const char *err)

0 commit comments

Comments
 (0)
0