]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
auth: userdb-passwd-file - Support iterating variable paths if variables are provided
authorAki Tuomi <aki.tuomi@open-xchange.com>
Fri, 8 Nov 2024 06:55:37 +0000 (08:55 +0200)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Fri, 17 Jan 2025 08:40:00 +0000 (10:40 +0200)
This still does not fix '*', but at least it can list users if you
provide domain.

src/auth/userdb-passwd-file.c

index bbf06d38bc2ac1994d9a0f2ba1818f697ce97500..1f91b209a493f32011979a48b3df46cadfb02920 100644 (file)
@@ -143,13 +143,34 @@ passwd_file_iterate_init(struct auth_request *auth_request,
        ctx->ctx.context = context;
        ctx->skip_passdb_entries = !module->pwf->userdb_warn_missing;
        if (module->pwf->default_file == NULL) {
-               e_error(authdb_event(auth_request),
-                       "passwd-file: User iteration isn't currently supported "
-                       "with %%variable paths");
-               ctx->ctx.failed = TRUE;
-               return &ctx->ctx;
+               const struct var_expand_params params = {
+                       .table = auth_request_get_var_expand_table(auth_request),
+                       .providers = auth_request_var_expand_providers,
+                       .context = auth_request,
+                       .event = authdb_event(auth_request),
+               };
+               const char *error;
+               string_t *dest = t_str_new(32);
+               if (var_expand_program_execute(dest, module->pwf->prog, &params,
+                                              &error) < 0) {
+                       e_error(authdb_event(auth_request),
+                               "passwd-file: User iteration failed: "
+                               "Cannot expand '%s': %s", module->pwf->path, error);
+                       ctx->ctx.failed = TRUE;
+                       return &ctx->ctx;
+               }
+               const char *path;
+               if (db_passwd_fix_path(str_c(dest), &path, module->pwf->path, &error) < 0) {
+                       e_error(authdb_event(auth_request),
+                               "passwd-file: User iteration failed: "
+                               "Cannot normalize '%s': %s", str_c(dest), error);
+                       ctx->ctx.failed = TRUE;
+                       return &ctx->ctx;
+               }
+               ctx->path = i_strdup(path);
+       } else {
+               ctx->path = i_strdup(module->pwf->default_file->path);
        }
-       ctx->path = i_strdup(module->pwf->default_file->path);
 
        /* for now we support only a single passwd-file */
        fd = open(ctx->path, O_RDONLY);