]> granicus.if.org Git - sudo/commitdiff
In -i mode, base the value of insert_env()'s dupcheck flag on DID_FOO flags.
authorTodd C. Miller <Todd.Miller@courtesan.com>
Wed, 16 Feb 2005 04:16:22 +0000 (04:16 +0000)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Wed, 16 Feb 2005 04:16:22 +0000 (04:16 +0000)
Move checks for $HOME resetting into rebuild_env()

env.c
sudo.c

diff --git a/env.c b/env.c
index 2256643afdc3e3d859cc44259777a4fd90abb9e4..a2a8ede561dd06f1c9e288d72bbd41769c81d2d7 100644 (file)
--- a/env.c
+++ b/env.c
@@ -420,10 +420,14 @@ rebuild_env(envp1, envp2, sudo_mode, noexec)
         * on sudoers options).
         */
        if (ISSET(sudo_mode, MODE_LOGIN_SHELL)) {
-           insert_env(format_env("HOME", runas_pw->pw_dir, VNULL), &env, 0);
-           insert_env(format_env("SHELL", runas_pw->pw_shell, VNULL), &env, 0);
-           insert_env(format_env("LOGNAME", runas_pw->pw_name, VNULL), &env, 0);
-           insert_env(format_env("USER", runas_pw->pw_name, VNULL), &env, 0);
+           insert_env(format_env("HOME", runas_pw->pw_dir, VNULL), &env,
+               ISSET(didvar, DID_HOME));
+           insert_env(format_env("SHELL", runas_pw->pw_shell, VNULL), &env,
+               ISSET(didvar, DID_SHELL));
+           insert_env(format_env("LOGNAME", runas_pw->pw_name, VNULL), &env,
+               ISSET(didvar, DID_LOGNAME));
+           insert_env(format_env("USER", runas_pw->pw_name, VNULL), &env,
+               ISSET(didvar, DID_USER));
        } else {
            if (!ISSET(didvar, DID_HOME))
                insert_env(format_env("HOME", user_dir, VNULL), &env, 0);
@@ -469,8 +473,12 @@ rebuild_env(envp1, envp2, sudo_mode, noexec)
     }
 
     /* Set $HOME for `sudo -H'.  Only valid at PERM_FULL_RUNAS. */
-    if ((def_env_reset || ISSET(sudo_mode, MODE_RESET_HOME)) && runas_pw->pw_dir)
-       insert_env(format_env("HOME", runas_pw->pw_dir, VNULL), &env, 1);
+    if (runas_pw->pw_dir) {
+       if (ISSET(sudo_mode, MODE_RESET_HOME) ||
+           (ISSET(sudo_mode, MODE_RUN) && (def_always_set_home ||
+           (ISSET(sudo_mode, MODE_SHELL) && def_set_home))))
+           insert_env(format_env("HOME", runas_pw->pw_dir, VNULL), &env, 1);
+    }
 
     /* Provide default values for $TERM and $PATH if they are not set. */
     if (!ISSET(didvar, DID_TERM))
diff --git a/sudo.c b/sudo.c
index 6d47a7b79941eec898f3174266316232002f8b8e..0416b7b62f4896de1455dc948acadd8d204b5d43 100644 (file)
--- a/sudo.c
+++ b/sudo.c
@@ -332,11 +332,6 @@ main(argc, argv)
     if (ISSET(sudo_mode, MODE_IMPLIED_SHELL) && !def_shell_noargs)
        usage(1);
 
-    /* May need to set $HOME to target user if we are running a command. */
-    if (ISSET(sudo_mode, MODE_RUN) && (def_always_set_home ||
-       (ISSET(sudo_mode, MODE_SHELL) && def_set_home)))
-       SET(sudo_mode, MODE_RESET_HOME);
-
     /* Bail if a tty is required and we don't have one.  */
     if (def_requiretty) {
        if ((fd = open(_PATH_TTY, O_RDWR|O_NOCTTY)) == -1)