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", dn, 0, 0 );
39 retry: /* transaction retry */
40 Debug( LDAP_DEBUG_TRACE, "==> bdb_delete: retrying...\n", 0, 0, 0 );
41 rc = txn_abort( ltid );
46 text = "internal error";
52 /* begin transaction */
53 rc = txn_begin( bdb->bi_dbenv, NULL, <id,
57 Debug( LDAP_DEBUG_TRACE,
58 "bdb_delete: txn_begin failed: %s (%d)\n",
59 db_strerror(rc), rc, 0 );
61 text = "internal error";
67 opinfo.boi_txn = ltid;
69 op->o_private = &opinfo;
71 /* get entry for read/modify/write */
72 rc = bdb_dn2entry( be, ltid, ndn, &e, &matched, DB_RMW );
78 case DB_LOCK_DEADLOCK:
79 case DB_LOCK_NOTGRANTED:
83 text = "internal error";
88 char *matched_dn = NULL;
91 Debug( LDAP_DEBUG_ARGS,
92 "<=- bdb_delete: no such object %s\n",
95 if ( matched != NULL ) {
96 matched_dn = ch_strdup( matched->e_dn );
97 refs = is_entry_referral( matched )
98 ? get_entry_referrals( be, conn, op, matched,
99 dn, LDAP_SCOPE_DEFAULT )
101 bdb_entry_return( be, matched );
105 refs = referral_rewrite( default_referral,
106 NULL, dn, LDAP_SCOPE_DEFAULT );
109 send_ldap_result( conn, op, LDAP_REFERRAL,
110 matched_dn, NULL, refs, NULL );
112 ber_bvecfree( refs );
119 pdn = dn_parent( be, ndn );
121 if( pdn != NULL && *pdn != '\0' ) {
123 rc = bdb_dn2entry( be, ltid, pdn, &p, NULL, 0 );
129 case DB_LOCK_DEADLOCK:
130 case DB_LOCK_NOTGRANTED:
134 text = "internal error";
139 Debug( LDAP_DEBUG_TRACE,
140 "<=- bdb_delete: parent does not exist\n",
143 text = "could not locate parent of entry";
147 /* check parent for "children" acl */
148 rc = access_allowed( be, conn, op, p,
149 children, NULL, ACL_WRITE );
151 bdb_entry_return( be, p );
155 Debug( LDAP_DEBUG_TRACE,
156 "<=- bdb_delete: no access to parent\n",
158 rc = LDAP_INSUFFICIENT_ACCESS;
163 /* no parent, must be root to delete */
164 if( ! be_isroot( be, op->o_ndn ) ) {
165 if ( be_issuffix( be, "" ) || be_isupdate( be, op->o_ndn ) ) {
166 p = (Entry *)&slap_entry_root;
168 /* check parent for "children" acl */
169 rc = access_allowed( be, conn, op, p,
170 children, NULL, ACL_WRITE );
174 Debug( LDAP_DEBUG_TRACE,
175 "<=- bdb_delete: no access "
176 "to parent\n", 0, 0, 0 );
177 rc = LDAP_INSUFFICIENT_ACCESS;
182 Debug( LDAP_DEBUG_TRACE,
183 "<=- bdb_delete: no parent "
184 "and not root\n", 0, 0, 0);
185 rc = LDAP_INSUFFICIENT_ACCESS;
191 if ( !manageDSAit && is_entry_referral( e ) ) {
192 /* parent is a referral, don't allow add */
193 /* parent is an alias, don't allow add */
194 struct berval **refs = get_entry_referrals( be,
195 conn, op, e, dn, LDAP_SCOPE_DEFAULT );
197 Debug( LDAP_DEBUG_TRACE,
198 "bdb_delete: entry is referral\n",
201 send_ldap_result( conn, op, LDAP_REFERRAL,
202 e->e_dn, NULL, refs, NULL );
204 ber_bvecfree( refs );
210 rc = bdb_dn2id_children( be, ltid, e->e_ndn );
211 if( rc != DB_NOTFOUND ) {
213 case DB_LOCK_DEADLOCK:
214 case DB_LOCK_NOTGRANTED:
217 Debug(LDAP_DEBUG_ARGS,
218 "<=- bdb_delete: non-leaf %s\n",
220 rc = LDAP_NOT_ALLOWED_ON_NONLEAF;
221 text = "subtree delete not supported";
224 Debug(LDAP_DEBUG_ARGS,
225 "<=- bdb_delete: has_children failed: %s (%d)\n",
226 db_strerror(rc), rc, 0 );
228 text = "internal error";
233 /* delete from dn2id */
234 rc = bdb_dn2id_delete( be, ltid, pdn, e->e_ndn, e->e_id );
237 case DB_LOCK_DEADLOCK:
238 case DB_LOCK_NOTGRANTED:
243 Debug(LDAP_DEBUG_ARGS,
244 "<=- bdb_delete: dn2id failed: %s (%d)\n",
245 db_strerror(rc), rc, 0 );
246 text = "DN index delete failed";
250 /* delete indices for old attributes */
251 rc = bdb_index_entry_del( be, ltid, e, e->e_attrs );
252 if ( rc != LDAP_SUCCESS ) {
254 case DB_LOCK_DEADLOCK:
255 case DB_LOCK_NOTGRANTED:
260 Debug( LDAP_DEBUG_ANY, "entry index delete failed!\n",
262 text = "entry index delete failed";
266 /* delete from id2entry */
267 rc = bdb_id2entry_delete( be, ltid, e->e_id );
270 case DB_LOCK_DEADLOCK:
271 case DB_LOCK_NOTGRANTED:
276 Debug(LDAP_DEBUG_ARGS,
277 "<=- bdb_delete: id2entry failed: %s (%d)\n",
278 db_strerror(rc), rc, 0 );
279 text = "entry delete failed";
284 #if 0 /* Do we want to reclaim deleted IDs? */
285 ldap_pvt_thread_mutex_lock( &bdb->bi_lastid_mutex );
286 if ( e->e_id == bdb->bi_lastid ) {
287 bdb_last_id( be, ltid );
289 ldap_pvt_thread_mutex_unlock( &bdb->bi_lastid_mutex );
293 rc = txn_commit( ltid, 0 );
296 op->o_private = NULL;
299 Debug( LDAP_DEBUG_TRACE,
300 "bdb_delete: txn_commit failed: %s (%d)\n",
301 db_strerror(rc), rc, 0 );
303 text = "commit failed";
306 Debug( LDAP_DEBUG_TRACE,
307 "bdb_delete: deleted id=%08lx dn=\"%s\"\n",
308 e->e_id, e->e_dn, 0 );
314 send_ldap_result( conn, op, LDAP_SUCCESS,
315 NULL, text, NULL, NULL );
317 if(rc == LDAP_SUCCESS && bdb->bi_txn_cp ) {
318 ldap_pvt_thread_yield();
319 TXN_CHECKPOINT( bdb->bi_dbenv,
320 bdb->bi_txn_cp_kbyte, bdb->bi_txn_cp_min, 0 );
330 bdb_entry_return( be, e );
335 op->o_private = NULL;