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;
37 Debug(LDAP_DEBUG_ARGS, "==> ldbm_back_delete: %s\n", dn, 0, 0);
39 /* get entry with writer lock */
40 if ( (e = dn2entry_w( be, ndn, &matched )) == NULL ) {
41 char *matched_dn = NULL;
42 struct berval **refs = NULL;
44 Debug(LDAP_DEBUG_ARGS, "<=- ldbm_back_delete: no such object %s\n",
47 if ( matched != NULL ) {
48 matched_dn = ch_strdup( matched->e_dn );
49 refs = is_entry_referral( matched )
50 ? get_entry_referrals( be, conn, op, matched )
52 cache_return_entry_r( &li->li_cache, matched );
54 refs = default_referral;
57 send_ldap_result( conn, op, LDAP_REFERRAL,
58 matched_dn, NULL, refs, NULL );
60 if ( matched != NULL ) {
68 #ifdef SLAPD_CHILD_MODIFICATION_WITH_ENTRY_ACL
69 if ( ! access_allowed( be, conn, op, e,
70 "entry", NULL, ACL_WRITE ) )
72 Debug(LDAP_DEBUG_ARGS,
73 "<=- ldbm_back_delete: insufficient access %s\n",
75 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
76 NULL, NULL, NULL, NULL );
81 if ( !manageDSAit && is_entry_referral( e ) ) {
82 /* parent is a referral, don't allow add */
83 /* parent is an alias, don't allow add */
84 struct berval **refs = get_entry_referrals( be,
87 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
90 send_ldap_result( conn, op, LDAP_REFERRAL,
91 e->e_dn, NULL, refs, NULL );
100 if ( has_children( be, e ) ) {
101 Debug(LDAP_DEBUG_ARGS, "<=- ldbm_back_delete: non leaf %s\n",
103 send_ldap_result( conn, op, LDAP_NOT_ALLOWED_ON_NONLEAF,
104 NULL, "subtree delete not supported", NULL, NULL );
108 /* delete from parent's id2children entry */
109 if( (pdn = dn_parent( be, e->e_ndn )) != NULL ) {
110 if( (p = dn2entry_w( be, pdn, NULL )) == NULL) {
111 Debug( LDAP_DEBUG_TRACE,
112 "<=- ldbm_back_delete: parent does not exist\n",
114 send_ldap_result( conn, op, LDAP_OTHER,
115 NULL, "could not locate parent of entry", NULL, NULL );
119 /* check parent for "children" acl */
120 if ( ! access_allowed( be, conn, op, p,
121 children, NULL, ACL_WRITE ) )
123 Debug( LDAP_DEBUG_TRACE,
124 "<=- ldbm_back_delete: no access to parent\n", 0,
126 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
127 NULL, NULL, NULL, NULL );
132 /* no parent, must be root to delete */
133 if( ! be_isroot( be, op->o_ndn ) ) {
134 Debug( LDAP_DEBUG_TRACE,
135 "<=- ldbm_back_delete: no parent & not root\n",
137 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
138 NULL, NULL, NULL, NULL );
142 ldap_pvt_thread_mutex_lock(&li->li_root_mutex);
146 /* delete from dn2id mapping */
147 if ( dn2id_delete( be, e->e_ndn, e->e_id ) != 0 ) {
148 Debug(LDAP_DEBUG_ARGS,
149 "<=- ldbm_back_delete: operations error %s\n",
151 send_ldap_result( conn, op, LDAP_OTHER,
152 NULL, "DN index delete failed", NULL, NULL );
156 /* delete from disk and cache */
157 if ( id2entry_delete( be, e ) != 0 ) {
158 Debug(LDAP_DEBUG_ARGS,
159 "<=- ldbm_back_delete: operations error %s\n",
161 send_ldap_result( conn, op, LDAP_OTHER,
162 NULL, "entry delete failed", NULL, NULL );
166 send_ldap_result( conn, op, LDAP_SUCCESS,
167 NULL, NULL, NULL, NULL );
171 if ( pdn != NULL ) free(pdn);
174 /* free parent and writer lock */
175 cache_return_entry_w( &li->li_cache, p );
179 /* release root lock */
180 ldap_pvt_thread_mutex_unlock(&li->li_root_mutex);
183 /* free entry and writer lock */
184 cache_return_entry_w( &li->li_cache, e );