static void set_loginclass(struct passwd *);
static void set_runasgr(const char *);
static void set_runaspw(const char *);
+static bool tty_present(void);
/*
* Globals
}
/* Bail if a tty is required and we don't have one. */
- if (def_requiretty && user_ttypath == NULL) {
+ if (def_requiretty && !tty_present()) {
audit_failure(NewArgv, N_("no tty"));
warningx(_("sorry, you must have a tty to run sudo"));
goto bad;
/* STUB */
}
#endif /* USE_ADMIN_FLAG */
+
+static bool
+tty_present(void)
+{
+#if defined(HAVE_STRUCT_KINFO_PROC2_P_TDEV) || defined(HAVE_STRUCT_KINFO_PROC_P_TDEV) || defined(HAVE_STRUCT_KINFO_PROC_KI_TDEV) || defined(HAVE_STRUCT_KINFO_PROC_KP_EPROC_E_TDEV) || defined(HAVE_STRUCT_PSINFO_PR_TTYDEV) || defined(HAVE_PSTAT_GETPROC) || defined(__linux__)
+ return user_ttypath != NULL;
+#else
+ int fd = open(_PATH_TTY, O_RDWR|O_NOCTTY);
+ if (fd != -1)
+ close(fd);
+ return fd != -1;
+#endif
+}