From ef11594011b589c484d092afdd9f23ae11f21487 Mon Sep 17 00:00:00 2001 From: Noriko Hosoi Date: Fri, 2 Nov 2012 12:15:03 -0700 Subject: [PATCH] Trac Ticket #190 - Un-resolvable server in replication agreement produces unclear error message https://fedorahosted.org/389/ticket/190 Fix description: This patch retrieves more info such as hostname and error code from getaddrinfo in case ldap_sasl_bind does not return any useful information about the failure. E.g., Error: could not send bind request for id [(anon)] mech [EXTERNAL]: error -1 (Can't contact LDAP server) -5987 (Invalid function argument.) -2 (Name or service not known "your_host_name") Error: could not send bind request for id [] mech [SIMPLE]: error -1 (Can't contact LDAP server) -5987 (Invalid function argument.) 107 (Transport endpoint is not connected "your_host_name") --- ldap/servers/slapd/ldaputil.c | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/ldap/servers/slapd/ldaputil.c b/ldap/servers/slapd/ldaputil.c index 7d77644..3d3b3c0 100644 --- a/ldap/servers/slapd/ldaputil.c +++ b/ldap/servers/slapd/ldaputil.c @@ -1083,15 +1083,43 @@ slapi_ldap_bind( mech ? mech : "SIMPLE", bindid, creds); if ((rc = ldap_sasl_bind(ld, bindid, mech, &bvcreds, serverctrls, - NULL /* clientctrls */, &mymsgid))) { + NULL /* clientctrls */, &mymsgid))) { + char *myhostname = NULL; + char *copy = NULL; + char *ptr = NULL; + int myerrno = errno; + int gaierr; + + ldap_get_option(ld, LDAP_OPT_HOST_NAME, &myhostname); + if (myhostname) { + PRAddrInfo *infop; + ptr = strchr(myhostname, ':'); + if (ptr) { + copy = slapi_ch_strdup(myhostname); + *(copy + (ptr - myhostname)) = '\0'; + myhostname = copy; + } + } + + if (0 == myerrno) { + struct addrinfo *result = NULL; + gaierr = getaddrinfo(myhostname, NULL, NULL, &result); + myerrno = errno; + if (result) { + freeaddrinfo(result); + } + } slapi_log_error(SLAPI_LOG_FATAL, "slapi_ldap_bind", "Error: could not send bind request for id " - "[%s] mech [%s]: error %d (%s) %d (%s) %d (%s)\n", + "[%s] mech [%s]: error %d (%s) %d (%s) %d (%s \"%s\")\n", bindid ? bindid : "(anon)", mech ? mech : "SIMPLE", rc, ldap_err2string(rc), PR_GetError(), slapd_pr_strerror(PR_GetError()), - errno, slapd_system_strerror(errno)); + myerrno ? myerrno : gaierr, + myerrno ? slapd_system_strerror(myerrno) : gai_strerror(gaierr), + myhostname ? myhostname : "unknown host"); + slapi_ch_free_string(©); goto done; } -- 1.7.11.7