]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
auth: db-ldap - Restore prefixes to messages
authorMarco Bettini <marco.bettini@open-xchange.com>
Wed, 17 Jul 2024 14:39:01 +0000 (14:39 +0000)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Wed, 12 Feb 2025 10:34:13 +0000 (12:34 +0200)
(replaces previously removed conn->config_path)

src/auth/db-ldap.c

index 0bab12ba5783532efd508d1ca8a7ebbb1bef9e76..7765c8d9acc0827c24ae84d2fbae9b50f45bac7d 100644 (file)
@@ -837,34 +837,37 @@ static void db_ldap_get_fd(struct ldap_connection *conn)
        /* get the connection's fd */
        ret = ldap_get_option(conn->ld, LDAP_OPT_DESC, (void *)&conn->fd);
        if (ret != LDAP_SUCCESS) {
-               i_fatal("LDAP: Can't get connection fd: %s", ldap_err2string(ret));
+               i_fatal("ldap(%s): Can't get connection fd: %s",
+                       conn->set->uris, ldap_err2string(ret));
        }
        if (conn->fd <= STDERR_FILENO) {
                /* Solaris LDAP library seems to be broken */
-               i_fatal("LDAP: Buggy LDAP library returned wrong fd: %d", conn->fd);
+               i_fatal("ldap(%s): Buggy LDAP library returned wrong fd: %d",
+                       conn->set->uris, conn->fd);
        }
        i_assert(conn->fd != -1);
        net_set_nonblock(conn->fd, TRUE);
 }
 
-static void ATTR_NULL(0)
-db_ldap_set_opt(LDAP *ld, int opt, const void *value, const char *optname,
-               const char *value_str)
+static void ATTR_NULL(1)
+db_ldap_set_opt(struct ldap_connection *conn, LDAP *ld, int opt,
+               const void *value, const char *optname, const char *value_str)
 {
        int ret;
 
        ret = ldap_set_option(ld, opt, value);
        if (ret != LDAP_SUCCESS) {
-               i_fatal("LDAP: Can't set option %s to %s: %s",
-                       optname, value_str, ldap_err2string(ret));
+               i_fatal("ldap(%s): Can't set option %s to %s: %s",
+                       conn->set->uris, optname, value_str, ldap_err2string(ret));
        }
 }
 
-static void ATTR_NULL(0)
-db_ldap_set_opt_str(LDAP *ld, int opt, const char *value, const char *optname)
+static void ATTR_NULL(1)
+db_ldap_set_opt_str(struct ldap_connection *conn, LDAP *ld, int opt,
+                   const char *value, const char *optname)
 {
        if (*value != '\0')
-               db_ldap_set_opt(ld, opt, value, optname, value);
+               db_ldap_set_opt(conn, ld, opt, value, optname, value);
 }
 
 static void db_ldap_set_tls_options(struct ldap_connection *conn)
@@ -873,24 +876,24 @@ static void db_ldap_set_tls_options(struct ldap_connection *conn)
        if (!conn->set->starttls && strstr(conn->set->uris, "ldaps:") == NULL)
                return;
 
