From a01372f36cfa5d2f2d75f54359d7243a140fffb6 Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Mon, 16 Mar 2020 21:02:18 +0000 Subject: modules/pam_tally2: use pam_str_skip_prefix * modules/pam_tally2/pam_tally2.c: Include "pam_inline.h". (tally_parse_args, getopts): Use pam_str_skip_prefix instead of ugly strncmp invocations. --- modules/pam_tally2/pam_tally2.c | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) (limited to 'modules/pam_tally2') diff --git a/modules/pam_tally2/pam_tally2.c b/modules/pam_tally2/pam_tally2.c index be13ffdd..6543991f 100644 --- a/modules/pam_tally2/pam_tally2.c +++ b/modules/pam_tally2/pam_tally2.c @@ -93,6 +93,7 @@ #endif #include #include +#include "pam_inline.h" /*---------------------------------------------------------------------*/ @@ -174,9 +175,10 @@ tally_parse_args(pam_handle_t *pamh, struct tally_options *opts, opts->root_unlock_time = -1; 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!='/' ) { pam_syslog(pamh, LOG_ERR, "filename not /rooted; %s", *argv); @@ -204,30 +206,30 @@ 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,"%hu",&opts->deny) != 1 ) { + if (sscanf(str, "%hu", &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; } } - else if ( ! strncmp( *argv, "root_unlock_time=", 17 ) ) { + else if ((str = pam_str_skip_prefix(*argv, "root_unlock_time=")) != NULL) { log_phase_no_auth(pamh, phase, *argv); - if ( sscanf((*argv)+17,"%ld",&opts->root_unlock_time) != 1 ) { + if (sscanf(str, "%ld", &opts->root_unlock_time) != 1) { pam_syslog(pamh, LOG_ERR, "bad number supplied: %s", *argv); return PAM_AUTH_ERR; } @@ -262,7 +264,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 @@ -868,16 +870,19 @@ getopts( char **argv ) { const char *pname = *argv; for ( ; *argv ; (void)(*argv && ++argv) ) { + const char *str; if ( !strcmp (*argv,"--file") ) cline_filename=*++argv; else if ( !strcmp(*argv,"-f") ) 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 ( !strcmp (*argv,"-u") ) 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 ( !strcmp (*argv,"-r") ) cline_reset=0; - else if ( !strncmp(*argv,"--reset=",8)) { - if ( sscanf(*argv+8,"%hu",&cline_reset) != 1 ) + else if ((str = pam_str_skip_prefix(*argv, "--reset=")) != NULL) { + if (sscanf(str, "%hu", &cline_reset) != 1) fprintf(stderr,_("%s: Bad number given to --reset=\n"),pname), exit(0); } else if ( !strcmp (*argv,"--quiet") ) cline_quiet=1; -- cgit v1.2.3