1 /* delete.c - bdb2 backend delete routine */
11 #include "back-bdb2.h"
12 #include "proto-back-bdb2.h"
15 bdb2i_back_delete_internal(
22 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
23 Entry *matched = NULL;
26 int rc = -1, manageDSAit;
28 Debug(LDAP_DEBUG_ARGS, "==> bdb2i_back_delete: %s\n", dn, 0, 0);
30 /* get entry with writer lock */
31 if ( (e = bdb2i_dn2entry_w( be, dn, &matched )) == NULL ) {
32 char *matched_dn = NULL;
33 struct berval **refs = NULL;
35 Debug(LDAP_DEBUG_ARGS, "<=- bdb2i_back_delete: no such object %s\n",
38 if ( matched != NULL ) {
39 matched_dn = ch_strdup( matched->e_dn );
40 refs = is_entry_referral( matched )
41 ? get_entry_referrals( be, conn, op, matched )
43 bdb2i_cache_return_entry_r( &li->li_cache, matched );
45 refs = default_referral;
48 send_ldap_result( conn, op, LDAP_REFERRAL,
49 matched_dn, NULL, refs, NULL );
51 if( matched != NULL ) {
59 if (!manageDSAit && is_entry_referral( e ) ) {
60 /* entry is a referral, don't allow add */
61 struct berval **refs = get_entry_referrals( be,
64 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
67 send_ldap_result( conn, op, LDAP_REFERRAL,
68 e->e_dn, NULL, refs, NULL );
75 if ( bdb2i_has_children( be, e ) ) {
76 Debug(LDAP_DEBUG_ARGS, "<=- bdb2i_back_delete: non leaf %s\n",
78 send_ldap_result( conn, op, LDAP_NOT_ALLOWED_ON_NONLEAF,
79 NULL, NULL, NULL, NULL );
83 #ifdef SLAPD_CHILD_MODIFICATION_WITH_ENTRY_ACL
84 if ( ! access_allowed( be, conn, op, e,
85 "entry", NULL, ACL_WRITE ) )
87 Debug(LDAP_DEBUG_ARGS,
88 "<=- bdb2i_back_delete: insufficient access %s\n",
90 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
91 NULL, NULL, NULL, NULL );
96 /* delete from parent's id2children entry */
97 if( (pdn = dn_parent( be, e->e_ndn )) != NULL ) {
98 if( (p = bdb2i_dn2entry_w( be, pdn, &matched )) == NULL) {
99 Debug( LDAP_DEBUG_TRACE,
100 "<=- bdb2i_back_delete: parent does not exist\n", 0, 0, 0);
101 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
102 NULL, NULL, 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 "<=- bdb2i_back_delete: no access to parent\n", 0, 0, 0 );
112 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
113 NULL, NULL, NULL, NULL );
118 /* no parent, must be root to delete */
119 if( ! be_isroot( be, op->o_ndn ) ) {
120 Debug( LDAP_DEBUG_TRACE,
121 "<=- bdb2i_back_delete: no parent & not root\n", 0, 0, 0);
122 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
123 NULL, NULL, NULL, NULL );
128 if ( bdb2i_id2children_remove( be, p, e ) != 0 ) {
129 Debug(LDAP_DEBUG_ARGS,
130 "<=- bdb2i_back_delete: operations error %s\n",
132 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
133 NULL, NULL, NULL, NULL );
137 /* delete from dn2id mapping */
138 if ( bdb2i_dn2id_delete( be, e->e_ndn ) != 0 ) {
139 Debug(LDAP_DEBUG_ARGS,
140 "<=- bdb2i_back_delete: operations error %s\n",
142 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
143 NULL, NULL, NULL, NULL );
147 /* delete from disk and cache */
148 if ( bdb2i_id2entry_delete( be, e ) != 0 ) {
149 Debug(LDAP_DEBUG_ARGS,
150 "<=- bdb2i_back_delete: operations error %s\n",
152 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
153 NULL, NULL, NULL, NULL );
157 send_ldap_result( conn, op, LDAP_SUCCESS,
158 NULL, NULL, NULL, NULL );
162 if ( pdn != NULL ) free(pdn);
165 /* free parent and writer lock */
166 bdb2i_cache_return_entry_w( &li->li_cache, p );
170 /* free entry and writer lock */
171 bdb2i_cache_return_entry_w( &li->li_cache, e );
173 if ( matched != NULL ) free(matched);
188 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
189 struct timeval time1;
192 bdb2i_start_timing( be->bd_info, &time1 );
194 if ( bdb2i_enter_backend_w( &lock ) != 0 ) {
195 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
196 NULL, NULL, NULL, NULL );
200 ret = bdb2i_back_delete_internal( be, conn, op, dn );
201 (void) bdb2i_leave_backend_w( lock );
202 bdb2i_stop_timing( be->bd_info, time1, "DEL", conn, op );