1 /* delete.c - ldbm backend delete routine */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2005 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
21 #include <ac/string.h>
22 #include <ac/socket.h>
25 #include "back-ldbm.h"
26 #include "proto-back-ldbm.h"
33 struct ldbminfo *li = (struct ldbminfo *) op->o_bd->be_private;
38 int manageDSAit = get_manageDSAit( op );
39 AttributeDescription *children = slap_schema.si_ad_children;
40 AttributeDescription *entry = slap_schema.si_ad_entry;
42 Debug(LDAP_DEBUG_ARGS, "==> ldbm_back_delete: %s\n", op->o_req_dn.bv_val, 0, 0);
44 /* grab giant lock for writing */
45 ldap_pvt_thread_rdwr_wlock(&li->li_giant_rwlock);
47 /* get entry with writer lock */
48 e = dn2entry_w( op->o_bd, &op->o_req_ndn, &matched );
50 /* FIXME : dn2entry() should return non-glue entry */
51 if ( e == NULL || ( !manageDSAit && is_entry_glue( e ))) {
52 BerVarray deref = NULL;
54 Debug(LDAP_DEBUG_ARGS, "<=- ldbm_back_delete: no such object %s\n",
55 op->o_req_dn.bv_val, 0, 0);
57 if ( matched != NULL ) {
58 rs->sr_matched = ch_strdup( matched->e_dn );
59 rs->sr_ref = is_entry_referral( matched )
60 ? get_entry_referrals( op, matched )
62 cache_return_entry_r( &li->li_cache, matched );
65 if ( !LDAP_STAILQ_EMPTY( &op->o_bd->be_syncinfo )) {
67 LDAP_STAILQ_FOREACH( si, &op->o_bd->be_syncinfo, si_next ) {
69 ber_dupbv( &tmpbv, &si->si_provideruri_bv[0] );
70 ber_bvarray_add( &deref, &tmpbv );
73 deref = default_referral;
75 rs->sr_ref = referral_rewrite( deref, NULL, &op->o_req_dn,
79 ldap_pvt_thread_rdwr_wunlock(&li->li_giant_rwlock);
81 rs->sr_err = LDAP_REFERRAL;
82 send_ldap_result( op, rs );
84 if ( rs->sr_ref ) ber_bvarray_free( rs->sr_ref );
85 if ( deref != default_referral ) {
86 ber_bvarray_free( deref );
88 free( (char *)rs->sr_matched );
90 rs->sr_matched = NULL;
94 /* check entry for "entry" acl */
95 if ( ! access_allowed( op, e,
96 entry, NULL, ACL_WRITE, NULL ) )
98 Debug( LDAP_DEBUG_TRACE,
99 "<=- ldbm_back_delete: no write access to entry\n", 0,
102 send_ldap_error( op, rs, LDAP_INSUFFICIENT_ACCESS,
103 "no write access to entry" );
105 rc = LDAP_INSUFFICIENT_ACCESS;
109 if ( !manageDSAit && is_entry_referral( e ) ) {
110 /* parent is a referral, don't allow add */
111 /* parent is an alias, don't allow add */
112 rs->sr_ref = get_entry_referrals( op, e );
114 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
117 rs->sr_err = LDAP_REFERRAL;
118 rs->sr_matched = e->e_name.bv_val;
119 send_ldap_result( op, rs );
121 if ( rs->sr_ref ) ber_bvarray_free( rs->sr_ref );
123 rs->sr_matched = NULL;
128 if ( has_children( op->o_bd, e ) ) {
129 Debug(LDAP_DEBUG_ARGS, "<=- ldbm_back_delete: non leaf %s\n",
130 op->o_req_dn.bv_val, 0, 0);
132 send_ldap_error( op, rs, LDAP_NOT_ALLOWED_ON_NONLEAF,
133 "subtree delete not supported" );
137 /* delete from parent's id2children entry */
138 if( !be_issuffix( op->o_bd, &e->e_nname ) && (dnParent( &e->e_nname, &pdn ),
140 if( (p = dn2entry_w( op->o_bd, &pdn, NULL )) == NULL) {
141 Debug( LDAP_DEBUG_TRACE,
142 "<=- ldbm_back_delete: parent does not exist\n",
145 send_ldap_error( op, rs, LDAP_OTHER,
146 "could not locate parent of entry" );
150 /* check parent for "children" acl */
151 if ( ! access_allowed( op, p,
152 children, NULL, ACL_WRITE, NULL ) )
154 Debug( LDAP_DEBUG_TRACE,
155 "<=- ldbm_back_delete: no access to parent\n", 0,
158 send_ldap_error( op, rs, LDAP_INSUFFICIENT_ACCESS,
159 "no write access to parent" );
164 /* no parent, must be root to delete */
165 if( ! be_isroot( op ) ) {
166 if ( be_issuffix( op->o_bd, (struct berval *)&slap_empty_bv )
167 || be_shadow_update( op ) ) {
168 p = (Entry *)&slap_entry_root;
170 rc = access_allowed( op, p,
171 children, NULL, ACL_WRITE, NULL );
174 /* check parent for "children" acl */
176 Debug( LDAP_DEBUG_TRACE,
177 "<=- ldbm_back_delete: no "
178 "access to parent\n", 0, 0, 0 );
180 send_ldap_error( op, rs, LDAP_INSUFFICIENT_ACCESS,
181 "no write access to parent" );
186 Debug( LDAP_DEBUG_TRACE,
187 "<=- ldbm_back_delete: no parent & "
188 "not root\n", 0, 0, 0);
190 send_ldap_error( op, rs,
191 LDAP_INSUFFICIENT_ACCESS,
198 /* delete from dn2id mapping */
199 if ( dn2id_delete( op->o_bd, &e->e_nname, e->e_id ) != 0 ) {
200 Debug(LDAP_DEBUG_ARGS,
201 "<=- ldbm_back_delete: operations error %s\n",
202 op->o_req_dn.bv_val, 0, 0);
204 send_ldap_error( op, rs, LDAP_OTHER,
205 "DN index delete failed" );
209 /* delete from disk and cache */
210 if ( id2entry_delete( op->o_bd, e ) != 0 ) {
211 Debug(LDAP_DEBUG_ARGS,
212 "<=- ldbm_back_delete: operations error %s\n",
213 op->o_req_dn.bv_val, 0, 0);
215 send_ldap_error( op, rs, LDAP_OTHER,
216 "entry delete failed" );
220 /* delete attribute indices */
221 (void) index_entry_del( op, e );
223 rs->sr_err = LDAP_SUCCESS;
224 send_ldap_result( op, rs );
229 /* free parent and writer lock */
230 cache_return_entry_w( &li->li_cache, p );
233 /* free entry and writer lock */
234 cache_return_entry_w( &li->li_cache, e );
236 ldap_pvt_thread_rdwr_wunlock(&li->li_giant_rwlock);