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);
45 /* get entry with writer lock */
46 if ( (e = dn2entry_w( be, ndn, &matched )) == NULL ) {
47 char *matched_dn = NULL;
48 struct berval **refs = NULL;
51 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
52 "ldbm_back_delete: no such object %s\n", dn ));
54 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 );
66 refs = default_referral;
69 send_ldap_result( conn, op, LDAP_REFERRAL,
70 matched_dn, NULL, refs, NULL );
72 if ( matched != NULL ) {
80 if ( !manageDSAit && is_entry_referral( e ) ) {
81 /* parent is a referral, don't allow add */
82 /* parent is an alias, don't allow add */
83 struct berval **refs = get_entry_referrals( be,
87 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
88 "ldbm_back_delete: entry (%s) is a referral.\n",
91 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
96 send_ldap_result( conn, op, LDAP_REFERRAL,
97 e->e_dn, NULL, refs, NULL );
106 if ( has_children( be, e ) ) {
108 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
109 "ldbm_back_delete: (%s) is a non-leaf node.\n", dn ));
111 Debug(LDAP_DEBUG_ARGS, "<=- ldbm_back_delete: non leaf %s\n",
115 send_ldap_result( conn, op, LDAP_NOT_ALLOWED_ON_NONLEAF,
116 NULL, "subtree delete not supported", NULL, NULL );
120 /* delete from parent's id2children entry */
121 if( (pdn = dn_parent( be, e->e_ndn )) != NULL ) {
122 if( (p = dn2entry_w( be, pdn, NULL )) == NULL) {
124 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
125 "ldbm_back_delete: parent of (%s) does not exist\n", dn ));
127 Debug( LDAP_DEBUG_TRACE,
128 "<=- ldbm_back_delete: parent does not exist\n",
132 send_ldap_result( conn, op, LDAP_OTHER,
133 NULL, "could not locate parent of entry", NULL, NULL );
137 /* check parent for "children" acl */
138 if ( ! access_allowed( be, conn, op, p,
139 children, NULL, ACL_WRITE ) )
142 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
143 "ldbm_back_delete: no access to parent of (%s)\n", dn ));
145 Debug( LDAP_DEBUG_TRACE,
146 "<=- ldbm_back_delete: no access to parent\n", 0,
150 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
151 NULL, NULL, NULL, NULL );
156 /* no parent, must be root to delete */
157 if( ! be_isroot( be, op->o_ndn ) ) {
159 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
160 "ldbm_back_delete: (%s) has no parent & not a root.\n",
163 Debug( LDAP_DEBUG_TRACE,
164 "<=- ldbm_back_delete: no parent & not root\n",
168 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
169 NULL, NULL, NULL, NULL );
173 ldap_pvt_thread_mutex_lock(&li->li_root_mutex);
177 /* delete from dn2id mapping */
178 if ( dn2id_delete( be, e->e_ndn, e->e_id ) != 0 ) {
180 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
181 "ldbm_back_delete: (%s) operations error\n", dn ));
183 Debug(LDAP_DEBUG_ARGS,
184 "<=- ldbm_back_delete: operations error %s\n",
188 send_ldap_result( conn, op, LDAP_OTHER,
189 NULL, "DN index delete failed", NULL, NULL );
193 /* delete from disk and cache */
194 if ( id2entry_delete( be, e ) != 0 ) {
196 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
197 "ldbm_back_delete: (%s) operations error\n",
200 Debug(LDAP_DEBUG_ARGS,
201 "<=- ldbm_back_delete: operations error %s\n",
205 send_ldap_result( conn, op, LDAP_OTHER,
206 NULL, "entry delete failed", NULL, NULL );
210 send_ldap_result( conn, op, LDAP_SUCCESS,
211 NULL, NULL, NULL, NULL );
215 if ( pdn != NULL ) free(pdn);
218 /* free parent and writer lock */
219 cache_return_entry_w( &li->li_cache, p );
223 /* release root lock */
224 ldap_pvt_thread_mutex_unlock(&li->li_root_mutex);
227 /* free entry and writer lock */
228 cache_return_entry_w( &li->li_cache, e );