diff options
author | Dmitry V. Levin <ldv@altlinux.org> | 2020-03-17 21:29:24 +0000 |
---|---|---|
committer | Dmitry V. Levin <ldv@altlinux.org> | 2020-03-19 18:40:16 +0000 |
commit | a61b015d85aca655ed355f7ebe94f6eb7b19a74b (patch) | |
tree | bc86f1ac16392a29bb543b77ecf4a14c143eda61 /modules/pam_umask | |
parent | 3130acba872c2645d2effa11cc80d1f6bfa59858 (diff) | |
download | pam-a61b015d85aca655ed355f7ebe94f6eb7b19a74b.tar.gz pam-a61b015d85aca655ed355f7ebe94f6eb7b19a74b.tar.bz2 pam-a61b015d85aca655ed355f7ebe94f6eb7b19a74b.zip |
modules/pam_umask: use pam_str_skip_icase_prefix
* modules/pam_umask/pam_umask.c: Include "pam_inline.h".
(parse_option, setup_limits_from_gecos): Use pam_str_skip_icase_prefix
instead of ugly strncasecmp invocations.
Diffstat (limited to 'modules/pam_umask')
-rw-r--r-- | modules/pam_umask/pam_umask.c | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/modules/pam_umask/pam_umask.c b/modules/pam_umask/pam_umask.c index 1446c6de..45b048e3 100644 --- a/modules/pam_umask/pam_umask.c +++ b/modules/pam_umask/pam_umask.c @@ -55,6 +55,7 @@ #include <security/pam_modules.h> #include <security/pam_modutil.h> #include <security/pam_ext.h> +#include "pam_inline.h" #define LOGIN_DEFS "/etc/login.defs" #define LOGIN_CONF "/etc/default/login" @@ -70,13 +71,15 @@ typedef struct options_t options_t; static void parse_option (const pam_handle_t *pamh, const char *argv, options_t *options) { + const char *str; + if (argv == NULL || argv[0] == '\0') return; if (strcasecmp (argv, "debug") == 0) options->debug = 1; - else if (strncasecmp (argv, "umask=", 6) == 0) - options->umask = strdup (&argv[6]); + else if ((str = pam_str_skip_icase_prefix (argv, "umask=")) != NULL) + options->umask = strdup (str); else if (strcasecmp (argv, "usergroups") == 0) options->usergroups = 1; else if (strcasecmp (argv, "nousergroups") == 0) @@ -149,25 +152,27 @@ setup_limits_from_gecos (pam_handle_t *pamh, options_t *options, /* See if the GECOS field contains values for NICE, UMASK or ULIMIT. */ for (cp = pw->pw_gecos; cp != NULL; cp = strchr (cp, ',')) { + const char *str; + if (*cp == ',') cp++; - if (strncasecmp (cp, "umask=", 6) == 0) - umask (strtol (cp + 6, NULL, 8) & 0777); - else if (strncasecmp (cp, "pri=", 4) == 0) + if ((str = pam_str_skip_icase_prefix (cp, "umask=")) != NULL) + umask (strtol (str, NULL, 8) & 0777); + else if ((str = pam_str_skip_icase_prefix (cp, "pri=")) != NULL) { errno = 0; - if (nice (strtol (cp + 4, NULL, 10)) == -1 && errno != 0) + if (nice (strtol (str, NULL, 10)) == -1 && errno != 0) { if (!options->silent || options->debug) pam_error (pamh, "nice failed: %m\n"); pam_syslog (pamh, LOG_ERR, "nice failed: %m"); } } - else if (strncasecmp (cp, "ulimit=", 7) == 0) + else if ((str = pam_str_skip_icase_prefix (cp, "ulimit=")) != NULL) { struct rlimit rlimit_fsize; - rlimit_fsize.rlim_cur = 512L * strtol (cp + 7, NULL, 10); + rlimit_fsize.rlim_cur = 512L * strtol (str, NULL, 10); rlimit_fsize.rlim_max = rlimit_fsize.rlim_cur; if (setrlimit (RLIMIT_FSIZE, &rlimit_fsize) == -1) { |