123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764 |
- /*
- * Copyright (c) 2010, 2017, 2019 Tomas Mraz <tmraz@redhat.com>
- * Copyright (c) 2010, 2017, 2019 Red Hat, Inc.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, and the entire permission notice in its entirety,
- * including the disclaimer of warranties.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote
- * products derived from this software without specific prior
- * written permission.
- *
- * ALTERNATIVELY, this product may be distributed under the terms of
- * the GNU Public License, in which case the provisions of the GPL are
- * required INSTEAD OF the above restrictions. (This clause is
- * necessary due to a potential bad interaction between the GPL and
- * the restrictions contained in a BSD-style copyright.)
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
- * OF THE POSSIBILITY OF SUCH DAMAGE.
- */
- #include "config.h"
- #include <stdio.h>
- #include <string.h>
- #include <unistd.h>
- #include <stdint.h>
- #include <stdlib.h>
- #include <errno.h>
- #include <time.h>
- #include <pwd.h>
- #include <syslog.h>
- #include <ctype.h>
- #ifdef HAVE_LIBAUDIT
- #include <libaudit.h>
- #endif
- #include <security/pam_modules.h>
- #include <security/pam_modutil.h>
- #include <security/pam_ext.h>
- #include "pam_inline.h"
- #include "faillock.h"
- #define FAILLOCK_ACTION_PREAUTH 0
- #define FAILLOCK_ACTION_AUTHSUCC 1
- #define FAILLOCK_ACTION_AUTHFAIL 2
- #define FAILLOCK_FLAG_DENY_ROOT 0x1
- #define FAILLOCK_FLAG_AUDIT 0x2
- #define FAILLOCK_FLAG_SILENT 0x4
- #define FAILLOCK_FLAG_NO_LOG_INFO 0x8
- #define FAILLOCK_FLAG_UNLOCKED 0x10
- #define FAILLOCK_FLAG_LOCAL_ONLY 0x20
- #define FAILLOCK_FLAG_NO_DELAY 0x40
- #define MAX_TIME_INTERVAL 604800 /* 7 days */
- #define FAILLOCK_CONF_MAX_LINELEN 1023
- static const char default_faillock_conf[] = FAILLOCK_DEFAULT_CONF;
- struct options {
- unsigned int action;
- unsigned int flags;
- unsigned short deny;
- unsigned int fail_interval;
- unsigned int unlock_time;
- unsigned int root_unlock_time;
- char *dir;
- const char *user;
- char *admin_group;
- int failures;
- uint64_t latest_time;
- uid_t uid;
- int is_admin;
- uint64_t now;
- int fatal_error;
- };
- static int read_config_file(
- pam_handle_t *pamh,
- struct options *opts,
- const char *cfgfile
- );
- static void set_conf_opt(
- pam_handle_t *pamh,
- struct options *opts,
- const char *name,
- const char *value
- );
- static int
- args_parse(pam_handle_t *pamh, int argc, const char **argv,
- int flags, struct options *opts)
- {
- int i;
- int config_arg_index = -1;
- int rv;
- const char *conf = default_faillock_conf;
- memset(opts, 0, sizeof(*opts));
- opts->dir = strdup(FAILLOCK_DEFAULT_TALLYDIR);
- opts->deny = 3;
- opts->fail_interval = 900;
- opts->unlock_time = 600;
- opts->root_unlock_time = MAX_TIME_INTERVAL+1;
- for (i = 0; i < argc; ++i) {
- const char *str = pam_str_skip_prefix(argv[i], "conf=");
- if (str != NULL) {
- conf = str;
- config_arg_index = i;
- }
- }
- if ((rv = read_config_file(pamh, opts, conf)) != PAM_SUCCESS) {
- pam_syslog(pamh, LOG_ERR,
- "Configuration file missing or broken");
- return rv;
- }
- for (i = 0; i < argc; ++i) {
- if (i == config_arg_index) {
- continue;
- }
- else if (strcmp(argv[i], "preauth") == 0) {
- opts->action = FAILLOCK_ACTION_PREAUTH;
- }
- else if (strcmp(argv[i], "authfail") == 0) {
- opts->action = FAILLOCK_ACTION_AUTHFAIL;
- }
- else if (strcmp(argv[i], "authsucc") == 0) {
- opts->action = FAILLOCK_ACTION_AUTHSUCC;
- }
- else {
- char buf[FAILLOCK_CONF_MAX_LINELEN + 1];
- char *val;
- strncpy(buf, argv[i], sizeof(buf) - 1);
- buf[sizeof(buf) - 1] = '\0';
- val = strchr(buf, '=');
- if (val != NULL) {
- *val = '\0';
- ++val;
- }
- else {
- val = buf + sizeof(buf) - 1;
- }
- set_conf_opt(pamh, opts, buf, val);
- }
- }
- if (opts->root_unlock_time == MAX_TIME_INTERVAL+1)
- opts->root_unlock_time = opts->unlock_time;
- if (flags & PAM_SILENT)
- opts->flags |= FAILLOCK_FLAG_SILENT;
- if (opts->dir == NULL) {
- pam_syslog(pamh, LOG_CRIT, "Error allocating memory: %m");
- opts->fatal_error = 1;
- }
- if (opts->fatal_error)
- return PAM_BUF_ERR;
- return PAM_SUCCESS;
- }
- /* parse a single configuration file */
- static int
- read_config_file(pam_handle_t *pamh, struct options *opts, const char *cfgfile)
- {
- FILE *f;
- char linebuf[FAILLOCK_CONF_MAX_LINELEN+1];
- f = fopen(cfgfile, "r");
- if (f == NULL) {
- /* ignore non-existent default config file */
- if (errno == ENOENT && cfgfile == default_faillock_conf)
- return PAM_SUCCESS;
- return PAM_SERVICE_ERR;
- }
- while (fgets(linebuf, sizeof(linebuf), f) != NULL) {
- size_t len;
- char *ptr;
- char *name;
- int eq;
- len = strlen(linebuf);
- /* len cannot be 0 unless there is a bug in fgets */
- if (len && linebuf[len - 1] != '\n' && !feof(f)) {
- (void) fclose(f);
- return PAM_SERVICE_ERR;
- }
- if ((ptr=strchr(linebuf, '#')) != NULL) {
- *ptr = '\0';
- } else {
- ptr = linebuf + len;
- }
- /* drop terminating whitespace including the \n */
- while (ptr > linebuf) {
- if (!isspace(*(ptr-1))) {
- *ptr = '\0';
- break;
- }
- --ptr;
- }
- /* skip initial whitespace */
- for (ptr = linebuf; isspace(*ptr); ptr++);
- if (*ptr == '\0')
- continue;
- /* grab the key name */
- eq = 0;
- name = ptr;
- while (*ptr != '\0') {
- if (isspace(*ptr) || *ptr == '=') {
- eq = *ptr == '=';
- *ptr = '\0';
- ++ptr;
- break;
- }
- ++ptr;
- }
- /* grab the key value */
- while (*ptr != '\0') {
- if (*ptr != '=' || eq) {
- if (!isspace(*ptr)) {
- break;
- }
- } else {
- eq = 1;
- }
- ++ptr;
- }
- /* set the key:value pair on opts */
- set_conf_opt(pamh, opts, name, ptr);
- }
- (void)fclose(f);
- return PAM_SUCCESS;
- }
- static void
- set_conf_opt(pam_handle_t *pamh, struct options *opts, const char *name, const char *value)
- {
- if (strcmp(name, "dir") == 0) {
- if (value[0] != '/') {
- pam_syslog(pamh, LOG_ERR,
- "Tally directory is not absolute path (%s); keeping default", value);
- } else {
- free(opts->dir);
- opts->dir = strdup(value);
- }
- }
- else if (strcmp(name, "deny") == 0) {
- if (sscanf(value, "%hu", &opts->deny) != 1) {
- pam_syslog(pamh, LOG_ERR,
- "Bad number supplied for deny argument");
- }
- }
- else if (strcmp(name, "fail_interval") == 0) {
- unsigned int temp;
- if (sscanf(value, "%u", &temp) != 1 ||
- temp > MAX_TIME_INTERVAL) {
- pam_syslog(pamh, LOG_ERR,
- "Bad number supplied for fail_interval argument");
- } else {
- opts->fail_interval = temp;
- }
- }
- else if (strcmp(name, "unlock_time") == 0) {
- unsigned int temp;
- if (strcmp(value, "never") == 0) {
- opts->unlock_time = 0;
- }
- else if (sscanf(value, "%u", &temp) != 1 ||
- temp > MAX_TIME_INTERVAL) {
- pam_syslog(pamh, LOG_ERR,
- "Bad number supplied for unlock_time argument");
- }
- else {
- opts->unlock_time = temp;
- }
- }
- else if (strcmp(name, "root_unlock_time") == 0) {
- unsigned int temp;
- if (strcmp(value, "never") == 0) {
- opts->root_unlock_time = 0;
- }
- else if (sscanf(value, "%u", &temp) != 1 ||
- temp > MAX_TIME_INTERVAL) {
- pam_syslog(pamh, LOG_ERR,
- "Bad number supplied for root_unlock_time argument");
- } else {
- opts->root_unlock_time = temp;
- }
- }
- else if (strcmp(name, "admin_group") == 0) {
- free(opts->admin_group);
- opts->admin_group = strdup(value);
- if (opts->admin_group == NULL) {
- opts->fatal_error = 1;
- pam_syslog(pamh, LOG_CRIT, "Error allocating memory: %m");
- }
- }
- else if (strcmp(name, "even_deny_root") == 0) {
- opts->flags |= FAILLOCK_FLAG_DENY_ROOT;
- }
- else if (strcmp(name, "audit") == 0) {
- opts->flags |= FAILLOCK_FLAG_AUDIT;
- }
- else if (strcmp(name, "silent") == 0) {
- opts->flags |= FAILLOCK_FLAG_SILENT;
- }
- else if (strcmp(name, "no_log_info") == 0) {
- opts->flags |= FAILLOCK_FLAG_NO_LOG_INFO;
- }
- else if (strcmp(name, "local_users_only") == 0) {
- opts->flags |= FAILLOCK_FLAG_LOCAL_ONLY;
- }
- else if (strcmp(name, "nodelay") == 0) {
- opts->flags |= FAILLOCK_FLAG_NO_DELAY;
- }
- else {
- pam_syslog(pamh, LOG_ERR, "Unknown option: %s", name);
- }
- }
- static int
- check_local_user (pam_handle_t *pamh, const char *user)
- {
- return pam_modutil_check_user_in_passwd(pamh, user, NULL) == PAM_SUCCESS;
- }
- static int
- get_pam_user(pam_handle_t *pamh, struct options *opts)
- {
- const char *user;
- int rv;
- struct passwd *pwd;
- if ((rv=pam_get_user(pamh, &user, NULL)) != PAM_SUCCESS) {
- return rv == PAM_CONV_AGAIN ? PAM_INCOMPLETE : rv;
- }
- if (*user == '\0') {
- return PAM_IGNORE;
- }
- if ((pwd=pam_modutil_getpwnam(pamh, user)) == NULL) {
- if (opts->flags & FAILLOCK_FLAG_AUDIT) {
- pam_syslog(pamh, LOG_NOTICE, "User unknown: %s", user);
- }
- else {
- pam_syslog(pamh, LOG_NOTICE, "User unknown");
- }
- return PAM_IGNORE;
- }
- opts->user = user;
- opts->uid = pwd->pw_uid;
- if (pwd->pw_uid == 0) {
- opts->is_admin = 1;
- return PAM_SUCCESS;
- }
- if (opts->admin_group && *opts->admin_group) {
- opts->is_admin = pam_modutil_user_in_group_uid_nam(pamh,
- pwd->pw_uid, opts->admin_group);
- }
- return PAM_SUCCESS;
- }
- static int
- check_tally(pam_handle_t *pamh, struct options *opts, struct tally_data *tallies, int *fd)
- {
- int tfd;
- unsigned int i;
- uint64_t latest_time;
- int failures;
- opts->now = time(NULL);
- tfd = open_tally(opts->dir, opts->user, opts->uid, 0);
- *fd = tfd;
- if (tfd == -1) {
- if (errno == EACCES || errno == ENOENT) {
- return PAM_SUCCESS;
- }
- pam_syslog(pamh, LOG_ERR, "Error opening the tally file for %s: %m", opts->user);
- return PAM_SYSTEM_ERR;
- }
- if (read_tally(tfd, tallies) != 0) {
- pam_syslog(pamh, LOG_ERR, "Error reading the tally file for %s: %m", opts->user);
- return PAM_SYSTEM_ERR;
- }
- if (opts->is_admin && !(opts->flags & FAILLOCK_FLAG_DENY_ROOT)) {
- return PAM_SUCCESS;
- }
- latest_time = 0;
- for (i = 0; i < tallies->count; i++) {
- if ((tallies->records[i].status & TALLY_STATUS_VALID) &&
- tallies->records[i].time > latest_time)
- latest_time = tallies->records[i].time;
- }
- opts->latest_time = latest_time;
- failures = 0;
- for (i = 0; i < tallies->count; i++) {
- if ((tallies->records[i].status & TALLY_STATUS_VALID) &&
- latest_time - tallies->records[i].time < opts->fail_interval) {
- ++failures;
- }
- }
- opts->failures = failures;
- if (opts->deny && failures >= opts->deny) {
- if ((!opts->is_admin && opts->unlock_time && latest_time + opts->unlock_time < opts->now) ||
- (opts->is_admin && opts->root_unlock_time && latest_time + opts->root_unlock_time < opts->now)) {
- #ifdef HAVE_LIBAUDIT
- if (opts->action != FAILLOCK_ACTION_PREAUTH) { /* do not audit in preauth */
- char buf[64];
- int audit_fd;
- const void *rhost = NULL, *tty = NULL;
- audit_fd = audit_open();
- /* If there is an error & audit support is in the kernel report error */
- if ((audit_fd < 0) && !(errno == EINVAL || errno == EPROTONOSUPPORT ||
- errno == EAFNOSUPPORT))
- return PAM_SYSTEM_ERR;
- (void)pam_get_item(pamh, PAM_TTY, &tty);
- (void)pam_get_item(pamh, PAM_RHOST, &rhost);
- snprintf(buf, sizeof(buf), "pam_faillock uid=%u ", opts->uid);
- audit_log_user_message(audit_fd, AUDIT_RESP_ACCT_UNLOCK_TIMED, buf,
- rhost, NULL, tty, 1);
- }
- #endif
- opts->flags |= FAILLOCK_FLAG_UNLOCKED;
- return PAM_SUCCESS;
- }
- return PAM_AUTH_ERR;
- }
- return PAM_SUCCESS;
- }
- static void
- reset_tally(pam_handle_t *pamh, struct options *opts, int *fd)
- {
- int rv;
- if (*fd == -1) {
- *fd = open_tally(opts->dir, opts->user, opts->uid, 1);
- }
- else {
- while ((rv=ftruncate(*fd, 0)) == -1 && errno == EINTR);
- if (rv == -1) {
- pam_syslog(pamh, LOG_ERR, "Error clearing the tally file for %s: %m", opts->user);
- }
- }
- }
- static int
- write_tally(pam_handle_t *pamh, struct options *opts, struct tally_data *tallies, int *fd)
- {
- struct tally *records;
- unsigned int i;
- int failures;
- unsigned int oldest;
- uint64_t oldtime;
- const void *source = NULL;
- if (*fd == -1) {
- *fd = open_tally(opts->dir, opts->user, opts->uid, 1);
- }
- if (*fd == -1) {
- if (errno == EACCES) {
- return PAM_SUCCESS;
- }
- pam_syslog(pamh, LOG_ERR, "Error opening the tally file for %s: %m", opts->user);
- return PAM_SYSTEM_ERR;
- }
- oldtime = 0;
- oldest = 0;
- failures = 0;
- for (i = 0; i < tallies->count; ++i) {
- if (oldtime == 0 || tallies->records[i].time < oldtime) {
- oldtime = tallies->records[i].time;
- oldest = i;
- }
- if (opts->flags & FAILLOCK_FLAG_UNLOCKED ||
- opts->now - tallies->records[i].time >= opts->fail_interval ) {
- tallies->records[i].status &= ~TALLY_STATUS_VALID;
- } else {
- ++failures;
- }
- }
- if (oldest >= tallies->count || (tallies->records[oldest].status & TALLY_STATUS_VALID)) {
- oldest = tallies->count;
- if ((records=realloc(tallies->records, (oldest+1) * sizeof (*tallies->records))) == NULL) {
- pam_syslog(pamh, LOG_CRIT, "Error allocating memory for tally records: %m");
- return PAM_BUF_ERR;
- }
- ++tallies->count;
- tallies->records = records;
- }
- memset(&tallies->records[oldest], 0, sizeof (*tallies->records));
- tallies->records[oldest].status = TALLY_STATUS_VALID;
- if (pam_get_item(pamh, PAM_RHOST, &source) != PAM_SUCCESS || source == NULL) {
- if (pam_get_item(pamh, PAM_TTY, &source) != PAM_SUCCESS || source == NULL) {
- if (pam_get_item(pamh, PAM_SERVICE, &source) != PAM_SUCCESS || source == NULL) {
- source = "";
- }
- }
- else {
- tallies->records[oldest].status |= TALLY_STATUS_TTY;
- }
- }
- else {
- tallies->records[oldest].status |= TALLY_STATUS_RHOST;
- }
- strncpy(tallies->records[oldest].source, source, sizeof(tallies->records[oldest].source));
- /* source does not have to be null terminated */
- tallies->records[oldest].time = opts->now;
- ++failures;
- if (opts->deny && failures == opts->deny) {
- #ifdef HAVE_LIBAUDIT
- char buf[64];
- int audit_fd;
- audit_fd = audit_open();
- /* If there is an error & audit support is in the kernel report error */
- if ((audit_fd < 0) && !(errno == EINVAL || errno == EPROTONOSUPPORT ||
- errno == EAFNOSUPPORT))
- return PAM_SYSTEM_ERR;
- snprintf(buf, sizeof(buf), "pam_faillock uid=%u ", opts->uid);
- audit_log_user_message(audit_fd, AUDIT_ANOM_LOGIN_FAILURES, buf,
- NULL, NULL, NULL, 1);
- if (!opts->is_admin || (opts->flags & FAILLOCK_FLAG_DENY_ROOT)) {
- audit_log_user_message(audit_fd, AUDIT_RESP_ACCT_LOCK, buf,
- NULL, NULL, NULL, 1);
- }
- close(audit_fd);
- #endif
- if (!(opts->flags & FAILLOCK_FLAG_NO_LOG_INFO)) {
- pam_syslog(pamh, LOG_INFO, "Consecutive login failures for user %s account temporarily locked",
- opts->user);
- }
- }
- if (update_tally(*fd, tallies) == 0)
- return PAM_SUCCESS;
- return PAM_SYSTEM_ERR;
- }
- static void
- faillock_message(pam_handle_t *pamh, struct options *opts)
- {
- int64_t left;
- if (!(opts->flags & FAILLOCK_FLAG_SILENT)) {
- if (opts->is_admin) {
- left = opts->latest_time + opts->root_unlock_time - opts->now;
- }
- else {
- left = opts->latest_time + opts->unlock_time - opts->now;
- }
- pam_info(pamh, _("The account is locked due to %u failed logins."),
- (unsigned int)opts->failures);
- if (left > 0) {
- left = (left + 59)/60; /* minutes */
- #if defined HAVE_DNGETTEXT && defined ENABLE_NLS
- pam_info(
- pamh,
- dngettext(PACKAGE,
- "(%d minute left to unlock)",
- "(%d minutes left to unlock)",
- (int)left),
- (int)left);
- #else
- if (left == 1)
- pam_info(pamh, _("(%d minute left to unlock)"), (int)left);
- else
- /* TRANSLATORS: only used if dngettext is not supported. */
- pam_info(pamh, _("(%d minutes left to unlock)"), (int)left);
- #endif
- }
- }
- }
- static void
- tally_cleanup(struct tally_data *tallies, int fd)
- {
- if (fd != -1) {
- close(fd);
- }
- free(tallies->records);
- }
- static void
- opts_cleanup(struct options *opts)
- {
- free(opts->dir);
- free(opts->admin_group);
- }
- /*---------------------------------------------------------------------*/
- int
- pam_sm_authenticate(pam_handle_t *pamh, int flags,
- int argc, const char **argv)
- {
- struct options opts;
- int rv, fd = -1;
- struct tally_data tallies;
- memset(&tallies, 0, sizeof(tallies));
- rv = args_parse(pamh, argc, argv, flags, &opts);
- if (rv != PAM_SUCCESS)
- goto err;
- if (!(opts.flags & FAILLOCK_FLAG_NO_DELAY)) {
- pam_fail_delay(pamh, 2000000); /* 2 sec delay on failure */
- }
- if ((rv=get_pam_user(pamh, &opts)) != PAM_SUCCESS) {
- goto err;
- }
- if (!(opts.flags & FAILLOCK_FLAG_LOCAL_ONLY) ||
- check_local_user (pamh, opts.user) != 0) {
- switch (opts.action) {
- case FAILLOCK_ACTION_PREAUTH:
- rv = check_tally(pamh, &opts, &tallies, &fd);
- if (rv == PAM_AUTH_ERR && !(opts.flags & FAILLOCK_FLAG_SILENT)) {
- faillock_message(pamh, &opts);
- }
- break;
- case FAILLOCK_ACTION_AUTHSUCC:
- rv = check_tally(pamh, &opts, &tallies, &fd);
- if (rv == PAM_SUCCESS) {
- reset_tally(pamh, &opts, &fd);
- }
- break;
- case FAILLOCK_ACTION_AUTHFAIL:
- rv = check_tally(pamh, &opts, &tallies, &fd);
- if (rv == PAM_SUCCESS) {
- rv = PAM_IGNORE; /* this return value should be ignored */
- write_tally(pamh, &opts, &tallies, &fd);
- }
- break;
- }
- }
- tally_cleanup(&tallies, fd);
- err:
- opts_cleanup(&opts);
- return rv;
- }
- /*---------------------------------------------------------------------*/
- int
- pam_sm_setcred(pam_handle_t *pamh UNUSED, int flags UNUSED,
- int argc UNUSED, const char **argv UNUSED)
- {
- return PAM_SUCCESS;
- }
- /*---------------------------------------------------------------------*/
- int
- pam_sm_acct_mgmt(pam_handle_t *pamh, int flags,
- int argc, const char **argv)
- {
- struct options opts;
- int rv, fd = -1;
- struct tally_data tallies;
- memset(&tallies, 0, sizeof(tallies));
- rv = args_parse(pamh, argc, argv, flags, &opts);
- if (rv != PAM_SUCCESS)
- goto err;
- opts.action = FAILLOCK_ACTION_AUTHSUCC;
- if ((rv=get_pam_user(pamh, &opts)) != PAM_SUCCESS) {
- goto err;
- }
- if (!(opts.flags & FAILLOCK_FLAG_LOCAL_ONLY) ||
- check_local_user (pamh, opts.user) != 0) {
- check_tally(pamh, &opts, &tallies, &fd); /* for auditing */
- reset_tally(pamh, &opts, &fd);
- }
- tally_cleanup(&tallies, fd);
- err:
- opts_cleanup(&opts);
- return rv;
- }
- /*-----------------------------------------------------------------------*/
|