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