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;
49 Debug( LDAP_DEBUG_TRACE, "do_delete\n", 0, 0, 0 );
52 * Parse the delete request. It looks like this:
54 * DelRequest := DistinguishedName
57 if ( ber_scanf( op->o_ber, "m", &dn ) == LBER_ERROR ) {
58 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
59 send_ldap_discon( op, rs, LDAP_PROTOCOL_ERROR, "decoding error" );
60 return SLAPD_DISCONNECT;
63 if( get_ctrls( op, rs, 1 ) != LDAP_SUCCESS ) {
64 Debug( LDAP_DEBUG_ANY, "do_delete: get_ctrls failed\n", 0, 0, 0 );
68 rs->sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn,
70 if( rs->sr_err != LDAP_SUCCESS ) {
71 Debug( LDAP_DEBUG_ANY,
72 "do_delete: invalid dn (%s)\n", dn.bv_val, 0, 0 );
73 send_ldap_error( op, rs, LDAP_INVALID_DN_SYNTAX, "invalid DN" );
77 if( op->o_req_ndn.bv_len == 0 ) {
78 Debug( LDAP_DEBUG_ANY, "do_delete: root dse!\n", 0, 0, 0 );
79 /* protocolError would likely be a more appropriate error */
80 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
81 "cannot delete the root DSE" );
84 } else if ( bvmatch( &op->o_req_ndn, &frontendDB->be_schemandn ) ) {
85 Debug( LDAP_DEBUG_ANY, "do_delete: subschema subentry!\n", 0, 0, 0 );
86 /* protocolError would likely be a more appropriate error */
87 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
88 "cannot delete the root DSE" );
92 Statslog( LDAP_DEBUG_STATS, "conn=%lu op=%lu DEL dn=\"%s\"\n",
93 op->o_connid, op->o_opid, op->o_req_dn.bv_val, 0, 0 );
95 op->o_bd = frontendDB;
96 rs->sr_err = frontendDB->be_delete( op, rs );
99 slap_graduate_commit_csn( op );
101 op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
102 op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
107 fe_op_delete( Operation *op, SlapReply *rs )
109 struct berval pdn = BER_BVNULL;
112 manageDSAit = get_manageDSAit( op );
115 * We could be serving multiple database backends. Select the
116 * appropriate one, or send a referral to our "referral server"
117 * if we don't hold it.
119 op->o_bd = select_backend( &op->o_req_ndn, manageDSAit, 0 );
120 if ( op->o_bd == NULL ) {
121 rs->sr_ref = referral_rewrite( default_referral,
122 NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
124 if (!rs->sr_ref) rs->sr_ref = default_referral;
125 if ( rs->sr_ref != NULL ) {
126 rs->sr_err = LDAP_REFERRAL;
128 send_ldap_result( op, rs );
130 if (rs->sr_ref != default_referral) ber_bvarray_free( rs->sr_ref );
132 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
133 "no global superior knowledge" );
138 /* check restrictions */
139 if( backend_check_restrictions( op, rs, NULL ) != LDAP_SUCCESS ) {
140 send_ldap_result( op, rs );
144 /* check for referrals */
145 if( backend_check_referrals( op, rs ) != LDAP_SUCCESS ) {
149 #if defined( LDAP_SLAPI )
152 slapi_int_pblock_set_operation( pb, op );
153 slapi_pblock_set( pb, SLAPI_DELETE_TARGET, (void *)op->o_req_dn.bv_val );
154 slapi_pblock_set( pb, SLAPI_MANAGEDSAIT, (void *)manageDSAit );
156 rs->sr_err = slapi_int_call_plugins( op->o_bd,
157 SLAPI_PLUGIN_PRE_DELETE_FN, pb );
158 if ( rs->sr_err < 0 ) {
160 * A preoperation plugin failure will abort the
163 Debug (LDAP_DEBUG_TRACE, "do_delete: "
164 "delete preoperation plugin failed.\n", 0, 0, 0);
165 if ( ( slapi_pblock_get( pb, SLAPI_RESULT_CODE,
166 (void *)&rs->sr_err ) != 0 ) ||
167 rs->sr_err == LDAP_SUCCESS )
169 rs->sr_err = LDAP_OTHER;
174 #endif /* defined( LDAP_SLAPI ) */
177 * do the delete if 1 && (2 || 3)
178 * 1) there is a delete function implemented in this backend;
179 * 2) this backend is master for what it holds;
180 * 3) it's a replica and the dn supplied is the update_ndn.
182 if ( op->o_bd->be_delete ) {
183 /* do the update here */
184 int repl_user = be_isupdate( op );
185 #ifndef SLAPD_MULTIMASTER
186 if ( !SLAP_SHADOW(op->o_bd) || repl_user )
189 struct berval org_req_dn = BER_BVNULL;
190 struct berval org_req_ndn = BER_BVNULL;
191 struct berval org_dn = BER_BVNULL;
192 struct berval org_ndn = BER_BVNULL;
194 slap_callback cb = { NULL, slap_replog_cb, NULL, NULL };
197 struct berval csn = BER_BVNULL;
198 char csnbuf[LDAP_LUTIL_CSNSTR_BUFSIZE];
199 slap_get_csn( op, csnbuf, sizeof(csnbuf), &csn, 1 );
202 #ifdef SLAPD_MULTIMASTER
203 if ( !op->o_bd->be_update_ndn.bv_len || !repl_user )
206 cb.sc_next = op->o_callback;
207 op->o_callback = &cb;
210 op->o_bd->be_delete( op, rs );
212 org_req_dn = op->o_req_dn;
213 org_req_ndn = op->o_req_ndn;
216 org_managedsait = get_manageDSAit( op );
217 op->o_dn = op->o_bd->be_rootdn;
218 op->o_ndn = op->o_bd->be_rootndn;
219 op->o_managedsait = 1;
221 while ( rs->sr_err == LDAP_SUCCESS &&
222 op->o_delete_glue_parent )
224 op->o_delete_glue_parent = 0;
225 if ( !be_issuffix( op->o_bd, &op->o_req_ndn )) {
226 slap_callback cb = { NULL };
227 cb.sc_response = slap_null_cb;
228 dnParent( &op->o_req_ndn, &pdn );
231 op->o_callback = &cb;
232 op->o_bd->be_delete( op, rs );
238 op->o_managedsait = org_managedsait;
241 op->o_req_dn = org_req_dn;
242 op->o_req_ndn = org_req_ndn;
243 op->o_delete_glue_parent = 0;
245 #ifndef SLAPD_MULTIMASTER
247 BerVarray defref = op->o_bd->be_update_refs
248 ? op->o_bd->be_update_refs : default_referral;
250 if ( defref != NULL ) {
251 rs->sr_ref = referral_rewrite( defref,
252 NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
253 if (!rs->sr_ref) rs->sr_ref = defref;
254 rs->sr_err = LDAP_REFERRAL;
255 send_ldap_result( op, rs );
257 if (rs->sr_ref != defref) ber_bvarray_free( rs->sr_ref );
260 send_ldap_error( op, rs,
261 LDAP_UNWILLING_TO_PERFORM,
262 "shadow context; no update referral" );
268 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
269 "operation not supported within namingContext" );
272 #if defined( LDAP_SLAPI )
273 if ( pb != NULL && slapi_int_call_plugins( op->o_bd,
274 SLAPI_PLUGIN_POST_DELETE_FN, pb ) < 0)
276 Debug(LDAP_DEBUG_TRACE,
277 "do_delete: delete postoperation plugins failed\n",
280 #endif /* defined( LDAP_SLAPI ) */