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;
86 struct berval **refs = 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 )
97 bdb_entry_return( be, matched );
101 refs = default_referral;
104 send_ldap_result( conn, op, LDAP_REFERRAL,
105 matched_dn, NULL, refs, NULL );
107 if ( matched != NULL ) {
108 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 Debug( LDAP_DEBUG_TRACE,
167 "<=- bdb_delete: no parent and not root\n",
169 rc = LDAP_INSUFFICIENT_ACCESS;
174 if ( !manageDSAit && is_entry_referral( e ) ) {
175 /* parent is a referral, don't allow add */
176 /* parent is an alias, don't allow add */
177 struct berval **refs = get_entry_referrals( be,
180 Debug( LDAP_DEBUG_TRACE,
181 "bdb_delete: entry is referral\n",
184 send_ldap_result( conn, op, LDAP_REFERRAL,
185 e->e_dn, NULL, refs, NULL );
187 ber_bvecfree( refs );
193 rc = bdb_dn2id_children( be, ltid, e->e_ndn );
194 if( rc != DB_NOTFOUND ) {
196 case DB_LOCK_DEADLOCK:
197 case DB_LOCK_NOTGRANTED:
200 Debug(LDAP_DEBUG_ARGS,
201 "<=- bdb_delete: non-leaf %s\n",
203 rc = LDAP_NOT_ALLOWED_ON_NONLEAF;
204 text = "subtree delete not supported";
207 Debug(LDAP_DEBUG_ARGS,
208 "<=- bdb_delete: has_children failed: %s (%d)\n",
209 db_strerror(rc), rc, 0 );
211 text = "internal error";
216 /* delete from dn2id */
217 rc = bdb_dn2id_delete( be, ltid, e->e_ndn, e->e_id );
220 case DB_LOCK_DEADLOCK:
221 case DB_LOCK_NOTGRANTED:
226 Debug(LDAP_DEBUG_ARGS,
227 "<=- bdb_delete: dn2id failed: %s (%d)\n",
228 db_strerror(rc), rc, 0 );
229 text = "DN index delete failed";
233 /* delete indices for old attributes */
234 rc = bdb_index_entry_del( be, ltid, e, e->e_attrs );
235 if ( rc != LDAP_SUCCESS ) {
237 case DB_LOCK_DEADLOCK:
238 case DB_LOCK_NOTGRANTED:
243 Debug( LDAP_DEBUG_ANY, "entry index delete failed!\n",
245 text = "entry index delete failed";
249 /* delete from id2entry */
250 if ( bdb_id2entry_delete( be, ltid, e->e_id ) != 0 ) {
252 case DB_LOCK_DEADLOCK:
253 case DB_LOCK_NOTGRANTED:
258 Debug(LDAP_DEBUG_ARGS,
259 "<=- bdb_delete: id2entry failed: %s (%d)\n",
260 db_strerror(rc), rc, 0 );
261 text = "entry delete failed";
265 rc = txn_commit( ltid, 0 );
267 op->o_private = NULL;
270 Debug( LDAP_DEBUG_TRACE,
271 "bdb_add: txn_commit failed: %s (%d)\n",
272 db_strerror(rc), rc, 0 );
274 text = "commit failed";
277 Debug( LDAP_DEBUG_TRACE,
278 "bdb_add: added id=%08x dn=\"%s\"\n",
279 e->e_id, e->e_dn, 0 );
285 send_ldap_result( conn, op, LDAP_SUCCESS,
286 NULL, text, NULL, NULL );
288 if(rc == LDAP_SUCCESS && bdb->bi_txn_cp ) {
289 ldap_pvt_thread_yield();
290 txn_checkpoint( bdb->bi_dbenv,
291 bdb->bi_txn_cp_kbyte, bdb->bi_txn_cp_min, 0 );
297 bdb_entry_return( be, e );
302 op->o_private = NULL;