Blame SOURCES/pam-1.1.1-faillock.patch

904b9f
diff -up Linux-PAM-1.1.1/configure.in.faillock Linux-PAM-1.1.1/configure.in
904b9f
--- Linux-PAM-1.1.1/configure.in.faillock	2010-09-17 15:58:41.000000000 +0200
904b9f
+++ Linux-PAM-1.1.1/configure.in	2010-09-17 15:58:41.000000000 +0200
904b9f
@@ -539,7 +539,7 @@ AC_CONFIG_FILES([Makefile libpam/Makefil
904b9f
 	modules/pam_access/Makefile modules/pam_cracklib/Makefile \
904b9f
         modules/pam_debug/Makefile modules/pam_deny/Makefile \
904b9f
 	modules/pam_echo/Makefile modules/pam_env/Makefile \
904b9f
-	modules/pam_faildelay/Makefile \
904b9f
+	modules/pam_faildelay/Makefile modules/pam_faillock/Makefile \
904b9f
 	modules/pam_filter/Makefile modules/pam_filter/upperLOWER/Makefile \
904b9f
 	modules/pam_ftp/Makefile modules/pam_group/Makefile \
904b9f
 	modules/pam_issue/Makefile modules/pam_keyinit/Makefile \
904b9f
diff -up Linux-PAM-1.1.1/doc/sag/pam_faillock.xml.faillock Linux-PAM-1.1.1/doc/sag/pam_faillock.xml
904b9f
--- Linux-PAM-1.1.1/doc/sag/pam_faillock.xml.faillock	2010-09-17 16:05:56.000000000 +0200
904b9f
+++ Linux-PAM-1.1.1/doc/sag/pam_faillock.xml	2010-09-17 16:08:26.000000000 +0200
904b9f
@@ -0,0 +1,38 @@
904b9f
+
904b9f
+
904b9f
+        "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
904b9f
+<section id='sag-pam_faillock'>
904b9f
+  <title>pam_faillock - temporarily locking access based on failed authentication attempts during an interval</title>
904b9f
+  <cmdsynopsis>
904b9f
+    
904b9f
+     href="../../modules/pam_faillock/pam_faillock.8.xml" xpointer='xpointer(//cmdsynopsis[@id = "pam_faillock-cmdsynopsisauth"]/*)'/>
904b9f
+  </cmdsynopsis>
904b9f
+  <cmdsynopsis>
904b9f
+    
904b9f
+     href="../../modules/pam_faillock/pam_faillock.8.xml" xpointer='xpointer(//cmdsynopsis[@id = "pam_faillock-cmdsynopsisacct"]/*)'/>
904b9f
+  </cmdsynopsis>
904b9f
+  <section id='sag-pam_faillock-description'>
904b9f
+    
904b9f
+     href="../../modules/pam_faillock/pam_faillock.8.xml" xpointer='xpointer(//refsect1[@id = "pam_faillock-description"]/*)'/>
904b9f
+  </section>
904b9f
+  <section id='sag-pam_faillock-options'>
904b9f
+    
904b9f
+     href="../../modules/pam_faillock/pam_faillock.8.xml" xpointer='xpointer(//refsect1[@id = "pam_faillock-options"]/*)'/>
904b9f
+  </section>
904b9f
+  <section id='sag-pam_faillock-types'>
904b9f
+    
904b9f
+     href="../../modules/pam_faillock/pam_faillock.8.xml" xpointer='xpointer(//refsect1[@id = "pam_faillock-types"]/*)'/>
904b9f
+  </section>
904b9f
+  <section id='sag-pam_faillock-return_values'>
904b9f
+    
904b9f
+     href="../../modules/pam_faillock/pam_faillock.8.xml" xpointer='xpointer(//refsect1[@id = "pam_faillock-return_values"]/*)'/>
904b9f
+  </section>
904b9f
+  <section id='sag-pam_faillock-examples'>
904b9f
+    
904b9f
+     href="../../modules/pam_faillock/pam_faillock.8.xml" xpointer='xpointer(//refsect1[@id = "pam_faillock-examples"]/*)'/>
904b9f
+  </section>
904b9f
+  <section id='sag-pam_faillock-author'>
904b9f
+    
904b9f
+     href="../../modules/pam_faillock/pam_faillock.8.xml" xpointer='xpointer(//refsect1[@id = "pam_faillock-author"]/*)'/>
904b9f
+  </section>
904b9f
+</section>
904b9f
diff -up Linux-PAM-1.1.1/modules/Makefile.am.faillock Linux-PAM-1.1.1/modules/Makefile.am
904b9f
--- Linux-PAM-1.1.1/modules/Makefile.am.faillock	2010-09-17 15:58:41.000000000 +0200
904b9f
+++ Linux-PAM-1.1.1/modules/Makefile.am	2010-09-17 15:58:41.000000000 +0200
904b9f
@@ -3,7 +3,7 @@
904b9f
 #
904b9f
 
904b9f
 SUBDIRS = pam_access pam_cracklib pam_debug pam_deny pam_echo \
904b9f
-	pam_chroot pam_console pam_postgresok \
904b9f
+	pam_chroot pam_console pam_postgresok pam_faillock \
904b9f
 	pam_env pam_exec pam_faildelay pam_filter pam_ftp \
904b9f
 	pam_group pam_issue pam_keyinit pam_lastlog pam_limits \
904b9f
 	pam_listfile pam_localuser pam_loginuid pam_mail \
904b9f
diff -up Linux-PAM-1.1.1/modules/pam_faillock/faillock.c.faillock Linux-PAM-1.1.1/modules/pam_faillock/faillock.c
904b9f
--- Linux-PAM-1.1.1/modules/pam_faillock/faillock.c.faillock	2010-09-17 15:58:41.000000000 +0200
904b9f
+++ Linux-PAM-1.1.1/modules/pam_faillock/faillock.c	2010-09-17 15:58:41.000000000 +0200
904b9f
@@ -0,0 +1,147 @@
904b9f
+/*
904b9f
+ * Copyright (c) 2010 Tomas Mraz <tmraz@redhat.com>
904b9f
+ *
904b9f
+ * Redistribution and use in source and binary forms, with or without
904b9f
+ * modification, are permitted provided that the following conditions
904b9f
+ * are met:
904b9f
+ * 1. Redistributions of source code must retain the above copyright
904b9f
+ *    notice, and the entire permission notice in its entirety,
904b9f
+ *    including the disclaimer of warranties.
904b9f
+ * 2. Redistributions in binary form must reproduce the above copyright
904b9f
+ *    notice, this list of conditions and the following disclaimer in the
904b9f
+ *    documentation and/or other materials provided with the distribution.
904b9f
+ * 3. The name of the author may not be used to endorse or promote
904b9f
+ *    products derived from this software without specific prior
904b9f
+ *    written permission.
904b9f
+ *
904b9f
+ * ALTERNATIVELY, this product may be distributed under the terms of
904b9f
+ * the GNU Public License, in which case the provisions of the GPL are
904b9f
+ * required INSTEAD OF the above restrictions.  (This clause is
904b9f
+ * necessary due to a potential bad interaction between the GPL and
904b9f
+ * the restrictions contained in a BSD-style copyright.)
904b9f
+ *
904b9f
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
904b9f
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
904b9f
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
904b9f
+ * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
904b9f
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
904b9f
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
904b9f
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
904b9f
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
904b9f
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
904b9f
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
904b9f
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
904b9f
+ */
904b9f
+
904b9f
+#include "config.h"
904b9f
+#include <string.h>
904b9f
+#include <stdlib.h>
904b9f
+#include <unistd.h>
904b9f
+#include <errno.h>
904b9f
+#include <sys/types.h>
904b9f
+#include <sys/stat.h>
904b9f
+#include <sys/file.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
+{
904b9f
+	char *path;
904b9f
+	int flags = O_RDWR;
904b9f
+	int fd;
904b9f
+
904b9f
+	if (strstr(user, "../") != NULL)
904b9f
+	/* just a defensive programming as the user must be a
904b9f
+	 * valid user on the system anyway
904b9f
+	 */
904b9f
+		return -1;
904b9f
+	path = malloc(strlen(dir) + strlen(user) + 2);
904b9f
+	if (path == NULL)
904b9f
+		return -1;
904b9f
+
904b9f
+	strcpy(path, dir);
904b9f
+	if (*dir && dir[strlen(dir) - 1] != '/') {
904b9f
+		strcat(path, "/");
904b9f
+	}
904b9f
+	strcat(path, user);
904b9f
+
904b9f
+	if (create) {
904b9f
+		flags |= O_CREAT;
904b9f
+	}
904b9f
+
904b9f
+	fd = open(path, flags, 0600);
904b9f
+
904b9f
+	if (fd != -1)
904b9f
+		while (flock(fd, LOCK_EX) == -1 && errno == EINTR);
904b9f
+
904b9f
+	return fd;
904b9f
+}
904b9f
+
904b9f
+#define CHUNK_SIZE (64 * sizeof(struct tally))
904b9f
+#define MAX_RECORDS 1024
904b9f
+
904b9f
+int
904b9f
+read_tally(int fd, struct tally_data *tallies)
904b9f
+{
904b9f
+	void *data = NULL, *newdata;
904b9f
+	unsigned int count = 0;
904b9f
+	ssize_t chunk = 0;
904b9f
+
904b9f
+	do {
904b9f
+		newdata = realloc(data, count * sizeof(struct tally) + CHUNK_SIZE);
904b9f
+		if (newdata == NULL) {
904b9f
+			free(data);
904b9f
+			return -1;
904b9f
+		}
904b9f
+
904b9f
+		data = newdata;
904b9f
+
904b9f
+		chunk = pam_modutil_read(fd, (char *)data + count * sizeof(struct tally), CHUNK_SIZE);
904b9f
+		if (chunk < 0) {
904b9f
+			free(data);
904b9f
+			return -1;
904b9f
+		}
904b9f
+
904b9f
+		count += chunk/sizeof(struct tally);
904b9f
+
904b9f
+		if (count >= MAX_RECORDS)
904b9f
+			break;
904b9f
+	}
904b9f
+	while (chunk == CHUNK_SIZE); 
904b9f
+
904b9f
+	tallies->records = data;
904b9f
+	tallies->count = count;
904b9f
+
904b9f
+	return 0;
904b9f
+}
904b9f
+
904b9f
+int
904b9f
+update_tally(int fd, struct tally_data *tallies)
904b9f
+{
904b9f
+	void *data = tallies->records;
904b9f
+	unsigned int count = tallies->count;
904b9f
+	ssize_t chunk;
904b9f
+
904b9f
+	if (tallies->count > MAX_RECORDS) {
904b9f
+		data = tallies->records + (count - MAX_RECORDS);
904b9f
+		count = MAX_RECORDS;
904b9f
+	}
904b9f
+
904b9f
+	if (lseek(fd, 0, SEEK_SET) == (off_t)-1) {
904b9f
+		return -1;
904b9f
+	}
904b9f
+
904b9f
+	chunk = pam_modutil_write(fd, data, count * sizeof(struct tally));
904b9f
+
904b9f
+	if (chunk != (ssize_t)(count * sizeof(struct tally))) {
904b9f
+		return -1;
904b9f
+	}
904b9f
+
904b9f
+	if (ftruncate(fd, count * sizeof(struct tally)) == -1)
904b9f
+		return -1;
904b9f
+
904b9f
+	return 0;
904b9f
+}
904b9f
diff -up Linux-PAM-1.1.1/modules/pam_faillock/faillock.h.faillock Linux-PAM-1.1.1/modules/pam_faillock/faillock.h
904b9f
--- Linux-PAM-1.1.1/modules/pam_faillock/faillock.h.faillock	2010-09-17 15:58:41.000000000 +0200
904b9f
+++ Linux-PAM-1.1.1/modules/pam_faillock/faillock.h	2010-09-17 15:58:41.000000000 +0200
904b9f
@@ -0,0 +1,72 @@
904b9f
+/*
904b9f
+ * Copyright (c) 2010 Tomas Mraz <tmraz@redhat.com>
904b9f
+ *
904b9f
+ * Redistribution and use in source and binary forms, with or without
904b9f
+ * modification, are permitted provided that the following conditions
904b9f
+ * are met:
904b9f
+ * 1. Redistributions of source code must retain the above copyright
904b9f
+ *    notice, and the entire permission notice in its entirety,
904b9f
+ *    including the disclaimer of warranties.
904b9f
+ * 2. Redistributions in binary form must reproduce the above copyright
904b9f
+ *    notice, this list of conditions and the following disclaimer in the
904b9f
+ *    documentation and/or other materials provided with the distribution.
904b9f
+ * 3. The name of the author may not be used to endorse or promote
904b9f
+ *    products derived from this software without specific prior
904b9f
+ *    written permission.
904b9f
+ *
904b9f
+ * ALTERNATIVELY, this product may be distributed under the terms of
904b9f
+ * the GNU Public License, in which case the provisions of the GPL are
904b9f
+ * required INSTEAD OF the above restrictions.  (This clause is
904b9f
+ * necessary due to a potential bad interaction between the GPL and
904b9f
+ * the restrictions contained in a BSD-style copyright.)
904b9f
+ *
904b9f
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
904b9f
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
904b9f
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
904b9f
+ * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
904b9f
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
904b9f
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
904b9f
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
904b9f
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
904b9f
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
904b9f
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
904b9f
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
904b9f
+ */
904b9f
+
904b9f
+/*
904b9f
+ * faillock.h - authentication failure data file record structure
904b9f
+ *
904b9f
+ * Each record in the file represents an instance of login failure of
904b9f
+ * the user at the recorded time
904b9f
+ */
904b9f
+
904b9f
+
904b9f
+#ifndef _FAILLOCK_H
904b9f
+#define _FAILLOCK_H
904b9f
+
904b9f
+#include <stdint.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
+#define TALLY_STATUS_TTY       0x4       /* the source is tty - if both TALLY_FLAG_RHOST and TALLY_FLAG_TTY are not set the source is service */
904b9f
+
904b9f
+struct	tally {
904b9f
+	char		source[52];	/* rhost or tty of the login failure (not necessarily NULL terminated) */
904b9f
+	uint16_t	reserved;	/* reserved for future use */
904b9f
+	uint16_t	status;		/* record status  */
904b9f
+	uint64_t	time;		/* time of the login failure */
904b9f
+};
904b9f
+/* 64 bytes per entry */
904b9f
+
904b9f
+struct tally_data {
904b9f
+	struct tally *records;		/* array of tallies */
904b9f
+	unsigned int count;		/* number of records */
904b9f
+};
904b9f
+
904b9f
+#define FAILLOCK_DEFAULT_TALLYDIR "/var/run/faillock"
904b9f
+
904b9f
+int open_tally(const char *dir, const char *user, 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
+
904b9f
diff -up Linux-PAM-1.1.1/modules/pam_faillock/faillock.8.xml.faillock Linux-PAM-1.1.1/modules/pam_faillock/faillock.8.xml
904b9f
--- Linux-PAM-1.1.1/modules/pam_faillock/faillock.8.xml.faillock	2010-09-17 15:58:41.000000000 +0200
904b9f
+++ Linux-PAM-1.1.1/modules/pam_faillock/faillock.8.xml	2010-09-17 15:58:41.000000000 +0200
904b9f
@@ -0,0 +1,123 @@
904b9f
+
904b9f
+
904b9f
+	"http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd">
904b9f
+
904b9f
+<refentry id="faillock">
904b9f
+
904b9f
+  <refmeta>
904b9f
+    <refentrytitle>faillock</refentrytitle>
904b9f
+    <manvolnum>8</manvolnum>
904b9f
+    <refmiscinfo class="sectdesc">Linux-PAM Manual</refmiscinfo>
904b9f
+  </refmeta>
904b9f
+
904b9f
+  <refnamediv id="pam_faillock-name">
904b9f
+    <refname>faillock</refname>
904b9f
+    <refpurpose>Tool for displaying and modifying the authentication failure record files</refpurpose>
904b9f
+  </refnamediv>
904b9f
+
904b9f
+  <refsynopsisdiv>
904b9f
+    <cmdsynopsis id="faillock-cmdsynopsis">
904b9f
+      <command>faillock</command>
904b9f
+      <arg choice="opt">
904b9f
+        --dir <replaceable>/path/to/tally-directory</replaceable>
904b9f
+      </arg>
904b9f
+      <arg choice="opt">
904b9f
+        --user <replaceable>username</replaceable>
904b9f
+      </arg>
904b9f
+      <arg choice="opt">
904b9f
+        --reset
904b9f
+      </arg>
904b9f
+    </cmdsynopsis>
904b9f
+  </refsynopsisdiv>
904b9f
+
904b9f
+  <refsect1 id="faillock-description">
904b9f
+
904b9f
+    <title>DESCRIPTION</title>
904b9f
+
904b9f
+    <para>
904b9f
+      The <emphasis>pam_faillock.so</emphasis> module maintains a list of
904b9f
+      failed authentication attempts per user during a specified interval
904b9f
+      and locks the account in case there were more than
904b9f
+      <replaceable>deny</replaceable> consecutive failed authentications.
904b9f
+      It stores the failure records into per-user files in the tally
904b9f
+      directory.
904b9f
+    </para>
904b9f
+    <para>
904b9f
+      The <command>faillock</command> command is an application which
904b9f
+      can be used to examine and modify the contents of the
904b9f
+      the tally files. It can display the recent failed authentication
904b9f
+      attempts of the <replaceable>username</replaceable> or clear the tally
904b9f
+      files of all or individual <replaceable>usernames</replaceable>.
904b9f
+    </para>
904b9f
+  </refsect1>
904b9f
+
904b9f
+  <refsect1 id="faillock-options">
904b9f
+
904b9f
+    <title>OPTIONS</title>
904b9f
+         <variablelist>
904b9f
+            <varlistentry>
904b9f
+              <term>
904b9f
+                <option>--dir <replaceable>/path/to/tally-directory</replaceable></option>
904b9f
+              </term>
904b9f
+              <listitem>
904b9f
+                <para>
904b9f
+                  The directory where the user files with the failure records are kept. The
904b9f
+                  default is <filename>/var/run/faillock</filename>.
904b9f
+                </para>
904b9f
+              </listitem>
904b9f
+            </varlistentry>
904b9f
+            <varlistentry>
904b9f
+              <term>
904b9f
+                <option>--user <replaceable>username</replaceable></option>
904b9f
+              </term>
904b9f
+              <listitem>
904b9f
+                <para>
904b9f
+                  The user whose failure records should be displayed or cleared.
904b9f
+                </para>
904b9f
+              </listitem>
904b9f
+            </varlistentry>
904b9f
+            <varlistentry>
904b9f
+              <term>
904b9f
+                <option>--reset</option>
904b9f
+              </term>
904b9f
+              <listitem>
904b9f
+                <para>
904b9f
+                  Instead of displaying the user's failure records, clear them.
904b9f
+                </para>
904b9f
+              </listitem>
904b9f
+            </varlistentry>
904b9f
+        </variablelist>
904b9f
+  </refsect1>
904b9f
+
904b9f
+  <refsect1 id="faillock-files">
904b9f
+    <title>FILES</title>
904b9f
+    <variablelist>
904b9f
+      <varlistentry>
904b9f
+        <term><filename>/var/run/faillock/*</filename></term>
904b9f
+        <listitem>
904b9f
+          <para>the files logging the authentication failures for users</para>
904b9f
+        </listitem>
904b9f
+      </varlistentry>
904b9f
+    </variablelist>
904b9f
+  </refsect1>
904b9f
+
904b9f
+  <refsect1 id='faillock-see_also'>
904b9f
+    <title>SEE ALSO</title>
904b9f
+    <para>
904b9f
+      <citerefentry>
904b9f
+        <refentrytitle>pam_faillock</refentrytitle><manvolnum>8</manvolnum>
904b9f
+      </citerefentry>,
904b9f
+      <citerefentry>
904b9f
+        <refentrytitle>pam</refentrytitle><manvolnum>8</manvolnum>
904b9f
+      </citerefentry>
904b9f
+    </para>
904b9f
+  </refsect1>
904b9f
+
904b9f
+  <refsect1 id='faillock-author'>
904b9f
+    <title>AUTHOR</title>
904b9f
+      <para>
904b9f
+        faillock was written by Tomas Mraz.
904b9f
+      </para>
904b9f
+  </refsect1>
904b9f
+
904b9f
+</refentry>
904b9f
diff -up Linux-PAM-1.1.1/modules/pam_faillock/main.c.faillock Linux-PAM-1.1.1/modules/pam_faillock/main.c
904b9f
--- Linux-PAM-1.1.1/modules/pam_faillock/main.c.faillock	2010-09-17 15:58:41.000000000 +0200
904b9f
+++ Linux-PAM-1.1.1/modules/pam_faillock/main.c	2010-09-17 15:58:41.000000000 +0200
904b9f
@@ -0,0 +1,231 @@
904b9f
+/*
904b9f
+ * Copyright (c) 2010 Tomas Mraz <tmraz@redhat.com>
904b9f
+ *
904b9f
+ * Redistribution and use in source and binary forms, with or without
904b9f
+ * modification, are permitted provided that the following conditions
904b9f
+ * are met:
904b9f
+ * 1. Redistributions of source code must retain the above copyright
904b9f
+ *    notice, and the entire permission notice in its entirety,
904b9f
+ *    including the disclaimer of warranties.
904b9f
+ * 2. Redistributions in binary form must reproduce the above copyright
904b9f
+ *    notice, this list of conditions and the following disclaimer in the
904b9f
+ *    documentation and/or other materials provided with the distribution.
904b9f
+ * 3. The name of the author may not be used to endorse or promote
904b9f
+ *    products derived from this software without specific prior
904b9f
+ *    written permission.
904b9f
+ *
904b9f
+ * ALTERNATIVELY, this product may be distributed under the terms of
904b9f
+ * the GNU Public License, in which case the provisions of the GPL are
904b9f
+ * required INSTEAD OF the above restrictions.  (This clause is
904b9f
+ * necessary due to a potential bad interaction between the GPL and
904b9f
+ * the restrictions contained in a BSD-style copyright.)
904b9f
+ *
904b9f
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
904b9f
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
904b9f
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
904b9f
+ * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
904b9f
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
904b9f
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
904b9f
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
904b9f
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
904b9f
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
904b9f
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
904b9f
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
904b9f
+ */
904b9f
+
904b9f
+#include "config.h"
904b9f
+
904b9f
+#include <stdio.h>
904b9f
+#include <stdlib.h>
904b9f
+#include <string.h>
904b9f
+#include <dirent.h>
904b9f
+#include <errno.h>
904b9f
+#include <pwd.h>
904b9f
+#include <time.h>
904b9f
+#ifdef HAVE_LIBAUDIT
904b9f
+#include <libaudit.h>
904b9f
+#endif
904b9f
+
904b9f
+#include "faillock.h"
904b9f
+
904b9f
+struct options {
904b9f
+	unsigned int reset;
904b9f
+	const char *dir;
904b9f
+	const char *user;
904b9f
+	const char *progname;
904b9f
+};
904b9f
+
904b9f
+static int
904b9f
+args_parse(int argc, char **argv, struct options *opts)
904b9f
+{
904b9f
+	int i;
904b9f
+	memset(opts, 0, sizeof(*opts));
904b9f
+
904b9f
+	opts->dir = FAILLOCK_DEFAULT_TALLYDIR;
904b9f
+	opts->progname = argv[0];
904b9f
+
904b9f
+	for (i = 1; i < argc; ++i) {
904b9f
+
904b9f
+		if (strcmp(argv[i], "--dir") == 0) {
904b9f
+			++i;
904b9f
+			if (i >= argc || strlen(argv[i]) == 0) {
904b9f
+				fprintf(stderr, "%s: No directory supplied.\n", argv[0]);				
904b9f
+				return -1;
904b9f
+			}
904b9f
+		        opts->dir = argv[i];
904b9f
+		} 
904b9f
+		else if (strcmp(argv[i], "--user") == 0) {
904b9f
+			++i;
904b9f
+			if (i >= argc || strlen(argv[i]) == 0) {
904b9f
+				fprintf(stderr, "%s: No user name supplied.\n", argv[0]);				
904b9f
+				return -1;
904b9f
+			}
904b9f
+		        opts->user = argv[i];
904b9f
+		}
904b9f
+ 		else if (strcmp(argv[i], "--reset") == 0) {
904b9f
+			opts->reset = 1;
904b9f
+		}
904b9f
+		else {
904b9f
+			fprintf(stderr, "%s: Unknown option: %s\n", argv[0], argv[i]);
904b9f
+			return -1;
904b9f
+		}
904b9f
+	}
904b9f
+	return 0;
904b9f
+}
904b9f
+
904b9f
+static void
904b9f
+usage(const char *progname)
904b9f
+{
904b9f
+	fprintf(stderr, _("Usage: %s [--dir /path/to/tally-directory] [--user username] [--reset]\n"),
904b9f
+		progname);
904b9f
+}
904b9f
+
904b9f
+static int
904b9f
+do_user(struct options *opts, const char *user)
904b9f
+{
904b9f
+	int fd;
904b9f
+	int rv;
904b9f
+	struct tally_data tallies;
904b9f
+
904b9f
+	fd = open_tally(opts->dir, user, 0);
904b9f
+
904b9f
+	if (fd == -1) {
904b9f
+		if (errno == ENOENT) {
904b9f
+			return 0;
904b9f
+		}
904b9f
+		else {
904b9f
+			fprintf(stderr, "%s: Error opening the tally file for %s:",
904b9f
+				opts->progname, user);
904b9f
+			perror(NULL);
904b9f
+			return 3;
904b9f
+		}
904b9f
+	}
904b9f
+	if (opts->reset) {
904b9f
+#ifdef HAVE_LIBAUDIT
904b9f
+		char buf[64];
904b9f
+		int audit_fd;
904b9f
+#endif
904b9f
+		
904b9f
+		while ((rv=ftruncate(fd, 0)) == -1 && errno == EINTR);
904b9f
+		if (rv == -1) {
904b9f
+			fprintf(stderr, "%s: Error clearing the tally file for %s:",
904b9f
+				opts->progname, user);
904b9f
+			perror(NULL);
904b9f
+#ifdef HAVE_LIBAUDIT
904b9f
+		}
904b9f
+		if ((audit_fd=audit_open()) >= 0) {
904b9f
+			struct passwd *pwd;
904b9f
+
904b9f
+			if ((pwd=getpwnam(user)) != 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
+					buf, NULL, NULL, NULL, rv == 0);
904b9f
+			}
904b9f
+			close(audit_fd);
904b9f
+		}
904b9f
+		if (rv == -1) {
904b9f
+#endif
904b9f
+			close(fd);
904b9f
+			return 4;
904b9f
+		}
904b9f
+	}
904b9f
+	else {
904b9f
+		unsigned int i;
904b9f
+
904b9f
+		memset(&tallies, 0, sizeof(tallies));
904b9f
+		if ((rv=read_tally(fd, &tallies)) == -1) {
904b9f
+			fprintf(stderr, "%s: Error reading the tally file for %s:",
904b9f
+				opts->progname, user);
904b9f
+			perror(NULL);
904b9f
+			close(fd);
904b9f
+			return 5;
904b9f
+		}
904b9f
+
904b9f
+		printf("%s:\n", user);
904b9f
+		printf("%-19s %-5s %-48s %-5s\n", "When", "Type", "Source", "Valid");
904b9f
+
904b9f
+		for (i = 0; i < tallies.count; i++) {
904b9f
+			struct tm *tm;
904b9f
+			char timebuf[80];
904b9f
+			uint16_t status = tallies.records[i].status;
904b9f
+			time_t when = tallies.records[i].time;
904b9f
+
904b9f
+			tm = localtime(&when);
904b9f
+			strftime(timebuf, sizeof(timebuf), "%Y-%m-%d %H:%M:%S", tm);
904b9f
+			printf("%-19s %-5s %-52.52s %s\n", timebuf,
904b9f
+				status & TALLY_STATUS_RHOST ? "RHOST" : (status & TALLY_STATUS_TTY ? "TTY" : "SVC"),
904b9f
+				tallies.records[i].source, status & TALLY_STATUS_VALID ? "V":"I");
904b9f
+		}
904b9f
+		free(tallies.records);
904b9f
+	}
904b9f
+	close(fd);
904b9f
+	return 0;
904b9f
+}
904b9f
+
904b9f
+static int
904b9f
+do_allusers(struct options *opts)
904b9f
+{
904b9f
+	struct dirent **userlist;
904b9f
+	int rv, i;
904b9f
+
904b9f
+	rv = scandir(opts->dir, &userlist, NULL, alphasort);
904b9f
+	if (rv < 0) {
904b9f
+		fprintf(stderr, "%s: Error reading tally directory: ", opts->progname);
904b9f
+		perror(NULL);
904b9f
+		return 2;
904b9f
+	}
904b9f
+
904b9f
+	for (i = 0; i < rv; i++) {
904b9f
+		if (userlist[i]->d_name[0] == '.') {
904b9f
+			if ((userlist[i]->d_name[1] == '.' && userlist[i]->d_name[2] == '\0') ||
904b9f
+			    userlist[i]->d_name[1] == '\0')
904b9f
+				continue;
904b9f
+		}
904b9f
+		do_user(opts, userlist[i]->d_name);
904b9f
+		free(userlist[i]);
904b9f
+	}
904b9f
+	free(userlist);
904b9f
+
904b9f
+	return 0;
904b9f
+}
904b9f
+
904b9f
+
904b9f
+/*-----------------------------------------------------------------------*/
904b9f
+int
904b9f
+main (int argc, char *argv[])
904b9f
+{
904b9f
+	struct options opts;
904b9f
+
904b9f
+	if (args_parse(argc, argv, &opts)) {
904b9f
+		usage(argv[0]);
904b9f
+		return 1;
904b9f
+	}
904b9f
+
904b9f
+	if (opts.user == NULL) {
904b9f
+		return do_allusers(&opts);		
904b9f
+	}
904b9f
+
904b9f
+	return do_user(&opts, opts.user);
904b9f
+}
904b9f
+
904b9f
diff -up Linux-PAM-1.1.1/modules/pam_faillock/Makefile.am.faillock Linux-PAM-1.1.1/modules/pam_faillock/Makefile.am
904b9f
--- Linux-PAM-1.1.1/modules/pam_faillock/Makefile.am.faillock	2010-09-17 15:58:41.000000000 +0200
904b9f
+++ Linux-PAM-1.1.1/modules/pam_faillock/Makefile.am	2010-09-17 15:58:41.000000000 +0200
904b9f
@@ -0,0 +1,43 @@
904b9f
+#
904b9f
+# Copyright (c) 2005, 2006, 2007, 2009 Thorsten Kukuk <kukuk@thkukuk.de>
904b9f
+# Copyright (c) 2008 Red Hat, Inc.
904b9f
+# Copyright (c) 2010 Tomas Mraz <tmraz@redhat.com>
904b9f
+#
904b9f
+
904b9f
+CLEANFILES = *~
904b9f
+MAINTAINERCLEANFILES = $(MANS) README
904b9f
+
904b9f
+EXTRA_DIST = README $(MANS) $(XMLS) tst-pam_faillock
904b9f
+
904b9f
+man_MANS = pam_faillock.8 faillock.8
904b9f
+XMLS = README.xml pam_faillock.8.xml faillock.8.xml
904b9f
+
904b9f
+TESTS = tst-pam_faillock
904b9f
+
904b9f
+securelibdir = $(SECUREDIR)
904b9f
+secureconfdir = $(SCONFIGDIR)
904b9f
+
904b9f
+noinst_HEADERS = faillock.h
904b9f
+
904b9f
+faillock_CFLAGS = -I$(top_srcdir)/libpam/include -I$(top_srcdir)/libpamc/include
904b9f
+pam_faillock_la_CFLAGS = -I$(top_srcdir)/libpam/include -I$(top_srcdir)/libpamc/include
904b9f
+
904b9f
+pam_faillock_la_LDFLAGS = -no-undefined -avoid-version -module
904b9f
+pam_faillock_la_LIBADD = -L$(top_builddir)/libpam -lpam $(LIBAUDIT)
904b9f
+if HAVE_VERSIONING
904b9f
+  pam_faillock_la_LDFLAGS += -Wl,--version-script=$(srcdir)/../modules.map
904b9f
+endif
904b9f
+
904b9f
+faillock_LDADD = -L$(top_builddir)/libpam -lpam $(LIBAUDIT)
904b9f
+
904b9f
+securelib_LTLIBRARIES = pam_faillock.la
904b9f
+sbin_PROGRAMS = faillock
904b9f
+
904b9f
+pam_faillock_la_SOURCES = pam_faillock.c faillock.c
904b9f
+faillock_SOURCES = main.c faillock.c
904b9f
+
904b9f
+if ENABLE_REGENERATE_MAN
904b9f
+noinst_DATA = README
904b9f
+README: pam_faillock.8.xml
904b9f
+-include $(top_srcdir)/Make.xml.rules
904b9f
+endif
904b9f
diff -up Linux-PAM-1.1.1/modules/pam_faillock/pam_faillock.c.faillock Linux-PAM-1.1.1/modules/pam_faillock/pam_faillock.c
904b9f
--- Linux-PAM-1.1.1/modules/pam_faillock/pam_faillock.c.faillock	2010-09-17 15:58:41.000000000 +0200
904b9f
+++ Linux-PAM-1.1.1/modules/pam_faillock/pam_faillock.c	2010-09-17 15:58:41.000000000 +0200
904b9f
@@ -0,0 +1,550 @@
904b9f
+/*
904b9f
+ * Copyright (c) 2010 Tomas Mraz <tmraz@redhat.com>
904b9f
+ *
904b9f
+ * Redistribution and use in source and binary forms, with or without
904b9f
+ * modification, are permitted provided that the following conditions
904b9f
+ * are met:
904b9f
+ * 1. Redistributions of source code must retain the above copyright
904b9f
+ *    notice, and the entire permission notice in its entirety,
904b9f
+ *    including the disclaimer of warranties.
904b9f
+ * 2. Redistributions in binary form must reproduce the above copyright
904b9f
+ *    notice, this list of conditions and the following disclaimer in the
904b9f
+ *    documentation and/or other materials provided with the distribution.
904b9f
+ * 3. The name of the author may not be used to endorse or promote
904b9f
+ *    products derived from this software without specific prior
904b9f
+ *    written permission.
904b9f
+ *
904b9f
+ * ALTERNATIVELY, this product may be distributed under the terms of
904b9f
+ * the GNU Public License, in which case the provisions of the GPL are
904b9f
+ * required INSTEAD OF the above restrictions.  (This clause is
904b9f
+ * necessary due to a potential bad interaction between the GPL and
904b9f
+ * the restrictions contained in a BSD-style copyright.)
904b9f
+ *
904b9f
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
904b9f
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
904b9f
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
904b9f
+ * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
904b9f
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
904b9f
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
904b9f
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
904b9f
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
904b9f
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
904b9f
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
904b9f
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
904b9f
+ */
904b9f
+
904b9f
+#include "config.h"
904b9f
+#include <stdio.h>
904b9f
+#include <string.h>
904b9f
+#include <unistd.h>
904b9f
+#include <stdint.h>
904b9f
+#include <stdlib.h>
904b9f
+#include <errno.h>
904b9f
+#include <time.h>
904b9f
+#include <pwd.h>
904b9f
+#include <syslog.h>
904b9f
+
904b9f
+#ifdef HAVE_LIBAUDIT
904b9f
+#include <libaudit.h>
904b9f
+#endif
904b9f
+
904b9f
+#include <security/pam_modules.h>
904b9f
+#include <security/pam_modutil.h>
904b9f
+#include <security/pam_ext.h>
904b9f
+
904b9f
+#include "faillock.h"
904b9f
+
904b9f
+#define PAM_SM_AUTH
904b9f
+#define PAM_SM_ACCOUNT
904b9f
+
904b9f
+#define FAILLOCK_ACTION_PREAUTH  0
904b9f
+#define FAILLOCK_ACTION_AUTHSUCC 1
904b9f
+#define FAILLOCK_ACTION_AUTHFAIL 2
904b9f
+
904b9f
+#define FAILLOCK_FLAG_DENY_ROOT		0x1
904b9f
+#define FAILLOCK_FLAG_AUDIT		0x2
904b9f
+#define FAILLOCK_FLAG_SILENT		0x4
904b9f
+#define FAILLOCK_FLAG_NO_LOG_INFO	0x8
904b9f
+#define FAILLOCK_FLAG_UNLOCKED		0x10
904b9f
+
904b9f
+#define MAX_TIME_INTERVAL 604800 /* 7 days */
904b9f
+
904b9f
+struct options {
904b9f
+	unsigned int action;
904b9f
+	unsigned int flags;
904b9f
+	unsigned short deny;
904b9f
+	unsigned int fail_interval;
904b9f
+	unsigned int unlock_time;
904b9f
+	unsigned int root_unlock_time;
904b9f
+	const char *dir;
904b9f
+	const char *user;
904b9f
+	int failures;
904b9f
+	uint64_t latest_time;
904b9f
+	uid_t uid;
904b9f
+	uint64_t now;
904b9f
+};
904b9f
+
904b9f
+static void
904b9f
+args_parse(pam_handle_t *pamh, int argc, const char **argv,
904b9f
+		int flags, struct options *opts)
904b9f
+{
904b9f
+	int i;
904b9f
+	memset(opts, 0, sizeof(*opts));
904b9f
+
904b9f
+	opts->dir = FAILLOCK_DEFAULT_TALLYDIR;
904b9f
+	opts->deny = 3;
904b9f
+	opts->fail_interval = 900;
904b9f
+	opts->unlock_time = 600;
904b9f
+	opts->root_unlock_time = MAX_TIME_INTERVAL+1;
904b9f
+
904b9f
+	for (i = 0; i < argc; ++i) {
904b9f
+
904b9f
+		if (strncmp(argv[i], "dir=", 4) == 0) {
904b9f
+			if (argv[i][4] != '/') {
904b9f
+				pam_syslog(pamh, LOG_ERR,
904b9f
+					"Tally directory is not absolute path (%s); keeping default", argv[i]);
904b9f
+	        	} else {
904b9f
+			        opts->dir = argv[i]+4;
904b9f
+			}
904b9f
+		} 
904b9f
+		else if (strncmp(argv[i], "deny=", 5) == 0) {
904b9f
+			if (sscanf(argv[i]+5, "%hu", &opts->deny) != 1) {
904b9f
+				pam_syslog(pamh, LOG_ERR,
904b9f
+					"Bad number supplied for deny argument");
904b9f
+        		}
904b9f
+		}
904b9f
+		else if (strncmp(argv[i], "fail_interval=", 14) == 0) {
904b9f
+			unsigned int temp;
904b9f
+			if (sscanf(argv[i]+14, "%u", &temp) != 1 ||
904b9f
+				temp > MAX_TIME_INTERVAL) {
904b9f
+				pam_syslog(pamh, LOG_ERR,
904b9f
+					"Bad number supplied for fail_interval argument");
904b9f
+	        	} else {
904b9f
+				opts->fail_interval = temp;
904b9f
+			}
904b9f
+		}
904b9f
+		else if (strncmp(argv[i], "unlock_time=", 12) == 0) {
904b9f
+			unsigned int temp;
904b9f
+			if (sscanf(argv[i]+12, "%u", &temp) != 1 ||
904b9f
+				temp > MAX_TIME_INTERVAL) {
904b9f
+				pam_syslog(pamh, LOG_ERR,
904b9f
+					"Bad number supplied for unlock_time argument");
904b9f
+        		} else {
904b9f
+				opts->unlock_time = temp;
904b9f
+			}
904b9f
+		}
904b9f
+		else if (strncmp(argv[i], "root_unlock_time=", 17) == 0) {
904b9f
+			unsigned int temp;
904b9f
+			if (sscanf(argv[i]+17, "%u", &temp) != 1 ||
904b9f
+				temp > MAX_TIME_INTERVAL) {
904b9f
+				pam_syslog(pamh, LOG_ERR,
904b9f
+					"Bad number supplied for root_unlock_time argument");
904b9f
+        		} else {
904b9f
+				opts->root_unlock_time = temp;
904b9f
+			}
904b9f
+		}
904b9f
+ 		else if (strcmp(argv[i], "preauth") == 0) {
904b9f
+			opts->action = FAILLOCK_ACTION_PREAUTH;
904b9f
+		}
904b9f
+ 		else if (strcmp(argv[i], "authfail") == 0) {
904b9f
+			opts->action = FAILLOCK_ACTION_AUTHFAIL;
904b9f
+		}
904b9f
+	 	else if (strcmp(argv[i], "authsucc") == 0) {
904b9f
+			opts->action = FAILLOCK_ACTION_AUTHSUCC;
904b9f
+		}
904b9f
+	 	else if (strcmp(argv[i], "even_deny_root") == 0) {
904b9f
+			opts->flags |= FAILLOCK_FLAG_DENY_ROOT;
904b9f
+		}
904b9f
+	 	else if (strcmp(argv[i], "audit") == 0) {
904b9f
+			opts->flags |= FAILLOCK_FLAG_AUDIT;
904b9f
+		}
904b9f
+	 	else if (strcmp(argv[i], "silent") == 0) {
904b9f
+			opts->flags |= FAILLOCK_FLAG_SILENT;
904b9f
+		}
904b9f
+	 	else if (strcmp(argv[i], "no_log_info") == 0) {
904b9f
+			opts->flags |= FAILLOCK_FLAG_NO_LOG_INFO;
904b9f
+		}
904b9f
+		else {
904b9f
+			pam_syslog(pamh, LOG_ERR, "Unknown option: %s", argv[i]);
904b9f
+		}
904b9f
+	}
904b9f
+
904b9f
+	if (opts->root_unlock_time == MAX_TIME_INTERVAL+1)
904b9f
+		opts->root_unlock_time = opts->unlock_time;
904b9f
+	if (flags & PAM_SILENT)
904b9f
+		opts->flags |= FAILLOCK_FLAG_SILENT;
904b9f
+}
904b9f
+
904b9f
+static int get_pam_user(pam_handle_t *pamh, struct options *opts)
904b9f
+{
904b9f
+	const char *user;
904b9f
+	int rv;
904b9f
+	struct passwd *pwd;
904b9f
+
904b9f
+	if ((rv=pam_get_user(pamh, &user, NULL)) != PAM_SUCCESS) {
904b9f
+		return rv;
904b9f
+	}
904b9f
+
904b9f
+	if (*user == '\0') {
904b9f
+		return PAM_IGNORE;
904b9f
+	}
904b9f
+
904b9f
+	if ((pwd=pam_modutil_getpwnam(pamh, user)) == NULL) {
904b9f
+		if (opts->flags & FAILLOCK_FLAG_AUDIT) {
904b9f
+			pam_syslog(pamh, LOG_ERR, "User unknown: %s", user);
904b9f
+		}
904b9f
+		else {
904b9f
+			pam_syslog(pamh, LOG_ERR, "User unknown");
904b9f
+		}
904b9f
+		return PAM_IGNORE;
904b9f
+	}
904b9f
+	opts->user = user;
904b9f
+	opts->uid = pwd->pw_uid;
904b9f
+	return PAM_SUCCESS;
904b9f
+}
904b9f
+
904b9f
+static int
904b9f
+check_tally(pam_handle_t *pamh, struct options *opts, struct tally_data *tallies, int *fd)
904b9f
+{
904b9f
+	int tfd;
904b9f
+	unsigned int i;
904b9f
+	uint64_t latest_time;
904b9f
+	int failures;
904b9f
+
904b9f
+	opts->now = time(NULL);
904b9f
+
904b9f
+	tfd = open_tally(opts->dir, opts->user, 0);
904b9f
+
904b9f
+	*fd = tfd;
904b9f
+
904b9f
+	if (tfd == -1) {
904b9f
+		if (errno == EACCES || errno == ENOENT) {
904b9f
+			return PAM_SUCCESS;
904b9f
+		}
904b9f
+		pam_syslog(pamh, LOG_ERR, "Error opening the tally file for %s: %m", opts->user);
904b9f
+		return PAM_SYSTEM_ERR;
904b9f
+	}
904b9f
+
904b9f
+	if (read_tally(tfd, tallies) != 0) {
904b9f
+		pam_syslog(pamh, LOG_ERR, "Error reading the tally file for %s: %m", opts->user);
904b9f
+		return PAM_SYSTEM_ERR;
904b9f
+	}
904b9f
+
904b9f
+	if (opts->uid == 0 && !(opts->flags & FAILLOCK_FLAG_DENY_ROOT)) {
904b9f
+		return PAM_SUCCESS;
904b9f
+	}
904b9f
+
904b9f
+	latest_time = 0;
904b9f
+	for(i = 0; i < tallies->count; i++) {
904b9f
+		if ((tallies->records[i].status & TALLY_STATUS_VALID) &&
904b9f
+			tallies->records[i].time > latest_time)
904b9f
+			latest_time = tallies->records[i].time;
904b9f
+	}
904b9f
+
904b9f
+	opts->latest_time = latest_time;
904b9f
+
904b9f
+	failures = 0;
904b9f
+	for(i = 0; i < tallies->count; i++) {
904b9f
+		if ((tallies->records[i].status & TALLY_STATUS_VALID) &&
904b9f
+			latest_time - tallies->records[i].time < opts->fail_interval) {
904b9f
+			++failures;
904b9f
+		}
904b9f
+	}
904b9f
+
904b9f
+	opts->failures = failures;
904b9f
+
904b9f
+	if (opts->uid == 0 && !(opts->flags & FAILLOCK_FLAG_DENY_ROOT)) {
904b9f
+		return PAM_SUCCESS;
904b9f
+	}
904b9f
+
904b9f
+	if (opts->deny && failures >= opts->deny) {
904b9f
+		if ((opts->uid && latest_time + opts->unlock_time < opts->now) ||
904b9f
+			(!opts->uid && latest_time + opts->root_unlock_time < opts->now)) {
904b9f
+#ifdef HAVE_LIBAUDIT
904b9f
+			if (opts->action != FAILLOCK_ACTION_PREAUTH) { /* do not audit in preauth */
904b9f
+				char buf[64];
904b9f
+				int audit_fd;
904b9f
+
904b9f
+				audit_fd = audit_open();
904b9f
+				/* If there is an error & audit support is in the kernel report error */
904b9f
+				if ((audit_fd < 0) && !(errno == EINVAL || errno == EPROTONOSUPPORT ||
904b9f
+					errno == EAFNOSUPPORT))
904b9f
+					return PAM_SYSTEM_ERR;
904b9f
+
904b9f
+				snprintf(buf, sizeof(buf), "pam_faillock uid=%u ", opts->uid);
904b9f
+				audit_log_user_message(audit_fd, AUDIT_RESP_ACCT_UNLOCK_TIMED, buf,
904b9f
+					NULL, NULL, NULL, 1);
904b9f
+			}
904b9f
+#endif
904b9f
+			opts->flags |= FAILLOCK_FLAG_UNLOCKED;
904b9f
+			return PAM_SUCCESS;
904b9f
+		}
904b9f
+		return PAM_AUTH_ERR;
904b9f
+	}
904b9f
+	return PAM_SUCCESS;
904b9f
+}
904b9f
+
904b9f
+static void
904b9f
+reset_tally(pam_handle_t *pamh, struct options *opts, int *fd)
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
+	}
904b9f
+}
904b9f
+
904b9f
+static int
904b9f
+write_tally(pam_handle_t *pamh, struct options *opts, struct tally_data *tallies, int *fd)
904b9f
+{
904b9f
+	struct tally *records;
904b9f
+	unsigned int i;
904b9f
+	int failures;
904b9f
+	unsigned int oldest;
904b9f
+	uint64_t oldtime;
904b9f
+	const void *source = NULL;
904b9f
+
904b9f
+	if (*fd == -1) {
904b9f
+		*fd = open_tally(opts->dir, opts->user, 1);
904b9f
+	}
904b9f
+	if (*fd == -1) {
904b9f
+		if (errno == EACCES) {
904b9f
+			return PAM_SUCCESS;
904b9f
+		}
904b9f
+		pam_syslog(pamh, LOG_ERR, "Error opening the tally file for %s: %m", opts->user);
904b9f
+		return PAM_SYSTEM_ERR;
904b9f
+	}
904b9f
+
904b9f
+	oldtime = 0;
904b9f
+	oldest = 0;
904b9f
+	failures = 0;
904b9f
+
904b9f
+	for (i = 0; i < tallies->count; ++i) {
904b9f
+		if (tallies->records[i].time < oldtime) {
904b9f
+			oldtime = tallies->records[i].time;
904b9f
+			oldest = i;
904b9f
+		}
904b9f
+		if (opts->flags & FAILLOCK_FLAG_UNLOCKED ||
904b9f
+			opts->now - tallies->records[i].time >= opts->fail_interval ) {
904b9f
+			tallies->records[i].status &= ~TALLY_STATUS_VALID;
904b9f
+		} else {
904b9f
+			++failures;
904b9f
+		}
904b9f
+	}
904b9f
+
904b9f
+	if (oldest >= tallies->count || (tallies->records[oldest].status & TALLY_STATUS_VALID)) {
904b9f
+		oldest = tallies->count;
904b9f
+
904b9f
+		if ((records=realloc(tallies->records, (oldest+1) * sizeof (*tallies->records))) == NULL) {
904b9f
+			pam_syslog(pamh, LOG_CRIT, "Error allocating memory for tally records: %m");
904b9f
+			return PAM_BUF_ERR;
904b9f
+		}
904b9f
+
904b9f
+		++tallies->count;
904b9f
+		tallies->records = records;
904b9f
+	}
904b9f
+
904b9f
+	memset(&tallies->records[oldest], 0, sizeof (*tallies->records));
904b9f
+
904b9f
+	tallies->records[oldest].status = TALLY_STATUS_VALID;
904b9f
+	if (pam_get_item(pamh, PAM_RHOST, &source) != PAM_SUCCESS || source == NULL) {
904b9f
+		if (pam_get_item(pamh, PAM_TTY, &source) != PAM_SUCCESS || source == NULL) {
904b9f
+			if (pam_get_item(pamh, PAM_SERVICE, &source) != PAM_SUCCESS || source == NULL) {
904b9f
+				source = "";
904b9f
+			}
904b9f
+		}
904b9f
+		else {
904b9f
+			tallies->records[oldest].status |= TALLY_STATUS_TTY;
904b9f
+		}
904b9f
+	}
904b9f
+	else {
904b9f
+		tallies->records[oldest].status |= TALLY_STATUS_RHOST;
904b9f
+	}
904b9f
+
904b9f
+	strncpy(tallies->records[oldest].source, source, sizeof(tallies->records[oldest].source));
904b9f
+	/* source does not have to be null terminated */
904b9f
+	
904b9f
+	tallies->records[oldest].time = opts->now;
904b9f
+
904b9f
+	++failures;
904b9f
+
904b9f
+	if (opts->deny && failures == opts->deny) {
904b9f
+#ifdef HAVE_LIBAUDIT
904b9f
+		char buf[64];
904b9f
+		int audit_fd;
904b9f
+
904b9f
+		audit_fd = audit_open();
904b9f
+		/* If there is an error & audit support is in the kernel report error */
904b9f
+		if ((audit_fd < 0) && !(errno == EINVAL || errno == EPROTONOSUPPORT ||
904b9f
+			errno == EAFNOSUPPORT))
904b9f
+			return PAM_SYSTEM_ERR;
904b9f
+
904b9f
+		snprintf(buf, sizeof(buf), "pam_faillock uid=%u ", opts->uid);
904b9f
+		audit_log_user_message(audit_fd, AUDIT_ANOM_LOGIN_FAILURES, buf,
904b9f
+			NULL, NULL, NULL, 1);
904b9f
+
904b9f
+		if (opts->uid != 0 || (opts->flags & FAILLOCK_FLAG_DENY_ROOT)) {
904b9f
+			audit_log_user_message(audit_fd, AUDIT_RESP_ACCT_LOCK, buf,
904b9f
+				NULL, NULL, NULL, 1);
904b9f
+		}
904b9f
+		close(audit_fd);
904b9f
+#endif
904b9f
+		if (!(opts->flags & FAILLOCK_FLAG_NO_LOG_INFO)) {
904b9f
+			pam_syslog(pamh, LOG_INFO, "Consecutive login failures for user %s account temporarily locked",
904b9f
+				opts->user);
904b9f
+		}
904b9f
+	}
904b9f
+
904b9f
+	if (update_tally(*fd, tallies) == 0)
904b9f
+		return PAM_SUCCESS;
904b9f
+
904b9f
+	return PAM_SYSTEM_ERR;
904b9f
+}
904b9f
+
904b9f
+static void
904b9f
+faillock_message(pam_handle_t *pamh, struct options *opts)
904b9f
+{
904b9f
+	int64_t left;
904b9f
+
904b9f
+	if (!(opts->flags & FAILLOCK_FLAG_SILENT)) {
904b9f
+		if (opts->uid) {
904b9f
+			left = opts->latest_time + opts->unlock_time - opts->now;
904b9f
+		}
904b9f
+		else {
904b9f
+			left = opts->latest_time + opts->root_unlock_time - opts->now;
904b9f
+		}
904b9f
+
904b9f
+		left /= 60; /* minutes */
904b9f
+
904b9f
+		pam_info(pamh, _("Account temporarily locked due to %d failed logins"),
904b9f
+			opts->failures);
904b9f
+		pam_info(pamh, _("(%d minutes left to unlock)"), (int)left);
904b9f
+	}
904b9f
+}
904b9f
+
904b9f
+static void
904b9f
+tally_cleanup(struct tally_data *tallies, int fd)
904b9f
+{
904b9f
+	if (fd != -1) {
904b9f
+		close(fd);
904b9f
+	}
904b9f
+
904b9f
+	free(tallies->records);
904b9f
+}
904b9f
+
904b9f
+/*---------------------------------------------------------------------*/
904b9f
+
904b9f
+PAM_EXTERN int
904b9f
+pam_sm_authenticate(pam_handle_t *pamh, int flags,
904b9f
+		    int argc, const char **argv)
904b9f
+{
904b9f
+	struct options opts;
904b9f
+	int rv, fd = -1;
904b9f
+	struct tally_data tallies;
904b9f
+
904b9f
+	memset(&tallies, 0, sizeof(tallies));
904b9f
+
904b9f
+	args_parse(pamh, argc, argv, flags, &opts);
904b9f
+
904b9f
+	pam_fail_delay(pamh, 2000000);	/* 2 sec delay for on failure */
904b9f
+
904b9f
+	if ((rv=get_pam_user(pamh, &opts)) != PAM_SUCCESS) {
904b9f
+		return rv;
904b9f
+	}
904b9f
+
904b9f
+	switch (opts.action) {
904b9f
+		case FAILLOCK_ACTION_PREAUTH:
904b9f
+			rv = check_tally(pamh, &opts, &tallies, &fd;;
904b9f
+			if (rv == PAM_AUTH_ERR && !(opts.flags & FAILLOCK_FLAG_SILENT)) {
904b9f
+				faillock_message(pamh, &opts);
904b9f
+			}
904b9f
+                        break;
904b9f
+
904b9f
+		case FAILLOCK_ACTION_AUTHSUCC:
904b9f
+			rv = check_tally(pamh, &opts, &tallies, &fd;;
904b9f
+			if (rv == PAM_SUCCESS && fd != -1) {
904b9f
+				reset_tally(pamh, &opts, &fd;;
904b9f
+			}
904b9f
+                        break;
904b9f
+
904b9f
+		case FAILLOCK_ACTION_AUTHFAIL:
904b9f
+			rv = check_tally(pamh, &opts, &tallies, &fd;;
904b9f
+			if (rv == PAM_SUCCESS) {
904b9f
+				rv = PAM_IGNORE; /* this return value should be ignored */
904b9f
+				write_tally(pamh, &opts, &tallies, &fd;;
904b9f
+			}
904b9f
+			break;
904b9f
+	}
904b9f
+
904b9f
+	tally_cleanup(&tallies, fd);
904b9f
+
904b9f
+	return rv;
904b9f
+}
904b9f
+
904b9f
+/*---------------------------------------------------------------------*/
904b9f
+
904b9f
+PAM_EXTERN int
904b9f
+pam_sm_setcred(pam_handle_t *pamh UNUSED, int flags UNUSED,
904b9f
+	       int argc UNUSED, const char **argv UNUSED)
904b9f
+{
904b9f
+	return PAM_SUCCESS;
904b9f
+}
904b9f
+
904b9f
+/*---------------------------------------------------------------------*/
904b9f
+
904b9f
+PAM_EXTERN int
904b9f
+pam_sm_acct_mgmt(pam_handle_t *pamh, int flags,
904b9f
+		 int argc, const char **argv)
904b9f
+{
904b9f
+	struct options opts;
904b9f
+	int rv, fd = -1;
904b9f
+	struct tally_data tallies;
904b9f
+
904b9f
+	memset(&tallies, 0, sizeof(tallies));
904b9f
+
904b9f
+	args_parse(pamh, argc, argv, flags, &opts);
904b9f
+
904b9f
+	opts.action = FAILLOCK_ACTION_AUTHSUCC;
904b9f
+
904b9f
+	if ((rv=get_pam_user(pamh, &opts)) != PAM_SUCCESS) {
904b9f
+		return rv;
904b9f
+	}
904b9f
+
904b9f
+	check_tally(pamh, &opts, &tallies, &fd;;
904b9f
+	if (fd != -1) {
904b9f
+		reset_tally(pamh, &opts, &fd;;
904b9f
+	}
904b9f
+
904b9f
+	tally_cleanup(&tallies, fd);
904b9f
+
904b9f
+	return PAM_SUCCESS;
904b9f
+}
904b9f
+
904b9f
+/*-----------------------------------------------------------------------*/
904b9f
+
904b9f
+#ifdef PAM_STATIC
904b9f
+
904b9f
+/* static module data */
904b9f
+
904b9f
+struct pam_module _pam_faillock_modstruct = {
904b9f
+     MODULE_NAME,
904b9f
+#ifdef PAM_SM_AUTH
904b9f
+     pam_sm_authenticate,
904b9f
+     pam_sm_setcred,
904b9f
+#else
904b9f
+     NULL,
904b9f
+     NULL,
904b9f
+#endif
904b9f
+#ifdef PAM_SM_ACCOUNT
904b9f
+     pam_sm_acct_mgmt,
904b9f
+#else
904b9f
+     NULL,
904b9f
+#endif
904b9f
+     NULL,
904b9f
+     NULL,
904b9f
+     NULL,
904b9f
+};
904b9f
+
904b9f
+#endif   /* #ifdef PAM_STATIC */
904b9f
+
904b9f
diff -up Linux-PAM-1.1.1/modules/pam_faillock/pam_faillock.8.xml.faillock Linux-PAM-1.1.1/modules/pam_faillock/pam_faillock.8.xml
904b9f
--- Linux-PAM-1.1.1/modules/pam_faillock/pam_faillock.8.xml.faillock	2010-09-17 15:58:41.000000000 +0200
904b9f
+++ Linux-PAM-1.1.1/modules/pam_faillock/pam_faillock.8.xml	2010-09-17 15:58:41.000000000 +0200
904b9f
@@ -0,0 +1,396 @@
904b9f
+
904b9f
+
904b9f
+	"http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd">
904b9f
+
904b9f
+<refentry id="pam_faillock">
904b9f
+
904b9f
+  <refmeta>
904b9f
+    <refentrytitle>pam_faillock</refentrytitle>
904b9f
+    <manvolnum>8</manvolnum>
904b9f
+    <refmiscinfo class="sectdesc">Linux-PAM Manual</refmiscinfo>
904b9f
+  </refmeta>
904b9f
+
904b9f
+  <refnamediv id="pam_faillock-name">
904b9f
+    <refname>pam_faillock</refname>
904b9f
+    <refpurpose>Module counting authentication failures during a specified interval</refpurpose>
904b9f
+  </refnamediv>
904b9f
+
904b9f
+  <refsynopsisdiv>
904b9f
+    <cmdsynopsis id="pam_faillock-cmdsynopsisauth">
904b9f
+      <command>auth ... pam_faillock.so</command>
904b9f
+      <arg choice="req">
904b9f
+        preauth|authfail|authsucc
904b9f
+      </arg>
904b9f
+      <arg choice="opt">
904b9f
+        dir=<replaceable>/path/to/tally-directory</replaceable>
904b9f
+      </arg>
904b9f
+      <arg choice="opt">
904b9f
+        even_deny_root
904b9f
+      </arg>
904b9f
+      <arg choice="opt">
904b9f
+        deny=<replaceable>n</replaceable>
904b9f
+      </arg>
904b9f
+      <arg choice="opt">
904b9f
+        fail_interval=<replaceable>n</replaceable>
904b9f
+      </arg>
904b9f
+      <arg choice="opt">
904b9f
+        unlock_time=<replaceable>n</replaceable>
904b9f
+      </arg>
904b9f
+      <arg choice="opt">
904b9f
+        root_unlock_time=<replaceable>n</replaceable>
904b9f
+      </arg>
904b9f
+      <arg choice="opt">
904b9f
+        audit
904b9f
+      </arg>
904b9f
+      <arg choice="opt">
904b9f
+        silent
904b9f
+      </arg>
904b9f
+      <arg choice="opt">
904b9f
+        no_log_info
904b9f
+      </arg>
904b9f
+    </cmdsynopsis>
904b9f
+    <cmdsynopsis id="pam_faillock-cmdsynopsisacct">
904b9f
+      <command>account ... pam_faillock.so</command>
904b9f
+      <arg choice="opt">
904b9f
+        dir=<replaceable>/path/to/tally-directory</replaceable>
904b9f
+      </arg>
904b9f
+      <arg choice="opt">
904b9f
+        no_log_info
904b9f
+      </arg>
904b9f
+    </cmdsynopsis>
904b9f
+  </refsynopsisdiv>
904b9f
+
904b9f
+  <refsect1 id="pam_faillock-description">
904b9f
+
904b9f
+    <title>DESCRIPTION</title>
904b9f
+
904b9f
+    <para>
904b9f
+      This module maintains a list of failed authentication attempts per
904b9f
+      user during a specified interval and locks the account in case
904b9f
+      there were more than <replaceable>deny</replaceable> consecutive
904b9f
+      failed authentications.
904b9f
+    </para>
904b9f
+    <para>
904b9f
+      Normally, failed attempts to authenticate <emphasis>root</emphasis> will
904b9f
+      <emphasis remap='B'>not</emphasis> cause the root account to become
904b9f
+      blocked, to prevent denial-of-service: if your users aren't given
904b9f
+      shell accounts and root may only login via <command>su</command> or
904b9f
+      at the machine console (not telnet/rsh, etc), this is safe.
904b9f
+    </para>
904b9f
+  </refsect1>
904b9f
+
904b9f
+  <refsect1 id="pam_faillock-options">
904b9f
+
904b9f
+    <title>OPTIONS</title>
904b9f
+         <variablelist>
904b9f
+            <varlistentry>
904b9f
+              <term>
904b9f
+                <option>{preauth|authfail|authsucc}</option>
904b9f
+              </term>
904b9f
+              <listitem>
904b9f
+                <para>
904b9f
+                  This argument must be set accordingly to the position of this module
904b9f
+                  instance in the PAM stack.
904b9f
+                </para>
904b9f
+                <para>
904b9f
+                  The <emphasis>preauth</emphasis> argument must be used when the module
904b9f
+                  is called before the modules which ask for the user credentials such
904b9f
+                  as the password. The module just examines whether the user should
904b9f
+                  be blocked from accessing the service in case there were anomalous
904b9f
+                  number of failed consecutive authentication attempts recently. This
904b9f
+                  call is optional if <emphasis>authsucc</emphasis> is used.
904b9f
+                </para>
904b9f
+                <para>
904b9f
+                  The <emphasis>authfail</emphasis> argument must be used when the module
904b9f
+                  is called after the modules which determine the authentication outcome,
904b9f
+                  failed. Unless the user is already blocked due to previous authentication
904b9f
+                  failures, the module will record the failure into the appropriate user
904b9f
+                  tally file.
904b9f
+                </para>
904b9f
+                <para>
904b9f
+                  The <emphasis>authsucc</emphasis> argument must be used when the module
904b9f
+                  is called after the modules which determine the authentication outcome,
904b9f
+                  succeded. Unless the user is already blocked due to previous authentication
904b9f
+                  failures, the module will then clear the record of the failures in the
904b9f
+                  respective user tally file. Otherwise it will return authentication error.
904b9f
+                  If this call is not done, the pam_faillock will not distinguish between
904b9f
+                  consecutive and non-consecutive failed authentication attempts. The
904b9f
+                  <emphasis>preauth</emphasis> call must be used in such case. Due to
904b9f
+                  complications in the way the PAM stack can be configured it is also
904b9f
+                  possible to call <emphasis>pam_faillock</emphasis> as an account module.
904b9f
+                  In such configuration the module must be also called in the
904b9f
+                  <emphasis>preauth</emphasis> stage.
904b9f
+                </para>
904b9f
+              </listitem>
904b9f
+            </varlistentry>
904b9f
+            <varlistentry>
904b9f
+              <term>
904b9f
+                <option>dir=<replaceable>/path/to/tally-directory</replaceable></option>
904b9f
+              </term>
904b9f
+              <listitem>
904b9f
+                <para>
904b9f
+                  The directory where the user files with the failure records are kept. The
904b9f
+                  default is <filename>/var/run/faillock</filename>.
904b9f
+                </para>
904b9f
+              </listitem>
904b9f
+            </varlistentry>
904b9f
+            <varlistentry>
904b9f
+              <term>
904b9f
+                <option>audit</option>
904b9f
+              </term>
904b9f
+              <listitem>
904b9f
+                <para>
904b9f
+                  Will log the user name into the system log if the user is not found.
904b9f
+                </para>
904b9f
+              </listitem>
904b9f
+            </varlistentry>
904b9f
+            <varlistentry>
904b9f
+              <term>
904b9f
+                <option>silent</option>
904b9f
+              </term>
904b9f
+              <listitem>
904b9f
+                <para>
904b9f
+                  Don't print informative messages. This option is implicite
904b9f
+                  in the <emphasis>authfail</emphasis> and <emphasis>authsucc</emphasis>
904b9f
+                  functions.
904b9f
+                </para>
904b9f
+              </listitem>
904b9f
+            </varlistentry>
904b9f
+            <varlistentry>
904b9f
+              <term>
904b9f
+                <option>no_log_info</option>
904b9f
+              </term>
904b9f
+              <listitem>
904b9f
+                <para>
904b9f
+                  Don't log informative messages via <citerefentry><refentrytitle>syslog</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
904b9f
+                </para>
904b9f
+              </listitem>
904b9f
+            </varlistentry>
904b9f
+            <varlistentry>
904b9f
+              <term>
904b9f
+                <option>deny=<replaceable>n</replaceable></option>
904b9f
+              </term>
904b9f
+              <listitem>
904b9f
+                <para>
904b9f
+                  Deny access if the number of consecutive authentication failures
904b9f
+                  for this user during the recent interval exceeds
904b9f
+                  <replaceable>n</replaceable>. The default is 3.
904b9f
+                </para>
904b9f
+              </listitem>
904b9f
+            </varlistentry>
904b9f
+            <varlistentry>
904b9f
+              <term>
904b9f
+                <option>fail_interval=<replaceable>n</replaceable></option>
904b9f
+              </term>
904b9f
+              <listitem>
904b9f
+                <para>
904b9f
+                  The length of the interval during which the consecutive
904b9f
+                  authentication failures must happen for the user account
904b9f
+                  lock out is <replaceable>n</replaceable> seconds.
904b9f
+                  The default is 900 (15 minutes).
904b9f
+                </para>
904b9f
+              </listitem>
904b9f
+            </varlistentry>
904b9f
+            <varlistentry>
904b9f
+              <term>
904b9f
+                <option>unlock_time=<replaceable>n</replaceable></option>
904b9f
+              </term>
904b9f
+              <listitem>
904b9f
+                <para>
904b9f
+                  The access will be reenabled after
904b9f
+                  <replaceable>n</replaceable> seconds after the lock out.
904b9f
+                  The default is 600 (10 minutes).
904b9f
+                </para>
904b9f
+              </listitem>
904b9f
+            </varlistentry>
904b9f
+            <varlistentry>
904b9f
+              <term>
904b9f
+                <option>even_deny_root</option>
904b9f
+              </term>
904b9f
+              <listitem>
904b9f
+                <para>
904b9f
+                  Root account can become locked as well as regular accounts.
904b9f
+                </para>
904b9f
+              </listitem>
904b9f
+            </varlistentry>
904b9f
+            <varlistentry>
904b9f
+              <term>
904b9f
+                <option>root_unlock_time=<replaceable>n</replaceable></option>
904b9f
+              </term>
904b9f
+              <listitem>
904b9f
+                <para>
904b9f
+                  This option implies <option>even_deny_root</option> option.
904b9f
+                  Allow access after <replaceable>n</replaceable> seconds
904b9f
+                  to root account after the account is locked. In case the
904b9f
+                  option is not specified the value is the same as of the
904b9f
+                  <option>unlock_time</option> option.
904b9f
+                </para>
904b9f
+              </listitem>
904b9f
+            </varlistentry>
904b9f
+        </variablelist>
904b9f
+  </refsect1>
904b9f
+
904b9f
+  <refsect1 id="pam_faillock-types">
904b9f
+    <title>MODULE TYPES PROVIDED</title>
904b9f
+    <para>
904b9f
+      The <option>auth</option> and <option>account</option> module types are
904b9f
+      provided.
904b9f
+    </para>
904b9f
+  </refsect1>
904b9f
+
904b9f
+  <refsect1 id='pam_faillock-return_values'>
904b9f
+    <title>RETURN VALUES</title>
904b9f
+    <variablelist>
904b9f
+      <varlistentry>
904b9f
+        <term>PAM_AUTH_ERR</term>
904b9f
+        <listitem>
904b9f
+          <para>
904b9f
+            A invalid option was given, the module was not able
904b9f
+            to retrieve the user name, no valid counter file
904b9f
+            was found, or too many failed logins.
904b9f
+          </para>
904b9f
+        </listitem>
904b9f
+      </varlistentry>
904b9f
+      <varlistentry>
904b9f
+        <term>PAM_SUCCESS</term>
904b9f
+        <listitem>
904b9f
+          <para>
904b9f
+            Everything was successful.
904b9f
+          </para>
904b9f
+        </listitem>
904b9f
+      </varlistentry>
904b9f
+      <varlistentry>
904b9f
+        <term>PAM_IGNORE</term>
904b9f
+        <listitem>
904b9f
+          <para>
904b9f
+            User not present in passwd database.
904b9f
+          </para>
904b9f
+        </listitem>
904b9f
+      </varlistentry>
904b9f
+    </variablelist>
904b9f
+  </refsect1>
904b9f
+
904b9f
+  <refsect1 id='pam_faillock-notes'>
904b9f
+    <title>NOTES</title>
904b9f
+    <para>
904b9f
+      <emphasis>pam_faillock</emphasis> setup in the PAM stack is different
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
+    </para>
904b9f
+    <para>
904b9f
+      Note that using the module in <option>preauth</option> without the
904b9f
+      <option>silent</option> option or with <emphasis>requisite</emphasis>
904b9f
+      control field leaks an information about existence or
904b9f
+      non-existence of an user account in the system because
904b9f
+      the failures are not recorded for the unknown users. The message
904b9f
+      about the user account being locked is never displayed for nonexisting
904b9f
+      user accounts allowing the adversary to infer that a particular account
904b9f
+      is not existing on a system.
904b9f
+    </para>
904b9f
+  </refsect1>
904b9f
+
904b9f
+  <refsect1 id='pam_faillock-examples'>
904b9f
+    <title>EXAMPLES</title>
904b9f
+    <para>
904b9f
+      Here are two possible configuration examples for <filename>/etc/pam.d/login</filename>.
904b9f
+      They make <emphasis>pam_faillock</emphasis> to lock the account after 4 consecutive
904b9f
+      failed logins during the default interval of 15 minutes. Root account will be locked
904b9f
+      as well. The accounts will be automatically unlocked after 20 minutes.
904b9f
+    </para>
904b9f
+    <para>
904b9f
+      In the first example the module is called only in the <emphasis>auth</emphasis>
904b9f
+      phase and the module does not print any information about the account blocking
904b9f
+      by <emphasis>pam_faillock</emphasis>. The <emphasis>preauth</emphasis> call can
904b9f
+      be added to tell the user that his login is blocked by the module and also to abort
904b9f
+      the authentication without even asking for password in such case.
904b9f
+    </para>
904b9f
+    <programlisting>
904b9f
+auth     required       pam_securetty.so
904b9f
+auth     required       pam_env.so
904b9f
+auth     required       pam_nologin.so
904b9f
+# optionally call: auth requisite pam_faillock.so preauth deny=4 even_deny_root unlock_time=1200
904b9f
+# to display the message about account being locked
904b9f
+auth     [success=1 default=bad] pam_unix.so
904b9f
+auth     [default=die]  pam_faillock.so authfail deny=4 even_deny_root unlock_time=1200
904b9f
+auth     sufficient     pam_faillock.so authsucc deny=4 even_deny_root unlock_time=1200
904b9f
+auth     required       pam_deny.so
904b9f
+account  required       pam_unix.so
904b9f
+password required       pam_unix.so shadow
904b9f
+session  required       pam_selinux.so close
904b9f
+session  required       pam_loginuid.so
904b9f
+session  required       pam_unix.so
904b9f
+session  required       pam_selinux.so open
904b9f
+    </programlisting>
904b9f
+    <para>
904b9f
+      In the second example the module is called both in the <emphasis>auth</emphasis>
904b9f
+      and <emphasis>account</emphasis> phases and the module gives the authenticating
904b9f
+      user message when the account is locked 
904b9f
+    </para>
904b9f
+    <programlisting>
904b9f
+auth     required       pam_securetty.so
904b9f
+auth     required       pam_env.so
904b9f
+auth     required       pam_nologin.so
904b9f
+auth     required       pam_faillock.so preauth silent deny=4 even_deny_root unlock_time=1200
904b9f
+# optionally use requisite above if you do not want to prompt for the password
904b9f
+# on locked accounts, possibly with removing the silent option as well
904b9f
+auth     sufficient     pam_unix.so
904b9f
+auth     [default=die]  pam_faillock.so authfail deny=4 even_deny_root unlock_time=1200
904b9f
+auth     required       pam_deny.so
904b9f
+account  required       pam_faillock.so
904b9f
+# if you drop the above call to pam_faillock.so the lock will be done also
904b9f
+# on non-consecutive authentication failures
904b9f
+account  required       pam_unix.so
904b9f
+password required       pam_unix.so shadow
904b9f
+session  required       pam_selinux.so close
904b9f
+session  required       pam_loginuid.so
904b9f
+session  required       pam_unix.so
904b9f
+session  required       pam_selinux.so open
904b9f
+    </programlisting>
904b9f
+  </refsect1>
904b9f
+
904b9f
+  <refsect1 id="pam_faillock-files">
904b9f
+    <title>FILES</title>
904b9f
+    <variablelist>
904b9f
+      <varlistentry>
904b9f
+        <term><filename>/var/run/faillock/*</filename></term>
904b9f
+        <listitem>
904b9f
+          <para>the files logging the authentication failures for users</para>
904b9f
+        </listitem>
904b9f
+      </varlistentry>
904b9f
+    </variablelist>
904b9f
+  </refsect1>
904b9f
+
904b9f
+  <refsect1 id='pam_faillock-see_also'>
904b9f
+    <title>SEE ALSO</title>
904b9f
+    <para>
904b9f
+      <citerefentry>
904b9f
+        <refentrytitle>faillock</refentrytitle><manvolnum>8</manvolnum>
904b9f
+      </citerefentry>,
904b9f
+      <citerefentry>
904b9f
+        <refentrytitle>pam.conf</refentrytitle><manvolnum>5</manvolnum>
904b9f
+      </citerefentry>,
904b9f
+      <citerefentry>
904b9f
+        <refentrytitle>pam.d</refentrytitle><manvolnum>5</manvolnum>
904b9f
+      </citerefentry>,
904b9f
+      <citerefentry>
904b9f
+        <refentrytitle>pam</refentrytitle><manvolnum>8</manvolnum>
904b9f
+      </citerefentry>
904b9f
+    </para>
904b9f
+  </refsect1>
904b9f
+
904b9f
+  <refsect1 id='pam_faillock-author'>
904b9f
+    <title>AUTHOR</title>
904b9f
+      <para>
904b9f
+        pam_faillock was written by Tomas Mraz.
904b9f
+      </para>
904b9f
+  </refsect1>
904b9f
+
904b9f
+</refentry>
904b9f
diff -up Linux-PAM-1.1.1/modules/pam_faillock/README.xml.faillock Linux-PAM-1.1.1/modules/pam_faillock/README.xml
904b9f
--- Linux-PAM-1.1.1/modules/pam_faillock/README.xml.faillock	2010-09-17 15:58:41.000000000 +0200
904b9f
+++ Linux-PAM-1.1.1/modules/pam_faillock/README.xml	2010-09-17 15:58:41.000000000 +0200
904b9f
@@ -0,0 +1,46 @@
904b9f
+
904b9f
+
904b9f
+"http://www.docbook.org/xml/4.3/docbookx.dtd"
904b9f
+[
904b9f
+
904b9f
+
904b9f
+-->
904b9f
+]>
904b9f
+
904b9f
+<article>
904b9f
+
904b9f
+  <articleinfo>
904b9f
+
904b9f
+    <title>
904b9f
+      
904b9f
+      href="pam_faillock.8.xml" xpointer='xpointer(//refnamediv[@id = "pam_faillock-name"]/*)'/>
904b9f
+    </title>
904b9f
+
904b9f
+  </articleinfo>
904b9f
+
904b9f
+  <section>
904b9f
+    
904b9f
+      href="pam_faillock.8.xml" xpointer='xpointer(//refsect1[@id = "pam_faillock-description"]/*)'/>
904b9f
+  </section>
904b9f
+
904b9f
+  <section>
904b9f
+    
904b9f
+      href="pam_faillock.8.xml" xpointer='xpointer(//refsect1[@id = "pam_faillock-options"]/*)'/>
904b9f
+  </section>
904b9f
+
904b9f
+  <section>
904b9f
+    
904b9f
+      href="pam_faillock.8.xml" xpointer='xpointer(//refsect1[@id = "pam_faillock-notes"]/*)'/>
904b9f
+  </section>
904b9f
+
904b9f
+  <section>
904b9f
+    
904b9f
+      href="pam_faillock.8.xml" xpointer='xpointer(//refsect1[@id = "pam_faillock-examples"]/*)'/>
904b9f
+  </section>
904b9f
+
904b9f
+  <section>
904b9f
+    
904b9f
+      href="pam_faillock.8.xml" xpointer='xpointer(//refsect1[@id = "pam_faillock-author"]/*)'/>
904b9f
+  </section>
904b9f
+
904b9f
+</article>
904b9f
diff -up Linux-PAM-1.1.1/modules/pam_faillock/tst-pam_faillock.faillock Linux-PAM-1.1.1/modules/pam_faillock/tst-pam_faillock
904b9f
--- Linux-PAM-1.1.1/modules/pam_faillock/tst-pam_faillock.faillock	2010-09-17 15:58:41.000000000 +0200
904b9f
+++ Linux-PAM-1.1.1/modules/pam_faillock/tst-pam_faillock	2010-09-17 15:58:41.000000000 +0200
904b9f
@@ -0,0 +1,2 @@
904b9f
+#!/bin/sh
904b9f
+../../tests/tst-dlopen .libs/pam_faillock.so