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 #ifdef SLAPD_SCHEMA_NOT_COMPAT
36 AttributeDescription *children = slap_schema.si_ad_children;
38 static const char *children = "children";
41 Debug(LDAP_DEBUG_ARGS, "==> ldbm_back_delete: %s\n", dn, 0, 0);
43 /* get entry with writer lock */
44 if ( (e = dn2entry_w( be, ndn, &matched )) == NULL ) {
45 char *matched_dn = NULL;
46 struct berval **refs = NULL;
48 Debug(LDAP_DEBUG_ARGS, "<=- ldbm_back_delete: no such object %s\n",
51 if ( matched != NULL ) {
52 matched_dn = ch_strdup( matched->e_dn );
53 refs = is_entry_referral( matched )
54 ? get_entry_referrals( be, conn, op, matched )
56 cache_return_entry_r( &li->li_cache, matched );
58 refs = default_referral;
61 send_ldap_result( conn, op, LDAP_REFERRAL,
62 matched_dn, NULL, refs, NULL );
64 if ( matched != NULL ) {
72 #ifdef SLAPD_CHILD_MODIFICATION_WITH_ENTRY_ACL
73 if ( ! access_allowed( be, conn, op, e,
74 "entry", NULL, ACL_WRITE ) )
76 Debug(LDAP_DEBUG_ARGS,
77 "<=- ldbm_back_delete: insufficient access %s\n",
79 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
80 NULL, NULL, NULL, NULL );
85 if ( !manageDSAit && is_entry_referral( e ) ) {
86 /* parent is a referral, don't allow add */
87 /* parent is an alias, don't allow add */
88 struct berval **refs = get_entry_referrals( be,
91 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
94 send_ldap_result( conn, op, LDAP_REFERRAL,
95 e->e_dn, NULL, refs, NULL );
104 if ( has_children( be, e ) ) {
105 Debug(LDAP_DEBUG_ARGS, "<=- ldbm_back_delete: non leaf %s\n",
107 send_ldap_result( conn, op, LDAP_NOT_ALLOWED_ON_NONLEAF,
108 NULL, "subtree delete not supported", NULL, NULL );
112 /* delete from parent's id2children entry */
113 if( (pdn = dn_parent( be, e->e_ndn )) != NULL ) {
114 if( (p = dn2entry_w( be, pdn, NULL )) == NULL) {
115 Debug( LDAP_DEBUG_TRACE,
116 "<=- ldbm_back_delete: parent does not exist\n",
118 send_ldap_result( conn, op, LDAP_OTHER,
119 NULL, "could not locate parent of entry", NULL, NULL );
123 /* check parent for "children" acl */
124 if ( ! access_allowed( be, conn, op, p,
125 children, NULL, ACL_WRITE ) )
127 Debug( LDAP_DEBUG_TRACE,
128 "<=- ldbm_back_delete: no access to parent\n", 0,
130 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
131 NULL, NULL, NULL, NULL );
136 /* no parent, must be root to delete */
137 if( ! be_isroot( be, op->o_ndn ) ) {
138 Debug( LDAP_DEBUG_TRACE,
139 "<=- ldbm_back_delete: no parent & not root\n",
141 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
142 NULL, NULL, NULL, NULL );
146 ldap_pvt_thread_mutex_lock(&li->li_root_mutex);
150 /* delete from dn2id mapping */
151 if ( dn2id_delete( be, e->e_ndn, e->e_id ) != 0 ) {
152 Debug(LDAP_DEBUG_ARGS,
153 "<=- ldbm_back_delete: operations error %s\n",
155 send_ldap_result( conn, op, LDAP_OTHER,
156 NULL, "DN index delete failed", NULL, NULL );
160 /* delete from disk and cache */
161 if ( id2entry_delete( be, e ) != 0 ) {
162 Debug(LDAP_DEBUG_ARGS,
163 "<=- ldbm_back_delete: operations error %s\n",
165 send_ldap_result( conn, op, LDAP_OTHER,
166 NULL, "entry delete failed", NULL, NULL );
170 send_ldap_result( conn, op, LDAP_SUCCESS,
171 NULL, NULL, NULL, NULL );
175 if ( pdn != NULL ) free(pdn);
178 /* free parent and writer lock */
179 cache_return_entry_w( &li->li_cache, p );
183 /* release root lock */
184 ldap_pvt_thread_mutex_unlock(&li->li_root_mutex);
187 /* free entry and writer lock */
188 cache_return_entry_w( &li->li_cache, e );