- for ( i=0; mods[i].bv_val != NULL; i++ ) {
- rc = value_normalize( ad, SLAP_MR_EQUALITY,
- &mods[i], &nmods[i], text );
-
- if ( rc != LDAP_SUCCESS ) {
- nmods[i].bv_val = NULL;
- goto return_results;
- }
-
- if ( numvals > 0 && numvals < nummods ) {
- for ( matched=0, j=0; nvals[j].bv_val; j++ ) {
- int match;
-
- rc = (*mr->smr_match)( &match,
- SLAP_MR_ATTRIBUTE_SYNTAX_MATCH,
- ad->ad_type->sat_syntax,
- mr, &nmods[ i ], &nvals[ j ] );
-
- if ( rc != LDAP_SUCCESS ) {
- nmods[ i + 1 ].bv_val = NULL;
- *text = textbuf;
- snprintf( textbuf, textlen,
- "%s: matching rule failed",
- ad->ad_cname.bv_val );
- goto return_results;
- }
-
- if ( match == 0 ) {
- if ( permissive ) {
- matched++;
- continue;
- }
- *text = textbuf;
- snprintf( textbuf, textlen,
- "%s: value #%d provided more than once",
- ad->ad_cname.bv_val, i );
- rc = LDAP_TYPE_OR_VALUE_EXISTS;
- nmods[ i + 1 ].bv_val = NULL;
- goto return_results;
- }
- }
-
- if ( permissive && matched == j ) {
- nmods[ i + 1 ].bv_val = NULL;
- rc = LDAP_TYPE_OR_VALUE_EXISTS;
- goto return_results;
- }
- }
-
- for ( matched = 0, j = 0; j < i; j++ ) {
- int match;
-
- rc = (*mr->smr_match)( &match,
- SLAP_MR_ATTRIBUTE_SYNTAX_MATCH,
- ad->ad_type->sat_syntax,
- mr, &nmods[ i ], &nmods[ j ] );
- if ( rc != LDAP_SUCCESS ) {
- nmods[ i + 1 ].bv_val = NULL;
- *text = textbuf;
- snprintf( textbuf, textlen,
- "%s: matching rule failed",
- ad->ad_cname.bv_val );
- goto return_results;
- }
-
- if ( match == 0 ) {
- if ( permissive ) {
- matched++;
- continue;
- }
- *text = textbuf;
- snprintf( textbuf, textlen,
- "%s: value #%d provided more than once",
- ad->ad_cname.bv_val, j );
- rc = LDAP_TYPE_OR_VALUE_EXISTS;
- nmods[ i + 1 ].bv_val = NULL;
- goto return_results;
- }
- }
-
- if ( permissive && matched == j ) {
- nmods[ i + 1 ].bv_val = NULL;
- rc = LDAP_TYPE_OR_VALUE_EXISTS;
- goto return_results;
- }
- }
- nmods[ i ].bv_val = NULL;
-
- /*
- * if new values are more than existing values, it is more
- * convenient to normalize and check all new values first,
- * then check each new value against existing values, which
- * can be normalized in place
- */
-
- if ( numvals >= nummods ) {
- for ( j = 0; vals[ j ].bv_val; j++ ) {
- struct berval asserted;
-
- rc = value_normalize( ad, SLAP_MR_EQUALITY,
- &vals[ j ], &asserted, text );
-
- if ( rc != LDAP_SUCCESS ) {
- goto return_results;
- }
-
- for ( matched = 0, i = 0; nmods[ i ].bv_val; i++ ) {
- int match;
-
- rc = (*mr->smr_match)( &match,
- SLAP_MR_ATTRIBUTE_SYNTAX_MATCH,
- ad->ad_type->sat_syntax,
- mr, &nmods[ i ], &asserted );
- if ( rc != LDAP_SUCCESS ) {
- *text = textbuf;
- snprintf( textbuf, textlen,
- "%s: matching rule failed",
- ad->ad_cname.bv_val );
- goto return_results;
- }
-
- if ( match == 0 ) {
- if ( permissive ) {
- matched++;
- continue;
- }
- *text = textbuf;
- snprintf( textbuf, textlen,
- "%s: value #%d provided more than once",
- ad->ad_cname.bv_val, j );
- rc = LDAP_TYPE_OR_VALUE_EXISTS;
- goto return_results;
- }
- }
-
- if ( permissive && matched == i ) {
- rc = LDAP_TYPE_OR_VALUE_EXISTS;
- goto return_results;
- }
- }
- }
-
-return_results:;
- if ( nvals ) {
- ber_bvarray_free( nvals );
- }
- if ( nmods ) {
- ber_bvarray_free( nmods );
- }
-
-#endif
- return rc;
-}