From: Timo Sirainen Date: Wed, 7 Jun 2023 11:16:48 +0000 (+0300) Subject: auth: Change "auth_mechanisms" setting to boolean-list X-Git-Tag: 2.4.1~1556 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6512a327ecf67b4ea6267c148a04f0ca360e3108;p=thirdparty%2Fdovecot%2Fcore.git auth: Change "auth_mechanisms" setting to boolean-list --- diff --git a/src/auth/auth-settings.c b/src/auth/auth-settings.c index 3f8a303a7f..a7421fecb9 100644 --- a/src/auth/auth-settings.c +++ b/src/auth/auth-settings.c @@ -213,7 +213,7 @@ const struct setting_parser_info auth_userdb_setting_parser_info = { SETTING_DEFINE_STRUCT_##type(#name, name, struct auth_settings) static const struct setting_define auth_setting_defines[] = { - DEF(STR, mechanisms), + DEF(BOOLLIST, mechanisms), DEF(STR, realms), DEF(STR, default_domain), DEF(SIZE, cache_size), @@ -287,7 +287,6 @@ static const struct setting_define auth_setting_defines[] = { }; static const struct auth_settings auth_default_settings = { - .mechanisms = "plain", .realms = "", .default_domain = "", .cache_size = 0, @@ -341,12 +340,17 @@ static const struct auth_settings auth_default_settings = { .first_valid_gid = 1, .last_valid_gid = 0, }; +static const struct setting_keyvalue auth_default_settings_keyvalue[] = { + { "auth_mechanisms", "plain" }, + { NULL, NULL } +}; const struct setting_parser_info auth_setting_parser_info = { .name = "auth", .defines = auth_setting_defines, .defaults = &auth_default_settings, + .default_settings = auth_default_settings_keyvalue, .struct_size = sizeof(struct auth_settings), .pool_offset1 = 1 + offsetof(struct auth_settings, pool), diff --git a/src/auth/auth-settings.h b/src/auth/auth-settings.h index b1428f341e..b30261d92d 100644 --- a/src/auth/auth-settings.h +++ b/src/auth/auth-settings.h @@ -41,7 +41,7 @@ struct auth_userdb_settings { struct auth_settings { pool_t pool; - const char *mechanisms; + ARRAY_TYPE(const_string) mechanisms; const char *realms; const char *default_domain; uoff_t cache_size; diff --git a/src/auth/mech.c b/src/auth/mech.c index 477f27bd3c..2d3ce27f52 100644 --- a/src/auth/mech.c +++ b/src/auth/mech.c @@ -134,7 +134,7 @@ mech_register_init(const struct auth_settings *set) { struct mechanisms_register *reg; const struct mech_module *mech; - const char *const *mechanisms; + const char *name; pool_t pool; pool = pool_alloconly_create("mechanisms register", 1024); @@ -143,9 +143,12 @@ mech_register_init(const struct auth_settings *set) reg->set = set; reg->handshake = str_new(pool, 512); - mechanisms = t_strsplit_spaces(set->mechanisms, " "); - for (; *mechanisms != NULL; mechanisms++) { - const char *name = t_str_ucase(*mechanisms); + if (!array_is_created(&set->mechanisms) || + array_is_empty(&set->mechanisms)) + i_fatal("No authentication mechanisms configured"); + + array_foreach_elem(&set->mechanisms, name) { + name = t_str_ucase(name); if (strcmp(name, "ANONYMOUS") == 0) { if (*set->anonymous_username == '\0') { @@ -163,9 +166,6 @@ mech_register_init(const struct auth_settings *set) i_fatal("Unknown authentication mechanism '%s'", name); mech_register_add(reg, mech); } - - if (reg->modules == NULL) - i_fatal("No authentication mechanisms configured"); return reg; } diff --git a/src/auth/test-auth.c b/src/auth/test-auth.c index 5fb4eee7a0..fa05b9eccb 100644 --- a/src/auth/test-auth.c +++ b/src/auth/test-auth.c @@ -27,7 +27,9 @@ void test_auth_init(void) test_auth_set = *(const struct auth_settings *)auth_setting_parser_info.defaults; test_auth_set.pool = pool_alloconly_create("test settings", 128); test_auth_set.base_dir = "."; - test_auth_set.mechanisms = "plain"; + p_array_init(&test_auth_set.mechanisms, test_auth_set.pool, 1); + const char *plain = "plain"; + array_push_back(&test_auth_set.mechanisms, &plain); global_auth_settings = &test_auth_set; memset((&test_auth_set)->username_chars_map, 1, sizeof((&test_auth_set)->username_chars_map));