]> git.sur5r.net Git - openldap/blob - servers/slapd/delete.c
Fix previous dn checkin
[openldap] / servers / slapd / delete.c
1 /* $OpenLDAP$ */
2 /*
3  * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
4  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
5  */
6 /*
7  * Copyright (c) 1995 Regents of the University of Michigan.
8  * All rights reserved.
9  *
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.
16  */
17
18 #include "portable.h"
19
20 #include <stdio.h>
21
22 #include <ac/string.h>
23 #include <ac/socket.h>
24
25 #include "slap.h"
26
27 int
28 do_delete(
29     Connection  *conn,
30     Operation   *op
31 )
32 {
33         char    *dn, *ndn;
34         Backend *be;
35         int rc;
36
37         Debug( LDAP_DEBUG_TRACE, "do_delete\n", 0, 0, 0 );
38
39         if( op->o_bind_in_progress ) {
40                 Debug( LDAP_DEBUG_ANY, "do_delete: SASL bind in progress.\n",
41                         0, 0, 0 );
42                 send_ldap_result( conn, op, LDAP_SASL_BIND_IN_PROGRESS,
43                         NULL, "SASL bind in progress", NULL, NULL );
44                 return LDAP_SASL_BIND_IN_PROGRESS;
45         }
46
47         /*
48          * Parse the delete request.  It looks like this:
49          *
50          *      DelRequest := DistinguishedName
51          */
52
53         if ( ber_scanf( op->o_ber, "a", &dn ) == LBER_ERROR ) {
54                 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
55                 send_ldap_disconnect( conn, op,
56                         LDAP_PROTOCOL_ERROR, "decoding error" );
57                 return -1;
58         }
59
60         ndn = ch_strdup( dn );
61
62         if(     dn_normalize_case( ndn ) == NULL ) {
63                 Debug( LDAP_DEBUG_ANY, "do_delete: invalid dn (%s)\n", dn, 0, 0 );
64                 send_ldap_result( conn, op, rc = LDAP_INVALID_DN_SYNTAX, NULL,
65                     "invalid DN", NULL, NULL );
66                 goto cleanup;
67         }
68
69         if( ( rc = get_ctrls( conn, op, 1 ) ) != LDAP_SUCCESS ) {
70                 Debug( LDAP_DEBUG_ANY, "do_add: get_ctrls failed\n", 0, 0, 0 );
71                 goto cleanup;
72         } 
73
74         Debug( LDAP_DEBUG_ARGS, "do_delete: dn (%s)\n", dn, 0, 0 );
75         Debug( LDAP_DEBUG_STATS, "DEL dn=\"%s\"\n", dn, 0, 0 );
76
77         /*
78          * We could be serving multiple database backends.  Select the
79          * appropriate one, or send a referral to our "referral server"
80          * if we don't hold it.
81          */
82         if ( (be = select_backend( ndn )) == NULL ) {
83                 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
84                         NULL, NULL, default_referral, NULL );
85                 goto cleanup;
86         }
87
88         if ( global_readonly || be->be_readonly ) {
89                 Debug( LDAP_DEBUG_ANY, "do_delete: database is read-only\n",
90                        0, 0, 0 );
91                 send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM,
92                                   NULL, "database is read-only", NULL, NULL );
93                 rc = LDAP_UNWILLING_TO_PERFORM;
94                 goto cleanup;
95         }
96
97         /* deref suffix alias if appropriate */
98         ndn = suffix_alias( be, ndn );
99
100         /*
101          * do the delete if 1 && (2 || 3)
102          * 1) there is a delete function implemented in this backend;
103          * 2) this backend is master for what it holds;
104          * 3) it's a replica and the dn supplied is the update_ndn.
105          */
106         if ( be->be_delete ) {
107                 /* do the update here */
108 #ifndef SLAPD_MULTIMASTER
109                 if ( be->be_update_ndn == NULL ||
110                         strcmp( be->be_update_ndn, op->o_ndn ) == 0 )
111 #endif
112                 {
113                         if ( (*be->be_delete)( be, conn, op, dn, ndn ) == 0 ) {
114 #ifdef SLAPD_MULTIMASTER
115                                 if (be->be_update_ndn == NULL ||
116                                         strcmp( be->be_update_ndn, op->o_ndn ))
117 #endif
118                                 {
119                                         replog( be, op, dn, NULL );
120                                 }
121                         }
122 #ifndef SLAPD_MULTIMASTER
123                 } else {
124                         send_ldap_result( conn, op, rc = LDAP_REFERRAL, NULL, NULL,
125                                 be->be_update_refs ? be->be_update_refs : default_referral, NULL );
126 #endif
127                 }
128
129         } else {
130                 send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
131                         NULL, "Function not implemented", NULL, NULL );
132         }
133 cleanup:
134         free( ndn );
135         free( dn );
136         return rc;
137 }