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 /* transaction retry */
40 retry: rc = txn_abort( ltid );
45 text = "internal error";
50 /* begin transaction */
51 rc = txn_begin( bdb->bi_dbenv, NULL, <id, 0 );
53 Debug( LDAP_DEBUG_TRACE,
54 "bdb_delete: txn_begin failed: %s (%d)\n",
55 db_strerror(rc), rc, 0 );
57 text = "internal error";
62 opinfo.boi_txn = ltid;
64 op->o_private = &opinfo;
66 /* get entry for read/modify/write */
67 rc = bdb_dn2entry( be, ltid, ndn, &e, &matched, DB_RMW );
73 case DB_LOCK_DEADLOCK:
74 case DB_LOCK_NOTGRANTED:
78 text = "internal error";
83 char *matched_dn = NULL;
84 struct berval **refs = NULL;
86 Debug( LDAP_DEBUG_ARGS,
87 "<=- bdb_delete: no such object %s\n",
90 if ( matched != NULL ) {
91 matched_dn = ch_strdup( matched->e_dn );
92 refs = is_entry_referral( matched )
93 ? get_entry_referrals( be, conn, op, matched )
95 bdb_entry_return( be, matched );
97 refs = default_referral;
100 send_ldap_result( conn, op, LDAP_REFERRAL,
101 matched_dn, NULL, refs, NULL );
103 if ( matched != NULL ) {
104 ber_bvecfree( refs );
112 pdn = dn_parent( be, ndn );
114 if( pdn != NULL && *pdn != '\0' ) {
116 rc = bdb_dn2entry( be, ltid, pdn, &p, NULL, 0 );
124 case DB_LOCK_DEADLOCK:
125 case DB_LOCK_NOTGRANTED:
129 text = "internal error";
134 Debug( LDAP_DEBUG_TRACE,
135 "<=- bdb_delete: parent does not exist\n",
138 text = "could not locate parent of entry";
142 /* check parent for "children" acl */
143 rc = access_allowed( be, conn, op, p,
144 children, NULL, ACL_WRITE );
146 bdb_entry_return( be, p );
149 Debug( LDAP_DEBUG_TRACE,
150 "<=- bdb_delete: no access to parent\n",
152 rc = LDAP_INSUFFICIENT_ACCESS;
159 /* no parent, must be root to delete */
160 if( ! be_isroot( be, op->o_ndn ) ) {
161 Debug( LDAP_DEBUG_TRACE,
162 "<=- bdb_delete: no parent and not root\n",
164 rc = LDAP_INSUFFICIENT_ACCESS;
169 if ( !manageDSAit && is_entry_referral( e ) ) {
170 /* parent is a referral, don't allow add */
171 /* parent is an alias, don't allow add */
172 struct berval **refs = get_entry_referrals( be,
175 Debug( LDAP_DEBUG_TRACE,
176 "bdb_delete: entry is referral\n",
179 send_ldap_result( conn, op, LDAP_REFERRAL,
180 e->e_dn, NULL, refs, NULL );
182 ber_bvecfree( refs );
188 rc = bdb_dn2id_children( be, ltid, e->e_ndn );
189 if( rc != DB_NOTFOUND ) {
191 case DB_LOCK_DEADLOCK:
192 case DB_LOCK_NOTGRANTED:
195 Debug(LDAP_DEBUG_ARGS,
196 "<=- bdb_delete: non-leaf %s\n",
198 rc = LDAP_NOT_ALLOWED_ON_NONLEAF;
199 text = "subtree delete not supported";
202 Debug(LDAP_DEBUG_ARGS,
203 "<=- bdb_delete: has_children failed: %s (%d)\n",
204 db_strerror(rc), rc, 0 );
206 text = "internal error";
211 /* delete from dn2id */
212 rc = bdb_dn2id_delete( be, ltid, e->e_ndn, e->e_id );
215 case DB_LOCK_DEADLOCK:
216 case DB_LOCK_NOTGRANTED:
221 Debug(LDAP_DEBUG_ARGS,
222 "<=- bdb_delete: dn2id failed: %s (%d)\n",
223 db_strerror(rc), rc, 0 );
224 text = "DN index delete failed";
228 /* delete from id2entry */
229 if ( bdb_id2entry_delete( be, ltid, e->e_id ) != 0 ) {
231 case DB_LOCK_DEADLOCK:
232 case DB_LOCK_NOTGRANTED:
237 Debug(LDAP_DEBUG_ARGS,
238 "<=- bdb_delete: id2entry failed: %s (%d)\n",
239 db_strerror(rc), rc, 0 );
240 text = "entry delete failed";
244 rc = txn_commit( ltid, 0 );
246 op->o_private = NULL;
249 Debug( LDAP_DEBUG_TRACE,
250 "bdb_add: txn_commit failed: %s (%d)\n",
251 db_strerror(rc), rc, 0 );
253 text = "commit failed";
256 Debug( LDAP_DEBUG_TRACE,
257 "bdb_add: added id=%08x dn=\"%s\"\n",
258 e->e_id, e->e_dn, 0 );
264 send_ldap_result( conn, op, LDAP_SUCCESS,
265 NULL, text, NULL, NULL );
269 if( e != NULL ) bdb_entry_return( be, e );
273 op->o_private = NULL;