Blame SOURCES/pam-1.1.3-faillock-screensaver.patch

904b9f
diff -up Linux-PAM-1.1.3/modules/pam_faillock/faillock.c.screensaver Linux-PAM-1.1.3/modules/pam_faillock/faillock.c
904b9f
--- Linux-PAM-1.1.3/modules/pam_faillock/faillock.c.screensaver	2010-11-10 11:46:07.000000000 +0100
904b9f
+++ Linux-PAM-1.1.3/modules/pam_faillock/faillock.c	2010-11-10 11:46:07.000000000 +0100
904b9f
@@ -41,13 +41,14 @@
904b9f
 #include <sys/types.h>
904b9f
 #include <sys/stat.h>
904b9f
 #include <sys/file.h>
904b9f
+#include <sys/stat.h>
904b9f
 #include <fcntl.h>
904b9f
 #include <security/pam_modutil.h>
904b9f
 
904b9f
 #include "faillock.h"
904b9f
 
904b9f
 int
904b9f
-open_tally (const char *dir, const char *user, int create)
904b9f
+open_tally (const char *dir, const char *user, uid_t uid, int create)
904b9f
 {
904b9f
 	char *path;
904b9f
 	int flags = O_RDWR;
904b9f
@@ -69,8 +70,18 @@ open_tally (const char *dir, const char 
904b9f
 
904b9f
 	fd = open(path, flags, 0600);
904b9f
 
904b9f
-	if (fd != -1)
904b9f
+	free(path);
904b9f
+
904b9f
+	if (fd != -1) {
904b9f
+		struct stat st;
904b9f
+
904b9f
 		while (flock(fd, LOCK_EX) == -1 && errno == EINTR);
904b9f
+		if (fstat(fd, &st) == 0) {
904b9f
+			if (st.st_uid != uid) {
904b9f
+				fchown(fd, uid, -1);
904b9f
+			}
904b9f
+		}
904b9f
+	}
904b9f
 
904b9f
 	return fd;
904b9f
 }
904b9f
diff -up Linux-PAM-1.1.3/modules/pam_faillock/faillock.h.screensaver Linux-PAM-1.1.3/modules/pam_faillock/faillock.h
904b9f
--- Linux-PAM-1.1.3/modules/pam_faillock/faillock.h.screensaver	2010-11-10 11:46:07.000000000 +0100
904b9f
+++ Linux-PAM-1.1.3/modules/pam_faillock/faillock.h	2010-11-10 11:46:07.000000000 +0100
904b9f
@@ -45,6 +45,7 @@
904b9f
 #define _FAILLOCK_H
904b9f
 
904b9f
 #include <stdint.h>
904b9f
+#include <sys/types.h>
904b9f
 
904b9f
 #define TALLY_STATUS_VALID     0x1       /* the tally file entry is valid */
904b9f
 #define TALLY_STATUS_RHOST     0x2       /* the source is rhost */
904b9f
@@ -65,7 +66,7 @@ struct tally_data {
904b9f
 
904b9f
 #define FAILLOCK_DEFAULT_TALLYDIR "/var/run/faillock"
904b9f
 
904b9f
-int open_tally(const char *dir, const char *user, int create);
904b9f
+int open_tally(const char *dir, const char *user, uid_t uid, int create);
904b9f
 int read_tally(int fd, struct tally_data *tallies);
904b9f
 int update_tally(int fd, struct tally_data *tallies);
904b9f
 #endif
904b9f
diff -up Linux-PAM-1.1.3/modules/pam_faillock/main.c.screensaver Linux-PAM-1.1.3/modules/pam_faillock/main.c
904b9f
--- Linux-PAM-1.1.3/modules/pam_faillock/main.c.screensaver	2010-11-10 11:46:07.000000000 +0100
904b9f
+++ Linux-PAM-1.1.3/modules/pam_faillock/main.c	2010-11-10 11:46:07.000000000 +0100
904b9f
@@ -106,8 +106,11 @@ do_user(struct options *opts, const char
904b9f
 	int fd;
904b9f
 	int rv;
904b9f
 	struct tally_data tallies;
904b9f
+	struct passwd *pwd;
904b9f
 
904b9f
-	fd = open_tally(opts->dir, user, 0);
904b9f
+	pwd = getpwnam(user);
904b9f
+
904b9f
+	fd = open_tally(opts->dir, user, pwd != NULL ? pwd->pw_uid : 0, 0);
904b9f
 
904b9f
 	if (fd == -1) {
904b9f
 		if (errno == ENOENT) {
904b9f
@@ -134,9 +137,8 @@ do_user(struct options *opts, const char
904b9f
 #ifdef HAVE_LIBAUDIT
904b9f
 		}
904b9f
 		if ((audit_fd=audit_open()) >= 0) {
904b9f
-			struct passwd *pwd;
904b9f
 
904b9f
-			if ((pwd=getpwnam(user)) != NULL) {
904b9f
+			if (pwd != NULL) {
904b9f
 				snprintf(buf, sizeof(buf), "faillock reset uid=%u",
904b9f
 					pwd->pw_uid);
904b9f
 				audit_log_user_message(audit_fd, AUDIT_USER_ACCT,
904b9f
diff -up Linux-PAM-1.1.3/modules/pam_faillock/pam_faillock.c.screensaver Linux-PAM-1.1.3/modules/pam_faillock/pam_faillock.c
904b9f
--- Linux-PAM-1.1.3/modules/pam_faillock/pam_faillock.c.screensaver	2010-11-10 11:46:07.000000000 +0100
904b9f
+++ Linux-PAM-1.1.3/modules/pam_faillock/pam_faillock.c	2010-11-10 11:46:07.000000000 +0100
904b9f
@@ -213,7 +213,7 @@ check_tally(pam_handle_t *pamh, struct o
904b9f
 
904b9f
 	opts->now = time(NULL);
904b9f
 
904b9f
-	tfd = open_tally(opts->dir, opts->user, 0);
904b9f
+	tfd = open_tally(opts->dir, opts->user, opts->uid, 0);
904b9f
 
904b9f
 	*fd = tfd;
904b9f
 
904b9f
@@ -289,9 +289,14 @@ reset_tally(pam_handle_t *pamh, struct o
904b9f
 {
904b9f
 	int rv;
904b9f
 
904b9f
-	while ((rv=ftruncate(*fd, 0)) == -1 && errno == EINTR);
904b9f
-	if (rv == -1) {
904b9f
-		pam_syslog(pamh, LOG_ERR, "Error clearing the tally file for %s: %m", opts->user);
904b9f
+	if (*fd == -1) {
904b9f
+		*fd = open_tally(opts->dir, opts->user, opts->uid, 1);
904b9f
+	}
904b9f
+	else {
904b9f
+		while ((rv=ftruncate(*fd, 0)) == -1 && errno == EINTR);
904b9f
+		if (rv == -1) {
904b9f
+			pam_syslog(pamh, LOG_ERR, "Error clearing the tally file for %s: %m", opts->user);
904b9f
+		}
904b9f
 	}
904b9f
 }
904b9f
 
904b9f
@@ -306,7 +311,7 @@ write_tally(pam_handle_t *pamh, struct o
904b9f
 	const void *source = NULL;
904b9f
 
904b9f
 	if (*fd == -1) {
904b9f
-		*fd = open_tally(opts->dir, opts->user, 1);
904b9f
+		*fd = open_tally(opts->dir, opts->user, opts->uid, 1);
904b9f
 	}
904b9f
 	if (*fd == -1) {
904b9f
 		if (errno == EACCES) {
904b9f
@@ -463,7 +468,7 @@ pam_sm_authenticate(pam_handle_t *pamh, 
904b9f
 
904b9f
 		case FAILLOCK_ACTION_AUTHSUCC:
904b9f
 			rv = check_tally(pamh, &opts, &tallies, &fd;;
904b9f
-			if (rv == PAM_SUCCESS && fd != -1) {
904b9f
+			if (rv == PAM_SUCCESS) {
904b9f
 				reset_tally(pamh, &opts, &fd;;
904b9f
 			}
904b9f
                         break;
904b9f
@@ -511,10 +516,8 @@ pam_sm_acct_mgmt(pam_handle_t *pamh, int
904b9f
 		return rv;
904b9f
 	}
904b9f
 
904b9f
-	check_tally(pamh, &opts, &tallies, &fd;;
904b9f
-	if (fd != -1) {
904b9f
-		reset_tally(pamh, &opts, &fd;;
904b9f
-	}
904b9f
+	check_tally(pamh, &opts, &tallies, &fd;; /* for auditing */
904b9f
+	reset_tally(pamh, &opts, &fd;;
904b9f
 
904b9f
 	tally_cleanup(&tallies, fd);
904b9f
 
904b9f
diff -up Linux-PAM-1.1.3/modules/pam_faillock/pam_faillock.8.xml.screensaver Linux-PAM-1.1.3/modules/pam_faillock/pam_faillock.8.xml
904b9f
--- Linux-PAM-1.1.3/modules/pam_faillock/pam_faillock.8.xml.screensaver	2010-11-10 11:46:07.000000000 +0100
904b9f
+++ Linux-PAM-1.1.3/modules/pam_faillock/pam_faillock.8.xml	2010-11-10 11:47:14.000000000 +0100
904b9f
@@ -277,13 +277,9 @@
904b9f
       from the <emphasis>pam_tally2</emphasis> module setup.
904b9f
     </para>
904b9f
     <para>
904b9f
-      There is no setuid wrapper for access to the data file such as when the
904b9f
-      <emphasis remap='B'>pam_faillock.so</emphasis> module is called from
904b9f
-      a screensaver. As this would make it impossible to share PAM configuration
904b9f
-      with such services the following workaround is used: If the data file
904b9f
-      cannot be opened because of insufficient permissions
904b9f
-      (<errorcode>EACCES</errorcode>) the module returns
904b9f
-      <errorcode>PAM_SUCCESS</errorcode>.
904b9f
+      The individual files with the failure records are created as owned by
904b9f
+      the user. This allows <emphasis remap='B'>pam_faillock.so</emphasis> module
904b9f
+      to work correctly when it is called from a screensaver.
904b9f
     </para>
904b9f
     <para>
904b9f
       Note that using the module in <option>preauth</option> without the