|
|
f109b2 |
diff -up Linux-PAM-1.3.1/modules/pam_faillock/faillock.8.xml.faillock-load-conf-from-file Linux-PAM-1.3.1/modules/pam_faillock/faillock.8.xml
|
|
|
f109b2 |
--- Linux-PAM-1.3.1/modules/pam_faillock/faillock.8.xml.faillock-load-conf-from-file 2022-05-26 10:57:11.713067506 +0200
|
|
|
f109b2 |
+++ Linux-PAM-1.3.1/modules/pam_faillock/faillock.8.xml 2022-05-26 10:57:11.747067749 +0200
|
|
|
f109b2 |
@@ -57,12 +57,29 @@
|
|
|
f109b2 |
<variablelist>
|
|
|
f109b2 |
<varlistentry>
|
|
|
f109b2 |
<term>
|
|
|
f109b2 |
+ <option>--conf <replaceable>/path/to/config-file</replaceable></option>
|
|
|
f109b2 |
+ </term>
|
|
|
f109b2 |
+ <listitem>
|
|
|
f109b2 |
+ <para>
|
|
|
f109b2 |
+ The file where the configuration is located. The default is
|
|
|
f109b2 |
+ <filename>/etc/security/faillock.conf</filename>.
|
|
|
f109b2 |
+ </para>
|
|
|
f109b2 |
+ </listitem>
|
|
|
f109b2 |
+ </varlistentry>
|
|
|
f109b2 |
+ <varlistentry>
|
|
|
f109b2 |
+ <term>
|
|
|
f109b2 |
<option>--dir <replaceable>/path/to/tally-directory</replaceable></option>
|
|
|
f109b2 |
</term>
|
|
|
f109b2 |
<listitem>
|
|
|
f109b2 |
<para>
|
|
|
f109b2 |
- The directory where the user files with the failure records are kept. The
|
|
|
f109b2 |
- default is <filename>/var/run/faillock</filename>.
|
|
|
f109b2 |
+ The directory where the user files with the failure records are kept.
|
|
|
f109b2 |
+ </para>
|
|
|
f109b2 |
+ <para>
|
|
|
f109b2 |
+ The priority to set this option is to use the value provided
|
|
|
f109b2 |
+ from the command line. If this isn't provided, then the value
|
|
|
f109b2 |
+ from the configuration file is used. Finally, if neither of
|
|
|
f109b2 |
+ them has been provided, then
|
|
|
f109b2 |
+ <filename>/var/run/faillock</filename> is used.
|
|
|
f109b2 |
</para>
|
|
|
f109b2 |
</listitem>
|
|
|
f109b2 |
</varlistentry>
|
|
|
f109b2 |
diff -up Linux-PAM-1.3.1/modules/pam_faillock/faillock_config.c.faillock-load-conf-from-file Linux-PAM-1.3.1/modules/pam_faillock/faillock_config.c
|
|
|
f109b2 |
--- Linux-PAM-1.3.1/modules/pam_faillock/faillock_config.c.faillock-load-conf-from-file 2022-05-26 10:57:11.747067749 +0200
|
|
|
f109b2 |
+++ Linux-PAM-1.3.1/modules/pam_faillock/faillock_config.c 2022-05-26 10:57:11.747067749 +0200
|
|
|
f109b2 |
@@ -0,0 +1,266 @@
|
|
|
f109b2 |
+/*
|
|
|
f109b2 |
+ * Copyright (c) 2022 Tomas Mraz <tm@t8m.info>
|
|
|
f109b2 |
+ * Copyright (c) 2022 Iker Pedrosa <ipedrosa@redhat.com>
|
|
|
f109b2 |
+ *
|
|
|
f109b2 |
+ * Redistribution and use in source and binary forms, with or without
|
|
|
f109b2 |
+ * modification, are permitted provided that the following conditions
|
|
|
f109b2 |
+ * are met:
|
|
|
f109b2 |
+ * 1. Redistributions of source code must retain the above copyright
|
|
|
f109b2 |
+ * notice, and the entire permission notice in its entirety,
|
|
|
f109b2 |
+ * including the disclaimer of warranties.
|
|
|
f109b2 |
+ * 2. Redistributions in binary form must reproduce the above copyright
|
|
|
f109b2 |
+ * notice, this list of conditions and the following disclaimer in the
|
|
|
f109b2 |
+ * documentation and/or other materials provided with the distribution.
|
|
|
f109b2 |
+ * 3. The name of the author may not be used to endorse or promote
|
|
|
f109b2 |
+ * products derived from this software without specific prior
|
|
|
f109b2 |
+ * written permission.
|
|
|
f109b2 |
+ *
|
|
|
f109b2 |
+ * ALTERNATIVELY, this product may be distributed under the terms of
|
|
|
f109b2 |
+ * the GNU Public License, in which case the provisions of the GPL are
|
|
|
f109b2 |
+ * required INSTEAD OF the above restrictions. (This clause is
|
|
|
f109b2 |
+ * necessary due to a potential bad interaction between the GPL and
|
|
|
f109b2 |
+ * the restrictions contained in a BSD-style copyright.)
|
|
|
f109b2 |
+ *
|
|
|
f109b2 |
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
|
|
f109b2 |
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
f109b2 |
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
f109b2 |
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
|
|
f109b2 |
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
f109b2 |
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
f109b2 |
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
f109b2 |
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
|
f109b2 |
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
f109b2 |
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
|
|
f109b2 |
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
f109b2 |
+ */
|
|
|
f109b2 |
+
|
|
|
f109b2 |
+#include "config.h"
|
|
|
f109b2 |
+
|
|
|
f109b2 |
+#include <ctype.h>
|
|
|
f109b2 |
+#include <errno.h>
|
|
|
f109b2 |
+#include <stdio.h>
|
|
|
f109b2 |
+#include <stdlib.h>
|
|
|
f109b2 |
+#include <string.h>
|
|
|
f109b2 |
+#include <syslog.h>
|
|
|
f109b2 |
+
|
|
|
f109b2 |
+#include <security/pam_modules.h>
|
|
|
f109b2 |
+
|
|
|
f109b2 |
+#include "faillock_config.h"
|
|
|
f109b2 |
+#include "faillock.h"
|
|
|
f109b2 |
+
|
|
|
f109b2 |
+#define FAILLOCK_DEFAULT_CONF "/etc/security/faillock.conf"
|
|
|
f109b2 |
+#ifdef VENDOR_SCONFIGDIR
|
|
|
f109b2 |
+#define VENDOR_FAILLOCK_DEFAULT_CONF VENDOR_SCONFIGDIR "/faillock.conf"
|
|
|
f109b2 |
+#endif
|
|
|
f109b2 |
+
|
|
|
f109b2 |
+static void PAM_FORMAT((printf, 3, 4)) PAM_NONNULL((3))
|
|
|
f109b2 |
+config_log(const pam_handle_t *pamh, int priority, const char *fmt, ...)
|
|
|
f109b2 |
+{
|
|
|
f109b2 |
+ va_list args;
|
|
|
f109b2 |
+
|
|
|
f109b2 |
+ va_start(args, fmt);
|
|
|
f109b2 |
+ if (pamh) {
|
|
|
f109b2 |
+ pam_vsyslog(pamh, priority, fmt, args);
|
|
|
f109b2 |
+ } else {
|
|
|
f109b2 |
+ char *buf = NULL;
|
|
|
f109b2 |
+
|
|
|
f109b2 |
+ if (vasprintf(&buf, fmt, args) < 0) {
|
|
|
f109b2 |
+ fprintf(stderr, "vasprintf: %m");
|
|
|
f109b2 |
+ va_end(args);
|
|
|
f109b2 |
+ return;
|
|
|
f109b2 |
+ }
|
|
|
f109b2 |
+ fprintf(stderr, "%s\n", buf);
|
|
|
f109b2 |
+ free(buf);
|
|
|
f109b2 |
+ }
|
|
|
f109b2 |
+ va_end(args);
|
|
|
f109b2 |
+}
|
|
|
f109b2 |
+
|
|
|
f109b2 |
+/* parse a single configuration file */
|
|
|
f109b2 |
+int
|
|
|
f109b2 |
+read_config_file(pam_handle_t *pamh, struct options *opts, const char *cfgfile)
|
|
|
f109b2 |
+{
|
|
|
f109b2 |
+ char linebuf[FAILLOCK_CONF_MAX_LINELEN+1];
|
|
|
f109b2 |
+ const char *fname = (cfgfile != NULL) ? cfgfile : FAILLOCK_DEFAULT_CONF;
|
|
|
f109b2 |
+ FILE *f = fopen(fname, "r");
|
|
|
f109b2 |
+
|
|
|
f109b2 |
+#ifdef VENDOR_FAILLOCK_DEFAULT_CONF
|
|
|
f109b2 |
+ if (f == NULL && errno == ENOENT && cfgfile == NULL) {
|
|
|
f109b2 |
+ /*
|
|
|
f109b2 |
+ * If the default configuration file in /etc does not exist,
|
|
|
f109b2 |
+ * try the vendor configuration file as fallback.
|
|
|
f109b2 |
+ */
|
|
|
f109b2 |
+ f = fopen(VENDOR_FAILLOCK_DEFAULT_CONF, "r");
|
|
|
f109b2 |
+ }
|
|
|
f109b2 |
+#endif /* VENDOR_FAILLOCK_DEFAULT_CONF */
|
|
|
f109b2 |
+
|
|
|
f109b2 |
+ if (f == NULL) {
|
|
|
f109b2 |
+ /* ignore non-existent default config file */
|
|
|
f109b2 |
+ if (errno == ENOENT && cfgfile == NULL)
|
|
|
f109b2 |
+ return PAM_SUCCESS;
|
|
|
f109b2 |
+ return PAM_SERVICE_ERR;
|
|
|
f109b2 |
+ }
|
|
|
f109b2 |
+
|
|
|
f109b2 |
+ while (fgets(linebuf, sizeof(linebuf), f) != NULL) {
|
|
|
f109b2 |
+ size_t len;
|
|
|
f109b2 |
+ char *ptr;
|
|
|
f109b2 |
+ char *name;
|
|
|
f109b2 |
+ int eq;
|
|
|
f109b2 |
+
|
|
|
f109b2 |
+ len = strlen(linebuf);
|
|
|
f109b2 |
+ /* len cannot be 0 unless there is a bug in fgets */
|
|
|
f109b2 |
+ if (len && linebuf[len - 1] != '\n' && !feof(f)) {
|
|
|
f109b2 |
+ (void) fclose(f);
|
|
|
f109b2 |
+ return PAM_SERVICE_ERR;
|
|
|
f109b2 |
+ }
|
|
|
f109b2 |
+
|
|
|
f109b2 |
+ if ((ptr=strchr(linebuf, '#')) != NULL) {
|
|
|
f109b2 |
+ *ptr = '\0';
|
|
|
f109b2 |
+ } else {
|
|
|
f109b2 |
+ ptr = linebuf + len;
|
|
|
f109b2 |
+ }
|
|
|
f109b2 |
+
|
|
|
f109b2 |
+ /* drop terminating whitespace including the \n */
|
|
|
f109b2 |
+ while (ptr > linebuf) {
|
|
|
f109b2 |
+ if (!isspace(*(ptr-1))) {
|
|
|
f109b2 |
+ *ptr = '\0';
|
|
|
f109b2 |
+ break;
|
|
|
f109b2 |
+ }
|
|
|
f109b2 |
+ --ptr;
|
|
|
f109b2 |
+ }
|
|
|
f109b2 |
+
|
|
|
f109b2 |
+ /* skip initial whitespace */
|
|
|
f109b2 |
+ for (ptr = linebuf; isspace(*ptr); ptr++);
|
|
|
f109b2 |
+ if (*ptr == '\0')
|
|
|
f109b2 |
+ continue;
|
|
|
f109b2 |
+
|
|
|
f109b2 |
+ /* grab the key name */
|
|
|
f109b2 |
+ eq = 0;
|
|
|
f109b2 |
+ name = ptr;
|
|
|
f109b2 |
+ while (*ptr != '\0') {
|
|
|
f109b2 |
+ if (isspace(*ptr) || *ptr == '=') {
|
|
|
f109b2 |
+ eq = *ptr == '=';
|
|
|
f109b2 |
+ *ptr = '\0';
|
|
|
f109b2 |
+ ++ptr;
|
|
|
f109b2 |
+ break;
|
|
|
f109b2 |
+ }
|
|
|
f109b2 |
+ ++ptr;
|
|
|
f109b2 |
+ }
|
|
|
f109b2 |
+
|
|
|
f109b2 |
+ /* grab the key value */
|
|
|
f109b2 |
+ while (*ptr != '\0') {
|
|
|
f109b2 |
+ if (*ptr != '=' || eq) {
|
|
|
f109b2 |
+ if (!isspace(*ptr)) {
|
|
|
f109b2 |
+ break;
|
|
|
f109b2 |
+ }
|
|
|
f109b2 |
+ } else {
|
|
|
f109b2 |
+ eq = 1;
|
|
|
f109b2 |
+ }
|
|
|
f109b2 |
+ ++ptr;
|
|
|
f109b2 |
+ }
|
|
|
f109b2 |
+
|
|
|
f109b2 |
+ /* set the key:value pair on opts */
|
|
|
f109b2 |
+ set_conf_opt(pamh, opts, name, ptr);
|
|
|
f109b2 |
+ }
|
|
|
f109b2 |
+
|
|
|
f109b2 |
+ (void)fclose(f);
|
|
|
f109b2 |
+ return PAM_SUCCESS;
|
|
|
f109b2 |
+}
|
|
|
f109b2 |
+
|
|
|
f109b2 |
+void
|
|
|
f109b2 |
+set_conf_opt(pam_handle_t *pamh, struct options *opts, const char *name,
|
|
|
f109b2 |
+ const char *value)
|
|
|
f109b2 |
+{
|
|
|
f109b2 |
+ if (strcmp(name, "dir") == 0) {
|
|
|
f109b2 |
+ if (value[0] != '/') {
|
|
|
f109b2 |
+ config_log(pamh, LOG_ERR,
|
|
|
f109b2 |
+ "Tally directory is not absolute path (%s); keeping value",
|
|
|
f109b2 |
+ value);
|
|
|
f109b2 |
+ } else {
|
|
|
f109b2 |
+ free(opts->dir);
|
|
|
f109b2 |
+ opts->dir = strdup(value);
|
|
|
f109b2 |
+ if (opts->dir == NULL) {
|
|
|
f109b2 |
+ opts->fatal_error = 1;
|
|
|
f109b2 |
+ config_log(pamh, LOG_CRIT, "Error allocating memory: %m");
|
|
|
f109b2 |
+ }
|
|
|
f109b2 |
+ }
|
|
|
f109b2 |
+ }
|
|
|
f109b2 |
+ else if (strcmp(name, "deny") == 0) {
|
|
|
f109b2 |
+ if (sscanf(value, "%hu", &opts->deny) != 1) {
|
|
|
f109b2 |
+ config_log(pamh, LOG_ERR,
|
|
|
f109b2 |
+ "Bad number supplied for deny argument");
|
|
|
f109b2 |
+ }
|
|
|
f109b2 |
+ }
|
|
|
f109b2 |
+ else if (strcmp(name, "fail_interval") == 0) {
|
|
|
f109b2 |
+ unsigned int temp;
|
|
|
f109b2 |
+ if (sscanf(value, "%u", &temp) != 1 ||
|
|
|
f109b2 |
+ temp > MAX_TIME_INTERVAL) {
|
|
|
f109b2 |
+ config_log(pamh, LOG_ERR,
|
|
|
f109b2 |
+ "Bad number supplied for fail_interval argument");
|
|
|
f109b2 |
+ } else {
|
|
|
f109b2 |
+ opts->fail_interval = temp;
|
|
|
f109b2 |
+ }
|
|
|
f109b2 |
+ }
|
|
|
f109b2 |
+ else if (strcmp(name, "unlock_time") == 0) {
|
|
|
f109b2 |
+ unsigned int temp;
|
|
|
f109b2 |
+
|
|
|
f109b2 |
+ if (strcmp(value, "never") == 0) {
|
|
|
f109b2 |
+ opts->unlock_time = 0;
|
|
|
f109b2 |
+ }
|
|
|
f109b2 |
+ else if (sscanf(value, "%u", &temp) != 1 ||
|
|
|
f109b2 |
+ temp > MAX_TIME_INTERVAL) {
|
|
|
f109b2 |
+ config_log(pamh, LOG_ERR,
|
|
|
f109b2 |
+ "Bad number supplied for unlock_time argument");
|
|
|
f109b2 |
+ }
|
|
|
f109b2 |
+ else {
|
|
|
f109b2 |
+ opts->unlock_time = temp;
|
|
|
f109b2 |
+ }
|
|
|
f109b2 |
+ }
|
|
|
f109b2 |
+ else if (strcmp(name, "root_unlock_time") == 0) {
|
|
|
f109b2 |
+ unsigned int temp;
|
|
|
f109b2 |
+
|
|
|
f109b2 |
+ if (strcmp(value, "never") == 0) {
|
|
|
f109b2 |
+ opts->root_unlock_time = 0;
|
|
|
f109b2 |
+ }
|
|
|
f109b2 |
+ else if (sscanf(value, "%u", &temp) != 1 ||
|
|
|
f109b2 |
+ temp > MAX_TIME_INTERVAL) {
|
|
|
f109b2 |
+ config_log(pamh, LOG_ERR,
|
|
|
f109b2 |
+ "Bad number supplied for root_unlock_time argument");
|
|
|
f109b2 |
+ } else {
|
|
|
f109b2 |
+ opts->root_unlock_time = temp;
|
|
|
f109b2 |
+ }
|
|
|
f109b2 |
+ }
|
|
|
f109b2 |
+ else if (strcmp(name, "admin_group") == 0) {
|
|
|
f109b2 |
+ free(opts->admin_group);
|
|
|
f109b2 |
+ opts->admin_group = strdup(value);
|
|
|
f109b2 |
+ if (opts->admin_group == NULL) {
|
|
|
f109b2 |
+ opts->fatal_error = 1;
|
|
|
f109b2 |
+ config_log(pamh, LOG_CRIT, "Error allocating memory: %m");
|
|
|
f109b2 |
+ }
|
|
|
f109b2 |
+ }
|
|
|
f109b2 |
+ else if (strcmp(name, "even_deny_root") == 0) {
|
|
|
f109b2 |
+ opts->flags |= FAILLOCK_FLAG_DENY_ROOT;
|
|
|
f109b2 |
+ }
|
|
|
f109b2 |
+ else if (strcmp(name, "audit") == 0) {
|
|
|
f109b2 |
+ opts->flags |= FAILLOCK_FLAG_AUDIT;
|
|
|
f109b2 |
+ }
|
|
|
f109b2 |
+ else if (strcmp(name, "silent") == 0) {
|
|
|
f109b2 |
+ opts->flags |= FAILLOCK_FLAG_SILENT;
|
|
|
f109b2 |
+ }
|
|
|
f109b2 |
+ else if (strcmp(name, "no_log_info") == 0) {
|
|
|
f109b2 |
+ opts->flags |= FAILLOCK_FLAG_NO_LOG_INFO;
|
|
|
f109b2 |
+ }
|
|
|
f109b2 |
+ else if (strcmp(name, "local_users_only") == 0) {
|
|
|
f109b2 |
+ opts->flags |= FAILLOCK_FLAG_LOCAL_ONLY;
|
|
|
f109b2 |
+ }
|
|
|
f109b2 |
+ else if (strcmp(name, "nodelay") == 0) {
|
|
|
f109b2 |
+ opts->flags |= FAILLOCK_FLAG_NO_DELAY;
|
|
|
f109b2 |
+ }
|
|
|
f109b2 |
+ else {
|
|
|
f109b2 |
+ config_log(pamh, LOG_ERR, "Unknown option: %s", name);
|
|
|
f109b2 |
+ }
|
|
|
f109b2 |
+}
|
|
|
f109b2 |
+
|
|
|
f109b2 |
+const char *get_tally_dir(const struct options *opts)
|
|
|
f109b2 |
+{
|
|
|
f109b2 |
+ return (opts->dir != NULL) ? opts->dir : FAILLOCK_DEFAULT_TALLYDIR;
|
|
|
f109b2 |
+}
|
|
|
f109b2 |
diff -up Linux-PAM-1.3.1/modules/pam_faillock/faillock_config.h.faillock-load-conf-from-file Linux-PAM-1.3.1/modules/pam_faillock/faillock_config.h
|
|
|
f109b2 |
--- Linux-PAM-1.3.1/modules/pam_faillock/faillock_config.h.faillock-load-conf-from-file 2022-05-26 10:57:11.747067749 +0200
|
|
|
f109b2 |
+++ Linux-PAM-1.3.1/modules/pam_faillock/faillock_config.h 2022-05-26 10:57:11.747067749 +0200
|
|
|
f109b2 |
@@ -0,0 +1,89 @@
|
|
|
f109b2 |
+/*
|
|
|
f109b2 |
+ * Copyright (c) 2022 Tomas Mraz <tm@t8m.info>
|
|
|
f109b2 |
+ * Copyright (c) 2022 Iker Pedrosa <ipedrosa@redhat.com>
|
|
|
f109b2 |
+ *
|
|
|
f109b2 |
+ * Redistribution and use in source and binary forms, with or without
|
|
|
f109b2 |
+ * modification, are permitted provided that the following conditions
|
|
|
f109b2 |
+ * are met:
|
|
|
f109b2 |
+ * 1. Redistributions of source code must retain the above copyright
|
|
|
f109b2 |
+ * notice, and the entire permission notice in its entirety,
|
|
|
f109b2 |
+ * including the disclaimer of warranties.
|
|
|
f109b2 |
+ * 2. Redistributions in binary form must reproduce the above copyright
|
|
|
f109b2 |
+ * notice, this list of conditions and the following disclaimer in the
|
|
|
f109b2 |
+ * documentation and/or other materials provided with the distribution.
|
|
|
f109b2 |
+ * 3. The name of the author may not be used to endorse or promote
|
|
|
f109b2 |
+ * products derived from this software without specific prior
|
|
|
f109b2 |
+ * written permission.
|
|
|
f109b2 |
+ *
|
|
|
f109b2 |
+ * ALTERNATIVELY, this product may be distributed under the terms of
|
|
|
f109b2 |
+ * the GNU Public License, in which case the provisions of the GPL are
|
|
|
f109b2 |
+ * required INSTEAD OF the above restrictions. (This clause is
|
|
|
f109b2 |
+ * necessary due to a potential bad interaction between the GPL and
|
|
|
f109b2 |
+ * the restrictions contained in a BSD-style copyright.)
|
|
|
f109b2 |
+ *
|
|
|
f109b2 |
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
|
|
f109b2 |
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
f109b2 |
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
f109b2 |
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
|
|
f109b2 |
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
f109b2 |
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
f109b2 |
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
f109b2 |
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
|
f109b2 |
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
f109b2 |
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
|
|
f109b2 |
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
f109b2 |
+ */
|
|
|
f109b2 |
+
|
|
|
f109b2 |
+/*
|
|
|
f109b2 |
+ * faillock_config.h - load configuration options from file
|
|
|
f109b2 |
+ *
|
|
|
f109b2 |
+ */
|
|
|
f109b2 |
+
|
|
|
f109b2 |
+#ifndef _FAILLOCK_CONFIG_H
|
|
|
f109b2 |
+#define _FAILLOCK_CONFIG_H
|
|
|
f109b2 |
+
|
|
|
f109b2 |
+#include <limits.h>
|
|
|
f109b2 |
+#include <stdint.h>
|
|
|
f109b2 |
+#include <sys/types.h>
|
|
|
f109b2 |
+
|
|
|
f109b2 |
+#include <security/pam_ext.h>
|
|
|
f109b2 |
+
|
|
|
f109b2 |
+#define FAILLOCK_FLAG_DENY_ROOT 0x1
|
|
|
f109b2 |
+#define FAILLOCK_FLAG_AUDIT 0x2
|
|
|
f109b2 |
+#define FAILLOCK_FLAG_SILENT 0x4
|
|
|
f109b2 |
+#define FAILLOCK_FLAG_NO_LOG_INFO 0x8
|
|
|
f109b2 |
+#define FAILLOCK_FLAG_UNLOCKED 0x10
|
|
|
f109b2 |
+#define FAILLOCK_FLAG_LOCAL_ONLY 0x20
|
|
|
f109b2 |
+#define FAILLOCK_FLAG_NO_DELAY 0x40
|
|
|
f109b2 |
+
|
|
|
f109b2 |
+#define FAILLOCK_CONF_MAX_LINELEN 1023
|
|
|
f109b2 |
+#define MAX_TIME_INTERVAL 604800 /* 7 days */
|
|
|
f109b2 |
+
|
|
|
f109b2 |
+struct options {
|
|
|
f109b2 |
+ unsigned int action;
|
|
|
f109b2 |
+ unsigned int flags;
|
|
|
f109b2 |
+ unsigned short deny;
|
|
|
f109b2 |
+ unsigned int fail_interval;
|
|
|
f109b2 |
+ unsigned int unlock_time;
|
|
|
f109b2 |
+ unsigned int root_unlock_time;
|
|
|
f109b2 |
+ char *dir;
|
|
|
f109b2 |
+ const char *user;
|
|
|
f109b2 |
+ char *admin_group;
|
|
|
f109b2 |
+ int failures;
|
|
|
f109b2 |
+ uint64_t latest_time;
|
|
|
f109b2 |
+ uid_t uid;
|
|
|
f109b2 |
+ int is_admin;
|
|
|
f109b2 |
+ uint64_t now;
|
|
|
f109b2 |
+ int fatal_error;
|
|
|
f109b2 |
+
|
|
|
f109b2 |
+ unsigned int reset;
|
|
|
f109b2 |
+ const char *progname;
|
|
|
f109b2 |
+};
|
|
|
f109b2 |
+
|
|
|
f109b2 |
+int read_config_file(pam_handle_t *pamh, struct options *opts,
|
|
|
f109b2 |
+ const char *cfgfile);
|
|
|
f109b2 |
+void set_conf_opt(pam_handle_t *pamh, struct options *opts, const char *name,
|
|
|
f109b2 |
+ const char *value);
|
|
|
f109b2 |
+const char *get_tally_dir(const struct options *opts);
|
|
|
f109b2 |
+
|
|
|
f109b2 |
+#endif /* _FAILLOCK_CONFIG_H */
|
|
|
f109b2 |
diff -up Linux-PAM-1.3.1/modules/pam_faillock/main.c.faillock-load-conf-from-file Linux-PAM-1.3.1/modules/pam_faillock/main.c
|
|
|
f109b2 |
--- Linux-PAM-1.3.1/modules/pam_faillock/main.c.faillock-load-conf-from-file 2022-05-26 10:57:11.713067506 +0200
|
|
|
f109b2 |
+++ Linux-PAM-1.3.1/modules/pam_faillock/main.c 2022-05-26 10:57:11.747067749 +0200
|
|
|
f109b2 |
@@ -48,43 +48,50 @@
|
|
|
f109b2 |
#include <libaudit.h>
|
|
|
f109b2 |
#endif
|
|
|
f109b2 |
|
|
|
f109b2 |
+#include "pam_inline.h"
|
|
|
f109b2 |
#include "faillock.h"
|
|
|
f109b2 |
-
|
|
|
f109b2 |
-struct options {
|
|
|
f109b2 |
- unsigned int reset;
|
|
|
f109b2 |
- const char *dir;
|
|
|
f109b2 |
- const char *user;
|
|
|
f109b2 |
- const char *progname;
|
|
|
f109b2 |
-};
|
|
|
f109b2 |
+#include "faillock_config.h"
|
|
|
f109b2 |
|
|
|
f109b2 |
static int
|
|
|
f109b2 |
args_parse(int argc, char **argv, struct options *opts)
|
|
|
f109b2 |
{
|
|
|
f109b2 |
int i;
|
|
|
f109b2 |
+ int rv;
|
|
|
f109b2 |
+ const char *dir = NULL;
|
|
|
f109b2 |
+ const char *conf = NULL;
|
|
|
f109b2 |
+
|
|
|
f109b2 |
memset(opts, 0, sizeof(*opts));
|
|
|
f109b2 |
|
|
|
f109b2 |
- opts->dir = FAILLOCK_DEFAULT_TALLYDIR;
|
|
|
f109b2 |
opts->progname = argv[0];
|
|
|
f109b2 |
|
|
|
f109b2 |
for (i = 1; i < argc; ++i) {
|
|
|
f109b2 |
-
|
|
|
f109b2 |
- if (strcmp(argv[i], "--dir") == 0) {
|
|
|
f109b2 |
+ if (strcmp(argv[i], "--conf") == 0) {
|
|
|
f109b2 |
+ ++i;
|
|
|
f109b2 |
+ if (i >= argc || strlen(argv[i]) == 0) {
|
|
|
f109b2 |
+ fprintf(stderr, "%s: No configuration file supplied.\n",
|
|
|
f109b2 |
+ argv[0]);
|
|
|
f109b2 |
+ return -1;
|
|
|
f109b2 |
+ }
|
|
|
f109b2 |
+ conf = argv[i];
|
|
|
f109b2 |
+ }
|
|
|
f109b2 |
+ else if (strcmp(argv[i], "--dir") == 0) {
|
|
|
f109b2 |
++i;
|
|
|
f109b2 |
if (i >= argc || strlen(argv[i]) == 0) {
|
|
|
f109b2 |
- fprintf(stderr, "%s: No directory supplied.\n", argv[0]);
|
|
|
f109b2 |
+ fprintf(stderr, "%s: No records directory supplied.\n",
|
|
|
f109b2 |
+ argv[0]);
|
|
|
f109b2 |
return -1;
|
|
|
f109b2 |
}
|
|
|
f109b2 |
- opts->dir = argv[i];
|
|
|
f109b2 |
- }
|
|
|
f109b2 |
+ dir = argv[i];
|
|
|
f109b2 |
+ }
|
|
|
f109b2 |
else if (strcmp(argv[i], "--user") == 0) {
|
|
|
f109b2 |
++i;
|
|
|
f109b2 |
if (i >= argc || strlen(argv[i]) == 0) {
|
|
|
f109b2 |
- fprintf(stderr, "%s: No user name supplied.\n", argv[0]);
|
|
|
f109b2 |
+ fprintf(stderr, "%s: No user name supplied.\n", argv[0]);
|
|
|
f109b2 |
return -1;
|
|
|
f109b2 |
}
|
|
|
f109b2 |
- opts->user = argv[i];
|
|
|
f109b2 |
+ opts->user = argv[i];
|
|
|
f109b2 |
}
|
|
|
f109b2 |
- else if (strcmp(argv[i], "--reset") == 0) {
|
|
|
f109b2 |
+ else if (strcmp(argv[i], "--reset") == 0) {
|
|
|
f109b2 |
opts->reset = 1;
|
|
|
f109b2 |
}
|
|
|
f109b2 |
else {
|
|
|
f109b2 |
@@ -92,6 +99,21 @@ args_parse(int argc, char **argv, struct
|
|
|
f109b2 |
return -1;
|
|
|
f109b2 |
}
|
|
|
f109b2 |
}
|
|
|
f109b2 |
+
|
|
|
f109b2 |
+ if ((rv = read_config_file(NULL, opts, conf)) != PAM_SUCCESS) {
|
|
|
f109b2 |
+ fprintf(stderr, "Configuration file missing or broken");
|
|
|
f109b2 |
+ return rv;
|
|
|
f109b2 |
+ }
|
|
|
f109b2 |
+
|
|
|
f109b2 |
+ if (dir != NULL) {
|
|
|
f109b2 |
+ free(opts->dir);
|
|
|
f109b2 |
+ opts->dir = strdup(dir);
|
|
|
f109b2 |
+ if (opts->dir == NULL) {
|
|
|
f109b2 |
+ fprintf(stderr, "Error allocating memory: %m");
|
|
|
f109b2 |
+ return -1;
|
|
|
f109b2 |
+ }
|
|
|
f109b2 |
+ }
|
|
|
f109b2 |
+
|
|
|
f109b2 |
return 0;
|
|
|
f109b2 |
}
|
|
|
f109b2 |
|
|
|
f109b2 |
@@ -109,10 +131,11 @@ do_user(struct options *opts, const char
|
|
|
f109b2 |
int rv;
|
|
|
f109b2 |
struct tally_data tallies;
|
|
|
f109b2 |
struct passwd *pwd;
|
|
|
f109b2 |
+ const char *dir = get_tally_dir(opts);
|
|
|
f109b2 |
|
|
|
f109b2 |
pwd = getpwnam(user);
|
|
|
f109b2 |
|
|
|
f109b2 |
- fd = open_tally(opts->dir, user, pwd != NULL ? pwd->pw_uid : 0, 0);
|
|
|
f109b2 |
+ fd = open_tally(dir, user, pwd != NULL ? pwd->pw_uid : 0, 0);
|
|
|
f109b2 |
|
|
|
f109b2 |
if (fd == -1) {
|
|
|
f109b2 |
if (errno == ENOENT) {
|
|
|
f109b2 |
@@ -189,11 +212,11 @@ do_allusers(struct options *opts)
|
|
|
f109b2 |
{
|
|
|
f109b2 |
struct dirent **userlist;
|
|
|
f109b2 |
int rv, i;
|
|
|
f109b2 |
+ const char *dir = get_tally_dir(opts);
|
|
|
f109b2 |
|
|
|
f109b2 |
- rv = scandir(opts->dir, &userlist, NULL, alphasort);
|
|
|
f109b2 |
+ rv = scandir(dir, &userlist, NULL, alphasort);
|
|
|
f109b2 |
if (rv < 0) {
|
|
|
f109b2 |
- fprintf(stderr, "%s: Error reading tally directory: ", opts->progname);
|
|
|
f109b2 |
- perror(NULL);
|
|
|
f109b2 |
+ fprintf(stderr, "%s: Error reading tally directory: %m\n", opts->progname);
|
|
|
f109b2 |
return 2;
|
|
|
f109b2 |
}
|
|
|
f109b2 |
|
|
|
f109b2 |
diff -up Linux-PAM-1.3.1/modules/pam_faillock/Makefile.am.faillock-load-conf-from-file Linux-PAM-1.3.1/modules/pam_faillock/Makefile.am
|
|
|
f109b2 |
--- Linux-PAM-1.3.1/modules/pam_faillock/Makefile.am.faillock-load-conf-from-file 2022-05-26 10:57:11.727067606 +0200
|
|
|
f109b2 |
+++ Linux-PAM-1.3.1/modules/pam_faillock/Makefile.am 2022-05-26 10:57:59.032406450 +0200
|
|
|
f109b2 |
@@ -17,7 +17,7 @@ TESTS = tst-pam_faillock
|
|
|
f109b2 |
securelibdir = $(SECUREDIR)
|
|
|
f109b2 |
secureconfdir = $(SCONFIGDIR)
|
|
|
f109b2 |
|
|
|
f109b2 |
-noinst_HEADERS = faillock.h
|
|
|
f109b2 |
+noinst_HEADERS = faillock.h faillock_config.h
|
|
|
f109b2 |
|
|
|
f109b2 |
faillock_CFLAGS = -I$(top_srcdir)/libpam/include -I$(top_srcdir)/libpamc/include @PIE_CFLAGS@
|
|
|
f109b2 |
pam_faillock_la_CFLAGS = -I$(top_srcdir)/libpam/include -I$(top_srcdir)/libpamc/include
|
|
|
f109b2 |
@@ -36,8 +36,8 @@ secureconf_DATA = faillock.conf
|
|
|
f109b2 |
securelib_LTLIBRARIES = pam_faillock.la
|
|
|
f109b2 |
sbin_PROGRAMS = faillock
|
|
|
f109b2 |
|
|
|
f109b2 |
-pam_faillock_la_SOURCES = pam_faillock.c faillock.c
|
|
|
f109b2 |
-faillock_SOURCES = main.c faillock.c
|
|
|
f109b2 |
+pam_faillock_la_SOURCES = pam_faillock.c faillock.c faillock_config.c
|
|
|
f109b2 |
+faillock_SOURCES = main.c faillock.c faillock_config.c
|
|
|
f109b2 |
|
|
|
f109b2 |
if ENABLE_REGENERATE_MAN
|
|
|
f109b2 |
noinst_DATA = README
|
|
|
f109b2 |
diff -up Linux-PAM-1.3.1/modules/pam_faillock/pam_faillock.c.faillock-load-conf-from-file Linux-PAM-1.3.1/modules/pam_faillock/pam_faillock.c
|
|
|
f109b2 |
--- Linux-PAM-1.3.1/modules/pam_faillock/pam_faillock.c.faillock-load-conf-from-file 2022-05-26 10:57:11.727067606 +0200
|
|
|
f109b2 |
+++ Linux-PAM-1.3.1/modules/pam_faillock/pam_faillock.c 2022-05-26 10:57:11.748067756 +0200
|
|
|
f109b2 |
@@ -38,7 +38,6 @@
|
|
|
f109b2 |
#include <stdio.h>
|
|
|
f109b2 |
#include <string.h>
|
|
|
f109b2 |
#include <unistd.h>
|
|
|
f109b2 |
-#include <stdint.h>
|
|
|
f109b2 |
#include <stdlib.h>
|
|
|
f109b2 |
#include <errno.h>
|
|
|
f109b2 |
#include <time.h>
|
|
|
f109b2 |
@@ -54,83 +53,50 @@
|
|
|
f109b2 |
#include <security/pam_modutil.h>
|
|
|
f109b2 |
#include <security/pam_ext.h>
|
|
|
f109b2 |
|
|
|
f109b2 |
+#include "pam_inline.h"
|
|
|
f109b2 |
#include "faillock.h"
|
|
|
f109b2 |
-
|
|
|
f109b2 |
-#define PAM_SM_AUTH
|
|
|
f109b2 |
-#define PAM_SM_ACCOUNT
|
|
|
f109b2 |
+#include "faillock_config.h"
|
|
|
f109b2 |
|
|
|
f109b2 |
#define FAILLOCK_ACTION_PREAUTH 0
|
|
|
f109b2 |
#define FAILLOCK_ACTION_AUTHSUCC 1
|
|
|
f109b2 |
#define FAILLOCK_ACTION_AUTHFAIL 2
|
|
|
f109b2 |
|
|
|
f109b2 |
-#define FAILLOCK_FLAG_DENY_ROOT 0x1
|
|
|
f109b2 |
-#define FAILLOCK_FLAG_AUDIT 0x2
|
|
|
f109b2 |
-#define FAILLOCK_FLAG_SILENT 0x4
|
|
|
f109b2 |
-#define FAILLOCK_FLAG_NO_LOG_INFO 0x8
|
|
|
f109b2 |
-#define FAILLOCK_FLAG_UNLOCKED 0x10
|
|
|
f109b2 |
-#define FAILLOCK_FLAG_LOCAL_ONLY 0x20
|
|
|
f109b2 |
-
|
|
|
f109b2 |
-#define MAX_TIME_INTERVAL 604800 /* 7 days */
|
|
|
f109b2 |
-#define FAILLOCK_CONF_MAX_LINELEN 1023
|
|
|
f109b2 |
-#define FAILLOCK_ERROR_CONF_OPEN -3
|
|
|
f109b2 |
-#define FAILLOCK_ERROR_CONF_MALFORMED -4
|
|
|
f109b2 |
-
|
|
|
f109b2 |
-#define PATH_PASSWD "/etc/passwd"
|
|
|
f109b2 |
-
|
|
|
f109b2 |
-struct options {
|
|
|
f109b2 |
- unsigned int action;
|
|
|
f109b2 |
- unsigned int flags;
|
|
|
f109b2 |
- unsigned short deny;
|
|
|
f109b2 |
- unsigned int fail_interval;
|
|
|
f109b2 |
- unsigned int unlock_time;
|
|
|
f109b2 |
- unsigned int root_unlock_time;
|
|
|
f109b2 |
- char *dir;
|
|
|
f109b2 |
- const char *conf;
|
|
|
f109b2 |
- const char *user;
|
|
|
f109b2 |
- char *admin_group;
|
|
|
f109b2 |
- int failures;
|
|
|
f109b2 |
- uint64_t latest_time;
|
|
|
f109b2 |
- uid_t uid;
|
|
|
f109b2 |
- int is_admin;
|
|
|
f109b2 |
- uint64_t now;
|
|
|
f109b2 |
- int fatal_error;
|
|
|
f109b2 |
-};
|
|
|
f109b2 |
-
|
|
|
f109b2 |
-int read_config_file(
|
|
|
f109b2 |
- pam_handle_t *pamh,
|
|
|
f109b2 |
- struct options *opts,
|
|
|
f109b2 |
- const char *cfgfile
|
|
|
f109b2 |
-);
|
|
|
f109b2 |
-
|
|
|
f109b2 |
-void set_conf_opt(
|
|
|
f109b2 |
- pam_handle_t *pamh,
|
|
|
f109b2 |
- struct options *opts,
|
|
|
f109b2 |
- const char *name,
|
|
|
f109b2 |
- const char *value
|
|
|
f109b2 |
-);
|
|
|
f109b2 |
-
|
|
|
f109b2 |
-static void
|
|
|
f109b2 |
+static int
|
|
|
f109b2 |
args_parse(pam_handle_t *pamh, int argc, const char **argv,
|
|
|
f109b2 |
int flags, struct options *opts)
|
|
|
f109b2 |
{
|
|
|
f109b2 |
int i;
|
|
|
f109b2 |
+ int config_arg_index = -1;
|
|
|
f109b2 |
int rv;
|
|
|
f109b2 |
+ const char *conf = NULL;
|
|
|
f109b2 |
+
|
|
|
f109b2 |
memset(opts, 0, sizeof(*opts));
|
|
|
f109b2 |
|
|
|
f109b2 |
- opts->dir = strdup(FAILLOCK_DEFAULT_TALLYDIR);
|
|
|
f109b2 |
- opts->conf = FAILLOCK_DEFAULT_CONF;
|
|
|
f109b2 |
opts->deny = 3;
|
|
|
f109b2 |
opts->fail_interval = 900;
|
|
|
f109b2 |
opts->unlock_time = 600;
|
|
|
f109b2 |
opts->root_unlock_time = MAX_TIME_INTERVAL+1;
|
|
|
f109b2 |
|
|
|
f109b2 |
- if ((rv=read_config_file(pamh, opts, opts->conf)) != PAM_SUCCESS) {
|
|
|
f109b2 |
- pam_syslog(pamh, LOG_DEBUG,
|
|
|
f109b2 |
- "Configuration file missing");
|
|
|
f109b2 |
+ for (i = 0; i < argc; ++i) {
|
|
|
f109b2 |
+ const char *str = pam_str_skip_prefix(argv[i], "conf=");
|
|
|
f109b2 |
+
|
|
|
f109b2 |
+ if (str != NULL) {
|
|
|
f109b2 |
+ conf = str;
|
|
|
f109b2 |
+ config_arg_index = i;
|
|
|
f109b2 |
+ }
|
|
|
f109b2 |
+ }
|
|
|
f109b2 |
+
|
|
|
f109b2 |
+ if ((rv = read_config_file(pamh, opts, conf)) != PAM_SUCCESS) {
|
|
|
f109b2 |
+ pam_syslog(pamh, LOG_ERR,
|
|
|
f109b2 |
+ "Configuration file missing or broken");
|
|
|
f109b2 |
+ return rv;
|
|
|
f109b2 |
}
|
|
|
f109b2 |
|
|
|
f109b2 |
for (i = 0; i < argc; ++i) {
|
|
|
f109b2 |
- if (strcmp(argv[i], "preauth") == 0) {
|
|
|
f109b2 |
+ if (i == config_arg_index) {
|
|
|
f109b2 |
+ continue;
|
|
|
f109b2 |
+ }
|
|
|
f109b2 |
+ else if (strcmp(argv[i], "preauth") == 0) {
|
|
|
f109b2 |
opts->action = FAILLOCK_ACTION_PREAUTH;
|
|
|
f109b2 |
}
|
|
|
f109b2 |
else if (strcmp(argv[i], "authfail") == 0) {
|
|
|
f109b2 |
@@ -163,226 +129,26 @@ args_parse(pam_handle_t *pamh, int argc,
|
|
|
f109b2 |
if (flags & PAM_SILENT)
|
|
|
f109b2 |
opts->flags |= FAILLOCK_FLAG_SILENT;
|
|
|
f109b2 |
|
|
|
f109b2 |
- if (opts->dir == NULL) {
|
|
|
f109b2 |
- pam_syslog(pamh, LOG_CRIT, "Error allocating memory: %m");
|
|
|
f109b2 |
- opts->fatal_error = 1;
|
|
|
f109b2 |
- }
|
|
|
f109b2 |
-}
|
|
|
f109b2 |
-
|
|
|
f109b2 |
-/* parse a single configuration file */
|
|
|
f109b2 |
-int
|
|
|
f109b2 |
-read_config_file(pam_handle_t *pamh, struct options *opts, const char *cfgfile)
|
|
|
f109b2 |
-{
|
|
|
f109b2 |
- FILE *f;
|
|
|
f109b2 |
- char linebuf[FAILLOCK_CONF_MAX_LINELEN+1];
|
|
|
f109b2 |
-
|
|
|
f109b2 |
- f = fopen(cfgfile, "r");
|
|
|
f109b2 |
- if (f == NULL) {
|
|
|
f109b2 |
- /* ignore non-existent default config file */
|
|
|
f109b2 |
- if (errno == ENOENT && strcmp(cfgfile, FAILLOCK_DEFAULT_CONF) == 0)
|
|
|
f109b2 |
- return 0;
|
|
|
f109b2 |
- return FAILLOCK_ERROR_CONF_OPEN;
|
|
|
f109b2 |
- }
|
|
|
f109b2 |
-
|
|
|
f109b2 |
- while (fgets(linebuf, sizeof(linebuf), f) != NULL) {
|
|
|
f109b2 |
- size_t len;
|
|
|
f109b2 |
- char *ptr;
|
|
|
f109b2 |
- char *name;
|
|
|
f109b2 |
- int eq;
|
|
|
f109b2 |
-
|
|
|
f109b2 |
- len = strlen(linebuf);
|
|
|
f109b2 |
- /* len cannot be 0 unless there is a bug in fgets */
|
|
|
f109b2 |
- if (len && linebuf[len - 1] != '\n' && !feof(f)) {
|
|
|
f109b2 |
- (void) fclose(f);
|
|
|
f109b2 |
- return FAILLOCK_ERROR_CONF_MALFORMED;
|
|
|
f109b2 |
- }
|
|
|
f109b2 |
-
|
|
|
f109b2 |
- if ((ptr=strchr(linebuf, '#')) != NULL) {
|
|
|
f109b2 |
- *ptr = '\0';
|
|
|
f109b2 |
- } else {
|
|
|
f109b2 |
- ptr = linebuf + len;
|
|
|
f109b2 |
- }
|
|
|
f109b2 |
-
|
|
|
f109b2 |
- /* drop terminating whitespace including the \n */
|
|
|
f109b2 |
- while (ptr > linebuf) {
|
|
|
f109b2 |
- if (!isspace(*(ptr-1))) {
|
|
|
f109b2 |
- *ptr = '\0';
|
|
|
f109b2 |
- break;
|
|
|
f109b2 |
- }
|
|
|
f109b2 |
- --ptr;
|
|
|
f109b2 |
- }
|
|
|
f109b2 |
-
|
|
|
f109b2 |
- /* skip initial whitespace */
|
|
|
f109b2 |
- for (ptr = linebuf; isspace(*ptr); ptr++);
|
|
|
f109b2 |
- if (*ptr == '\0')
|
|
|
f109b2 |
- continue;
|
|
|
f109b2 |
-
|
|
|
f109b2 |
- /* grab the key name */
|
|
|
f109b2 |
- eq = 0;
|
|
|
f109b2 |
- name = ptr;
|
|
|
f109b2 |
- while (*ptr != '\0') {
|
|
|
f109b2 |
- if (isspace(*ptr) || *ptr == '=') {
|
|
|
f109b2 |
- eq = *ptr == '=';
|
|
|
f109b2 |
- *ptr = '\0';
|
|
|
f109b2 |
- ++ptr;
|
|
|
f109b2 |
- break;
|
|
|
f109b2 |
- }
|
|
|
f109b2 |
- ++ptr;
|
|
|
f109b2 |
- }
|
|
|
f109b2 |
-
|
|
|
f109b2 |
- /* grab the key value */
|
|
|
f109b2 |
- while (*ptr != '\0') {
|
|
|
f109b2 |
- if (*ptr != '=' || eq) {
|
|
|
f109b2 |
- if (!isspace(*ptr)) {
|
|
|
f109b2 |
- break;
|
|
|
f109b2 |
- }
|
|
|
f109b2 |
- } else {
|
|
|
f109b2 |
- eq = 1;
|
|
|
f109b2 |
- }
|
|
|
f109b2 |
- ++ptr;
|
|
|
f109b2 |
- }
|
|
|
f109b2 |
-
|
|
|
f109b2 |
- /* set the key:value pair on opts */
|
|
|
f109b2 |
- set_conf_opt(pamh, opts, name, ptr);
|
|
|
f109b2 |
- }
|
|
|
f109b2 |
-
|
|
|
f109b2 |
- (void)fclose(f);
|
|
|
f109b2 |
+ if (opts->fatal_error)
|
|
|
f109b2 |
+ return PAM_BUF_ERR;
|
|
|
f109b2 |
return PAM_SUCCESS;
|
|
|
f109b2 |
}
|
|
|
f109b2 |
|
|
|
f109b2 |
-void set_conf_opt(pam_handle_t *pamh, struct options *opts, const char *name, const char *value)
|
|
|
f109b2 |
-{
|
|
|
f109b2 |
- if (strcmp(name, "dir") == 0) {
|
|
|
f109b2 |
- if (value[0] != '/') {
|
|
|
f109b2 |
- pam_syslog(pamh, LOG_ERR,
|
|
|
f109b2 |
- "Tally directory is not absolute path (%s); keeping default", value);
|
|
|
f109b2 |
- } else {
|
|
|
f109b2 |
- free(opts->dir);
|
|
|
f109b2 |
- opts->dir = strdup(value);
|
|
|
f109b2 |
- }
|
|
|
f109b2 |
- }
|
|
|
f109b2 |
- else if (strcmp(name, "deny") == 0) {
|
|
|
f109b2 |
- if (sscanf(value, "%hu", &opts->deny) != 1) {
|
|
|
f109b2 |
- pam_syslog(pamh, LOG_ERR,
|
|
|
f109b2 |
- "Bad number supplied for deny argument");
|
|
|
f109b2 |
- }
|
|
|
f109b2 |
- }
|
|
|
f109b2 |
- else if (strcmp(name, "fail_interval") == 0) {
|
|
|
f109b2 |
- unsigned int temp;
|
|
|
f109b2 |
- if (sscanf(value, "%u", &temp) != 1 ||
|
|
|
f109b2 |
- temp > MAX_TIME_INTERVAL) {
|
|
|
f109b2 |
- pam_syslog(pamh, LOG_ERR,
|
|
|
f109b2 |
- "Bad number supplied for fail_interval argument");
|
|
|
f109b2 |
- } else {
|
|
|
f109b2 |
- opts->fail_interval = temp;
|
|
|
f109b2 |
- }
|
|
|
f109b2 |
- }
|
|
|
f109b2 |
- else if (strcmp(name, "unlock_time") == 0) {
|
|
|
f109b2 |
- unsigned int temp;
|
|
|
f109b2 |
-
|
|
|
f109b2 |
- if (strcmp(value, "never") == 0) {
|
|
|
f109b2 |
- opts->unlock_time = 0;
|
|
|
f109b2 |
- }
|
|
|
f109b2 |
- else if (sscanf(value, "%u", &temp) != 1 ||
|
|
|
f109b2 |
- temp > MAX_TIME_INTERVAL) {
|
|
|
f109b2 |
- pam_syslog(pamh, LOG_ERR,
|
|
|
f109b2 |
- "Bad number supplied for unlock_time argument");
|
|
|
f109b2 |
- }
|
|
|
f109b2 |
- else {
|
|
|
f109b2 |
- opts->unlock_time = temp;
|
|
|
f109b2 |
- }
|
|
|
f109b2 |
- }
|
|
|
f109b2 |
- else if (strcmp(name, "root_unlock_time") == 0) {
|
|
|
f109b2 |
- unsigned int temp;
|
|
|
f109b2 |
-
|
|
|
f109b2 |
- if (strcmp(value, "never") == 0) {
|
|
|
f109b2 |
- opts->root_unlock_time = 0;
|
|
|
f109b2 |
- }
|
|
|
f109b2 |
- else if (sscanf(value, "%u", &temp) != 1 ||
|
|
|
f109b2 |
- temp > MAX_TIME_INTERVAL) {
|
|
|
f109b2 |
- pam_syslog(pamh, LOG_ERR,
|
|
|
f109b2 |
- "Bad number supplied for root_unlock_time argument");
|
|
|
f109b2 |
- } else {
|
|
|
f109b2 |
- opts->root_unlock_time = temp;
|
|
|
f109b2 |
- }
|
|
|
f109b2 |
- }
|
|
|
f109b2 |
- else if (strcmp(name, "admin_group") == 0) {
|
|
|
f109b2 |
- free(opts->admin_group);
|
|
|
f109b2 |
- opts->admin_group = strdup(value);
|
|
|
f109b2 |
- if (opts->admin_group == NULL) {
|
|
|
f109b2 |
- opts->fatal_error = 1;
|
|
|
f109b2 |
- pam_syslog(pamh, LOG_CRIT, "Error allocating memory: %m");
|
|
|
f109b2 |
- }
|
|
|
f109b2 |
- }
|
|
|
f109b2 |
- else if (strcmp(name, "even_deny_root") == 0) {
|
|
|
f109b2 |
- opts->flags |= FAILLOCK_FLAG_DENY_ROOT;
|
|
|
f109b2 |
- }
|
|
|
f109b2 |
- else if (strcmp(name, "audit") == 0) {
|
|
|
f109b2 |
- opts->flags |= FAILLOCK_FLAG_AUDIT;
|
|
|
f109b2 |
- }
|
|
|
f109b2 |
- else if (strcmp(name, "silent") == 0) {
|
|
|
f109b2 |
- opts->flags |= FAILLOCK_FLAG_SILENT;
|
|
|
f109b2 |
- }
|
|
|
f109b2 |
- else if (strcmp(name, "no_log_info") == 0) {
|
|
|
f109b2 |
- opts->flags |= FAILLOCK_FLAG_NO_LOG_INFO;
|
|
|
f109b2 |
- }
|
|
|
f109b2 |
- else if (strcmp(name, "local_users_only") == 0) {
|
|
|
f109b2 |
- opts->flags |= FAILLOCK_FLAG_LOCAL_ONLY;
|
|
|
f109b2 |
- }
|
|
|
f109b2 |
- else {
|
|
|
f109b2 |
- pam_syslog(pamh, LOG_ERR, "Unknown option: %s", name);
|
|
|
f109b2 |
- }
|
|
|
f109b2 |
-}
|
|
|
f109b2 |
-
|
|
|
f109b2 |
-static int check_local_user (pam_handle_t *pamh, const char *user)
|
|
|
f109b2 |
+static int
|
|
|
f109b2 |
+check_local_user (pam_handle_t *pamh, const char *user)
|
|
|
f109b2 |
{
|
|
|
f109b2 |
- struct passwd pw, *pwp;
|
|
|
f109b2 |
- char buf[4096];
|
|
|
f109b2 |
- int found = 0;
|
|
|
f109b2 |
- FILE *fp;
|
|
|
f109b2 |
- int errn;
|
|
|
f109b2 |
-
|
|
|
f109b2 |
- fp = fopen(PATH_PASSWD, "r");
|
|
|
f109b2 |
- if (fp == NULL) {
|
|
|
f109b2 |
- pam_syslog(pamh, LOG_ERR, "unable to open %s: %m",
|
|
|
f109b2 |
- PATH_PASSWD);
|
|
|
f109b2 |
- return -1;
|
|
|
f109b2 |
- }
|
|
|
f109b2 |
-
|
|
|
f109b2 |
- for (;;) {
|
|
|
f109b2 |
- errn = fgetpwent_r(fp, &pw, buf, sizeof (buf), &pwp);
|
|
|
f109b2 |
- if (errn == ERANGE) {
|
|
|
f109b2 |
- pam_syslog(pamh, LOG_WARNING, "%s contains very long lines; corrupted?",
|
|
|
f109b2 |
- PATH_PASSWD);
|
|
|
f109b2 |
- /* we can continue here as next call will read further */
|
|
|
f109b2 |
- continue;
|
|
|
f109b2 |
- }
|
|
|
f109b2 |
- if (errn != 0)
|
|
|
f109b2 |
- break;
|
|
|
f109b2 |
- if (strcmp(pwp->pw_name, user) == 0) {
|
|
|
f109b2 |
- found = 1;
|
|
|
f109b2 |
- break;
|
|
|
f109b2 |
- }
|
|
|
f109b2 |
- }
|
|
|
f109b2 |
-
|
|
|
f109b2 |
- fclose (fp);
|
|
|
f109b2 |
-
|
|
|
f109b2 |
- if (errn != 0 && errn != ENOENT) {
|
|
|
f109b2 |
- pam_syslog(pamh, LOG_ERR, "unable to enumerate local accounts: %m");
|
|
|
f109b2 |
- return -1;
|
|
|
f109b2 |
- } else {
|
|
|
f109b2 |
- return found;
|
|
|
f109b2 |
- }
|
|
|
f109b2 |
+ return pam_modutil_check_user_in_passwd(pamh, user, NULL) == PAM_SUCCESS;
|
|
|
f109b2 |
}
|
|
|
f109b2 |
|
|
|
f109b2 |
-static int get_pam_user(pam_handle_t *pamh, struct options *opts)
|
|
|
f109b2 |
+static int
|
|
|
f109b2 |
+get_pam_user(pam_handle_t *pamh, struct options *opts)
|
|
|
f109b2 |
{
|
|
|
f109b2 |
const char *user;
|
|
|
f109b2 |
int rv;
|
|
|
f109b2 |
struct passwd *pwd;
|
|
|
f109b2 |
|
|
|
f109b2 |
if ((rv=pam_get_user(pamh, &user, NULL)) != PAM_SUCCESS) {
|
|
|
f109b2 |
- return rv;
|
|
|
f109b2 |
+ return rv == PAM_CONV_AGAIN ? PAM_INCOMPLETE : rv;
|
|
|
f109b2 |
}
|
|
|
f109b2 |
|
|
|
f109b2 |
if (*user == '\0') {
|
|
|
f109b2 |
@@ -391,10 +157,10 @@ static int get_pam_user(pam_handle_t *pa
|
|
|
f109b2 |
|
|
|
f109b2 |
if ((pwd=pam_modutil_getpwnam(pamh, user)) == NULL) {
|
|
|
f109b2 |
if (opts->flags & FAILLOCK_FLAG_AUDIT) {
|
|
|
f109b2 |
- pam_syslog(pamh, LOG_ERR, "User unknown: %s", user);
|
|
|
f109b2 |
+ pam_syslog(pamh, LOG_NOTICE, "User unknown: %s", user);
|
|
|
f109b2 |
}
|
|
|
f109b2 |
else {
|
|
|
f109b2 |
- pam_syslog(pamh, LOG_ERR, "User unknown");
|
|
|
f109b2 |
+ pam_syslog(pamh, LOG_NOTICE, "User unknown");
|
|
|
f109b2 |
}
|
|
|
f109b2 |
return PAM_IGNORE;
|
|
|
f109b2 |
}
|
|
|
f109b2 |
@@ -421,10 +187,11 @@ check_tally(pam_handle_t *pamh, struct o
|
|
|
f109b2 |
unsigned int i;
|
|
|
f109b2 |
uint64_t latest_time;
|
|
|
f109b2 |
int failures;
|
|
|
f109b2 |
+ const char *dir = get_tally_dir(opts);
|
|
|
f109b2 |
|
|
|
f109b2 |
opts->now = time(NULL);
|
|
|
f109b2 |
|
|
|
f109b2 |
- tfd = open_tally(opts->dir, opts->user, opts->uid, 0);
|
|
|
f109b2 |
+ tfd = open_tally(dir, opts->user, opts->uid, 0);
|
|
|
f109b2 |
|
|
|
f109b2 |
*fd = tfd;
|
|
|
f109b2 |
|
|
|
f109b2 |
@@ -446,7 +213,7 @@ check_tally(pam_handle_t *pamh, struct o
|
|
|
f109b2 |
}
|
|
|
f109b2 |
|
|
|
f109b2 |
latest_time = 0;
|
|
|
f109b2 |
- for(i = 0; i < tallies->count; i++) {
|
|
|
f109b2 |
+ for (i = 0; i < tallies->count; i++) {
|
|
|
f109b2 |
if ((tallies->records[i].status & TALLY_STATUS_VALID) &&
|
|
|
f109b2 |
tallies->records[i].time > latest_time)
|
|
|
f109b2 |
latest_time = tallies->records[i].time;
|
|
|
f109b2 |
@@ -455,7 +222,7 @@ check_tally(pam_handle_t *pamh, struct o
|
|
|
f109b2 |
opts->latest_time = latest_time;
|
|
|
f109b2 |
|
|
|
f109b2 |
failures = 0;
|
|
|
f109b2 |
- for(i = 0; i < tallies->count; i++) {
|
|
|
f109b2 |
+ for (i = 0; i < tallies->count; i++) {
|
|
|
f109b2 |
if ((tallies->records[i].status & TALLY_STATUS_VALID) &&
|
|
|
f109b2 |
latest_time - tallies->records[i].time < opts->fail_interval) {
|
|
|
f109b2 |
++failures;
|
|
|
f109b2 |
@@ -498,9 +265,10 @@ static void
|
|
|
f109b2 |
reset_tally(pam_handle_t *pamh, struct options *opts, int *fd)
|
|
|
f109b2 |
{
|
|
|
f109b2 |
int rv;
|
|
|
f109b2 |
+ const char *dir = get_tally_dir(opts);
|
|
|
f109b2 |
|
|
|
f109b2 |
if (*fd == -1) {
|
|
|
f109b2 |
- *fd = open_tally(opts->dir, opts->user, opts->uid, 1);
|
|
|
f109b2 |
+ *fd = open_tally(dir, opts->user, opts->uid, 1);
|
|
|
f109b2 |
}
|
|
|
f109b2 |
else {
|
|
|
f109b2 |
while ((rv=ftruncate(*fd, 0)) == -1 && errno == EINTR);
|
|
|
f109b2 |
@@ -519,9 +287,10 @@ write_tally(pam_handle_t *pamh, struct o
|
|
|
f109b2 |
unsigned int oldest;
|
|
|
f109b2 |
uint64_t oldtime;
|
|
|
f109b2 |
const void *source = NULL;
|
|
|
f109b2 |
+ const char *dir = get_tally_dir(opts);
|
|
|
f109b2 |
|
|
|
f109b2 |
if (*fd == -1) {
|
|
|
f109b2 |
- *fd = open_tally(opts->dir, opts->user, opts->uid, 1);
|
|
|
f109b2 |
+ *fd = open_tally(dir, opts->user, opts->uid, 1);
|
|
|
f109b2 |
}
|
|
|
f109b2 |
if (*fd == -1) {
|
|
|
f109b2 |
if (errno == EACCES) {
|
|
|
f109b2 |
@@ -536,7 +305,7 @@ write_tally(pam_handle_t *pamh, struct o
|
|
|
f109b2 |
failures = 0;
|
|
|
f109b2 |
|
|
|
f109b2 |
for (i = 0; i < tallies->count; ++i) {
|
|
|
f109b2 |
- if (tallies->records[i].time < oldtime) {
|
|
|
f109b2 |
+ if (oldtime == 0 || tallies->records[i].time < oldtime) {
|
|
|
f109b2 |
oldtime = tallies->records[i].time;
|
|
|
f109b2 |
oldest = i;
|
|
|
f109b2 |
}
|
|
|
f109b2 |
@@ -630,16 +399,26 @@ faillock_message(pam_handle_t *pamh, str
|
|
|
f109b2 |
left = opts->latest_time + opts->unlock_time - opts->now;
|
|
|
f109b2 |
}
|
|
|
f109b2 |
|
|
|
f109b2 |
+ pam_info(pamh, _("The account is locked due to %u failed logins."),
|
|
|
f109b2 |
+ (unsigned int)opts->failures);
|
|
|
f109b2 |
if (left > 0) {
|
|
|
f109b2 |
left = (left + 59)/60; /* minutes */
|
|
|
f109b2 |
|
|
|
f109b2 |
- pam_info(pamh, _("Account temporarily locked due to %d failed logins"),
|
|
|
f109b2 |
- opts->failures);
|
|
|
f109b2 |
- pam_info(pamh, _("(%d minutes left to unlock)"), (int)left);
|
|
|
f109b2 |
- }
|
|
|
f109b2 |
- else {
|
|
|
f109b2 |
- pam_info(pamh, _("Account locked due to %d failed logins"),
|
|
|
f109b2 |
- opts->failures);
|
|
|
f109b2 |
+#if defined HAVE_DNGETTEXT && defined ENABLE_NLS
|
|
|
f109b2 |
+ pam_info(
|
|
|
f109b2 |
+ pamh,
|
|
|
f109b2 |
+ dngettext(PACKAGE,
|
|
|
f109b2 |
+ "(%d minute left to unlock)",
|
|
|
f109b2 |
+ "(%d minutes left to unlock)",
|
|
|
f109b2 |
+ (int)left),
|
|
|
f109b2 |
+ (int)left);
|
|
|
f109b2 |
+#else
|
|
|
f109b2 |
+ if (left == 1)
|
|
|
f109b2 |
+ pam_info(pamh, _("(%d minute left to unlock)"), (int)left);
|
|
|
f109b2 |
+ else
|
|
|
f109b2 |
+ /* TRANSLATORS: only used if dngettext is not supported. */
|
|
|
f109b2 |
+ pam_info(pamh, _("(%d minutes left to unlock)"), (int)left);
|
|
|
f109b2 |
+#endif
|
|
|
f109b2 |
}
|
|
|
f109b2 |
}
|
|
|
f109b2 |
}
|
|
|
f109b2 |
@@ -663,7 +442,7 @@ opts_cleanup(struct options *opts)
|
|
|
f109b2 |
|
|
|
f109b2 |
/*---------------------------------------------------------------------*/
|
|
|
f109b2 |
|
|
|
f109b2 |
-PAM_EXTERN int
|
|
|
f109b2 |
+int
|
|
|
f109b2 |
pam_sm_authenticate(pam_handle_t *pamh, int flags,
|
|
|
f109b2 |
int argc, const char **argv)
|
|
|
f109b2 |
{
|
|
|
f109b2 |
@@ -673,13 +452,13 @@ pam_sm_authenticate(pam_handle_t *pamh,
|
|
|
f109b2 |
|
|
|
f109b2 |
memset(&tallies, 0, sizeof(tallies));
|
|
|
f109b2 |
|
|
|
f109b2 |
- args_parse(pamh, argc, argv, flags, &opts);
|
|
|
f109b2 |
- if (opts.fatal_error) {
|
|
|
f109b2 |
- rv = PAM_BUF_ERR;
|
|
|
f109b2 |
+ rv = args_parse(pamh, argc, argv, flags, &opts);
|
|
|
f109b2 |
+ if (rv != PAM_SUCCESS)
|
|
|
f109b2 |
goto err;
|
|
|
f109b2 |
- }
|
|
|
f109b2 |
|
|
|
f109b2 |
- pam_fail_delay(pamh, 2000000); /* 2 sec delay for on failure */
|
|
|
f109b2 |
+ if (!(opts.flags & FAILLOCK_FLAG_NO_DELAY)) {
|
|
|
f109b2 |
+ pam_fail_delay(pamh, 2000000); /* 2 sec delay on failure */
|
|
|
f109b2 |
+ }
|
|
|
f109b2 |
|
|
|
f109b2 |
if ((rv=get_pam_user(pamh, &opts)) != PAM_SUCCESS) {
|
|
|
f109b2 |
goto err;
|
|
|
f109b2 |
@@ -722,7 +501,7 @@ err:
|
|
|
f109b2 |
|
|
|
f109b2 |
/*---------------------------------------------------------------------*/
|
|
|
f109b2 |
|
|
|
f109b2 |
-PAM_EXTERN int
|
|
|
f109b2 |
+int
|
|
|
f109b2 |
pam_sm_setcred(pam_handle_t *pamh UNUSED, int flags UNUSED,
|
|
|
f109b2 |
int argc UNUSED, const char **argv UNUSED)
|
|
|
f109b2 |
{
|
|
|
f109b2 |
@@ -731,7 +510,7 @@ pam_sm_setcred(pam_handle_t *pamh UNUSED
|
|
|
f109b2 |
|
|
|
f109b2 |
/*---------------------------------------------------------------------*/
|
|
|
f109b2 |
|
|
|
f109b2 |
-PAM_EXTERN int
|
|
|
f109b2 |
+int
|
|
|
f109b2 |
pam_sm_acct_mgmt(pam_handle_t *pamh, int flags,
|
|
|
f109b2 |
int argc, const char **argv)
|
|
|
f109b2 |
{
|
|
|
f109b2 |
@@ -741,12 +520,10 @@ pam_sm_acct_mgmt(pam_handle_t *pamh, int
|
|
|
f109b2 |
|
|
|
f109b2 |
memset(&tallies, 0, sizeof(tallies));
|
|
|
f109b2 |
|
|
|
f109b2 |
- args_parse(pamh, argc, argv, flags, &opts);
|
|
|
f109b2 |
+ rv = args_parse(pamh, argc, argv, flags, &opts);
|
|
|
f109b2 |
|
|
|
f109b2 |
- if (opts.fatal_error) {
|
|
|
f109b2 |
- rv = PAM_BUF_ERR;
|
|
|
f109b2 |
+ if (rv != PAM_SUCCESS)
|
|
|
f109b2 |
goto err;
|
|
|
f109b2 |
- }
|
|
|
f109b2 |
|
|
|
f109b2 |
opts.action = FAILLOCK_ACTION_AUTHSUCC;
|
|
|
f109b2 |
|
|
|
f109b2 |
@@ -770,28 +547,3 @@ err:
|
|
|
f109b2 |
|
|
|
f109b2 |
/*-----------------------------------------------------------------------*/
|
|
|
f109b2 |
|
|
|
f109b2 |
-#ifdef PAM_STATIC
|
|
|
f109b2 |
-
|
|
|
f109b2 |
-/* static module data */
|
|
|
f109b2 |
-
|
|
|
f109b2 |
-struct pam_module _pam_faillock_modstruct = {
|
|
|
f109b2 |
- MODULE_NAME,
|
|
|
f109b2 |
-#ifdef PAM_SM_AUTH
|
|
|
f109b2 |
- pam_sm_authenticate,
|
|
|
f109b2 |
- pam_sm_setcred,
|
|
|
f109b2 |
-#else
|
|
|
f109b2 |
- NULL,
|
|
|
f109b2 |
- NULL,
|
|
|
f109b2 |
-#endif
|
|
|
f109b2 |
-#ifdef PAM_SM_ACCOUNT
|
|
|
f109b2 |
- pam_sm_acct_mgmt,
|
|
|
f109b2 |
-#else
|
|
|
f109b2 |
- NULL,
|
|
|
f109b2 |
-#endif
|
|
|
f109b2 |
- NULL,
|
|
|
f109b2 |
- NULL,
|
|
|
f109b2 |
- NULL,
|
|
|
f109b2 |
-};
|
|
|
f109b2 |
-
|
|
|
f109b2 |
-#endif /* #ifdef PAM_STATIC */
|
|
|
f109b2 |
-
|
|
|
f109b2 |
diff --git a/modules/pam_faillock/faillock.h b/modules/pam_faillock/faillock.h
|
|
|
f109b2 |
index b22a9dfb..0ea0ffba 100644
|
|
|
f109b2 |
--- a/modules/pam_faillock/faillock.h
|
|
|
f109b2 |
+++ b/modules/pam_faillock/faillock.h
|
|
|
f109b2 |
diff -up Linux-PAM-1.5.1/modules/pam_faillock/faillock.h.faillock-load-conf-from-file Linux-PAM-1.5.1/modules/pam_faillock/faillock.h
|
|
|
f109b2 |
--- Linux-PAM-1.5.1/modules/pam_faillock/faillock.h.faillock-load-conf-from-file 2020-11-25 17:57:02.000000000 +0100
|
|
|
f109b2 |
+++ Linux-PAM-1.5.1/modules/pam_faillock/faillock.h 2022-05-25 15:33:03.885551825 +0200
|
|
|
f109b2 |
@@ -67,7 +67,6 @@ struct tally_data {
|
|
|
f109b2 |
};
|
|
|
f109b2 |
|
|
|
f109b2 |
#define FAILLOCK_DEFAULT_TALLYDIR "/var/run/faillock"
|
|
|
f109b2 |
-#define FAILLOCK_DEFAULT_CONF "/etc/security/faillock.conf"
|
|
|
f109b2 |
|
|
|
f109b2 |
int open_tally(const char *dir, const char *user, uid_t uid, int create);
|
|
|
f109b2 |
int read_tally(int fd, struct tally_data *tallies);
|
|
|
f109b2 |
diff --git a/modules/pam_faillock/pam_faillock.c b/modules/pam_faillock/pam_faillock.c
|
|
|
f109b2 |
index ddbb90e7..f46fca99 100644
|
|
|
f109b2 |
--- a/modules/pam_faillock/pam_faillock.c
|
|
|
f109b2 |
+++ b/modules/pam_faillock/pam_faillock.c
|
|
|
f109b2 |
@@ -134,10 +134,96 @@ args_parse(pam_handle_t *pamh, int argc, const char **argv,
|
|
|
f109b2 |
return PAM_SUCCESS;
|
|
|
f109b2 |
}
|
|
|
f109b2 |
|
|
|
f109b2 |
+static int
|
|
|
f109b2 |
+check_user_in_passwd(pam_handle_t *pamh,
|
|
|
f109b2 |
+ const char *user_name,
|
|
|
f109b2 |
+ const char *file_name)
|
|
|
f109b2 |
+{
|
|
|
f109b2 |
+ int rc;
|
|
|
f109b2 |
+ size_t user_len;
|
|
|
f109b2 |
+ FILE *fp;
|
|
|
f109b2 |
+ char line[BUFSIZ];
|
|
|
f109b2 |
+
|
|
|
f109b2 |
+ /* Validate the user name. */
|
|
|
f109b2 |
+ if ((user_len = strlen(user_name)) == 0) {
|
|
|
f109b2 |
+ pam_syslog(pamh, LOG_NOTICE, "user name is not valid");
|
|
|
f109b2 |
+ return PAM_SERVICE_ERR;
|
|
|
f109b2 |
+ }
|
|
|
f109b2 |
+
|
|
|
f109b2 |
+ if (user_len > sizeof(line) - sizeof(":")) {
|
|
|
f109b2 |
+ pam_syslog(pamh, LOG_NOTICE, "user name is too long");
|
|
|
f109b2 |
+ return PAM_SERVICE_ERR;
|
|
|
f109b2 |
+ }
|
|
|
f109b2 |
+
|
|
|
f109b2 |
+ if (strchr(user_name, ':') != NULL) {
|
|
|
f109b2 |
+ /*
|
|
|
f109b2 |
+ * "root:x" is not a local user name even if the passwd file
|
|
|
f109b2 |
+ * contains a line starting with "root:x:".
|
|
|
f109b2 |
+ */
|
|
|
f109b2 |
+ return PAM_PERM_DENIED;
|
|
|
f109b2 |
+ }
|
|
|
f109b2 |
+
|
|
|
f109b2 |
+ /* Open the passwd file. */
|
|
|
f109b2 |
+ if (file_name == NULL) {
|
|
|
f109b2 |
+ file_name = "/etc/passwd";
|
|
|
f109b2 |
+ }
|
|
|
f109b2 |
+ if ((fp = fopen(file_name, "r")) == NULL) {
|
|
|
f109b2 |
+ pam_syslog(pamh, LOG_ERR, "error opening %s: %m", file_name);
|
|
|
f109b2 |
+ return PAM_SERVICE_ERR;
|
|
|
f109b2 |
+ }
|
|
|
f109b2 |
+
|
|
|
f109b2 |
+ /*
|
|
|
f109b2 |
+ * Scan the file using fgets() instead of fgetpwent_r() because
|
|
|
f109b2 |
+ * the latter is not flexible enough in handling long lines
|
|
|
f109b2 |
+ * in passwd files.
|
|
|
f109b2 |
+ */
|
|
|
f109b2 |
+ rc = PAM_PERM_DENIED;
|
|
|
f109b2 |
+ while (fgets(line, sizeof(line), fp) != NULL) {
|
|
|
f109b2 |
+ size_t line_len;
|
|
|
f109b2 |
+ const char *str;
|
|
|
f109b2 |
+
|
|
|
f109b2 |
+ /*
|
|
|
f109b2 |
+ * Does this line start with the user name
|
|
|
f109b2 |
+ * followed by a colon?
|
|
|
f109b2 |
+ */
|
|
|
f109b2 |
+ if (strncmp(user_name, line, user_len) == 0 &&
|
|
|
f109b2 |
+ line[user_len] == ':') {
|
|
|
f109b2 |
+ rc = PAM_SUCCESS;
|
|
|
f109b2 |
+ /*
|
|
|
f109b2 |
+ * Continue reading the file to avoid timing attacks.
|
|
|
f109b2 |
+ */
|
|
|
f109b2 |
+ }
|
|
|
f109b2 |
+ /* Has a newline been read? */
|
|
|
f109b2 |
+ line_len = strlen(line);
|
|
|
f109b2 |
+ if (line_len < sizeof(line) - 1 ||
|
|
|
f109b2 |
+ line[line_len - 1] == '\n') {
|
|
|
f109b2 |
+ /* Yes, continue with the next line. */
|
|
|
f109b2 |
+ continue;
|
|
|
f109b2 |
+ }
|
|
|
f109b2 |
+
|
|
|
f109b2 |
+ /* No, read till the end of this line first. */
|
|
|
f109b2 |
+ while ((str = fgets(line, sizeof(line), fp)) != NULL) {
|
|
|
f109b2 |
+ line_len = strlen(line);
|
|
|
f109b2 |
+ if (line_len == 0 ||
|
|
|
f109b2 |
+ line[line_len - 1] == '\n') {
|
|
|
f109b2 |
+ break;
|
|
|
f109b2 |
+ }
|
|
|
f109b2 |
+ }
|
|
|
f109b2 |
+ if (str == NULL) {
|
|
|
f109b2 |
+ /* fgets returned NULL, we are done. */
|
|
|
f109b2 |
+ break;
|
|
|
f109b2 |
+ }
|
|
|
f109b2 |
+ /* Continue with the next line. */
|
|
|
f109b2 |
+ }
|
|
|
f109b2 |
+
|
|
|
f109b2 |
+ fclose(fp);
|
|
|
f109b2 |
+ return rc;
|
|
|
f109b2 |
+}
|
|
|
f109b2 |
+
|
|
|
f109b2 |
static int
|
|
|
f109b2 |
check_local_user (pam_handle_t *pamh, const char *user)
|
|
|
f109b2 |
{
|
|
|
f109b2 |
- return pam_modutil_check_user_in_passwd(pamh, user, NULL) == PAM_SUCCESS;
|
|
|
f109b2 |
+ return check_user_in_passwd(pamh, user, NULL) == PAM_SUCCESS;
|
|
|
f109b2 |
}
|
|
|
f109b2 |
|
|
|
f109b2 |
static int
|