From 3130acba872c2645d2effa11cc80d1f6bfa59858 Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Tue, 17 Mar 2020 21:29:24 +0000 Subject: modules/pam_pwhistory: use pam_str_skip_icase_prefix * modules/pam_pwhistory/pam_pwhistory.c: Include "pam_inline.h". (parse_option): Use pam_str_skip_icase_prefix instead of ugly strncasecmp invocations. --- modules/pam_pwhistory/pam_pwhistory.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'modules/pam_pwhistory') diff --git a/modules/pam_pwhistory/pam_pwhistory.c b/modules/pam_pwhistory/pam_pwhistory.c index 3efb0ca5..2d4507d5 100644 --- a/modules/pam_pwhistory/pam_pwhistory.c +++ b/modules/pam_pwhistory/pam_pwhistory.c @@ -57,6 +57,7 @@ #include #include "opasswd.h" +#include "pam_inline.h" #define DEFAULT_BUFLEN 2048 @@ -72,6 +73,8 @@ typedef struct options_t options_t; static void parse_option (pam_handle_t *pamh, const char *argv, options_t *options) { + const char *str; + if (strcasecmp (argv, "try_first_pass") == 0) /* ignore */; else if (strcasecmp (argv, "use_first_pass") == 0) @@ -80,23 +83,23 @@ parse_option (pam_handle_t *pamh, const char *argv, options_t *options) /* ignore, handled by pam_get_authtok */; else if (strcasecmp (argv, "debug") == 0) options->debug = 1; - else if (strncasecmp (argv, "remember=", 9) == 0) + else if ((str = pam_str_skip_icase_prefix(argv, "remember=")) != NULL) { - options->remember = strtol(&argv[9], NULL, 10); + options->remember = strtol(str, NULL, 10); if (options->remember < 0) options->remember = 0; if (options->remember > 400) options->remember = 400; } - else if (strncasecmp (argv, "retry=", 6) == 0) + else if ((str = pam_str_skip_icase_prefix(argv, "retry=")) != NULL) { - options->tries = strtol(&argv[6], NULL, 10); + options->tries = strtol(str, NULL, 10); if (options->tries < 0) options->tries = 1; } else if (strcasecmp (argv, "enforce_for_root") == 0) options->enforce_for_root = 1; - else if (strncasecmp (argv, "authtok_type=", 13) == 0) + else if (pam_str_skip_icase_prefix(argv, "authtok_type=") != NULL) { /* ignore, for pam_get_authtok */; } else pam_syslog (pamh, LOG_ERR, "pam_pwhistory: unknown option: %s", argv); -- cgit v1.2.3