From: Kurt Zeilenga Date: Sat, 19 Jan 2002 01:56:35 +0000 (+0000) Subject: Add checks for duplicate values X-Git-Tag: LDBM_PRE_GIANT_RWLOCK~71 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=014ea5f48696a8d7c1dc1fecfd8672622ae3991d;p=openldap Add checks for duplicate values --- diff --git a/servers/slapd/add.c b/servers/slapd/add.c index d041060170..d8e4deaacd 100644 --- a/servers/slapd/add.c +++ b/servers/slapd/add.c @@ -387,6 +387,56 @@ static int slap_mods2entry( #endif } + if( mods->sml_bvalues[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++ ) { + int rc = ber_bvcmp( &mods->sml_bvalues[i], + &mods->sml_bvalues[j] ); + + if( rc == 0 ) { + /* value exists already */ + return LDAP_TYPE_OR_VALUE_EXISTS; + } + } + } + + } else { + for ( i = 0; mods->sml_bvalues[i].bv_val != NULL; i++ ) { + int rc, match; + const char *text = NULL; + struct berval asserted; + + rc = value_normalize( mods->sml_desc, + SLAP_MR_EQUALITY, + &mods->sml_bvalues[i], + &asserted, + &text ); + + if( rc != LDAP_SUCCESS ) return rc; + + for ( j = 0; j < i; j++ ) { + int rc = value_match( &match, mods->sml_desc, mr, + SLAP_MR_VALUE_SYNTAX_MATCH, + &mods->sml_bvalues[j], &asserted, &text ); + + if( rc == LDAP_SUCCESS && match == 0 ) { + free( asserted.bv_val ); + return LDAP_TYPE_OR_VALUE_EXISTS; + } + } + + free( asserted.bv_val ); + } + } + } + attr = ch_calloc( 1, sizeof(Attribute) ); /* move ad to attr structure */