ldap/servers/slapd/ldaputil.c | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-)
New commits: commit 996034bc98d0f2ef33bdf70ae226fd4410b88075 Author: Noriko Hosoi nhosoi@redhat.com Date: Fri Nov 2 16:43:48 2012 -0700
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 [<binddn>] mech [SIMPLE]: error -1 (Can't contact LDAP server) -5987 (Invalid function argument.) 107 (Transport endpoint is not connected "your_host_name")
diff --git a/ldap/servers/slapd/ldaputil.c b/ldap/servers/slapd/ldaputil.c index 7d77644..1c67e51 100644 --- a/ldap/servers/slapd/ldaputil.c +++ b/ldap/servers/slapd/ldaputil.c @@ -1083,15 +1083,42 @@ 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) { + 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; }
389-commits@lists.fedoraproject.org