Blame SOURCES/pam-1.3.1-pam-pwhistory-load-conf-from-file.patch

73ee87
diff -up Linux-PAM-1.3.1/modules/pam_pwhistory/Makefile.am.pam-pwhistory-load-conf-from-file Linux-PAM-1.3.1/modules/pam_pwhistory/Makefile.am
73ee87
--- Linux-PAM-1.3.1/modules/pam_pwhistory/Makefile.am.pam-pwhistory-load-conf-from-file	2022-09-29 10:13:35.709355179 +0200
73ee87
+++ Linux-PAM-1.3.1/modules/pam_pwhistory/Makefile.am	2022-09-29 10:13:35.780355766 +0200
73ee87
@@ -10,9 +10,10 @@ EXTRA_DIST = README $(MANS) $(XMLS) tst-
73ee87
 
73ee87
 TESTS = tst-pam_pwhistory
73ee87
 
73ee87
-man_MANS = pam_pwhistory.8 pwhistory_helper.8
73ee87
+man_MANS = pam_pwhistory.8 pwhistory_helper.8 pwhistory.conf.5
73ee87
 
73ee87
-XMLS = README.xml pam_pwhistory.8.xml pwhistory_helper.8.xml
73ee87
+XMLS = README.xml pam_pwhistory.8.xml pwhistory_helper.8.xml \
73ee87
+  pwhistory.conf.5.xml
73ee87
 
73ee87
 securelibdir = $(SECUREDIR)
73ee87
 secureconfdir = $(SCONFIGDIR)
73ee87
@@ -25,12 +26,14 @@ if HAVE_VERSIONING
73ee87
   pam_pwhistory_la_LDFLAGS += -Wl,--version-script=$(srcdir)/../modules.map
73ee87
 endif
73ee87
 
73ee87
-noinst_HEADERS = opasswd.h
73ee87
+noinst_HEADERS = opasswd.h pwhistory_config.h
73ee87
+
73ee87
+dist_secureconf_DATA = pwhistory.conf
73ee87
 
73ee87
 securelib_LTLIBRARIES = pam_pwhistory.la
73ee87
 pam_pwhistory_la_CFLAGS = $(AM_CFLAGS)
73ee87
 pam_pwhistory_la_LIBADD = $(top_builddir)/libpam/libpam.la @LIBCRYPT@ @LIBSELINUX@
73ee87
-pam_pwhistory_la_SOURCES = pam_pwhistory.c opasswd.c
73ee87
+pam_pwhistory_la_SOURCES = pam_pwhistory.c opasswd.c pwhistory_config.c
73ee87
 
73ee87
 sbin_PROGRAMS = pwhistory_helper
73ee87
 pwhistory_helper_CFLAGS = $(AM_CFLAGS) -DHELPER_COMPILE=\"pwhistory_helper\" @PIE_CFLAGS@
73ee87
diff -up Linux-PAM-1.3.1/modules/pam_pwhistory/pam_pwhistory.8.xml.pam-pwhistory-load-conf-from-file Linux-PAM-1.3.1/modules/pam_pwhistory/pam_pwhistory.8.xml
73ee87
--- Linux-PAM-1.3.1/modules/pam_pwhistory/pam_pwhistory.8.xml.pam-pwhistory-load-conf-from-file	2017-02-10 11:10:15.000000000 +0100
73ee87
+++ Linux-PAM-1.3.1/modules/pam_pwhistory/pam_pwhistory.8.xml	2022-09-29 10:13:35.780355766 +0200
73ee87
@@ -36,6 +36,9 @@
73ee87
       <arg choice="opt">
73ee87
         authtok_type=<replaceable>STRING</replaceable>
73ee87
       </arg>
73ee87
+      <arg choice="opt">
73ee87
+	      conf=<replaceable>/path/to/config-file</replaceable>
73ee87
+      </arg>
73ee87
 
73ee87
     </cmdsynopsis>
73ee87
   </refsynopsisdiv>
73ee87
@@ -104,7 +107,7 @@
73ee87
         <listitem>
73ee87
           <para>
73ee87
             The last <replaceable>N</replaceable> passwords for each
