Blame SOURCES/pam-1.1.8-limits-check-process.patch

b10636
diff -up Linux-PAM-1.1.8/modules/pam_limits/pam_limits.c.check-process Linux-PAM-1.1.8/modules/pam_limits/pam_limits.c
b10636
--- Linux-PAM-1.1.8/modules/pam_limits/pam_limits.c.check-process	2013-06-18 16:11:21.000000000 +0200
b10636
+++ Linux-PAM-1.1.8/modules/pam_limits/pam_limits.c	2014-09-10 16:39:36.263256066 +0200
b10636
@@ -27,6 +27,7 @@
b10636
 #include <errno.h>
b10636
 #include <syslog.h>
b10636
 #include <stdarg.h>
b10636
+#include <signal.h>
b10636
 #include <sys/types.h>
b10636
 #include <sys/stat.h>
b10636
 #include <sys/resource.h>
b10636
@@ -269,16 +270,27 @@ check_logins (pam_handle_t *pamh, const
b10636
             continue;
b10636
 	}
b10636
         if (!pl->flag_numsyslogins) {
b10636
+	    char user[sizeof(ut->UT_USER) + 1];
b10636
+	    user[0] = '\0';
b10636
+	    strncat(user, ut->UT_USER, sizeof(ut->UT_USER));
b10636
+
b10636
 	    if (((pl->login_limit_def == LIMITS_DEF_USER)
b10636
 	         || (pl->login_limit_def == LIMITS_DEF_GROUP)
b10636
 		 || (pl->login_limit_def == LIMITS_DEF_DEFAULT))
b10636
-		&& strncmp(name, ut->UT_USER, sizeof(ut->UT_USER)) != 0) {
b10636
+		&& strcmp(name, user) != 0) {
b10636
                 continue;
b10636
 	    }
b10636
 	    if ((pl->login_limit_def == LIMITS_DEF_ALLGROUP)
b10636
-		&& !pam_modutil_user_in_group_nam_nam(pamh, ut->UT_USER, pl->login_group)) {
b10636
+		&& !pam_modutil_user_in_group_nam_nam(pamh, user, pl->login_group)) {
b10636
                 continue;
b10636
 	    }
b10636
+	    if (kill(ut->ut_pid, 0) == -1 && errno == ESRCH) {
b10636
+		/* process does not exist anymore */
b10636
+		pam_syslog(pamh, LOG_WARNING,
b10636
+			   "Stale utmp entry (pid %d) for '%s' ignored",
b10636
+			   ut->ut_pid, user);
b10636
+		continue;
b10636
+	    }
b10636
 	}
b10636
 	if (++count > limit) {
b10636
 	    break;