Avoid setting LOGNAME, USER and USERNAME variables twice when

set_logname is enabled.
This commit is contained in:
Todd C. Miller
2012-09-11 10:24:20 -04:00
parent 6beab19148
commit 40d0492a42

View File

@@ -835,12 +835,15 @@ rebuild_env(void)
} else { } else {
if (!ISSET(didvar, DID_SHELL)) if (!ISSET(didvar, DID_SHELL))
sudo_setenv2("SHELL", sudo_user.pw->pw_shell, false, true); sudo_setenv2("SHELL", sudo_user.pw->pw_shell, false, true);
if (!ISSET(didvar, DID_LOGNAME)) /* We will set LOGNAME later in the !def_set_logname case. */
sudo_setenv2("LOGNAME", user_name, false, true); if (!def_set_logname) {
if (!ISSET(didvar, DID_USER)) if (!ISSET(didvar, DID_LOGNAME))
sudo_setenv2("USER", user_name, false, true); sudo_setenv2("LOGNAME", user_name, false, true);
if (!ISSET(didvar, DID_USERNAME)) if (!ISSET(didvar, DID_USER))
sudo_setenv2("USERNAME", user_name, false, true); sudo_setenv2("USER", user_name, false, true);
if (!ISSET(didvar, DID_USERNAME))
sudo_setenv2("USERNAME", user_name, false, true);
}
} }
/* If we didn't keep HOME, reset it based on target user. */ /* If we didn't keep HOME, reset it based on target user. */
@@ -892,8 +895,8 @@ rebuild_env(void)
/* /*
* Set $USER, $LOGNAME and $USERNAME to target if "set_logname" is not * Set $USER, $LOGNAME and $USERNAME to target if "set_logname" is not
* disabled. We skip this if we are running a login shell (because * disabled. We skip this if we are running a login shell (because
* they have already been set them) or sudoedit (because we want the * they have already been set) or sudoedit (because we want the editor
* editor to find the user's startup files). * to find the invoking user's startup files).
*/ */
if (def_set_logname && !ISSET(sudo_mode, MODE_LOGIN_SHELL|MODE_EDIT)) { if (def_set_logname && !ISSET(sudo_mode, MODE_LOGIN_SHELL|MODE_EDIT)) {
if (!ISSET(didvar, KEPT_LOGNAME)) if (!ISSET(didvar, KEPT_LOGNAME))