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, entry, NULL, ACL_WDEL, NULL ) )
82 Debug( LDAP_DEBUG_TRACE,
83 "<=- ldbm_back_delete: no write access to entry\n", 0,
86 send_ldap_error( op, rs, LDAP_INSUFFICIENT_ACCESS,
87 "no write access to entry" );
89 rc = LDAP_INSUFFICIENT_ACCESS;
93 if ( !manageDSAit && is_entry_referral( e ) ) {
94 /* parent is a referral, don't allow add */
95 /* parent is an alias, don't allow add */
96 rs->sr_ref = get_entry_referrals( op, e );
98 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
101 rs->sr_err = LDAP_REFERRAL;
102 rs->sr_matched = e->e_name.bv_val;
103 send_ldap_result( op, rs );
105 if ( rs->sr_ref ) ber_bvarray_free( rs->sr_ref );
107 rs->sr_matched = NULL;
112 if ( has_children( op->o_bd, e ) ) {
113 Debug(LDAP_DEBUG_ARGS, "<=- ldbm_back_delete: non leaf %s\n",
114 op->o_req_dn.bv_val, 0, 0);
116 send_ldap_error( op, rs, LDAP_NOT_ALLOWED_ON_NONLEAF,
117 "subordinate objects must be deleted first");
121 /* delete from parent's id2children entry */
122 if( !be_issuffix( op->o_bd, &e->e_nname ) && (dnParent( &e->e_nname, &pdn ),
124 if( (p = dn2entry_w( op->o_bd, &pdn, NULL )) == NULL) {
125 Debug( LDAP_DEBUG_TRACE,
126 "<=- ldbm_back_delete: parent does not exist\n",
129 send_ldap_error( op, rs, LDAP_OTHER,
130 "could not locate parent of entry" );
134 /* check parent for "children" acl */
135 if ( ! access_allowed( op, p,
136 children, NULL, ACL_WDEL, NULL ) )
138 Debug( LDAP_DEBUG_TRACE,
139 "<=- ldbm_back_delete: no access to parent\n", 0,
142 send_ldap_error( op, rs, LDAP_INSUFFICIENT_ACCESS,
143 "no write access to parent" );
148 /* no parent, must be root to delete */
149 if( ! be_isroot( op ) ) {
150 if ( be_issuffix( op->o_bd, (struct berval *)&slap_empty_bv )
151 || be_shadow_update( op ) ) {
152 p = (Entry *)&slap_entry_root;
154 rc = access_allowed( op, p,
155 children, NULL, ACL_WDEL, NULL );
158 /* check parent for "children" acl */
160 Debug( LDAP_DEBUG_TRACE,
161 "<=- ldbm_back_delete: no "
162 "access to parent\n", 0, 0, 0 );
164 send_ldap_error( op, rs, LDAP_INSUFFICIENT_ACCESS,
165 "no write access to parent" );
170 Debug( LDAP_DEBUG_TRACE,
171 "<=- ldbm_back_delete: no parent & "
172 "not root\n", 0, 0, 0);
174 send_ldap_error( op, rs,
175 LDAP_INSUFFICIENT_ACCESS,
182 /* delete from dn2id mapping */
183 if ( dn2id_delete( op->o_bd, &e->e_nname, e->e_id ) != 0 ) {
184 Debug(LDAP_DEBUG_ARGS,
185 "<=- ldbm_back_delete: operations error %s\n",
186 op->o_req_dn.bv_val, 0, 0);
188 send_ldap_error( op, rs, LDAP_OTHER,
189 "DN index delete failed" );
193 /* delete from disk and cache */
194 if ( id2entry_delete( op->o_bd, e ) != 0 ) {
195 Debug(LDAP_DEBUG_ARGS,
196 "<=- ldbm_back_delete: operations error %s\n",
197 op->o_req_dn.bv_val, 0, 0);
199 send_ldap_error( op, rs, LDAP_OTHER,
200 "entry delete failed" );
204 /* delete attribute indices */
205 (void) index_entry_del( op, e );
207 rs->sr_err = LDAP_SUCCESS;
208 send_ldap_result( op, rs );
213 /* free parent and writer lock */
214 cache_return_entry_w( &li->li_cache, p );
217 /* free entry and writer lock */
218 cache_return_entry_w( &li->li_cache, e );
220 ldap_pvt_thread_rdwr_wunlock(&li->li_giant_rwlock);