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.
19 #include "slapi_common.h"
23 #include <ac/string.h>
24 #include <ac/socket.h>
36 struct berval dn = { 0, NULL };
37 struct berval pdn = { 0, NULL };
38 struct berval ndn = { 0, NULL };
44 Slapi_PBlock *pb = op->o_pb;
47 LDAP_LOG( OPERATION, ENTRY,
48 "do_delete: conn %d\n", conn->c_connid, 0, 0 );
50 Debug( LDAP_DEBUG_TRACE, "do_delete\n", 0, 0, 0 );
54 * Parse the delete request. It looks like this:
56 * DelRequest := DistinguishedName
59 if ( ber_scanf( op->o_ber, "m", &dn ) == LBER_ERROR ) {
61 LDAP_LOG( OPERATION, ERR,
62 "do_delete: conn: %d ber_scanf failed\n", conn->c_connid, 0, 0 );
64 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
66 send_ldap_disconnect( conn, op,
67 LDAP_PROTOCOL_ERROR, "decoding error" );
68 return SLAPD_DISCONNECT;
71 if( ( rc = get_ctrls( conn, op, 1 ) ) != LDAP_SUCCESS ) {
73 LDAP_LOG( OPERATION, ERR,
74 "do_delete: conn %d get_ctrls failed\n", conn->c_connid, 0, 0 );
76 Debug( LDAP_DEBUG_ANY, "do_delete: get_ctrls failed\n", 0, 0, 0 );
81 rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn );
82 if( rc != LDAP_SUCCESS ) {
84 LDAP_LOG( OPERATION, INFO,
85 "do_delete: conn %d invalid dn (%s)\n",
86 conn->c_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_result( conn, op, rc = LDAP_INVALID_DN_SYNTAX, NULL,
92 "invalid DN", NULL, NULL );
96 if( ndn.bv_len == 0 ) {
98 LDAP_LOG( OPERATION, INFO,
99 "do_delete: conn %d: Attempt to delete root DSE.\n",
100 conn->c_connid, 0, 0 );
102 Debug( LDAP_DEBUG_ANY, "do_delete: root dse!\n", 0, 0, 0 );
104 /* protocolError would likely be a more appropriate error */
105 send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
106 NULL, "cannot delete the root DSE", NULL, NULL );
109 } else if ( bvmatch( &ndn, &global_schemandn ) ) {
111 LDAP_LOG( OPERATION, INFO, "do_delete: conn %d: "
112 "Attempt to delete subschema subentry.\n", conn->c_connid, 0, 0 );
114 Debug( LDAP_DEBUG_ANY, "do_delete: subschema subentry!\n", 0, 0, 0 );
116 /* protocolError would likely be a more appropriate error */
117 send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
118 NULL, "cannot delete the root DSE", NULL, NULL );
122 Statslog( LDAP_DEBUG_STATS, "conn=%lu op=%lu DEL dn=\"%s\"\n",
123 op->o_connid, op->o_opid, pdn.bv_val, 0, 0 );
125 manageDSAit = get_manageDSAit( op );
128 * We could be serving multiple database backends. Select the
129 * appropriate one, or send a referral to our "referral server"
130 * if we don't hold it.
132 if ( (be = select_backend( &ndn, manageDSAit, 0 )) == NULL ) {
133 BerVarray ref = referral_rewrite( default_referral,
134 NULL, &pdn, LDAP_SCOPE_DEFAULT );
136 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
137 NULL, NULL, ref ? ref : default_referral, NULL );
139 ber_bvarray_free( ref );
143 /* check restrictions */
144 rc = backend_check_restrictions( be, conn, op, NULL, &text ) ;
145 if( rc != LDAP_SUCCESS ) {
146 send_ldap_result( conn, op, rc,
147 NULL, text, NULL, NULL );
151 /* check for referrals */
152 rc = backend_check_referrals( be, conn, op, &pdn, &ndn );
153 if ( rc != LDAP_SUCCESS ) {
157 /* deref suffix alias if appropriate */
158 suffix_alias( be, &ndn );
160 #if defined( LDAP_SLAPI )
161 slapi_pblock_set( pb, SLAPI_BACKEND, (void *)be );
162 slapi_pblock_set( pb, SLAPI_CONNECTION, (void *)conn );
163 slapi_pblock_set( pb, SLAPI_OPERATION, (void *)op );
164 slapi_pblock_set( pb, SLAPI_BIND_TARGET, (void *)dn.bv_val );
165 slapi_pblock_set( pb, SLAPI_MANAGEDSAIT, (void *)(1) );
166 slapi_pblock_set( pb, SLAPI_REQCONTROLS, (void *)op->o_ctrls );
168 rc = doPluginFNs( be, SLAPI_PLUGIN_PRE_DELETE_FN, pb );
169 if ( rc != 0 && rc != LDAP_OTHER ) {
171 * either there is no preOp (delete) plugins
172 * or a plugin failed. Just log it
174 * FIXME: is this correct?
177 LDAP_LOG( OPERATION, INFO, "do_delete: delete preOps "
178 "failed\n", 0, 0, 0 );
180 Debug (LDAP_DEBUG_TRACE, "do_delete: delete preOps failed.\n",
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 ( be->be_delete ) {
193 /* do the update here */
194 int repl_user = be_isupdate( be, &op->o_ndn );
195 #ifndef SLAPD_MULTIMASTER
196 if ( !be->be_update_ndn.bv_len || repl_user )
199 if ( (*be->be_delete)( be, conn, op, &pdn, &ndn ) == 0 ) {
200 #ifdef SLAPD_MULTIMASTER
201 if ( !be->be_update_ndn.bv_len || !repl_user )
204 replog( be, op, &pdn, &ndn, NULL );
207 #ifndef SLAPD_MULTIMASTER
209 BerVarray defref = be->be_update_refs
210 ? be->be_update_refs : default_referral;
211 BerVarray ref = referral_rewrite( default_referral,
212 NULL, &pdn, LDAP_SCOPE_DEFAULT );
214 send_ldap_result( conn, op, rc = LDAP_REFERRAL, NULL, NULL,
215 ref ? ref : defref, NULL );
217 ber_bvarray_free( ref );
222 send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
223 NULL, "operation not supported within namingContext", NULL, NULL );
226 #if defined( LDAP_SLAPI )
227 rc = doPluginFNs( be, SLAPI_PLUGIN_POST_DELETE_FN, pb );
228 if ( rc != 0 && rc != LDAP_OTHER ) {
230 * either there is no postOp (delete) plugins
231 * or a plugin failed. Just log it
233 * FIXME: is this correct?
236 LDAP_LOG( OPERATION, INFO, "do_delete: delete postOps "
237 "failed\n", 0, 0, 0 );
239 Debug(LDAP_DEBUG_TRACE, "do_delete: delete postOps "
240 "failed.\n", 0, 0, 0);
243 #endif /* defined( LDAP_SLAPI ) */