ITS#9305 libldap: report errmsg from hostname lookup failures

Use new LDAP_X_SERVER_UNKNOWN error code for failed lookups.
This commit is contained in:
Howard Chu 2025-12-05 10:31:13 +00:00 committed by Quanah Gibson-Mount
parent b3821e772a
commit b0e95d023a
3 changed files with 15 additions and 1 deletions

View 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)
/*

View 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:

View 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;
}