Move tty checks into check_user() so we only do them if we actually

need a password.
This commit is contained in:
Todd C. Miller
2008-11-11 18:28:08 +00:00
parent 8e480f4ae3
commit 3cc3114d92
2 changed files with 22 additions and 22 deletions

17
check.c
View File

@@ -104,6 +104,23 @@ check_user(validated, interactive)
if (!interactive)
errorx(1, "sorry, a password is required to run %s", getprogname());
/* If user specified -A, make sure we have an askpass helper. */
if (ISSET(tgetpass_flags, TGP_ASKPASS)) {
if (user_askpass == NULL)
log_error(NO_MAIL,
"no askpass program specified, try setting SUDO_ASKPASS");
} else {
/* If no tty but DISPLAY is set, use askpass if we have it. */
if (!user_ttypath && !ISSET(tgetpass_flags, TGP_STDIN)) {
if (user_askpass && user_display && *user_display != '\0') {
SET(tgetpass_flags, TGP_ASKPASS);
} else if (!def_visiblepw) {
log_error(NO_MAIL,
"no tty present and no askpass program specified");
}
}
}
if (!ISSET(tgetpass_flags, TGP_ASKPASS))
lecture(status);

27
sudo.c
View File

@@ -388,6 +388,10 @@ main(argc, argv, envp)
(void) close(fd);
}
/* Use askpass value from sudoers unless user specified their own. */
if (def_askpass && !user_askpass)
user_askpass = def_askpass;
/* User may have overridden environment resetting via the -E flag. */
if (ISSET(sudo_mode, MODE_PRESERVE_ENV) && def_setenv)
def_env_reset = FALSE;
@@ -399,29 +403,8 @@ main(argc, argv, envp)
auth_pw = get_authpw();
/* Require a password if sudoers says so. */
if (def_authenticate) {
/* Use askpass value from sudoers unless user specified their own. */
if (def_askpass && !user_askpass)
user_askpass = def_askpass;
/* If user specified -A, make sure we have an askpass helper. */
if (ISSET(tgetpass_flags, TGP_ASKPASS)) {
if (user_askpass == NULL)
log_error(NO_MAIL,
"no askpass program specified, try setting SUDO_ASKPASS");
} else {
/* If no tty but DISPLAY is set, use askpass if we have it. */
if (!user_ttypath && !ISSET(tgetpass_flags, TGP_STDIN)) {
if (user_askpass && user_display && *user_display != '\0') {
SET(tgetpass_flags, TGP_ASKPASS);
} else if (!def_visiblepw) {
log_error(NO_MAIL,
"no tty present and no askpass program specified");
}
}
}
if (def_authenticate)
check_user(validated, !ISSET(sudo_mode, MODE_NONINTERACTIVE));
}
/* 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 */