From: Todd C. Miller Date: Tue, 11 Sep 2012 14:26:26 +0000 (-0400) Subject: Avoid setting LOGNAME, USER and USERNAME variables twice when X-Git-Tag: SUDO_1_7_10p1~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=49ed97f36068528bb396c4a33a9e75e8986e8457;p=sudo Avoid setting LOGNAME, USER and USERNAME variables twice when set_logname is enabled. --HG-- branch : 1.7 --- diff --git a/env.c b/env.c index c9279b9eb..52dff6db1 100644 --- a/env.c +++ b/env.c @@ -775,12 +775,15 @@ rebuild_env(noexec) } else { if (!ISSET(didvar, DID_SHELL)) sudo_setenv("SHELL", sudo_user.pw->pw_shell, FALSE); - if (!ISSET(didvar, DID_LOGNAME)) - sudo_setenv("LOGNAME", user_name, FALSE); - if (!ISSET(didvar, DID_USER)) - sudo_setenv("USER", user_name, FALSE); - if (!ISSET(didvar, DID_USERNAME)) - sudo_setenv("USERNAME", user_name, FALSE); + /* We will set LOGNAME later in the !def_set_logname case. */ + if (!def_set_logname) { + if (!ISSET(didvar, DID_LOGNAME)) + sudo_setenv("LOGNAME", user_name, FALSE); + if (!ISSET(didvar, DID_USER)) + sudo_setenv("USER", user_name, FALSE); + if (!ISSET(didvar, DID_USERNAME)) + sudo_setenv("USERNAME", user_name, FALSE); + } } /* If we didn't keep HOME, reset it based on target user. */ @@ -841,8 +844,8 @@ rebuild_env(noexec) /* * Set $USER, $LOGNAME and $USERNAME to target if "set_logname" is not * disabled. We skip this if we are running a login shell (because - * they have already been set them) or sudoedit (because we want the - * editor to find the user's startup files). + * they have already been set) or sudoedit (because we want the editor + * to find the invoking user's startup files). */ if (def_set_logname && !ISSET(sudo_mode, MODE_LOGIN_SHELL|MODE_EDIT)) { if (!ISSET(didvar, KEPT_LOGNAME))