]> git.sur5r.net Git - openldap/commitdiff
Updated attribute routine to pass back bervals.
authorMark Valence <mrv@openldap.org>
Wed, 28 Jun 2000 05:26:17 +0000 (05:26 +0000)
committerMark Valence <mrv@openldap.org>
Wed, 28 Jun 2000 05:26:17 +0000 (05:26 +0000)
servers/slapd/back-ldap/attribute.c
servers/slapd/back-ldap/external.h
servers/slapd/back-ldbm/attribute.c

index 8588a291209045010b2d01ef2af01154440f4cad..df465f6619b7f90352bd262314cb72e2b615498e 100644 (file)
@@ -27,14 +27,14 @@ ldap_back_attribute(
        Entry   *target,
        const char      *e_ndn,
        AttributeDescription *entry_at,
-       const char ***vals
+       struct berval ***vals
 )
 {
        struct ldapinfo *li = (struct ldapinfo *) be->be_private;    
-       int rc = 1, i, j;
+       int rc = 1, i, j, count;
        Attribute *attr;
-       struct berval **abv;
-       char *s, **v;
+       struct berval **abv, **v;
+       char **vs;
        LDAPMessage     *result, *e;
        char *gattr[2];
        LDAP *ld;
@@ -45,17 +45,14 @@ ldap_back_attribute(
                if ((attr = attr_find(target->e_attrs, entry_at)) == NULL)
                        return(1);
 
-               for ( i = 0; attr->a_vals[i] != NULL; i++ ) { }
-               v = (char **) ch_calloc( (i + 1), sizeof(char *) );
+               for ( count = 0; attr->a_vals[count] != NULL; count++ ) { }
+               v = (struct berval **) ch_calloc( (count + 1), sizeof(struct berval *) );
                if (v != NULL) {
-                       for ( j = 0, abv = attr->a_vals; --i >= 0; abv++ ) {
+                       for ( j = 0, abv = attr->a_vals; --count >= 0; abv++ ) {
                                if ( (*abv)->bv_len > 0 ) {
-                                       s = ch_malloc( (*abv)->bv_len + 1 );
-                                       if( s == NULL )
+                                       v[j] = ber_bvdup( *abv );
+                                       if( v[j] == NULL )
                                                break;
-                                       memcpy(s, (*abv)->bv_val, (*abv)->bv_len);
-                                       s[(*abv)->bv_len] = 0;
-                                       v[j++] = s;
                                }
                        }
                        v[j] = NULL;
@@ -76,9 +73,26 @@ ldap_back_attribute(
                                                                        LDAP_NO_LIMIT, &result) == LDAP_SUCCESS)
                        {
                                if ((e = ldap_first_entry(ld, result)) != NULL) {
-                                       *vals = ldap_get_values(ld, e, entry_at->ad_cname->bv_val);
-                                       if (*vals != NULL)
-                                               rc = 0;
+                                       vs = ldap_get_values(ld, e, entry_at->ad_cname->bv_val);
+                                       if (vs != NULL) {
+                                               for ( count = 0; vs[count] != NULL; count++ ) { }
+                                               v = (struct berval **) ch_calloc( (count + 1), sizeof(struct berval *) );
+                                               if (v == NULL) {
+                                                       ldap_value_free(vs);
+                                               } else {
+                                                       for ( i = 0, j = 0; i < count; i++) {
+                                                               v[j] = ber_bvstr( vs[i] );
+                                                               if( v[j] == NULL )
+                                                                       ch_free(vs[i]);
+                                                               else
+                                                                       j++;
+                                                       }
+                                                       v[j] = NULL;
+                                                       *vals = v;
+                                                       rc = 0;
+                                                       ch_free(vs);
+                                               }
+                                       }
                                }
                                ldap_msgfree(result);
                        }
index 5aec1c2c87d02339b3780b826a591eab786e511f..bef70998bc9b76e338bff841722340e774384e30 100644 (file)
@@ -67,7 +67,7 @@ extern int    ldap_back_attribute LDAP_P(( BackendDB *bd,
        Entry *target,
        const char* e_ndn,
        AttributeDescription* entry_at,
-       const char ***vals));
+       struct berval ***vals));
 
 LDAP_END_DECL
 
index 43bbf14bd539acd7e63018f37f1feff77b4e6950..a76d4374153f4eeb41b81d98f31950541113bae0 100644 (file)
@@ -116,8 +116,10 @@ ldbm_back_attribute(
        v = (struct berval **) ch_malloc( sizeof(struct berval *) * (i+1) );
 
        for ( i=0, j=0; attr->a_vals[i] != NULL; i++ ) {
-               if( access_allowed(be, conn, op, e, entry_at,
-                       attr->a_vals[i], ACL_READ) == 0)
+               if( conn != NULL
+                       && op != NULL
+                       && access_allowed(be, conn, op, e, entry_at,
+                               attr->a_vals[i], ACL_READ) == 0)
                {
                        continue;
                }