From: Timo Sirainen Date: Wed, 4 Jan 2023 23:27:29 +0000 (+0200) Subject: auth: Use master_service_settings_get[_or_fatal]() X-Git-Tag: 2.4.0~2333 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=987776c514a95132f4a7a06e5f86c31976c77f6a;p=thirdparty%2Fdovecot%2Fcore.git auth: Use master_service_settings_get[_or_fatal]() --- diff --git a/src/auth/auth-policy.c b/src/auth/auth-policy.c index 848a5359ef..8f17e64508 100644 --- a/src/auth/auth-policy.c +++ b/src/auth/auth-policy.c @@ -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 */ diff --git a/src/auth/auth-settings.c b/src/auth/auth-settings.c index ce1365e0fb..070941aaca 100644 --- a/src/auth/auth-settings.c +++ b/src/auth/auth-settings.c @@ -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; } diff --git a/src/auth/auth-settings.h b/src/auth/auth-settings.h index 26bbcf37ad..6c921205c6 100644 --- a/src/auth/auth-settings.h +++ b/src/auth/auth-settings.h @@ -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); diff --git a/src/auth/auth.c b/src/auth/auth.c index 9f6c4ba60c..7785906ef2 100644 --- a/src/auth/auth.c +++ b/src/auth/auth.c @@ -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); } diff --git a/src/auth/auth.h b/src/auth/auth.h index 460a179765..b158543fc2 100644 --- a/src/auth/auth.h +++ b/src/auth/auth.h @@ -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); diff --git a/src/auth/main.c b/src/auth/main.c index 5a2ecb1d75..79f6f70b00 100644 --- a/src/auth/main.c +++ b/src/auth/main.c @@ -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) diff --git a/src/auth/test-mech.c b/src/auth/test-mech.c index 0bb3696c69..c979b761e3 100644 --- a/src/auth/test-mech.c +++ b/src/auth/test-mech.c @@ -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(); }