1 /* delete.c - ldbm backend delete routine */
4 * Copyright 1998-2002 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;
36 Debug(LDAP_DEBUG_ARGS, "==> ldbm_back_delete: %s\n", dn, 0, 0);
38 /* grab giant lock for writing */
39 ldap_pvt_thread_rdwr_wlock(&li->li_giant_rwlock);
41 /* get entry with writer lock */
42 if ( (e = dn2entry_w( be, ndn, &matched )) == NULL ) {
43 char *matched_dn = NULL;
44 struct berval **refs = NULL;
46 Debug(LDAP_DEBUG_ARGS, "<=- ldbm_back_delete: no such object %s\n",
49 if ( matched != NULL ) {
50 matched_dn = ch_strdup( matched->e_dn );
51 refs = is_entry_referral( matched )
52 ? get_entry_referrals( be, conn, op, matched )
54 cache_return_entry_r( &li->li_cache, matched );
56 refs = default_referral;
59 ldap_pvt_thread_rdwr_wunlock(&li->li_giant_rwlock);
61 send_ldap_result( conn, op, LDAP_REFERRAL,
62 matched_dn, NULL, refs, NULL );
64 if ( matched != NULL ) {
72 if ( !manageDSAit && is_entry_referral( e ) ) {
73 /* parent is a referral, don't allow add */
74 /* parent is an alias, don't allow add */
75 struct berval **refs = get_entry_referrals( be,
78 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
81 send_ldap_result( conn, op, LDAP_REFERRAL,
82 e->e_dn, NULL, refs, NULL );
91 if ( has_children( be, e ) ) {
92 Debug(LDAP_DEBUG_ARGS, "<=- ldbm_back_delete: non leaf %s\n",
94 send_ldap_result( conn, op, LDAP_NOT_ALLOWED_ON_NONLEAF,
95 NULL, "subtree delete not supported", NULL, NULL );
99 /* delete from parent's id2children entry */
100 if( (pdn = dn_parent( be, e->e_ndn )) != NULL && pdn[ 0 ] != '\0' ) {
101 if( (p = dn2entry_w( be, pdn, NULL )) == NULL) {
102 Debug( LDAP_DEBUG_TRACE,
103 "<=- ldbm_back_delete: parent does not exist\n",
105 send_ldap_result( conn, op, LDAP_OTHER,
106 NULL, "could not locate parent of entry", NULL, NULL );
110 /* check parent for "children" acl */
111 if ( ! access_allowed( be, conn, op, p,
112 children, NULL, ACL_WRITE ) )
114 Debug( LDAP_DEBUG_TRACE,
115 "<=- ldbm_back_delete: no access to parent\n", 0,
117 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
118 NULL, NULL, NULL, NULL );
123 /* no parent, must be root to delete */
124 if( ! be_isroot( be, op->o_ndn ) ) {
125 if ( be_issuffix( be, "" )
126 || be_isupdate( be, op->o_ndn ) ) {
127 static const Entry rootp = { NOID, "", "", NULL, NULL };
130 rc = access_allowed( be, conn, op, p,
131 children, NULL, ACL_WRITE );
134 /* check parent for "children" acl */
136 Debug( LDAP_DEBUG_TRACE,
137 "<=- ldbm_back_delete: no "
138 "access to parent\n", 0, 0, 0 );
140 send_ldap_result( conn, op,
141 LDAP_INSUFFICIENT_ACCESS,
142 NULL, NULL, NULL, NULL );
147 Debug( LDAP_DEBUG_TRACE,
148 "<=- ldbm_back_delete: no parent & "
149 "not root\n", 0, 0, 0);
151 send_ldap_result( conn, op,
152 LDAP_INSUFFICIENT_ACCESS,
153 NULL, NULL, NULL, NULL );
159 /* delete from dn2id mapping */
160 if ( dn2id_delete( be, e->e_ndn, e->e_id ) != 0 ) {
161 Debug(LDAP_DEBUG_ARGS,
162 "<=- ldbm_back_delete: operations error %s\n",
164 send_ldap_result( conn, op, LDAP_OTHER,
165 NULL, "DN index delete failed", NULL, NULL );
169 /* delete from disk and cache */
170 if ( id2entry_delete( be, e ) != 0 ) {
171 Debug(LDAP_DEBUG_ARGS,
172 "<=- ldbm_back_delete: operations error %s\n",
174 send_ldap_result( conn, op, LDAP_OTHER,
175 NULL, "entry delete failed", NULL, NULL );
179 /* delete attribute indices */
180 (void) index_entry_del( be, e, e->e_attrs );
182 send_ldap_result( conn, op, LDAP_SUCCESS,
183 NULL, NULL, NULL, NULL );
187 if ( pdn != NULL ) free(pdn);
190 /* free parent and writer lock */
191 cache_return_entry_w( &li->li_cache, p );
194 /* free entry and writer lock */
195 cache_return_entry_w( &li->li_cache, e );
197 ldap_pvt_thread_rdwr_wunlock(&li->li_giant_rwlock);