2
0
mirror of https://github.com/sudo-project/sudo.git synced 2025-08-30 22:05:46 +00:00

Make -H flag work when HOME is listed in env_keep. Also makes

"set_home" and "always_set_home" override override HOME in env_keep.
This commit is contained in:
Todd C. Miller
2010-09-09 16:16:39 -04:00
parent e069b74dc8
commit 1b9ca115b7

View File

@@ -429,10 +429,15 @@ rebuild_env(int noexec)
#ifdef ENV_DEBUG
memset(env.envp, 0, env.env_size * sizeof(char *));
#endif
if (def_env_reset || ISSET(sudo_mode, MODE_LOGIN_SHELL)) {
/* Reset HOME based on target user unless keeping old value. */
reset_home = TRUE;
/* Reset HOME based on target user if configured to. */
if (ISSET(sudo_mode, MODE_RUN)) {
if (def_always_set_home || ISSET(sudo_mode, MODE_RESET_HOME) ||
(ISSET(sudo_mode, MODE_SHELL) && def_set_home))
reset_home = TRUE;
}
if (def_env_reset || ISSET(sudo_mode, MODE_LOGIN_SHELL)) {
/* Pull in vars we want to keep from the old environment. */
for (ep = old_envp; *ep; ep++) {
int keepit;
@@ -517,6 +522,11 @@ rebuild_env(int noexec)
if (!ISSET(didvar, DID_USERNAME))
sudo_setenv("USERNAME", user_name, FALSE);
}
/* If we didn't keep HOME, reset it based on target user. */
if (!ISSET(didvar, KEPT_HOME))
reset_home = TRUE;
/*
* Set MAIL to target user in -i mode or if MAIL is not preserved
* from user's environment.
@@ -530,13 +540,6 @@ rebuild_env(int noexec)
sudo_putenv(cp, ISSET(didvar, DID_MAIL), TRUE);
}
} else {
/* Reset HOME based on target user if configured to. */
if (ISSET(sudo_mode, MODE_RUN)) {
if (def_always_set_home || ISSET(sudo_mode, MODE_RESET_HOME) ||
(ISSET(sudo_mode, MODE_SHELL) && def_set_home))
reset_home = TRUE;
}
/*
* Copy environ entries as long as they don't match env_delete or
* env_check.
@@ -586,7 +589,7 @@ rebuild_env(int noexec)
}
/* Set $HOME to target user if not preserving user's value. */
if (reset_home && !ISSET(didvar, KEPT_HOME))
if (reset_home)
sudo_setenv("HOME", runas_pw->pw_dir, TRUE);
/* Provide default values for $TERM and $PATH if they are not set. */