1 /* delete.c - ldbm 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;
30 const char *text = NULL;
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 );
54 Debug( LDAP_DEBUG_TRACE,
55 "bdb_delete: txn_begin failed: %s (%d)\n",
56 db_strerror(rc), rc, 0 );
58 text = "internal error";
63 opinfo.boi_txn = ltid;
65 op->o_private = &opinfo;
67 /* get entry for read/modify/write */
68 rc = bdb_dn2entry( be, ltid, ndn, &e, &matched, DB_RMW );
74 case DB_LOCK_DEADLOCK:
75 case DB_LOCK_NOTGRANTED:
79 text = "internal error";
84 char *matched_dn = NULL;
85 struct berval **refs = NULL;
87 Debug( LDAP_DEBUG_ARGS,
88 "<=- bdb_delete: no such object %s\n",
91 if ( matched != NULL ) {
92 matched_dn = ch_strdup( matched->e_dn );
93 refs = is_entry_referral( matched )
94 ? get_entry_referrals( be, conn, op, matched )
96 bdb_entry_return( be, matched );
98 refs = default_referral;
101 send_ldap_result( conn, op, LDAP_REFERRAL,
102 matched_dn, NULL, refs, NULL );
104 if ( matched != NULL ) {
105 ber_bvecfree( refs );
113 pdn = dn_parent( be, ndn );
115 if( pdn != NULL && *pdn != '\0' ) {
117 rc = bdb_dn2entry( be, ltid, pdn, &p, NULL, 0 );
125 case DB_LOCK_DEADLOCK:
126 case DB_LOCK_NOTGRANTED:
130 text = "internal error";
135 Debug( LDAP_DEBUG_TRACE,
136 "<=- bdb_delete: parent does not exist\n",
139 text = "could not locate parent of entry";
143 /* check parent for "children" acl */
144 rc = access_allowed( be, conn, op, p,
145 children, NULL, ACL_WRITE );
147 bdb_entry_return( be, p );
150 Debug( LDAP_DEBUG_TRACE,
151 "<=- bdb_delete: no access to parent\n",
153 rc = LDAP_INSUFFICIENT_ACCESS;
160 /* no parent, must be root to delete */
161 if( ! be_isroot( be, op->o_ndn ) ) {
162 Debug( LDAP_DEBUG_TRACE,
163 "<=- bdb_delete: no parent and not root\n",
165 rc = LDAP_INSUFFICIENT_ACCESS;
170 if ( !manageDSAit && is_entry_referral( e ) ) {
171 /* parent is a referral, don't allow add */
172 /* parent is an alias, don't allow add */
173 struct berval **refs = get_entry_referrals( be,
176 Debug( LDAP_DEBUG_TRACE,
177 "bdb_delete: entry is referral\n",
180 send_ldap_result( conn, op, LDAP_REFERRAL,
181 e->e_dn, NULL, refs, NULL );
183 ber_bvecfree( refs );
189 rc = bdb_dn2id_children( be, ltid, e->e_ndn );
190 if( rc != DB_NOTFOUND ) {
192 case DB_LOCK_DEADLOCK:
193 case DB_LOCK_NOTGRANTED:
196 Debug(LDAP_DEBUG_ARGS,
197 "<=- bdb_delete: non-leaf %s\n",
199 rc = LDAP_NOT_ALLOWED_ON_NONLEAF;
200 text = "subtree delete not supported";
203 Debug(LDAP_DEBUG_ARGS,
204 "<=- bdb_delete: has_children failed: %s (%d)\n",
205 db_strerror(rc), rc, 0 );
207 text = "internal error";
212 /* delete from dn2id */
213 rc = bdb_dn2id_delete( be, ltid, e->e_ndn, e->e_id );
216 case DB_LOCK_DEADLOCK:
217 case DB_LOCK_NOTGRANTED:
222 Debug(LDAP_DEBUG_ARGS,
223 "<=- bdb_delete: dn2id failed: %s (%d)\n",
224 db_strerror(rc), rc, 0 );
225 text = "DN index delete failed";
229 /* delete from id2entry */
230 if ( bdb_id2entry_delete( be, ltid, e->e_id ) != 0 ) {
232 case DB_LOCK_DEADLOCK:
233 case DB_LOCK_NOTGRANTED:
238 Debug(LDAP_DEBUG_ARGS,
239 "<=- bdb_delete: id2entry failed: %s (%d)\n",
240 db_strerror(rc), rc, 0 );
241 text = "entry delete failed";
245 rc = txn_commit( ltid, 0 );
247 op->o_private = NULL;
250 Debug( LDAP_DEBUG_TRACE,
251 "bdb_add: txn_commit failed: %s (%d)\n",
252 db_strerror(rc), rc, 0 );
254 text = "commit failed";
257 Debug( LDAP_DEBUG_TRACE,
258 "bdb_add: added id=%08x dn=\"%s\"\n",
259 e->e_id, e->e_dn, 0 );
265 send_ldap_result( conn, op, LDAP_SUCCESS,
266 NULL, text, NULL, NULL );
270 if( e != NULL ) bdb_entry_return( be, e );
274 op->o_private = NULL;