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 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 rs->sr_ref = referral_rewrite( default_referral, NULL,
64 &op->o_req_dn, LDAP_SCOPE_DEFAULT );
67 ldap_pvt_thread_rdwr_wunlock(&li->li_giant_rwlock);
69 rs->sr_err = LDAP_REFERRAL;
70 send_ldap_result( op, rs );
72 if ( rs->sr_ref ) ber_bvarray_free( rs->sr_ref );
73 free( (char *)rs->sr_matched );
75 rs->sr_matched = NULL;
79 /* check entry for "entry" acl */
80 if ( ! access_allowed( op, e,
81 entry, NULL, ACL_WRITE, NULL ) )
83 Debug( LDAP_DEBUG_TRACE,
84 "<=- ldbm_back_delete: no write access to entry\n", 0,
87 send_ldap_error( op, rs, LDAP_INSUFFICIENT_ACCESS,
88 "no write access to entry" );
90 rc = LDAP_INSUFFICIENT_ACCESS;
94 if ( !manageDSAit && is_entry_referral( e ) ) {
95 /* parent is a referral, don't allow add */
96 /* parent is an alias, don't allow add */
97 rs->sr_ref = get_entry_referrals( op, e );
99 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
102 rs->sr_err = LDAP_REFERRAL;
103 rs->sr_matched = e->e_name.bv_val;
104 send_ldap_result( op, rs );
106 if ( rs->sr_ref ) ber_bvarray_free( rs->sr_ref );
108 rs->sr_matched = NULL;
113 if ( has_children( op->o_bd, e ) ) {
114 Debug(LDAP_DEBUG_ARGS, "<=- ldbm_back_delete: non leaf %s\n",
115 op->o_req_dn.bv_val, 0, 0);
117 send_ldap_error( op, rs, LDAP_NOT_ALLOWED_ON_NONLEAF,
118 "subtree delete not supported" );
122 /* delete from parent's id2children entry */
123 if( !be_issuffix( op->o_bd, &e->e_nname ) && (dnParent( &e->e_nname, &pdn ),
125 if( (p = dn2entry_w( op->o_bd, &pdn, NULL )) == NULL) {
126 Debug( LDAP_DEBUG_TRACE,
127 "<=- ldbm_back_delete: parent does not exist\n",
130 send_ldap_error( op, rs, LDAP_OTHER,
131 "could not locate parent of entry" );
135 /* check parent for "children" acl */
136 if ( ! access_allowed( op, p,
137 children, NULL, ACL_WRITE, NULL ) )
139 Debug( LDAP_DEBUG_TRACE,
140 "<=- ldbm_back_delete: no access to parent\n", 0,
143 send_ldap_error( op, rs, LDAP_INSUFFICIENT_ACCESS,
144 "no write access to parent" );
149 /* no parent, must be root to delete */
150 if( ! be_isroot( op ) ) {
151 if ( be_issuffix( op->o_bd, (struct berval *)&slap_empty_bv )
152 || be_shadow_update( op ) ) {
153 p = (Entry *)&slap_entry_root;
155 rc = access_allowed( op, p,
156 children, NULL, ACL_WRITE, NULL );
159 /* check parent for "children" acl */
161 Debug( LDAP_DEBUG_TRACE,
162 "<=- ldbm_back_delete: no "
163 "access to parent\n", 0, 0, 0 );
165 send_ldap_error( op, rs, LDAP_INSUFFICIENT_ACCESS,
166 "no write access to parent" );
171 Debug( LDAP_DEBUG_TRACE,
172 "<=- ldbm_back_delete: no parent & "
173 "not root\n", 0, 0, 0);
175 send_ldap_error( op, rs,
176 LDAP_INSUFFICIENT_ACCESS,
183 /* delete from dn2id mapping */
184 if ( dn2id_delete( op->o_bd, &e->e_nname, e->e_id ) != 0 ) {
185 Debug(LDAP_DEBUG_ARGS,
186 "<=- ldbm_back_delete: operations error %s\n",
187 op->o_req_dn.bv_val, 0, 0);
189 send_ldap_error( op, rs, LDAP_OTHER,
190 "DN index delete failed" );
194 /* delete from disk and cache */
195 if ( id2entry_delete( op->o_bd, e ) != 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 "entry delete failed" );
205 /* delete attribute indices */
206 (void) index_entry_del( op, e );
208 rs->sr_err = LDAP_SUCCESS;
209 send_ldap_result( op, rs );
214 /* free parent and writer lock */
215 cache_return_entry_w( &li->li_cache, p );
218 /* free entry and writer lock */
219 cache_return_entry_w( &li->li_cache, e );
221 ldap_pvt_thread_rdwr_wunlock(&li->li_giant_rwlock);