diff options
author | Dmitry V. Levin <ldv@altlinux.org> | 2020-03-16 21:02:18 +0000 |
---|---|---|
committer | Dmitry V. Levin <ldv@altlinux.org> | 2020-03-19 18:40:16 +0000 |
commit | 1e1d27de3d9cc68aa20c4df4ddf46965651359a7 (patch) | |
tree | 5886f0b7918f27f82530afa82203888232aaf52a | |
parent | a01372f36cfa5d2f2d75f54359d7243a140fffb6 (diff) | |
download | pam-1e1d27de3d9cc68aa20c4df4ddf46965651359a7.tar.gz pam-1e1d27de3d9cc68aa20c4df4ddf46965651359a7.tar.bz2 pam-1e1d27de3d9cc68aa20c4df4ddf46965651359a7.zip |
modules/pam_tally: use pam_str_skip_prefix
* modules/pam_tally/pam_tally.c: Include "pam_inline.h".
(tally_parse_args, getopts): Use pam_str_skip_prefix instead of ugly
strncmp invocations.
-rw-r--r-- | modules/pam_tally/pam_tally.c | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/modules/pam_tally/pam_tally.c b/modules/pam_tally/pam_tally.c index 2eea4c5b..cc221b87 100644 --- a/modules/pam_tally/pam_tally.c +++ b/modules/pam_tally/pam_tally.c @@ -47,6 +47,7 @@ #include <security/pam_ext.h> #endif #include <security/pam_modules.h> +#include "pam_inline.h" #ifndef TRUE #define TRUE 1L @@ -147,9 +148,10 @@ tally_parse_args(pam_handle_t *pamh, struct tally_options *opts, opts->filename = DEFAULT_LOGFILE; for ( ; argc-- > 0; ++argv ) { + const char *str; - if ( ! strncmp( *argv, "file=", 5 ) ) { - const char *from = *argv + 5; + if ((str = pam_str_skip_prefix(*argv, "file=")) != NULL) { + const char *from = str; if ( *from!='/' || strlen(from)>FILENAME_MAX-1 ) { pam_syslog(pamh, LOG_ERR, "filename not /rooted or too long; %s", *argv); @@ -170,23 +172,23 @@ tally_parse_args(pam_handle_t *pamh, struct tally_options *opts, log_phase_no_auth(pamh, phase, *argv); opts->ctrl |= OPT_DENY_ROOT; } - else if ( ! strncmp( *argv, "deny=", 5 ) ) { + else if ((str = pam_str_skip_prefix(*argv, "deny=")) != NULL) { log_phase_no_auth(pamh, phase, *argv); - if ( sscanf((*argv)+5,TALLY_FMT,&opts->deny) != 1 ) { + if (sscanf(str, TALLY_FMT, &opts->deny) != 1) { pam_syslog(pamh, LOG_ERR, "bad number supplied: %s", *argv); return PAM_AUTH_ERR; } } - else if ( ! strncmp( *argv, "lock_time=", 10 ) ) { + else if ((str = pam_str_skip_prefix(*argv, "lock_time=")) != NULL) { log_phase_no_auth(pamh, phase, *argv); - if ( sscanf((*argv)+10,"%ld",&opts->lock_time) != 1 ) { + if (sscanf(str, "%ld", &opts->lock_time) != 1) { pam_syslog(pamh, LOG_ERR, "bad number supplied: %s", *argv); return PAM_AUTH_ERR; } } - else if ( ! strncmp( *argv, "unlock_time=", 12 ) ) { + else if ((str = pam_str_skip_prefix(*argv, "unlock_time=")) != NULL) { log_phase_no_auth(pamh, phase, *argv); - if ( sscanf((*argv)+12,"%ld",&opts->unlock_time) != 1 ) { + if (sscanf(str, "%ld", &opts->unlock_time) != 1) { pam_syslog(pamh, LOG_ERR, "bad number supplied: %s", *argv); return PAM_AUTH_ERR; } @@ -229,7 +231,7 @@ tally_parse_args(pam_handle_t *pamh, struct tally_options *opts, cline_user --- */ #ifdef MAIN -static char *cline_user=0; /* cline_user is used in the administration prog */ +static const char *cline_user=0; /* cline_user is used in the administration prog */ #endif static int @@ -759,13 +761,16 @@ getopts( char **argv ) { const char *pname = *argv; for ( ; *argv ; (void)(*argv && ++argv) ) { + const char *str; if ( !strcmp (*argv,"--file") ) cline_filename=*++argv; - else if ( !strncmp(*argv,"--file=",7) ) cline_filename=*argv+7; + else if ((str = pam_str_skip_prefix(*argv, "--file=")) != NULL) + cline_filename = str; else if ( !strcmp (*argv,"--user") ) cline_user=*++argv; - else if ( !strncmp(*argv,"--user=",7) ) cline_user=*argv+7; + else if ((str = pam_str_skip_prefix(*argv, "--user=")) != NULL) + cline_user = str; else if ( !strcmp (*argv,"--reset") ) cline_reset=0; - else if ( !strncmp(*argv,"--reset=",8)) { - if ( sscanf(*argv+8,TALLY_FMT,&cline_reset) != 1 ) + else if ((str = pam_str_skip_prefix(*argv, "--reset=")) != NULL) { + if (sscanf(str, TALLY_FMT, &cline_reset) != 1 ) fprintf(stderr,_("%s: Bad number given to --reset=\n"),pname), exit(0); } else if ( !strcmp (*argv,"--quiet") ) cline_quiet=1; |