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;
35 Debug(LDAP_DEBUG_ARGS, "==> bdb_delete: %s\n", dn, 0, 0);
38 /* transaction retry */
39 retry: rc = txn_abort( ltid );
44 text = "internal error";
49 /* begin transaction */
50 rc = txn_begin( bdb->bi_dbenv, NULL, <id, 0 );
52 Debug( LDAP_DEBUG_TRACE,
53 "bdb_delete: txn_begin failed: %s (%d)\n",
54 db_strerror(rc), rc, 0 );
56 text = "internal error";
62 pdn = dn_parent( be, e->e_ndn );
64 if( pdn != NULL && *pdn != '\0' ) {
65 /* get parent with reader lock */
66 rc = dn2entry_r( be, ltid, pdn, &p, NULL );
74 case DB_LOCK_DEADLOCK:
75 case DB_LOCK_NOTGRANTED:
79 text = "internal error";
84 Debug( LDAP_DEBUG_TRACE,
85 "<=- bdb_delete: parent does not exist\n",
88 text = "could not locate parent of entry";
92 /* check parent for "children" acl */
93 rc = access_allowed( be, conn, op, p,
94 children, NULL, ACL_WRITE );
96 bdb_entry_return( be, p );
99 Debug( LDAP_DEBUG_TRACE,
100 "<=- bdb_delete: no access to parent\n",
102 rc = LDAP_INSUFFICIENT_ACCESS;
109 /* no parent, must be root to delete */
110 if( ! be_isroot( be, op->o_ndn ) ) {
111 Debug( LDAP_DEBUG_TRACE,
112 "<=- bdb_delete: no parent and not root\n",
114 rc = LDAP_INSUFFICIENT_ACCESS;
120 rc = dn2entry_w( be, ltid, ndn, &e, &matched );
126 case DB_LOCK_DEADLOCK:
127 case DB_LOCK_NOTGRANTED:
131 text = "internal error";
136 char *matched_dn = NULL;
137 struct berval **refs = NULL;
139 Debug( LDAP_DEBUG_ARGS,
140 "<=- bdb_delete: no such object %s\n",
143 if ( matched != NULL ) {
144 matched_dn = ch_strdup( matched->e_dn );
145 refs = is_entry_referral( matched )
146 ? get_entry_referrals( be, conn, op, matched )
148 bdb_entry_return( be, matched );
150 refs = default_referral;
153 send_ldap_result( conn, op, LDAP_REFERRAL,
154 matched_dn, NULL, refs, NULL );
156 if ( matched != NULL ) {
157 ber_bvecfree( refs );
165 if ( !manageDSAit && is_entry_referral( e ) ) {
166 /* parent is a referral, don't allow add */
167 /* parent is an alias, don't allow add */
168 struct berval **refs = get_entry_referrals( be,
171 Debug( LDAP_DEBUG_TRACE,
172 "bdb_delete: entry is referral\n",
175 send_ldap_result( conn, op, LDAP_REFERRAL,
176 e->e_dn, NULL, refs, NULL );
178 ber_bvecfree( refs );
184 rc = bdb_dn2id_children( be, ltid, e->e_ndn );
185 if( rc != DB_NOTFOUND ) {
187 case DB_LOCK_DEADLOCK:
188 case DB_LOCK_NOTGRANTED:
191 Debug(LDAP_DEBUG_ARGS,
192 "<=- bdb_delete: non-leaf %s\n",
194 rc = LDAP_NOT_ALLOWED_ON_NONLEAF;
195 text = "subtree delete not supported";
198 Debug(LDAP_DEBUG_ARGS,
199 "<=- bdb_delete: has_children failed: %s (%d)\n",
200 db_strerror(rc), rc, 0 );
202 text = "internal error";
207 /* delete from dn2id */
208 rc = bdb_dn2id_delete( be, ltid, e->e_ndn, e->e_id );
211 case DB_LOCK_DEADLOCK:
212 case DB_LOCK_NOTGRANTED:
217 Debug(LDAP_DEBUG_ARGS,
218 "<=- bdb_delete: dn2id failed: %s (%d)\n",
219 db_strerror(rc), rc, 0 );
220 text = "DN index delete failed";
224 /* delete from id2entry */
225 if ( bdb_id2entry_delete( be, ltid, e->e_id ) != 0 ) {
227 case DB_LOCK_DEADLOCK:
228 case DB_LOCK_NOTGRANTED:
233 Debug(LDAP_DEBUG_ARGS,
234 "<=- bdb_delete: id2entry failed: %s (%d)\n",
235 db_strerror(rc), rc, 0 );
236 text = "entry delete failed";
240 rc = txn_commit( ltid, 0 );
242 op->o_private = NULL;
245 Debug( LDAP_DEBUG_TRACE,
246 "bdb_add: txn_commit failed: %s (%d)\n",
247 db_strerror(rc), rc, 0 );
249 text = "commit failed";
252 Debug( LDAP_DEBUG_TRACE,
253 "bdb_add: added id=%08x dn=\"%s\"\n",
254 e->e_id, e->e_dn, 0 );
260 send_ldap_result( conn, op, LDAP_SUCCESS,
261 NULL, text, NULL, NULL );
265 if( e != NULL ) bdb_entry_return( be, e );
269 op->o_private = NULL;