]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage, global: Move mail_user_settings.{plugin_envs|namespaces} to mail_storage...
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Fri, 20 Jan 2023 03:11:06 +0000 (05:11 +0200)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Mon, 20 Nov 2023 12:20:55 +0000 (14:20 +0200)
The following commits change %{home} to stop working in mail_user_settings.
Also, it makes more sense that namespaces are storage-related settings.

src/doveadm/doveadm-dsync.c
src/imap/imap-client.c
src/lib-storage/mail-namespace.c
src/lib-storage/mail-storage-settings.c
src/lib-storage/mail-storage-settings.h
src/lib-storage/mail-user.c
src/lib-storage/mail-user.h
src/plugins/quota/quota-status.c

index a8fafbda2320902d5c714647d5b2f66cacae542a..a4c728fc5b451be3d98d4b8f3fb9c01427f0a0cb 100644 (file)
@@ -1014,6 +1014,26 @@ parse_location(struct dsync_cmd_context *ctx,
        return 0;
 }
 
+static int
+get_default_replica_location(struct dsync_cmd_context *ctx,
+                            struct mail_storage_service_user *service_user,
+                            const char **error_r)
+{
+       struct setting_parser_context *set_parser =
+               mail_storage_service_user_get_settings_parser(service_user);
+       const struct mail_storage_settings *mail_set;
+       if (master_service_settings_parser_get(NULL, set_parser,
+                       &mail_storage_setting_parser_info,
+                       MASTER_SERVICE_SETTINGS_GET_FLAG_NO_CHECK |
+                       MASTER_SERVICE_SETTINGS_GET_FLAG_NO_EXPAND,
+                       &mail_set, error_r) < 0)
+               return -1;
+       ctx->local_location = p_strdup(ctx->ctx.pool,
+               mail_user_set_plugin_getenv(mail_set, "mail_replica"));
+       master_service_settings_free(mail_set);
+       return 0;
+}
+
 static int cmd_dsync_prerun(struct doveadm_mail_cmd_context *_ctx,
                            struct mail_storage_service_user *service_user,
                            const char **error_r)
