+ /*
+ * If permissive is set, then the non-existence of an
+ * attribute is not treated as an error.
+ */
+
+ /* delete the entire attribute */
+ if ( mod->sm_values == NULL ) {
+ rc = attr_delete( &e->e_attrs, mod->sm_desc );
+
+ if( permissive ) {
+ rc = LDAP_SUCCESS;
+ } else if( rc != LDAP_SUCCESS ) {
+ *text = textbuf;
+ snprintf( textbuf, textlen,
+ "modify/delete: %s: no such attribute",
+ mod->sm_desc->ad_cname.bv_val );
+ rc = LDAP_NO_SUCH_ATTRIBUTE;
+ }
+ return rc;
+ }
+
+ if( mr == NULL || !mr->smr_match ) {
+ /* disallow specific attributes from being deleted if
+ no equality rule */
+ *text = textbuf;
+ snprintf( textbuf, textlen,
+ "modify/delete: %s: no equality matching rule",
+ mod->sm_desc->ad_cname.bv_val );
+ return LDAP_INAPPROPRIATE_MATCHING;
+ }
+
+ /* delete specific values - find the attribute first */
+ if ( (a = attr_find( e->e_attrs, mod->sm_desc )) == NULL ) {
+ if( permissive ) {
+ return LDAP_SUCCESS;
+ }
+ *text = textbuf;
+ snprintf( textbuf, textlen,
+ "modify/delete: %s: no such attribute",
+ mod->sm_desc->ad_cname.bv_val );
+ return LDAP_NO_SUCH_ATTRIBUTE;
+ }
+
+ for ( i = 0; !BER_BVISNULL( &mod->sm_values[i] ); i++ ) {
+ int found = 0;
+ for ( j = 0; !BER_BVISNULL( &a->a_vals[j] ); j++ ) {
+ /* skip already deleted values */
+ if ( a->a_vals[j].bv_val == &dummy ) {
+ continue;
+ }
+
+ if( mod->sm_nvalues ) {
+ assert( a->a_nvals != NULL );
+ rc = ordered_value_match( &match, a->a_desc, mr,
+ SLAP_MR_EQUALITY | SLAP_MR_VALUE_OF_ASSERTION_SYNTAX
+ | SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH
+ | SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH,
+ &a->a_nvals[j], &mod->sm_nvalues[i], text );
+ } else {
+#if 0
+ assert( a->a_nvals == NULL );
+#endif
+ rc = ordered_value_match( &match, a->a_desc, mr,
+ SLAP_MR_EQUALITY | SLAP_MR_VALUE_OF_ASSERTION_SYNTAX,
+ &a->a_vals[j], &mod->sm_values[i], text );
+ }
+
+ if ( rc != LDAP_SUCCESS ) {
+ *text = textbuf;
+ snprintf( textbuf, textlen,
+ "%s: matching rule failed",
+ mod->sm_desc->ad_cname.bv_val );
+ break;
+ }
+
+ if ( match != 0 ) {
+ continue;
+ }
+
+ found = 1;
+
+ if ( idx )
+ idx[i] = j;
+
+ /* delete value and mark it as dummy */
+ free( a->a_vals[j].bv_val );
+ a->a_vals[j].bv_val = &dummy;
+ if( a->a_nvals != a->a_vals ) {
+ free( a->a_nvals[j].bv_val );
+ a->a_nvals[j].bv_val = &dummy;
+ }
+
+ break;
+ }
+
+ if ( found == 0 ) {
+ *text = textbuf;
+ snprintf( textbuf, textlen,
+ "modify/delete: %s: no such value",
+ mod->sm_desc->ad_cname.bv_val );
+ rc = LDAP_NO_SUCH_ATTRIBUTE;
+ if ( i > 0 ) {
+ break;
+ } else {
+ goto return_results;
+ }
+ }
+ }
+
+ /* compact array skipping dummies */
+ for ( k = 0, j = 0; !BER_BVISNULL( &a->a_vals[k] ); k++ ) {
+ /* skip dummies */
+ if( a->a_vals[k].bv_val == &dummy ) {
+ assert( a->a_nvals[k].bv_val == &dummy );
+ continue;
+ }
+ if ( j != k ) {
+ a->a_vals[ j ] = a->a_vals[ k ];
+ if (a->a_nvals != a->a_vals) {
+ a->a_nvals[ j ] = a->a_nvals[ k ];
+ }
+ }
+
+ j++;