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>
38 struct berval dn = { 0, NULL };
42 Slapi_PBlock *pb = op->o_pb;
46 LDAP_LOG( OPERATION, ENTRY,
47 "do_delete: conn %d\n", op->o_connid, 0, 0 );
49 Debug( LDAP_DEBUG_TRACE, "do_delete\n", 0, 0, 0 );
53 * Parse the delete request. It looks like this:
55 * DelRequest := DistinguishedName
58 if ( ber_scanf( op->o_ber, "m", &dn ) == LBER_ERROR ) {
60 LDAP_LOG( OPERATION, ERR,
61 "do_delete: conn: %d ber_scanf failed\n", op->o_connid, 0, 0 );
63 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
65 send_ldap_discon( op, rs, LDAP_PROTOCOL_ERROR, "decoding error" );
66 return SLAPD_DISCONNECT;
69 if( get_ctrls( op, rs, 1 ) != LDAP_SUCCESS ) {
71 LDAP_LOG( OPERATION, ERR,
72 "do_delete: conn %d get_ctrls failed\n", op->o_connid, 0, 0 );
74 Debug( LDAP_DEBUG_ANY, "do_delete: get_ctrls failed\n", 0, 0, 0 );
79 rs->sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn );
80 if( rs->sr_err != LDAP_SUCCESS ) {
82 LDAP_LOG( OPERATION, INFO,
83 "do_delete: conn %d invalid dn (%s)\n",
84 op->o_connid, dn.bv_val, 0 );
86 Debug( LDAP_DEBUG_ANY,
87 "do_delete: invalid dn (%s)\n", dn.bv_val, 0, 0 );
89 send_ldap_error( op, rs, LDAP_INVALID_DN_SYNTAX, "invalid DN" );
93 if( op->o_req_ndn.bv_len == 0 ) {
95 LDAP_LOG( OPERATION, INFO,
96 "do_delete: conn %d: Attempt to delete root DSE.\n",
99 Debug( LDAP_DEBUG_ANY, "do_delete: root dse!\n", 0, 0, 0 );
101 /* protocolError would likely be a more appropriate error */
102 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
103 "cannot delete the root DSE" );
106 } else if ( bvmatch( &op->o_req_ndn, &global_schemandn ) ) {
108 LDAP_LOG( OPERATION, INFO, "do_delete: conn %d: "
109 "Attempt to delete subschema subentry.\n", op->o_connid, 0, 0 );
111 Debug( LDAP_DEBUG_ANY, "do_delete: subschema subentry!\n", 0, 0, 0 );
113 /* protocolError would likely be a more appropriate error */
114 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
115 "cannot delete the root DSE" );
119 Statslog( LDAP_DEBUG_STATS, "conn=%lu op=%lu DEL dn=\"%s\"\n",
120 op->o_connid, op->o_opid, op->o_req_dn.bv_val, 0, 0 );
122 manageDSAit = get_manageDSAit( op );
125 * We could be serving multiple database backends. Select the
126 * appropriate one, or send a referral to our "referral server"
127 * if we don't hold it.
129 if ( (op->o_bd = select_backend( &op->o_req_ndn, manageDSAit, 0 )) == NULL ) {
130 rs->sr_ref = referral_rewrite( default_referral,
131 NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
133 if (!rs->sr_ref) rs->sr_ref = default_referral;
134 rs->sr_err = LDAP_REFERRAL;
136 send_ldap_result( op, rs );
138 if (rs->sr_ref!= default_referral) ber_bvarray_free( rs->sr_ref );
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 ) {
153 #if defined( LDAP_SLAPI )
154 slapi_x_backend_set_pb( pb, op->o_bd );
155 slapi_x_connection_set_pb( pb, op->o_conn );
156 slapi_x_operation_set_pb( pb, op );
157 slapi_pblock_set( pb, SLAPI_DELETE_TARGET, (void *)dn.bv_val );
158 slapi_pblock_set( pb, SLAPI_MANAGEDSAIT, (void *)manageDSAit );
160 rs->sr_err = doPluginFNs( op->o_bd, SLAPI_PLUGIN_PRE_DELETE_FN, pb );
161 if ( rs->sr_err != 0 ) {
163 * A preoperation plugin failure will abort the
167 LDAP_LOG( OPERATION, INFO, "do_delete: delete preoperation plugin "
168 "failed\n", 0, 0, 0 );
170 Debug (LDAP_DEBUG_TRACE, "do_delete: delete preoperation plugin failed.\n",
173 if ( slapi_pblock_get( pb, SLAPI_RESULT_CODE, (void *)&rs->sr_err ) != 0 )
174 rs->sr_err = LDAP_OTHER;
177 #endif /* defined( LDAP_SLAPI ) */
180 * do the delete if 1 && (2 || 3)
181 * 1) there is a delete function implemented in this backend;
182 * 2) this backend is master for what it holds;
183 * 3) it's a replica and the dn supplied is the update_ndn.
185 if ( op->o_bd->be_delete ) {
186 /* do the update here */
187 int repl_user = be_isupdate( op->o_bd, &op->o_ndn );
188 #ifndef SLAPD_MULTIMASTER
189 if ( !op->o_bd->be_update_ndn.bv_len || repl_user )
192 if ( (op->o_bd->be_delete)( op, rs ) == 0 ) {
193 #ifdef SLAPD_MULTIMASTER
194 if ( !op->o_bd->be_update_ndn.bv_len || !repl_user )
200 #ifndef SLAPD_MULTIMASTER
202 BerVarray defref = op->o_bd->be_update_refs
203 ? op->o_bd->be_update_refs : default_referral;
204 rs->sr_ref = referral_rewrite( default_referral,
205 NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
207 if (!rs->sr_ref) rs->sr_ref = defref;
208 rs->sr_err = LDAP_REFERRAL;
209 send_ldap_result( op, rs );
211 if (rs->sr_ref != defref) ber_bvarray_free( rs->sr_ref );
216 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
217 "operation not supported within namingContext" );
220 #if defined( LDAP_SLAPI )
221 if ( doPluginFNs( op->o_bd, SLAPI_PLUGIN_POST_DELETE_FN, pb ) != 0) {
223 LDAP_LOG( OPERATION, INFO, "do_delete: delete postoperation plugins "
224 "failed\n", 0, 0, 0 );
226 Debug(LDAP_DEBUG_TRACE, "do_delete: delete postoperation plugins "
227 "failed.\n", 0, 0, 0);
230 #endif /* defined( LDAP_SLAPI ) */
233 free( op->o_req_dn.bv_val );
234 free( op->o_req_ndn.bv_val );