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;
39 Debug( LDAP_DEBUG_TRACE, "do_delete\n", 0, 0, 0 );
42 * Parse the delete request. It looks like this:
44 * DelRequest := DistinguishedName
47 if ( ber_scanf( op->o_ber, "a", &dn ) == LBER_ERROR ) {
48 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
49 send_ldap_disconnect( conn, op,
50 LDAP_PROTOCOL_ERROR, "decoding error" );
51 return SLAPD_DISCONNECT;
54 if( ( rc = get_ctrls( conn, op, 1 ) ) != LDAP_SUCCESS ) {
55 Debug( LDAP_DEBUG_ANY, "do_delete: get_ctrls failed\n", 0, 0, 0 );
59 ndn = ch_strdup( dn );
61 if( dn_normalize( ndn ) == NULL ) {
62 Debug( LDAP_DEBUG_ANY, "do_delete: invalid dn (%s)\n", dn, 0, 0 );
63 send_ldap_result( conn, op, rc = LDAP_INVALID_DN_SYNTAX, NULL,
64 "invalid DN", NULL, NULL );
68 Statslog( LDAP_DEBUG_STATS, "conn=%ld op=%d DEL dn=\"%s\"\n",
69 op->o_connid, op->o_opid, dn, 0, 0 );
72 * We could be serving multiple database backends. Select the
73 * appropriate one, or send a referral to our "referral server"
74 * if we don't hold it.
76 if ( (be = select_backend( ndn )) == NULL ) {
77 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
78 NULL, NULL, default_referral, NULL );
82 /* make sure this backend recongizes critical controls */
83 rc = backend_check_controls( be, conn, op, &text ) ;
84 if( rc != LDAP_SUCCESS ) {
85 send_ldap_result( conn, op, rc,
86 NULL, text, NULL, NULL );
90 /* check for referrals */
91 rc = backend_check_referrals( be, conn, op, dn, ndn );
92 if ( rc != LDAP_SUCCESS ) {
96 if ( global_readonly || be->be_readonly ) {
97 Debug( LDAP_DEBUG_ANY, "do_delete: database is read-only\n",
99 send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
100 NULL, "directory is read-only", NULL, NULL );
104 /* deref suffix alias if appropriate */
105 ndn = suffix_alias( be, ndn );
108 * do the delete if 1 && (2 || 3)
109 * 1) there is a delete function implemented in this backend;
110 * 2) this backend is master for what it holds;
111 * 3) it's a replica and the dn supplied is the update_ndn.
113 if ( be->be_delete ) {
114 /* do the update here */
115 #ifndef SLAPD_MULTIMASTER
116 if ( be->be_update_ndn == NULL ||
117 strcmp( be->be_update_ndn, op->o_ndn ) == 0 )
120 if ( (*be->be_delete)( be, conn, op, dn, ndn ) == 0 ) {
121 #ifdef SLAPD_MULTIMASTER
122 if (be->be_update_ndn == NULL ||
123 strcmp( be->be_update_ndn, op->o_ndn ))
126 replog( be, op, dn, NULL );
129 #ifndef SLAPD_MULTIMASTER
131 send_ldap_result( conn, op, rc = LDAP_REFERRAL, NULL, NULL,
132 be->be_update_refs ? be->be_update_refs : default_referral, NULL );
137 send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
138 NULL, "operation not supported within namingContext", NULL, NULL );
141 if( ndn != NULL ) free( ndn );