73ee87
-            user are saved in <filename>/etc/security/opasswd</filename>.
73ee87
+            user are saved.
73ee87
             The default is <emphasis>10</emphasis>. Value of
73ee87
             <emphasis>0</emphasis> makes the module to keep the existing
73ee87
             contents of the <filename>opasswd</filename> file unchanged.
73ee87
@@ -137,7 +140,26 @@
73ee87
           </listitem>
73ee87
         </varlistentry>
73ee87
 
73ee87
+        <varlistentry>
73ee87
+          <term>
73ee87
+            <option>conf=<replaceable>/path/to/config-file</replaceable></option>
73ee87
+          </term>
73ee87
+          <listitem>
73ee87
+            <para>
73ee87
+              Use another configuration file instead of the default
73ee87
+              <filename>/etc/security/pwhistory.conf</filename>.
73ee87
+            </para>
73ee87
+          </listitem>
73ee87
+        </varlistentry>
73ee87
+
73ee87
     </variablelist>
73ee87
+    <para>
73ee87
+      The options for configuring the module behavior are described in the
73ee87
+      <citerefentry><refentrytitle>pwhistory.conf</refentrytitle>
73ee87
+      <manvolnum>5</manvolnum></citerefentry> manual page. The options
73ee87
+      specified on the module command line override the values from the
73ee87
+      configuration file.
73ee87
+    </para>
73ee87
   </refsect1>
73ee87
 
73ee87
   <refsect1 id="pam_pwhistory-types">
73ee87
@@ -223,6 +245,9 @@ password     required       pam_unix.so
73ee87
     <title>SEE ALSO</title>
73ee87
     <para>
73ee87
       <citerefentry>
73ee87
+	<refentrytitle>pwhistory.conf</refentrytitle><manvolnum>5</manvolnum>
73ee87
+      </citerefentry>,
73ee87
+      <citerefentry>
73ee87
 	<refentrytitle>pam.conf</refentrytitle><manvolnum>5</manvolnum>
73ee87
       </citerefentry>,
73ee87
       <citerefentry>
73ee87
diff -up Linux-PAM-1.3.1/modules/pam_pwhistory/pam_pwhistory.c.pam-pwhistory-load-conf-from-file Linux-PAM-1.3.1/modules/pam_pwhistory/pam_pwhistory.c
73ee87
--- Linux-PAM-1.3.1/modules/pam_pwhistory/pam_pwhistory.c.pam-pwhistory-load-conf-from-file	2022-09-29 10:13:35.711355195 +0200
73ee87
+++ Linux-PAM-1.3.1/modules/pam_pwhistory/pam_pwhistory.c	2022-09-29 10:13:35.780355766 +0200
73ee87
@@ -62,18 +62,11 @@
73ee87
 #include <security/_pam_macros.h>
73ee87
 
73ee87
 #include "opasswd.h"
73ee87
+#include "pwhistory_config.h"
73ee87
 
73ee87
 #define DEFAULT_BUFLEN 2048
73ee87
 #define MAX_FD_NO 20000
73ee87
 
73ee87
-struct options_t {
73ee87
-  int debug;
73ee87
-  int enforce_for_root;
73ee87
-  int remember;
73ee87
-  int tries;
73ee87
-};
73ee87
-typedef struct options_t options_t;
73ee87
-
73ee87
 
73ee87
 static void
73ee87
 parse_option (pam_handle_t *pamh, const char *argv, options_t *options)
