From 4eb04f3974b9245e31a59b0910c7b81ac5bc0496 Mon Sep 17 00:00:00 2001 From: Tomas Mraz Date: Mon, 20 Jan 2014 17:12:53 +0100 Subject: pam_limits: detect and ignore stale utmp entries Original idea by Christopher Hailey * modules/pam_limits/pam_limits.c (check_logins): Use kill() to detect if pid of the utmp entry is still running and ignore the entry if it is not. --- modules/pam_limits/pam_limits.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/modules/pam_limits/pam_limits.c b/modules/pam_limits/pam_limits.c index 8bf3b9bb..e2bc8e18 100644 --- a/modules/pam_limits/pam_limits.c +++ b/modules/pam_limits/pam_limits.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -279,6 +280,12 @@ check_logins (pam_handle_t *pamh, const char *name, int limit, int ctrl, && !pam_modutil_user_in_group_nam_nam(pamh, ut->UT_USER, pl->login_group)) { continue; } + if (kill(ut->ut_pid, 0) == -1 && errno == ESRCH) { + /* process does not exist anymore */ + pam_syslog(pamh, LOG_WARNING, + "Stale utmp entry (pid %d) for '%s' ignored", ut->ut_pid, name); + continue; + } } if (++count > limit) { break; -- cgit v1.2.3