-       db_ldap_set_opt_str(NULL, LDAP_OPT_X_TLS_CACERTFILE,
+       db_ldap_set_opt_str(conn, NULL, LDAP_OPT_X_TLS_CACERTFILE,
                            conn->ssl_set->ssl_client_ca_file, "ssl_client_ca_file");
-       db_ldap_set_opt_str(NULL, LDAP_OPT_X_TLS_CACERTDIR,
+       db_ldap_set_opt_str(conn, NULL, LDAP_OPT_X_TLS_CACERTDIR,
                            conn->ssl_set->ssl_client_ca_dir, "ssl_client_ca_dir");
-       db_ldap_set_opt_str(NULL, LDAP_OPT_X_TLS_CERTFILE,
+       db_ldap_set_opt_str(conn, NULL, LDAP_OPT_X_TLS_CERTFILE,
                            conn->ssl_set->ssl_client_cert_file, "ssl_client_cert_file");
-       db_ldap_set_opt_str(NULL, LDAP_OPT_X_TLS_KEYFILE,
+       db_ldap_set_opt_str(conn, NULL, LDAP_OPT_X_TLS_KEYFILE,
                            conn->ssl_set->ssl_client_key_file, "ssl_client_key_file");
-       db_ldap_set_opt_str(NULL, LDAP_OPT_X_TLS_CIPHER_SUITE,
+       db_ldap_set_opt_str(conn, NULL, LDAP_OPT_X_TLS_CIPHER_SUITE,
                            conn->ssl_set->ssl_cipher_list, "ssl_cipher_list");
-       db_ldap_set_opt_str(NULL, LDAP_OPT_X_TLS_PROTOCOL_MIN,
+       db_ldap_set_opt_str(conn, NULL, LDAP_OPT_X_TLS_PROTOCOL_MIN,
                            conn->ssl_set->ssl_min_protocol, "ssl_min_protocol");
-       db_ldap_set_opt_str(NULL, LDAP_OPT_X_TLS_ECNAME,
+       db_ldap_set_opt_str(conn, NULL, LDAP_OPT_X_TLS_ECNAME,
                            conn->ssl_set->ssl_curve_list, "ssl_curve_list");
 
        bool requires = conn->ssl_set->ssl_client_require_valid_cert;
        int opt = requires ? LDAP_OPT_X_TLS_HARD : LDAP_OPT_X_TLS_ALLOW;
-       db_ldap_set_opt(NULL, LDAP_OPT_X_TLS_REQUIRE_CERT, &opt,
+       db_ldap_set_opt(conn, NULL, LDAP_OPT_X_TLS_REQUIRE_CERT, &opt,
                        "ssl_client_require_valid_cert", requires ? "yes" : "no" );
 #endif
 }
@@ -904,21 +907,22 @@ static void db_ldap_set_options(struct ldap_connection *conn)
        tv.tv_sec = DB_LDAP_CONNECT_TIMEOUT_SECS; tv.tv_usec = 0;
        ret = ldap_set_option(conn->ld, LDAP_OPT_NETWORK_TIMEOUT, &tv);
        if (ret != LDAP_SUCCESS)
-               i_fatal("LDAP: Can't set network-timeout: %s", ldap_err2string(ret));
+               i_fatal("ldap(%s): Can't set network-timeout: %s",
+                       conn->set->uris, ldap_err2string(ret));
 #endif
 
-       db_ldap_set_opt(conn->ld, LDAP_OPT_DEREF, &conn->set->parsed_deref,
+       db_ldap_set_opt(conn, conn->ld, LDAP_OPT_DEREF, &conn->set->parsed_deref,
                        "ldap_deref", conn->set->deref);
 #ifdef LDAP_OPT_DEBUG_LEVEL
        int debug_level;
        if (str_to_int(conn->set->debug_level, &debug_level) >= 0 && debug_level != 0) {
-               db_ldap_set_opt(NULL, LDAP_OPT_DEBUG_LEVEL, &debug_level,
+               db_ldap_set_opt(conn, NULL, LDAP_OPT_DEBUG_LEVEL, &debug_level,
                                "ldap_debug_level", conn->set->debug_level);
                event_set_forced_debug(conn->event, TRUE);
        }
 #endif
 
-       db_ldap_set_opt(conn->ld, LDAP_OPT_PROTOCOL_VERSION,
+       db_ldap_set_opt(conn, conn->ld, LDAP_OPT_PROTOCOL_VERSION,
                        &conn->set->version,
                        "ldap_version", dec2str(conn->set->version));
        db_ldap_set_tls_options(conn);
@@ -928,7 +932,7 @@ static void db_ldap_init_ld(struct ldap_connection *conn)
 {
        int ret = ldap_initialize(&conn->ld, conn->set->uris);
        if (ret != LDAP_SUCCESS) {
-               i_fatal("LDAP: ldap_initialize() failed with uris %s: %s",
+               i_fatal("ldap(%s): ldap_initialize() failed: %s",
                        conn->set->uris, ldap_err2string(ret));
        }
        db_ldap_set_options(conn);
@@ -959,7 +963,9 @@ int db_ldap_connect(struct ldap_connection *conn)
                        if (ret == LDAP_OPERATIONS_ERROR &&
                            *conn->set->uris != '\0' &&
                            str_begins_with(conn->set->uris, "ldaps:")) {
-                               i_fatal("LDAP: Don't use both ldap_starttls=yes and ldaps URI");
+                               i_fatal("ldap(%s): "
+                                       "Don't use both ldap_starttls=yes and ldaps URI",
+                                       conn->set->uris);
                        }
                        e_error(conn->event, "ldap_start_tls_s() failed: %s",
                                ldap_err2string(ret));
@@ -1552,7 +1558,7 @@ struct ldap_connection *db_ldap_init(struct event *event)
        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);
+               i_fatal("ldap(%s): %s", set->uris, error);
 
        /* see if it already exists */
        struct ldap_connection *conn = db_ldap_conn_find(set, ssl_set);