]> granicus.if.org Git - apache/commitdiff
Keep track of the number of attributes retrieved from LDAP so that all the values...
authorBradley Nicholes <bnicholes@apache.org>
Wed, 9 Mar 2005 00:15:01 +0000 (00:15 +0000)
committerBradley Nicholes <bnicholes@apache.org>
Wed, 9 Mar 2005 00:15:01 +0000 (00:15 +0000)
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@156587 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
modules/ldap/util_ldap.c
modules/ldap/util_ldap_cache.c
modules/ldap/util_ldap_cache.h

diff --git a/CHANGES b/CHANGES
index a27be68a795fccbdd03501beb23acd7d80c6d265..7ef5afd99b7f2e03a37b8a9b4d61e80057bd34a7 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -2,6 +2,10 @@ Changes with Apache 2.1.4
 
   [Remove entries to the current 2.0 section below, when backported]
 
+  *) util_ldap: Keep track of the number of attributes retrieved from 
+     LDAP so that all the values can be properly cached even if the 
+     value is NULL. PR 33901 [Brad Nicholes]
+  
   *) mod_cache: Fix error where incoming Cache-Control would be ignored.
      [Justin Erenkrantz]
 
index 3a561fa85ccb163dae8985f0199517f7e2513101..18fd26abd528f4535e5dfd511ddcfb64fafa3e8c 100644 (file)
@@ -815,6 +815,7 @@ LDAP_DECLARE(int) util_ldap_cache_checkuserid(request_rec *r, util_ldap_connecti
                               const char ***retvals)
 {
     const char **vals = NULL;
+    int numvals = 0;
     int result = 0;
     LDAPMessage *res, *entry;
     char *dn;
@@ -977,6 +978,7 @@ start_over:
         int i = 0;
         while (attrs[k++]);
         vals = apr_pcalloc(r->pool, sizeof(char *) * (k+1));
+        numvals = k;
         while (attrs[i]) {
             char **values;
             int j = 0;
@@ -1004,6 +1006,7 @@ start_over:
         the_search_node.bindpw = bindpw;
         the_search_node.lastbind = apr_time_now();
         the_search_node.vals = vals;
+        the_search_node.numvals = numvals;
 
         /* Search again to make sure that another thread didn't ready insert this node
            into the cache before we got here. If it does exist then update the lastbind */
@@ -1046,6 +1049,7 @@ LDAP_DECLARE(int) util_ldap_cache_getuserdn(request_rec *r, util_ldap_connection
                               const char ***retvals)
 {
     const char **vals = NULL;
+    int numvals = 0;
     int result = 0;
     LDAPMessage *res, *entry;
     char *dn;
@@ -1160,6 +1164,7 @@ start_over:
         int i = 0;
         while (attrs[k++]);
         vals = apr_pcalloc(r->pool, sizeof(char *) * (k+1));
+        numvals = k;
         while (attrs[i]) {
             char **values;
             int j = 0;
@@ -1187,6 +1192,7 @@ start_over:
         the_search_node.bindpw = NULL;
         the_search_node.lastbind = apr_time_now();
         the_search_node.vals = vals;
+        the_search_node.numvals = numvals;
 
         /* Search again to make sure that another thread didn't ready insert this node
            into the cache before we got here. If it does exist then update the lastbind */
index 97cb83d61361cb57569ea8be2e1a7a87937ebb67..9adf20a4faad223184db499df58f949cac0e40fb 100644 (file)
@@ -159,18 +159,22 @@ void *util_ldap_search_node_copy(util_ald_cache_t *cache, void *c)
 
         /* copy vals */
         if (node->vals) {
-            int k = 0;
+            int k = node->numvals;
             int i = 0;
-            while (node->vals[k++]);
             if (!(newnode->vals = util_ald_alloc(cache, sizeof(char *) * (k+1)))) {
                 util_ldap_search_node_free(cache, newnode);
                 return NULL;
             }
-            while (node->vals[i]) {
-                if (!(newnode->vals[i] = util_ald_strdup(cache, node->vals[i]))) {
-                    util_ldap_search_node_free(cache, newnode);
-                    return NULL;
+            newnode->numvals = node->numvals;
+            for (;k;k--) {
+                if (node->vals[i]) {
+                    if (!(newnode->vals[i] = util_ald_strdup(cache, node->vals[i]))) {
+                        util_ldap_search_node_free(cache, newnode);
+                        return NULL;
+                    }
                 }
+                else
+                    newnode->vals[i] = NULL;
                 i++;
             }
         }
@@ -200,9 +204,12 @@ void util_ldap_search_node_free(util_ald_cache_t *cache, void *n)
 {
     int i = 0;
     util_search_node_t *node = (util_search_node_t *)n;
+    int k = node->numvals;
     if (node->vals) {
-        while (node->vals[i]) {
-            util_ald_free(cache, node->vals[i++]);
+        for (;k;k--,i++) {
+            if (node->vals[i]) {
+                util_ald_free(cache, node->vals[i]);
+            }
         }
         util_ald_free(cache, node->vals);
     }
index 478fbfc186df7ce66029a9a035a7b7783f7858b1..65580f574aa0be627f700ede66986ea8b6f79207 100644 (file)
@@ -107,6 +107,7 @@ typedef struct util_search_node_t {
                                           NULL if the bind failed */
     apr_time_t lastbind;               /* Time of last successful bind */
     const char **vals;                 /* Values of queried attributes */
+    int        numvals;         /* Number of queried attributes */
 } util_search_node_t;
 
 /*