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>
24 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
29 const char *text = NULL;
30 int manageDSAit = get_manageDSAit( op );
31 AttributeDescription *children = slap_schema.si_ad_children;
34 Debug(LDAP_DEBUG_ARGS, "==> bdb_delete: %s\n", dn, 0, 0);
37 retry: rc = txn_abort( ltid );
42 text = "internal error";
47 /* begin transaction */
48 rc = txn_begin( bdb->bi_dbenv, NULL, <id, 0 );
50 Debug( LDAP_DEBUG_TRACE,
51 "bdb_delete: txn_begin failed: %s (%d)\n",
52 db_strerror(rc), rc, 0 );
54 text = "internal error";
60 pdn = dn_parent( be, e->e_ndn );
62 if( pdn != NULL && *pdn != '\0' ) {
63 /* get parent with reader lock */
64 rc = dn2entry_r( be, ltid, pdn, &p, NULL );
69 case DB_LOCK_DEADLOCK:
70 case DB_LOCK_NOTGRANTED:
74 text = "internal error";
79 Debug( LDAP_DEBUG_TRACE,
80 "<=- bdb_delete: parent does not exist\n",
83 text = "could not locate parent of entry";
87 /* check parent for "children" acl */
88 rc = access_allowed( be, conn, op, p,
89 children, NULL, ACL_WRITE );
91 bdb_entry_return( be, p );
94 Debug( LDAP_DEBUG_TRACE,
95 "<=- bdb_delete: no access to parent\n",
97 rc = LDAP_INSUFFICIENT_ACCESS;
104 /* no parent, must be root to delete */
105 if( ! be_isroot( be, op->o_ndn ) ) {
106 Debug( LDAP_DEBUG_TRACE,
107 "<=- bdb_delete: no parent and not root\n",
109 rc = LDAP_INSUFFICIENT_ACCESS;
115 rc = dn2entry_w( be, ltid, ndn, &e, &matched );
118 case DB_LOCK_DEADLOCK:
119 case DB_LOCK_NOTGRANTED:
123 text = "internal error";
128 char *matched_dn = NULL;
129 struct berval **refs = NULL;
131 Debug( LDAP_DEBUG_ARGS,
132 "<=- bdb_delete: no such object %s\n",
135 if ( matched != NULL ) {
136 matched_dn = ch_strdup( matched->e_dn );
137 refs = is_entry_referral( matched )
138 ? get_entry_referrals( be, conn, op, matched )
140 bdb_entry_return( be, matched );
142 refs = default_referral;
145 send_ldap_result( conn, op, LDAP_REFERRAL,
146 matched_dn, NULL, refs, NULL );
148 if ( matched != NULL ) {
149 ber_bvecfree( refs );
157 if ( !manageDSAit && is_entry_referral( e ) ) {
158 /* parent is a referral, don't allow add */
159 /* parent is an alias, don't allow add */
160 struct berval **refs = get_entry_referrals( be,
163 Debug( LDAP_DEBUG_TRACE,
164 "bdb_delete: entry is referral\n",
167 send_ldap_result( conn, op, LDAP_REFERRAL,
168 e->e_dn, NULL, refs, NULL );
170 ber_bvecfree( refs );
177 if ( bdb_has_children( be, e ) ) {
178 Debug(LDAP_DEBUG_ARGS,
179 "<=- bdb_delete: non leaf %s\n",
181 rc = LDAP_NOT_ALLOWED_ON_NONLEAF;
182 text = "subtree delete not supported";
186 /* delete from dn2id mapping */
187 if ( bdb_dn2id_delete( be, e->e_ndn, e->e_id ) != 0 ) {
188 Debug(LDAP_DEBUG_ARGS,
189 "<=- ldbm_back_delete: operations error %s\n",
192 text = "DN index delete failed";
196 /* delete from disk and cache */
197 if ( bdb_id2entry_delete( be, e ) != 0 ) {
198 Debug(LDAP_DEBUG_ARGS,
199 "<=- bdb_delete: operations error %s\n",
202 text = "entry delete failed";
206 rc = txn_commit( ltid, 0 );
208 op->o_private = NULL;
211 Debug( LDAP_DEBUG_TRACE,
212 "bdb_add: txn_commit failed: %s (%d)\n",
213 db_strerror(rc), rc, 0 );
215 text = "commit failed";
217 Debug( LDAP_DEBUG_TRACE,
218 "bdb_add: added id=%08x dn=\"%s\"\n",
219 e->e_id, e->e_dn, 0 );
225 send_ldap_result( conn, op, LDAP_SUCCESS,
226 NULL, text, NULL, NULL );
229 /* free entry and writer lock */
230 bdb_entry_return( be, e );
234 op->o_private = NULL;