* modules/pam_userdb/pam_userdb.c: Include "pam_inline.h".
(_pam_parse, user_lookup): Use pam_str_skip_icase_prefix
instead of ugly strncasecmp invocations.
---
modules/pam_userdb/pam_userdb.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/modules/pam_userdb/pam_userdb.c b/modules/pam_userdb/pam_userdb.c
index cab37b30..df171f6e 100644
--- a/modules/pam_userdb/pam_userdb.c
+++ b/modules/pam_userdb/pam_userdb.c
@@ -50,6 +50,7 @@
#include <security/pam_modules.h>
#include <security/pam_ext.h>
#include <security/_pam_macros.h>
+#include "pam_inline.h"
/*
* Conversation function to obtain the user's password
@@ -97,6 +98,8 @@ _pam_parse (pam_handle_t *pamh, int argc, const char **argv,
/* step through arguments */
for (ctrl = 0; argc-- > 0; ++argv)
{
+ const char *str;
+
/* generic options */
if (!strcmp(*argv,"debug"))
@@ -113,18 +116,18 @@ _pam_parse (pam_handle_t *pamh, int argc, const char **argv,
ctrl |= PAM_USE_FPASS_ARG;
else if (!strcasecmp(*argv, "try_first_pass"))
ctrl |= PAM_TRY_FPASS_ARG;
- else if (!strncasecmp(*argv,"db=", 3))
+ else if ((str = pam_str_skip_icase_prefix(*argv, "db=")))
{
- *database = (*argv) + 3;
+ *database = str;
if (**database == '\0') {
*database = NULL;
pam_syslog(pamh, LOG_ERR,
"db= specification missing argument - ignored");
}
}
- else if (!strncasecmp(*argv,"crypt=", 6))
+ else if ((str = pam_str_skip_icase_prefix(*argv, "crypt=")))
{
- *cryptmode = (*argv) + 6;
+ *cryptmode = str;
if (**cryptmode == '\0')
pam_syslog(pamh, LOG_ERR,
"crypt= specification missing argument - ignored");
@@ -209,7 +212,7 @@ user_lookup (pam_handle_t *pamh, const char *database, const char
*cryptmode,
return 0; /* found it, data contents don't matter */
}
- if (cryptmode && strncasecmp(cryptmode, "crypt", 5) == 0) {
+ if (cryptmode && pam_str_skip_icase_prefix(cryptmode, "crypt")) {
/* crypt(3) password storage */
@@ -260,7 +263,7 @@ user_lookup (pam_handle_t *pamh, const char *database, const char
*cryptmode,
compare = strncmp(data.dptr, pass, data.dsize);
}
- if (cryptmode && strncasecmp(cryptmode, "none", 4)
+ if (cryptmode && !pam_str_skip_icase_prefix(cryptmode, "none")
&& (ctrl & PAM_DEBUG_ARG)) {
pam_syslog(pamh, LOG_INFO, "invalid value for crypt parameter: %s",
cryptmode);
--
ldv