1 /* delete.c - bdb2 backend delete routine */
12 #include "back-bdb2.h"
13 #include "proto-back-bdb2.h"
16 bdb2i_back_delete_internal(
23 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
24 Entry *matched = NULL;
27 int rc = -1, manageDSAit;
29 Debug(LDAP_DEBUG_ARGS, "==> bdb2i_back_delete: %s\n", dn, 0, 0);
31 /* get entry with writer lock */
32 if ( (e = bdb2i_dn2entry_w( be, dn, &matched )) == NULL ) {
33 char *matched_dn = NULL;
34 struct berval **refs = NULL;
36 Debug(LDAP_DEBUG_ARGS, "<=- bdb2i_back_delete: no such object %s\n",
39 if ( matched != NULL ) {
40 matched_dn = ch_strdup( matched->e_dn );
41 refs = is_entry_referral( matched )
42 ? get_entry_referrals( be, conn, op, matched )
44 bdb2i_cache_return_entry_r( &li->li_cache, matched );
46 refs = default_referral;
49 send_ldap_result( conn, op, LDAP_REFERRAL,
50 matched_dn, NULL, refs, NULL );
52 if( matched != NULL ) {
60 if (!manageDSAit && is_entry_referral( e ) ) {
61 /* entry is a referral, don't allow add */
62 struct berval **refs = get_entry_referrals( be,
65 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
68 send_ldap_result( conn, op, LDAP_REFERRAL,
69 e->e_dn, NULL, refs, NULL );
76 if ( bdb2i_has_children( be, e ) ) {
77 Debug(LDAP_DEBUG_ARGS, "<=- bdb2i_back_delete: non leaf %s\n",
79 send_ldap_result( conn, op, LDAP_NOT_ALLOWED_ON_NONLEAF,
80 NULL, NULL, NULL, NULL );
84 #ifdef SLAPD_CHILD_MODIFICATION_WITH_ENTRY_ACL
85 if ( ! access_allowed( be, conn, op, e,
86 "entry", NULL, ACL_WRITE ) )
88 Debug(LDAP_DEBUG_ARGS,
89 "<=- bdb2i_back_delete: insufficient access %s\n",
91 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
92 NULL, NULL, NULL, NULL );
97 /* find parent's entry */
98 if( (pdn = dn_parent( be, e->e_ndn )) != NULL ) {
99 if( (p = bdb2i_dn2entry_w( be, pdn, &matched )) == NULL) {
100 Debug( LDAP_DEBUG_TRACE,
101 "<=- bdb2i_back_delete: parent does not exist\n", 0, 0, 0);
102 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
103 NULL, NULL, NULL, NULL );
107 /* check parent for "children" acl */
108 if ( ! access_allowed( be, conn, op, p,
109 "children", NULL, ACL_WRITE ) )
111 Debug( LDAP_DEBUG_TRACE,
112 "<=- bdb2i_back_delete: no access to parent\n", 0, 0, 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 "<=- bdb2i_back_delete: no parent & not root\n", 0, 0, 0);
123 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
124 NULL, NULL, NULL, NULL );
129 /* delete from dn2id mapping */
130 if ( bdb2i_dn2id_delete( be, e->e_ndn, e->e_id ) != 0 ) {
131 Debug(LDAP_DEBUG_ARGS,
132 "<=- bdb2i_back_delete: operations error %s\n",
134 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
135 NULL, NULL, NULL, NULL );
139 /* delete from disk and cache */
140 if ( bdb2i_id2entry_delete( be, e ) != 0 ) {
141 Debug(LDAP_DEBUG_ARGS,
142 "<=- bdb2i_back_delete: operations error %s\n",
144 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
145 NULL, NULL, NULL, NULL );
149 send_ldap_result( conn, op, LDAP_SUCCESS,
150 NULL, NULL, NULL, NULL );
154 if ( pdn != NULL ) free(pdn);
157 /* free parent and writer lock */
158 bdb2i_cache_return_entry_w( &li->li_cache, p );
162 /* free entry and writer lock */
163 bdb2i_cache_return_entry_w( &li->li_cache, e );
165 if ( matched != NULL ) free(matched);
181 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
182 struct timeval time1;
185 bdb2i_start_timing( be->bd_info, &time1 );
187 if ( bdb2i_enter_backend_w( &lock ) != 0 ) {
188 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
189 NULL, NULL, NULL, NULL );
193 ret = bdb2i_back_delete_internal( be, conn, op, ndn );
194 (void) bdb2i_leave_backend_w( lock );
195 bdb2i_stop_timing( be->bd_info, time1, "DEL", conn, op );