X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fattr.c;h=5cf97ec67e6d00f63af0ef264ac3918605a57e53;hb=58886b6a9c7c6b8e9e829fe24fe057e5a77b6117;hp=78784736b2d54ba628d5428697182ba26aff7dee;hpb=cb3248f173c03bad9bef639105b44aa05f8e8262;p=openldap diff --git a/servers/slapd/attr.c b/servers/slapd/attr.c index 78784736b2..5cf97ec67e 100644 --- a/servers/slapd/attr.c +++ b/servers/slapd/attr.c @@ -181,15 +181,10 @@ attrs_free( Attribute *a ) } } -Attribute * -attr_dup( Attribute *a ) -{ - Attribute *tmp; - - if ( a == NULL) return NULL; - - tmp = attr_alloc( a->a_desc ); +static void +attr_dup2( Attribute *tmp, Attribute *a ) +{ if ( a->a_vals != NULL ) { int i; @@ -224,31 +219,43 @@ attr_dup( Attribute *a ) } else { tmp->a_nvals = tmp->a_vals; } - - } else { - tmp->a_vals = NULL; - tmp->a_nvals = NULL; } +} + +Attribute * +attr_dup( Attribute *a ) +{ + Attribute *tmp; + + if ( a == NULL) return NULL; + + tmp = attr_alloc( a->a_desc ); + attr_dup2( tmp, a ); return tmp; } Attribute * attrs_dup( Attribute *a ) { - Attribute *tmp, **next; + int i; + Attribute *tmp, *anew; if( a == NULL ) return NULL; - tmp = NULL; - next = &tmp; + /* count them */ + for( tmp=a,i=0; tmp; tmp=tmp->a_next ) { + i++; + } + + anew = attrs_alloc( i ); - for( ; a != NULL ; a = a->a_next ) { - *next = attr_dup( a ); - next = &((*next)->a_next); + for( tmp=anew; a; a=a->a_next ) { + tmp->a_desc = a->a_desc; + attr_dup2( tmp, a ); + tmp=tmp->a_next; } - *next = NULL; - return tmp; + return anew; } @@ -307,15 +314,22 @@ attr_merge( return rc; } +/* + * if a normalization function is defined for the equality matchingRule + * of desc, the value is normalized and stored in nval; otherwise nval + * is NULL + */ int -attr_merge_normalize( - Entry *e, - AttributeDescription *desc, - BerVarray vals, - void *memctx ) +attr_normalize( + AttributeDescription *desc, + BerVarray vals, + BerVarray *nvalsp, + void *memctx ) { + int rc = LDAP_SUCCESS; BerVarray nvals = NULL; - int rc; + + *nvalsp = NULL; if ( desc->ad_type->sat_equality && desc->ad_type->sat_equality->smr_normalize ) @@ -326,7 +340,7 @@ attr_merge_normalize( nvals = slap_sl_calloc( sizeof(struct berval), i + 1, memctx ); for ( i = 0; !BER_BVISNULL( &vals[i] ); i++ ) { - rc = (*desc->ad_type->sat_equality->smr_normalize)( + rc = desc->ad_type->sat_equality->smr_normalize( SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX, desc->ad_type->sat_syntax, desc->ad_type->sat_equality, @@ -334,18 +348,39 @@ attr_merge_normalize( if ( rc != LDAP_SUCCESS ) { BER_BVZERO( &nvals[i + 1] ); - goto error_return; + break; } } BER_BVZERO( &nvals[i] ); + *nvalsp = nvals; } - rc = attr_merge( e, desc, vals, nvals ); - error_return:; - if ( nvals != NULL ) { + if ( rc != LDAP_SUCCESS && nvals != NULL ) { ber_bvarray_free_x( nvals, memctx ); } + + return rc; +} + +int +attr_merge_normalize( + Entry *e, + AttributeDescription *desc, + BerVarray vals, + void *memctx ) +{ + BerVarray nvals = NULL; + int rc; + + rc = attr_normalize( desc, vals, &nvals, memctx ); + if ( rc == LDAP_SUCCESS ) { + rc = attr_merge( e, desc, vals, nvals ); + if ( nvals != NULL ) { + ber_bvarray_free_x( nvals, memctx ); + } + } + return rc; } @@ -382,29 +417,52 @@ attr_merge_one( return rc; } +/* + * if a normalization function is defined for the equality matchingRule + * of desc, the value is normalized and stored in nval; otherwise nval + * is NULL + */ int -attr_merge_normalize_one( - Entry *e, +attr_normalize_one( AttributeDescription *desc, struct berval *val, + struct berval *nval, void *memctx ) { - struct berval nval; - struct berval *nvalp = NULL; - int rc; + int rc = LDAP_SUCCESS; + + BER_BVZERO( nval ); if ( desc->ad_type->sat_equality && desc->ad_type->sat_equality->smr_normalize ) { - rc = (*desc->ad_type->sat_equality->smr_normalize)( + rc = desc->ad_type->sat_equality->smr_normalize( SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX, desc->ad_type->sat_syntax, desc->ad_type->sat_equality, - val, &nval, memctx ); + val, nval, memctx ); if ( rc != LDAP_SUCCESS ) { return rc; } + } + + return rc; +} + +int +attr_merge_normalize_one( + Entry *e, + AttributeDescription *desc, + struct berval *val, + void *memctx ) +{ + struct berval nval = BER_BVNULL; + struct berval *nvalp = NULL; + int rc; + + rc = attr_normalize_one( desc, val, &nval, memctx ); + if ( rc == LDAP_SUCCESS && !BER_BVISNULL( &nval ) ) { nvalp = &nval; }