]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
auth: Convert userdbs_generate_md5() to read all settings
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Fri, 29 Nov 2024 10:39:32 +0000 (12:39 +0200)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Fri, 17 Jan 2025 08:40:01 +0000 (10:40 +0200)
src/auth/auth-worker-connection.c
src/auth/auth-worker-server.c
src/auth/auth.c
src/auth/auth.h
src/auth/userdb.c
src/auth/userdb.h

index afdd9a5eb945ac42cc82323781372aaffeabc2f3..775413085fb38d16b473232108770e42c4f01136 100644 (file)
@@ -195,7 +195,7 @@ static void auth_worker_connection_connected(struct connection *conn,
        string_t *str = t_str_new(128);
 
        auth_passdbs_generate_md5(passdb_md5);
-       userdbs_generate_md5(userdb_md5);
+       auth_userdbs_generate_md5(userdb_md5);
        str_append(str, "DBHASH\t");
        binary_to_hex_append(str, passdb_md5, sizeof(passdb_md5));
        str_append_c(str, '\t');
index c3d5b5126a4dd0f8aff164a92d02977a0bc956e8..8faac6905875f0740bbcb29d120404176a8acfcf 100644 (file)
@@ -750,7 +750,7 @@ static bool auth_worker_verify_db_hash(const char *passdb_hash, const char *user
        unsigned char userdb_md5[MD5_RESULTLEN];
 
        auth_passdbs_generate_md5(passdb_md5);
-       userdbs_generate_md5(userdb_md5);
+       auth_userdbs_generate_md5(userdb_md5);
 
        binary_to_hex_append(str, passdb_md5, sizeof(passdb_md5));
        if (strcmp(str_c(str), passdb_hash) != 0)
index d55b1cf1898e16ff26cf2b3d690834654ebd7a07..a733e7ba0743b714ecdb17792dc0b898dbf1ed77 100644 (file)
@@ -150,6 +150,7 @@ auth_userdb_preinit(struct auth *auth, const struct auth_userdb_settings *_set)
 {
        struct auth_userdb *auth_userdb, **dest;
        const struct auth_userdb_settings *set;
+       const char *error;
 
        /* Lookup userdb-specific auth_settings */
        struct event *event = event_create(auth_event);
@@ -169,6 +170,11 @@ auth_userdb_preinit(struct auth *auth, const struct auth_userdb_settings *_set)
        auth_userdb = p_new(auth->pool, struct auth_userdb, 1);
        auth_userdb->auth_set =
                settings_get_or_fatal(event, &auth_setting_parser_info);
+       if (settings_get(event, &auth_userdb_post_setting_parser_info,
+                        SETTINGS_GET_FLAG_NO_CHECK |
+                        SETTINGS_GET_FLAG_NO_EXPAND,
+                        &auth_userdb->unexpanded_post_set, &error) < 0)
+               i_fatal("%s", error);
 
        auth_userdb->name = set->name;
        auth_userdb->set = set;
@@ -197,6 +203,7 @@ static void auth_userdb_deinit(struct auth_userdb *userdb)
        if (userdb->set != &userdb_dummy_set)
                settings_free(userdb->set);
        settings_free(userdb->auth_set);
+       settings_free(userdb->unexpanded_post_set);
        userdb_deinit(userdb->userdb);
 }
 
@@ -434,6 +441,37 @@ void auth_passdbs_generate_md5(unsigned char md5[STATIC_ARRAY MD5_RESULTLEN])
        md5_final(&ctx, md5);
 }
 
+static void
+auth_userdbs_update_md5(struct auth *auth, struct md5_context *ctx)
+{
+       struct auth_userdb *userdb;
+       unsigned int hash;
+
+       for (userdb = auth->userdbs; userdb != NULL; userdb = userdb->next) {
+               md5_update(ctx, &userdb->userdb->id, sizeof(userdb->userdb->id));
+               hash = settings_hash(&auth_userdb_setting_parser_info,
+                                    userdb->set, NULL);
+               md5_update(ctx, &hash, sizeof(hash));
+               hash = settings_hash(&auth_setting_parser_info,
+                                    userdb->auth_set, NULL);
+               md5_update(ctx, &hash, sizeof(hash));
+               hash = settings_hash(&auth_userdb_post_setting_parser_info,
+                                    userdb->unexpanded_post_set, NULL);
+               md5_update(ctx, &hash, sizeof(hash));
+       }
+}
+
+void auth_userdbs_generate_md5(unsigned char md5[STATIC_ARRAY MD5_RESULTLEN])
+{
+       struct auth *auth;
+       struct md5_context ctx;
+
+       md5_init(&ctx);
+       array_foreach_elem(&auths, auth)
+               auth_userdbs_update_md5(auth, &ctx);
+       md5_final(&ctx, md5);
+}
+
 struct auth *auth_find_protocol(const char *name)
 {
        struct auth *const *a;
index acffb651c2c1c6e03c8a9009a6017dad3be5b8c0..d1c1b96c1c1d9342571f5f255be0209b154e8040 100644 (file)
@@ -59,6 +59,7 @@ struct auth_userdb {
        const char *name;
        const struct auth_settings *auth_set;
        const struct auth_userdb_settings *set;
+       const struct auth_userdb_post_settings *unexpanded_post_set;
        struct userdb_module *userdb;
 
        /* The caching key for this userdb, or NULL if caching isn't wanted. */
@@ -88,6 +89,7 @@ struct auth *auth_find_protocol(const char *name);
 struct auth *auth_default_protocol(void);
 
 void auth_passdbs_generate_md5(unsigned char md5[STATIC_ARRAY MD5_RESULTLEN]);
+void auth_userdbs_generate_md5(unsigned char md5[STATIC_ARRAY MD5_RESULTLEN]);
 
 void auths_preinit(struct event *parent_event,
                   const struct auth_settings *set,
index f822cdda1fd9cd640244bf4713ba341cdc0427de..dadaeb20028112707339f40bed8078ee097e2d63 100644 (file)
@@ -170,23 +170,6 @@ void userdb_deinit(struct userdb_module *userdb)
        userdb->iface = &userdb_iface_deinit;
 }
 
-void userdbs_generate_md5(unsigned char md5[STATIC_ARRAY MD5_RESULTLEN])
-{
-       struct md5_context ctx;
-       struct userdb_module *const *userdbs;
-       unsigned int i, count;
-
-       md5_init(&ctx);
-       userdbs = array_get(&userdb_modules, &count);
-       for (i = 0; i < count; i++) {
-               md5_update(&ctx, &userdbs[i]->id, sizeof(userdbs[i]->id));
-               md5_update(&ctx, userdbs[i]->iface->name,
-                          strlen(userdbs[i]->iface->name));
-               md5_update(&ctx, userdbs[i]->args, strlen(userdbs[i]->args));
-       }
-       md5_final(&ctx, md5);
-}
-
 const char *userdb_result_to_string(enum userdb_result result)
 {
        switch (result) {
index 3343595722f644dc72e56cdd66127c80bd6106d5..961f4d766cfb58ba6399f444770313502c08507c 100644 (file)
@@ -83,8 +83,6 @@ void userdb_deinit(struct userdb_module *userdb);
 void userdb_register_module(struct userdb_module_interface *iface);
 void userdb_unregister_module(struct userdb_module_interface *iface);
 
-void userdbs_generate_md5(unsigned char md5[STATIC_ARRAY MD5_RESULTLEN]);
-
 void userdbs_init(void);
 void userdbs_deinit(void);