1 /* delete.c - ldbm backend delete routine */
11 #include "back-ldbm.h"
12 #include "proto-back-ldbm.h"
22 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
23 Entry *matched = NULL;
28 int manageDSAit = get_manageDSAit( op );
30 Debug(LDAP_DEBUG_ARGS, "==> ldbm_back_delete: %s\n", dn, 0, 0);
32 /* get entry with writer lock */
33 if ( (e = dn2entry_w( be, dn, &matched )) == NULL ) {
34 char *matched_dn = NULL;
35 struct berval **refs = NULL;
37 Debug(LDAP_DEBUG_ARGS, "<=- ldbm_back_delete: no such object %s\n",
40 if ( matched != NULL ) {
41 matched_dn = ch_strdup( matched->e_dn );
42 refs = is_entry_referral( matched )
43 ? get_entry_referrals( be, conn, op, matched )
45 cache_return_entry_r( &li->li_cache, matched );
47 refs = default_referral;
50 send_ldap_result( conn, op, LDAP_REFERRAL,
51 matched_dn, NULL, refs, NULL );
53 if ( matched != NULL ) {
61 #ifdef SLAPD_CHILD_MODIFICATION_WITH_ENTRY_ACL
62 if ( ! access_allowed( be, conn, op, e,
63 "entry", NULL, ACL_WRITE ) )
65 Debug(LDAP_DEBUG_ARGS,
66 "<=- ldbm_back_delete: insufficient access %s\n",
68 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
69 NULL, NULL, NULL, NULL );
74 if ( !manageDSAit && is_entry_referral( e ) ) {
75 /* parent is a referral, don't allow add */
76 /* parent is an alias, don't allow add */
77 struct berval **refs = get_entry_referrals( be,
80 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
83 send_ldap_result( conn, op, LDAP_REFERRAL,
84 e->e_dn, NULL, refs, NULL );
93 if ( has_children( be, e ) ) {
94 Debug(LDAP_DEBUG_ARGS, "<=- ldbm_back_delete: non leaf %s\n",
96 send_ldap_result( conn, op, LDAP_NOT_ALLOWED_ON_NONLEAF,
97 NULL, NULL, NULL, NULL );
101 /* delete from parent's id2children entry */
102 if( (pdn = dn_parent( be, e->e_ndn )) != NULL ) {
103 if( (p = dn2entry_w( be, pdn, &matched )) == NULL) {
104 Debug( LDAP_DEBUG_TRACE,
105 "<=- ldbm_back_delete: parent does not exist\n",
107 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
108 NULL, NULL, NULL, NULL );
112 /* check parent for "children" acl */
113 if ( ! access_allowed( be, conn, op, p,
114 "children", NULL, ACL_WRITE ) )
116 Debug( LDAP_DEBUG_TRACE,
117 "<=- ldbm_back_delete: no access to parent\n", 0,
119 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
120 NULL, NULL, NULL, NULL );
125 /* no parent, must be root to delete */
126 if( ! be_isroot( be, op->o_ndn ) ) {
127 Debug( LDAP_DEBUG_TRACE,
128 "<=- ldbm_back_delete: no parent & not root\n",
130 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
131 NULL, NULL, NULL, NULL );
135 ldap_pvt_thread_mutex_lock(&li->li_root_mutex);
139 if ( id2children_remove( be, p, e ) != 0 ) {
140 Debug(LDAP_DEBUG_ARGS,
141 "<=- ldbm_back_delete: operations error %s\n",
143 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
144 NULL, NULL, NULL, NULL );
148 /* delete from dn2id mapping */
149 if ( dn2id_delete( be, e->e_ndn ) != 0 ) {
150 Debug(LDAP_DEBUG_ARGS,
151 "<=- ldbm_back_delete: operations error %s\n",
153 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
154 NULL, NULL, NULL, NULL );
158 /* delete from disk and cache */
159 if ( id2entry_delete( be, e ) != 0 ) {
160 Debug(LDAP_DEBUG_ARGS,
161 "<=- ldbm_back_delete: operations error %s\n",
163 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
164 NULL, NULL, NULL, NULL );
168 send_ldap_result( conn, op, LDAP_SUCCESS,
169 NULL, NULL, NULL, NULL );
173 if ( pdn != NULL ) free(pdn);
176 /* free parent and writer lock */
177 cache_return_entry_w( &li->li_cache, p );
181 /* release root lock */
182 ldap_pvt_thread_mutex_unlock(&li->li_root_mutex);
185 /* free entry and writer lock */
186 cache_return_entry_w( &li->li_cache, e );
188 if ( matched != NULL ) free(matched);