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";
51 /* begin transaction */
52 rc = txn_begin( bdb->bi_dbenv, NULL, <id, 0 );
55 Debug( LDAP_DEBUG_TRACE,
56 "bdb_delete: txn_begin failed: %s (%d)\n",
57 db_strerror(rc), rc, 0 );
59 text = "internal error";
64 opinfo.boi_txn = ltid;
66 op->o_private = &opinfo;
68 /* get entry for read/modify/write */
69 rc = bdb_dn2entry( be, ltid, ndn, &e, &matched, DB_RMW );
75 case DB_LOCK_DEADLOCK:
76 case DB_LOCK_NOTGRANTED:
80 text = "internal error";
85 char *matched_dn = NULL;
88 Debug( LDAP_DEBUG_ARGS,
89 "<=- bdb_delete: no such object %s\n",
92 if ( matched != NULL ) {
93 matched_dn = ch_strdup( matched->e_dn );
94 refs = is_entry_referral( matched )
95 ? get_entry_referrals( be, conn, op, matched,
96 dn, LDAP_SCOPE_DEFAULT )
98 bdb_entry_return( be, matched );
102 refs = referral_rewrite( default_referral,
103 NULL, dn, LDAP_SCOPE_DEFAULT );
106 send_ldap_result( conn, op, LDAP_REFERRAL,
107 matched_dn, NULL, refs, NULL );
109 ber_bvecfree( refs );
116 pdn = dn_parent( be, ndn );
118 if( pdn != NULL && *pdn != '\0' ) {
120 rc = bdb_dn2entry( be, ltid, pdn, &p, NULL, 0 );
128 case DB_LOCK_DEADLOCK:
129 case DB_LOCK_NOTGRANTED:
133 text = "internal error";
138 Debug( LDAP_DEBUG_TRACE,
139 "<=- bdb_delete: parent does not exist\n",
142 text = "could not locate parent of entry";
146 /* check parent for "children" acl */
147 rc = access_allowed( be, conn, op, p,
148 children, NULL, ACL_WRITE );
150 bdb_entry_return( be, p );
154 Debug( LDAP_DEBUG_TRACE,
155 "<=- bdb_delete: no access to parent\n",
157 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,
196 conn, op, e, dn, LDAP_SCOPE_DEFAULT );
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, e->e_ndn, e->e_id );
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 if ( bdb_id2entry_delete( be, ltid, e->e_id ) != 0 ) {
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";
283 rc = txn_commit( ltid, 0 );
285 op->o_private = NULL;
288 Debug( LDAP_DEBUG_TRACE,
289 "bdb_add: txn_commit failed: %s (%d)\n",
290 db_strerror(rc), rc, 0 );
292 text = "commit failed";
295 Debug( LDAP_DEBUG_TRACE,
296 "bdb_add: added id=%08lx dn=\"%s\"\n",
297 e->e_id, e->e_dn, 0 );
303 send_ldap_result( conn, op, LDAP_SUCCESS,
304 NULL, text, NULL, NULL );
306 if(rc == LDAP_SUCCESS && bdb->bi_txn_cp ) {
307 ldap_pvt_thread_yield();
308 txn_checkpoint( bdb->bi_dbenv,
309 bdb->bi_txn_cp_kbyte, bdb->bi_txn_cp_min, 0 );
315 bdb_entry_return( be, e );
320 op->o_private = NULL;