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 };
42 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
43 "do_delete: conn %d\n", conn->c_connid ));
45 Debug( LDAP_DEBUG_TRACE, "do_delete\n", 0, 0, 0 );
49 * Parse the delete request. It looks like this:
51 * DelRequest := DistinguishedName
54 if ( ber_scanf( op->o_ber, "o", &dn ) == LBER_ERROR ) {
56 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
57 "do_delete: conn: %d ber_scanf failed\n", conn->c_connid ));
59 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
61 send_ldap_disconnect( conn, op,
62 LDAP_PROTOCOL_ERROR, "decoding error" );
63 return SLAPD_DISCONNECT;
66 if( ( rc = get_ctrls( conn, op, 1 ) ) != LDAP_SUCCESS ) {
68 LDAP_LOG(( "oepration", LDAP_LEVEL_ERR,
69 "do_delete: conn %d get_ctrls failed\n", conn->c_connid ));
71 Debug( LDAP_DEBUG_ANY, "do_delete: get_ctrls failed\n", 0, 0, 0 );
76 ndn = ch_strdup( dn.bv_val );
78 if( dn_normalize( ndn ) == NULL ) {
80 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
81 "do_delete: conn %d invalid dn (%s).\n",
82 conn->c_connid, dn.bv_val ));
84 Debug( LDAP_DEBUG_ANY, "do_delete: invalid dn (%s)\n",
87 send_ldap_result( conn, op, rc = LDAP_INVALID_DN_SYNTAX, NULL,
88 "invalid DN", NULL, NULL );
94 LDAP_LOG(( "operation", LDAP_LEVEL_INFO, "do_delete: conn %d: "
95 "Attempt to delete root DSE.\n", conn->c_connid ));
97 Debug( LDAP_DEBUG_ANY, "do_delete: root dse!\n", 0, 0, 0 );
99 /* protocolError would likely be a more appropriate error */
100 send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
101 NULL, "cannot delete the root DSE", NULL, NULL );
104 #ifdef SLAPD_SCHEMA_DN
105 } else if ( strcasecmp( ndn, SLAPD_SCHEMA_DN ) == 0 ) {
107 LDAP_LOG(( "operation", LDAP_LEVEL_INFO, "do_delete: conn %d: "
108 "Attempt to delete subschema subentry.\n", conn->c_connid ));
110 Debug( LDAP_DEBUG_ANY, "do_delete: subschema subentry!\n", 0, 0, 0 );
112 /* protocolError would likely be a more appropriate error */
113 send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
114 NULL, "cannot delete the root DSE", NULL, NULL );
120 Statslog( LDAP_DEBUG_STATS, "conn=%ld op=%d DEL dn=\"%s\"\n",
121 op->o_connid, op->o_opid, dn.bv_val, 0, 0 );
123 manageDSAit = get_manageDSAit( op );
126 * We could be serving multiple database backends. Select the
127 * appropriate one, or send a referral to our "referral server"
128 * if we don't hold it.
130 if ( (be = select_backend( ndn, manageDSAit, 0 )) == NULL ) {
131 struct berval **ref = referral_rewrite( default_referral,
132 NULL, dn.bv_val, LDAP_SCOPE_DEFAULT );
134 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
135 NULL, NULL, ref ? ref : default_referral, NULL );
141 /* check restrictions */
142 rc = backend_check_restrictions( be, conn, op, NULL, &text ) ;
143 if( rc != LDAP_SUCCESS ) {
144 send_ldap_result( conn, op, rc,
145 NULL, text, NULL, NULL );
149 /* check for referrals */
150 rc = backend_check_referrals( be, conn, op, dn.bv_val, ndn );
151 if ( rc != LDAP_SUCCESS ) {
155 /* deref suffix alias if appropriate */
156 ndn = suffix_alias( be, ndn );
159 * do the delete if 1 && (2 || 3)
160 * 1) there is a delete function implemented in this backend;
161 * 2) this backend is master for what it holds;
162 * 3) it's a replica and the dn supplied is the update_ndn.
164 if ( be->be_delete ) {
165 /* do the update here */
166 int repl_user = be_isupdate( be, op->o_ndn );
167 #ifndef SLAPD_MULTIMASTER
168 if ( be->be_update_ndn == NULL || repl_user )
171 if ( (*be->be_delete)( be, conn, op, dn.bv_val, ndn ) == 0 ) {
172 #ifdef SLAPD_MULTIMASTER
173 if (be->be_update_ndn == NULL || !repl_user )
176 replog( be, op, dn.bv_val, ndn, NULL );
179 #ifndef SLAPD_MULTIMASTER
181 struct berval **defref = be->be_update_refs
182 ? be->be_update_refs : default_referral;
183 struct berval **ref = referral_rewrite( default_referral,
184 NULL, dn.bv_val, LDAP_SCOPE_DEFAULT );
186 send_ldap_result( conn, op, rc = LDAP_REFERRAL, NULL, NULL,
187 ref ? ref : defref, NULL );
194 send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
195 NULL, "operation not supported within namingContext", NULL, NULL );
199 if( ndn != NULL ) free( ndn );