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"
28 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
33 int manageDSAit = get_manageDSAit( op );
34 AttributeDescription *children = slap_schema.si_ad_children;
35 AttributeDescription *entry = slap_schema.si_ad_entry;
38 LDAP_LOG( BACK_LDBM, ENTRY, "ldbm_back_delete: %s\n", dn->bv_val, 0, 0 );
40 Debug(LDAP_DEBUG_ARGS, "==> ldbm_back_delete: %s\n", dn->bv_val, 0, 0);
43 /* grab giant lock for writing */
44 ldap_pvt_thread_rdwr_wlock(&li->li_giant_rwlock);
46 /* get entry with writer lock */
47 if ( (e = dn2entry_w( be, ndn, &matched )) == NULL ) {
48 char *matched_dn = NULL;
52 LDAP_LOG( BACK_LDBM, INFO,
53 "ldbm_back_delete: no such object %s\n", dn->bv_val, 0, 0 );
55 Debug(LDAP_DEBUG_ARGS, "<=- ldbm_back_delete: no such object %s\n",
59 if ( matched != NULL ) {
60 matched_dn = ch_strdup( matched->e_dn );
61 refs = is_entry_referral( matched )
62 ? get_entry_referrals( be, conn, op, matched )
64 cache_return_entry_r( &li->li_cache, matched );
67 refs = referral_rewrite( default_referral,
68 NULL, dn, LDAP_SCOPE_DEFAULT );
71 ldap_pvt_thread_rdwr_wunlock(&li->li_giant_rwlock);
73 send_ldap_result( conn, op, LDAP_REFERRAL,
74 matched_dn, NULL, refs, NULL );
76 if ( refs ) ber_bvarray_free( refs );
82 /* check entry for "entry" acl */
84 if( !op->o_caching_on ) {
85 #endif /* LDAP_CACHING */
86 if ( ! access_allowed( be, conn, op, e,
87 entry, NULL, ACL_WRITE, NULL ) )
90 LDAP_LOG( BACK_LDBM, ERR,
91 "ldbm_back_delete: no write access to entry of (%s)\n",
94 Debug( LDAP_DEBUG_TRACE,
95 "<=- ldbm_back_delete: no write access to entry\n", 0,
99 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
100 NULL, "no write access to entry", NULL, NULL );
106 if ( !manageDSAit && is_entry_referral( e ) ) {
107 /* parent is a referral, don't allow add */
108 /* parent is an alias, don't allow add */
109 BerVarray refs = get_entry_referrals( be,
113 LDAP_LOG( BACK_LDBM, INFO,
114 "ldbm_back_delete: entry (%s) is a referral.\n", e->e_dn, 0, 0 );
116 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
120 send_ldap_result( conn, op, LDAP_REFERRAL,
121 e->e_dn, NULL, refs, NULL );
123 if ( refs ) ber_bvarray_free( refs );
129 if ( has_children( be, e ) ) {
131 LDAP_LOG( BACK_LDBM, ERR,
132 "ldbm_back_delete: (%s) is a non-leaf node.\n", dn->bv_val, 0,0);
134 Debug(LDAP_DEBUG_ARGS, "<=- ldbm_back_delete: non leaf %s\n",
138 send_ldap_result( conn, op, LDAP_NOT_ALLOWED_ON_NONLEAF,
139 NULL, "subtree delete not supported", NULL, NULL );
143 /* delete from parent's id2children entry */
144 if( !be_issuffix( be, &e->e_nname ) && (dnParent( &e->e_nname, &pdn ),
146 if( (p = dn2entry_w( be, &pdn, NULL )) == NULL) {
148 LDAP_LOG( BACK_LDBM, ERR,
149 "ldbm_back_delete: parent of (%s) does not exist\n", dn, 0, 0 );
151 Debug( LDAP_DEBUG_TRACE,
152 "<=- ldbm_back_delete: parent does not exist\n",
156 send_ldap_result( conn, op, LDAP_OTHER,
157 NULL, "could not locate parent of entry", NULL, NULL );
161 /* check parent for "children" acl */
162 if ( ! access_allowed( be, conn, op, p,
163 children, NULL, ACL_WRITE, NULL ) )
166 LDAP_LOG( BACK_LDBM, ERR,
167 "ldbm_back_delete: no access to parent of (%s)\n",
170 Debug( LDAP_DEBUG_TRACE,
171 "<=- ldbm_back_delete: no access to parent\n", 0,
175 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
176 NULL, "no write access to parent", NULL, NULL );
181 /* no parent, must be root to delete */
182 if( ! be_isroot( be, &op->o_ndn ) ) {
183 if ( be_issuffix( be, (struct berval *)&slap_empty_bv ) || be_isupdate( be, &op->o_ndn ) ) {
184 p = (Entry *)&slap_entry_root;
186 rc = access_allowed( be, conn, op, p,
187 children, NULL, ACL_WRITE, NULL );
190 /* check parent for "children" acl */
193 LDAP_LOG( BACK_LDBM, ERR,
194 "ldbm_back_delete: no access "
195 "to parent of ("")\n", 0, 0, 0 );
197 Debug( LDAP_DEBUG_TRACE,
198 "<=- ldbm_back_delete: no "
199 "access to parent\n", 0, 0, 0 );
202 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
203 NULL, "no write access to parent", NULL, NULL );
209 LDAP_LOG( BACK_LDBM, ERR,
210 "ldbm_back_delete: (%s) has no "
211 "parent & not a root.\n", dn, 0, 0 );
213 Debug( LDAP_DEBUG_TRACE,
214 "<=- ldbm_back_delete: no parent & "
215 "not root\n", 0, 0, 0);
218 send_ldap_result( conn, op,
219 LDAP_INSUFFICIENT_ACCESS,
220 NULL, NULL, NULL, NULL );
227 #endif /* LDAP_CACHING */
229 /* delete from dn2id mapping */
230 if ( dn2id_delete( be, &e->e_nname, e->e_id ) != 0 ) {
232 LDAP_LOG( BACK_LDBM, ERR,
233 "ldbm_back_delete: (%s) operations error\n", dn->bv_val, 0, 0 );
235 Debug(LDAP_DEBUG_ARGS,
236 "<=- ldbm_back_delete: operations error %s\n",
240 send_ldap_result( conn, op, LDAP_OTHER,
241 NULL, "DN index delete failed", NULL, NULL );
245 /* delete from disk and cache */
246 if ( id2entry_delete( be, e ) != 0 ) {
248 LDAP_LOG( BACK_LDBM, ERR,
249 "ldbm_back_delete: (%s) operations error\n", dn->bv_val, 0, 0 );
251 Debug(LDAP_DEBUG_ARGS,
252 "<=- ldbm_back_delete: operations error %s\n",
256 send_ldap_result( conn, op, LDAP_OTHER,
257 NULL, "entry delete failed", NULL, NULL );
261 /* delete attribute indices */
262 (void) index_entry_del( be, e, e->e_attrs );
264 send_ldap_result( conn, op, LDAP_SUCCESS,
265 NULL, NULL, NULL, NULL );
270 /* free parent and writer lock */
271 cache_return_entry_w( &li->li_cache, p );
274 /* free entry and writer lock */
275 cache_return_entry_w( &li->li_cache, e );
277 ldap_pvt_thread_rdwr_wunlock(&li->li_giant_rwlock);