From: Howard Chu Date: Fri, 27 Feb 2009 01:22:23 +0000 (+0000) Subject: ITS#5977 strip duplicates out of sorted attrs X-Git-Tag: ACLCHECK_0~780 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=755e645da37aa2f0e05fe7bc4196342bee562f5f;p=openldap ITS#5977 strip duplicates out of sorted attrs --- diff --git a/servers/slapd/back-meta/search.c b/servers/slapd/back-meta/search.c index a094de66ed..8927ef2697 100644 --- a/servers/slapd/back-meta/search.c +++ b/servers/slapd/back-meta/search.c @@ -1801,6 +1801,7 @@ meta_send_entry( metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private; struct berval a, mapped; int check_duplicate_attrs = 0; + int check_sorted_attrs = 0; Entry ent = { 0 }; BerElement ber = *e->lm_ber; Attribute *attr, **attrp; @@ -1925,6 +1926,9 @@ meta_send_entry( } } + if ( attr->a_desc->ad_type->sat_flags & SLAP_AT_SORTED_VAL ) + check_sorted_attrs = 1; + /* no subschemaSubentry */ if ( attr->a_desc == slap_schema.si_ad_subschemaSubentry || attr->a_desc == slap_schema.si_ad_entryDN ) @@ -2157,6 +2161,34 @@ next_attr:; } } + /* Check for sorted attributes */ + if ( check_sorted_attrs ) { + for ( attr = ent.e_attrs; attr; attr = attr->a_next ) { + if ( attr->a_desc->ad_type->sat_flags & SLAP_AT_SORTED_VAL ) { + while ( attr->a_numvals > 1 ) { + int i; + int rc = slap_sort_vals( (Modifications *)attr, &text, &i, op->o_tmpmemctx ); + if ( rc != LDAP_TYPE_OR_VALUE_EXISTS ) + break; + + /* Strip duplicate values */ + if ( attr->a_nvals != attr->a_vals ) + LBER_FREE( attr->a_nvals[i].bv_val ); + LBER_FREE( attr->a_vals[i].bv_val ); + attr->a_numvals--; + if ( i < attr->a_numvals ) { + attr->a_vals[i] = attr->a_vals[attr->a_numvals]; + if ( attr->a_nvals != attr->a_vals ) + attr->a_nvals[i] = attr->a_nvals[attr->a_numvals]; + } + BER_BVZERO(&attr->a_vals[attr->a_numvals]); + if ( attr->a_nvals != attr->a_vals ) + BER_BVZERO(&attr->a_vals[attr->a_numvals]); + } + } + } + } + ldap_get_entry_controls( mc->mc_conns[target].msc_ld, e, &rs->sr_ctrls ); rs->sr_entry = &ent;