Even if neither stdin nor stdout are ttys we may still have /dev/tty

available to us.
This commit is contained in:
Todd C. Miller
2008-11-25 17:01:34 +00:00
parent 30296d0500
commit b18eede622
3 changed files with 13 additions and 2 deletions

View File

@@ -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) {

1
sudo.h
View File

@@ -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

View 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);
}