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"
48 struct berval dn = BER_BVNULL;
49 struct berval pdn = BER_BVNULL;
50 struct berval org_req_dn = BER_BVNULL;
51 struct berval org_req_ndn = BER_BVNULL;
52 struct berval org_dn = BER_BVNULL;
53 struct berval org_ndn = BER_BVNULL;
58 LDAP_LOG( OPERATION, ENTRY,
59 "do_delete: conn %d\n", op->o_connid, 0, 0 );
61 Debug( LDAP_DEBUG_TRACE, "do_delete\n", 0, 0, 0 );
65 * Parse the delete request. It looks like this:
67 * DelRequest := DistinguishedName
70 if ( ber_scanf( op->o_ber, "m", &dn ) == LBER_ERROR ) {
72 LDAP_LOG( OPERATION, ERR,
73 "do_delete: conn: %d ber_scanf failed\n", op->o_connid, 0, 0 );
75 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
77 send_ldap_discon( op, rs, LDAP_PROTOCOL_ERROR, "decoding error" );
78 return SLAPD_DISCONNECT;
81 if( get_ctrls( op, rs, 1 ) != LDAP_SUCCESS ) {
83 LDAP_LOG( OPERATION, ERR,
84 "do_delete: conn %d get_ctrls failed\n", op->o_connid, 0, 0 );
86 Debug( LDAP_DEBUG_ANY, "do_delete: get_ctrls failed\n", 0, 0, 0 );
91 rs->sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn, op->o_tmpmemctx );
92 if( rs->sr_err != LDAP_SUCCESS ) {
94 LDAP_LOG( OPERATION, INFO,
95 "do_delete: conn %d invalid dn (%s)\n",
96 op->o_connid, dn.bv_val, 0 );
98 Debug( LDAP_DEBUG_ANY,
99 "do_delete: invalid dn (%s)\n", dn.bv_val, 0, 0 );
101 send_ldap_error( op, rs, LDAP_INVALID_DN_SYNTAX, "invalid DN" );
105 if( op->o_req_ndn.bv_len == 0 ) {
107 LDAP_LOG( OPERATION, INFO,
108 "do_delete: conn %d: Attempt to delete root DSE.\n",
109 op->o_connid, 0, 0 );
111 Debug( LDAP_DEBUG_ANY, "do_delete: root dse!\n", 0, 0, 0 );
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" );
118 } else if ( bvmatch( &op->o_req_ndn, &global_schemandn ) ) {
120 LDAP_LOG( OPERATION, INFO, "do_delete: conn %d: "
121 "Attempt to delete subschema subentry.\n", op->o_connid, 0, 0 );
123 Debug( LDAP_DEBUG_ANY, "do_delete: subschema subentry!\n", 0, 0, 0 );
125 /* protocolError would likely be a more appropriate error */
126 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
127 "cannot delete the root DSE" );
131 Statslog( LDAP_DEBUG_STATS, "conn=%lu op=%lu DEL dn=\"%s\"\n",
132 op->o_connid, op->o_opid, op->o_req_dn.bv_val, 0, 0 );
134 manageDSAit = get_manageDSAit( op );
137 * We could be serving multiple database backends. Select the
138 * appropriate one, or send a referral to our "referral server"
139 * if we don't hold it.
141 op->o_bd = select_backend( &op->o_req_ndn, manageDSAit, 0 );
142 if ( op->o_bd == NULL ) {
143 rs->sr_ref = referral_rewrite( default_referral,
144 NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
146 if (!rs->sr_ref) rs->sr_ref = default_referral;
147 if ( rs->sr_ref != NULL ) {
148 rs->sr_err = LDAP_REFERRAL;
150 send_ldap_result( op, rs );
152 if (rs->sr_ref != default_referral) ber_bvarray_free( rs->sr_ref );
154 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
155 "no global superior knowledge" );
160 /* check restrictions */
161 if( backend_check_restrictions( op, rs, NULL ) != LDAP_SUCCESS ) {
162 send_ldap_result( op, rs );
166 /* check for referrals */
167 if( backend_check_referrals( op, rs ) != LDAP_SUCCESS ) {
171 #if defined( LDAP_SLAPI )
174 slapi_int_pblock_set_operation( pb, op );
175 slapi_pblock_set( pb, SLAPI_DELETE_TARGET, (void *)dn.bv_val );
176 slapi_pblock_set( pb, SLAPI_MANAGEDSAIT, (void *)manageDSAit );
178 rs->sr_err = slapi_int_call_plugins( op->o_bd, SLAPI_PLUGIN_PRE_DELETE_FN, pb );
179 if ( rs->sr_err < 0 ) {
181 * A preoperation plugin failure will abort the
185 LDAP_LOG( OPERATION, INFO, "do_delete: delete preoperation plugin "
186 "failed\n", 0, 0, 0 );
188 Debug (LDAP_DEBUG_TRACE, "do_delete: delete preoperation plugin failed.\n",
191 if ( ( slapi_pblock_get( pb, SLAPI_RESULT_CODE, (void *)&rs->sr_err ) != 0 ) ||
192 rs->sr_err == LDAP_SUCCESS ) {
193 rs->sr_err = LDAP_OTHER;
198 #endif /* defined( LDAP_SLAPI ) */
201 * do the delete if 1 && (2 || 3)
202 * 1) there is a delete function implemented in this backend;
203 * 2) this backend is master for what it holds;
204 * 3) it's a replica and the dn supplied is the update_ndn.
206 if ( op->o_bd->be_delete ) {
207 /* do the update here */
208 int repl_user = be_isupdate( op );
209 #ifndef SLAPD_MULTIMASTER
210 if ( !SLAP_SHADOW(op->o_bd) || repl_user )
213 slap_callback cb = { NULL, slap_replog_cb, NULL, NULL };
216 struct berval csn = { 0 , NULL };
217 char csnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];
218 slap_get_csn( op, csnbuf, sizeof(csnbuf), &csn, 1 );
221 #ifdef SLAPD_MULTIMASTER
222 if ( !op->o_bd->be_update_ndn.bv_len || !repl_user )
225 cb.sc_next = op->o_callback;
226 op->o_callback = &cb;
229 op->o_bd->be_delete( op, rs );
231 org_req_dn = op->o_req_dn;
232 org_req_ndn = op->o_req_ndn;
235 org_managedsait = get_manageDSAit( op );
236 op->o_dn = op->o_bd->be_rootdn;
237 op->o_ndn = op->o_bd->be_rootndn;
238 op->o_managedsait = 1;
240 while ( rs->sr_err == LDAP_SUCCESS &&
241 op->o_delete_glue_parent )
243 op->o_delete_glue_parent = 0;
244 if ( !be_issuffix( op->o_bd, &op->o_req_ndn )) {
245 slap_callback cb = { NULL };
246 cb.sc_response = slap_null_cb;
247 dnParent( &op->o_req_ndn, &pdn );
250 op->o_callback = &cb;
251 op->o_bd->be_delete( op, rs );
257 op->o_managedsait = org_managedsait;
260 op->o_req_dn = org_req_dn;
261 op->o_req_ndn = org_req_ndn;
262 op->o_delete_glue_parent = 0;
264 #ifndef SLAPD_MULTIMASTER
266 BerVarray defref = op->o_bd->be_update_refs
267 ? op->o_bd->be_update_refs : default_referral;
269 if ( defref != NULL ) {
270 rs->sr_ref = referral_rewrite( defref,
271 NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
272 if (!rs->sr_ref) rs->sr_ref = defref;
273 rs->sr_err = LDAP_REFERRAL;
274 send_ldap_result( op, rs );
276 if (rs->sr_ref != defref) ber_bvarray_free( rs->sr_ref );
279 send_ldap_error( op, rs,
280 LDAP_UNWILLING_TO_PERFORM,
281 "shadow context; no update referral" );
287 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
288 "operation not supported within namingContext" );
291 #if defined( LDAP_SLAPI )
292 if ( pb != NULL && slapi_int_call_plugins( op->o_bd, SLAPI_PLUGIN_POST_DELETE_FN, pb ) < 0) {
294 LDAP_LOG( OPERATION, INFO, "do_delete: delete postoperation plugins "
295 "failed\n", 0, 0, 0 );
297 Debug(LDAP_DEBUG_TRACE, "do_delete: delete postoperation plugins "
298 "failed.\n", 0, 0, 0);
301 #endif /* defined( LDAP_SLAPI ) */
305 slap_graduate_commit_csn( op );
307 op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
308 op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );