Commit 8d663746 authored by Jim Jagielski's avatar Jim Jagielski
Browse files

Merge r472633 from trunk:

Better detection and clean up of ldap connection that have been
terminated by the ldap server. PR#40878

Submitted by: Rob Baily <rbaily servicebench com>
Reviewed by: bnicholes


Submitted by: bnicholes
Reviewed by: jim


git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.2.x@484981 13f79535-47bb-0310-9956-ffa450edef68
parent 9b58c46b
Loading
Loading
Loading
Loading
+4 −0
Changes for CHANGES: 4 added lines, 0 removed lines.
Original line number Diff line number Diff line
                                                        -*- coding: utf-8 -*-
Changes with Apache 2.2.4
  *) Better detection and clean up of ldap connection that has been
     terminated by the ldap server.  PR 40878.
     [Rob Baily <rbaily servicebench com>]
  *) mod_mem_cache: Convert mod_mem_cache to use APR memory pool functions
     by creating a root pool for object persistence across requests. This
     also eliminates the need for custom serialization code.
+0 −7
Changes for STATUS: 0 added lines, 7 removed lines.
Original line number Diff line number Diff line
@@ -89,13 +89,6 @@ PATCHES ACCEPTED TO BACKPORT FROM TRUNK:
     Cumulative patch: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/database/mod_dbd.c?r1=466641&r2=420983&pathrev=466641
     +1: minfrin, niq, wrowe

   * mod_ldap: Better detection and clean up of ldap connection
     that have been terminated by the ldap server.
     http://svn.apache.org/viewvc?view=rev&revision=472633
     +1: bnicholes, jim, wrowe
     wrowe adds; keeping the old idents for backporting would have
                 made this alot easier for review - mind \x09's please.

PATCHES PROPOSED TO BACKPORT FROM TRUNK:

    * mpm_winnt: Fix return values from wait_for_many_objects.
+48 −35
Changes for modules/ldap/util_ldap.c: 48 added lines, 35 removed lines.
Original line number Diff line number Diff line
@@ -198,18 +198,10 @@ static apr_status_t uldap_connection_cleanup(void *param)
    return APR_SUCCESS;
}


/*
 * Connect to the LDAP server and binds. Does not connect if already
 * connected (i.e. ldc->ldap is non-NULL.) Does not bind if already bound.
 *
 * Returns LDAP_SUCCESS on success; and an error code on failure
 */
static int uldap_connection_open(request_rec *r,
static int uldap_connection_init(request_rec *r,
                                          util_ldap_connection_t *ldc )
{
    int rc = 0;
    int failures = 0;
    int version  = LDAP_VERSION3;
    apr_ldap_err_t *result = NULL;
    struct timeval timeOut = {10,0};    /* 10 second connection timeout */
@@ -217,23 +209,6 @@ static int uldap_connection_open(request_rec *r,
        (util_ldap_state_t *)ap_get_module_config(r->server->module_config,
        &ldap_module);

    /* sanity check for NULL */
    if (!ldc) {
        return -1;
    }

    /* If the connection is already bound, return
    */
    if (ldc->bound)
    {
        ldc->reason = "LDAP: connection open successful (already bound)";
        return LDAP_SUCCESS;
    }

    /* create the ldap session handle
    */
    if (NULL == ldc->ldap)
    {
    /* Since the host will include a port if the default port is not used,
     * always specify the default ports for the port parameter.  This will
     * allow a host string that contains multiple hosts the ability to mix
@@ -271,9 +246,7 @@ static int uldap_connection_open(request_rec *r,
        apr_ldap_set_option(ldc->pool, ldc->ldap, APR_LDAP_OPT_TLS_CERT,
                            ldc->client_certs, &(result));
        if (LDAP_SUCCESS != result->rc) {
                ldap_unbind_s(ldc->ldap);
                ldc->ldap = NULL;
                ldc->bound = 0;
            uldap_connection_unbind( ldc );
            ldc->reason = result->reason;
            return(result->rc);
        }
@@ -284,9 +257,7 @@ static int uldap_connection_open(request_rec *r,
        apr_ldap_set_option(ldc->pool, ldc->ldap,
                            APR_LDAP_OPT_TLS, &ldc->secure, &(result));
        if (LDAP_SUCCESS != result->rc) {
                ldap_unbind_s(ldc->ldap);
                ldc->ldap = NULL;
                ldc->bound = 0;
            uldap_connection_unbind( ldc );
            ldc->reason = result->reason;
            return(result->rc);
        }
@@ -336,7 +307,43 @@ static int uldap_connection_open(request_rec *r,
    }
#endif

    return(rc);
}

/*
 * Connect to the LDAP server and binds. Does not connect if already
 * connected (i.e. ldc->ldap is non-NULL.) Does not bind if already bound.
 *
 * Returns LDAP_SUCCESS on success; and an error code on failure
 */
static int uldap_connection_open(request_rec *r,
                                 util_ldap_connection_t *ldc)
{
    int rc = 0;
    int failures = 0;

    /* sanity check for NULL */
    if (!ldc) {
        return -1;
    }

    /* If the connection is already bound, return
    */
    if (ldc->bound)
    {
        ldc->reason = "LDAP: connection open successful (already bound)";
        return LDAP_SUCCESS;
    }

    /* create the ldap session handle
    */
    if (NULL == ldc->ldap)
    {
       rc = uldap_connection_init( r, ldc );
       if (LDAP_SUCCESS != rc)
       {
           return rc;
       }
    }


@@ -355,6 +362,14 @@ static int uldap_connection_open(request_rec *r,
                                (char *)ldc->bindpw);
        if (LDAP_SERVER_DOWN != rc) {
            break;
        } else if (failures == 5) {
           /* attempt to init the connection once again */
           uldap_connection_unbind( ldc );
           rc = uldap_connection_init( r, ldc );
           if (LDAP_SUCCESS != rc)
           {
               break;
           }
       }
    }

@@ -362,9 +377,7 @@ static int uldap_connection_open(request_rec *r,
    */
    if (LDAP_SUCCESS != rc)
    {
        ldap_unbind_s(ldc->ldap);
        ldc->ldap = NULL;
        ldc->bound = 0;
       uldap_connection_unbind(ldc);
        ldc->reason = "LDAP: ldap_simple_bind_s() failed";
    }
    else {