1 /* delete.c - ldbm backend delete routine */
4 * Copyright 1998-2003 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"
24 struct ldbminfo *li = (struct ldbminfo *) op->o_bd->be_private;
29 int manageDSAit = get_manageDSAit( op );
30 AttributeDescription *children = slap_schema.si_ad_children;
31 AttributeDescription *entry = slap_schema.si_ad_entry;
34 LDAP_LOG( BACK_LDBM, ENTRY, "ldbm_back_delete: %s\n", op->o_req_dn.bv_val, 0, 0 );
36 Debug(LDAP_DEBUG_ARGS, "==> ldbm_back_delete: %s\n", op->o_req_dn.bv_val, 0, 0);
39 /* grab giant lock for writing */
40 ldap_pvt_thread_rdwr_wlock(&li->li_giant_rwlock);
42 /* get entry with writer lock */
43 e = dn2entry_w( op->o_bd, &op->o_req_ndn, &matched );
45 /* FIXME : dn2entry() should return non-glue entry */
46 if ( e == NULL || ( !manageDSAit && is_entry_glue( e ))) {
48 LDAP_LOG( BACK_LDBM, INFO,
49 "ldbm_back_delete: no such object %s\n", op->o_req_dn.bv_val, 0, 0 );
51 Debug(LDAP_DEBUG_ARGS, "<=- ldbm_back_delete: no such object %s\n",
52 op->o_req_dn.bv_val, 0, 0);
55 if ( matched != NULL ) {
56 rs->sr_matched = ch_strdup( matched->e_dn );
57 rs->sr_ref = is_entry_referral( matched )
58 ? get_entry_referrals( op, matched )
60 cache_return_entry_r( &li->li_cache, matched );
63 BerVarray deref = op->o_bd->be_syncinfo ?
64 op->o_bd->be_syncinfo->si_provideruri_bv : default_referral;
65 rs->sr_ref = referral_rewrite( deref, NULL, &op->o_req_dn,
69 ldap_pvt_thread_rdwr_wunlock(&li->li_giant_rwlock);
71 rs->sr_err = LDAP_REFERRAL;
72 send_ldap_result( op, rs );
74 if ( rs->sr_ref ) ber_bvarray_free( rs->sr_ref );
75 free( (char *)rs->sr_matched );
77 rs->sr_matched = NULL;
81 /* check entry for "entry" acl */
82 if ( ! access_allowed( op, e,
83 entry, NULL, ACL_WRITE, NULL ) )
86 LDAP_LOG( BACK_LDBM, ERR,
87 "ldbm_back_delete: no write access to entry of (%s)\n",
88 op->o_req_dn.bv_val, 0, 0 );
90 Debug( LDAP_DEBUG_TRACE,
91 "<=- ldbm_back_delete: no write access to entry\n", 0,
95 send_ldap_error( op, rs, LDAP_INSUFFICIENT_ACCESS,
96 "no write access to entry" );
98 rc = LDAP_INSUFFICIENT_ACCESS;
102 if ( !manageDSAit && is_entry_referral( e ) ) {
103 /* parent is a referral, don't allow add */
104 /* parent is an alias, don't allow add */
105 rs->sr_ref = get_entry_referrals( op, e );
108 LDAP_LOG( BACK_LDBM, INFO,
109 "ldbm_back_delete: entry (%s) is a referral.\n", e->e_dn, 0, 0 );
111 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
115 rs->sr_err = LDAP_REFERRAL;
116 rs->sr_matched = e->e_name.bv_val;
117 send_ldap_result( op, rs );
119 if ( rs->sr_ref ) ber_bvarray_free( rs->sr_ref );
121 rs->sr_matched = NULL;
126 if ( has_children( op->o_bd, e ) ) {
128 LDAP_LOG( BACK_LDBM, ERR,
129 "ldbm_back_delete: (%s) is a non-leaf node.\n", op->o_req_dn.bv_val, 0,0);
131 Debug(LDAP_DEBUG_ARGS, "<=- ldbm_back_delete: non leaf %s\n",
132 op->o_req_dn.bv_val, 0, 0);
135 send_ldap_error( op, rs, LDAP_NOT_ALLOWED_ON_NONLEAF,
136 "subtree delete not supported" );
140 /* delete from parent's id2children entry */
141 if( !be_issuffix( op->o_bd, &e->e_nname ) && (dnParent( &e->e_nname, &pdn ),
143 if( (p = dn2entry_w( op->o_bd, &pdn, NULL )) == NULL) {
145 LDAP_LOG( BACK_LDBM, ERR,
146 "ldbm_back_delete: parent of (%s) does not exist\n", op->o_req_dn, 0, 0 );
148 Debug( LDAP_DEBUG_TRACE,
149 "<=- ldbm_back_delete: parent does not exist\n",
153 send_ldap_error( op, rs, LDAP_OTHER,
154 "could not locate parent of entry" );
158 /* check parent for "children" acl */
159 if ( ! access_allowed( 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",
165 op->o_req_dn.bv_val, 0, 0 );
167 Debug( LDAP_DEBUG_TRACE,
168 "<=- ldbm_back_delete: no access to parent\n", 0,
172 send_ldap_error( op, rs, LDAP_INSUFFICIENT_ACCESS,
173 "no write access to parent" );
178 /* no parent, must be root to delete */
179 if( ! be_isroot( op->o_bd, &op->o_ndn ) ) {
180 if ( be_issuffix( op->o_bd, (struct berval *)&slap_empty_bv ) || be_isupdate( op->o_bd, &op->o_ndn ) ) {
181 p = (Entry *)&slap_entry_root;
183 rc = access_allowed( 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_error( op, rs, LDAP_INSUFFICIENT_ACCESS,
200 "no write access to parent" );
206 LDAP_LOG( BACK_LDBM, ERR,
207 "ldbm_back_delete: (%s) has no "
208 "parent & not a root.\n", op->o_ndn, 0, 0 );
210 Debug( LDAP_DEBUG_TRACE,
211 "<=- ldbm_back_delete: no parent & "
212 "not root\n", 0, 0, 0);
215 send_ldap_error( op, rs,
216 LDAP_INSUFFICIENT_ACCESS,
223 /* delete from dn2id mapping */
224 if ( dn2id_delete( op->o_bd, &e->e_nname, e->e_id ) != 0 ) {
226 LDAP_LOG( BACK_LDBM, ERR,
227 "ldbm_back_delete: (%s) operations error\n", op->o_req_dn.bv_val, 0, 0 );
229 Debug(LDAP_DEBUG_ARGS,
230 "<=- ldbm_back_delete: operations error %s\n",
231 op->o_req_dn.bv_val, 0, 0);
234 send_ldap_error( op, rs, LDAP_OTHER,
235 "DN index delete failed" );
239 /* delete from disk and cache */
240 if ( id2entry_delete( op->o_bd, e ) != 0 ) {
242 LDAP_LOG( BACK_LDBM, ERR,
243 "ldbm_back_delete: (%s) operations error\n", op->o_req_dn.bv_val, 0, 0 );
245 Debug(LDAP_DEBUG_ARGS,
246 "<=- ldbm_back_delete: operations error %s\n",
247 op->o_req_dn.bv_val, 0, 0);
250 send_ldap_error( op, rs, LDAP_OTHER,
251 "entry delete failed" );
255 /* delete attribute indices */
256 (void) index_entry_del( op, e );
258 rs->sr_err = LDAP_SUCCESS;
259 send_ldap_result( op, rs );
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);