From bf31775618b964a8228b10f8cf004541cb7b0ce7 Mon Sep 17 00:00:00 2001 From: Bdale Garbee Date: Thu, 7 Oct 2010 15:59:19 -0600 Subject: [PATCH] fix for 596493 from upstream --- debian/changelog | 4 +++- env.c | 26 +++++++++++++++----------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/debian/changelog b/debian/changelog index 687948b..42313dd 100644 --- a/debian/changelog +++ b/debian/changelog @@ -2,10 +2,12 @@ sudo (1.7.4p4-4) unstable; urgency=low * patch from upstream to resolve problem always prompting for a password when run without a tty, closes: #599376 + * patch from upstream to resolve interoperability problem between HOME in + env_keep and the -H flag, closes: #596493 * change path syntax to avoid tar error when /var/run/sudo exists but is empty, closes: #598877 - -- Bdale Garbee Tue, 21 Sep 2010 23:53:08 -0600 + -- Bdale Garbee Thu, 07 Oct 2010 15:59:06 -0600 sudo (1.7.4p4-3) unstable; urgency=low diff --git a/env.c b/env.c index 739631f..2be75d8 100644 --- a/env.c +++ b/env.c @@ -608,10 +608,16 @@ rebuild_env(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 | MODE_LOGIN_SHELL) || + (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; @@ -696,6 +702,11 @@ rebuild_env(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. @@ -709,13 +720,6 @@ rebuild_env(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. @@ -765,7 +769,7 @@ rebuild_env(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. */ -- 2.30.2