]> granicus.if.org Git - sudo/commitdiff
In tty_present(), check for /dev/tty if sudo was unable to get the tty name.
authorTodd C. Miller <Todd.Miller@sudo.ws>
Thu, 20 Jun 2019 02:32:22 +0000 (20:32 -0600)
committerTodd C. Miller <Todd.Miller@sudo.ws>
Thu, 20 Jun 2019 02:32:22 +0000 (20:32 -0600)
For requiretty it is enough to check that /dev/tty is available.
If sudo can't get the tty from the kernel (missing /proc?) that is OK.

plugins/sudoers/sudoers.c

index a809e854655f341bc03bac38861acd8bfd6a521a..5ec1bc3d35da7f68740d1e99fc452caefcdf8016 100644 (file)
@@ -1272,12 +1272,13 @@ create_admin_success_flag(void)
 static bool
 tty_present(void)
 {
-#if defined(HAVE_KINFO_PROC2_NETBSD) || defined(HAVE_KINFO_PROC_OPENBSD) || defined(HAVE_KINFO_PROC_FREEBSD) || defined(HAVE_KINFO_PROC_44BSD) || defined(HAVE_STRUCT_PSINFO_PR_TTYDEV) || defined(HAVE_PSTAT_GETPROC) || defined(__linux__)
-    return user_ttypath != NULL;
-#else
-    int fd = open(_PATH_TTY, O_RDWR);
-    if (fd != -1)
+    debug_decl(tty_present, SUDOERS_DEBUG_PLUGIN)
+    
+    if (user_ttypath == NULL) {
+       int fd = open(_PATH_TTY, O_RDWR);
+       if (fd == -1)
+           debug_return_bool(false);
        close(fd);
-    return fd != -1;
-#endif
+    }
+    debug_return_bool(true);
 }