]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-settings: Use only the same setting root's settings
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Mon, 14 Aug 2023 23:01:46 +0000 (19:01 -0400)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Wed, 12 Feb 2025 10:34:10 +0000 (12:34 +0200)
src/lib-settings/settings.c
src/lib-settings/settings.h

index 8d2034bc3edf5a6d9026189ce7803cfe57ebddf5..fca6d222bfa37e67c323f4069fc9b3985e94ef5b 100644 (file)
@@ -81,6 +81,7 @@ struct settings_root {
 
 struct settings_instance {
        pool_t pool;
+       struct settings_root *root;
        struct settings_mmap *mmap;
        ARRAY_TYPE(settings_override) overrides;
 };
@@ -1374,9 +1375,9 @@ settings_get_full(struct event *event,
                  unsigned int source_linenum,
                  const void **set_r, const char **error_r)
 {
-       struct settings_root *root = NULL;
+       struct settings_root *scan_root, *root = NULL;
        struct settings_mmap *mmap = NULL;
-       struct settings_instance *instance = NULL;
+       struct settings_instance *scan_instance, *instance = NULL;
        struct event *lookup_event, *scan_event = event;
        const char *str, *filter_name = NULL;
        bool filter_name_required = FALSE;
@@ -1399,12 +1400,23 @@ settings_get_full(struct event *event,
        }
 
        do {
+               scan_root = event_get_ptr(scan_event, SETTINGS_EVENT_ROOT);
+               scan_instance = event_get_ptr(scan_event,
+                                             SETTINGS_EVENT_INSTANCE);
+
                if (root == NULL)
-                       root = event_get_ptr(scan_event, SETTINGS_EVENT_ROOT);
-               if (instance == NULL) {
-                       instance = event_get_ptr(scan_event,
-                                                SETTINGS_EVENT_INSTANCE);
+                       root = scan_root;
+               else if ((scan_root != NULL && root != scan_root) ||
+                        (scan_instance != NULL && root != scan_instance->root)) {
+                       /* settings root changed - ignore the rest of the
+                          event hierarchy. */
+                       break;
                }
+               if (instance == NULL && scan_instance != NULL) {
+                       instance = scan_instance;
+                       root = instance->root;
+               }
+
                str = event_get_ptr(scan_event, SETTINGS_EVENT_FILTER_NAME);
                if (str != NULL) {
                        event_strlist_append(lookup_event,
@@ -1590,6 +1602,7 @@ struct settings_instance *
 settings_instance_new(struct settings_root *root)
 {
        struct settings_instance *instance = settings_instance_alloc();
+       instance->root = root;
        instance->mmap = root->mmap;
        return instance;
 }
@@ -1598,6 +1611,7 @@ struct settings_instance *
 settings_instance_dup(const struct settings_instance *src)
 {
        struct settings_instance *dest = settings_instance_alloc();
+       dest->root = src->root;
        dest->mmap = src->mmap;
 
        if (!array_is_created(&src->overrides))
index 19d110d7c214e63fa06f20875cbb119e5eee8c89..daff02f11a8dc8d603f60b24e3d56094eca2d063 100644 (file)
@@ -45,7 +45,12 @@ enum settings_get_flags {
 #define SETTINGS_EVENT_INSTANCE "settings_instance"
 
 /* Used by settings_get() to find struct settings_root via the event.
-   This is set automatically by lib-master for all created root events. */
+   This is set automatically by lib-master for all created root events.
+
+   If a new root is created in the event hierarchy (or an instance with a new
+   root is used), only the settings under the new root are used. This allows
+   specifying the exact wanted settings in the code, and they can't be changed
+   with config file or command line options. */
 #define SETTINGS_EVENT_ROOT "settings_root"
 
 /* Used by settings_get() to access the named filter. This is copied to the