+
+ if( mods->sml_values[1].bv_val != NULL ) {
+ /* check for duplicates */
+ int i, j;
+ MatchingRule *mr = mods->sml_desc->ad_type->sat_equality;
+
+ /* check if the values we're adding already exist */
+ if( mr == NULL || !mr->smr_match ) {
+ for ( i = 0; mods->sml_bvalues[i].bv_val != NULL; i++ ) {
+ /* test asserted values against themselves */
+ for( j = 0; j < i; j++ ) {
+ if ( bvmatch( &mods->sml_bvalues[i],
+ &mods->sml_bvalues[j] ) ) {
+ /* value exists already */
+ snprintf( textbuf, textlen,
+ "%s: value #%d provided more than once",
+ mods->sml_desc->ad_cname.bv_val, j );
+ return LDAP_TYPE_OR_VALUE_EXISTS;
+ }
+ }
+ }
+
+ } else {
+ int rc = LDAP_SUCCESS;
+ int match;
+
+ for ( i = 0; mods->sml_nvalues[i].bv_val != NULL; i++ ) {
+ /* test asserted values against themselves */
+ for( j = 0; j < i; j++ ) {
+ rc = value_match( &match, mods->sml_desc, mr,
+ SLAP_MR_EQUALITY | SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX
+ | SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH
+ | SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH,
+ &mods->sml_nvalues[i], &mods->sml_nvalues[j], text );
+ if ( rc == LDAP_SUCCESS && match == 0 ) {
+ /* value exists already */
+ snprintf( textbuf, textlen,
+ "%s: value #%d provided more than once",
+ mods->sml_desc->ad_cname.bv_val, j );
+ return LDAP_TYPE_OR_VALUE_EXISTS;
+ }
+ }
+ }
+ if ( rc != LDAP_SUCCESS ) {
+ return rc;
+ }
+ }
+ }
+
+ attr = ch_calloc( 1, sizeof(Attribute) );
+
+ /* move ad to attr structure */
+ attr->a_desc = mods->sml_desc;
+ mods->sml_desc = NULL;
+
+ /* move values to attr structure */
+ /* should check for duplicates */
+ attr->a_vals = mods->sml_values;
+ mods->sml_values = NULL;
+
+ if ( mods->sml_nvalues ) {
+ attr->a_nvals = mods->sml_nvalues;
+ mods->sml_nvalues = NULL;
+ } else {
+ attr->a_nvals = attr->a_vals;
+ }
+
+ *tail = attr;
+ tail = &attr->a_next;