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 = NULL;
64 if ( !LDAP_STAILQ_EMPTY( &op->o_bd->be_syncinfo )) {
66 LDAP_STAILQ_FOREACH( si, &op->o_bd->be_syncinfo, si_next ) {
68 ber_dupbv( &tmpbv, &si->si_provideruri_bv[0] );
69 ber_bvarray_add( &deref, &tmpbv );
72 deref = default_referral;
74 rs->sr_ref = referral_rewrite( deref, NULL, &op->o_req_dn,
78 ldap_pvt_thread_rdwr_wunlock(&li->li_giant_rwlock);
80 rs->sr_err = LDAP_REFERRAL;
81 send_ldap_result( op, rs );
83 if ( rs->sr_ref ) ber_bvarray_free( rs->sr_ref );
84 free( (char *)rs->sr_matched );
86 rs->sr_matched = NULL;
90 /* check entry for "entry" acl */
91 if ( ! access_allowed( op, e,
92 entry, NULL, ACL_WRITE, NULL ) )
95 LDAP_LOG( BACK_LDBM, ERR,
96 "ldbm_back_delete: no write access to entry of (%s)\n",
97 op->o_req_dn.bv_val, 0, 0 );
99 Debug( LDAP_DEBUG_TRACE,
100 "<=- ldbm_back_delete: no write access to entry\n", 0,
104 send_ldap_error( op, rs, LDAP_INSUFFICIENT_ACCESS,
105 "no write access to entry" );
107 rc = LDAP_INSUFFICIENT_ACCESS;
111 if ( !manageDSAit && is_entry_referral( e ) ) {
112 /* parent is a referral, don't allow add */
113 /* parent is an alias, don't allow add */
114 rs->sr_ref = get_entry_referrals( op, e );
117 LDAP_LOG( BACK_LDBM, INFO,
118 "ldbm_back_delete: entry (%s) is a referral.\n", e->e_dn, 0, 0 );
120 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
124 rs->sr_err = LDAP_REFERRAL;
125 rs->sr_matched = e->e_name.bv_val;
126 send_ldap_result( op, rs );
128 if ( rs->sr_ref ) ber_bvarray_free( rs->sr_ref );
130 rs->sr_matched = NULL;
135 if ( has_children( op->o_bd, e ) ) {
137 LDAP_LOG( BACK_LDBM, ERR,
138 "ldbm_back_delete: (%s) is a non-leaf node.\n", op->o_req_dn.bv_val, 0,0);
140 Debug(LDAP_DEBUG_ARGS, "<=- ldbm_back_delete: non leaf %s\n",
141 op->o_req_dn.bv_val, 0, 0);
144 send_ldap_error( op, rs, LDAP_NOT_ALLOWED_ON_NONLEAF,
145 "subtree delete not supported" );
149 /* delete from parent's id2children entry */
150 if( !be_issuffix( op->o_bd, &e->e_nname ) && (dnParent( &e->e_nname, &pdn ),
152 if( (p = dn2entry_w( op->o_bd, &pdn, NULL )) == NULL) {
154 LDAP_LOG( BACK_LDBM, ERR,
155 "ldbm_back_delete: parent of (%s) does not exist\n", op->o_req_dn, 0, 0 );
157 Debug( LDAP_DEBUG_TRACE,
158 "<=- ldbm_back_delete: parent does not exist\n",
162 send_ldap_error( op, rs, LDAP_OTHER,
163 "could not locate parent of entry" );
167 /* check parent for "children" acl */
168 if ( ! access_allowed( op, p,
169 children, NULL, ACL_WRITE, NULL ) )
172 LDAP_LOG( BACK_LDBM, ERR,
173 "ldbm_back_delete: no access to parent of (%s)\n",
174 op->o_req_dn.bv_val, 0, 0 );
176 Debug( LDAP_DEBUG_TRACE,
177 "<=- ldbm_back_delete: no access to parent\n", 0,
181 send_ldap_error( op, rs, LDAP_INSUFFICIENT_ACCESS,
182 "no write access to parent" );
187 /* no parent, must be root to delete */
188 if( ! be_isroot( op->o_bd, &op->o_ndn ) ) {
189 if ( be_issuffix( op->o_bd, (struct berval *)&slap_empty_bv ) || be_isupdate( op->o_bd, &op->o_ndn ) ) {
190 p = (Entry *)&slap_entry_root;
192 rc = access_allowed( op, p,
193 children, NULL, ACL_WRITE, NULL );
196 /* check parent for "children" acl */
199 LDAP_LOG( BACK_LDBM, ERR,
200 "ldbm_back_delete: no access "
201 "to parent of ("")\n", 0, 0, 0 );
203 Debug( LDAP_DEBUG_TRACE,
204 "<=- ldbm_back_delete: no "
205 "access to parent\n", 0, 0, 0 );
208 send_ldap_error( op, rs, LDAP_INSUFFICIENT_ACCESS,
209 "no write access to parent" );
215 LDAP_LOG( BACK_LDBM, ERR,
216 "ldbm_back_delete: (%s) has no "
217 "parent & not a root.\n", op->o_ndn, 0, 0 );
219 Debug( LDAP_DEBUG_TRACE,
220 "<=- ldbm_back_delete: no parent & "
221 "not root\n", 0, 0, 0);
224 send_ldap_error( op, rs,
225 LDAP_INSUFFICIENT_ACCESS,
232 /* delete from dn2id mapping */
233 if ( dn2id_delete( op->o_bd, &e->e_nname, e->e_id ) != 0 ) {
235 LDAP_LOG( BACK_LDBM, ERR,
236 "ldbm_back_delete: (%s) operations error\n", op->o_req_dn.bv_val, 0, 0 );
238 Debug(LDAP_DEBUG_ARGS,
239 "<=- ldbm_back_delete: operations error %s\n",
240 op->o_req_dn.bv_val, 0, 0);
243 send_ldap_error( op, rs, LDAP_OTHER,
244 "DN index delete failed" );
248 /* delete from disk and cache */
249 if ( id2entry_delete( op->o_bd, e ) != 0 ) {
251 LDAP_LOG( BACK_LDBM, ERR,
252 "ldbm_back_delete: (%s) operations error\n", op->o_req_dn.bv_val, 0, 0 );
254 Debug(LDAP_DEBUG_ARGS,
255 "<=- ldbm_back_delete: operations error %s\n",
256 op->o_req_dn.bv_val, 0, 0);
259 send_ldap_error( op, rs, LDAP_OTHER,
260 "entry delete failed" );
264 /* delete attribute indices */
265 (void) index_entry_del( op, e );
267 rs->sr_err = LDAP_SUCCESS;
268 send_ldap_result( op, rs );
273 /* free parent and writer lock */
274 cache_return_entry_w( &li->li_cache, p );
277 /* free entry and writer lock */
278 cache_return_entry_w( &li->li_cache, e );
280 ldap_pvt_thread_rdwr_wunlock(&li->li_giant_rwlock);