From: shumikhinaka Date: Tue, 30 Jun 2026 19:51:34 +0000 (+0400) Subject: pam_winbind: fix partial configuration argument matching X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5bc9de27802120bfd405bc66d496dbd7b3ab4d66;p=thirdparty%2Fsamba.git pam_winbind: fix partial configuration argument matching get_config_item_int and get_conf_item_string function used strncmp to check command line arguments, but didn't verify the trailing character. This allowed partial prefix matches (e.g., matching "itemXYZ=value" when looking for "item"). Refactored lookup-logic to ensure correct parsing. Pair-Programmed-With: Dmitry Mikhalchenko Signed-off-by: Shumikhina Ksenia Reviewed-by: Anoop C S Reviewed-by: Volker Lendecke Autobuild-User(master): Volker Lendecke Autobuild-Date(master): Wed Jul 1 09:30:23 UTC 2026 on atb-devel-224 --- diff --git a/nsswitch/pam_winbind.c b/nsswitch/pam_winbind.c index cb9edb4bc7b..9f305144f1b 100644 --- a/nsswitch/pam_winbind.c +++ b/nsswitch/pam_winbind.c @@ -2325,21 +2325,29 @@ static const char *get_conf_item_string(struct pwb_context *ctx, } /* let the pam opt take precedence over the pam_winbind.conf option */ - for (i=0; iargc; i++) { + for (i = 0; i < ctx->argc; i++) { + const char *p = strchr(ctx->argv[i], '='); + if (p != NULL) { + size_t len = p - ctx->argv[i]; + char name[len + 1]; - if ((strncmp(ctx->argv[i], item, strlen(item)) == 0)) { - const char *p; + memcpy(name, ctx->argv[i], len); + name[len] = 0; - if ((p = strchr(ctx->argv[i], '=')) == NULL) { - _pam_log(ctx, LOG_INFO, - "no \"=\" delimiter for \"%s\" found\n", - item); - goto out; + if (strcmp(name, item) != 0) { + continue; } _pam_log_debug(ctx, LOG_INFO, - "PAM config: %s '%s'\n", item, p+1); + "PAM config: %s '%s'\n", + item, p + 1); return p + 1; } + if (strcmp(ctx->argv[i], item) == 0) { + _pam_log(ctx, LOG_INFO, + "no \"=\" delimiter for \"%s\" found\n", + item); + goto out; + } } if (ctx->dict) { @@ -2364,49 +2372,14 @@ static int get_config_item_int(struct pwb_context *ctx, const char *item, int config_flag) { - int i, parm_opt = -1; - - if (!(ctx->ctrl & config_flag)) { - goto out; - } - - /* let the pam opt take precedence over the pam_winbind.conf option */ - for (i = 0; i < ctx->argc; i++) { + const char *value; - if ((strncmp(ctx->argv[i], item, strlen(item)) == 0)) { - const char *p; - - if ((p = strchr(ctx->argv[i], '=')) == NULL) { - _pam_log(ctx, LOG_INFO, - "no \"=\" delimiter for \"%s\" found\n", - item); - goto out; - } - parm_opt = atoi(p + 1); - _pam_log_debug(ctx, LOG_INFO, - "PAM config: %s '%d'\n", - item, parm_opt); - return parm_opt; - } + value = get_conf_item_string(ctx, item, config_flag); + if (value == NULL) { + return -1; } - if (ctx->dict) { - char *key = NULL; - - key = talloc_asprintf(ctx, "global:%s", item); - if (!key) { - goto out; - } - - parm_opt = tiniparser_getint(ctx->dict, key, -1); - TALLOC_FREE(key); - - _pam_log_debug(ctx, LOG_INFO, - "CONFIG file: %s '%d'\n", - item, parm_opt); - } -out: - return parm_opt; + return atoi(value); } static const char *get_krb5_cc_type_from_config(struct pwb_context *ctx)