]> granicus.if.org Git - apache/commitdiff
add a static method to retrieve the LDAP errno, and call from a
authorEric Covener <covener@apache.org>
Sun, 14 Aug 2011 22:03:02 +0000 (22:03 +0000)
committerEric Covener <covener@apache.org>
Sun, 14 Aug 2011 22:03:02 +0000 (22:03 +0000)
few other paths that have us returning LDAP_OTHER (since
only 'server down' is retryable, we want to work hard to get
it returned when appropriate)

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1157677 13f79535-47bb-0310-9956-ffa450edef68

modules/ldap/util_ldap.c

index e0185949c3b6ab5f3d84b6ba010fa324282053da..a5d226438e985ba55278542eee7bce42dd02250f 100644 (file)
@@ -449,6 +449,17 @@ static int uldap_connection_init(request_rec *r,
     return(rc);
 }
 
+static int lderrno(util_ldap_connection_t *ldc) 
+{ 
+    int ldaprc;
+#ifdef LDAP_OPT_ERROR_NUMBER
+    if (LDAP_SUCCESS == ldap_get_option(ldc->ldap, LDAP_OPT_ERROR_NUMBER, &ldaprc)) return ldaprc;
+#endif
+#ifdef LDAP_OPT_RESULT_CODE
+    if (LDAP_SUCCESS == ldap_get_option(ldc->ldap, LDAP_OPT_RESULT_CODE, &ldaprc)) return ldaprc;
+#endif
+    return LDAP_OTHER;
+}
 /*
  * Replacement function for ldap_simple_bind_s() with a timeout.
  * To do this in a portable way, we have to use ldap_simple_bind() and 
@@ -463,22 +474,14 @@ static int uldap_simple_bind(util_ldap_connection_t *ldc, char *binddn,
     int rc;
     int msgid = ldap_simple_bind(ldc->ldap, binddn, bindpw);
     if (msgid == -1) {
-        int ldaprc;
         ldc->reason = "LDAP: ldap_simple_bind() failed";
-#ifdef LDAP_OPT_ERROR_NUMBER
-        if (LDAP_SUCCESS == ldap_get_option(ldc->ldap, LDAP_OPT_ERROR_NUMBER, &ldaprc)) return ldaprc;
-#endif
-#ifdef LDAP_OPT_RESULT_CODE
-        if (LDAP_SUCCESS == ldap_get_option(ldc->ldap, LDAP_OPT_RESULT_CODE, &ldaprc)) return ldaprc;
-#endif
-        /* -1 is LDAP_SERVER_DOWN in openldap, use something else */
-        return LDAP_OTHER;
+        return lderrno(ldc);
     }
     rc = ldap_result(ldc->ldap, msgid, 0, timeout, &result);
     if (rc == -1) {
         ldc->reason = "LDAP: ldap_simple_bind() result retrieval failed";
         /* -1 is LDAP_SERVER_DOWN in openldap, use something else */
-        rc = LDAP_OTHER;
+        return lderrno(ldc);
     }
     else if (rc == 0) {
         ldc->reason = "LDAP: ldap_simple_bind() timed out";
@@ -486,6 +489,7 @@ static int uldap_simple_bind(util_ldap_connection_t *ldc, char *binddn,
     } else if (ldap_parse_result(ldc->ldap, result, &rc, NULL, NULL, NULL,
                                  NULL, 1) == -1) {
         ldc->reason = "LDAP: ldap_simple_bind() parse result failed";
+        return lderrno(ldc);
     }
     return rc;
 }