summaryrefslogtreecommitdiffstats
path: root/login-utils/su.c
diff options
context:
space:
mode:
authorLudwig Nussel2012-06-01 14:51:17 +0200
committerKarel Zak2012-06-05 15:16:10 +0200
commita711e67a44a9214f174c466a2345d329a077e111 (patch)
tree598673c76a2064ea029bf06f33f56aa5dc130a81 /login-utils/su.c
parentsu: use EXIT_FAILURE consistently (diff)
downloadkernel-qcow2-util-linux-a711e67a44a9214f174c466a2345d329a077e111.tar.gz
kernel-qcow2-util-linux-a711e67a44a9214f174c466a2345d329a077e111.tar.xz
kernel-qcow2-util-linux-a711e67a44a9214f174c466a2345d329a077e111.zip
su: use ENV_PATH resp ENV_SUPATH to be consistent with login
Signed-off-by: Ludwig Nussel <ludwig.nussel@suse.de>
Diffstat (limited to 'login-utils/su.c')
-rw-r--r--login-utils/su.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/login-utils/su.c b/login-utils/su.c
index b1fca5fbd..22b9ccc08 100644
--- a/login-utils/su.c
+++ b/login-utils/su.c
@@ -476,6 +476,20 @@ clearsbin (const char *const path)
return ret;
}
+static void
+set_path(const struct passwd* pw)
+{
+ int r;
+ if (pw->pw_uid)
+ r = logindefs_setenv("PATH", "ENV_PATH", _PATH_DEFPATH);
+
+ else if ((r = logindefs_setenv("PATH", "ENV_ROOTPATH", NULL)) != 0)
+ r = logindefs_setenv("PATH", "ENV_SUPATH", _PATH_DEFPATH_ROOT);
+
+ if (r != 0)
+ err (EXIT_FAILURE, _("failed to set PATH"));
+}
+
/* Update `environ' for the new shell based on PW, with SHELL being
the value for the SHELL environment variable. */
@@ -497,9 +511,7 @@ modify_environment (const struct passwd *pw, const char *shell)
xsetenv ("SHELL", shell);
xsetenv ("USER", pw->pw_name);
xsetenv ("LOGNAME", pw->pw_name);
- xsetenv ("PATH", (pw->pw_uid
- ? getlogindefs_str ("PATH", _PATH_DEFPATH)
- : getlogindefs_str ("SUPATH", _PATH_DEFPATH_ROOT)));
+ set_path(pw);
}
else
{
@@ -510,11 +522,7 @@ modify_environment (const struct passwd *pw, const char *shell)
xsetenv ("HOME", pw->pw_dir);
xsetenv ("SHELL", shell);
if (getlogindefs_bool ("ALWAYS_SET_PATH", 0))
- xsetenv ("PATH", (pw->pw_uid
- ? getlogindefs_str ("PATH",
- _PATH_DEFPATH)
- : getlogindefs_str ("SUPATH",
- _PATH_DEFPATH_ROOT)));
+ set_path(pw);
else
{
char const *path = getenv ("PATH");