]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/delete.c
error message from be_entry_put tool backend function
[openldap] / servers / slapd / back-ldbm / delete.c
1 /* delete.c - ldbm backend delete routine */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2002 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     Backend     *be,
22     Connection  *conn,
23     Operation   *op,
24     struct berval       *dn,
25     struct berval       *ndn
26 )
27 {
28         struct ldbminfo *li = (struct ldbminfo *) be->be_private;
29         Entry   *matched;
30         struct berval   pdn;
31         Entry   *e, *p = NULL;
32         int rootlock = 0;
33         int     rc = -1;
34         int             manageDSAit = get_manageDSAit( op );
35         AttributeDescription *children = slap_schema.si_ad_children;
36
37 #ifdef NEW_LOGGING
38         LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
39                 "ldbm_back_delete: %s\n", dn->bv_val ));
40 #else
41         Debug(LDAP_DEBUG_ARGS, "==> ldbm_back_delete: %s\n", dn->bv_val, 0, 0);
42 #endif
43
44         /* get entry with writer lock */
45         if ( (e = dn2entry_w( be, ndn, &matched )) == NULL ) {
46                 char *matched_dn = NULL;
47                 BVarray refs;
48
49 #ifdef NEW_LOGGING
50                 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
51                         "ldbm_back_delete: no such object %s\n", dn->bv_val ));
52 #else
53                 Debug(LDAP_DEBUG_ARGS, "<=- ldbm_back_delete: no such object %s\n",
54                         dn->bv_val, 0, 0);
55 #endif
56
57                 if ( matched != NULL ) {
58                         matched_dn = ch_strdup( matched->e_dn );
59                         refs = is_entry_referral( matched )
60                                 ? get_entry_referrals( be, conn, op, matched )
61                                 : NULL;
62                         cache_return_entry_r( &li->li_cache, matched );
63
64                 } else {
65                         refs = referral_rewrite( default_referral,
66                                 NULL, dn, LDAP_SCOPE_DEFAULT );
67                 }
68
69                 send_ldap_result( conn, op, LDAP_REFERRAL,
70                         matched_dn, NULL, refs, NULL );
71
72                 if ( refs ) bvarray_free( refs );
73                 free( matched_dn );
74
75                 return( -1 );
76         }
77
78     if ( !manageDSAit && is_entry_referral( e ) ) {
79                 /* parent is a referral, don't allow add */
80                 /* parent is an alias, don't allow add */
81                 BVarray refs = get_entry_referrals( be,
82                         conn, op, e );
83
84 #ifdef NEW_LOGGING
85                 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
86                         "ldbm_back_delete: entry (%s) is a referral.\n",
87                         e->e_dn ));
88 #else
89                 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
90                     0, 0 );
91 #endif
92
93                 send_ldap_result( conn, op, LDAP_REFERRAL,
94                     e->e_dn, NULL, refs, NULL );
95
96                 if ( refs ) bvarray_free( refs );
97
98                 rc = 1;
99                 goto return_results;
100         }
101
102
103         if ( has_children( be, e ) ) {
104 #ifdef NEW_LOGGING
105                 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
106                            "ldbm_back_delete: (%s) is a non-leaf node.\n", dn->bv_val ));
107 #else
108                 Debug(LDAP_DEBUG_ARGS, "<=- ldbm_back_delete: non leaf %s\n",
109                         dn->bv_val, 0, 0);
110 #endif
111
112                 send_ldap_result( conn, op, LDAP_NOT_ALLOWED_ON_NONLEAF,
113                         NULL, "subtree delete not supported", NULL, NULL );
114                 goto return_results;
115         }
116
117         /* delete from parent's id2children entry */
118         if( (pdn.bv_val = dn_parent( be, e->e_ndn )) != NULL && pdn.bv_val[ 0 ] != '\0' ) {
119                 pdn.bv_len = e->e_nname.bv_len - (pdn.bv_val - e->e_ndn);
120                 if( (p = dn2entry_w( be, &pdn, NULL )) == NULL) {
121 #ifdef NEW_LOGGING
122                         LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
123                                 "ldbm_back_delete: parent of (%s) does not exist\n", dn ));
124 #else
125                         Debug( LDAP_DEBUG_TRACE,
126                                 "<=- ldbm_back_delete: parent does not exist\n",
127                                 0, 0, 0);
128 #endif
129
130                         send_ldap_result( conn, op, LDAP_OTHER,
131                                 NULL, "could not locate parent of entry", NULL, NULL );
132                         goto return_results;
133                 }
134
135                 /* check parent for "children" acl */
136                 if ( ! access_allowed( be, conn, op, p,
137                         children, NULL, ACL_WRITE ) )
138                 {
139 #ifdef NEW_LOGGING
140                         LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
141                                 "ldbm_back_delete: no access to parent of (%s)\n",
142                                 dn->bv_val ));
143 #else
144                         Debug( LDAP_DEBUG_TRACE,
145                                 "<=- ldbm_back_delete: no access to parent\n", 0,
146                                 0, 0 );
147 #endif
148
149                         send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
150                                 NULL, NULL, NULL, NULL );
151                         goto return_results;
152                 }
153
154         } else {
155                 /* no parent, must be root to delete */
156                 if( ! be_isroot( be, &op->o_ndn ) ) {
157                         if ( be_issuffix( be, "" ) || be_isupdate( be, &op->o_ndn ) ) {
158                                 p = (Entry *)&slap_entry_root;
159                                 
160                                 rc = access_allowed( be, conn, op, p,
161                                         children, NULL, ACL_WRITE );
162                                 p = NULL;
163                                                                 
164                                 /* check parent for "children" acl */
165                                 if ( ! rc ) {
166 #ifdef NEW_LOGGING
167                                         LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
168                                                 "ldbm_back_delete: no access "
169                                                 "to parent of ("")\n" ));
170 #else
171                                         Debug( LDAP_DEBUG_TRACE,
172                                                 "<=- ldbm_back_delete: no "
173                                                 "access to parent\n", 0, 0, 0 );
174 #endif
175
176                                         send_ldap_result( conn, op, 
177                                                 LDAP_INSUFFICIENT_ACCESS,
178                                                 NULL, NULL, NULL, NULL );
179                                         goto return_results;
180                                 }
181
182                         } else {
183 #ifdef NEW_LOGGING
184                                 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
185                                         "ldbm_back_delete: (%s) has no "
186                                         "parent & not a root.\n", dn ));
187 #else
188                                 Debug( LDAP_DEBUG_TRACE,
189                                         "<=- ldbm_back_delete: no parent & "
190                                         "not root\n", 0, 0, 0);
191 #endif
192
193                                 send_ldap_result( conn, op, 
194                                         LDAP_INSUFFICIENT_ACCESS,
195                                         NULL, NULL, NULL, NULL );
196                                 goto return_results;
197                         }
198                 }
199
200                 ldap_pvt_thread_mutex_lock(&li->li_root_mutex);
201                 rootlock = 1;
202         }
203
204         /* delete from dn2id mapping */
205         if ( dn2id_delete( be, &e->e_nname, e->e_id ) != 0 ) {
206 #ifdef NEW_LOGGING
207                 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
208                         "ldbm_back_delete: (%s) operations error\n",
209                         dn->bv_val ));
210 #else
211                 Debug(LDAP_DEBUG_ARGS,
212                         "<=- ldbm_back_delete: operations error %s\n",
213                         dn->bv_val, 0, 0);
214 #endif
215
216                 send_ldap_result( conn, op, LDAP_OTHER,
217                         NULL, "DN index delete failed", NULL, NULL );
218                 goto return_results;
219         }
220
221         /* delete from disk and cache */
222         if ( id2entry_delete( be, e ) != 0 ) {
223 #ifdef NEW_LOGGING
224                 LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
225                         "ldbm_back_delete: (%s) operations error\n",
226                         dn->bv_val ));
227 #else
228                 Debug(LDAP_DEBUG_ARGS,
229                         "<=- ldbm_back_delete: operations error %s\n",
230                         dn->bv_val, 0, 0);
231 #endif
232
233                 send_ldap_result( conn, op, LDAP_OTHER,
234                         NULL, "entry delete failed", NULL, NULL );
235                 goto return_results;
236         }
237
238         /* delete attribute indices */
239         (void) index_entry_del( be, e, e->e_attrs );
240
241         send_ldap_result( conn, op, LDAP_SUCCESS,
242                 NULL, NULL, NULL, NULL );
243         rc = 0;
244
245 return_results:;
246         if( p != NULL ) {
247                 /* free parent and writer lock */
248                 cache_return_entry_w( &li->li_cache, p );
249         }
250
251         if ( rootlock ) {
252                 /* release root lock */
253                 ldap_pvt_thread_mutex_unlock(&li->li_root_mutex);
254         }
255
256         /* free entry and writer lock */
257         cache_return_entry_w( &li->li_cache, e );
258
259         return rc;
260 }