1 /* delete.c - ldbm backend delete routine */
4 * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
12 #include <ac/string.h>
13 #include <ac/socket.h>
16 #include "back-ldbm.h"
17 #include "proto-back-ldbm.h"
28 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
33 int manageDSAit = get_manageDSAit( op );
34 AttributeDescription *children = slap_schema.si_ad_children;
35 AttributeDescription *entry = slap_schema.si_ad_entry;
38 LDAP_LOG( BACK_LDBM, ENTRY, "ldbm_back_delete: %s\n", dn->bv_val, 0, 0 );
40 Debug(LDAP_DEBUG_ARGS, "==> ldbm_back_delete: %s\n", dn->bv_val, 0, 0);
43 /* grab giant lock for writing */
44 ldap_pvt_thread_rdwr_wlock(&li->li_giant_rwlock);
46 /* get entry with writer lock */
47 if ( (e = dn2entry_w( be, ndn, &matched )) == NULL ) {
48 char *matched_dn = NULL;
52 LDAP_LOG( BACK_LDBM, INFO,
53 "ldbm_back_delete: no such object %s\n", dn->bv_val, 0, 0 );
55 Debug(LDAP_DEBUG_ARGS, "<=- ldbm_back_delete: no such object %s\n",
59 if ( matched != NULL ) {
60 matched_dn = ch_strdup( matched->e_dn );
61 refs = is_entry_referral( matched )
62 ? get_entry_referrals( be, conn, op, matched )
64 cache_return_entry_r( &li->li_cache, matched );
67 refs = referral_rewrite( default_referral,
68 NULL, dn, LDAP_SCOPE_DEFAULT );
71 ldap_pvt_thread_rdwr_wunlock(&li->li_giant_rwlock);
73 send_ldap_result( conn, op, LDAP_REFERRAL,
74 matched_dn, NULL, refs, NULL );
76 if ( refs ) ber_bvarray_free( refs );
82 /* check entry for "entry" acl */
83 if ( ! access_allowed( be, conn, op, e,
84 entry, NULL, ACL_WRITE, NULL ) )
87 LDAP_LOG( BACK_LDBM, ERR,
88 "ldbm_back_delete: no write access to entry of (%s)\n",
91 Debug( LDAP_DEBUG_TRACE,
92 "<=- ldbm_back_delete: no write access to entry\n", 0,
96 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
97 NULL, "no write access to entry", NULL, NULL );
103 if ( !manageDSAit && is_entry_referral( e ) ) {
104 /* parent is a referral, don't allow add */
105 /* parent is an alias, don't allow add */
106 BerVarray refs = get_entry_referrals( be,
110 LDAP_LOG( BACK_LDBM, INFO,
111 "ldbm_back_delete: entry (%s) is a referral.\n", e->e_dn, 0, 0 );
113 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
117 send_ldap_result( conn, op, LDAP_REFERRAL,
118 e->e_dn, NULL, refs, NULL );
120 if ( refs ) ber_bvarray_free( refs );
126 if ( has_children( be, e ) ) {
128 LDAP_LOG( BACK_LDBM, ERR,
129 "ldbm_back_delete: (%s) is a non-leaf node.\n", dn->bv_val, 0,0);
131 Debug(LDAP_DEBUG_ARGS, "<=- ldbm_back_delete: non leaf %s\n",
135 send_ldap_result( conn, op, LDAP_NOT_ALLOWED_ON_NONLEAF,
136 NULL, "subtree delete not supported", NULL, NULL );
140 /* delete from parent's id2children entry */
141 if( !be_issuffix( be, &e->e_nname ) && (dnParent( &e->e_nname, &pdn ),
143 if( (p = dn2entry_w( be, &pdn, NULL )) == NULL) {
145 LDAP_LOG( BACK_LDBM, ERR,
146 "ldbm_back_delete: parent of (%s) does not exist\n", dn, 0, 0 );
148 Debug( LDAP_DEBUG_TRACE,
149 "<=- ldbm_back_delete: parent does not exist\n",
153 send_ldap_result( conn, op, LDAP_OTHER,
154 NULL, "could not locate parent of entry", NULL, NULL );
158 /* check parent for "children" acl */
159 if ( ! access_allowed( be, conn, op, p,
160 children, NULL, ACL_WRITE, NULL ) )
163 LDAP_LOG( BACK_LDBM, ERR,
164 "ldbm_back_delete: no access to parent of (%s)\n",
167 Debug( LDAP_DEBUG_TRACE,
168 "<=- ldbm_back_delete: no access to parent\n", 0,
172 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
173 NULL, "no write access to parent", NULL, NULL );
178 /* no parent, must be root to delete */
179 if( ! be_isroot( be, &op->o_ndn ) ) {
180 if ( be_issuffix( be, (struct berval *)&slap_empty_bv ) || be_isupdate( be, &op->o_ndn ) ) {
181 p = (Entry *)&slap_entry_root;
183 rc = access_allowed( be, conn, op, p,
184 children, NULL, ACL_WRITE, NULL );
187 /* check parent for "children" acl */
190 LDAP_LOG( BACK_LDBM, ERR,
191 "ldbm_back_delete: no access "
192 "to parent of ("")\n", 0, 0, 0 );
194 Debug( LDAP_DEBUG_TRACE,
195 "<=- ldbm_back_delete: no "
196 "access to parent\n", 0, 0, 0 );
199 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
200 NULL, "no write access to parent", NULL, NULL );
206 LDAP_LOG( BACK_LDBM, ERR,
207 "ldbm_back_delete: (%s) has no "
208 "parent & not a root.\n", dn, 0, 0 );
210 Debug( LDAP_DEBUG_TRACE,
211 "<=- ldbm_back_delete: no parent & "
212 "not root\n", 0, 0, 0);
215 send_ldap_result( conn, op,
216 LDAP_INSUFFICIENT_ACCESS,
217 NULL, NULL, NULL, NULL );
223 /* delete from dn2id mapping */
224 if ( dn2id_delete( be, &e->e_nname, e->e_id ) != 0 ) {
226 LDAP_LOG( BACK_LDBM, ERR,
227 "ldbm_back_delete: (%s) operations error\n", dn->bv_val, 0, 0 );
229 Debug(LDAP_DEBUG_ARGS,
230 "<=- ldbm_back_delete: operations error %s\n",
234 send_ldap_result( conn, op, LDAP_OTHER,
235 NULL, "DN index delete failed", NULL, NULL );
239 /* delete from disk and cache */
240 if ( id2entry_delete( be, e ) != 0 ) {
242 LDAP_LOG( BACK_LDBM, ERR,
243 "ldbm_back_delete: (%s) operations error\n", dn->bv_val, 0, 0 );
245 Debug(LDAP_DEBUG_ARGS,
246 "<=- ldbm_back_delete: operations error %s\n",
250 send_ldap_result( conn, op, LDAP_OTHER,
251 NULL, "entry delete failed", NULL, NULL );
255 /* delete attribute indices */
256 (void) index_entry_del( be, e, e->e_attrs );
258 send_ldap_result( conn, op, LDAP_SUCCESS,
259 NULL, NULL, NULL, NULL );
264 /* free parent and writer lock */
265 cache_return_entry_w( &li->li_cache, p );
268 /* free entry and writer lock */
269 cache_return_entry_w( &li->li_cache, e );
271 ldap_pvt_thread_rdwr_wunlock(&li->li_giant_rwlock);