3 * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
7 * Copyright (c) 1995 Regents of the University of Michigan.
10 * Redistribution and use in source and binary forms are permitted
11 * provided that this notice is preserved and that due credit is given
12 * to the University of Michigan at Ann Arbor. The name of the University
13 * may not be used to endorse or promote products derived from this
14 * software without specific prior written permission. This software
15 * is provided ``as is'' without express or implied warranty.
22 #include <ac/string.h>
23 #include <ac/socket.h>
40 struct berval dn = { 0, NULL };
44 LDAP_LOG( OPERATION, ENTRY,
45 "do_delete: conn %d\n", op->o_connid, 0, 0 );
47 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 ) {
58 LDAP_LOG( OPERATION, ERR,
59 "do_delete: conn: %d ber_scanf failed\n", op->o_connid, 0, 0 );
61 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
63 send_ldap_discon( op, rs, LDAP_PROTOCOL_ERROR, "decoding error" );
64 return SLAPD_DISCONNECT;
67 if( get_ctrls( op, rs, 1 ) != LDAP_SUCCESS ) {
69 LDAP_LOG( OPERATION, ERR,
70 "do_delete: conn %d get_ctrls failed\n", op->o_connid, 0, 0 );
72 Debug( LDAP_DEBUG_ANY, "do_delete: get_ctrls failed\n", 0, 0, 0 );
77 rs->sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn, op->o_tmpmemctx );
78 if( rs->sr_err != LDAP_SUCCESS ) {
80 LDAP_LOG( OPERATION, INFO,
81 "do_delete: conn %d invalid dn (%s)\n",
82 op->o_connid, dn.bv_val, 0 );
84 Debug( LDAP_DEBUG_ANY,
85 "do_delete: invalid dn (%s)\n", dn.bv_val, 0, 0 );
87 send_ldap_error( op, rs, LDAP_INVALID_DN_SYNTAX, "invalid DN" );
91 if( op->o_req_ndn.bv_len == 0 ) {
93 LDAP_LOG( OPERATION, INFO,
94 "do_delete: conn %d: Attempt to delete root DSE.\n",
97 Debug( LDAP_DEBUG_ANY, "do_delete: root dse!\n", 0, 0, 0 );
99 /* protocolError would likely be a more appropriate error */
100 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
101 "cannot delete the root DSE" );
104 } else if ( bvmatch( &op->o_req_ndn, &global_schemandn ) ) {
106 LDAP_LOG( OPERATION, INFO, "do_delete: conn %d: "
107 "Attempt to delete subschema subentry.\n", op->o_connid, 0, 0 );
109 Debug( LDAP_DEBUG_ANY, "do_delete: subschema subentry!\n", 0, 0, 0 );
111 /* protocolError would likely be a more appropriate error */
112 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
113 "cannot delete the root DSE" );
117 Statslog( LDAP_DEBUG_STATS, "conn=%lu op=%lu DEL dn=\"%s\"\n",
118 op->o_connid, op->o_opid, op->o_req_dn.bv_val, 0, 0 );
120 manageDSAit = get_manageDSAit( op );
123 * We could be serving multiple database backends. Select the
124 * appropriate one, or send a referral to our "referral server"
125 * if we don't hold it.
127 if ( (op->o_bd = select_backend( &op->o_req_ndn, manageDSAit, 0 )) == 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;
135 send_ldap_result( op, rs );
137 if (rs->sr_ref != default_referral) ber_bvarray_free( rs->sr_ref );
139 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
140 "referral missing" );
145 /* check restrictions */
146 if( backend_check_restrictions( op, rs, NULL ) != LDAP_SUCCESS ) {
147 send_ldap_result( op, rs );
151 /* check for referrals */
152 if( backend_check_referrals( op, rs ) != LDAP_SUCCESS ) {
156 #if defined( LDAP_SLAPI )
159 slapi_x_pblock_set_operation( pb, op );
160 slapi_pblock_set( pb, SLAPI_DELETE_TARGET, (void *)dn.bv_val );
161 slapi_pblock_set( pb, SLAPI_MANAGEDSAIT, (void *)manageDSAit );
163 rs->sr_err = doPluginFNs( op->o_bd, SLAPI_PLUGIN_PRE_DELETE_FN, pb );
164 if ( rs->sr_err < 0 ) {
166 * A preoperation plugin failure will abort the
170 LDAP_LOG( OPERATION, INFO, "do_delete: delete preoperation plugin "
171 "failed\n", 0, 0, 0 );
173 Debug (LDAP_DEBUG_TRACE, "do_delete: delete preoperation plugin failed.\n",
176 if ( ( slapi_pblock_get( pb, SLAPI_RESULT_CODE, (void *)&rs->sr_err ) != 0 ) ||
177 rs->sr_err == LDAP_SUCCESS ) {
178 rs->sr_err = LDAP_OTHER;
183 #endif /* defined( LDAP_SLAPI ) */
186 * do the delete if 1 && (2 || 3)
187 * 1) there is a delete function implemented in this backend;
188 * 2) this backend is master for what it holds;
189 * 3) it's a replica and the dn supplied is the update_ndn.
191 if ( op->o_bd->be_delete ) {
192 /* do the update here */
193 int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
194 #ifndef SLAPD_MULTIMASTER
195 if ( !op->o_bd->be_syncinfo &&
196 ( !op->o_bd->be_update_ndn.bv_len || repl_user ))
198 if ( !op->o_bd->be_syncinfo )
203 struct berval csn = { 0 , NULL };
204 char csnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];
205 slap_get_csn( op, csnbuf, sizeof(csnbuf), &csn, 1 );
208 if ( (op->o_bd->be_delete)( op, rs ) == 0 ) {
209 #ifdef SLAPD_MULTIMASTER
210 if ( !op->o_bd->be_update_ndn.bv_len || !repl_user )
216 #ifndef SLAPD_MULTIMASTER
218 BerVarray defref = NULL;
219 if ( op->o_bd->be_syncinfo ) {
220 defref = op->o_bd->be_syncinfo->si_provideruri_bv;
222 defref = op->o_bd->be_update_refs
223 ? op->o_bd->be_update_refs : default_referral;
225 if ( defref != NULL ) {
226 rs->sr_ref = referral_rewrite( defref,
227 NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
228 if (!rs->sr_ref) rs->sr_ref = defref;
229 rs->sr_err = LDAP_REFERRAL;
230 send_ldap_result( op, rs );
232 if (rs->sr_ref != defref) ber_bvarray_free( rs->sr_ref );
234 send_ldap_error( op, rs,
235 LDAP_UNWILLING_TO_PERFORM,
236 "referral missing" );
242 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
243 "operation not supported within namingContext" );
246 #if defined( LDAP_SLAPI )
247 if ( pb && doPluginFNs( op->o_bd, SLAPI_PLUGIN_POST_DELETE_FN, pb ) < 0) {
249 LDAP_LOG( OPERATION, INFO, "do_delete: delete postoperation plugins "
250 "failed\n", 0, 0, 0 );
252 Debug(LDAP_DEBUG_TRACE, "do_delete: delete postoperation plugins "
253 "failed.\n", 0, 0, 0);
256 #endif /* defined( LDAP_SLAPI ) */
260 slap_graduate_commit_csn( op );
262 op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
263 op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );