From 100e6910fb1df6b3b7165a8b4b5107ad71538c14 Mon Sep 17 00:00:00 2001 From: dtucker Date: Wed, 14 Jan 2004 11:14:04 +0000 Subject: [PATCH] - (dtucker) [auth-pam.c] Have monitor die if PAM authentication thread exits unexpectedly. with & ok djm@ --- ChangeLog | 4 ++++ auth-pam.c | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/ChangeLog b/ChangeLog index 58ad89c3..0759caac 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +20040114 + - (dtucker) [auth-pam.c] Have monitor die if PAM authentication thread exits + unexpectedly. with & ok djm@ + 20040113 - (dtucker) [auth-pam.c] Relocate struct pam_ctxt and prototypes. No functional changes. diff --git a/auth-pam.c b/auth-pam.c index 80e00c3b..3b363c26 100644 --- a/auth-pam.c +++ b/auth-pam.c @@ -86,6 +86,23 @@ static struct pam_ctxt *cleanup_ctxt; * Simulate threads with processes. */ +static int sshpam_thread_status = -1; +static mysig_t sshpam_oldsig; + +static void +sshpam_sigchld_handler(int sig) +{ + if (waitpid(cleanup_ctxt->pam_thread, &sshpam_thread_status, 0) == -1) + return; /* couldn't wait for process */ + if (WIFSIGNALED(sshpam_thread_status) && + WTERMSIG(sshpam_thread_status) == SIGTERM) + return; /* terminated by pthread_cancel */ + if (!WIFEXITED(sshpam_thread_status)) + fatal("PAM: authentication thread exited unexpectedly"); + if (WEXITSTATUS(sshpam_thread_status) != 0) + fatal("PAM: authentication thread exited uncleanly"); +} + static void pthread_exit(void *value __unused) { @@ -107,6 +124,7 @@ pthread_create(sp_pthread_t *thread, const void *attr __unused, _exit(1); default: *thread = pid; + sshpam_oldsig = signal(SIGCHLD, sshpam_sigchld_handler); return (0); } } @@ -122,6 +140,9 @@ pthread_join(sp_pthread_t thread, void **value __unused) { int status; + if (sshpam_thread_status != -1) + return (sshpam_thread_status); + signal(SIGCHLD, sshpam_oldsig); waitpid(thread, &status, 0); return (status); } -- 2.45.1