From: Howard Chu Date: Fri, 5 Dec 2025 10:31:13 +0000 (+0000) Subject: ITS#9305 libldap: report errmsg from hostname lookup failures X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b0e95d023a78a553c07257e14c05e9a1af09e299;p=thirdparty%2Fopenldap.git ITS#9305 libldap: report errmsg from hostname lookup failures Use new LDAP_X_SERVER_UNKNOWN error code for failed lookups. --- diff --git a/include/ldap.h b/include/ldap.h index a482b2bf55..521bc0caba 100644 --- a/include/ldap.h +++ b/include/ldap.h @@ -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) /* diff --git a/libraries/libldap/error.c b/libraries/libldap/error.c index 9ca2af9c5b..011a3c86d3 100644 --- a/libraries/libldap/error.c +++ b/libraries/libldap/error.c @@ -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: diff --git a/libraries/libldap/os-ip.c b/libraries/libldap/os-ip.c index 629b540352..89f36eba0b 100644 --- a/libraries/libldap/os-ip.c +++ b/libraries/libldap/os-ip.c @@ -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; }