1 /* modify.c - bdb2 backend modify routine */
11 #include "back-bdb2.h"
12 #include "proto-back-bdb2.h"
15 bdb2i_back_modify_internal(
24 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
28 Debug(LDAP_DEBUG_ARGS, "bdb2i_back_modify:\n", 0, 0, 0);
30 if ( (err = acl_check_modlist( be, conn, op, e, modlist )) != LDAP_SUCCESS ) {
31 send_ldap_result( conn, op, err,
32 NULL, NULL, NULL, NULL );
36 for ( ml = modlist; ml != NULL; ml = ml->ml_next ) {
37 LDAPMod *mod = &ml->ml_mod;
39 switch ( mod->mod_op & ~LDAP_MOD_BVALUES ) {
41 err = bdb2i_add_values( e, mod, op->o_ndn );
45 err = bdb2i_delete_values( e, mod, op->o_ndn );
48 case LDAP_MOD_REPLACE:
49 err = bdb2i_replace_values( e, mod, op->o_ndn );
52 case LDAP_MOD_SOFTADD:
53 /* Avoid problems in index_add_mods()
54 * We need to add index if necessary.
56 mod->mod_op = LDAP_MOD_ADD;
57 if ( (err = bdb2i_add_values( e, mod, op->o_ndn ))
58 == LDAP_TYPE_OR_VALUE_EXISTS ) {
61 mod->mod_op = LDAP_MOD_SOFTADD;
67 if ( err != LDAP_SUCCESS ) {
68 /* unlock entry, delete from cache */
69 send_ldap_result( conn, op, err,
70 NULL, NULL, NULL, NULL );
75 /* check that the entry still obeys the schema */
76 if ( global_schemacheck && oc_schema_check( e ) != 0 ) {
77 Debug( LDAP_DEBUG_ANY, "entry failed schema check\n", 0, 0, 0 );
78 send_ldap_result( conn, op, LDAP_OBJECT_CLASS_VIOLATION,
79 NULL, NULL, NULL, NULL );
83 /* check for abandon */
84 ldap_pvt_thread_mutex_lock( &op->o_abandonmutex );
85 if ( op->o_abandon ) {
86 ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
89 ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
92 if ( bdb2i_index_add_mods( be, modlist, e->e_id ) != 0 ) {
93 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
94 NULL, NULL, NULL, NULL );
98 /* check for abandon */
99 ldap_pvt_thread_mutex_lock( &op->o_abandonmutex );
100 if ( op->o_abandon ) {
101 ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
104 ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
106 /* change the entry itself */
107 if ( bdb2i_id2entry_add( be, e ) != 0 ) {
108 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
109 NULL, NULL, NULL, NULL );
113 send_ldap_result( conn, op, LDAP_SUCCESS,
114 NULL, NULL, NULL, NULL );
132 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
133 struct timeval time1;
134 int ret, manageDSAit;
138 bdb2i_start_timing( be->bd_info, &time1 );
140 if ( bdb2i_enter_backend_w( &lock ) != 0 ) {
141 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
142 NULL, NULL, NULL, NULL );
146 /* check, if a new default attribute index will be created,
147 in which case we have to open the index file BEFORE TP */
148 switch ( slapMode ) {
149 case SLAP_SERVER_MODE:
150 case SLAP_TIMEDSERVER_MODE:
152 case SLAP_TOOLID_MODE:
153 bdb2i_check_default_attr_index_mod( li, modlist );
157 if ( (e = bdb2i_dn2entry_w( be, dn, &matched )) == NULL ) {
158 char *matched_dn = NULL;
159 struct berval **refs = NULL;
161 if ( matched != NULL ) {
162 matched_dn = ch_strdup( matched->e_dn );
163 refs = is_entry_referral( matched )
164 ? get_entry_referrals( be, conn, op, matched )
166 bdb2i_cache_return_entry_r( &li->li_cache, matched );
168 refs = default_referral;
171 send_ldap_result( conn, op, LDAP_REFERRAL,
172 matched_dn, NULL, refs, NULL );
174 if( matched != NULL ) {
175 ber_bvecfree( refs );
183 if (!manageDSAit && is_entry_referral( e ) ) {
184 /* entry is a referral, don't allow add */
185 struct berval **refs = get_entry_referrals( be,
188 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
191 send_ldap_result( conn, op, LDAP_REFERRAL,
192 e->e_dn, NULL, refs, NULL );
194 bdb2i_cache_return_entry_w( &li->li_cache, e );
196 ber_bvecfree( refs );
202 ret = bdb2i_back_modify_internal( be, conn, op, dn, modlist, e );
203 bdb2i_cache_return_entry_w( &li->li_cache, e );
206 (void) bdb2i_leave_backend_w( lock );
207 bdb2i_stop_timing( be->bd_info, time1, "MOD", conn, op );
223 /* check if the values we're adding already exist */
224 if ( (a = attr_find( e->e_attrs, mod->mod_type )) != NULL ) {
225 for ( i = 0; mod->mod_bvalues[i] != NULL; i++ ) {
226 if ( value_find( a->a_vals, mod->mod_bvalues[i],
227 a->a_syntax, 3 ) == 0 ) {
228 return( LDAP_TYPE_OR_VALUE_EXISTS );
234 if( attr_merge( e, mod->mod_type, mod->mod_bvalues ) != 0 ) {
235 return( LDAP_CONSTRAINT_VIOLATION );
238 return( LDAP_SUCCESS );
251 /* delete the entire attribute */
252 if ( mod->mod_bvalues == NULL ) {
253 Debug( LDAP_DEBUG_ARGS, "removing entire attribute %s\n",
254 mod->mod_type, 0, 0 );
255 return( attr_delete( &e->e_attrs, mod->mod_type ) ?
256 LDAP_NO_SUCH_ATTRIBUTE : LDAP_SUCCESS );
259 /* delete specific values - find the attribute first */
260 if ( (a = attr_find( e->e_attrs, mod->mod_type )) == NULL ) {
261 Debug( LDAP_DEBUG_ARGS, "could not find attribute %s\n",
262 mod->mod_type, 0, 0 );
263 return( LDAP_NO_SUCH_ATTRIBUTE );
266 /* find each value to delete */
267 for ( i = 0; mod->mod_bvalues[i] != NULL; i++ ) {
269 for ( j = 0; a->a_vals[j] != NULL; j++ ) {
270 if ( value_cmp( mod->mod_bvalues[i], a->a_vals[j],
271 a->a_syntax, 3 ) != 0 ) {
276 /* found a matching value - delete it */
277 ber_bvfree( a->a_vals[j] );
278 for ( k = j + 1; a->a_vals[k] != NULL; k++ ) {
279 a->a_vals[k - 1] = a->a_vals[k];
281 a->a_vals[k - 1] = NULL;
283 /* delete the entire attribute, if no values remain */
284 if ( a->a_vals[0] == NULL) {
285 Debug( LDAP_DEBUG_ARGS,
286 "removing entire attribute %s\n",
287 mod->mod_type, 0, 0 );
288 if ( attr_delete( &e->e_attrs, mod->mod_type ) ) {
289 return LDAP_NO_SUCH_ATTRIBUTE;
296 /* looked through them all w/o finding it */
298 Debug( LDAP_DEBUG_ARGS,
299 "could not find value for attr %s\n",
300 mod->mod_type, 0, 0 );
301 return( LDAP_NO_SUCH_ATTRIBUTE );
305 return( LDAP_SUCCESS );
309 bdb2i_replace_values(
315 (void) attr_delete( &e->e_attrs, mod->mod_type );
317 if ( attr_merge( e, mod->mod_type, mod->mod_bvalues ) != 0 ) {
318 return( LDAP_CONSTRAINT_VIOLATION );
321 return( LDAP_SUCCESS );