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,
92 "do_delete: conn %d 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 );
102 Statslog( LDAP_DEBUG_STATS, "conn=%ld op=%d DEL dn=\"%s\"\n",
103 op->o_connid, op->o_opid, dn, 0, 0 );
105 manageDSAit = get_manageDSAit( op );
108 * We could be serving multiple database backends. Select the
109 * appropriate one, or send a referral to our "referral server"
110 * if we don't hold it.
112 if ( (be = select_backend( ndn, manageDSAit )) == NULL ) {
113 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
114 NULL, NULL, default_referral, NULL );
118 /* check restrictions */
119 rc = backend_check_restrictions( be, conn, op, NULL, &text ) ;
120 if( rc != LDAP_SUCCESS ) {
121 send_ldap_result( conn, op, rc,
122 NULL, text, NULL, NULL );
126 /* check for referrals */
127 rc = backend_check_referrals( be, conn, op, dn, ndn );
128 if ( rc != LDAP_SUCCESS ) {
132 /* deref suffix alias if appropriate */
133 ndn = suffix_alias( be, ndn );
136 * do the delete if 1 && (2 || 3)
137 * 1) there is a delete function implemented in this backend;
138 * 2) this backend is master for what it holds;
139 * 3) it's a replica and the dn supplied is the update_ndn.
141 if ( be->be_delete ) {
142 /* do the update here */
143 #ifndef SLAPD_MULTIMASTER
144 if ( be->be_update_ndn == NULL ||
145 strcmp( be->be_update_ndn, op->o_ndn ) == 0 )
148 if ( (*be->be_delete)( be, conn, op, dn, ndn ) == 0 ) {
149 #ifdef SLAPD_MULTIMASTER
150 if (be->be_update_ndn == NULL ||
151 strcmp( be->be_update_ndn, op->o_ndn ))
154 replog( be, op, dn, NULL );
157 #ifndef SLAPD_MULTIMASTER
159 send_ldap_result( conn, op, rc = LDAP_REFERRAL, NULL, NULL,
160 be->be_update_refs ? be->be_update_refs : default_referral, NULL );
165 send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
166 NULL, "operation not supported within namingContext", NULL, NULL );
169 if( ndn != NULL ) free( ndn );