2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1998-2004 The OpenLDAP Foundation.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted only as authorized by the OpenLDAP
11 * A copy of this license is available in the file LICENSE in the
12 * top-level directory of the distribution or, alternatively, at
13 * <http://www.OpenLDAP.org/license.html>.
15 /* Portions Copyright (c) 1995 Regents of the University of Michigan.
16 * All rights reserved.
18 * Redistribution and use in source and binary forms are permitted
19 * provided that this notice is preserved and that due credit is given
20 * to the University of Michigan at Ann Arbor. The name of the University
21 * may not be used to endorse or promote products derived from this
22 * software without specific prior written permission. This software
23 * is provided ``as is'' without express or implied warranty.
30 #include <ac/string.h>
31 #include <ac/socket.h>
39 #include "slapi/slapi.h"
47 struct berval dn = BER_BVNULL;
50 LDAP_LOG( OPERATION, ENTRY,
51 "do_delete: conn %d\n", op->o_connid, 0, 0 );
53 Debug( LDAP_DEBUG_TRACE, "do_delete\n", 0, 0, 0 );
57 * Parse the delete request. It looks like this:
59 * DelRequest := DistinguishedName
62 if ( ber_scanf( op->o_ber, "m", &dn ) == LBER_ERROR ) {
64 LDAP_LOG( OPERATION, ERR,
65 "do_delete: conn: %d ber_scanf failed\n", op->o_connid, 0, 0 );
67 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
69 send_ldap_discon( op, rs, LDAP_PROTOCOL_ERROR, "decoding error" );
70 return SLAPD_DISCONNECT;
73 if( get_ctrls( op, rs, 1 ) != LDAP_SUCCESS ) {
75 LDAP_LOG( OPERATION, ERR,
76 "do_delete: conn %d get_ctrls failed\n", op->o_connid, 0, 0 );
78 Debug( LDAP_DEBUG_ANY, "do_delete: get_ctrls failed\n", 0, 0, 0 );
83 rs->sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn,
85 if( rs->sr_err != LDAP_SUCCESS ) {
87 LDAP_LOG( OPERATION, INFO,
88 "do_delete: conn %d invalid dn (%s)\n",
89 op->o_connid, dn.bv_val, 0 );
91 Debug( LDAP_DEBUG_ANY,
92 "do_delete: invalid dn (%s)\n", dn.bv_val, 0, 0 );
94 send_ldap_error( op, rs, LDAP_INVALID_DN_SYNTAX, "invalid DN" );
98 if( op->o_req_ndn.bv_len == 0 ) {
100 LDAP_LOG( OPERATION, INFO,
101 "do_delete: conn %d: Attempt to delete root DSE.\n",
102 op->o_connid, 0, 0 );
104 Debug( LDAP_DEBUG_ANY, "do_delete: root dse!\n", 0, 0, 0 );
106 /* protocolError would likely be a more appropriate error */
107 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
108 "cannot delete the root DSE" );
111 } else if ( bvmatch( &op->o_req_ndn, &frontendDB->be_schemandn ) ) {
113 LDAP_LOG( OPERATION, INFO, "do_delete: conn %d: "
114 "Attempt to delete subschema subentry.\n", op->o_connid, 0, 0 );
116 Debug( LDAP_DEBUG_ANY, "do_delete: subschema subentry!\n", 0, 0, 0 );
118 /* protocolError would likely be a more appropriate error */
119 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
120 "cannot delete the root DSE" );
124 Statslog( LDAP_DEBUG_STATS, "conn=%lu op=%lu DEL dn=\"%s\"\n",
125 op->o_connid, op->o_opid, op->o_req_dn.bv_val, 0, 0 );
127 op->o_bd = frontendDB;
128 rs->sr_err = frontendDB->be_delete( op, rs );
131 slap_graduate_commit_csn( op );
133 op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
134 op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
139 fe_op_delete( Operation *op, SlapReply *rs )
141 struct berval pdn = BER_BVNULL;
144 manageDSAit = get_manageDSAit( op );
147 * We could be serving multiple database backends. Select the
148 * appropriate one, or send a referral to our "referral server"
149 * if we don't hold it.
151 op->o_bd = select_backend( &op->o_req_ndn, manageDSAit, 0 );
152 if ( op->o_bd == NULL ) {
153 rs->sr_ref = referral_rewrite( default_referral,
154 NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
156 if (!rs->sr_ref) rs->sr_ref = default_referral;
157 if ( rs->sr_ref != NULL ) {
158 rs->sr_err = LDAP_REFERRAL;
160 send_ldap_result( op, rs );
162 if (rs->sr_ref != default_referral) ber_bvarray_free( rs->sr_ref );
164 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
165 "no global superior knowledge" );
170 /* check restrictions */
171 if( backend_check_restrictions( op, rs, NULL ) != LDAP_SUCCESS ) {
172 send_ldap_result( op, rs );
176 /* check for referrals */
177 if( backend_check_referrals( op, rs ) != LDAP_SUCCESS ) {
181 #if defined( LDAP_SLAPI )
184 slapi_int_pblock_set_operation( pb, op );
185 slapi_pblock_set( pb, SLAPI_DELETE_TARGET, (void *)op->o_req_dn.bv_val );
186 slapi_pblock_set( pb, SLAPI_MANAGEDSAIT, (void *)manageDSAit );
188 rs->sr_err = slapi_int_call_plugins( op->o_bd,
189 SLAPI_PLUGIN_PRE_DELETE_FN, pb );
190 if ( rs->sr_err < 0 ) {
192 * A preoperation plugin failure will abort the
196 LDAP_LOG( OPERATION, INFO, "do_delete: "
197 "delete preoperation plugin failed\n", 0, 0, 0 );
199 Debug (LDAP_DEBUG_TRACE, "do_delete: "
200 "delete preoperation plugin failed.\n", 0, 0, 0);
202 if ( ( slapi_pblock_get( pb, SLAPI_RESULT_CODE,
203 (void *)&rs->sr_err ) != 0 ) ||
204 rs->sr_err == LDAP_SUCCESS )
206 rs->sr_err = LDAP_OTHER;
211 #endif /* defined( LDAP_SLAPI ) */
214 * do the delete if 1 && (2 || 3)
215 * 1) there is a delete function implemented in this backend;
216 * 2) this backend is master for what it holds;
217 * 3) it's a replica and the dn supplied is the update_ndn.
219 if ( op->o_bd->be_delete ) {
220 /* do the update here */
221 int repl_user = be_isupdate( op );
222 #ifndef SLAPD_MULTIMASTER
223 if ( !SLAP_SHADOW(op->o_bd) || repl_user )
226 struct berval org_req_dn = BER_BVNULL;
227 struct berval org_req_ndn = BER_BVNULL;
228 struct berval org_dn = BER_BVNULL;
229 struct berval org_ndn = BER_BVNULL;
231 slap_callback cb = { NULL, slap_replog_cb, NULL, NULL };
234 struct berval csn = { 0 , NULL };
235 char csnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];
236 slap_get_csn( op, csnbuf, sizeof(csnbuf), &csn, 1 );
239 #ifdef SLAPD_MULTIMASTER
240 if ( !op->o_bd->be_update_ndn.bv_len || !repl_user )
243 cb.sc_next = op->o_callback;
244 op->o_callback = &cb;
247 op->o_bd->be_delete( op, rs );
249 org_req_dn = op->o_req_dn;
250 org_req_ndn = op->o_req_ndn;
253 org_managedsait = get_manageDSAit( op );
254 op->o_dn = op->o_bd->be_rootdn;
255 op->o_ndn = op->o_bd->be_rootndn;
256 op->o_managedsait = 1;
258 while ( rs->sr_err == LDAP_SUCCESS &&
259 op->o_delete_glue_parent )
261 op->o_delete_glue_parent = 0;
262 if ( !be_issuffix( op->o_bd, &op->o_req_ndn )) {
263 slap_callback cb = { NULL };
264 cb.sc_response = slap_null_cb;
265 dnParent( &op->o_req_ndn, &pdn );
268 op->o_callback = &cb;
269 op->o_bd->be_delete( op, rs );
275 op->o_managedsait = org_managedsait;
278 op->o_req_dn = org_req_dn;
279 op->o_req_ndn = org_req_ndn;
280 op->o_delete_glue_parent = 0;
282 #ifndef SLAPD_MULTIMASTER
284 BerVarray defref = op->o_bd->be_update_refs
285 ? op->o_bd->be_update_refs : default_referral;
287 if ( defref != NULL ) {
288 rs->sr_ref = referral_rewrite( defref,
289 NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
290 if (!rs->sr_ref) rs->sr_ref = defref;
291 rs->sr_err = LDAP_REFERRAL;
292 send_ldap_result( op, rs );
294 if (rs->sr_ref != defref) ber_bvarray_free( rs->sr_ref );
297 send_ldap_error( op, rs,
298 LDAP_UNWILLING_TO_PERFORM,
299 "shadow context; no update referral" );
305 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
306 "operation not supported within namingContext" );
309 #if defined( LDAP_SLAPI )
310 if ( pb != NULL && slapi_int_call_plugins( op->o_bd,
311 SLAPI_PLUGIN_POST_DELETE_FN, pb ) < 0)
314 LDAP_LOG( OPERATION, INFO,
315 "do_delete: delete postoperation plugins failed\n",
318 Debug(LDAP_DEBUG_TRACE,
319 "do_delete: delete postoperation plugins failed\n",
323 #endif /* defined( LDAP_SLAPI ) */