]> git.ipfire.org Git - thirdparty/openldap.git/commitdiff
ITS#9305 libldap: report errmsg from hostname lookup failures
authorHoward Chu <hyc@openldap.org>
Fri, 5 Dec 2025 10:31:13 +0000 (10:31 +0000)
committerQuanah Gibson-Mount <quanah@openldap.org>
Tue, 9 Dec 2025 15:06:05 +0000 (15:06 +0000)
Use new LDAP_X_SERVER_UNKNOWN error code for failed lookups.

include/ldap.h
libraries/libldap/error.c
libraries/libldap/os-ip.c

index a482b2bf55a9d6198b9ba50991421aae2c8a4ea9..521bc0cabaea9b4a9a81b662573a66fb7cca9f32 100644 (file)
@@ -751,6 +751,7 @@ typedef struct ldapcontrol {
 #define LDAP_CLIENT_LOOP                               (-16)
 #define LDAP_REFERRAL_LIMIT_EXCEEDED   (-17)
 #define        LDAP_X_CONNECTING                       (-18)
+#define        LDAP_X_SERVER_UNKNOWN                   (-19)
 
 
 /*
index 9ca2af9c5b65e3bedddfee7223d93471e4dc88e4..011a3c86d38185af13f88422f1a615a06d83f9dc 100644 (file)
@@ -148,6 +148,7 @@ ldap_err2string( int err )
        C(LDAP_CLIENT_LOOP,                             N_("Client Loop"));
        C(LDAP_REFERRAL_LIMIT_EXCEEDED, N_("Referral Limit Exceeded"));
        C(LDAP_X_CONNECTING,                    N_("Connecting (X)"));
+       C(LDAP_X_SERVER_UNKNOWN,                N_("Unknown server (X)"));
 #      undef C
 
        default:
index 629b540352484f85cb1b50e4b191e00de4fef832..89f36eba0b698824b2165230ad50249e0ae240fa 100644 (file)
@@ -632,6 +632,7 @@ ldap_connect_to_host(LDAP *ld, Sockbuf *sb,
                Debug1(LDAP_DEBUG_TRACE,
                        "ldap_connect_to_host: unknown proto: %d\n",
                        proto );
+               ld->ld_errno = LDAP_X_SERVER_UNKNOWN;
                return -1;
        }
 
@@ -653,9 +654,14 @@ ldap_connect_to_host(LDAP *ld, Sockbuf *sb,
        LDAP_MUTEX_UNLOCK(&ldap_int_resolv_mutex);
 
        if ( err != 0 ) {
+               if ( ld->ld_error )
+                       LDAP_FREE( ld->ld_error );
+               ld->ld_error = LDAP_STRDUP( AC_GAI_STRERROR( err ));
                Debug1(LDAP_DEBUG_TRACE,
                        "ldap_connect_to_host: getaddrinfo failed: %s\n",
-                       AC_GAI_STRERROR(err) );
+                       ld->ld_error );
+               ld->ld_errno = LDAP_X_SERVER_UNKNOWN;
+
                return -1;
        }
        rc = -1;
@@ -768,10 +774,16 @@ ldap_connect_to_host(LDAP *ld, Sockbuf *sb,
 #ifdef HAVE_WINSOCK
                        ldap_pvt_set_errno( WSAGetLastError() );
 #else
+#ifdef HAVE_HSTRERROR
+                       if ( ld->ld_error )
+                               LDAP_FREE( ld->ld_error );
+                       ld->ld_error = LDAP_STRDUP( h_strerror( local_h_errno ));
+#endif
                        /* not exactly right, but... */
                        ldap_pvt_set_errno( EHOSTUNREACH );
 #endif
                        if (ha_buf) LDAP_FREE(ha_buf);
+                       ld->ld_errno = LDAP_X_SERVER_UNKNOWN;
                        return -1;
                }