2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1998-2017 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>
42 struct berval dn = BER_BVNULL;
44 Debug( LDAP_DEBUG_TRACE, "%s do_delete\n",
45 op->o_log_prefix, 0, 0 );
47 * Parse the delete request. It looks like this:
49 * DelRequest := DistinguishedName
52 if ( ber_scanf( op->o_ber, "m", &dn ) == LBER_ERROR ) {
53 Debug( LDAP_DEBUG_ANY, "%s do_delete: ber_scanf failed\n",
54 op->o_log_prefix, 0, 0 );
55 send_ldap_discon( op, rs, LDAP_PROTOCOL_ERROR, "decoding error" );
56 return SLAPD_DISCONNECT;
59 if( get_ctrls( op, rs, 1 ) != LDAP_SUCCESS ) {
60 Debug( LDAP_DEBUG_ANY, "%s do_delete: get_ctrls failed\n",
61 op->o_log_prefix, 0, 0 );
65 rs->sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn,
67 if( rs->sr_err != LDAP_SUCCESS ) {
68 Debug( LDAP_DEBUG_ANY, "%s do_delete: invalid dn (%s)\n",
69 op->o_log_prefix, dn.bv_val, 0 );
70 send_ldap_error( op, rs, LDAP_INVALID_DN_SYNTAX, "invalid DN" );
74 Statslog( LDAP_DEBUG_STATS, "%s DEL dn=\"%s\"\n",
75 op->o_log_prefix, op->o_req_dn.bv_val, 0, 0, 0 );
77 if( op->o_req_ndn.bv_len == 0 ) {
78 Debug( LDAP_DEBUG_ANY, "%s do_delete: root dse!\n",
79 op->o_log_prefix, 0, 0 );
80 /* protocolError would likely be a more appropriate error */
81 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
82 "cannot delete the root DSE" );
85 } else if ( bvmatch( &op->o_req_ndn, &frontendDB->be_schemandn ) ) {
86 Debug( LDAP_DEBUG_ANY, "%s do_delete: subschema subentry!\n",
87 op->o_log_prefix, 0, 0 );
88 /* protocolError would likely be a more appropriate error */
89 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
90 "cannot delete the root DSE" );
94 op->o_bd = frontendDB;
95 rs->sr_err = frontendDB->be_delete( op, rs );
96 if ( rs->sr_err == SLAPD_ASYNCOP ) {
102 if( rs->sr_err == LDAP_X_TXN_SPECIFY_OKAY ) {
109 op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
110 op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
115 fe_op_delete( Operation *op, SlapReply *rs )
117 struct berval pdn = BER_BVNULL;
118 BackendDB *op_be, *bd = op->o_bd;
121 * We could be serving multiple database backends. Select the
122 * appropriate one, or send a referral to our "referral server"
123 * if we don't hold it.
125 op->o_bd = select_backend( &op->o_req_ndn, 1 );
126 if ( op->o_bd == NULL ) {
128 rs->sr_ref = referral_rewrite( default_referral,
129 NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
131 if (!rs->sr_ref) rs->sr_ref = default_referral;
132 if ( rs->sr_ref != NULL ) {
133 rs->sr_err = LDAP_REFERRAL;
134 send_ldap_result( op, rs );
136 if (rs->sr_ref != default_referral) ber_bvarray_free( rs->sr_ref );
138 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
139 "no global superior knowledge" );
144 /* If we've got a glued backend, check the real backend */
146 if ( SLAP_GLUE_INSTANCE( op->o_bd )) {
147 op->o_bd = select_backend( &op->o_req_ndn, 0 );
150 /* check restrictions */
151 if( backend_check_restrictions( op, rs, NULL ) != LDAP_SUCCESS ) {
152 send_ldap_result( op, rs );
156 /* check for referrals */
157 if( backend_check_referrals( op, rs ) != LDAP_SUCCESS ) {
162 * do the delete if 1 && (2 || 3)
163 * 1) there is a delete function implemented in this backend;
164 * 2) this backend is master for what it holds;
165 * 3) it's a replica and the dn supplied is the update_ndn.
167 if ( op->o_bd->be_delete ) {
168 /* do the update here */
169 int repl_user = be_isupdate( op );
170 if ( !SLAP_SINGLE_SHADOW(op->o_bd) || repl_user ) {
171 struct berval org_req_dn = BER_BVNULL;
172 struct berval org_req_ndn = BER_BVNULL;
173 struct berval org_dn = BER_BVNULL;
174 struct berval org_ndn = BER_BVNULL;
178 op->o_bd->be_delete( op, rs );
180 org_req_dn = op->o_req_dn;
181 org_req_ndn = op->o_req_ndn;
184 org_managedsait = get_manageDSAit( op );
185 op->o_dn = op->o_bd->be_rootdn;
186 op->o_ndn = op->o_bd->be_rootndn;
187 op->o_managedsait = SLAP_CONTROL_NONCRITICAL;
189 while ( rs->sr_err == LDAP_SUCCESS &&
190 op->o_delete_glue_parent )
192 op->o_delete_glue_parent = 0;
193 if ( !be_issuffix( op->o_bd, &op->o_req_ndn )) {
194 slap_callback cb = { NULL, NULL, NULL, NULL };
195 cb.sc_response = slap_null_cb;
196 dnParent( &op->o_req_ndn, &pdn );
199 op->o_callback = &cb;
200 op->o_bd->be_delete( op, rs );
206 op->o_managedsait = org_managedsait;
209 op->o_req_dn = org_req_dn;
210 op->o_req_ndn = org_req_ndn;
211 op->o_delete_glue_parent = 0;
214 BerVarray defref = op->o_bd->be_update_refs
215 ? op->o_bd->be_update_refs : default_referral;
217 if ( defref != NULL ) {
218 rs->sr_ref = referral_rewrite( defref,
219 NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
220 if (!rs->sr_ref) rs->sr_ref = defref;
221 rs->sr_err = LDAP_REFERRAL;
222 send_ldap_result( op, rs );
224 if (rs->sr_ref != defref) ber_bvarray_free( rs->sr_ref );
227 send_ldap_error( op, rs,
228 LDAP_UNWILLING_TO_PERFORM,
229 "shadow context; no update referral" );
234 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
235 "operation not supported within namingContext" );