1 /* delete.c - ldbm backend delete routine */
3 * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
11 #include <ac/string.h>
12 #include <ac/socket.h>
15 #include "back-ldbm.h"
16 #include "proto-back-ldbm.h"
26 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
27 Entry *matched = NULL;
32 int manageDSAit = get_manageDSAit( op );
34 Debug(LDAP_DEBUG_ARGS, "==> ldbm_back_delete: %s\n", dn, 0, 0);
36 /* get entry with writer lock */
37 if ( (e = dn2entry_w( be, dn, &matched )) == NULL ) {
38 char *matched_dn = NULL;
39 struct berval **refs = NULL;
41 Debug(LDAP_DEBUG_ARGS, "<=- ldbm_back_delete: no such object %s\n",
44 if ( matched != NULL ) {
45 matched_dn = ch_strdup( matched->e_dn );
46 refs = is_entry_referral( matched )
47 ? get_entry_referrals( be, conn, op, matched )
49 cache_return_entry_r( &li->li_cache, matched );
51 refs = default_referral;
54 send_ldap_result( conn, op, LDAP_REFERRAL,
55 matched_dn, NULL, refs, NULL );
57 if ( matched != NULL ) {
65 #ifdef SLAPD_CHILD_MODIFICATION_WITH_ENTRY_ACL
66 if ( ! access_allowed( be, conn, op, e,
67 "entry", NULL, ACL_WRITE ) )
69 Debug(LDAP_DEBUG_ARGS,
70 "<=- ldbm_back_delete: insufficient access %s\n",
72 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
73 NULL, NULL, NULL, NULL );
78 if ( !manageDSAit && is_entry_referral( e ) ) {
79 /* parent is a referral, don't allow add */
80 /* parent is an alias, don't allow add */
81 struct berval **refs = get_entry_referrals( be,
84 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
87 send_ldap_result( conn, op, LDAP_REFERRAL,
88 e->e_dn, NULL, refs, NULL );
97 if ( has_children( be, e ) ) {
98 Debug(LDAP_DEBUG_ARGS, "<=- ldbm_back_delete: non leaf %s\n",
100 send_ldap_result( conn, op, LDAP_NOT_ALLOWED_ON_NONLEAF,
101 NULL, NULL, NULL, NULL );
105 /* delete from parent's id2children entry */
106 if( (pdn = dn_parent( be, e->e_ndn )) != NULL ) {
107 if( (p = dn2entry_w( be, pdn, &matched )) == NULL) {
108 Debug( LDAP_DEBUG_TRACE,
109 "<=- ldbm_back_delete: parent does not exist\n",
111 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
112 NULL, NULL, NULL, NULL );
116 /* check parent for "children" acl */
117 if ( ! access_allowed( be, conn, op, p,
118 "children", NULL, ACL_WRITE ) )
120 Debug( LDAP_DEBUG_TRACE,
121 "<=- ldbm_back_delete: no access to parent\n", 0,
123 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
124 NULL, NULL, NULL, NULL );
129 /* no parent, must be root to delete */
130 if( ! be_isroot( be, op->o_ndn ) ) {
131 Debug( LDAP_DEBUG_TRACE,
132 "<=- ldbm_back_delete: no parent & not root\n",
134 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
135 NULL, NULL, NULL, NULL );
139 ldap_pvt_thread_mutex_lock(&li->li_root_mutex);
143 /* delete from dn2id mapping */
144 if ( dn2id_delete( be, e->e_ndn ) != 0 ) {
145 Debug(LDAP_DEBUG_ARGS,
146 "<=- ldbm_back_delete: operations error %s\n",
148 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
149 NULL, NULL, NULL, NULL );
153 /* delete from disk and cache */
154 if ( id2entry_delete( be, e ) != 0 ) {
155 Debug(LDAP_DEBUG_ARGS,
156 "<=- ldbm_back_delete: operations error %s\n",
158 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
159 NULL, NULL, NULL, NULL );
163 send_ldap_result( conn, op, LDAP_SUCCESS,
164 NULL, NULL, NULL, NULL );
168 if ( pdn != NULL ) free(pdn);
171 /* free parent and writer lock */
172 cache_return_entry_w( &li->li_cache, p );
176 /* release root lock */
177 ldap_pvt_thread_mutex_unlock(&li->li_root_mutex);
180 /* free entry and writer lock */
181 cache_return_entry_w( &li->li_cache, e );
183 if ( matched != NULL ) free(matched);