2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1998-2007 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, "do_delete\n", 0, 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, "ber_scanf failed\n", 0, 0, 0 );
54 send_ldap_discon( op, rs, LDAP_PROTOCOL_ERROR, "decoding error" );
55 return SLAPD_DISCONNECT;
58 if( get_ctrls( op, rs, 1 ) != LDAP_SUCCESS ) {
59 Debug( LDAP_DEBUG_ANY, "do_delete: get_ctrls failed\n", 0, 0, 0 );
63 rs->sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn,
65 if( rs->sr_err != LDAP_SUCCESS ) {
66 Debug( LDAP_DEBUG_ANY,
67 "do_delete: invalid dn (%s)\n", dn.bv_val, 0, 0 );
68 send_ldap_error( op, rs, LDAP_INVALID_DN_SYNTAX, "invalid DN" );
72 if( op->o_req_ndn.bv_len == 0 ) {
73 Debug( LDAP_DEBUG_ANY, "do_delete: root dse!\n", 0, 0, 0 );
74 /* protocolError would likely be a more appropriate error */
75 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
76 "cannot delete the root DSE" );
79 } else if ( bvmatch( &op->o_req_ndn, &frontendDB->be_schemandn ) ) {
80 Debug( LDAP_DEBUG_ANY, "do_delete: subschema subentry!\n", 0, 0, 0 );
81 /* protocolError would likely be a more appropriate error */
82 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
83 "cannot delete the root DSE" );
87 Statslog( LDAP_DEBUG_STATS, "%s DEL dn=\"%s\"\n",
88 op->o_log_prefix, op->o_req_dn.bv_val, 0, 0, 0 );
90 op->o_bd = frontendDB;
91 rs->sr_err = frontendDB->be_delete( op, rs );
94 if( rs->sr_err == LDAP_X_TXN_SPECIFY_OKAY ) {
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;
110 BackendDB *op_be, *bd = op->o_bd;
113 * We could be serving multiple database backends. Select the
114 * appropriate one, or send a referral to our "referral server"
115 * if we don't hold it.
117 op->o_bd = select_backend( &op->o_req_ndn, 1 );
118 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;
126 send_ldap_result( op, rs );
128 if (rs->sr_ref != default_referral) ber_bvarray_free( rs->sr_ref );
130 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
131 "no global superior knowledge" );
136 /* If we've got a glued backend, check the real backend */
138 if ( SLAP_GLUE_INSTANCE( op->o_bd )) {
139 op->o_bd = select_backend( &op->o_req_ndn, 0 );
142 /* check restrictions */
143 if( backend_check_restrictions( op, rs, NULL ) != LDAP_SUCCESS ) {
144 send_ldap_result( op, rs );
148 /* check for referrals */
149 if( backend_check_referrals( op, rs ) != LDAP_SUCCESS ) {
154 * do the delete if 1 && (2 || 3)
155 * 1) there is a delete function implemented in this backend;
156 * 2) this backend is master for what it holds;
157 * 3) it's a replica and the dn supplied is the update_ndn.
159 if ( op->o_bd->be_delete ) {
160 /* do the update here */
161 int repl_user = be_isupdate( op );
162 if ( !SLAP_SINGLE_SHADOW(op->o_bd) || repl_user ) {
163 struct berval org_req_dn = BER_BVNULL;
164 struct berval org_req_ndn = BER_BVNULL;
165 struct berval org_dn = BER_BVNULL;
166 struct berval org_ndn = BER_BVNULL;
170 op->o_bd->be_delete( op, rs );
172 org_req_dn = op->o_req_dn;
173 org_req_ndn = op->o_req_ndn;
176 org_managedsait = get_manageDSAit( op );
177 op->o_dn = op->o_bd->be_rootdn;
178 op->o_ndn = op->o_bd->be_rootndn;
179 op->o_managedsait = SLAP_CONTROL_NONCRITICAL;
181 while ( rs->sr_err == LDAP_SUCCESS &&
182 op->o_delete_glue_parent )
184 op->o_delete_glue_parent = 0;
185 if ( !be_issuffix( op->o_bd, &op->o_req_ndn )) {
186 slap_callback cb = { NULL, NULL, NULL, NULL };
187 cb.sc_response = slap_null_cb;
188 dnParent( &op->o_req_ndn, &pdn );
191 op->o_callback = &cb;
192 op->o_bd->be_delete( op, rs );
198 op->o_managedsait = org_managedsait;
201 op->o_req_dn = org_req_dn;
202 op->o_req_ndn = org_req_ndn;
203 op->o_delete_glue_parent = 0;
206 BerVarray defref = op->o_bd->be_update_refs
207 ? op->o_bd->be_update_refs : default_referral;
209 if ( defref != NULL ) {
210 rs->sr_ref = referral_rewrite( defref,
211 NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
212 if (!rs->sr_ref) rs->sr_ref = defref;
213 rs->sr_err = LDAP_REFERRAL;
214 send_ldap_result( op, rs );
216 if (rs->sr_ref != defref) ber_bvarray_free( rs->sr_ref );
219 send_ldap_error( op, rs,
220 LDAP_UNWILLING_TO_PERFORM,
221 "shadow context; no update referral" );
226 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
227 "operation not supported within namingContext" );