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 char *dn, *ndn = NULL;
41 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
42 "do_delete: conn %d\n", conn->c_connid ));
44 Debug( LDAP_DEBUG_TRACE, "do_delete\n", 0, 0, 0 );
48 * Parse the delete request. It looks like this:
50 * DelRequest := DistinguishedName
53 if ( ber_scanf( op->o_ber, "a", &dn ) == LBER_ERROR ) {
55 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
56 "do_delete: conn: %d ber_scanf failed\n", conn->c_connid ));
58 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
60 send_ldap_disconnect( conn, op,
61 LDAP_PROTOCOL_ERROR, "decoding error" );
62 return SLAPD_DISCONNECT;
65 if( ( rc = get_ctrls( conn, op, 1 ) ) != LDAP_SUCCESS ) {
67 LDAP_LOG(( "oepration", LDAP_LEVEL_ERR,
68 "do_delete: conn %d get_ctrls failed\n", conn->c_connid ));
70 Debug( LDAP_DEBUG_ANY, "do_delete: get_ctrls failed\n", 0, 0, 0 );
75 ndn = ch_strdup( dn );
77 if( dn_normalize( ndn ) == NULL ) {
79 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
80 "do_delete: conn %d invalid dn (%s).\n", conn->c_connid, dn ));
82 Debug( LDAP_DEBUG_ANY, "do_delete: invalid dn (%s)\n", dn, 0, 0 );
84 send_ldap_result( conn, op, rc = LDAP_INVALID_DN_SYNTAX, NULL,
85 "invalid DN", NULL, NULL );
91 LDAP_LOG(( "operation", LDAP_LEVEL_INFO, "do_delete: conn %d: "
92 "Attempt to delete root DSE.\n", conn->c_connid ));
94 Debug( LDAP_DEBUG_ANY, "do_delete: root dse!\n", 0, 0, 0 );
96 /* protocolError would likely be a more appropriate error */
97 send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
98 NULL, "cannot delete the root DSE", NULL, NULL );
101 #ifdef SLAPD_SCHEMA_DN
102 } else if ( strcasecmp( ndn, SLAPD_SCHEMA_DN ) == 0 ) {
104 LDAP_LOG(( "operation", LDAP_LEVEL_INFO, "do_delete: conn %d: "
105 "Attempt to delete subschema subentry.\n", conn->c_connid ));
107 Debug( LDAP_DEBUG_ANY, "do_delete: subschema subentry!\n", 0, 0, 0 );
109 /* protocolError would likely be a more appropriate error */
110 send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
111 NULL, "cannot delete the root DSE", NULL, NULL );
117 Statslog( LDAP_DEBUG_STATS, "conn=%ld op=%d DEL dn=\"%s\"\n",
118 op->o_connid, op->o_opid, dn, 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 ( (be = select_backend( ndn, manageDSAit )) == NULL ) {
128 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
129 NULL, NULL, default_referral, NULL );
133 /* check restrictions */
134 rc = backend_check_restrictions( be, conn, op, NULL, &text ) ;
135 if( rc != LDAP_SUCCESS ) {
136 send_ldap_result( conn, op, rc,
137 NULL, text, NULL, NULL );
141 /* check for referrals */
142 rc = backend_check_referrals( be, conn, op, dn, ndn );
143 if ( rc != LDAP_SUCCESS ) {
147 /* deref suffix alias if appropriate */
148 ndn = suffix_alias( be, ndn );
151 * do the delete if 1 && (2 || 3)
152 * 1) there is a delete function implemented in this backend;
153 * 2) this backend is master for what it holds;
154 * 3) it's a replica and the dn supplied is the update_ndn.
156 if ( be->be_delete ) {
157 /* do the update here */
158 #ifndef SLAPD_MULTIMASTER
159 if ( be->be_update_ndn == NULL ||
160 strcmp( be->be_update_ndn, op->o_ndn ) == 0 )
163 if ( (*be->be_delete)( be, conn, op, dn, ndn ) == 0 ) {
164 #ifdef SLAPD_MULTIMASTER
165 if (be->be_update_ndn == NULL ||
166 strcmp( be->be_update_ndn, op->o_ndn ))
169 replog( be, op, dn, NULL );
172 #ifndef SLAPD_MULTIMASTER
174 send_ldap_result( conn, op, rc = LDAP_REFERRAL, NULL, NULL,
175 be->be_update_refs ? be->be_update_refs : default_referral, NULL );
180 send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
181 NULL, "operation not supported within namingContext", NULL, NULL );
184 if( ndn != NULL ) free( ndn );