1 /* delete.c - bdb backend delete routine */
4 * Copyright 1998-2000 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;
31 int manageDSAit = get_manageDSAit( op );
32 AttributeDescription *children = slap_schema.si_ad_children;
34 struct bdb_op_info opinfo;
36 Debug( LDAP_DEBUG_ARGS, "==> bdb_delete: %s\n",
40 retry: /* transaction retry */
41 Debug( LDAP_DEBUG_TRACE, "==> bdb_delete: retrying...\n",
43 rc = txn_abort( ltid );
48 text = "internal error";
54 /* begin transaction */
55 rc = txn_begin( bdb->bi_dbenv, NULL, <id,
59 Debug( LDAP_DEBUG_TRACE,
60 "bdb_delete: txn_begin failed: %s (%d)\n",
61 db_strerror(rc), rc, 0 );
63 text = "internal error";
69 opinfo.boi_txn = ltid;
71 op->o_private = &opinfo;
73 /* get entry for read/modify/write */
74 rc = bdb_dn2entry( be, ltid, ndn->bv_val, &e, &matched, DB_RMW );
80 case DB_LOCK_DEADLOCK:
81 case DB_LOCK_NOTGRANTED:
85 text = "internal error";
90 char *matched_dn = NULL;
93 Debug( LDAP_DEBUG_ARGS,
94 "<=- bdb_delete: no such object %s\n",
97 if ( matched != NULL ) {
98 matched_dn = ch_strdup( matched->e_dn );
99 refs = is_entry_referral( matched )
100 ? get_entry_referrals( be, conn, op, matched )
102 bdb_entry_return( be, matched );
106 refs = referral_rewrite( default_referral,
107 NULL, dn, LDAP_SCOPE_DEFAULT );
110 send_ldap_result( conn, op, LDAP_REFERRAL,
111 matched_dn, NULL, refs, NULL );
113 ber_bvecfree( refs );
120 pdn = dn_parent( be, ndn->bv_val );
122 if( pdn != NULL && *pdn != '\0' ) {
124 rc = bdb_dn2entry( be, ltid, pdn, &p, NULL, 0 );
130 case DB_LOCK_DEADLOCK:
131 case DB_LOCK_NOTGRANTED:
135 text = "internal error";
140 Debug( LDAP_DEBUG_TRACE,
141 "<=- bdb_delete: parent does not exist\n",
144 text = "could not locate parent of entry";
148 /* check parent for "children" acl */
149 rc = access_allowed( be, conn, op, p,
150 children, NULL, ACL_WRITE );
152 bdb_entry_return( be, p );
156 Debug( LDAP_DEBUG_TRACE,
157 "<=- bdb_delete: no access to parent\n",
159 rc = LDAP_INSUFFICIENT_ACCESS;
164 /* no parent, must be root to delete */
165 if( ! be_isroot( be, &op->o_ndn ) ) {
166 if ( be_issuffix( be, "" ) || be_isupdate( be, &op->o_ndn ) ) {
167 p = (Entry *)&slap_entry_root;
169 /* check parent for "children" acl */
170 rc = access_allowed( be, conn, op, p,
171 children, NULL, ACL_WRITE );
175 Debug( LDAP_DEBUG_TRACE,
176 "<=- bdb_delete: no access "
177 "to parent\n", 0, 0, 0 );
178 rc = LDAP_INSUFFICIENT_ACCESS;
183 Debug( LDAP_DEBUG_TRACE,
184 "<=- bdb_delete: no parent "
185 "and not root\n", 0, 0, 0);
186 rc = LDAP_INSUFFICIENT_ACCESS;
192 if ( !manageDSAit && is_entry_referral( e ) ) {
193 /* parent is a referral, don't allow add */
194 /* parent is an alias, don't allow add */
195 struct berval **refs = get_entry_referrals( be,
198 Debug( LDAP_DEBUG_TRACE,
199 "bdb_delete: entry is referral\n",
202 send_ldap_result( conn, op, LDAP_REFERRAL,
203 e->e_dn, NULL, refs, NULL );
205 ber_bvecfree( refs );
211 rc = bdb_dn2id_children( be, ltid, e->e_ndn );
212 if( rc != DB_NOTFOUND ) {
214 case DB_LOCK_DEADLOCK:
215 case DB_LOCK_NOTGRANTED:
218 Debug(LDAP_DEBUG_ARGS,
219 "<=- bdb_delete: non-leaf %s\n",
221 rc = LDAP_NOT_ALLOWED_ON_NONLEAF;
222 text = "subtree delete not supported";
225 Debug(LDAP_DEBUG_ARGS,
226 "<=- bdb_delete: has_children failed: %s (%d)\n",
227 db_strerror(rc), rc, 0 );
229 text = "internal error";
234 /* delete from dn2id */
235 rc = bdb_dn2id_delete( be, ltid, pdn, e );
238 case DB_LOCK_DEADLOCK:
239 case DB_LOCK_NOTGRANTED:
244 Debug(LDAP_DEBUG_ARGS,
245 "<=- bdb_delete: dn2id failed: %s (%d)\n",
246 db_strerror(rc), rc, 0 );
247 text = "DN index delete failed";
251 /* delete indices for old attributes */
252 rc = bdb_index_entry_del( be, ltid, e, e->e_attrs );
253 if ( rc != LDAP_SUCCESS ) {
255 case DB_LOCK_DEADLOCK:
256 case DB_LOCK_NOTGRANTED:
261 Debug( LDAP_DEBUG_ANY, "entry index delete failed!\n",
263 text = "entry index delete failed";
267 /* delete from id2entry */
268 rc = bdb_id2entry_delete( be, ltid, e->e_id );
271 case DB_LOCK_DEADLOCK:
272 case DB_LOCK_NOTGRANTED:
277 Debug(LDAP_DEBUG_ARGS,
278 "<=- bdb_delete: id2entry failed: %s (%d)\n",
279 db_strerror(rc), rc, 0 );
280 text = "entry delete failed";
285 #if 0 /* Do we want to reclaim deleted IDs? */
286 ldap_pvt_thread_mutex_lock( &bdb->bi_lastid_mutex );
287 if ( e->e_id == bdb->bi_lastid ) {
288 bdb_last_id( be, ltid );
290 ldap_pvt_thread_mutex_unlock( &bdb->bi_lastid_mutex );
294 rc = txn_commit( ltid, 0 );
297 op->o_private = NULL;
300 Debug( LDAP_DEBUG_TRACE,
301 "bdb_delete: txn_commit failed: %s (%d)\n",
302 db_strerror(rc), rc, 0 );
304 text = "commit failed";
307 Debug( LDAP_DEBUG_TRACE,
308 "bdb_delete: deleted id=%08lx dn=\"%s\"\n",
309 e->e_id, e->e_dn, 0 );
315 send_ldap_result( conn, op, LDAP_SUCCESS,
316 NULL, text, NULL, NULL );
318 if(rc == LDAP_SUCCESS && bdb->bi_txn_cp ) {
319 ldap_pvt_thread_yield();
320 TXN_CHECKPOINT( bdb->bi_dbenv,
321 bdb->bi_txn_cp_kbyte, bdb->bi_txn_cp_min, 0 );
327 bdb_entry_return( be, e );
332 op->o_private = NULL;