1 /* delete.c - ldbm backend delete routine */
4 * Copyright 1998-2000 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;
34 int manageDSAit = get_manageDSAit( op );
35 AttributeDescription *children = slap_schema.si_ad_children;
38 LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
39 "ldbm_back_delete: %s\n", dn->bv_val ));
41 Debug(LDAP_DEBUG_ARGS, "==> ldbm_back_delete: %s\n", dn->bv_val, 0, 0);
44 /* get entry with writer lock */
45 if ( (e = dn2entry_w( be, ndn->bv_val, &matched )) == NULL ) {
46 char *matched_dn = NULL;
50 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
51 "ldbm_back_delete: no such object %s\n", dn->bv_val ));
53 Debug(LDAP_DEBUG_ARGS, "<=- ldbm_back_delete: no such object %s\n",
57 if ( matched != NULL ) {
58 matched_dn = ch_strdup( matched->e_dn );
59 refs = is_entry_referral( matched )
60 ? get_entry_referrals( be, conn, op, matched )
62 cache_return_entry_r( &li->li_cache, matched );
65 refs = referral_rewrite( default_referral,
66 NULL, dn, LDAP_SCOPE_DEFAULT );
69 send_ldap_result( conn, op, LDAP_REFERRAL,
70 matched_dn, NULL, refs, NULL );
78 if ( !manageDSAit && is_entry_referral( e ) ) {
79 /* parent is a referral, don't allow add */
80 /* parent is an alias, don't allow add */
81 struct berval **refs = get_entry_referrals( be,
85 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
86 "ldbm_back_delete: entry (%s) is a referral.\n",
89 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
93 send_ldap_result( conn, op, LDAP_REFERRAL,
94 e->e_dn, NULL, refs, NULL );
103 if ( has_children( be, e ) ) {
105 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
106 "ldbm_back_delete: (%s) is a non-leaf node.\n", dn ));
108 Debug(LDAP_DEBUG_ARGS, "<=- ldbm_back_delete: non leaf %s\n",
112 send_ldap_result( conn, op, LDAP_NOT_ALLOWED_ON_NONLEAF,
113 NULL, "subtree delete not supported", NULL, NULL );
117 /* delete from parent's id2children entry */
118 if( (pdn = dn_parent( be, e->e_ndn )) != NULL && pdn[ 0 ] != '\0' ) {
119 if( (p = dn2entry_w( be, pdn, NULL )) == NULL) {
121 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
122 "ldbm_back_delete: parent of (%s) does not exist\n", dn ));
124 Debug( LDAP_DEBUG_TRACE,
125 "<=- ldbm_back_delete: parent does not exist\n",
129 send_ldap_result( conn, op, LDAP_OTHER,
130 NULL, "could not locate parent of entry", NULL, NULL );
134 /* check parent for "children" acl */
135 if ( ! access_allowed( be, conn, op, p,
136 children, NULL, ACL_WRITE ) )
139 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
140 "ldbm_back_delete: no access to parent of (%s)\n",
143 Debug( LDAP_DEBUG_TRACE,
144 "<=- ldbm_back_delete: no access to parent\n", 0,
148 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
149 NULL, NULL, NULL, NULL );
154 /* no parent, must be root to delete */
155 if( ! be_isroot( be, &op->o_ndn ) ) {
156 if ( be_issuffix( be, "" ) || be_isupdate( be, &op->o_ndn ) ) {
157 p = (Entry *)&slap_entry_root;
159 rc = access_allowed( be, conn, op, p,
160 children, NULL, ACL_WRITE );
163 /* check parent for "children" acl */
166 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
167 "ldbm_back_delete: no access "
168 "to parent of ("")\n" ));
170 Debug( LDAP_DEBUG_TRACE,
171 "<=- ldbm_back_delete: no "
172 "access to parent\n", 0, 0, 0 );
175 send_ldap_result( conn, op,
176 LDAP_INSUFFICIENT_ACCESS,
177 NULL, NULL, NULL, NULL );
183 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
184 "ldbm_back_delete: (%s) has no "
185 "parent & not a root.\n", dn ));
187 Debug( LDAP_DEBUG_TRACE,
188 "<=- ldbm_back_delete: no parent & "
189 "not root\n", 0, 0, 0);
192 send_ldap_result( conn, op,
193 LDAP_INSUFFICIENT_ACCESS,
194 NULL, NULL, NULL, NULL );
199 ldap_pvt_thread_mutex_lock(&li->li_root_mutex);
203 /* delete from dn2id mapping */
204 if ( dn2id_delete( be, e->e_ndn, e->e_id ) != 0 ) {
206 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
207 "ldbm_back_delete: (%s) operations error\n",
210 Debug(LDAP_DEBUG_ARGS,
211 "<=- ldbm_back_delete: operations error %s\n",
215 send_ldap_result( conn, op, LDAP_OTHER,
216 NULL, "DN index delete failed", NULL, NULL );
220 /* delete from disk and cache */
221 if ( id2entry_delete( be, e ) != 0 ) {
223 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
224 "ldbm_back_delete: (%s) operations error\n",
227 Debug(LDAP_DEBUG_ARGS,
228 "<=- ldbm_back_delete: operations error %s\n",
232 send_ldap_result( conn, op, LDAP_OTHER,
233 NULL, "entry delete failed", NULL, NULL );
237 /* delete attribute indices */
238 (void) index_entry_del( be, e, e->e_attrs );
240 send_ldap_result( conn, op, LDAP_SUCCESS,
241 NULL, NULL, NULL, NULL );
246 /* free parent and writer lock */
247 cache_return_entry_w( &li->li_cache, p );
251 /* release root lock */
252 ldap_pvt_thread_mutex_unlock(&li->li_root_mutex);
255 /* free entry and writer lock */
256 cache_return_entry_w( &li->li_cache, e );