- nvals = ch_calloc( j + 1, sizeof( struct berval ) );
-
- /* normalize the existing values first */
- for ( j = 0; vals[ j ].bv_val != NULL; j++ ) {
- rc = value_normalize( ad, SLAP_MR_EQUALITY,
- &vals[ j ], &nvals[ j ], text );
-
- /* existing attribute values must normalize */
- assert( rc == LDAP_SUCCESS );
-
- if ( rc != LDAP_SUCCESS ) {
- nvals[ j ].bv_val = NULL;
- goto return_results;
- }
- }
- nvals[ j ].bv_val = NULL;
- }
-
- for ( i = 0; mods[ i ].bv_val != NULL; i++ )
- /* count new values */ ;
-
- nmods = ch_calloc( i + 1, sizeof( struct berval ) );
-
- 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 ( vals ) {
- for ( j = 0; nvals[ j ].bv_val; j++ ) {
-#ifdef QUICK_DIRTY_DUPLICATE_CHECK
- if ( bvmatch( &nmods[ i ], &nvals[ j ] ) ) {
-#else /* !QUICK_DIRTY_DUPLICATE_CHECK */
- int match;
-
- rc = (mr->smr_match)( &match,
- SLAP_MR_VALUE_SYNTAX_MATCH,
- ad->ad_type->sat_syntax,
- mr, &nmods[ i ], &nvals[ j ] );
- if ( rc != LDAP_SUCCESS ) {
- nmods[ i + 1 ].bv_val = NULL;
- goto return_results;
- }
-
- if ( match == 0 ) {
-#endif /* !QUICK_DIRTY_DUPLICATE_CHECK */
- 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;
- }
- }
- }
-
- for ( j = 0; j < i; j++ ) {
-#ifdef QUICK_DIRTY_DUPLICATE_CHECK
- if ( bvmatch( &nmods[ i ], &nmods[ j ] ) ) {
-#else /* !QUICK_DIRTY_DUPLICATE_CHECK */
- int match;
-
- rc = (mr->smr_match)( &match,
- SLAP_MR_VALUE_SYNTAX_MATCH,
- ad->ad_type->sat_syntax,
- mr, &nmods[ i ], &nmods[ j ] );
- if ( rc != LDAP_SUCCESS ) {
- nmods[ i + 1 ].bv_val = NULL;
- goto return_results;
- }
-
- if ( match == 0 ) {
-#endif /* !QUICK_DIRTY_DUPLICATE_CHECK */
- 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;
- }
- }
- }
- nmods[ i ].bv_val = NULL;
-
-return_results:;
- if ( nvals ) {
- ber_bvarray_free( nvals );
- }
- if ( nmods ) {
- ber_bvarray_free( nmods );
- }
-
- return rc;
-}