]> granicus.if.org Git - sudo/commitdiff
Move tty checks into check_user() so we only do them if we actually
authorTodd C. Miller <Todd.Miller@courtesan.com>
Tue, 11 Nov 2008 18:28:08 +0000 (18:28 +0000)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Tue, 11 Nov 2008 18:28:08 +0000 (18:28 +0000)
need a password.

check.c
sudo.c

diff --git a/check.c b/check.c
index e12aef7ce12fcca431bf5c2c5f6b2315d6278930..e1573e453a3202ce325b3f72d135baeb7a925697 100644 (file)
--- 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 d292c6c8f7ca0ab7fa45a9364da1424d82a485ab..3b965da74106accc9de85d8a8098bfb1a3174ea4 100644 (file)
--- 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 */