73ee87
@@ -304,6 +297,8 @@ pam_sm_chauthtok (pam_handle_t *pamh, in
73ee87
   options.remember = 10;
73ee87
   options.tries = 1;
73ee87
 
73ee87
+  parse_config_file(pamh, argc, argv, &options);
73ee87
+
73ee87
   /* Parse parameters for module */
73ee87
   for ( ; argc-- > 0; argv++)
73ee87
     parse_option (pamh, *argv, &options);
73ee87
@@ -311,7 +306,6 @@ pam_sm_chauthtok (pam_handle_t *pamh, in
73ee87
   if (options.debug)
73ee87
     pam_syslog (pamh, LOG_DEBUG, "pam_sm_chauthtok entered");
73ee87
 
73ee87
-
73ee87
   if (options.remember == 0)
73ee87
     return PAM_IGNORE;
73ee87
 
73ee87
diff -up Linux-PAM-1.3.1/modules/pam_pwhistory/pwhistory.conf.5.xml.pam-pwhistory-load-conf-from-file Linux-PAM-1.3.1/modules/pam_pwhistory/pwhistory.conf.5.xml
73ee87
--- Linux-PAM-1.3.1/modules/pam_pwhistory/pwhistory.conf.5.xml.pam-pwhistory-load-conf-from-file	2022-09-29 10:13:35.780355766 +0200
73ee87
+++ Linux-PAM-1.3.1/modules/pam_pwhistory/pwhistory.conf.5.xml	2022-09-29 10:13:35.780355766 +0200
73ee87
@@ -0,0 +1,155 @@
73ee87
+
73ee87
+
73ee87
+	"http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd">
73ee87
+
73ee87
+<refentry id="pwhistory.conf">
73ee87
+
73ee87
+  <refmeta>
73ee87
+    <refentrytitle>pwhistory.conf</refentrytitle>
73ee87
+    <manvolnum>5</manvolnum>
73ee87
+    <refmiscinfo class="sectdesc">Linux-PAM Manual</refmiscinfo>
73ee87
+  </refmeta>
73ee87
+
73ee87
+  <refnamediv id="pwhistory.conf-name">
73ee87
+    <refname>pwhistory.conf</refname>
73ee87
+    <refpurpose>pam_pwhistory configuration file</refpurpose>
73ee87
+  </refnamediv>
73ee87
+
73ee87
+  <refsect1 id="pwhistory.conf-description">
73ee87
+
73ee87
+    <title>DESCRIPTION</title>
73ee87
+    <para>
73ee87
+       <emphasis remap='B'>pwhistory.conf</emphasis> provides a way to configure the
73ee87
+       default settings for saving the last passwords for each user.
73ee87
+       This file is read by the <emphasis>pam_pwhistory</emphasis> module and is the
73ee87
+       preferred method over configuring <emphasis>pam_pwhistory</emphasis> directly.
73ee87
+    </para>
73ee87
+    <para>
73ee87
+       The file has a very simple <emphasis>name = value</emphasis> format with possible comments
73ee87
+       starting with <emphasis>#</emphasis> character. The whitespace at the beginning of line, end
73ee87
+       of line, and around the <emphasis>=</emphasis> sign is ignored.
73ee87
+    </para>
73ee87
+  </refsect1>
73ee87
+
73ee87
+  <refsect1 id="pwhistory.conf-options">
73ee87
+
73ee87
+    <title>OPTIONS</title>
73ee87
+         <variablelist>
73ee87
+            <varlistentry>
73ee87
+              <term>
73ee87
+                <option>debug</option>
73ee87
+              </term>
73ee87
+              <listitem>
73ee87
+                <para>
73ee87
+                  Turns on debugging via
73ee87
+                  <citerefentry>
73ee87
+                    <refentrytitle>syslog</refentrytitle><manvolnum>3</manvolnum>
73ee87
+                  </citerefentry>.
73ee87
+                </para>
73ee87
+              </listitem>
73ee87
+            </varlistentry>
73ee87
+            <varlistentry>
73ee87
+              <term>
73ee87
+                <option>enforce_for_root</option>
73ee87
+              </term>
73ee87
+              <listitem>
73ee87
+                <para>
73ee87
+                  If this option is set, the check is enforced for root, too.
73ee87
+                </para>
73ee87
+              </listitem>
73ee87
+            </varlistentry>
73ee87
+            <varlistentry>
73ee87
+              <term>
73ee87
+                <option>remember=<replaceable>N</replaceable></option>
73ee87
+              </term>
73ee87
+              <listitem>
73ee87
+                <para>
73ee87
+                  The last <replaceable>N</replaceable> passwords for each
73ee87
+                  user are saved.
73ee87
+                  The default is <emphasis>10</emphasis>. Value of
73ee87
+                  <emphasis>0</emphasis> makes the module to keep the existing
73ee87
+                  contents of the <filename>opasswd</filename> file unchanged.
73ee87
+                </para>
73ee87
+              </listitem>
73ee87
+            </varlistentry>
73ee87
+            <varlistentry>
73ee87
+              <term>
73ee87
+                <option>retry=<replaceable>N</replaceable></option>
73ee87
+              </term>
73ee87
+              <listitem>
73ee87
+                <para>
73ee87
+                  Prompt user at most <replaceable>N</replaceable> times
73ee87
+                  before returning with error. The default is 1.
73ee87
+                </para>
73ee87
+              </listitem>
73ee87
+            </varlistentry>
73ee87
+            <varlistentry>
73ee87
+              <term>
73ee87
+                <option>file=<replaceable>/path/filename</replaceable></option>
73ee87
+              </term>
73ee87
+              <listitem>
73ee87
+                <para>
73ee87
+                  Store password history in file
73ee87
+                  <replaceable>/path/filename</replaceable> rather than the default
73ee87
+                  location. The default location is
73ee87
+	                <filename>/etc/security/opasswd</filename>.
73ee87
+                </para>
73ee87
+              </listitem>
73ee87
+            </varlistentry>
73ee87
+        </variablelist>
73ee87
+  </refsect1>
73ee87
+
73ee87
+  <refsect1 id='pwhistory.conf-examples'>
73ee87
+    <title>EXAMPLES</title>
73ee87
+    <para>
73ee87
+      /etc/security/pwhistory.conf file example:
73ee87
+    </para>
73ee87
+    <programlisting>
73ee87
+debug
73ee87
+remember=5
73ee87
+file=/tmp/opasswd
73ee87
+    </programlisting>
73ee87
+  </refsect1>
73ee87
+
73ee87
+  <refsect1 id="pwhistory.conf-files">
73ee87
+    <title>FILES</title>
73ee87
+    <variablelist>
73ee87
+      <varlistentry>
73ee87
+        <term><filename>/etc/security/pwhistory.conf</filename></term>
73ee87
+        <listitem>
73ee87
+          <para>the config file for custom options</para>
73ee87
+        </listitem>
73ee87
+      </varlistentry>
73ee87
+    </variablelist>
73ee87
+  </refsect1>
73ee87
+
73ee87
+  <refsect1 id='pwhistory.conf-see_also'>
73ee87
+    <title>SEE ALSO</title>
73ee87
+    <para>
73ee87
+      <citerefentry>
73ee87
+        <refentrytitle>pwhistory</refentrytitle><manvolnum>8</manvolnum>
73ee87
+      </citerefentry>,
73ee87
+      <citerefentry>
73ee87
+        <refentrytitle>pam_pwhistory</refentrytitle><manvolnum>8</manvolnum>
73ee87
+      </citerefentry>,
73ee87
+      <citerefentry>
73ee87
+        <refentrytitle>pam.conf</refentrytitle><manvolnum>5</manvolnum>
73ee87
+      </citerefentry>,
73ee87
+      <citerefentry>
73ee87
+        <refentrytitle>pam.d</refentrytitle><manvolnum>5</manvolnum>
73ee87
+      </citerefentry>,
73ee87
+      <citerefentry>
73ee87
+        <refentrytitle>pam</refentrytitle><manvolnum>8</manvolnum>
73ee87
+      </citerefentry>
73ee87
+    </para>
73ee87
+  </refsect1>
73ee87
+
73ee87
+  <refsect1 id='pwhistory.conf-author'>
73ee87
+    <title>AUTHOR</title>
73ee87
+      <para>
73ee87
+        pam_pwhistory was written by Thorsten Kukuk. The support for
73ee87
+        pwhistory.conf was written by Iker Pedrosa.
73ee87
+      </para>
73ee87
+  </refsect1>
73ee87
+
73ee87
+</refentry>
73ee87
diff -up Linux-PAM-1.3.1/modules/pam_pwhistory/pwhistory_config.c.pam-pwhistory-load-conf-from-file Linux-PAM-1.3.1/modules/pam_pwhistory/pwhistory_config.c
73ee87
--- Linux-PAM-1.3.1/modules/pam_pwhistory/pwhistory_config.c.pam-pwhistory-load-conf-from-file	2022-09-29 10:13:35.781355775 +0200
73ee87
+++ Linux-PAM-1.3.1/modules/pam_pwhistory/pwhistory_config.c	2022-09-29 10:14:33.377832622 +0200
73ee87
@@ -0,0 +1,195 @@
73ee87
+/*
73ee87
+ * Copyright (c) 2022 Iker Pedrosa <ipedrosa@redhat.com>
73ee87
+ *
73ee87
+ * Redistribution and use in source and binary forms, with or without
73ee87
+ * modification, are permitted provided that the following conditions
73ee87
+ * are met:
73ee87
+ * 1. Redistributions of source code must retain the above copyright
73ee87
+ *    notice, and the entire permission notice in its entirety,
73ee87
+ *    including the disclaimer of warranties.
73ee87
+ * 2. Redistributions in binary form must reproduce the above copyright
73ee87
+ *    notice, this list of conditions and the following disclaimer in the
73ee87
+ *    documentation and/or other materials provided with the distribution.
73ee87
+ * 3. The name of the author may not be used to endorse or promote
73ee87
+ *    products derived from this software without specific prior
73ee87
+ *    written permission.
73ee87
+ *
73ee87
+ * ALTERNATIVELY, this product may be distributed under the terms of
73ee87
+ * the GNU Public License, in which case the provisions of the GPL are
73ee87
+ * required INSTEAD OF the above restrictions.  (This clause is
73ee87
+ * necessary due to a potential bad interaction between the GPL and
73ee87
+ * the restrictions contained in a BSD-style copyright.)
73ee87
+ *
73ee87
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
73ee87
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
73ee87
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
73ee87
+ * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
73ee87
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
73ee87
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
73ee87
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
73ee87
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
73ee87
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
73ee87
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
73ee87
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
73ee87
+ */
73ee87
+
73ee87
+#include "config.h"
73ee87
+
73ee87
+#include <stdio.h>
73ee87
+#include <stdlib.h>
73ee87
+#include <string.h>
73ee87
+#include <syslog.h>
73ee87
+#include <ctype.h>
73ee87
+
73ee87
+#include <security/pam_modutil.h>
73ee87
+
73ee87
+#include "pam_inline.h"
73ee87
+#include "pwhistory_config.h"
73ee87
+
73ee87
+#define PWHISTORY_DEFAULT_CONF "/etc/security/pwhistory.conf"
73ee87
+
73ee87
+/* lookup a value for key in login.defs file or similar key value format */
73ee87
+static char *
73ee87
+pwhistory_search_key(pam_handle_t *pamh UNUSED,
73ee87
+		       const char *file_name,
73ee87
+		       const char *key)
73ee87
+{
73ee87
+	FILE *fp;
73ee87
+	char *buf = NULL;
73ee87
+	size_t buflen = 0;
73ee87
+	char *retval = NULL;
73ee87
+
73ee87
+#ifdef USE_ECONF
73ee87
+	if (strcmp (file_name, LOGIN_DEFS) == 0)
73ee87
+		return econf_search_key ("login", ".defs", key);
73ee87
+#endif
73ee87
+
73ee87
+	fp = fopen(file_name, "r");
73ee87
+	if (NULL == fp)
73ee87
+		return NULL;
73ee87
+
73ee87
+	while (!feof(fp)) {
73ee87
+		char *tmp, *cp;
73ee87
+#if defined(HAVE_GETLINE)
73ee87
+		ssize_t n = getline(&buf, &buflen, fp);
73ee87
+#elif defined (HAVE_GETDELIM)
73ee87
+		ssize_t n = getdelim(&buf, &buflen, '\n', fp);
73ee87
+#else
73ee87
+		ssize_t n;
73ee87
+
73ee87
+		if (buf == NULL) {
73ee87
+			buflen = BUF_SIZE;
73ee87
+			buf = malloc(buflen);
73ee87
+			if (buf == NULL) {
73ee87
+				fclose(fp);
73ee87
+				return NULL;
73ee87
+			}
73ee87
+		}
73ee87
+		buf[0] = '\0';
73ee87
+		if (fgets(buf, buflen - 1, fp) == NULL)
73ee87
+			break;
73ee87
+		else if (buf != NULL)
73ee87
+			n = strlen(buf);
73ee87
+		else
73ee87
+			n = 0;
73ee87
+#endif /* HAVE_GETLINE / HAVE_GETDELIM */
73ee87
+		cp = buf;
73ee87
+
73ee87
+		if (n < 1)
73ee87
+			break;
73ee87
+		if (cp[n - 1] == '\n')
73ee87
+			cp[n - 1] = '\0';
73ee87
+
73ee87
+		tmp = strchr(cp, '#');  /* remove comments */
73ee87
+		if (tmp)
73ee87
+			*tmp = '\0';
73ee87
+		while (isspace((int)*cp))    /* remove spaces and tabs */
73ee87
+			++cp;
73ee87
+		if (*cp == '\0')        /* ignore empty lines */
73ee87
+			continue;
73ee87
+
73ee87
+		tmp = strsep (&cp, " \t=");
73ee87
+		if (cp != NULL)
73ee87
+			while (isspace((int)*cp) || *cp == '=')
73ee87
+				++cp;
73ee87
+		else
73ee87
+			cp = buf + n;   /* empty string */
73ee87
+
73ee87
+		if (strcasecmp(tmp, key) == 0) {
73ee87
+			retval = strdup(cp);
73ee87
+			break;
73ee87
+		}
73ee87
+	}
73ee87
+	fclose(fp);
73ee87
+
73ee87
+	free(buf);
73ee87
+
73ee87
+	return retval;
73ee87
+}
73ee87
+
73ee87
+void
73ee87
+parse_config_file(pam_handle_t *pamh, int argc, const char **argv,
73ee87
+                  struct options_t *options)
73ee87
+{
73ee87
+    const char *fname = NULL;
73ee87
+    int i;
73ee87
+    char *val;
73ee87
+
73ee87
+    for (i = 0; i < argc; ++i) {
73ee87
+        const char *str = pam_str_skip_prefix(argv[i], "conf=");
73ee87
+
73ee87
+        if (str != NULL) {
73ee87
+            fname = str;
73ee87
+        }
73ee87
+    }
73ee87
+
73ee87
+    if (fname == NULL) {
73ee87
+        fname = PWHISTORY_DEFAULT_CONF;
73ee87
+    }
73ee87
+
73ee87
+    val = pwhistory_search_key (pamh, fname, "debug");
73ee87
+    if (val != NULL) {
73ee87
+        options->debug = 1;
73ee87
+        free(val);
73ee87
+    }
73ee87
+
73ee87
+    val = pwhistory_search_key (pamh, fname, "enforce_for_root");
73ee87
+    if (val != NULL) {
73ee87
+        options->enforce_for_root = 1;
73ee87
+        free(val);
73ee87
+    }
73ee87
+
73ee87
+    val = pwhistory_search_key (pamh, fname, "remember");
73ee87
+    if (val != NULL) {
73ee87
+        unsigned int temp;
73ee87
+        if (sscanf(val, "%u", &temp) != 1) {
73ee87
+            pam_syslog(pamh, LOG_ERR,
73ee87
+                "Bad number supplied for remember argument");
73ee87
+        } else {
73ee87
+            options->remember = temp;
73ee87
+        }
73ee87
+        free(val);
73ee87
+    }
73ee87
+
73ee87
+    val = pwhistory_search_key (pamh, fname, "retry");
73ee87
+    if (val != NULL) {
73ee87
+        unsigned int temp;
73ee87
+        if (sscanf(val, "%u", &temp) != 1) {
73ee87
+            pam_syslog(pamh, LOG_ERR,
73ee87
+                "Bad number supplied for retry argument");
73ee87
+        } else {
73ee87
+            options->tries = temp;
73ee87
+        }
73ee87
+        free(val);
73ee87
+    }
73ee87
+
73ee87
+    val = pwhistory_search_key (pamh, fname, "file");
73ee87
+    if (val != NULL) {
73ee87
+        if (*val != '/') {
73ee87
+            pam_syslog (pamh, LOG_ERR,
73ee87
+                "File path should be absolute: %s", val);
73ee87
+        } else {
73ee87
+            options->filename = val;
73ee87
+        }
73ee87
+    }
73ee87
+}
73ee87
diff -up Linux-PAM-1.3.1/modules/pam_pwhistory/pwhistory_config.h.pam-pwhistory-load-conf-from-file Linux-PAM-1.3.1/modules/pam_pwhistory/pwhistory_config.h
73ee87
--- Linux-PAM-1.3.1/modules/pam_pwhistory/pwhistory_config.h.pam-pwhistory-load-conf-from-file	2022-09-29 10:13:35.781355775 +0200
73ee87
+++ Linux-PAM-1.3.1/modules/pam_pwhistory/pwhistory_config.h	2022-09-29 10:13:35.781355775 +0200
73ee87
@@ -0,0 +1,54 @@
73ee87
+/*
73ee87
+ * Copyright (c) 2022 Iker Pedrosa <ipedrosa@redhat.com>
73ee87
+ *
73ee87
+ * Redistribution and use in source and binary forms, with or without
73ee87
+ * modification, are permitted provided that the following conditions
73ee87
+ * are met:
73ee87
+ * 1. Redistributions of source code must retain the above copyright
73ee87
+ *    notice, and the entire permission notice in its entirety,
73ee87
+ *    including the disclaimer of warranties.
73ee87
+ * 2. Redistributions in binary form must reproduce the above copyright
73ee87
+ *    notice, this list of conditions and the following disclaimer in the
73ee87
+ *    documentation and/or other materials provided with the distribution.
73ee87
+ * 3. The name of the author may not be used to endorse or promote
73ee87
+ *    products derived from this software without specific prior
73ee87
+ *    written permission.
73ee87
+ *
73ee87
+ * ALTERNATIVELY, this product may be distributed under the terms of
73ee87
+ * the GNU Public License, in which case the provisions of the GPL are
73ee87
+ * required INSTEAD OF the above restrictions.  (This clause is
73ee87
+ * necessary due to a potential bad interaction between the GPL and
73ee87
+ * the restrictions contained in a BSD-style copyright.)
73ee87
+ *
73ee87
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
73ee87
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
73ee87
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
73ee87
+ * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
73ee87
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
73ee87
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
73ee87
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
73ee87
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
73ee87
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
73ee87
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
73ee87
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
73ee87
+ */
73ee87
+
73ee87
+#ifndef _PWHISTORY_CONFIG_H
73ee87
+#define _PWHISTORY_CONFIG_H
73ee87
+
73ee87
+#include <security/pam_ext.h>
73ee87
+
73ee87
+struct options_t {
73ee87
+    int debug;
73ee87
+    int enforce_for_root;
73ee87
+    int remember;
73ee87
+    int tries;
73ee87
+    const char *filename;
73ee87
+};
73ee87
+typedef struct options_t options_t;
73ee87
+
73ee87
+void
73ee87
+parse_config_file(pam_handle_t *pamh, int argc, const char **argv,
73ee87
+                  struct options_t *options);
73ee87
+
73ee87
+#endif /* _PWHISTORY_CONFIG_H */
73ee87
diff -up Linux-PAM-1.3.1/modules/pam_pwhistory/pwhistory.conf.pam-pwhistory-load-conf-from-file Linux-PAM-1.3.1/modules/pam_pwhistory/pwhistory.conf
73ee87
--- Linux-PAM-1.3.1/modules/pam_pwhistory/pwhistory.conf.pam-pwhistory-load-conf-from-file	2022-09-29 10:13:35.781355775 +0200
73ee87
+++ Linux-PAM-1.3.1/modules/pam_pwhistory/pwhistory.conf	2022-09-29 10:13:35.781355775 +0200
73ee87
@@ -0,0 +1,21 @@
73ee87
+# Configuration for remembering the last passwords used by a user.
73ee87
+#
73ee87
+# Enable the debugging logs.
73ee87
+# Enabled if option is present.
73ee87
+# debug
73ee87
+#
73ee87
+# root account's passwords are also remembered.
73ee87
+# Enabled if option is present.
73ee87
+# enforce_for_root
73ee87
+#
73ee87
+# Number of passwords to remember.
73ee87
+# The default is 10.
73ee87
+# remember = 10
73ee87
+#
73ee87
+# Number of times to prompt for the password.
73ee87
+# The default is 1.
73ee87
+# retry = 1
73ee87
+#
73ee87
+# The directory where the last passwords are kept.
73ee87
+# The default is /etc/security/opasswd.
73ee87
+# file = /etc/security/opasswd