Return-Path: Delivered-To: apmail-httpd-cvs-archive@httpd.apache.org Received: (qmail 72859 invoked by uid 500); 24 Feb 2003 23:19:33 -0000 Mailing-List: contact cvs-help@httpd.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@httpd.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list cvs@httpd.apache.org Received: (qmail 72840 invoked by uid 500); 24 Feb 2003 23:19:33 -0000 Delivered-To: apmail-httpd-2.0-cvs@apache.org Date: 24 Feb 2003 23:19:31 -0000 Message-ID: <20030224231931.28415.qmail@icarus.apache.org> From: bnicholes@apache.org To: httpd-2.0-cvs@apache.org Subject: cvs commit: httpd-2.0/modules/experimental util_ldap.c X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N bnicholes 2003/02/24 15:19:31 Modified: modules/experimental util_ldap.c Log: Don't try to use the LDAP cache if it has been turned off. Make sure that we have a "curl" before trying to use it. If caching has been turned off then the curl variable will be NULL. This fixes a problem where LDAP caching would fault when caching was disabled. Revision Changes Path 1.12 +103 -91 httpd-2.0/modules/experimental/util_ldap.c Index: util_ldap.c =================================================================== RCS file: /home/cvs/httpd-2.0/modules/experimental/util_ldap.c,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- util_ldap.c 14 Feb 2003 16:04:01 -0000 1.11 +++ util_ldap.c 24 Feb 2003 23:19:30 -0000 1.12 @@ -536,23 +536,25 @@ } } - /* no - it's a server side compare */ - LDAP_CACHE_RDLOCK(); - - /* is it in the compare cache? */ - newnode.reqdn = (char *)reqdn; - node = util_ald_cache_fetch(curl->dn_compare_cache, &newnode); - if (node != NULL) { - /* If it's in the cache, it's good */ + if (curl) { + /* no - it's a server side compare */ + LDAP_CACHE_RDLOCK(); + + /* is it in the compare cache? */ + newnode.reqdn = (char *)reqdn; + node = util_ald_cache_fetch(curl->dn_compare_cache, &newnode); + if (node != NULL) { + /* If it's in the cache, it's good */ + /* unlock this read lock */ + LDAP_CACHE_UNLOCK(); + ldc->reason = "DN Comparison TRUE (cached)"; + return LDAP_COMPARE_TRUE; + } + /* unlock this read lock */ LDAP_CACHE_UNLOCK(); - ldc->reason = "DN Comparison TRUE (cached)"; - return LDAP_COMPARE_TRUE; } - /* unlock this read lock */ - LDAP_CACHE_UNLOCK(); - start_over: if (failures++ > 10) { /* too many failures */ @@ -589,12 +591,14 @@ result = LDAP_COMPARE_FALSE; } else { - /* compare successful - add to the compare cache */ - LDAP_CACHE_RDLOCK(); - newnode.reqdn = (char *)reqdn; - newnode.dn = (char *)dn; - util_ald_cache_insert(curl->dn_compare_cache, &newnode); - LDAP_CACHE_UNLOCK(); + if (curl) { + /* compare successful - add to the compare cache */ + LDAP_CACHE_RDLOCK(); + newnode.reqdn = (char *)reqdn; + newnode.dn = (char *)dn; + util_ald_cache_insert(curl->dn_compare_cache, &newnode); + LDAP_CACHE_UNLOCK(); + } ldc->reason = "DN Comparison TRUE (checked on server)"; result = LDAP_COMPARE_TRUE; } @@ -639,47 +643,49 @@ } LDAP_CACHE_UNLOCK(); - /* make a comparison to the cache */ - LDAP_CACHE_RDLOCK(); - curtime = apr_time_now(); - - the_compare_node.dn = (char *)dn; - the_compare_node.attrib = (char *)attrib; - the_compare_node.value = (char *)value; - the_compare_node.result = 0; - - compare_nodep = util_ald_cache_fetch(curl->compare_cache, &the_compare_node); - - if (compare_nodep != NULL) { - /* found it... */ - if (curtime - compare_nodep->lastcompare > st->compare_cache_ttl) { - /* ...but it is too old */ - util_ald_cache_remove(curl->compare_cache, compare_nodep); - } - else { - /* ...and it is good */ - /* unlock this read lock */ - LDAP_CACHE_UNLOCK(); - if (LDAP_COMPARE_TRUE == compare_nodep->result) { - ldc->reason = "Comparison true (cached)"; - return compare_nodep->result; - } - else if (LDAP_COMPARE_FALSE == compare_nodep->result) { - ldc->reason = "Comparison false (cached)"; - return compare_nodep->result; - } - else if (LDAP_NO_SUCH_ATTRIBUTE == compare_nodep->result) { - ldc->reason = "Comparison no such attribute (cached)"; - return compare_nodep->result; + if (curl) { + /* make a comparison to the cache */ + LDAP_CACHE_RDLOCK(); + curtime = apr_time_now(); + + the_compare_node.dn = (char *)dn; + the_compare_node.attrib = (char *)attrib; + the_compare_node.value = (char *)value; + the_compare_node.result = 0; + + compare_nodep = util_ald_cache_fetch(curl->compare_cache, &the_compare_node); + + if (compare_nodep != NULL) { + /* found it... */ + if (curtime - compare_nodep->lastcompare > st->compare_cache_ttl) { + /* ...but it is too old */ + util_ald_cache_remove(curl->compare_cache, compare_nodep); } else { - ldc->reason = "Comparison undefined (cached)"; - return compare_nodep->result; + /* ...and it is good */ + /* unlock this read lock */ + LDAP_CACHE_UNLOCK(); + if (LDAP_COMPARE_TRUE == compare_nodep->result) { + ldc->reason = "Comparison true (cached)"; + return compare_nodep->result; + } + else if (LDAP_COMPARE_FALSE == compare_nodep->result) { + ldc->reason = "Comparison false (cached)"; + return compare_nodep->result; + } + else if (LDAP_NO_SUCH_ATTRIBUTE == compare_nodep->result) { + ldc->reason = "Comparison no such attribute (cached)"; + return compare_nodep->result; + } + else { + ldc->reason = "Comparison undefined (cached)"; + return compare_nodep->result; + } } } + /* unlock this read lock */ + LDAP_CACHE_UNLOCK(); } - /* unlock this read lock */ - LDAP_CACHE_UNLOCK(); start_over: if (failures++ > 10) { @@ -703,12 +709,14 @@ if ((LDAP_COMPARE_TRUE == result) || (LDAP_COMPARE_FALSE == result) || (LDAP_NO_SUCH_ATTRIBUTE == result)) { - /* compare completed; caching result */ - LDAP_CACHE_WRLOCK(); - the_compare_node.lastcompare = curtime; - the_compare_node.result = result; - util_ald_cache_insert(curl->compare_cache, &the_compare_node); - LDAP_CACHE_UNLOCK(); + if (curl) { + /* compare completed; caching result */ + LDAP_CACHE_WRLOCK(); + the_compare_node.lastcompare = curtime; + the_compare_node.result = result; + util_ald_cache_insert(curl->compare_cache, &the_compare_node); + LDAP_CACHE_UNLOCK(); + } if (LDAP_COMPARE_TRUE == result) { ldc->reason = "Comparison true (adding to cache)"; return LDAP_COMPARE_TRUE; @@ -758,37 +766,39 @@ } LDAP_CACHE_UNLOCK(); - LDAP_CACHE_RDLOCK(); - the_search_node.username = filter; - search_nodep = util_ald_cache_fetch(curl->search_cache, &the_search_node); - if (search_nodep != NULL && search_nodep->bindpw) { - - /* found entry in search cache... */ - curtime = apr_time_now(); - - /* - * Remove this item from the cache if its expired, or if the - * sent password doesn't match the storepassword. - */ - if ((curtime - search_nodep->lastbind) > st->search_cache_ttl) { - /* ...but entry is too old */ - util_ald_cache_remove(curl->search_cache, search_nodep); - } - else if (strcmp(search_nodep->bindpw, bindpw) != 0) { - /* ...but cached password doesn't match sent password */ - util_ald_cache_remove(curl->search_cache, search_nodep); - } - else { - /* ...and entry is valid */ - *binddn = search_nodep->dn; - *retvals = search_nodep->vals; - LDAP_CACHE_UNLOCK(); - ldc->reason = "Authentication successful (cached)"; - return LDAP_SUCCESS; + if (curl) { + LDAP_CACHE_RDLOCK(); + the_search_node.username = filter; + search_nodep = util_ald_cache_fetch(curl->search_cache, &the_search_node); + if (search_nodep != NULL && search_nodep->bindpw) { + + /* found entry in search cache... */ + curtime = apr_time_now(); + + /* + * Remove this item from the cache if its expired, or if the + * sent password doesn't match the storepassword. + */ + if ((curtime - search_nodep->lastbind) > st->search_cache_ttl) { + /* ...but entry is too old */ + util_ald_cache_remove(curl->search_cache, search_nodep); + } + else if (strcmp(search_nodep->bindpw, bindpw) != 0) { + /* ...but cached password doesn't match sent password */ + util_ald_cache_remove(curl->search_cache, search_nodep); + } + else { + /* ...and entry is valid */ + *binddn = search_nodep->dn; + *retvals = search_nodep->vals; + LDAP_CACHE_UNLOCK(); + ldc->reason = "Authentication successful (cached)"; + return LDAP_SUCCESS; + } } + /* unlock this read lock */ + LDAP_CACHE_UNLOCK(); } - /* unlock this read lock */ - LDAP_CACHE_UNLOCK(); /* * At this point, there is no valid cached search, so lets do the search. @@ -909,7 +919,9 @@ the_search_node.bindpw = bindpw; the_search_node.lastbind = apr_time_now(); the_search_node.vals = vals; - util_ald_cache_insert(curl->search_cache, &the_search_node); + if (curl) { + util_ald_cache_insert(curl->search_cache, &the_search_node); + } ldap_msgfree(res); LDAP_CACHE_UNLOCK();