From: Timo Sirainen Date: Sun, 13 Nov 2022 15:18:47 +0000 (+0200) Subject: lib-storage, global: Change mail_user_init() to expand all settings automatically... X-Git-Tag: 2.4.0~3335 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4dd07fac4e5d308d2777562f0013ca2c8c2a7f58;p=thirdparty%2Fdovecot%2Fcore.git lib-storage, global: Change mail_user_init() to expand all settings automatically (2/3) The callers must no longer expand the settings again. --- diff --git a/src/imap-urlauth/imap-urlauth-worker.c b/src/imap-urlauth/imap-urlauth-worker.c index 5124fe2f4d..9b31c61703 100644 --- a/src/imap-urlauth/imap-urlauth-worker.c +++ b/src/imap-urlauth/imap-urlauth-worker.c @@ -590,13 +590,6 @@ client_handle_user_command(struct client *client, const char *cmd, set = settings_parser_get_root_set(mail_user->set_parser, &imap_urlauth_worker_setting_parser_info); - if (mail_user_var_expand(mail_user, &imap_urlauth_worker_setting_parser_info, - set, &error) <= 0) { - client_send_line(client, "NO"); - client_abort(client, t_strdup_printf( - "Session aborted: Failed to expand settings: %s", error)); - return 0; - } if (set->verbose_proctitle) { verbose_proctitle = TRUE; diff --git a/src/imap/main.c b/src/imap/main.c index 3086b7096d..2e68a4fe56 100644 --- a/src/imap/main.c +++ b/src/imap/main.c @@ -248,7 +248,6 @@ int client_create_from_input(const struct mail_storage_service_input *input, struct imap_settings *imap_set; struct smtp_submit_settings *smtp_set; struct event *event; - const char *errstr; event = event_create(NULL); event_add_category(event, &event_category_imap); @@ -285,17 +284,6 @@ int client_create_from_input(const struct mail_storage_service_input *input, if (imap_set->verbose_proctitle) verbose_proctitle = TRUE; - if (mail_user_var_expand(mail_user, &smtp_submit_setting_parser_info, - smtp_set, &errstr) <= 0 || - mail_user_var_expand(mail_user, &imap_setting_parser_info, - imap_set, &errstr) <= 0) { - *error_r = t_strdup_printf("Failed to expand settings: %s", errstr); - mail_user_deinit(&mail_user); - mail_storage_service_user_unref(&user); - event_unref(&event); - return -1; - } - client = client_create(fd_in, fd_out, unhibernated, event, mail_user, user, imap_set, smtp_set); client->userdb_fields = input->userdb_fields == NULL ? NULL : diff --git a/src/lda/main.c b/src/lda/main.c index 450b7876bc..0dc90587cb 100644 --- a/src/lda/main.c +++ b/src/lda/main.c @@ -284,26 +284,12 @@ lda_deliver(struct mail_deliver_input *dinput, bool stderr_rejection) { struct mail_deliver_context ctx; - struct lda_settings *lda_set; - struct smtp_submit_settings *smtp_set; - const char *errstr; int ret; - lda_set = settings_parser_get_root_set(dinput->rcpt_user->set_parser, + dinput->set = settings_parser_get_root_set(dinput->rcpt_user->set_parser, &lda_setting_parser_info); - smtp_set = settings_parser_get_root_set(dinput->rcpt_user->set_parser, - &smtp_submit_setting_parser_info); - ret = mail_user_var_expand(dinput->rcpt_user, &lda_setting_parser_info, - lda_set, &errstr); - if (ret > 0) { - ret = mail_user_var_expand(dinput->rcpt_user, - &smtp_submit_setting_parser_info, - smtp_set, &errstr); - } - if (ret <= 0) - i_fatal("Failed to expand settings: %s", errstr); - dinput->set = lda_set; - dinput->smtp_set = smtp_set; + dinput->smtp_set = settings_parser_get_root_set(dinput->rcpt_user->set_parser, + &smtp_submit_setting_parser_info); dinput->src_mail = lda_raw_mail_open(dinput, path); lda_set_rcpt_to(dinput, rcpt_to, user, rcpt_to_source); diff --git a/src/lib-storage/mail-user.c b/src/lib-storage/mail-user.c index a355b8f0b9..88a10c97b0 100644 --- a/src/lib-storage/mail-user.c +++ b/src/lib-storage/mail-user.c @@ -170,11 +170,24 @@ int mail_user_init(struct mail_user *user, const char **error_r) i_assert(!user->initialized); - if (mail_user_var_expand(user, user->set_info, user->set, - &error) <= 0) { - user->error = p_strdup_printf(user->pool, - "Failed to expand settings: %s", error); + struct mail_storage_service_ctx *service_ctx = + user->_service_user != NULL ? + mail_storage_service_user_get_service_ctx(user->_service_user) : + mail_storage_service_get_global(); + const struct setting_parser_info *const *set_roots = + mail_storage_service_get_set_roots(service_ctx); + for (unsigned int i = 0; set_roots[i] != NULL; i++) { + if (user->error != NULL) + break; + + void *set = settings_parser_get_root_set(user->set_parser, set_roots[i]); + if (mail_user_var_expand(user, set_roots[i], set, &error) <= 0) { + user->error = p_strdup_printf(user->pool, + "Failed to expand settings: %s", error); + break; + } } + user->settings_expanded = TRUE; mail_user_expand_plugins_envs(user); diff --git a/src/lmtp/lmtp-local.c b/src/lmtp/lmtp-local.c index ca3c5e5727..fbf1576d5f 100644 --- a/src/lmtp/lmtp-local.c +++ b/src/lmtp/lmtp-local.c @@ -419,9 +419,7 @@ lmtp_local_deliver(struct lmtp_local *local, struct mail_user *rcpt_user; const struct mail_storage_service_input *input; const struct mail_storage_settings *mail_set; - struct smtp_submit_settings *smtp_set; struct smtp_proxy_data proxy_data; - struct lda_settings *lda_set; struct mail_namespace *ns; struct setting_parser_context *set_parser; const char *line, *error, *username; @@ -468,31 +466,16 @@ lmtp_local_deliver(struct lmtp_local *local, } local->rcpt_user = rcpt_user; - smtp_set = settings_parser_get_root_set(rcpt_user->set_parser, - &smtp_submit_setting_parser_info); - lda_set = settings_parser_get_root_set(rcpt_user->set_parser, - &lda_setting_parser_info); - ret = mail_user_var_expand(rcpt_user, &smtp_submit_setting_parser_info, - smtp_set, &error); - if (ret > 0) { - ret = mail_user_var_expand(rcpt_user, &lda_setting_parser_info, - lda_set, &error); - } - if (ret <= 0) { - e_error(rcpt->event, "Failed to expand settings: %s", error); - smtp_server_recipient_reply(rcpt, 451, "4.3.0", - "Temporary internal error"); - return -1; - } - /* Set the log prefix for the user. The default log prefix is automatically restored later when user context gets deactivated. */ i_set_failure_prefix("%s", mail_storage_service_user_get_log_prefix(service_user)); lldctx.rcpt_user = rcpt_user; - lldctx.smtp_set = smtp_set; - lldctx.lda_set = lda_set; + lldctx.smtp_set = settings_parser_get_root_set(rcpt_user->set_parser, + &smtp_submit_setting_parser_info); + lldctx.lda_set = settings_parser_get_root_set(rcpt_user->set_parser, + &lda_setting_parser_info); if (*lrcpt->detail == '\0' || !client->lmtp_set->lmtp_save_to_detail_mailbox) diff --git a/src/pop3/main.c b/src/pop3/main.c index 56ff186262..1df8950ce9 100644 --- a/src/pop3/main.c +++ b/src/pop3/main.c @@ -119,7 +119,6 @@ client_create_from_input(const struct mail_storage_service_input *input, struct mail_storage_service_user *user; struct mail_user *mail_user; struct pop3_settings *set; - const char *errstr; struct event *event = event_create(NULL); event_add_category(event, &event_category_pop3); @@ -153,14 +152,6 @@ client_create_from_input(const struct mail_storage_service_input *input, if (set->verbose_proctitle) verbose_proctitle = TRUE; - if (mail_user_var_expand(mail_user, &pop3_setting_parser_info, set, - &errstr) <= 0) { - *error_r = t_strdup_printf("Failed to expand settings: %s", errstr); - mail_user_deinit(&mail_user); - mail_storage_service_user_unref(&user); - return -1; - } - *client_r = client_create(fd_in, fd_out, event, mail_user, user, set); event_unref(&event); return 0; diff --git a/src/submission/main.c b/src/submission/main.c index 9426c92d71..d138a0e48b 100644 --- a/src/submission/main.c +++ b/src/submission/main.c @@ -156,7 +156,6 @@ client_create_from_input(const struct mail_storage_service_input *input, bool no_greeting = HAS_ALL_BITS(login_flags, LOGIN_REQUEST_FLAG_IMPLICIT); struct event *event; - const char *errstr; const char *helo = NULL; struct smtp_proxy_data proxy_data; const unsigned char *data; @@ -197,17 +196,6 @@ client_create_from_input(const struct mail_storage_service_input *input, if (set->verbose_proctitle) verbose_proctitle = TRUE; - if (mail_user_var_expand(mail_user, &submission_setting_parser_info, - set, &errstr) <= 0) { - *error_r = t_strdup_printf("Failed to expand settings: %s", errstr); - send_error(fd_out, event, set->hostname, - "4.3.5", MAIL_ERRSTR_CRITICAL_MSG); - mail_user_deinit(&mail_user); - mail_storage_service_user_unref(&user); - event_unref(&event); - return -1; - } - if (set->submission_relay_host == NULL || *set->submission_relay_host == '\0') { *error_r = "No relay host configured for submission proxy "