- out = NULL;
- bvdn = ber_bvstr( dn );
-
- if ( dnNormalize( NULL, bvdn, &nbvdn ) == LDAP_SUCCESS ) {
- if ( nbvdn->bv_len <= bvdn->bv_len ) {
- out = dn;
- strcpy( out, nbvdn->bv_val );
+ rc = slap_bv2ad( &ava->la_attr, &ad, &text );
+ if ( rc != LDAP_SUCCESS ) {
+ return LDAP_INVALID_SYNTAX;
+ }
+
+ ava->la_private = ( void * )ad;
+ do_sort = 1;
+ }
+
+ /*
+ * Replace attr oid/name with the canonical name
+ */
+ ava->la_attr = ad->ad_cname;
+
+ if( ava->la_flags & LDAP_AVA_BINARY ) {
+ /* AVA is binary encoded, don't muck with it */
+ validf = NULL;
+ transf = NULL;
+ mr = NULL;
+ } else if( flags & SLAP_LDAPDN_PRETTY ) {
+ validf = NULL;
+ transf = ad->ad_type->sat_syntax->ssyn_pretty;
+ mr = NULL;
+ } else {
+ validf = ad->ad_type->sat_syntax->ssyn_validate;
+ transf = ad->ad_type->sat_syntax->ssyn_normalize;
+ mr = ad->ad_type->sat_equality;
+ }
+
+ if ( validf ) {
+ /* validate value before normalization */
+ rc = ( *validf )( ad->ad_type->sat_syntax,
+ ava->la_value.bv_len
+ ? &ava->la_value
+ : (struct berval *) &slap_empty_bv );
+
+ if ( rc != LDAP_SUCCESS ) {
+ return LDAP_INVALID_SYNTAX;
+ }
+ }
+
+ if ( transf ) {
+ /*
+ * transform value by normalize/pretty function
+ * if value is empty, use empty_bv
+ */
+ rc = ( *transf )( ad->ad_type->sat_syntax,
+ ava->la_value.bv_len
+ ? &ava->la_value
+ : (struct berval *) &slap_empty_bv,
+ &bv );
+
+ if ( rc != LDAP_SUCCESS ) {
+ return LDAP_INVALID_SYNTAX;
+ }
+ }
+
+ if( mr && ( mr->smr_usage & SLAP_MR_DN_FOLD ) ) {
+ char *s = bv.bv_val;
+
+ if ( UTF8bvnormalize( &bv, &bv,
+ LDAP_UTF8_CASEFOLD ) == NULL ) {
+ return LDAP_INVALID_SYNTAX;
+ }
+ free( s );
+ }
+
+ if( bv.bv_val ) {
+ free( ava->la_value.bv_val );
+ ava->la_value = bv;
+ }
+
+ if( do_sort ) AVA_Sort( rdn, iAVA );