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 Slapi_PBlock *pb = op->o_pb;
48 LDAP_LOG( OPERATION, ENTRY,
49 "do_delete: conn %d\n", op->o_connid, 0, 0 );
51 Debug( LDAP_DEBUG_TRACE, "do_delete\n", 0, 0, 0 );
55 * Parse the delete request. It looks like this:
57 * DelRequest := DistinguishedName
60 if ( ber_scanf( op->o_ber, "m", &dn ) == LBER_ERROR ) {
62 LDAP_LOG( OPERATION, ERR,
63 "do_delete: conn: %d ber_scanf failed\n", op->o_connid, 0, 0 );
65 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
67 send_ldap_discon( op, rs, LDAP_PROTOCOL_ERROR, "decoding error" );
68 return SLAPD_DISCONNECT;
71 if( get_ctrls( op, rs, 1 ) != LDAP_SUCCESS ) {
73 LDAP_LOG( OPERATION, ERR,
74 "do_delete: conn %d get_ctrls failed\n", op->o_connid, 0, 0 );
76 Debug( LDAP_DEBUG_ANY, "do_delete: get_ctrls failed\n", 0, 0, 0 );
81 rs->sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn, op->o_tmpmemctx );
82 if( rs->sr_err != LDAP_SUCCESS ) {
84 LDAP_LOG( OPERATION, INFO,
85 "do_delete: conn %d invalid dn (%s)\n",
86 op->o_connid, dn.bv_val, 0 );
88 Debug( LDAP_DEBUG_ANY,
89 "do_delete: invalid dn (%s)\n", dn.bv_val, 0, 0 );
91 send_ldap_error( op, rs, LDAP_INVALID_DN_SYNTAX, "invalid DN" );
95 if( op->o_req_ndn.bv_len == 0 ) {
97 LDAP_LOG( OPERATION, INFO,
98 "do_delete: conn %d: Attempt to delete root DSE.\n",
101 Debug( LDAP_DEBUG_ANY, "do_delete: root dse!\n", 0, 0, 0 );
103 /* protocolError would likely be a more appropriate error */
104 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
105 "cannot delete the root DSE" );
108 } else if ( bvmatch( &op->o_req_ndn, &global_schemandn ) ) {
110 LDAP_LOG( OPERATION, INFO, "do_delete: conn %d: "
111 "Attempt to delete subschema subentry.\n", op->o_connid, 0, 0 );
113 Debug( LDAP_DEBUG_ANY, "do_delete: subschema subentry!\n", 0, 0, 0 );
115 /* protocolError would likely be a more appropriate error */
116 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
117 "cannot delete the root DSE" );
121 Statslog( LDAP_DEBUG_STATS, "conn=%lu op=%lu DEL dn=\"%s\"\n",
122 op->o_connid, op->o_opid, op->o_req_dn.bv_val, 0, 0 );
124 manageDSAit = get_manageDSAit( op );
127 * We could be serving multiple database backends. Select the
128 * appropriate one, or send a referral to our "referral server"
129 * if we don't hold it.
131 if ( (op->o_bd = select_backend( &op->o_req_ndn, manageDSAit, 0 )) == NULL ) {
132 rs->sr_ref = referral_rewrite( default_referral,
133 NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
135 if (!rs->sr_ref) rs->sr_ref = default_referral;
136 if ( rs->sr_ref != NULL ) {
137 rs->sr_err = LDAP_REFERRAL;
139 send_ldap_result( op, rs );
141 if (rs->sr_ref != default_referral) ber_bvarray_free( rs->sr_ref );
143 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
144 "referral missing" );
149 /* check restrictions */
150 if( backend_check_restrictions( op, rs, NULL ) != LDAP_SUCCESS ) {
151 send_ldap_result( op, rs );
155 /* check for referrals */
156 if( backend_check_referrals( op, rs ) != LDAP_SUCCESS ) {
160 #if defined( LDAP_SLAPI )
161 slapi_x_pblock_set_operation( pb, op );
162 slapi_pblock_set( pb, SLAPI_DELETE_TARGET, (void *)dn.bv_val );
163 slapi_pblock_set( pb, SLAPI_MANAGEDSAIT, (void *)manageDSAit );
165 rs->sr_err = doPluginFNs( op->o_bd, SLAPI_PLUGIN_PRE_DELETE_FN, pb );
166 if ( rs->sr_err < 0 ) {
168 * A preoperation plugin failure will abort the
172 LDAP_LOG( OPERATION, INFO, "do_delete: delete preoperation plugin "
173 "failed\n", 0, 0, 0 );
175 Debug (LDAP_DEBUG_TRACE, "do_delete: delete preoperation plugin failed.\n",
178 if ( ( slapi_pblock_get( op->o_pb, SLAPI_RESULT_CODE, (void *)&rs->sr_err ) != 0 ) ||
179 rs->sr_err == LDAP_SUCCESS ) {
180 rs->sr_err = LDAP_OTHER;
184 #endif /* defined( LDAP_SLAPI ) */
187 * do the delete if 1 && (2 || 3)
188 * 1) there is a delete function implemented in this backend;
189 * 2) this backend is master for what it holds;
190 * 3) it's a replica and the dn supplied is the update_ndn.
192 if ( op->o_bd->be_delete ) {
193 /* do the update here */
194 int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
195 #ifndef SLAPD_MULTIMASTER
196 if ( !op->o_bd->be_syncinfo &&
197 ( !op->o_bd->be_update_ndn.bv_len || repl_user ))
199 if ( !op->o_bd->be_syncinfo )
204 struct berval csn = { 0 , NULL };
205 char csnbuf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];
206 slap_get_csn( op, csnbuf, sizeof(csnbuf), &csn, 1 );
209 if ( (op->o_bd->be_delete)( op, rs ) == 0 ) {
210 #ifdef SLAPD_MULTIMASTER
211 if ( !op->o_bd->be_update_ndn.bv_len || !repl_user )
217 #ifndef SLAPD_MULTIMASTER
219 BerVarray defref = NULL;
220 if ( op->o_bd->be_syncinfo ) {
221 defref = op->o_bd->be_syncinfo->si_provideruri_bv;
223 defref = op->o_bd->be_update_refs
224 ? op->o_bd->be_update_refs : default_referral;
226 if ( defref != NULL ) {
227 rs->sr_ref = referral_rewrite( defref,
228 NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
229 if (!rs->sr_ref) rs->sr_ref = defref;
230 rs->sr_err = LDAP_REFERRAL;
231 send_ldap_result( op, rs );
233 if (rs->sr_ref != defref) ber_bvarray_free( rs->sr_ref );
235 send_ldap_error( op, rs,
236 LDAP_UNWILLING_TO_PERFORM,
237 "referral missing" );
243 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
244 "operation not supported within namingContext" );
247 #if defined( LDAP_SLAPI )
248 if ( doPluginFNs( op->o_bd, SLAPI_PLUGIN_POST_DELETE_FN, pb ) < 0) {
250 LDAP_LOG( OPERATION, INFO, "do_delete: delete postoperation plugins "
251 "failed\n", 0, 0, 0 );
253 Debug(LDAP_DEBUG_TRACE, "do_delete: delete postoperation plugins "
254 "failed.\n", 0, 0, 0);
257 #endif /* defined( LDAP_SLAPI ) */
261 slap_graduate_commit_csn( op );
263 op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
264 op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );