From ec97bfb838ff45a1f7c3a640cb29f7eeb2718db3 Mon Sep 17 00:00:00 2001 From: Kyle Manna Date: Thu, 25 Sep 2014 22:22:17 -0700 Subject: [PATCH] vlock: Handle tty dying * Gracefully exit when the parent tty dies. * Typical causes of death include closing: * terminal tab or window * shell * ssh session * If no tty exists, I'm not sure what vlock would be locking. Signed-off-by: Kyle Manna --- src/vlock/auth.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/vlock/auth.c b/src/vlock/auth.c index da135ce..79b1319 100644 --- a/src/vlock/auth.c +++ b/src/vlock/auth.c @@ -67,6 +67,17 @@ get_password (pam_handle_t * pamh, const char *username, const char *tty) int rc; const char *msg; + /* Ensure that the process has a tty. If the parent had died, + * stdin/out are likely no longer valid and PAM will fail continuously. + */ + if (isatty(STDIN_FILENO) != 1) + { + syslog (LOG_INFO, + "TTY %s disappeared for %s by (uid=%u)", + tty, username, uid); + return EXIT_FAILURE; + } + if (!pamh) { pamh = init_pam (username, tty, 1); -- 2.1.1