]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
auth: Change "auth_mechanisms" setting to boolean-list
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Wed, 7 Jun 2023 11:16:48 +0000 (14:16 +0300)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Wed, 12 Feb 2025 10:34:09 +0000 (12:34 +0200)
src/auth/auth-settings.c
src/auth/auth-settings.h
src/auth/mech.c
src/auth/test-auth.c

index 3f8a303a7f4403bb6257d766d940916fe38c4be0..a7421fecb93feb942fb468b7a82a02ba026eff59 100644 (file)
@@ -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),
index b1428f341ec48c3158de9f73aeed5e500c90a0f1..b30261d92d653d435fc07abf9ebe776f7888beb4 100644 (file)
@@ -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;
index 477f27bd3cdfa701c7233758f226b46afd0b1571..2d3ce27f52e14b65947e2e83b2eb430cec59bb32 100644 (file)
@@ -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;
 }
 
index 5fb4eee7a07f356d8e15f25c55aa3f24f9cdb58c..fa05b9eccbee8a4ad6fb9dac4fabc66c23cbf59c 100644 (file)
@@ -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));