]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
pam_winbind: fix partial configuration argument matching
authorshumikhinaka <shumikhinaka@sgu.ru>
Tue, 30 Jun 2026 19:51:34 +0000 (23:51 +0400)
committerVolker Lendecke <vl@samba.org>
Wed, 1 Jul 2026 09:30:23 +0000 (09:30 +0000)
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 <tascad@altlinux.org>
Signed-off-by: Shumikhina Ksenia <shumikhinaka@sgu.ru>
Reviewed-by: Anoop C S <anoopcs@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
Autobuild-User(master): Volker Lendecke <vl@samba.org>
Autobuild-Date(master): Wed Jul  1 09:30:23 UTC 2026 on atb-devel-224

nsswitch/pam_winbind.c

index cb9edb4bc7b3aa5bff3cc11d7b798edf7cce58e7..9f305144f1bd81176cc18a280b6d8a5772f8517c 100644 (file)
@@ -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; i<ctx->argc; 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)