]> granicus.if.org Git - sudo/commitdiff
The SHELL environment variable was preserved from the user's
authorTodd C. Miller <Todd.Miller@courtesan.com>
Tue, 15 Jan 2002 23:43:59 +0000 (23:43 +0000)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Tue, 15 Jan 2002 23:43:59 +0000 (23:43 +0000)
environment instead of being reset based on the passwd database
when the "env_reset" option was used.  Now it is reset as it should be.

env.c
getspwuid.c
sudo.c

diff --git a/env.c b/env.c
index b6e035affa192eab69966f29cb5f313f699ee4b6..42f2ce0fa27f74b7a7af6f35ef7dbc477fe49358 100644 (file)
--- a/env.c
+++ b/env.c
@@ -341,7 +341,7 @@ rebuild_env(sudo_mode, envp)
        if (!(didvar & DID_HOME))
            *nep++ = format_env("HOME", user_dir);
        if (!(didvar & DID_SHELL))
-           *nep++ = format_env("SHELL", user_shell);
+           *nep++ = format_env("SHELL", sudo_user.pw->pw_shell);
        if (!(didvar & DID_LOGNAME))
            *nep++ = format_env("LOGNAME", user_name);
        if (!(didvar & DID_USER))
index b67027baa3953f71cbce7ba69bc750c0e9cba075..f6d1370178b00ccf14083dcf550d88308395ffec 100644 (file)
@@ -98,30 +98,9 @@ int crypt_type = INT_MAX;
 /*
  * Local functions not visible outside getspwuid.c
  */
-static char *sudo_getshell             __P((struct passwd *));
 static struct passwd *sudo_pwdup       __P((struct passwd *));
 
 
-/*
- * Return the user's shell based on either the SHELL environment variable
- * (already assigned to user_shell) or, failing that, the passwd(5) entry.
- */
-static char *
-sudo_getshell(pw)
-    struct passwd *pw;
-{
-    char *pw_shell;
-
-    if ((pw_shell = user_shell) == NULL)
-       pw_shell = pw->pw_shell;
-
-    /* empty string "" means bourne shell */
-    if (*pw_shell == '\0')
-       pw_shell = _PATH_BSHELL;
-
-    return(pw_shell);
-}
-
 /*
  * Return a copy of the encrypted password for the user described by pw.
  * If shadow passwords are in use, look in the shadow file.
@@ -236,8 +215,11 @@ sudo_pwdup(pw)
     local_pw->pw_class = estrdup(pw->pw_class);
 #endif
 
-    /* pw_shell is a special case since we overide with $SHELL */
-    local_pw->pw_shell = estrdup(sudo_getshell(pw));
+    /* If shell field is empty, expand to _PATH_BSHELL. */
+    if (local_pw->pw_shell[0] == '\0')
+       local_pw->pw_shell = _PATH_BSHELL;
+    else
+       local_pw->pw_shell = estrdup(pw->pw_shell);
 
     /* pw_passwd gets a shadow password if applicable */
     local_pw->pw_passwd = sudo_getepw(pw);
diff --git a/sudo.c b/sudo.c
index 87a76eb423194e8e4f5bb97f01fd61214aa17fba..39ef205be46842eefedb5ef4f1088caedd74c29d 100644 (file)
--- a/sudo.c
+++ b/sudo.c
@@ -511,7 +511,8 @@ init_vars(sudo_mode)
        log_error(0, "uid %ld does not exist in the passwd file!",
            (long) pw.pw_uid);
     }
-    user_shell = sudo_user.pw->pw_shell;
+    if (user_shell == NULL || *user_shell == '\0')
+       user_shell = sudo_user.pw->pw_shell;
 
     /* It is now safe to use log_error() and set_perms() */