@@ -1023,11 +1043,8 @@ static int cmd_dsync_prerun(struct doveadm_mail_cmd_context *_ctx,
                container_of(_ctx, struct dsync_cmd_context, ctx);
 
        const char *const *remote_cmd_args = NULL;
-       const struct mail_user_settings *user_set;
        const char *username = "";
 
-       user_set = mail_storage_service_user_get_set(service_user);
-
        ctx->fd_in = -1;
        ctx->fd_out = -1;
        ctx->fd_err = -1;
@@ -1035,8 +1052,9 @@ static int cmd_dsync_prerun(struct doveadm_mail_cmd_context *_ctx,
        ctx->remote_name = "remote";
 
        if (ctx->default_replica_location) {
-               ctx->local_location =
-                       mail_user_set_plugin_getenv(user_set, "mail_replica");
+               if (get_default_replica_location(ctx, service_user, error_r) < 0)
+                       return -1;
+
                if (ctx->local_location == NULL ||
                    *ctx->local_location == '\0') {
                        *error_r = "User has no mail_replica in userdb";
index 2db8e7eb376b40e8fd68307a20ec753522a43195..637454ee14eacbc6b0aad363af7036e72d369007 100644 (file)
@@ -95,10 +95,12 @@ static bool user_has_special_use_mailboxes(struct mail_user *user)
         */
 
        /* no namespaces => no special use flags */
-       if (!array_is_created(&user->set->namespaces))
+       const struct mail_storage_settings *mail_set =
+               mail_user_set_get_storage_set(user);
+       if (!array_is_created(&mail_set->namespaces))
                return FALSE;
 
-       array_foreach_elem(&user->set->namespaces, ns_set) {
+       array_foreach_elem(&mail_set->namespaces, ns_set) {
                struct mailbox_settings *box_set;
 
                /* no mailboxes => no special use flags */
index 915257bf8b03d1730a22e6a548c8d50c4ee1c0f3..7df3daf50db9e5517806923d6a2ec3c8020c0df6 100644 (file)
@@ -445,8 +445,10 @@ int mail_namespaces_init(struct mail_user *user, const char **error_r)
 
         namespaces = NULL; ns_p = &namespaces;
 
-       if (array_is_created(&user->set->namespaces))
-               ns_set = array_get(&user->set->namespaces, &count);
+       const struct mail_storage_settings *mail_set =
+               mail_user_set_get_storage_set(user);
+       if (array_is_created(&mail_set->namespaces))
+               ns_set = array_get(&mail_set->namespaces, &count);
        else {
                ns_set = NULL;
                count = 0;
index 3deb1c60147a8cee12265dde138074255a40b219..df6292c2a8aa3b895a3de98e15ef32bb832ac4a3 100644 (file)
@@ -26,8 +26,13 @@ static bool mail_user_settings_check(void *_set, pool_t pool, const char **error
 static bool mail_user_settings_expand_check(void *_set, pool_t pool ATTR_UNUSED, const char **error_r);
 
 #undef DEF
+#undef DEFLIST_UNIQUE
 #define DEF(type, name) \
        SETTING_DEFINE_STRUCT_##type(#name, name, struct mail_storage_settings)
+#define DEFLIST_UNIQUE(field, name, defines) \
+       { .type = SET_DEFLIST_UNIQUE, .key = name, \
+         .offset = offsetof(struct mail_storage_settings, field), \
+         .list_info = defines }
 
 static const struct setting_define mail_storage_setting_defines[] = {
        DEF(STR_VARS, mail_location),
@@ -83,6 +88,10 @@ static const struct setting_define mail_storage_setting_defines[] = {
 
        DEF(STR, recipient_delimiter),
 
+       DEFLIST_UNIQUE(namespaces, "namespace", &mail_namespace_setting_parser_info),
+       { .type = SET_STRLIST, .key = "plugin",
+         .offset = offsetof(struct mail_storage_settings, plugin_envs) },
+
        SETTING_DEFINE_LIST_END
 };
 
@@ -138,6 +147,9 @@ const struct mail_storage_settings mail_storage_default_settings = {
        .pop3_uidl_format = "%08Xu%08Xv",
 
        .recipient_delimiter = "+",
+
+       .namespaces = ARRAY_INIT,
+       .plugin_envs = ARRAY_INIT,
 };
 
 const struct setting_parser_info mail_storage_setting_parser_info = {
@@ -249,20 +261,15 @@ const struct setting_parser_info mail_namespace_setting_parser_info = {
        .type_offset1 = 1 + offsetof(struct mail_namespace_settings, name),
        .struct_size = sizeof(struct mail_namespace_settings),
 
-       .parent_offset1 = 1 + offsetof(struct mail_namespace_settings, user_set),
-       .parent = &mail_user_setting_parser_info,
+       .parent_offset1 = 1 + offsetof(struct mail_namespace_settings, mail_set),
+       .parent = &mail_storage_setting_parser_info,
 
        .check_func = namespace_settings_check
 };
 
 #undef DEF
-#undef DEFLIST_UNIQUE
 #define DEF(type, name) \
        SETTING_DEFINE_STRUCT_##type(#name, name, struct mail_user_settings)
-#define DEFLIST_UNIQUE(field, name, defines) \
-       { .type = SET_DEFLIST_UNIQUE, .key = name, \
-         .offset = offsetof(struct mail_user_settings, field), \
-         .list_info = defines }
 
 static const struct setting_define mail_user_setting_defines[] = {
        DEF(STR, base_dir),
@@ -291,10 +298,6 @@ static const struct setting_define mail_user_setting_defines[] = {
        DEF(STR, hostname),
        DEF(STR_VARS, postmaster_address),
 
-       DEFLIST_UNIQUE(namespaces, "namespace", &mail_namespace_setting_parser_info),
-       { .type = SET_STRLIST, .key = "plugin",
-         .offset = offsetof(struct mail_user_settings, plugin_envs) },
-
        SETTING_DEFINE_LIST_END
 };
 
@@ -324,9 +327,6 @@ static const struct mail_user_settings mail_user_default_settings = {
 
        .hostname = "",
        .postmaster_address = "postmaster@%{if;%d;ne;;%d;%{hostname}}",
-
-       .namespaces = ARRAY_INIT,
-       .plugin_envs = ARRAY_INIT
 };
 
 const struct setting_parser_info mail_user_setting_parser_info = {
@@ -555,8 +555,8 @@ static bool namespace_settings_check(void *_set, pool_t pool ATTR_UNUSED,
        }
 
        if (ns->alias_for != NULL && !ns->disabled) {
-               if (array_is_created(&ns->user_set->namespaces)) {
-                       namespaces = array_get(&ns->user_set->namespaces,
+               if (array_is_created(&ns->mail_set->namespaces)) {
+                       namespaces = array_get(&ns->mail_set->namespaces,
                                               &count);
                } else {
                        namespaces = NULL;
index bfec46e8a32f75fd5eef4534dbc4ef1f14c04f47..8504684cd672f1e91fa520f8b2c266edf63a7b60 100644 (file)
@@ -66,6 +66,9 @@ struct mail_storage_settings {
 
        const char *mail_attachment_detection_options;
 
+       ARRAY(struct mail_namespace_settings *) namespaces;
+       ARRAY(const char *) plugin_envs;
+
        enum file_lock_method parsed_lock_method;
        enum fsync_mode parsed_fsync_mode;
        const char *unexpanded_mail_location;
@@ -93,7 +96,7 @@ struct mail_namespace_settings {
        unsigned int order;
 
        ARRAY(struct mailbox_settings *) mailboxes;
-       struct mail_user_settings *user_set;
+       struct mail_storage_settings *mail_set;
        const char *unexpanded_location;
 };
 
@@ -138,9 +141,6 @@ struct mail_user_settings {
        const char *hostname;
        const char *postmaster_address;
 
-       ARRAY(struct mail_namespace_settings *) namespaces;
-       ARRAY(const char *) plugin_envs;
-
        /* May be NULL - use mail_storage_get_postmaster_address() instead of
           directly accessing this. */
        const struct message_address *_parsed_postmaster_address;
index 25db99c5f83fa9c30af3b040e704db6ab7a8a7d6..d721c459cd536870567ead219919a5a362783fa4 100644 (file)
@@ -100,17 +100,18 @@ mail_user_alloc(struct mail_storage_service_user *service_user)
 }
 
 static void
-mail_user_expand_plugins_envs(struct mail_user *user)
+mail_user_expand_plugins_envs(struct mail_user *user,
+                             struct mail_storage_settings *set)
 {
        const char **envs, *home, *error;
        string_t *str;
        unsigned int i, count;
 
-       if (!array_is_created(&user->set->plugin_envs))
+       if (!array_is_created(&set->plugin_envs))
                return;
 
        str = t_str_new(256);
-       envs = array_get_modifiable(&user->set->plugin_envs, &count);
+       envs = array_get_modifiable(&set->plugin_envs, &count);
        i_assert((count % 2) == 0);
        for (i = 0; i < count; i += 2) {
                if (user->_home == NULL &&
@@ -174,8 +175,11 @@ int mail_user_init(struct mail_user *user, const char **error_r)
                }
        }
 
+       struct mail_storage_settings *mail_set =
+               settings_parser_get_root_set(user->set_parser,
+                       &mail_storage_setting_parser_info);
        user->settings_expanded = TRUE;
-       mail_user_expand_plugins_envs(user);
+       mail_user_expand_plugins_envs(user, mail_set);
 
        user->ssl_set = p_new(user->pool, struct ssl_iostream_settings, 1);
        if (user->error == NULL &&
@@ -539,10 +543,12 @@ bool mail_user_is_plugin_loaded(struct mail_user *user, struct module *module)
 
 bool mail_user_plugin_getenv_bool(struct mail_user *user, const char *name)
 {
-       return mail_user_set_plugin_getenv_bool(user->set, name);
+       const struct mail_storage_settings *mail_set =
+               mail_user_set_get_storage_set(user);
+       return mail_user_set_plugin_getenv_bool(mail_set, name);
 }
 
-bool mail_user_set_plugin_getenv_bool(const struct mail_user_settings *set,
+bool mail_user_set_plugin_getenv_bool(const struct mail_storage_settings *set,
                                      const char *name)
 {
        const char *env = mail_user_set_plugin_getenv(set, name);
@@ -564,10 +570,12 @@ bool mail_user_set_plugin_getenv_bool(const struct mail_user_settings *set,
 
 const char *mail_user_plugin_getenv(struct mail_user *user, const char *name)
 {
-       return mail_user_set_plugin_getenv(user->set, name);
+       const struct mail_storage_settings *mail_set =
+               mail_user_set_get_storage_set(user);
+       return mail_user_set_plugin_getenv(mail_set, name);
 }
 
-const char *mail_user_set_plugin_getenv(const struct mail_user_settings *set,
+const char *mail_user_set_plugin_getenv(const struct mail_storage_settings *set,
                                        const char *name)
 {
        const char *const *envs;
index 261ee47197ceb2c7f61aa1c2737d3df6cd8cc0ee..cf034535db383c24de0da3a9b9975f759a955d1a 100644 (file)
@@ -179,9 +179,9 @@ bool mail_user_is_plugin_loaded(struct mail_user *user, struct module *module);
 /* If name exists in plugin_envs, return its value. */
 const char *mail_user_plugin_getenv(struct mail_user *user, const char *name);
 bool mail_user_plugin_getenv_bool(struct mail_user *user, const char *name);
-const char *mail_user_set_plugin_getenv(const struct mail_user_settings *set,
+const char *mail_user_set_plugin_getenv(const struct mail_storage_settings *set,
                                        const char *name);
-bool mail_user_set_plugin_getenv_bool(const struct mail_user_settings *set,
+bool mail_user_set_plugin_getenv_bool(const struct mail_storage_settings *set,
                                      const char *name);
 
 /* Add more namespaces to user's namespaces. The ->next pointers may be
index 159f3876e2320bc4d45fdaaa1b385e463b59f69f..34147c1ee7a8e688b8bb923273186ca68f643d13 100644 (file)
@@ -290,7 +290,7 @@ static void main_init(void)
        };
        struct mail_storage_service_input input;
        struct setting_parser_context *set_parser;
-       const struct mail_user_settings *user_set;
+       const struct mail_storage_settings *mail_set;
        const char *value, *error;
 
        clients = connection_list_init(&client_set, &client_vfuncs);
@@ -311,16 +311,16 @@ static void main_init(void)
                i_fatal("%s", error);
 
        if (master_service_settings_parser_get(NULL, set_parser,
-                       &mail_user_setting_parser_info,
+                       &mail_storage_setting_parser_info,
                        MASTER_SERVICE_SETTINGS_GET_FLAG_NO_EXPAND,
-                       &user_set, &error) < 0)
+                       &mail_set, &error) < 0)
                i_fatal("%s", error);
        quota_status_settings = master_service_settings_get_or_fatal(NULL,
                &quota_status_setting_parser_info);
 
-       value = mail_user_set_plugin_getenv(user_set, "quota_status_nouser");
+       value = mail_user_set_plugin_getenv(mail_set, "quota_status_nouser");
        nouser_reply = i_strdup(value != NULL ? value : "REJECT Unknown user");
-       master_service_settings_free(user_set);
+       master_service_settings_free(mail_set);
 }
 
 static void main_deinit(void)