1 /* delete.c - bdb backend delete routine */
4 * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
11 #include <ac/string.h>
25 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
27 struct berval pdn = {0, NULL};
32 int manageDSAit = get_manageDSAit( op );
33 AttributeDescription *children = slap_schema.si_ad_children;
35 struct bdb_op_info opinfo;
45 LDAP_LOG ( OPERATION, ARGS, "==> bdb_delete: %s\n", dn->bv_val, 0, 0 );
47 Debug( LDAP_DEBUG_ARGS, "==> bdb_delete: %s\n",
52 retry: /* transaction retry */
54 bdb_unlocked_cache_return_entry_w(&bdb->bi_cache, e);
57 LDAP_LOG ( OPERATION, DETAIL1,
58 "==> bdb_delete: retrying...\n", 0, 0, 0 );
60 Debug( LDAP_DEBUG_TRACE, "==> bdb_delete: retrying...\n",
63 rc = TXN_ABORT( ltid );
68 text = "internal error";
71 ldap_pvt_thread_yield();
74 /* begin transaction */
75 rc = TXN_BEGIN( bdb->bi_dbenv, NULL, <id,
80 LDAP_LOG ( OPERATION, ERR,
81 "==> bdb_delete: txn_begin failed: %s (%d)\n",
82 db_strerror(rc), rc, 0 );
84 Debug( LDAP_DEBUG_TRACE,
85 "bdb_delete: txn_begin failed: %s (%d)\n",
86 db_strerror(rc), rc, 0 );
89 text = "internal error";
93 locker = TXN_ID ( ltid );
95 lockid = TXN_ID( ltid );
99 opinfo.boi_txn = ltid;
101 op->o_private = &opinfo;
103 if ( !be_issuffix( be, ndn ) ) {
104 dnParent( ndn, &pdn );
107 if( pdn.bv_len != 0 ) {
111 obj.data = pdn.bv_val-1;
112 obj.size = pdn.bv_len+1;
113 rc = LOCK_GET( bdb->bi_dbenv, lockid, 0, &obj,
114 DB_LOCK_WRITE, &lock);
118 rc = bdb_dn2entry_r( be, ltid, &pdn, &p, NULL, 0, locker, &lock );
124 case DB_LOCK_DEADLOCK:
125 case DB_LOCK_NOTGRANTED:
128 text = "ldap server busy";
132 text = "internal error";
138 LDAP_LOG ( OPERATION, DETAIL1,
139 "<=- bdb_delete: parent does not exist\n", 0, 0, 0 );
141 Debug( LDAP_DEBUG_TRACE,
142 "<=- bdb_delete: parent does not exist\n",
146 text = "could not locate parent of entry";
150 /* check parent for "children" acl */
151 rc = access_allowed( be, conn, op, p,
152 children, NULL, ACL_WRITE, NULL );
154 bdb_unlocked_cache_return_entry_r(&bdb->bi_cache, p);
157 switch( opinfo.boi_err ) {
158 case DB_LOCK_DEADLOCK:
159 case DB_LOCK_NOTGRANTED:
165 LDAP_LOG ( OPERATION, DETAIL1,
166 "<=- bdb_delete: no access to parent\n", 0, 0, 0 );
168 Debug( LDAP_DEBUG_TRACE,
169 "<=- bdb_delete: no access to parent\n",
172 rc = LDAP_INSUFFICIENT_ACCESS;
177 /* no parent, must be root to delete */
178 if( ! be_isroot( be, &op->o_ndn ) ) {
179 if ( be_issuffix( be, (struct berval *)&slap_empty_bv )
180 || be_isupdate( be, &op->o_ndn ) ) {
181 p = (Entry *)&slap_entry_root;
183 /* check parent for "children" acl */
184 rc = access_allowed( be, conn, op, p,
185 children, NULL, ACL_WRITE, NULL );
188 switch( opinfo.boi_err ) {
189 case DB_LOCK_DEADLOCK:
190 case DB_LOCK_NOTGRANTED:
196 LDAP_LOG ( OPERATION, DETAIL1,
197 "<=- bdb_delete: no access to parent\n", 0, 0, 0 );
199 Debug( LDAP_DEBUG_TRACE,
200 "<=- bdb_delete: no access "
201 "to parent\n", 0, 0, 0 );
203 rc = LDAP_INSUFFICIENT_ACCESS;
209 LDAP_LOG ( OPERATION, DETAIL1,
210 "<=- bdb_delete: no parent and not root\n", 0, 0, 0 );
212 Debug( LDAP_DEBUG_TRACE,
213 "<=- bdb_delete: no parent "
214 "and not root\n", 0, 0, 0);
216 rc = LDAP_INSUFFICIENT_ACCESS;
226 rc = LOCK_GET( bdb->bi_dbenv, lockid, 0, &obj,
227 DB_LOCK_WRITE, &lock);
232 /* get entry for read/modify/write */
233 rc = bdb_dn2entry_w( be, ltid, ndn, &e, &matched, DB_RMW, locker, &lock );
239 case DB_LOCK_DEADLOCK:
240 case DB_LOCK_NOTGRANTED:
243 text = "ldap server busy";
247 text = "internal error";
252 char *matched_dn = NULL;
256 LDAP_LOG ( OPERATION, ARGS,
257 "<=- bdb_delete: no such object %s\n", dn->bv_val, 0, 0);
259 Debug( LDAP_DEBUG_ARGS,
260 "<=- bdb_delete: no such object %s\n",
264 if ( matched != NULL ) {
265 matched_dn = ch_strdup( matched->e_dn );
266 refs = is_entry_referral( matched )
267 ? get_entry_referrals( be, conn, op, matched )
269 bdb_unlocked_cache_return_entry_r(&bdb->bi_cache, matched);
273 refs = referral_rewrite( default_referral,
274 NULL, dn, LDAP_SCOPE_DEFAULT );
277 send_ldap_result( conn, op, LDAP_REFERRAL,
278 matched_dn, NULL, refs, NULL );
280 ber_bvarray_free( refs );
287 if ( !manageDSAit && is_entry_referral( e ) ) {
288 /* entry is a referral, don't allow delete */
289 BerVarray refs = get_entry_referrals( be,
293 LDAP_LOG ( OPERATION, DETAIL1,
294 "<=- bdb_delete: entry is referral\n", 0, 0, 0 );
296 Debug( LDAP_DEBUG_TRACE,
297 "bdb_delete: entry is referral\n",
301 send_ldap_result( conn, op, LDAP_REFERRAL,
302 e->e_dn, NULL, refs, NULL );
304 ber_bvarray_free( refs );
310 rc = bdb_dn2id_children( be, ltid, &e->e_nname, 0 );
311 if( rc != DB_NOTFOUND ) {
313 case DB_LOCK_DEADLOCK:
314 case DB_LOCK_NOTGRANTED:
318 LDAP_LOG ( OPERATION, DETAIL1,
319 "<=- bdb_delete: non-leaf %s\n", dn->bv_val, 0, 0 );
321 Debug(LDAP_DEBUG_ARGS,
322 "<=- bdb_delete: non-leaf %s\n",
325 rc = LDAP_NOT_ALLOWED_ON_NONLEAF;
326 text = "subtree delete not supported";
330 LDAP_LOG ( OPERATION, ERR,
331 "<=- bdb_delete: has_children failed %s (%d)\n",
332 db_strerror(rc), rc, 0 );
334 Debug(LDAP_DEBUG_ARGS,
335 "<=- bdb_delete: has_children failed: %s (%d)\n",
336 db_strerror(rc), rc, 0 );
339 text = "internal error";
344 /* delete from dn2id */
345 rc = bdb_dn2id_delete( be, ltid, pdn.bv_val, e );
348 case DB_LOCK_DEADLOCK:
349 case DB_LOCK_NOTGRANTED:
355 LDAP_LOG ( OPERATION, ERR,
356 "<=- bdb_delete: dn2id failed %s (%d)\n", db_strerror(rc), rc, 0 );
358 Debug(LDAP_DEBUG_ARGS,
359 "<=- bdb_delete: dn2id failed: %s (%d)\n",
360 db_strerror(rc), rc, 0 );
362 text = "DN index delete failed";
366 /* delete from id2entry */
367 rc = bdb_id2entry_delete( be, ltid, e );
370 case DB_LOCK_DEADLOCK:
371 case DB_LOCK_NOTGRANTED:
377 LDAP_LOG ( OPERATION, ERR,
378 "<=- bdb_delete: id2entry failed: %s (%d)\n",
379 db_strerror(rc), rc, 0 );
381 Debug(LDAP_DEBUG_ARGS,
382 "<=- bdb_delete: id2entry failed: %s (%d)\n",
383 db_strerror(rc), rc, 0 );
385 text = "entry delete failed";
389 /* delete indices for old attributes */
390 rc = bdb_index_entry_del( be, ltid, e, e->e_attrs );
391 if ( rc != LDAP_SUCCESS ) {
393 case DB_LOCK_DEADLOCK:
394 case DB_LOCK_NOTGRANTED:
400 LDAP_LOG ( OPERATION, ERR,
401 "<=- bdb_delete: entry index delete failed!\n", 0, 0, 0 );
403 Debug( LDAP_DEBUG_ANY, "entry index delete failed!\n",
406 text = "entry index delete failed";
410 #if 0 /* Do we want to reclaim deleted IDs? */
411 ldap_pvt_thread_mutex_lock( &bdb->bi_lastid_mutex );
412 if ( e->e_id == bdb->bi_lastid ) {
413 bdb_last_id( be, ltid );
415 ldap_pvt_thread_mutex_unlock( &bdb->bi_lastid_mutex );
419 rc = TXN_ABORT( ltid );
421 rc = TXN_COMMIT( ltid, 0 );
424 op->o_private = NULL;
428 LDAP_LOG ( OPERATION, ERR,
429 "bdb_delete: txn_%s failed: %s (%d)\n",
430 op->o_noop ? "abort (no-op)" : "commit", db_strerror(rc), rc );
432 Debug( LDAP_DEBUG_TRACE,
433 "bdb_delete: txn_%s failed: %s (%d)\n",
434 op->o_noop ? "abort (no-op)" : "commit",
435 db_strerror(rc), rc );
438 text = "commit failed";
442 LDAP_LOG ( OPERATION, RESULTS,
443 "bdb_delete: deleted%s id=%08lx db=\"%s\"\n",
444 op->o_noop ? " (no-op)" : "", e->e_id, e->e_dn );
446 Debug( LDAP_DEBUG_TRACE,
447 "bdb_delete: deleted%s id=%08lx dn=\"%s\"\n",
448 op->o_noop ? " (no-op)" : "",
456 send_ldap_result( conn, op, rc, NULL, text, NULL, NULL );
458 if(rc == LDAP_SUCCESS && bdb->bi_txn_cp ) {
459 ldap_pvt_thread_yield();
460 TXN_CHECKPOINT( bdb->bi_dbenv,
461 bdb->bi_txn_cp_kbyte, bdb->bi_txn_cp_min, 0 );
467 bdb_unlocked_cache_return_entry_w(&bdb->bi_cache, e);
472 op->o_private = NULL;