2
0
mirror of https://github.com/sudo-project/sudo.git synced 2025-09-01 14:55:12 +00:00

In -i mode, base the value of insert_env()'s dupcheck flag on DID_FOO flags.

Move checks for $HOME resetting into rebuild_env()
This commit is contained in:
Todd C. Miller
2005-02-16 04:16:22 +00:00
parent 74894ebf62
commit 87a8b5b48b
2 changed files with 14 additions and 11 deletions

18
env.c
View File

@@ -420,10 +420,14 @@ rebuild_env(envp1, envp2, sudo_mode, noexec)
* on sudoers options). * on sudoers options).
*/ */
if (ISSET(sudo_mode, MODE_LOGIN_SHELL)) { if (ISSET(sudo_mode, MODE_LOGIN_SHELL)) {
insert_env(format_env("HOME", runas_pw->pw_dir, VNULL), &env, 0); insert_env(format_env("HOME", runas_pw->pw_dir, VNULL), &env,
insert_env(format_env("SHELL", runas_pw->pw_shell, VNULL), &env, 0); ISSET(didvar, DID_HOME));
insert_env(format_env("LOGNAME", runas_pw->pw_name, VNULL), &env, 0); insert_env(format_env("SHELL", runas_pw->pw_shell, VNULL), &env,
insert_env(format_env("USER", runas_pw->pw_name, VNULL), &env, 0); 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 { } else {
if (!ISSET(didvar, DID_HOME)) if (!ISSET(didvar, DID_HOME))
insert_env(format_env("HOME", user_dir, VNULL), &env, 0); 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. */ /* 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) 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); insert_env(format_env("HOME", runas_pw->pw_dir, VNULL), &env, 1);
}
/* Provide default values for $TERM and $PATH if they are not set. */ /* Provide default values for $TERM and $PATH if they are not set. */
if (!ISSET(didvar, DID_TERM)) if (!ISSET(didvar, DID_TERM))

5
sudo.c
View File

@@ -332,11 +332,6 @@ main(argc, argv)
if (ISSET(sudo_mode, MODE_IMPLIED_SHELL) && !def_shell_noargs) if (ISSET(sudo_mode, MODE_IMPLIED_SHELL) && !def_shell_noargs)
usage(1); 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. */ /* Bail if a tty is required and we don't have one. */
if (def_requiretty) { if (def_requiretty) {
if ((fd = open(_PATH_TTY, O_RDWR|O_NOCTTY)) == -1) if ((fd = open(_PATH_TTY, O_RDWR|O_NOCTTY)) == -1)