1 /* delete.c - ldbm backend delete routine */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2004 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 Debug(LDAP_DEBUG_ARGS, "<=- ldbm_back_delete: no such object %s\n",
53 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 ) )
94 Debug( LDAP_DEBUG_TRACE,
95 "<=- ldbm_back_delete: no write access to entry\n", 0,
98 send_ldap_error( op, rs, LDAP_INSUFFICIENT_ACCESS,
99 "no write access to entry" );
101 rc = LDAP_INSUFFICIENT_ACCESS;
105 if ( !manageDSAit && is_entry_referral( e ) ) {
106 /* parent is a referral, don't allow add */
107 /* parent is an alias, don't allow add */
108 rs->sr_ref = get_entry_referrals( op, e );
110 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
113 rs->sr_err = LDAP_REFERRAL;
114 rs->sr_matched = e->e_name.bv_val;
115 send_ldap_result( op, rs );
117 if ( rs->sr_ref ) ber_bvarray_free( rs->sr_ref );
119 rs->sr_matched = NULL;
124 if ( has_children( op->o_bd, e ) ) {
125 Debug(LDAP_DEBUG_ARGS, "<=- ldbm_back_delete: non leaf %s\n",
126 op->o_req_dn.bv_val, 0, 0);
128 send_ldap_error( op, rs, LDAP_NOT_ALLOWED_ON_NONLEAF,
129 "subtree delete not supported" );
133 /* delete from parent's id2children entry */
134 if( !be_issuffix( op->o_bd, &e->e_nname ) && (dnParent( &e->e_nname, &pdn ),
136 if( (p = dn2entry_w( op->o_bd, &pdn, NULL )) == NULL) {
137 Debug( LDAP_DEBUG_TRACE,
138 "<=- ldbm_back_delete: parent does not exist\n",
141 send_ldap_error( op, rs, LDAP_OTHER,
142 "could not locate parent of entry" );
146 /* check parent for "children" acl */
147 if ( ! access_allowed( op, p,
148 children, NULL, ACL_WRITE, NULL ) )
150 Debug( LDAP_DEBUG_TRACE,
151 "<=- ldbm_back_delete: no access to parent\n", 0,
154 send_ldap_error( op, rs, LDAP_INSUFFICIENT_ACCESS,
155 "no write access to parent" );
160 /* no parent, must be root to delete */
161 if( ! be_isroot( op ) ) {
162 if ( be_issuffix( op->o_bd, (struct berval *)&slap_empty_bv )
163 || be_shadow_update( op ) ) {
164 p = (Entry *)&slap_entry_root;
166 rc = access_allowed( op, p,
167 children, NULL, ACL_WRITE, NULL );
170 /* check parent for "children" acl */
172 Debug( LDAP_DEBUG_TRACE,
173 "<=- ldbm_back_delete: no "
174 "access to parent\n", 0, 0, 0 );
176 send_ldap_error( op, rs, LDAP_INSUFFICIENT_ACCESS,
177 "no write access to parent" );
182 Debug( LDAP_DEBUG_TRACE,
183 "<=- ldbm_back_delete: no parent & "
184 "not root\n", 0, 0, 0);
186 send_ldap_error( op, rs,
187 LDAP_INSUFFICIENT_ACCESS,
194 /* delete from dn2id mapping */
195 if ( dn2id_delete( op->o_bd, &e->e_nname, e->e_id ) != 0 ) {
196 Debug(LDAP_DEBUG_ARGS,
197 "<=- ldbm_back_delete: operations error %s\n",
198 op->o_req_dn.bv_val, 0, 0);
200 send_ldap_error( op, rs, LDAP_OTHER,
201 "DN index delete failed" );
205 /* delete from disk and cache */
206 if ( id2entry_delete( op->o_bd, e ) != 0 ) {
207 Debug(LDAP_DEBUG_ARGS,
208 "<=- ldbm_back_delete: operations error %s\n",
209 op->o_req_dn.bv_val, 0, 0);
211 send_ldap_error( op, rs, LDAP_OTHER,
212 "entry delete failed" );
216 /* delete attribute indices */
217 (void) index_entry_del( op, e );
219 rs->sr_err = LDAP_SUCCESS;
220 send_ldap_result( op, rs );
225 /* free parent and writer lock */
226 cache_return_entry_w( &li->li_cache, p );
229 /* free entry and writer lock */
230 cache_return_entry_w( &li->li_cache, e );
232 ldap_pvt_thread_rdwr_wunlock(&li->li_giant_rwlock);