]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
auth: Support expanding variables for passdb/userdb settings
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Wed, 17 Jan 2024 21:45:26 +0000 (16:45 -0500)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Wed, 12 Feb 2025 10:34:11 +0000 (12:34 +0200)
src/auth/auth-request-var-expand.c
src/auth/auth-request-var-expand.h
src/auth/auth-request.c

index 85b3d62a378ddb6c2074a4e734a809dd9bdbe6bc..7dbf439fd9fe3cdf7a1f2739c63911241de905eb 100644 (file)
@@ -3,6 +3,7 @@
 #include "auth-common.h"
 #include "str.h"
 #include "strescape.h"
+#include "settings.h"
 #include "auth-request.h"
 
 struct auth_request_var_expand_ctx {
@@ -308,3 +309,29 @@ int t_auth_request_var_expand(const char *str,
        *value_r = str_c(dest);
        return ret;
 }
+
+static void
+auth_request_event_var_expand_callback(struct event *event,
+       const struct var_expand_table **tab_r,
+       const struct var_expand_func_table **func_tab_r)
+{
+       struct auth_request_var_expand_ctx *ctx =
+               event_get_ptr(event, SETTINGS_EVENT_VAR_EXPAND_FUNC_CONTEXT);
+
+       *tab_r = auth_request_get_var_expand_table(ctx->auth_request,
+                                                  ctx->escape_func);
+       *func_tab_r = auth_request_var_funcs_table;
+}
+
+void auth_request_event_set_var_expand(struct auth_request *auth_request)
+{
+       struct auth_request_var_expand_ctx *ctx =
+               p_new(auth_request->pool, struct auth_request_var_expand_ctx, 1);
+       ctx->auth_request = auth_request;
+       ctx->escape_func = escape_none;
+
+       event_set_ptr(auth_request->event, SETTINGS_EVENT_VAR_EXPAND_CALLBACK,
+                     auth_request_event_var_expand_callback);
+       event_set_ptr(auth_request->event,
+                     SETTINGS_EVENT_VAR_EXPAND_FUNC_CONTEXT, ctx);
+}
index 0c2897c37dfedbdbc730d380a7e1d955de4c57e6..ab34b3143ca21558178f44386acb8ada368b8f02 100644 (file)
@@ -41,4 +41,6 @@ int t_auth_request_var_expand(const char *str,
 const char *auth_request_str_escape(const char *string,
                                    const struct auth_request *request);
 
+void auth_request_event_set_var_expand(struct auth_request *auth_request);
+
 #endif
index 8e06ce3edab475c247b2e212e5be777c1e1797fc..5c7fba1f862672685a882f2880ebc9b1f2c62d76 100644 (file)
@@ -146,6 +146,7 @@ auth_request_post_alloc_init(struct auth_request *request,
        event_add_category(request->event, &event_category_auth);
        event_set_log_prefix_callback(request->event, TRUE,
                                      get_log_prefix, request);
+       auth_request_event_set_var_expand(request);
 
        p_array_init(&request->authdb_event, request->pool, 2);
 }