From: Timo Sirainen Date: Sun, 27 Feb 2022 14:51:58 +0000 (+0100) Subject: lib-storage: Add mail_user.[unexpanded_]set_parser X-Git-Tag: 2.4.0~3348 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e20c5c67fc01c80dd48bfc8efe15c212b725d46e;p=thirdparty%2Fdovecot%2Fcore.git lib-storage: Add mail_user.[unexpanded_]set_parser The original parser stays unexpanded, while a duplicate parser will be used for expanding settings. Also, since the whole parser is duplicated, there's no need to anymore duplicate the settings structs themselves. --- diff --git a/src/lda/main.c b/src/lda/main.c index e76d7fc284..7e4d8fffe9 100644 --- a/src/lda/main.c +++ b/src/lda/main.c @@ -156,7 +156,8 @@ lda_raw_mail_open(struct mail_deliver_input *dinput, const char *path) user_set = master_service_settings_get_root_set(master_service, &mail_user_setting_parser_info); - raw_mail_user = raw_storage_create_from_set(dinput->rcpt_user->set_info, + raw_mail_user = raw_storage_create_from_set(dinput->rcpt_user->unexpanded_set_parser, + dinput->rcpt_user->set_info, user_set); mail_from = (dinput->mail_from != NULL ? diff --git a/src/lib-storage/index/raw/raw-storage.c b/src/lib-storage/index/raw/raw-storage.c index a8d9f00920..085990cdcd 100644 --- a/src/lib-storage/index/raw/raw-storage.c +++ b/src/lib-storage/index/raw/raw-storage.c @@ -13,7 +13,8 @@ extern struct mail_storage raw_storage; extern struct mailbox raw_mailbox; struct mail_user * -raw_storage_create_from_set(const struct setting_parser_info *set_info, +raw_storage_create_from_set(const struct setting_parser_context *unexpanded_set_parser, + const struct setting_parser_info *set_info, const struct mail_user_settings *set) { struct mail_user *user; @@ -27,7 +28,7 @@ raw_storage_create_from_set(const struct setting_parser_info *set_info, /* Don't include raw user's events in statistics or anything else. They would just cause confusion. */ event_disable_callbacks(event); - user = mail_user_alloc(event, "raw mail user", set_info, set); + user = mail_user_alloc(event, "raw mail user", unexpanded_set_parser, set_info, set); event_unref(&event); user->autocreated = TRUE; diff --git a/src/lib-storage/index/raw/raw-storage.h b/src/lib-storage/index/raw/raw-storage.h index 124ca7ed0e..4591dadcfd 100644 --- a/src/lib-storage/index/raw/raw-storage.h +++ b/src/lib-storage/index/raw/raw-storage.h @@ -3,6 +3,8 @@ #include "index-storage.h" +struct setting_parser_context; + #define RAW_STORAGE_NAME "raw" #define RAW_SUBSCRIPTION_FILE_NAME "subscriptions" @@ -28,7 +30,8 @@ struct raw_mailbox { extern struct mail_vfuncs raw_mail_vfuncs; struct mail_user * -raw_storage_create_from_set(const struct setting_parser_info *set_info, +raw_storage_create_from_set(const struct setting_parser_context *unexpanded_set_parser, + const struct setting_parser_info *set_info, const struct mail_user_settings *set); int raw_mailbox_alloc_stream(struct mail_user *user, struct istream *input, diff --git a/src/lib-storage/index/shared/shared-storage.c b/src/lib-storage/index/shared/shared-storage.c index 978949eeb8..b805569fcf 100644 --- a/src/lib-storage/index/shared/shared-storage.c +++ b/src/lib-storage/index/shared/shared-storage.c @@ -249,7 +249,8 @@ int shared_storage_get_namespace(struct mail_namespace **_ns, } owner = mail_user_alloc(event_get_parent(user->event), userdomain, - user->set_info, user->unexpanded_set); + user->unexpanded_set_parser, user->set_info, + user->unexpanded_set); owner->_service_user = user->_service_user; mail_storage_service_user_ref(owner->_service_user); owner->creator = user; diff --git a/src/lib-storage/mail-storage-service.c b/src/lib-storage/mail-storage-service.c index c0bdf0e897..95e27ec8fa 100644 --- a/src/lib-storage/mail-storage-service.c +++ b/src/lib-storage/mail-storage-service.c @@ -685,7 +685,8 @@ mail_storage_service_init_post(struct mail_storage_service_ctx *ctx, /* NOTE: if more user initialization is added, add it also to mail_user_dup() */ mail_user = mail_user_alloc_nodup_set(user->event, user->input.username, - user->user_info, user->user_set); + user->set_parser, user->user_info, + user->user_set); mail_user->_service_user = user; mail_storage_service_user_ref(user); mail_user_set_home(mail_user, *home == '\0' ? NULL : home); diff --git a/src/lib-storage/mail-user.c b/src/lib-storage/mail-user.c index 7f22aaef1a..766e63efb4 100644 --- a/src/lib-storage/mail-user.c +++ b/src/lib-storage/mail-user.c @@ -51,6 +51,7 @@ static void mail_user_deinit_pre_base(struct mail_user *user ATTR_UNUSED) static struct mail_user * mail_user_alloc_int(struct event *parent_event, const char *username, + const struct setting_parser_context *unexpanded_set_parser, const struct setting_parser_info *set_info, const struct mail_user_settings *set, pool_t pool) { @@ -64,9 +65,12 @@ mail_user_alloc_int(struct event *parent_event, user->pool = pool; user->refcount = 1; user->username = p_strdup(pool, username); + user->unexpanded_set_parser = unexpanded_set_parser; + user->set_parser = settings_parser_dup(unexpanded_set_parser, pool); user->set_info = set_info; user->unexpanded_set = set; - user->set = settings_dup_with_pointers(set_info, user->unexpanded_set, pool); + user->set = settings_parser_get_root_set(user->set_parser, + &mail_user_setting_parser_info); user->service = master_service_get_name(master_service); user->default_normalizer = uni_utf8_to_decomposed_titlecase; user->session_create_time = ioloop_time; @@ -88,24 +92,29 @@ mail_user_alloc_int(struct event *parent_event, struct mail_user * mail_user_alloc_nodup_set(struct event *parent_event, const char *username, + const struct setting_parser_context *unexpanded_set_parser, const struct setting_parser_info *set_info, const struct mail_user_settings *set) { pool_t pool; pool = pool_alloconly_create(MEMPOOL_GROWING"mail user", 16*1024); - return mail_user_alloc_int(parent_event, username, set_info, set, pool); + return mail_user_alloc_int(parent_event, username, + unexpanded_set_parser, set_info, set, pool); } struct mail_user *mail_user_alloc(struct event *parent_event, const char *username, + const struct setting_parser_context *unexpanded_set_parser, const struct setting_parser_info *set_info, const struct mail_user_settings *set) { pool_t pool; pool = pool_alloconly_create(MEMPOOL_GROWING"mail user", 16*1024); - return mail_user_alloc_int(parent_event, username, set_info, + return mail_user_alloc_int(parent_event, username, + settings_parser_dup(unexpanded_set_parser, pool), + set_info, settings_dup(set_info, set, pool), pool); } @@ -747,7 +756,8 @@ struct mail_user *mail_user_dup(struct mail_user *user) struct mail_user *user2; user2 = mail_user_alloc(event_get_parent(user->event), user->username, - user->set_info, user->unexpanded_set); + user->unexpanded_set_parser, user->set_info, + user->unexpanded_set); if (user2->_service_user != NULL) { user2->_service_user = user->_service_user; mail_storage_service_user_ref(user2->_service_user); diff --git a/src/lib-storage/mail-user.h b/src/lib-storage/mail-user.h index cc9efbeff9..15cf198c54 100644 --- a/src/lib-storage/mail-user.h +++ b/src/lib-storage/mail-user.h @@ -58,6 +58,8 @@ struct mail_user { This could be set by plugins that need to fail the initialization. */ const char *error; + const struct setting_parser_context *unexpanded_set_parser; + const struct setting_parser_context *set_parser; const struct setting_parser_info *set_info; const struct mail_user_settings *unexpanded_set; struct mail_user_settings *set; @@ -128,11 +130,13 @@ extern const struct var_expand_func_table *mail_user_var_expand_func_table; struct mail_user *mail_user_alloc(struct event *parent_event, const char *username, + const struct setting_parser_context *unexpanded_set_parser, const struct setting_parser_info *set_info, const struct mail_user_settings *set); struct mail_user * mail_user_alloc_nodup_set(struct event *parent_event, const char *username, + const struct setting_parser_context *set_parser, const struct setting_parser_info *set_info, const struct mail_user_settings *set); /* Returns -1 if settings were invalid. */ diff --git a/src/lmtp/lmtp-client.c b/src/lmtp/lmtp-client.c index 7e11997098..4b2970e0ed 100644 --- a/src/lmtp/lmtp-client.c +++ b/src/lmtp/lmtp-client.c @@ -97,14 +97,17 @@ static void client_load_modules(struct client *client) module_dir_init(mail_storage_service_modules); } -static void client_raw_user_create(struct client *client) +static void +client_raw_user_create(struct client *client, + const struct setting_parser_context *set_parser) { const struct mail_user_settings *user_set; user_set = master_service_settings_get_root_set(master_service, &mail_user_setting_parser_info); client->raw_mail_user = - raw_storage_create_from_set(client->user_set_info, user_set); + raw_storage_create_from_set(set_parser, + client->user_set_info, user_set); } static void client_read_settings(struct client *client, bool ssl) @@ -130,6 +133,9 @@ static void client_read_settings(struct client *client, bool ssl) &set_parser, &error) < 0) i_fatal("%s", error); + /* create raw user before duplicating the settings parser */ + client_raw_user_create(client, set_parser); + set_parser = settings_parser_dup(set_parser, client->pool); lmtp_settings_get(set_parser, client->pool, &lmtp_set, &lda_set); const struct var_expand_table *tab = @@ -173,7 +179,6 @@ struct client *client_create(int fd_in, int fd_out, event_add_category(client->event, &event_category_lmtp); client_read_settings(client, conn_tls); - client_raw_user_create(client); client_load_modules(client); client->my_domain = client->unexpanded_lda_set->hostname;