From: Aki Tuomi Date: Fri, 8 Nov 2024 06:55:37 +0000 (+0200) Subject: auth: userdb-passwd-file - Support iterating variable paths if variables are provided X-Git-Tag: 2.4.0~267 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3f0230d7eaf2e31d43f200746308ca933c7f0227;p=thirdparty%2Fdovecot%2Fcore.git 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. --- 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);