1 /* delete.c - ldbm backend delete routine */
4 * Copyright 1998-1999 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 );
36 Debug(LDAP_DEBUG_ARGS, "==> ldbm_back_delete: %s\n", dn, 0, 0);
38 /* get entry with writer lock */
39 if ( (e = dn2entry_w( be, ndn, &matched )) == NULL ) {
40 char *matched_dn = NULL;
41 struct berval **refs = NULL;
43 Debug(LDAP_DEBUG_ARGS, "<=- ldbm_back_delete: no such object %s\n",
46 if ( matched != NULL ) {
47 matched_dn = ch_strdup( matched->e_dn );
48 refs = is_entry_referral( matched )
49 ? get_entry_referrals( be, conn, op, matched )
51 cache_return_entry_r( &li->li_cache, matched );
53 refs = default_referral;
56 send_ldap_result( conn, op, LDAP_REFERRAL,
57 matched_dn, NULL, refs, NULL );
59 if ( matched != NULL ) {
67 #ifdef SLAPD_CHILD_MODIFICATION_WITH_ENTRY_ACL
68 if ( ! access_allowed( be, conn, op, e,
69 "entry", NULL, ACL_WRITE ) )
71 Debug(LDAP_DEBUG_ARGS,
72 "<=- ldbm_back_delete: insufficient access %s\n",
74 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
75 NULL, NULL, NULL, 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,
86 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
89 send_ldap_result( conn, op, LDAP_REFERRAL,
90 e->e_dn, NULL, refs, NULL );
99 if ( has_children( be, e ) ) {
100 Debug(LDAP_DEBUG_ARGS, "<=- ldbm_back_delete: non leaf %s\n",
102 send_ldap_result( conn, op, LDAP_NOT_ALLOWED_ON_NONLEAF,
103 NULL, NULL, NULL, NULL );
107 /* delete from parent's id2children entry */
108 if( (pdn = dn_parent( be, e->e_ndn )) != NULL ) {
109 if( (p = dn2entry_w( be, pdn, NULL )) == NULL) {
110 Debug( LDAP_DEBUG_TRACE,
111 "<=- ldbm_back_delete: parent does not exist\n",
113 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
114 NULL, NULL, NULL, NULL );
118 /* check parent for "children" acl */
119 if ( ! access_allowed( be, conn, op, p,
120 "children", NULL, ACL_WRITE ) )
122 Debug( LDAP_DEBUG_TRACE,
123 "<=- ldbm_back_delete: no access to parent\n", 0,
125 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
126 NULL, NULL, NULL, NULL );
131 /* no parent, must be root to delete */
132 if( ! be_isroot( be, op->o_ndn ) ) {
133 Debug( LDAP_DEBUG_TRACE,
134 "<=- ldbm_back_delete: no parent & not root\n",
136 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
137 NULL, NULL, NULL, NULL );
141 ldap_pvt_thread_mutex_lock(&li->li_root_mutex);
145 /* delete from dn2id mapping */
146 if ( dn2id_delete( be, e->e_ndn, e->e_id ) != 0 ) {
147 Debug(LDAP_DEBUG_ARGS,
148 "<=- ldbm_back_delete: operations error %s\n",
150 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
151 NULL, NULL, NULL, NULL );
155 /* delete from disk and cache */
156 if ( id2entry_delete( be, e ) != 0 ) {
157 Debug(LDAP_DEBUG_ARGS,
158 "<=- ldbm_back_delete: operations error %s\n",
160 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
161 NULL, NULL, NULL, NULL );
165 send_ldap_result( conn, op, LDAP_SUCCESS,
166 NULL, NULL, NULL, NULL );
170 if ( pdn != NULL ) free(pdn);
173 /* free parent and writer lock */
174 cache_return_entry_w( &li->li_cache, p );
178 /* release root lock */
179 ldap_pvt_thread_mutex_unlock(&li->li_root_mutex);
182 /* free entry and writer lock */
183 cache_return_entry_w( &li->li_cache, e );