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 ));
41 Debug(LDAP_DEBUG_ARGS, "==> ldbm_back_delete: %s\n", dn, 0, 0);
44 /* get entry with writer lock */
45 if ( (e = dn2entry_w( be, ndn, &matched )) == NULL ) {
46 char *matched_dn = NULL;
50 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
51 "ldbm_back_delete: no such object %s\n", dn ));
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,
61 dn, LDAP_SCOPE_DEFAULT )
63 cache_return_entry_r( &li->li_cache, matched );
66 refs = referral_rewrite( default_referral,
67 NULL, dn, LDAP_SCOPE_DEFAULT );
70 send_ldap_result( conn, op, LDAP_REFERRAL,
71 matched_dn, NULL, refs, NULL );
79 if ( !manageDSAit && is_entry_referral( e ) ) {
80 /* parent is a referral, don't allow add */
81 /* parent is an alias, don't allow add */
82 struct berval **refs = get_entry_referrals( be,
83 conn, op, e, dn, LDAP_SCOPE_DEFAULT );
86 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
87 "ldbm_back_delete: entry (%s) is a referral.\n",
90 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
95 send_ldap_result( conn, op, LDAP_REFERRAL,
96 e->e_dn, NULL, refs, NULL );
105 if ( has_children( be, e ) ) {
107 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
108 "ldbm_back_delete: (%s) is a non-leaf node.\n", dn ));
110 Debug(LDAP_DEBUG_ARGS, "<=- ldbm_back_delete: non leaf %s\n",
114 send_ldap_result( conn, op, LDAP_NOT_ALLOWED_ON_NONLEAF,
115 NULL, "subtree delete not supported", NULL, NULL );
119 /* delete from parent's id2children entry */
120 if( (pdn = dn_parent( be, e->e_ndn )) != NULL && pdn[ 0 ] != '\0' ) {
121 if( (p = dn2entry_w( be, pdn, NULL )) == NULL) {
123 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
124 "ldbm_back_delete: parent of (%s) does not exist\n", dn ));
126 Debug( LDAP_DEBUG_TRACE,
127 "<=- ldbm_back_delete: parent does not exist\n",
131 send_ldap_result( conn, op, LDAP_OTHER,
132 NULL, "could not locate parent of entry", NULL, NULL );
136 /* check parent for "children" acl */
137 if ( ! access_allowed( be, conn, op, p,
138 children, NULL, ACL_WRITE ) )
141 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
142 "ldbm_back_delete: no access to parent of (%s)\n", dn ));
144 Debug( LDAP_DEBUG_TRACE,
145 "<=- ldbm_back_delete: no access to parent\n", 0,
149 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
150 NULL, NULL, NULL, NULL );
155 /* no parent, must be root to delete */
156 if( ! be_isroot( be, op->o_ndn ) ) {
157 if ( be_issuffix( be, "" )
158 || be_isupdate( be, op->o_ndn ) ) {
159 static const Entry rootp = { NOID, "", "", NULL, NULL };
162 rc = access_allowed( be, conn, op, p,
163 children, NULL, ACL_WRITE );
166 /* check parent for "children" acl */
169 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
170 "ldbm_back_delete: no access "
171 "to parent of ("")\n" ));
173 Debug( LDAP_DEBUG_TRACE,
174 "<=- ldbm_back_delete: no "
175 "access to parent\n", 0, 0, 0 );
178 send_ldap_result( conn, op,
179 LDAP_INSUFFICIENT_ACCESS,
180 NULL, NULL, NULL, NULL );
186 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
187 "ldbm_back_delete: (%s) has no "
188 "parent & not a root.\n", dn ));
190 Debug( LDAP_DEBUG_TRACE,
191 "<=- ldbm_back_delete: no parent & "
192 "not root\n", 0, 0, 0);
195 send_ldap_result( conn, op,
196 LDAP_INSUFFICIENT_ACCESS,
197 NULL, NULL, NULL, NULL );
202 ldap_pvt_thread_mutex_lock(&li->li_root_mutex);
206 /* delete from dn2id mapping */
207 if ( dn2id_delete( be, e->e_ndn, e->e_id ) != 0 ) {
209 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
210 "ldbm_back_delete: (%s) operations error\n", dn ));
212 Debug(LDAP_DEBUG_ARGS,
213 "<=- ldbm_back_delete: operations error %s\n",
217 send_ldap_result( conn, op, LDAP_OTHER,
218 NULL, "DN index delete failed", NULL, NULL );
222 /* delete from disk and cache */
223 if ( id2entry_delete( be, e ) != 0 ) {
225 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
226 "ldbm_back_delete: (%s) operations error\n",
229 Debug(LDAP_DEBUG_ARGS,
230 "<=- ldbm_back_delete: operations error %s\n",
234 send_ldap_result( conn, op, LDAP_OTHER,
235 NULL, "entry delete failed", NULL, NULL );
239 /* delete attribute indices */
240 (void) index_entry_del( be, e, e->e_attrs );
242 send_ldap_result( conn, op, LDAP_SUCCESS,
243 NULL, NULL, NULL, NULL );
247 if ( pdn != NULL ) free(pdn);
250 /* free parent and writer lock */
251 cache_return_entry_w( &li->li_cache, p );
255 /* release root lock */
256 ldap_pvt_thread_mutex_unlock(&li->li_root_mutex);
259 /* free entry and writer lock */
260 cache_return_entry_w( &li->li_cache, e );