diff options
author | Dmitry V. Levin <ldv@altlinux.org> | 2020-03-19 18:40:16 +0000 |
---|---|---|
committer | Dmitry V. Levin <ldv@altlinux.org> | 2020-03-19 18:40:16 +0000 |
commit | 498f844615bad7a03a483bcb3322620f1e638e0b (patch) | |
tree | c3d345b1ab79bc9a7d8abc5d30ac520b82b69171 | |
parent | f501babfcffea72a6a5604ff4644444b0ad6aa5a (diff) | |
download | pam-498f844615bad7a03a483bcb3322620f1e638e0b.tar.gz pam-498f844615bad7a03a483bcb3322620f1e638e0b.tar.bz2 pam-498f844615bad7a03a483bcb3322620f1e638e0b.zip |
modules/pam_cracklib: use pam_str_skip_prefix
* modules/pam_cracklib/pam_cracklib.c: Include "pam_inline.h".
(_pam_parse): Use pam_str_skip_prefix instead of ugly strncmp
invocations.
-rw-r--r-- | modules/pam_cracklib/pam_cracklib.c | 58 |
1 files changed, 30 insertions, 28 deletions
diff --git a/modules/pam_cracklib/pam_cracklib.c b/modules/pam_cracklib/pam_cracklib.c index 488d3170..e87ff7d8 100644 --- a/modules/pam_cracklib/pam_cracklib.c +++ b/modules/pam_cracklib/pam_cracklib.c @@ -81,6 +81,7 @@ extern char *FascistCheck(char *pw, const char *dictpath); #include <security/pam_modules.h> #include <security/_pam_macros.h> #include <security/pam_ext.h> +#include "pam_inline.h" /* argument parsing */ #define PAM_DEBUG_ARG 0x0001 @@ -121,60 +122,61 @@ _pam_parse (pam_handle_t *pamh, struct cracklib_options *opt, /* step through arguments */ for (ctrl=0; argc-- > 0; ++argv) { + const char *str; char *ep = NULL; /* generic options */ if (!strcmp(*argv,"debug")) ctrl |= PAM_DEBUG_ARG; - else if (!strncmp(*argv,"type=",5)) - pam_set_item (pamh, PAM_AUTHTOK_TYPE, *argv+5); - else if (!strncmp(*argv,"retry=",6)) { - opt->retry_times = strtol(*argv+6,&ep,10); + else if ((str = pam_str_skip_prefix(*argv, "type=")) != NULL) + pam_set_item (pamh, PAM_AUTHTOK_TYPE, str); + else if ((str = pam_str_skip_prefix(*argv, "retry=")) != NULL) { + opt->retry_times = strtol(str, &ep, 10); if (!ep || (opt->retry_times < 1)) opt->retry_times = CO_RETRY_TIMES; - } else if (!strncmp(*argv,"difok=",6)) { - opt->diff_ok = strtol(*argv+6,&ep,10); + } else if ((str = pam_str_skip_prefix(*argv, "difok=")) != NULL) { + opt->diff_ok = strtol(str, &ep, 10); if (!ep || (opt->diff_ok < 0)) opt->diff_ok = CO_DIFF_OK; - } else if (!strncmp(*argv,"difignore=",10)) { + } else if (pam_str_skip_prefix(*argv, "difignore=") != NULL) { /* just ignore */ - } else if (!strncmp(*argv,"minlen=",7)) { - opt->min_length = strtol(*argv+7,&ep,10); + } else if ((str = pam_str_skip_prefix(*argv, "minlen=")) != NULL) { + opt->min_length = strtol(str, &ep, 10); if (!ep || (opt->min_length < CO_MIN_LENGTH_BASE)) opt->min_length = CO_MIN_LENGTH_BASE; - } else if (!strncmp(*argv,"dcredit=",8)) { - opt->dig_credit = strtol(*argv+8,&ep,10); + } else if ((str = pam_str_skip_prefix(*argv, "dcredit=")) != NULL) { + opt->dig_credit = strtol(str, &ep, 10); if (!ep) opt->dig_credit = 0; - } else if (!strncmp(*argv,"ucredit=",8)) { - opt->up_credit = strtol(*argv+8,&ep,10); + } else if ((str = pam_str_skip_prefix(*argv, "ucredit=")) != NULL) { + opt->up_credit = strtol(str, &ep, 10); if (!ep) opt->up_credit = 0; - } else if (!strncmp(*argv,"lcredit=",8)) { - opt->low_credit = strtol(*argv+8,&ep,10); + } else if ((str = pam_str_skip_prefix(*argv, "lcredit=")) != NULL) { + opt->low_credit = strtol(str, &ep, 10); if (!ep) opt->low_credit = 0; - } else if (!strncmp(*argv,"ocredit=",8)) { - opt->oth_credit = strtol(*argv+8,&ep,10); + } else if ((str = pam_str_skip_prefix(*argv, "ocredit=")) != NULL) { + opt->oth_credit = strtol(str, &ep, 10); if (!ep) opt->oth_credit = 0; - } else if (!strncmp(*argv,"minclass=",9)) { - opt->min_class = strtol(*argv+9,&ep,10); + } else if ((str = pam_str_skip_prefix(*argv, "minclass=")) != NULL) { + opt->min_class = strtol(str, &ep, 10); if (!ep) opt->min_class = 0; if (opt->min_class > 4) opt->min_class = 4; - } else if (!strncmp(*argv,"maxrepeat=",10)) { - opt->max_repeat = strtol(*argv+10,&ep,10); + } else if ((str = pam_str_skip_prefix(*argv, "maxrepeat=")) != NULL) { + opt->max_repeat = strtol(str, &ep, 10); if (!ep) opt->max_repeat = 0; - } else if (!strncmp(*argv,"maxsequence=",12)) { - opt->max_sequence = strtol(*argv+12,&ep,10); + } else if ((str = pam_str_skip_prefix(*argv, "maxsequence=")) != NULL) { + opt->max_sequence = strtol(str, &ep, 10); if (!ep) opt->max_sequence = 0; - } else if (!strncmp(*argv,"maxclassrepeat=",15)) { - opt->max_class_repeat = strtol(*argv+15,&ep,10); + } else if ((str = pam_str_skip_prefix(*argv, "maxclassrepeat=")) != NULL) { + opt->max_class_repeat = strtol(str, &ep, 10); if (!ep) opt->max_class_repeat = 0; } else if (!strcmp(*argv, "reject_username")) { @@ -183,7 +185,7 @@ _pam_parse (pam_handle_t *pamh, struct cracklib_options *opt, opt->gecos_check = 1; } else if (!strcmp(*argv, "enforce_for_root")) { opt->enforce_for_root = 1; - } else if (!strncmp(*argv,"authtok_type",12)) { + } else if (pam_str_skip_prefix(*argv, "authtok_type=") != NULL) { /* for pam_get_authtok, ignore */; } else if (!strcmp(*argv, "use_authtok")) { /* for pam_get_authtok, ignore */; @@ -191,8 +193,8 @@ _pam_parse (pam_handle_t *pamh, struct cracklib_options *opt, /* for pam_get_authtok, ignore */; } else if (!strcmp(*argv, "try_first_pass")) { /* for pam_get_authtok, ignore */; - } else if (!strncmp(*argv,"dictpath=",9)) { - opt->cracklib_dictpath = *argv+9; + } else if ((str = pam_str_skip_prefix(*argv, "dictpath=")) != NULL) { + opt->cracklib_dictpath = str; if (!*(opt->cracklib_dictpath)) { opt->cracklib_dictpath = CRACKLIB_DICTS; } |