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>
38 #include "slapi/slapi.h"
46 struct berval dn = BER_BVNULL;
48 Debug( LDAP_DEBUG_TRACE, "do_delete\n", 0, 0, 0 );
51 * Parse the delete request. It looks like this:
53 * DelRequest := DistinguishedName
56 if ( ber_scanf( op->o_ber, "m", &dn ) == LBER_ERROR ) {
57 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
58 send_ldap_discon( op, rs, LDAP_PROTOCOL_ERROR, "decoding error" );
59 return SLAPD_DISCONNECT;
62 if( get_ctrls( op, rs, 1 ) != LDAP_SUCCESS ) {
63 Debug( LDAP_DEBUG_ANY, "do_delete: get_ctrls failed\n", 0, 0, 0 );
67 rs->sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn,
69 if( rs->sr_err != LDAP_SUCCESS ) {
70 Debug( LDAP_DEBUG_ANY,
71 "do_delete: invalid dn (%s)\n", dn.bv_val, 0, 0 );
72 send_ldap_error( op, rs, LDAP_INVALID_DN_SYNTAX, "invalid DN" );
76 if( op->o_req_ndn.bv_len == 0 ) {
77 Debug( LDAP_DEBUG_ANY, "do_delete: root dse!\n", 0, 0, 0 );
78 /* protocolError would likely be a more appropriate error */
79 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
80 "cannot delete the root DSE" );
83 } else if ( bvmatch( &op->o_req_ndn, &frontendDB->be_schemandn ) ) {
84 Debug( LDAP_DEBUG_ANY, "do_delete: subschema subentry!\n", 0, 0, 0 );
85 /* protocolError would likely be a more appropriate error */
86 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
87 "cannot delete the root DSE" );
91 Statslog( LDAP_DEBUG_STATS, "%s DEL dn=\"%s\"\n",
92 op->o_log_prefix, op->o_req_dn.bv_val, 0, 0, 0 );
94 op->o_bd = frontendDB;
95 rs->sr_err = frontendDB->be_delete( op, rs );
98 slap_graduate_commit_csn( op );
100 op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
101 op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
106 fe_op_delete( Operation *op, SlapReply *rs )
108 struct berval pdn = BER_BVNULL;
111 manageDSAit = get_manageDSAit( op );
114 * We could be serving multiple database backends. Select the
115 * appropriate one, or send a referral to our "referral server"
116 * if we don't hold it.
118 op->o_bd = select_backend( &op->o_req_ndn, manageDSAit, 0 );
119 if ( op->o_bd == NULL ) {
120 rs->sr_ref = referral_rewrite( default_referral,
121 NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
123 if (!rs->sr_ref) rs->sr_ref = default_referral;
124 if ( rs->sr_ref != NULL ) {
125 rs->sr_err = LDAP_REFERRAL;
127 send_ldap_result( op, rs );
129 if (rs->sr_ref != default_referral) ber_bvarray_free( rs->sr_ref );
131 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
132 "no global superior knowledge" );
137 /* check restrictions */
138 if( backend_check_restrictions( op, rs, NULL ) != LDAP_SUCCESS ) {
139 send_ldap_result( op, rs );
143 /* check for referrals */
144 if( backend_check_referrals( op, rs ) != LDAP_SUCCESS ) {
148 #if defined( LDAP_SLAPI )
151 slapi_int_pblock_set_operation( pb, op );
152 slapi_pblock_set( pb, SLAPI_DELETE_TARGET, (void *)op->o_req_dn.bv_val );
153 slapi_pblock_set( pb, SLAPI_MANAGEDSAIT, (void *)manageDSAit );
155 rs->sr_err = slapi_int_call_plugins( op->o_bd,
156 SLAPI_PLUGIN_PRE_DELETE_FN, pb );
157 if ( rs->sr_err < 0 ) {
159 * A preoperation plugin failure will abort the
162 Debug (LDAP_DEBUG_TRACE, "do_delete: "
163 "delete preoperation plugin failed.\n", 0, 0, 0);
164 if ( ( slapi_pblock_get( pb, SLAPI_RESULT_CODE,
165 (void *)&rs->sr_err ) != 0 ) ||
166 rs->sr_err == LDAP_SUCCESS )
168 rs->sr_err = LDAP_OTHER;
173 #endif /* defined( LDAP_SLAPI ) */
176 * do the delete if 1 && (2 || 3)
177 * 1) there is a delete function implemented in this backend;
178 * 2) this backend is master for what it holds;
179 * 3) it's a replica and the dn supplied is the update_ndn.
181 if ( op->o_bd->be_delete ) {
182 /* do the update here */
183 int repl_user = be_isupdate( op );
184 #ifndef SLAPD_MULTIMASTER
185 if ( !SLAP_SHADOW(op->o_bd) || repl_user )
188 struct berval org_req_dn = BER_BVNULL;
189 struct berval org_req_ndn = BER_BVNULL;
190 struct berval org_dn = BER_BVNULL;
191 struct berval org_ndn = BER_BVNULL;
193 slap_callback cb = { NULL, slap_replog_cb, NULL, NULL };
196 struct berval csn = BER_BVNULL;
197 char csnbuf[LDAP_LUTIL_CSNSTR_BUFSIZE];
198 slap_get_csn( op, csnbuf, sizeof(csnbuf), &csn, 1 );
201 #ifdef SLAPD_MULTIMASTER
202 if ( !op->o_bd->be_update_ndn.bv_len || !repl_user )
205 cb.sc_next = op->o_callback;
206 op->o_callback = &cb;
209 op->o_bd->be_delete( op, rs );
211 org_req_dn = op->o_req_dn;
212 org_req_ndn = op->o_req_ndn;
215 org_managedsait = get_manageDSAit( op );
216 op->o_dn = op->o_bd->be_rootdn;
217 op->o_ndn = op->o_bd->be_rootndn;
218 op->o_managedsait = 1;
220 while ( rs->sr_err == LDAP_SUCCESS &&
221 op->o_delete_glue_parent )
223 op->o_delete_glue_parent = 0;
224 if ( !be_issuffix( op->o_bd, &op->o_req_ndn )) {
225 slap_callback cb = { NULL };
226 cb.sc_response = slap_null_cb;
227 dnParent( &op->o_req_ndn, &pdn );
230 op->o_callback = &cb;
231 op->o_bd->be_delete( op, rs );
237 op->o_managedsait = org_managedsait;
240 op->o_req_dn = org_req_dn;
241 op->o_req_ndn = org_req_ndn;
242 op->o_delete_glue_parent = 0;
244 #ifndef SLAPD_MULTIMASTER
246 BerVarray defref = op->o_bd->be_update_refs
247 ? op->o_bd->be_update_refs : default_referral;
249 if ( defref != NULL ) {
250 rs->sr_ref = referral_rewrite( defref,
251 NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
252 if (!rs->sr_ref) rs->sr_ref = defref;
253 rs->sr_err = LDAP_REFERRAL;
254 send_ldap_result( op, rs );
256 if (rs->sr_ref != defref) ber_bvarray_free( rs->sr_ref );
259 send_ldap_error( op, rs,
260 LDAP_UNWILLING_TO_PERFORM,
261 "shadow context; no update referral" );
267 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
268 "operation not supported within namingContext" );
271 #if defined( LDAP_SLAPI )
272 if ( pb != NULL && slapi_int_call_plugins( op->o_bd,
273 SLAPI_PLUGIN_POST_DELETE_FN, pb ) < 0)
275 Debug(LDAP_DEBUG_TRACE,
276 "do_delete: delete postoperation plugins failed\n",
279 #endif /* defined( LDAP_SLAPI ) */