From b18eede6223ee3cc77e8768be3a0d287536b0398 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Tue, 25 Nov 2008 17:01:34 +0000 Subject: [PATCH] Even if neither stdin nor stdout are ttys we may still have /dev/tty available to us. --- check.c | 4 ++-- sudo.h | 1 + tgetpass.c | 10 ++++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/check.c b/check.c index e1573e453..ad4074bdb 100644 --- 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 6987988d5..d3b06367a 100644 --- 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 diff --git a/tgetpass.c b/tgetpass.c index d0e3d840f..dc51cf1b5 100644 --- a/tgetpass.c +++ b/tgetpass.c @@ -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); +} -- 2.40.0