]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
auth: Use master_service_settings_get[_or_fatal]()
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Wed, 4 Jan 2023 23:27:29 +0000 (01:27 +0200)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Mon, 20 Nov 2023 12:11:41 +0000 (14:11 +0200)
src/auth/auth-policy.c
src/auth/auth-settings.c
src/auth/auth-settings.h
src/auth/auth.c
src/auth/auth.h
src/auth/main.c
src/auth/test-mech.c

index 848a5359ef26ccf3ccbb6996d4ece89df4731086..8f17e64508d5a553a679ebffd5b8388698967ab8 100644 (file)
@@ -155,7 +155,7 @@ auth_policy_open_and_close_to_key(struct json_ostream *json_output,
 void auth_policy_init(void)
 {
        const struct master_service_ssl_settings *master_ssl_set =
-               master_service_settings_get_root_set(master_service,
+               master_service_settings_get_or_fatal(NULL,
                        &master_service_ssl_setting_parser_info);
        struct ssl_iostream_settings ssl_set;
        i_zero(&ssl_set);
@@ -170,6 +170,7 @@ void auth_policy_init(void)
        http_client_set.ssl = &ssl_set;
        http_client_set.event_parent = auth_event;
        http_client = http_client_init(&http_client_set);
+       master_service_settings_free(master_ssl_set);
 
        /* prepare template */
 
index ce1365e0fb68900b543da57ad6f93e6183d3109b..070941aaca1dbb70111cc70353370bf329e0ab49 100644 (file)
@@ -379,6 +379,7 @@ const struct setting_parser_info auth_setting_parser_info = {
        .defaults = &auth_default_settings,
 
        .struct_size = sizeof(struct auth_settings),
+       .pool_offset1 = 1 + offsetof(struct auth_settings, pool),
        .check_func = auth_settings_check
 };
 
@@ -544,7 +545,7 @@ auth_userdb_settings_check(void *_set, pool_t pool ATTR_UNUSED,
 const struct auth_settings *global_auth_settings;
 
 const struct auth_settings *
-auth_settings_read(const char *service, pool_t pool,
+auth_settings_read(const char *service,
                   struct master_service_settings_output *output_r)
 {
        static const struct setting_parser_info *set_roots[] = {
@@ -552,23 +553,21 @@ auth_settings_read(const char *service, pool_t pool,
                NULL
        };
        struct master_service_settings_input input;
-       struct setting_parser_context *set_parser;
        const char *error;
 
        i_zero(&input);
        input.roots = set_roots;
        input.service = service;
+       input.disable_check_settings = TRUE;
        if (master_service_settings_read(master_service, &input,
                                         output_r, &error) < 0)
                i_fatal("%s", error);
 
-       pool_ref(pool);
-       set_parser = settings_parser_dup(master_service->set_parser, pool);
-       if (!settings_parser_check(set_parser, pool, &error))
-               i_unreached();
-
-       struct auth_settings *set =
-               settings_parser_get_root_set(set_parser, &auth_setting_parser_info);
-       settings_parser_unref(&set_parser);
+       struct event *event = event_create(NULL);
+       event_add_str(event, "protocol", service);
+       const struct auth_settings *set =
+               master_service_settings_get_or_fatal(event,
+                                                    &auth_setting_parser_info);
+       event_unref(&event);
        return set;
 }
index 26bbcf37ad82ba16c1439ca39038d57d5f87c1bc..6c921205c60b9aec7c524253fa7447f52b8976dd 100644 (file)
@@ -38,6 +38,7 @@ struct auth_userdb_settings {
 };
 
 struct auth_settings {
+       pool_t pool;
        const char *mechanisms;
        const char *realms;
        const char *default_domain;
@@ -101,7 +102,7 @@ extern const struct setting_parser_info auth_setting_parser_info;
 extern const struct auth_settings *global_auth_settings;
 
 const struct auth_settings *
-auth_settings_read(const char *service, pool_t pool,
+auth_settings_read(const char *service,
                   struct master_service_settings_output *output_r)
        ATTR_NULL(1);
 
index 9f6c4ba60c5f450041d4f52484e17f1977c81b83..7785906ef2181e806ab707099a4422120d77a08f 100644 (file)
@@ -256,7 +256,7 @@ static void auth_mech_list_verify_passdb(const struct auth *auth)
 }
 
 static struct auth * ATTR_NULL(2)
-auth_preinit(const struct auth_settings *set, const char *service, pool_t pool,
+auth_preinit(const struct auth_settings *set, const char *service,
             const struct mechanisms_register *reg)
 {
        struct auth_passdb_settings *const *passdbs;
@@ -264,6 +264,7 @@ auth_preinit(const struct auth_settings *set, const char *service, pool_t pool,
        struct auth *auth;
        unsigned int i, count, db_count, passdb_count, last_passdb = 0;
 
+       pool_t pool = pool_alloconly_create("auth", 128);
        auth = p_new(pool, struct auth, 1);
        auth->pool = pool;
        auth->service = p_strdup(pool, service);
@@ -402,7 +403,7 @@ struct auth *auth_default_service(void)
        return a[0];
 }
 
-void auths_preinit(const struct auth_settings *set, pool_t pool,
+void auths_preinit(const struct auth_settings *set,
                   const struct mechanisms_register *reg,
                   const char *const *services)
 {
@@ -418,7 +419,7 @@ void auths_preinit(const struct auth_settings *set, pool_t pool,
        event_add_category(auth_event, &event_category_auth);
        i_array_init(&auths, 8);
 
-       auth = auth_preinit(set, NULL, pool, reg);
+       auth = auth_preinit(set, NULL, reg);
        array_push_back(&auths, &auth);
 
        for (i = 0; services[i] != NULL; i++) {
@@ -430,9 +431,8 @@ void auths_preinit(const struct auth_settings *set, pool_t pool,
                        }
                        not_service = services[i];
                }
-               service_set = auth_settings_read(services[i], pool,
-                                                &set_output);
-               auth = auth_preinit(service_set, services[i], pool, reg);
+               service_set = auth_settings_read(services[i], &set_output);
+               auth = auth_preinit(service_set, services[i], reg);
                array_push_back(&auths, &auth);
        }
 
@@ -473,13 +473,11 @@ void auths_deinit(void)
 
 void auths_free(void)
 {
-       struct auth **auth;
-       unsigned int i, count;
+       struct auth *auth;
 
-       /* deinit in reverse order, because modules have been allocated by
-          the first auth pool that used them */
-       auth = array_get_modifiable(&auths, &count);
-       for (i = count; i > 0; i--)
-               pool_unref(&auth[i-1]->pool);
+       array_foreach_elem(&auths, auth) {
+               master_service_settings_free(auth->set);
+               pool_unref(&auth->pool);
+       }
        array_free(&auths);
 }
index 460a1797656370b5c01f9ca426d393b68fa423d4..b158543fc26d9a38bb80a06b32b09df099f26daa 100644 (file)
@@ -88,7 +88,7 @@ extern struct auth_penalty *auth_penalty;
 struct auth *auth_find_service(const char *name);
 struct auth *auth_default_service(void);
 
-void auths_preinit(const struct auth_settings *set, pool_t pool,
+void auths_preinit(const struct auth_settings *set,
                   const struct mechanisms_register *reg,
                   const char *const *services);
 void auths_init(void);
index 5a2ecb1d75ff2cd9cf8aa1171bd5608f6e5e9e8c..79f6f70b00a772e1a1230f4408f8639be1046b60 100644 (file)
@@ -67,7 +67,6 @@ bool worker = FALSE, worker_restart_request = FALSE;
 time_t process_start_time;
 struct auth_penalty *auth_penalty;
 
-static pool_t auth_set_pool;
 static struct module *modules = NULL;
 static struct mechanisms_register *mech_reg;
 static ARRAY(struct auth_socket_listener) listeners;
@@ -89,22 +88,11 @@ void auth_refresh_proctitle(void)
 static const char *const *read_global_settings(void)
 {
        struct master_service_settings_output set_output;
-       const char **services;
-       unsigned int i, count;
-
-       auth_set_pool = pool_alloconly_create("auth settings", 8192);
-       global_auth_settings =
-               auth_settings_read(NULL, auth_set_pool, &set_output);
-
-       /* strdup() the service names, because they're allocated from
-          set parser pool, and we'll later clear it. */
-       count = str_array_length(set_output.specific_services);
-       services = p_new(auth_set_pool, const char *, count + 1);
-       for (i = 0; i < count; i++) {
-               services[i] = p_strdup(auth_set_pool,
-                                      set_output.specific_services[i]);
-       }
-       return services;
+
+       global_auth_settings = auth_settings_read(NULL, &set_output);
+       if (set_output.specific_services == NULL)
+               return t_new(const char *, 1);
+       return set_output.specific_services;
 }
 
 static enum auth_socket_type auth_socket_type_get(const char *typename)
@@ -189,8 +177,7 @@ static void main_preinit(void)
        mech_init(global_auth_settings);
        mech_reg = mech_register_init(global_auth_settings);
        dict_drivers_register_builtin();
-       auths_preinit(global_auth_settings, auth_set_pool,
-                     mech_reg, services);
+       auths_preinit(global_auth_settings, mech_reg, services);
 
        listeners_init();
        if (!worker)
@@ -297,7 +284,6 @@ static void main_deinit(void)
        array_foreach_modifiable(&listeners, l)
                i_free(l->path);
        array_free(&listeners);
-       pool_unref(&auth_set_pool);
 }
 
 static void worker_connected(struct master_service_connection *conn)
index 0bb3696c69a847f538f6127c734d76eeb21025c2..c979b761e377c4170bd00e64cc9aaae2e10b04a0 100644 (file)
@@ -122,7 +122,7 @@ static void test_mechs_init(void)
        password_schemes_init();
        password_schemes_allow_weak(TRUE);
 
-       auths_preinit(&set, pool_datastack_create(), mech_reg, services);
+       auths_preinit(&set, mech_reg, services);
        auths_init();
        auth_token_init();
 }