+#define SLURPD_FRIENDLY
+#ifdef SLURPD_FRIENDLY
+ ber_len_t i,j;
+
+ if( !repl_user ) {
+ snprintf( textbuf, textlen,
+ "attribute '%s' provided more than once",
+ mods->sml_desc->ad_cname.bv_val );
+ return LDAP_TYPE_OR_VALUE_EXISTS;
+ }
+
+ for( i=0; attr->a_vals[i].bv_val; i++ ) {
+ /* count them */
+ }
+ for( j=0; mods->sml_values[j].bv_val; j++ ) {
+ /* count them */
+ }
+ j++; /* NULL */
+
+ attr->a_vals = ch_realloc( attr->a_vals,
+ sizeof( struct berval ) * (i+j) );
+
+ /* should check for duplicates */
+
+ AC_MEMCPY( &attr->a_vals[i], mods->sml_values,
+ sizeof( struct berval ) * j );
+
+ /* trim the mods array */
+ ch_free( mods->sml_values );
+ mods->sml_values = NULL;
+
+ if( mods->sml_nvalues ) {
+ attr->a_nvals = ch_realloc( attr->a_nvals,
+ sizeof( struct berval ) * (i+j) );
+
+ AC_MEMCPY( &attr->a_nvals[i], mods->sml_nvalues,
+ sizeof( struct berval ) * j );
+
+ /* trim the mods array */
+ ch_free( mods->sml_nvalues );
+ mods->sml_nvalues = NULL;
+
+ } else {
+ attr->a_nvals = attr->a_vals;
+ }
+
+ continue;
+#else
+ snprintf( textbuf, textlen,
+ "attribute '%s' provided more than once",
+ mods->sml_desc->ad_cname.bv_val );
+ return LDAP_TYPE_OR_VALUE_EXISTS;
+#endif
+ }
+
+ 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_values[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
+ ? &mods->sml_nvalues[i]
+ : &mods->sml_values[i],
+ mods->sml_nvalues
+ ? &mods->sml_nvalues[j]
+ : &mods->sml_values[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;
+ }
+ }