]> granicus.if.org Git - sudo/commitdiff
Even if neither stdin nor stdout are ttys we may still have /dev/tty
authorTodd C. Miller <Todd.Miller@courtesan.com>
Tue, 25 Nov 2008 17:01:34 +0000 (17:01 +0000)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Tue, 25 Nov 2008 17:01:34 +0000 (17:01 +0000)
available to us.

check.c
sudo.h
tgetpass.c

diff --git a/check.c b/check.c
index e1573e453a3202ce325b3f72d135baeb7a925697..ad4074bdbb9f2ca2895ca167c66918f2f81e8f4b 100644 (file)
--- a/check.c
+++ b/check.c
@@ -109,9 +109,9 @@ check_user(validated, interactive)
            if (user_askpass == NULL)
                log_error(NO_MAIL,
                    "no askpass program specified, try setting SUDO_ASKPASS");
-       } else {
+       } else if (!ISSET(tgetpass_flags, TGP_STDIN)) {
            /* If no tty but DISPLAY is set, use askpass if we have it. */
-           if (!user_ttypath && !ISSET(tgetpass_flags, TGP_STDIN)) {
+           if (!user_ttypath && !tty_present()) {
                if (user_askpass && user_display && *user_display != '\0') {
                    SET(tgetpass_flags, TGP_ASKPASS);
                } else if (!def_visiblepw) {
diff --git a/sudo.h b/sudo.h
index 6987988d56f5ba1937cd5bcaa0d8132c6da7175d..d3b06367aa3e36cce166bd406a4ebd4c4e95f2a6 100644 (file)
--- a/sudo.h
+++ b/sudo.h
@@ -240,6 +240,7 @@ int mkstemp         __P((char *));
 char *sudo_goodpath    __P((const char *, struct stat *));
 char *tgetpass         __P((const char *, int, int));
 int find_path          __P((char *, char **, struct stat *, char *));
+int tty_present                __P((void));
 void check_user                __P((int, int));
 void verify_user       __P((struct passwd *, char *));
 #ifdef HAVE_LDAP
index d0e3d840f2cde0ff402b60c5ee1635e7878f6024..dc51cf1b574ea97cd9ffd0555e40e5101a9d2e81 100644 (file)
@@ -309,3 +309,13 @@ handler(s)
     if (s != SIGALRM)
        signo = s;
 }
+
+int
+tty_present()
+{
+    int fd;
+
+    if ((fd = open(_PATH_TTY, O_RDWR|O_NOCTTY)) != -1)
+       close(fd);
+    return(fd != -1);
+}