From 3f0230d7eaf2e31d43f200746308ca933c7f0227 Mon Sep 17 00:00:00 2001 From: Aki Tuomi Date: Fri, 8 Nov 2024 08:55:37 +0200 Subject: [PATCH] auth: userdb-passwd-file - Support iterating variable paths if variables are provided This still does not fix '*', but at least it can list users if you provide domain. --- src/auth/userdb-passwd-file.c | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/src/auth/userdb-passwd-file.c b/src/auth/userdb-passwd-file.c index bbf06d38bc..1f91b209a4 100644 --- a/src/auth/userdb-passwd-file.c +++ b/src/auth/userdb-passwd-file.c @@ -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, ¶ms, + &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); -- 2.47.3