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 = { 0, NULL };
52 LDAP_LOG( OPERATION, ENTRY,
53 "do_delete: conn %d\n", op->o_connid, 0, 0 );
55 Debug( LDAP_DEBUG_TRACE, "do_delete\n", 0, 0, 0 );
59 * Parse the delete request. It looks like this:
61 * DelRequest := DistinguishedName
64 if ( ber_scanf( op->o_ber, "m", &dn ) == LBER_ERROR ) {
66 LDAP_LOG( OPERATION, ERR,
67 "do_delete: conn: %d ber_scanf failed\n", op->o_connid, 0, 0 );
69 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
71 send_ldap_discon( op, rs, LDAP_PROTOCOL_ERROR, "decoding error" );
72 return SLAPD_DISCONNECT;
75 if( get_ctrls( op, rs, 1 ) != LDAP_SUCCESS ) {
77 LDAP_LOG( OPERATION, ERR,
78 "do_delete: conn %d get_ctrls failed\n", op->o_connid, 0, 0 );
80 Debug( LDAP_DEBUG_ANY, "do_delete: get_ctrls failed\n", 0, 0, 0 );
85 rs->sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn, op->o_tmpmemctx );
86 if( rs->sr_err != LDAP_SUCCESS ) {
88 LDAP_LOG( OPERATION, INFO,
89 "do_delete: conn %d invalid dn (%s)\n",
90 op->o_connid, dn.bv_val, 0 );
92 Debug( LDAP_DEBUG_ANY,
93 "do_delete: invalid dn (%s)\n", dn.bv_val, 0, 0 );
95 send_ldap_error( op, rs, LDAP_INVALID_DN_SYNTAX, "invalid DN" );
99 if( op->o_req_ndn.bv_len == 0 ) {
101 LDAP_LOG( OPERATION, INFO,
102 "do_delete: conn %d: Attempt to delete root DSE.\n",
103 op->o_connid, 0, 0 );
105 Debug( LDAP_DEBUG_ANY, "do_delete: root dse!\n", 0, 0, 0 );
107 /* protocolError would likely be a more appropriate error */
108 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
109 "cannot delete the root DSE" );
112 } else if ( bvmatch( &op->o_req_ndn, &global_schemandn ) ) {
114 LDAP_LOG( OPERATION, INFO, "do_delete: conn %d: "
115 "Attempt to delete subschema subentry.\n", op->o_connid, 0, 0 );
117 Debug( LDAP_DEBUG_ANY, "do_delete: subschema subentry!\n", 0, 0, 0 );
119 /* protocolError would likely be a more appropriate error */
120 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
121 "cannot delete the root DSE" );
125 Statslog( LDAP_DEBUG_STATS, "conn=%lu op=%lu DEL dn=\"%s\"\n",
126 op->o_connid, op->o_opid, op->o_req_dn.bv_val, 0, 0 );
128 manageDSAit = get_manageDSAit( op );
131 * We could be serving multiple database backends. Select the
132 * appropriate one, or send a referral to our "referral server"
133 * if we don't hold it.
135 if ( (op->o_bd = select_backend( &op->o_req_ndn, manageDSAit, 0 )) == NULL ) {
136 rs->sr_ref = referral_rewrite( default_referral,
137 NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
139 if (!rs->sr_ref) rs->sr_ref = default_referral;
140 if ( rs->sr_ref != NULL ) {
141 rs->sr_err = LDAP_REFERRAL;
143 send_ldap_result( op, rs );
145 if (rs->sr_ref != default_referral) ber_bvarray_free( rs->sr_ref );
147 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
148 "referral missing" );
153 /* check restrictions */
154 if( backend_check_restrictions( op, rs, NULL ) != LDAP_SUCCESS ) {
155 send_ldap_result( op, rs );
159 /* check for referrals */
160 if( backend_check_referrals( op, rs ) != LDAP_SUCCESS ) {
164 #if defined( LDAP_SLAPI )
167 slapi_int_pblock_set_operation( pb, op );
168 slapi_pblock_set( pb, SLAPI_DELETE_TARGET, (void *)dn.bv_val );
169 slapi_pblock_set( pb, SLAPI_MANAGEDSAIT, (void *)manageDSAit );
171 rs->sr_err = slapi_int_call_plugins( op->o_bd, SLAPI_PLUGIN_PRE_DELETE_FN, pb );
172 if ( rs->sr_err < 0 ) {
174 * A preoperation plugin failure will abort the
178 LDAP_LOG( OPERATION, INFO, "do_delete: delete preoperation plugin "
179 "failed\n", 0, 0, 0 );
181 Debug (LDAP_DEBUG_TRACE, "do_delete: delete preoperation plugin failed.\n",
184 if ( ( slapi_pblock_get( pb, SLAPI_RESULT_CODE, (void *)&rs->sr_err ) != 0 ) ||
185 rs->sr_err == LDAP_SUCCESS ) {
186 rs->sr_err = LDAP_OTHER;
191 #endif /* defined( LDAP_SLAPI ) */
194 * do the delete if 1 && (2 || 3)
195 * 1) there is a delete function implemented in this backend;
196 * 2) this backend is master for what it holds;
197 * 3) it's a replica and the dn supplied is the update_ndn.
199 if ( op->o_bd->be_delete ) {
200 /* do the update here */
201 int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
202 #ifndef SLAPD_MULTIMASTER
203 if ( LDAP_STAILQ_EMPTY( &op->o_bd->be_syncinfo ) &&
204 ( !op->o_bd->be_update_ndn.bv_len || repl_user ))
206 if ( LDAP_STAILQ_EMPTY( &op->o_bd->be_syncinfo ))
209 slap_callback cb = { NULL, slap_replog_cb, NULL, NULL };
212 struct berval csn = { 0 , NULL };
213 char csnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];
214 slap_get_csn( op, csnbuf, sizeof(csnbuf), &csn, 1 );
217 #ifdef SLAPD_MULTIMASTER
218 if ( !op->o_bd->be_update_ndn.bv_len || !repl_user )
221 cb.sc_next = op->o_callback;
222 op->o_callback = &cb;
224 op->o_bd->be_delete( op, rs );
225 #ifndef SLAPD_MULTIMASTER
227 BerVarray defref = NULL;
228 if ( !LDAP_STAILQ_EMPTY( &op->o_bd->be_syncinfo )) {
230 LDAP_STAILQ_FOREACH( si, &op->o_bd->be_syncinfo, si_next ) {
232 ber_dupbv( &tmpbv, &si->si_provideruri_bv[0] );
233 ber_bvarray_add( &defref, &tmpbv );
236 defref = op->o_bd->be_update_refs
237 ? op->o_bd->be_update_refs : default_referral;
239 if ( defref != NULL ) {
240 rs->sr_ref = referral_rewrite( defref,
241 NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
242 if (!rs->sr_ref) rs->sr_ref = defref;
243 rs->sr_err = LDAP_REFERRAL;
244 send_ldap_result( op, rs );
246 if (rs->sr_ref != defref) ber_bvarray_free( rs->sr_ref );
248 send_ldap_error( op, rs,
249 LDAP_UNWILLING_TO_PERFORM,
250 "referral missing" );
256 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
257 "operation not supported within namingContext" );
260 #if defined( LDAP_SLAPI )
261 if ( pb != NULL && slapi_int_call_plugins( op->o_bd, SLAPI_PLUGIN_POST_DELETE_FN, pb ) < 0) {
263 LDAP_LOG( OPERATION, INFO, "do_delete: delete postoperation plugins "
264 "failed\n", 0, 0, 0 );
266 Debug(LDAP_DEBUG_TRACE, "do_delete: delete postoperation plugins "
267 "failed.\n", 0, 0, 0);
270 #endif /* defined( LDAP_SLAPI ) */
274 slap_graduate_commit_csn( op );
276 op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
277 op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );