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,
101 dn->bv_val, LDAP_SCOPE_DEFAULT )
103 bdb_entry_return( be, matched );
107 refs = referral_rewrite( default_referral,
108 NULL, dn->bv_val, LDAP_SCOPE_DEFAULT );
111 send_ldap_result( conn, op, LDAP_REFERRAL,
112 matched_dn, NULL, refs, NULL );
114 ber_bvecfree( refs );
121 pdn = dn_parent( be, ndn->bv_val );
123 if( pdn != NULL && *pdn != '\0' ) {
125 rc = bdb_dn2entry( be, ltid, pdn, &p, NULL, 0 );
131 case DB_LOCK_DEADLOCK:
132 case DB_LOCK_NOTGRANTED:
136 text = "internal error";
141 Debug( LDAP_DEBUG_TRACE,
142 "<=- bdb_delete: parent does not exist\n",
145 text = "could not locate parent of entry";
149 /* check parent for "children" acl */
150 rc = access_allowed( be, conn, op, p,
151 children, NULL, ACL_WRITE );
153 bdb_entry_return( be, p );
157 Debug( LDAP_DEBUG_TRACE,
158 "<=- bdb_delete: no access to parent\n",
160 rc = LDAP_INSUFFICIENT_ACCESS;
165 /* no parent, must be root to delete */
166 if( ! be_isroot( be, &op->o_ndn ) ) {
167 if ( be_issuffix( be, "" ) || be_isupdate( be, &op->o_ndn ) ) {
168 p = (Entry *)&slap_entry_root;
170 /* check parent for "children" acl */
171 rc = access_allowed( be, conn, op, p,
172 children, NULL, ACL_WRITE );
176 Debug( LDAP_DEBUG_TRACE,
177 "<=- bdb_delete: no access "
178 "to parent\n", 0, 0, 0 );
179 rc = LDAP_INSUFFICIENT_ACCESS;
184 Debug( LDAP_DEBUG_TRACE,
185 "<=- bdb_delete: no parent "
186 "and not root\n", 0, 0, 0);
187 rc = LDAP_INSUFFICIENT_ACCESS;
193 if ( !manageDSAit && is_entry_referral( e ) ) {
194 /* parent is a referral, don't allow add */
195 /* parent is an alias, don't allow add */
196 struct berval **refs = get_entry_referrals( be,
197 conn, op, e, dn->bv_val, LDAP_SCOPE_DEFAULT );
199 Debug( LDAP_DEBUG_TRACE,
200 "bdb_delete: entry is referral\n",
203 send_ldap_result( conn, op, LDAP_REFERRAL,
204 e->e_dn, NULL, refs, NULL );
206 ber_bvecfree( refs );
212 rc = bdb_dn2id_children( be, ltid, e->e_ndn );
213 if( rc != DB_NOTFOUND ) {
215 case DB_LOCK_DEADLOCK:
216 case DB_LOCK_NOTGRANTED:
219 Debug(LDAP_DEBUG_ARGS,
220 "<=- bdb_delete: non-leaf %s\n",
222 rc = LDAP_NOT_ALLOWED_ON_NONLEAF;
223 text = "subtree delete not supported";
226 Debug(LDAP_DEBUG_ARGS,
227 "<=- bdb_delete: has_children failed: %s (%d)\n",
228 db_strerror(rc), rc, 0 );
230 text = "internal error";
235 /* delete from dn2id */
236 rc = bdb_dn2id_delete( be, ltid, pdn, e );
239 case DB_LOCK_DEADLOCK:
240 case DB_LOCK_NOTGRANTED:
245 Debug(LDAP_DEBUG_ARGS,
246 "<=- bdb_delete: dn2id failed: %s (%d)\n",
247 db_strerror(rc), rc, 0 );
248 text = "DN index delete failed";
252 /* delete indices for old attributes */
253 rc = bdb_index_entry_del( be, ltid, e, e->e_attrs );
254 if ( rc != LDAP_SUCCESS ) {
256 case DB_LOCK_DEADLOCK:
257 case DB_LOCK_NOTGRANTED:
262 Debug( LDAP_DEBUG_ANY, "entry index delete failed!\n",
264 text = "entry index delete failed";
268 /* delete from id2entry */
269 rc = bdb_id2entry_delete( be, ltid, e->e_id );
272 case DB_LOCK_DEADLOCK:
273 case DB_LOCK_NOTGRANTED:
278 Debug(LDAP_DEBUG_ARGS,
279 "<=- bdb_delete: id2entry failed: %s (%d)\n",
280 db_strerror(rc), rc, 0 );
281 text = "entry delete failed";
286 #if 0 /* Do we want to reclaim deleted IDs? */
287 ldap_pvt_thread_mutex_lock( &bdb->bi_lastid_mutex );
288 if ( e->e_id == bdb->bi_lastid ) {
289 bdb_last_id( be, ltid );
291 ldap_pvt_thread_mutex_unlock( &bdb->bi_lastid_mutex );
295 rc = txn_commit( ltid, 0 );
298 op->o_private = NULL;
301 Debug( LDAP_DEBUG_TRACE,
302 "bdb_delete: txn_commit failed: %s (%d)\n",
303 db_strerror(rc), rc, 0 );
305 text = "commit failed";
308 Debug( LDAP_DEBUG_TRACE,
309 "bdb_delete: deleted id=%08lx dn=\"%s\"\n",
310 e->e_id, e->e_dn, 0 );
316 send_ldap_result( conn, op, LDAP_SUCCESS,
317 NULL, text, NULL, NULL );
319 if(rc == LDAP_SUCCESS && bdb->bi_txn_cp ) {
320 ldap_pvt_thread_yield();
321 TXN_CHECKPOINT( bdb->bi_dbenv,
322 bdb->bi_txn_cp_kbyte, bdb->bi_txn_cp_min, 0 );
328 bdb_entry_return( be, e );
333 op->o_private = NULL;