From: Todd C. Miller Date: Wed, 16 Feb 2005 04:16:22 +0000 (+0000) Subject: In -i mode, base the value of insert_env()'s dupcheck flag on DID_FOO flags. X-Git-Tag: SUDO_1_7_0~697 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=87a8b5b48b173a31a38ad2596774e8cf91ec07b6;p=sudo In -i mode, base the value of insert_env()'s dupcheck flag on DID_FOO flags. Move checks for $HOME resetting into rebuild_env() --- diff --git a/env.c b/env.c index 2256643af..a2a8ede56 100644 --- 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 6d47a7b79..0416b7b62 100644 --- 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)