3 * Copyright 1998-2000 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>
34 struct berval dn = { 0, NULL };
35 struct berval *ndn = NULL;
36 struct berval *pdn = NULL;
43 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
44 "do_delete: conn %d\n", conn->c_connid ));
46 Debug( LDAP_DEBUG_TRACE, "do_delete\n", 0, 0, 0 );
50 * Parse the delete request. It looks like this:
52 * DelRequest := DistinguishedName
55 if ( ber_scanf( op->o_ber, "o", &dn ) == LBER_ERROR ) {
57 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
58 "do_delete: conn: %d ber_scanf failed\n", conn->c_connid ));
60 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
62 send_ldap_disconnect( conn, op,
63 LDAP_PROTOCOL_ERROR, "decoding error" );
64 return SLAPD_DISCONNECT;
67 if( ( rc = get_ctrls( conn, op, 1 ) ) != LDAP_SUCCESS ) {
69 LDAP_LOG(( "oepration", LDAP_LEVEL_ERR,
70 "do_delete: conn %d get_ctrls failed\n", conn->c_connid ));
72 Debug( LDAP_DEBUG_ANY, "do_delete: get_ctrls failed\n", 0, 0, 0 );
77 rc = dnPretty( NULL, &dn, &pdn );
78 if( rc != LDAP_SUCCESS ) {
80 LDAP_LOG(( "operation", LDAP_LEVEL_INFO,
81 "do_delete: conn %d invalid dn (%s)\n",
82 conn->c_connid, dn.bv_val ));
84 Debug( LDAP_DEBUG_ANY,
85 "do_delete: invalid dn (%s)\n", dn.bv_val, 0, 0 );
87 send_ldap_result( conn, op, rc = LDAP_INVALID_DN_SYNTAX, NULL,
88 "invalid DN", NULL, NULL );
92 rc = dnNormalize( NULL, &dn, &ndn );
93 if( rc != LDAP_SUCCESS ) {
95 LDAP_LOG(( "operation", LDAP_LEVEL_INFO,
96 "do_delete: conn %d invalid dn (%s)\n",
97 conn->c_connid, dn.bv_val ));
99 Debug( LDAP_DEBUG_ANY,
100 "do_delete: invalid dn (%s)\n", dn.bv_val, 0, 0 );
102 send_ldap_result( conn, op, rc = LDAP_INVALID_DN_SYNTAX, NULL,
103 "invalid DN", NULL, NULL );
107 if( ndn->bv_len == 0 ) {
109 LDAP_LOG(( "operation", LDAP_LEVEL_INFO, "do_delete: conn %d: "
110 "Attempt to delete root DSE.\n", conn->c_connid ));
112 Debug( LDAP_DEBUG_ANY, "do_delete: root dse!\n", 0, 0, 0 );
114 /* protocolError would likely be a more appropriate error */
115 send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
116 NULL, "cannot delete the root DSE", NULL, NULL );
119 #ifdef SLAPD_SCHEMA_DN
121 } else if ( strcasecmp( ndn->bv_val, SLAPD_SCHEMA_DN ) == 0 ) {
123 LDAP_LOG(( "operation", LDAP_LEVEL_INFO, "do_delete: conn %d: "
124 "Attempt to delete subschema subentry.\n", conn->c_connid ));
126 Debug( LDAP_DEBUG_ANY, "do_delete: subschema subentry!\n", 0, 0, 0 );
128 /* protocolError would likely be a more appropriate error */
129 send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
130 NULL, "cannot delete the root DSE", NULL, NULL );
136 Statslog( LDAP_DEBUG_STATS, "conn=%ld op=%d DEL dn=\"%s\"\n",
137 op->o_connid, op->o_opid, pdn->bv_val, 0, 0 );
139 manageDSAit = get_manageDSAit( op );
142 * We could be serving multiple database backends. Select the
143 * appropriate one, or send a referral to our "referral server"
144 * if we don't hold it.
146 if ( (be = select_backend( ndn->bv_val, manageDSAit, 0 )) == NULL ) {
147 struct berval **ref = referral_rewrite( default_referral,
148 NULL, pdn->bv_val, LDAP_SCOPE_DEFAULT );
150 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
151 NULL, NULL, ref ? ref : default_referral, NULL );
157 /* check restrictions */
158 rc = backend_check_restrictions( be, conn, op, NULL, &text ) ;
159 if( rc != LDAP_SUCCESS ) {
160 send_ldap_result( conn, op, rc,
161 NULL, text, NULL, NULL );
165 /* check for referrals */
166 rc = backend_check_referrals( be, conn, op, pdn->bv_val, ndn->bv_val );
167 if ( rc != LDAP_SUCCESS ) {
171 /* deref suffix alias if appropriate */
172 ndn->bv_val = suffix_alias( be, ndn->bv_val );
173 ndn->bv_len = strlen( ndn->bv_val );
176 * do the delete if 1 && (2 || 3)
177 * 1) there is a delete function implemented in this backend;
178 * 2) this backend is master for what it holds;
179 * 3) it's a replica and the dn supplied is the update_ndn.
181 if ( be->be_delete ) {
182 /* do the update here */
183 int repl_user = be_isupdate( be, op->o_ndn );
184 #ifndef SLAPD_MULTIMASTER
185 if ( be->be_update_ndn == NULL || repl_user )
188 if ( (*be->be_delete)( be, conn, op, pdn->bv_val, ndn->bv_val ) == 0 ) {
189 #ifdef SLAPD_MULTIMASTER
190 if (be->be_update_ndn == NULL || !repl_user )
193 replog( be, op, pdn->bv_val, ndn->bv_val, NULL );
196 #ifndef SLAPD_MULTIMASTER
198 struct berval **defref = be->be_update_refs
199 ? be->be_update_refs : default_referral;
200 struct berval **ref = referral_rewrite( default_referral,
201 NULL, pdn->bv_val, LDAP_SCOPE_DEFAULT );
203 send_ldap_result( conn, op, rc = LDAP_REFERRAL, NULL, NULL,
204 ref ? ref : defref, NULL );
211 send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
212 NULL, "operation not supported within namingContext", NULL, NULL );
217 if( pdn != NULL ) ber_bvfree( pdn );
218 if( ndn != NULL ) ber_bvfree( ndn );