From 11ccf961047837f4b8d1ca768018b058dbe673fc Mon Sep 17 00:00:00 2001 From: Mark Valence Date: Wed, 28 Jun 2000 05:26:17 +0000 Subject: [PATCH] Updated attribute routine to pass back bervals. --- servers/slapd/back-ldap/attribute.c | 44 +++++++++++++++++++---------- servers/slapd/back-ldap/external.h | 2 +- servers/slapd/back-ldbm/attribute.c | 6 ++-- 3 files changed, 34 insertions(+), 18 deletions(-) diff --git a/servers/slapd/back-ldap/attribute.c b/servers/slapd/back-ldap/attribute.c index 8588a29120..df465f6619 100644 --- a/servers/slapd/back-ldap/attribute.c +++ b/servers/slapd/back-ldap/attribute.c @@ -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); } diff --git a/servers/slapd/back-ldap/external.h b/servers/slapd/back-ldap/external.h index 5aec1c2c87..bef70998bc 100644 --- a/servers/slapd/back-ldap/external.h +++ b/servers/slapd/back-ldap/external.h @@ -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 diff --git a/servers/slapd/back-ldbm/attribute.c b/servers/slapd/back-ldbm/attribute.c index 43bbf14bd5..a76d437415 100644 --- a/servers/slapd/back-ldbm/attribute.c +++ b/servers/slapd/back-ldbm/attribute.c @@ -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; } -- 2.39.5