2 * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
3 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6 * Copyright (c) 1995 Regents of the University of Michigan.
9 * Redistribution and use in source and binary forms are permitted
10 * provided that this notice is preserved and that due credit is given
11 * to the University of Michigan at Ann Arbor. The name of the University
12 * may not be used to endorse or promote products derived from this
13 * software without specific prior written permission. This software
14 * is provided ``as is'' without express or implied warranty.
26 char *textbuf, size_t textlen
31 MatchingRule *mr = mod->sm_desc->ad_type->sat_equality;
34 switch( mod->sm_op ) {
38 case LDAP_MOD_REPLACE:
46 a = attr_find( e->e_attrs, mod->sm_desc );
48 /* check if the values we're adding already exist */
49 if( mr == NULL || !mr->smr_match ) {
51 /* do not allow add of additional attribute
52 if no equality rule exists */
54 snprintf( textbuf, textlen,
55 "modify/%s: %s: no equality matching rule",
56 op, mod->sm_desc->ad_cname.bv_val );
57 return LDAP_INAPPROPRIATE_MATCHING;
60 for ( i = 0; mod->sm_bvalues[i].bv_val != NULL; i++ ) {
61 /* test asserted values against existing values */
63 for( j = 0; a->a_vals[j].bv_val != NULL; j++ ) {
64 int rc = ber_bvcmp( &mod->sm_bvalues[i],
68 /* value exists already */
70 snprintf( textbuf, textlen,
71 "modify/%s: %s: value #%i already exists",
72 op, mod->sm_desc->ad_cname.bv_val, j );
73 return LDAP_TYPE_OR_VALUE_EXISTS;
78 /* test asserted values against themselves */
79 for( j = 0; j < i; j++ ) {
80 int rc = ber_bvcmp( &mod->sm_bvalues[i],
81 &mod->sm_bvalues[j] );
84 /* value exists already */
86 snprintf( textbuf, textlen,
87 "modify/%s: %s: value #%i already exists",
88 op, mod->sm_desc->ad_cname.bv_val, j );
89 return LDAP_TYPE_OR_VALUE_EXISTS;
95 for ( i = 0; mod->sm_bvalues[i].bv_val != NULL; i++ ) {
97 struct berval asserted;
99 rc = value_normalize( mod->sm_desc,
105 if( rc != LDAP_SUCCESS ) return rc;
108 for ( j = 0; a->a_vals[j].bv_val != NULL; j++ ) {
109 int rc = value_match( &match, mod->sm_desc, mr,
110 SLAP_MR_VALUE_SYNTAX_MATCH,
111 &a->a_vals[j], &asserted, text );
113 if( rc == LDAP_SUCCESS && match == 0 ) {
114 free( asserted.bv_val );
115 return LDAP_TYPE_OR_VALUE_EXISTS;
120 for ( j = 0; j < i; j++ ) {
121 int rc = value_match( &match, mod->sm_desc, mr,
122 SLAP_MR_VALUE_SYNTAX_MATCH,
123 &mod->sm_bvalues[j], &asserted, text );
125 if( rc == LDAP_SUCCESS && match == 0 ) {
126 free( asserted.bv_val );
127 return LDAP_TYPE_OR_VALUE_EXISTS;
131 free( asserted.bv_val );
136 if( attr_merge( e, mod->sm_desc, mod->sm_bvalues ) != 0 ) {
137 /* this should return result of attr_merge */
139 snprintf( textbuf, textlen,
140 "modify/%s: %s: merge error",
141 op, mod->sm_desc->ad_cname.bv_val );
149 modify_delete_values(
153 char *textbuf, size_t textlen
158 MatchingRule *mr = mod->sm_desc->ad_type->sat_equality;
160 /* delete the entire attribute */
161 if ( mod->sm_bvalues == NULL ) {
162 int rc = attr_delete( &e->e_attrs, mod->sm_desc );
164 if( rc != LDAP_SUCCESS ) {
166 snprintf( textbuf, textlen,
167 "modify/delete: %s: no such attribute",
168 mod->sm_desc->ad_cname.bv_val );
169 rc = LDAP_NO_SUCH_ATTRIBUTE;
174 if( mr == NULL || !mr->smr_match ) {
175 /* disallow specific attributes from being deleted if
178 snprintf( textbuf, textlen,
179 "modify/delete: %s: no equality matching rule",
180 mod->sm_desc->ad_cname.bv_val );
181 return LDAP_INAPPROPRIATE_MATCHING;
184 /* delete specific values - find the attribute first */
185 if ( (a = attr_find( e->e_attrs, mod->sm_desc )) == NULL ) {
187 snprintf( textbuf, textlen,
188 "modify/delete: %s: no such attribute",
189 mod->sm_desc->ad_cname.bv_val );
190 return LDAP_NO_SUCH_ATTRIBUTE;
193 /* find each value to delete */
194 for ( i = 0; mod->sm_bvalues[i].bv_val != NULL; i++ ) {
196 struct berval asserted;
198 rc = value_normalize( mod->sm_desc,
204 if( rc != LDAP_SUCCESS ) return rc;
207 for ( j = 0; a->a_vals[j].bv_val != NULL; j++ ) {
209 int rc = value_match( &match, mod->sm_desc, mr,
210 SLAP_MR_VALUE_SYNTAX_MATCH,
211 &a->a_vals[j], &asserted, text );
213 if( rc == LDAP_SUCCESS && match != 0 ) {
217 /* found a matching value */
221 free( a->a_vals[j].bv_val );
222 for ( k = j + 1; a->a_vals[k].bv_val != NULL; k++ ) {
223 a->a_vals[k - 1] = a->a_vals[k];
225 a->a_vals[k - 1].bv_val = NULL;
226 a->a_vals[k - 1].bv_len = 0;
231 free( asserted.bv_val );
233 /* looked through them all w/o finding it */
236 snprintf( textbuf, textlen,
237 "modify/delete: %s: no such value",
238 mod->sm_desc->ad_cname.bv_val );
239 return LDAP_NO_SUCH_ATTRIBUTE;
243 /* if no values remain, delete the entire attribute */
244 if ( a->a_vals[0].bv_val == NULL ) {
245 if ( attr_delete( &e->e_attrs, mod->sm_desc ) ) {
247 snprintf( textbuf, textlen,
248 "modify/delete: %s: no such attribute",
249 mod->sm_desc->ad_cname.bv_val );
250 return LDAP_NO_SUCH_ATTRIBUTE;
258 modify_replace_values(
262 char *textbuf, size_t textlen
265 (void) attr_delete( &e->e_attrs, mod->sm_desc );
267 if ( mod->sm_bvalues ) {
268 return modify_add_values( e, mod, text, textbuf, textlen );
281 if ( mod->sm_type.bv_val)
282 free( mod->sm_type.bv_val );
284 if ( mod->sm_bvalues != NULL )
285 ber_bvarray_free( mod->sm_bvalues );
298 for ( ; ml != NULL; ml = next ) {
301 slap_mod_free( &ml->sml_mod, 0 );