]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/delete.c
Proxy caching update : op->o_caching_on flag removed
[openldap] / servers / slapd / back-ldbm / delete.c
1 /* delete.c - ldbm backend delete routine */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
5  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6  */
7
8 #include "portable.h"
9
10 #include <stdio.h>
11
12 #include <ac/string.h>
13 #include <ac/socket.h>
14
15 #include "slap.h"
16 #include "back-ldbm.h"
17 #include "proto-back-ldbm.h"
18
19 int
20 ldbm_back_delete(
21     Operation   *op,
22     SlapReply   *rs )
23 {
24         struct ldbminfo *li = (struct ldbminfo *) op->o_bd->be_private;
25         Entry   *matched;
26         struct berval   pdn;
27         Entry   *e, *p = NULL;
28         int     rc = -1;
29         int             manageDSAit = get_manageDSAit( op );
30         AttributeDescription *children = slap_schema.si_ad_children;
31         AttributeDescription *entry = slap_schema.si_ad_entry;
32
33 #ifdef NEW_LOGGING
34         LDAP_LOG( BACK_LDBM, ENTRY, "ldbm_back_delete: %s\n", op->o_req_dn.bv_val, 0, 0 );
35 #else
36         Debug(LDAP_DEBUG_ARGS, "==> ldbm_back_delete: %s\n", op->o_req_dn.bv_val, 0, 0);
37 #endif
38
39         /* grab giant lock for writing */
40         ldap_pvt_thread_rdwr_wlock(&li->li_giant_rwlock);
41
42         /* get entry with writer lock */
43         e = dn2entry_w( op->o_bd, &op->o_req_ndn, &matched );
44
45 #ifdef LDAP_SYNCREPL /* FIXME : dn2entry() should return non-glue entry */
46         if ( e == NULL || ( !manageDSAit && is_entry_glue( e ))) {
47 #else
48         if ( e == NULL ) {
49 #endif
50 #ifdef NEW_LOGGING
51                 LDAP_LOG( BACK_LDBM, INFO, 
52                         "ldbm_back_delete: no such object %s\n", op->o_req_dn.bv_val, 0, 0 );
53 #else
54                 Debug(LDAP_DEBUG_ARGS, "<=- ldbm_back_delete: no such object %s\n",
55                         op->o_req_dn.bv_val, 0, 0);
56 #endif
57
58                 if ( matched != NULL ) {
59                         rs->sr_matched = ch_strdup( matched->e_dn );
60                         rs->sr_ref = is_entry_referral( matched )
61                                 ? get_entry_referrals( op, matched )
62                                 : NULL;
63                         cache_return_entry_r( &li->li_cache, matched );
64
65                 } else {
66 #ifdef LDAP_SYNCREPL
67                         BerVarray deref = op->o_bd->syncinfo ?
68                                                           op->o_bd->syncinfo->provideruri_bv : default_referral;
69 #else
70                         BerVarray deref = default_referral;
71 #endif
72                         rs->sr_ref = referral_rewrite( deref, NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
73                 }
74
75                 ldap_pvt_thread_rdwr_wunlock(&li->li_giant_rwlock);
76
77                 rs->sr_err = LDAP_REFERRAL;
78                 send_ldap_result( op, rs );
79
80                 if ( rs->sr_ref ) ber_bvarray_free( rs->sr_ref );
81                 free( (char *)rs->sr_matched );
82
83                 return( -1 );
84         }
85
86         /* check entry for "entry" acl */
87         if ( ! access_allowed( op, e,
88                 entry, NULL, ACL_WRITE, NULL ) )
89         {
90 #ifdef NEW_LOGGING
91                 LDAP_LOG( BACK_LDBM, ERR, 
92                         "ldbm_back_delete: no write access to entry of (%s)\n", 
93                         op->o_req_dn.bv_val, 0, 0 );
94 #else
95                 Debug( LDAP_DEBUG_TRACE,
96                         "<=- ldbm_back_delete: no write access to entry\n", 0,
97                         0, 0 );
98 #endif
99
100                 send_ldap_error( op, rs, LDAP_INSUFFICIENT_ACCESS,
101                         "no write access to entry" );
102
103                 rc = 1;
104                 goto return_results;
105         }
106
107         if ( !manageDSAit && is_entry_referral( e ) ) {
108                 /* parent is a referral, don't allow add */
109                 /* parent is an alias, don't allow add */
110                 rs->sr_ref = get_entry_referrals( op, e );
111
112 #ifdef NEW_LOGGING
113                 LDAP_LOG( BACK_LDBM, INFO, 
114                         "ldbm_back_delete: entry (%s) is a referral.\n", e->e_dn, 0, 0 );
115 #else
116                 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
117                     0, 0 );
118 #endif
119
120                 rs->sr_err = LDAP_REFERRAL;
121                 rs->sr_matched = e->e_name.bv_val;
122                 send_ldap_result( op, rs );
123
124                 if ( rs->sr_ref ) ber_bvarray_free( rs->sr_ref );
125
126                 rc = 1;
127                 goto return_results;
128         }
129
130         if ( has_children( op->o_bd, e ) ) {
131 #ifdef NEW_LOGGING
132                 LDAP_LOG( BACK_LDBM, ERR, 
133                            "ldbm_back_delete: (%s) is a non-leaf node.\n", op->o_req_dn.bv_val, 0,0);
134 #else
135                 Debug(LDAP_DEBUG_ARGS, "<=- ldbm_back_delete: non leaf %s\n",
136                         op->o_req_dn.bv_val, 0, 0);
137 #endif
138
139                 send_ldap_error( op, rs, LDAP_NOT_ALLOWED_ON_NONLEAF,
140                         "subtree delete not supported" );
141                 goto return_results;
142         }
143
144         /* delete from parent's id2children entry */
145         if( !be_issuffix( op->o_bd, &e->e_nname ) && (dnParent( &e->e_nname, &pdn ),
146                 pdn.bv_len) ) {
147                 if( (p = dn2entry_w( op->o_bd, &pdn, NULL )) == NULL) {
148 #ifdef NEW_LOGGING
149                         LDAP_LOG( BACK_LDBM, ERR, 
150                                 "ldbm_back_delete: parent of (%s) does not exist\n", op->o_req_dn, 0, 0 );
151 #else
152                         Debug( LDAP_DEBUG_TRACE,
153                                 "<=- ldbm_back_delete: parent does not exist\n",
154                                 0, 0, 0);
155 #endif
156
157                         send_ldap_error( op, rs, LDAP_OTHER,
158                                 "could not locate parent of entry" );
159                         goto return_results;
160                 }
161
162                 /* check parent for "children" acl */
163                 if ( ! access_allowed( op, p,
164                         children, NULL, ACL_WRITE, NULL ) )
165                 {
166 #ifdef NEW_LOGGING
167                         LDAP_LOG( BACK_LDBM, ERR, 
168                                 "ldbm_back_delete: no access to parent of (%s)\n", 
169                                 op->o_req_dn.bv_val, 0, 0 );
170 #else
171                         Debug( LDAP_DEBUG_TRACE,
172                                 "<=- ldbm_back_delete: no access to parent\n", 0,
173                                 0, 0 );
174 #endif
175
176                         send_ldap_error( op, rs, LDAP_INSUFFICIENT_ACCESS,
177                                 "no write access to parent" );
178                         goto return_results;
179                 }
180
181         } else {
182                 /* no parent, must be root to delete */
183                 if( ! be_isroot( op->o_bd, &op->o_ndn ) ) {
184                         if ( be_issuffix( op->o_bd, (struct berval *)&slap_empty_bv ) || be_isupdate( op->o_bd, &op->o_ndn ) ) {
185                                 p = (Entry *)&slap_entry_root;
186                                 
187                                 rc = access_allowed( op, p,
188                                         children, NULL, ACL_WRITE, NULL );
189                                 p = NULL;
190                                                                 
191                                 /* check parent for "children" acl */
192                                 if ( ! rc ) {
193 #ifdef NEW_LOGGING
194                                         LDAP_LOG( BACK_LDBM, ERR,
195                                                 "ldbm_back_delete: no access "
196                                                 "to parent of ("")\n", 0, 0, 0 );
197 #else
198                                         Debug( LDAP_DEBUG_TRACE,
199                                                 "<=- ldbm_back_delete: no "
200                                                 "access to parent\n", 0, 0, 0 );
201 #endif
202
203                                         send_ldap_error( op, rs, LDAP_INSUFFICIENT_ACCESS,
204                                                 "no write access to parent" );
205                                         goto return_results;
206                                 }
207
208                         } else {
209 #ifdef NEW_LOGGING
210                                 LDAP_LOG( BACK_LDBM, ERR, 
211                                         "ldbm_back_delete: (%s) has no "
212                                         "parent & not a root.\n", op->o_ndn, 0, 0 );
213 #else
214                                 Debug( LDAP_DEBUG_TRACE,
215                                         "<=- ldbm_back_delete: no parent & "
216                                         "not root\n", 0, 0, 0);
217 #endif
218
219                                 send_ldap_error( op, rs,
220                                         LDAP_INSUFFICIENT_ACCESS,
221                                         NULL );
222                                 goto return_results;
223                         }
224                 }
225         }
226
227         /* delete from dn2id mapping */
228         if ( dn2id_delete( op->o_bd, &e->e_nname, e->e_id ) != 0 ) {
229 #ifdef NEW_LOGGING
230                 LDAP_LOG( BACK_LDBM, ERR, 
231                         "ldbm_back_delete: (%s) operations error\n", op->o_req_dn.bv_val, 0, 0 );
232 #else
233                 Debug(LDAP_DEBUG_ARGS,
234                         "<=- ldbm_back_delete: operations error %s\n",
235                         op->o_req_dn.bv_val, 0, 0);
236 #endif
237
238                 send_ldap_error( op, rs, LDAP_OTHER,
239                         "DN index delete failed" );
240                 goto return_results;
241         }
242
243         /* delete from disk and cache */
244         if ( id2entry_delete( op->o_bd, e ) != 0 ) {
245 #ifdef NEW_LOGGING
246                 LDAP_LOG( BACK_LDBM, ERR, 
247                         "ldbm_back_delete: (%s) operations error\n", op->o_req_dn.bv_val, 0, 0 );
248 #else
249                 Debug(LDAP_DEBUG_ARGS,
250                         "<=- ldbm_back_delete: operations error %s\n",
251                         op->o_req_dn.bv_val, 0, 0);
252 #endif
253
254                 send_ldap_error( op, rs, LDAP_OTHER,
255                         "entry delete failed" );
256                 goto return_results;
257         }
258
259         /* delete attribute indices */
260         (void) index_entry_del( op, e );
261
262         rs->sr_err = LDAP_SUCCESS;
263         send_ldap_result( op, rs );
264         rc = 0;
265
266 return_results:;
267         if( p != NULL ) {
268                 /* free parent and writer lock */
269                 cache_return_entry_w( &li->li_cache, p );
270         }
271
272         /* free entry and writer lock */
273         cache_return_entry_w( &li->li_cache, e );
274
275         ldap_pvt_thread_rdwr_wunlock(&li->li_giant_rwlock);
276
277         return rc;
278 }