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 if ( !manageDSAit && is_entry_referral( e ) ) {
69 /* parent is a referral, don't allow add */
70 /* parent is an alias, don't allow add */
71 struct berval **refs = get_entry_referrals( be,
74 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
77 send_ldap_result( conn, op, LDAP_REFERRAL,
78 e->e_dn, NULL, refs, NULL );
87 if ( has_children( be, e ) ) {
88 Debug(LDAP_DEBUG_ARGS, "<=- ldbm_back_delete: non leaf %s\n",
90 send_ldap_result( conn, op, LDAP_NOT_ALLOWED_ON_NONLEAF,
91 NULL, "subtree delete not supported", NULL, NULL );
95 /* delete from parent's id2children entry */
96 if( (pdn = dn_parent( be, e->e_ndn )) != NULL ) {
97 if( (p = dn2entry_w( be, pdn, NULL )) == NULL) {
98 Debug( LDAP_DEBUG_TRACE,
99 "<=- ldbm_back_delete: parent does not exist\n",
101 send_ldap_result( conn, op, LDAP_OTHER,
102 NULL, "could not locate parent of entry", NULL, NULL );
106 /* check parent for "children" acl */
107 if ( ! access_allowed( be, conn, op, p,
108 children, NULL, ACL_WRITE ) )
110 Debug( LDAP_DEBUG_TRACE,
111 "<=- ldbm_back_delete: no access to parent\n", 0,
113 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
114 NULL, NULL, NULL, NULL );
119 /* no parent, must be root to delete */
120 if( ! be_isroot( be, op->o_ndn ) ) {
121 Debug( LDAP_DEBUG_TRACE,
122 "<=- ldbm_back_delete: no parent & not root\n",
124 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
125 NULL, NULL, NULL, NULL );
129 ldap_pvt_thread_mutex_lock(&li->li_root_mutex);
133 /* delete from dn2id mapping */
134 if ( dn2id_delete( be, e->e_ndn, e->e_id ) != 0 ) {
135 Debug(LDAP_DEBUG_ARGS,
136 "<=- ldbm_back_delete: operations error %s\n",
138 send_ldap_result( conn, op, LDAP_OTHER,
139 NULL, "DN index delete failed", NULL, NULL );
143 /* delete from disk and cache */
144 if ( id2entry_delete( be, e ) != 0 ) {
145 Debug(LDAP_DEBUG_ARGS,
146 "<=- ldbm_back_delete: operations error %s\n",
148 send_ldap_result( conn, op, LDAP_OTHER,
149 NULL, "entry delete failed", NULL, NULL );
153 send_ldap_result( conn, op, LDAP_SUCCESS,
154 NULL, NULL, NULL, NULL );
158 if ( pdn != NULL ) free(pdn);
161 /* free parent and writer lock */
162 cache_return_entry_w( &li->li_cache, p );
166 /* release root lock */
167 ldap_pvt_thread_mutex_unlock(&li->li_root_mutex);
170 /* free entry and writer lock */
171 cache_return_entry_w( &li->li_cache, e );