]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
auth: db-ldap-settings - Defer some checks to runtime
authorMarco Bettini <marco.bettini@open-xchange.com>
Wed, 20 Mar 2024 16:25:00 +0000 (16:25 +0000)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Fri, 17 Jan 2025 08:39:59 +0000 (10:39 +0200)
src/auth/db-ldap-settings.c
src/auth/db-ldap-settings.h
src/auth/db-ldap.c

index dc711ea29157e0cd2168ce06b4d099e5de1ef54c..5773ea393e233eb5aa200abf31c92c342f43246b 100644 (file)
@@ -132,16 +132,6 @@ static bool ldap_setting_check(void *_set, pool_t pool ATTR_UNUSED,
                return FALSE;
        }
 
-       if (*set->base == '\0') {
-               *error_r = "No ldap_base given";
-               return FALSE;
-       }
-
-       if (*set->uris == '\0' && *set->hosts == '\0') {
-               *error_r = "Neither ldap_uris nor ldap_hosts set";
-               return FALSE;
-       }
-
 #ifndef LDAP_HAVE_INITIALIZE
        if (*set->uris != '\0') {
                *error_r = "ldap_uris set, but Dovecot compiled without support for LDAP uris "
@@ -164,18 +154,33 @@ static bool ldap_setting_check(void *_set, pool_t pool ATTR_UNUSED,
        }
 #endif
 
+       return TRUE;
+}
+
+/* </settings checks> */
+
+int ldap_setting_post_check(const struct ldap_settings *set, const char **error_r)
+{
+       if (*set->base == '\0') {
+               *error_r = "No ldap_base given";
+               return -1;
+       }
+
+       if (*set->uris == '\0' && *set->hosts == '\0') {
+               *error_r = "Neither ldap_uris nor ldap_hosts set";
+               return -1;
+       }
+
        if (set->version < 3) {
                if (set->sasl_bind) {
                        *error_r = "ldap_sasl_bind=yes requires ldap_version=3";
-                       return FALSE;
+                       return -1;
                }
                if (set->starttls) {
                        *error_r = "ldap_starttls=yes requires ldap_version=3";
-                       return FALSE;
+                       return -1;
                }
        }
 
-       return TRUE;
+       return 0;
 }
-
-/* </settings checks> */
index 82e79eb02882fdb55179a60b69d89255ee14b6f9..ff9e0421f9faa2b13c4e1d2cf85a91dce550c06d 100644 (file)
@@ -42,5 +42,6 @@ struct ldap_settings {
 };
 
 extern const struct setting_parser_info ldap_setting_parser_info;
+int ldap_setting_post_check(const struct ldap_settings *set, const char **error_r);
 
 #endif
index 74a24a915fcff5dc57d07fd1f2734db243779399..f0cede3d7ca286119d53097601095b5dc6ff599d 100644 (file)
@@ -1683,9 +1683,12 @@ struct ldap_connection *db_ldap_init(struct event *event)
 {
         const struct ldap_settings *set;
        const struct ssl_settings *ssl_set;
+       const char *error;
 
        set     = settings_get_or_fatal(event, &ldap_setting_parser_info);
        ssl_set = settings_get_or_fatal(event, &ssl_setting_parser_info);
+       if (ldap_setting_post_check(set, &error) < 0)
+               i_fatal("LDAP: %s", error);
 
        /* see if it already exists */
        struct ldap_connection *conn = db_ldap_conn_find(set, ssl_set);