]> git.sur5r.net Git - openldap/blob - servers/slapd/delete.c
s/forms/form in PADL copyright
[openldap] / servers / slapd / delete.c
1 /* $OpenLDAP$ */
2 /*
3  * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
4  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
5  */
6 /*
7  * Copyright (c) 1995 Regents of the University of Michigan.
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms are permitted
11  * provided that this notice is preserved and that due credit is given
12  * to the University of Michigan at Ann Arbor. The name of the University
13  * may not be used to endorse or promote products derived from this
14  * software without specific prior written permission. This software
15  * is provided ``as is'' without express or implied warranty.
16  */
17
18 #include "portable.h"
19
20 #include <stdio.h>
21
22 #include <ac/string.h>
23 #include <ac/socket.h>
24
25 #include "ldap_pvt.h"
26 #include "slap.h"
27
28 #ifdef LDAP_SLAPI
29 #include "slapi.h"
30 #endif
31
32 int
33 do_delete(
34     Operation   *op,
35     SlapReply   *rs
36 )
37 {
38         struct berval dn = { 0, NULL };
39         int manageDSAit;
40
41 #ifdef LDAP_SLAPI
42         Slapi_PBlock *pb = op->o_pb;
43 #endif
44
45 #ifdef NEW_LOGGING
46         LDAP_LOG( OPERATION, ENTRY, 
47                 "do_delete: conn %d\n", op->o_connid, 0, 0 );
48 #else
49         Debug( LDAP_DEBUG_TRACE, "do_delete\n", 0, 0, 0 );
50 #endif
51
52         /*
53          * Parse the delete request.  It looks like this:
54          *
55          *      DelRequest := DistinguishedName
56          */
57
58         if ( ber_scanf( op->o_ber, "m", &dn ) == LBER_ERROR ) {
59 #ifdef NEW_LOGGING
60                 LDAP_LOG( OPERATION, ERR, 
61                         "do_delete: conn: %d  ber_scanf failed\n", op->o_connid, 0, 0 );
62 #else
63                 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
64 #endif
65                 send_ldap_discon( op, rs, LDAP_PROTOCOL_ERROR, "decoding error" );
66                 return SLAPD_DISCONNECT;
67         }
68
69         if( get_ctrls( op, rs, 1 ) != LDAP_SUCCESS ) {
70 #ifdef NEW_LOGGING
71                 LDAP_LOG( OPERATION, ERR, 
72                         "do_delete: conn %d  get_ctrls failed\n", op->o_connid, 0, 0 );
73 #else
74                 Debug( LDAP_DEBUG_ANY, "do_delete: get_ctrls failed\n", 0, 0, 0 );
75 #endif
76                 goto cleanup;
77         } 
78
79         rs->sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn, op->o_tmpmemctx );
80         if( rs->sr_err != LDAP_SUCCESS ) {
81 #ifdef NEW_LOGGING
82                 LDAP_LOG( OPERATION, INFO, 
83                         "do_delete: conn %d  invalid dn (%s)\n",
84                         op->o_connid, dn.bv_val, 0 );
85 #else
86                 Debug( LDAP_DEBUG_ANY,
87                         "do_delete: invalid dn (%s)\n", dn.bv_val, 0, 0 );
88 #endif
89                 send_ldap_error( op, rs, LDAP_INVALID_DN_SYNTAX, "invalid DN" );
90                 goto cleanup;
91         }
92
93         if( op->o_req_ndn.bv_len == 0 ) {
94 #ifdef NEW_LOGGING
95                 LDAP_LOG( OPERATION, INFO, 
96                         "do_delete: conn %d: Attempt to delete root DSE.\n", 
97                         op->o_connid, 0, 0 );
98 #else
99                 Debug( LDAP_DEBUG_ANY, "do_delete: root dse!\n", 0, 0, 0 );
100 #endif
101                 /* protocolError would likely be a more appropriate error */
102                 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
103                         "cannot delete the root DSE" );
104                 goto cleanup;
105
106         } else if ( bvmatch( &op->o_req_ndn, &global_schemandn ) ) {
107 #ifdef NEW_LOGGING
108                 LDAP_LOG( OPERATION, INFO, "do_delete: conn %d: "
109                         "Attempt to delete subschema subentry.\n", op->o_connid, 0, 0 );
110 #else
111                 Debug( LDAP_DEBUG_ANY, "do_delete: subschema subentry!\n", 0, 0, 0 );
112 #endif
113                 /* protocolError would likely be a more appropriate error */
114                 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
115                         "cannot delete the root DSE" );
116                 goto cleanup;
117         }
118
119         Statslog( LDAP_DEBUG_STATS, "conn=%lu op=%lu DEL dn=\"%s\"\n",
120                 op->o_connid, op->o_opid, op->o_req_dn.bv_val, 0, 0 );
121
122         manageDSAit = get_manageDSAit( op );
123
124         /*
125          * We could be serving multiple database backends.  Select the
126          * appropriate one, or send a referral to our "referral server"
127          * if we don't hold it.
128          */
129         if ( (op->o_bd = select_backend( &op->o_req_ndn, manageDSAit, 0 )) == NULL ) {
130                 rs->sr_ref = referral_rewrite( default_referral,
131                         NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
132
133                 if (!rs->sr_ref) rs->sr_ref = default_referral;
134                 if ( rs->sr_ref != NULL ) {
135                         rs->sr_err = LDAP_REFERRAL;
136
137                         send_ldap_result( op, rs );
138
139                         if (rs->sr_ref != default_referral) ber_bvarray_free( rs->sr_ref );
140                 } else {
141                         send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
142                                         "referral missing" );
143                 }
144                 goto cleanup;
145         }
146
147         /* check restrictions */
148         if( backend_check_restrictions( op, rs, NULL ) != LDAP_SUCCESS ) {
149                 send_ldap_result( op, rs );
150                 goto cleanup;
151         }
152
153         /* check for referrals */
154         if( backend_check_referrals( op, rs ) != LDAP_SUCCESS ) {
155                 goto cleanup;
156         }
157
158 #if defined( LDAP_SLAPI )
159         slapi_x_pblock_set_operation( pb, op );
160         slapi_pblock_set( pb, SLAPI_DELETE_TARGET, (void *)dn.bv_val );
161         slapi_pblock_set( pb, SLAPI_MANAGEDSAIT, (void *)manageDSAit );
162
163         rs->sr_err = doPluginFNs( op->o_bd, SLAPI_PLUGIN_PRE_DELETE_FN, pb );
164         if ( rs->sr_err < 0 ) {
165                 /*
166                  * A preoperation plugin failure will abort the
167                  * entire operation.
168                  */
169 #ifdef NEW_LOGGING
170                 LDAP_LOG( OPERATION, INFO, "do_delete: delete preoperation plugin "
171                                 "failed\n", 0, 0, 0 );
172 #else
173                 Debug (LDAP_DEBUG_TRACE, "do_delete: delete preoperation plugin failed.\n",
174                                 0, 0, 0);
175 #endif
176                 if ( ( slapi_pblock_get( op->o_pb, SLAPI_RESULT_CODE, (void *)&rs->sr_err ) != 0 )  ||
177                      rs->sr_err == LDAP_SUCCESS ) {
178                         rs->sr_err = LDAP_OTHER;
179                 }
180                 goto cleanup;
181         }
182 #endif /* defined( LDAP_SLAPI ) */
183
184         /*
185          * do the delete if 1 && (2 || 3)
186          * 1) there is a delete function implemented in this backend;
187          * 2) this backend is master for what it holds;
188          * 3) it's a replica and the dn supplied is the update_ndn.
189          */
190         if ( op->o_bd->be_delete ) {
191                 /* do the update here */
192                 int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
193 #if defined(LDAP_SYNCREPL) && !defined(SLAPD_MULTIMASTER)
194                 if ( !op->o_bd->syncinfo && ( !op->o_bd->be_update_ndn.bv_len || repl_user ))
195 #elif defined(LDAP_SYNCREPL) && defined(SLAPD_MULTIMASTER)
196                 if ( !op->o_bd->syncinfo )  /* LDAP_SYNCREPL overrides MM */
197 #elif !defined(LDAP_SYNCREPL) && !defined(SLAPD_MULTIMASTER)
198                 if ( !op->o_bd->be_update_ndn.bv_len || repl_user )
199 #endif
200                 {
201                         if ( (op->o_bd->be_delete)( op, rs ) == 0 ) {
202 #ifdef SLAPD_MULTIMASTER
203                                 if ( !op->o_bd->be_update_ndn.bv_len || !repl_user )
204 #endif
205                                 {
206                                         replog( op );
207                                 }
208                         }
209 #if defined(LDAP_SYNCREPL) || !defined(SLAPD_MULTIMASTER)
210                 } else {
211                         BerVarray defref = NULL;
212 #ifdef LDAP_SYNCREPL
213                         if ( op->o_bd->syncinfo ) {
214                                 defref = op->o_bd->syncinfo->master_bv;
215                         } else
216 #endif
217                         {
218                                 defref = op->o_bd->be_update_refs
219                                                 ? op->o_bd->be_update_refs : default_referral;
220                         }
221                         if ( defref != NULL ) {
222                                 rs->sr_ref = referral_rewrite( defref,
223                                         NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
224                                 if (!rs->sr_ref) rs->sr_ref = defref;
225                                 rs->sr_err = LDAP_REFERRAL;
226                                 send_ldap_result( op, rs );
227
228                                 if (rs->sr_ref != defref) ber_bvarray_free( rs->sr_ref );
229                         } else {
230                                 send_ldap_error( op, rs,
231                                                 LDAP_UNWILLING_TO_PERFORM,
232                                                 "referral missing" );
233                         }
234 #endif
235                 }
236
237         } else {
238                 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
239                         "operation not supported within namingContext" );
240         }
241
242 #if defined( LDAP_SLAPI )
243         if ( doPluginFNs( op->o_bd, SLAPI_PLUGIN_POST_DELETE_FN, pb ) < 0) {
244 #ifdef NEW_LOGGING
245                 LDAP_LOG( OPERATION, INFO, "do_delete: delete postoperation plugins "
246                                 "failed\n", 0, 0, 0 );
247 #else
248                 Debug(LDAP_DEBUG_TRACE, "do_delete: delete postoperation plugins "
249                                 "failed.\n", 0, 0, 0);
250 #endif
251         }
252 #endif /* defined( LDAP_SLAPI ) */
253
254 cleanup:
255         op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
256         op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
257         return rs->sr_err;
258 }