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"
27 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
33 int manageDSAit = get_manageDSAit( op );
35 Debug(LDAP_DEBUG_ARGS, "==> ldbm_back_delete: %s\n", dn, 0, 0);
37 /* get entry with writer lock */
38 if ( (e = dn2entry_w( be, dn, &matched )) == NULL ) {
39 char *matched_dn = NULL;
40 struct berval **refs = NULL;
42 Debug(LDAP_DEBUG_ARGS, "<=- ldbm_back_delete: no such object %s\n",
45 if ( matched != NULL ) {
46 matched_dn = ch_strdup( matched->e_dn );
47 refs = is_entry_referral( matched )
48 ? get_entry_referrals( be, conn, op, matched )
50 cache_return_entry_r( &li->li_cache, matched );
52 refs = default_referral;
55 send_ldap_result( conn, op, LDAP_REFERRAL,
56 matched_dn, NULL, refs, NULL );
58 if ( matched != NULL ) {
66 #ifdef SLAPD_CHILD_MODIFICATION_WITH_ENTRY_ACL
67 if ( ! access_allowed( be, conn, op, e,
68 "entry", NULL, ACL_WRITE ) )
70 Debug(LDAP_DEBUG_ARGS,
71 "<=- ldbm_back_delete: insufficient access %s\n",
73 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
74 NULL, NULL, NULL, NULL );
79 if ( !manageDSAit && is_entry_referral( e ) ) {
80 /* parent is a referral, don't allow add */
81 /* parent is an alias, don't allow add */
82 struct berval **refs = get_entry_referrals( be,
85 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
88 send_ldap_result( conn, op, LDAP_REFERRAL,
89 e->e_dn, NULL, refs, NULL );
98 if ( has_children( be, e ) ) {
99 Debug(LDAP_DEBUG_ARGS, "<=- ldbm_back_delete: non leaf %s\n",
101 send_ldap_result( conn, op, LDAP_NOT_ALLOWED_ON_NONLEAF,
102 NULL, NULL, NULL, NULL );
106 /* delete from parent's id2children entry */
107 if( (pdn = dn_parent( be, e->e_ndn )) != NULL ) {
108 if( (p = dn2entry_w( be, pdn, NULL )) == NULL) {
109 Debug( LDAP_DEBUG_TRACE,
110 "<=- ldbm_back_delete: parent does not exist\n",
112 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
113 NULL, NULL, NULL, NULL );
117 /* check parent for "children" acl */
118 if ( ! access_allowed( be, conn, op, p,
119 "children", NULL, ACL_WRITE ) )
121 Debug( LDAP_DEBUG_TRACE,
122 "<=- ldbm_back_delete: no access to parent\n", 0,
124 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
125 NULL, NULL, NULL, NULL );
130 /* no parent, must be root to delete */
131 if( ! be_isroot( be, op->o_ndn ) ) {
132 Debug( LDAP_DEBUG_TRACE,
133 "<=- ldbm_back_delete: no parent & not root\n",
135 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
136 NULL, NULL, NULL, NULL );
140 ldap_pvt_thread_mutex_lock(&li->li_root_mutex);
144 /* delete from dn2id mapping */
145 if ( dn2id_delete( be, e->e_ndn, e->e_id ) != 0 ) {
146 Debug(LDAP_DEBUG_ARGS,
147 "<=- ldbm_back_delete: operations error %s\n",
149 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
150 NULL, NULL, NULL, NULL );
154 /* delete from disk and cache */
155 if ( id2entry_delete( be, e ) != 0 ) {
156 Debug(LDAP_DEBUG_ARGS,
157 "<=- ldbm_back_delete: operations error %s\n",
159 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
160 NULL, NULL, NULL, NULL );
164 send_ldap_result( conn, op, LDAP_SUCCESS,
165 NULL, NULL, NULL, NULL );
169 if ( pdn != NULL ) free(pdn);
172 /* free parent and writer lock */
173 cache_return_entry_w( &li->li_cache, p );
177 /* release root lock */
178 ldap_pvt_thread_mutex_unlock(&li->li_root_mutex);
181 /* free entry and writer lock */
182 cache_return_entry_w( &li->li_cache, e );