From 705ee62ff03a083ea7c06159420b7a71b0b20902 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 2 Oct 2012 10:14:05 +0200 Subject: [PATCH] su: don't modify PATH if -l not specified MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This patch reverts a6fdd3f8125be23930d955c2bc6b7a46cdaf8a12. su(1) modifies PATH if: - option -l specified - ALWAYS_SET_PATH login.defs variable set Reported-by: Thomas Bächler Signed-off-by: Karel Zak --- login-utils/su-common.c | 126 +--------------------------------------- 1 file changed, 1 insertion(+), 125 deletions(-) diff --git a/login-utils/su-common.c b/login-utils/su-common.c index 2749303136..263db700ad 100644 --- a/login-utils/su-common.c +++ b/login-utils/su-common.c @@ -407,115 +407,6 @@ done: } } -/* Add or clear /sbin and /usr/sbin for the su command - used without `-'. */ - -/* Set if /sbin is found in path. */ -#define SBIN_MASK 0x01 -/* Set if /usr/sbin is found in path. */ -#define USBIN_MASK 0x02 - -static char * -addsbin (const char *const path) -{ - unsigned char smask = 0; - char *ptr, *tmp, *cur, *ret = NULL; - size_t len; - - if (!path || *path == 0) - return NULL; - - tmp = xstrdup (path); - cur = tmp; - for (ptr = strsep (&cur, ":"); ptr != NULL; ptr = strsep (&cur, ":")) - { - if (!strcmp (ptr, "/sbin")) - smask |= SBIN_MASK; - if (!strcmp (ptr, "/usr/sbin")) - smask |= USBIN_MASK; - } - - if ((smask & (USBIN_MASK|SBIN_MASK)) == (USBIN_MASK|SBIN_MASK)) - { - free (tmp); - return NULL; - } - - len = strlen (path); - if (!(smask & USBIN_MASK)) - len += strlen ("/usr/sbin:"); - - if (!(smask & SBIN_MASK)) - len += strlen (":/sbin"); - - ret = xmalloc (len + 1); - strcpy (tmp, path); - - *ret = 0; - cur = tmp; - for (ptr = strsep (&cur, ":"); ptr; ptr = strsep (&cur, ":")) - { - if (!strcmp (ptr, ".")) - continue; - if (*ret) - strcat (ret, ":"); - if (!(smask & USBIN_MASK) && !strcmp (ptr, "/bin")) - { - strcat (ret, "/usr/sbin:"); - strcat (ret, ptr); - smask |= USBIN_MASK; - continue; - } - if (!(smask & SBIN_MASK) && !strcmp (ptr, "/usr/bin")) - { - strcat (ret, ptr); - strcat (ret, ":/sbin"); - smask |= SBIN_MASK; - continue; - } - strcat (ret, ptr); - } - free (tmp); - - if (!(smask & USBIN_MASK)) - strcat (ret, ":/usr/sbin"); - - if (!(smask & SBIN_MASK)) - strcat (ret, ":/sbin"); - - return ret; -} - -static char * -clearsbin (const char *const path) -{ - char *ptr, *tmp, *cur, *ret = NULL; - - if (!path || *path == 0) - return NULL; - - tmp = xstrdup (path); - - ret = xmalloc (strlen (path) + 1); - *ret = 0; - cur = tmp; - for (ptr = strsep (&cur, ":"); ptr; ptr = strsep (&cur, ":")) - { - if (!strcmp (ptr, "/sbin")) - continue; - if (!strcmp (ptr, "/usr/sbin")) - continue; - if (!strcmp (ptr, "/usr/local/sbin")) - continue; - if (*ret) - strcat (ret, ":"); - strcat (ret, ptr); - } - free (tmp); - - return ret; -} - static void set_path(const struct passwd* pw) { @@ -563,22 +454,7 @@ modify_environment (const struct passwd *pw, const char *shell) xsetenv ("SHELL", shell, 1); if (getlogindefs_bool ("ALWAYS_SET_PATH", 0)) set_path(pw); - else - { - char const *path = getenv ("PATH"); - char *new = NULL; - - if (pw->pw_uid) - new = clearsbin (path); - else - new = addsbin (path); - - if (new) - { - xsetenv ("PATH", new, 1); - free (new); - } - } + if (pw->pw_uid) { xsetenv ("USER", pw->pw_name, 1); -- 2.47.3