From: Todd C. Miller Date: Tue, 11 Nov 2008 18:28:08 +0000 (+0000) Subject: Move tty checks into check_user() so we only do them if we actually X-Git-Tag: SUDO_1_7_0~33 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3cc3114d92b13d728e16604b0325b7ad953070df;p=sudo Move tty checks into check_user() so we only do them if we actually need a password. --- diff --git a/check.c b/check.c index e12aef7ce..e1573e453 100644 --- a/check.c +++ b/check.c @@ -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); diff --git a/sudo.c b/sudo.c index d292c6c8f..3b965da74 100644 --- a/sudo.c +++ b/sudo.c @@ -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 */