From: Todd C. Miller Date: Wed, 27 Oct 2004 16:16:23 +0000 (+0000) Subject: Only reset sudo_user.pw based on SUDO_USER environment variables for X-Git-Tag: SUDO_1_7_0~847 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=29fc2c9475ec418cd54bddecc344cc6234e8ca7e;p=sudo Only reset sudo_user.pw based on SUDO_USER environment variables for real commands and sudoedit. This avoids a confusing message when a user tries "sudo -l" or "sudo -v" and is denied. --- diff --git a/sudo.c b/sudo.c index 60ec110f9..18d12aea7 100644 --- a/sudo.c +++ b/sudo.c @@ -338,13 +338,15 @@ main(argc, argv, envp) /* If run as root with SUDO_USER set, set sudo_user.pw to that user. */ /* XXX - causes confusion when root is not listed in sudoers */ - if (user_uid == 0 && prev_user != NULL && strcmp(prev_user, "root") != 0) { - struct passwd *pw; + if (sudo_mode & (MODE_RUN | MODE_EDIT) && prev_user != NULL) { + if (user_uid == 0 && strcmp(prev_user, "root") != 0) { + struct passwd *pw; - if ((pw = sudo_getpwnam(prev_user)) != NULL) { - free(sudo_user.pw); - sudo_user.pw = pw; - } + if ((pw = sudo_getpwnam(prev_user)) != NULL) { + free(sudo_user.pw); + sudo_user.pw = pw; + } + } } /* Build a new environment that avoids any nasty bits if we have a cmnd. */