]> git.sur5r.net Git - openldap/blob - servers/slapd/delete.c
Eliminate second session protocol version field.
[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 "ldap_pvt.h"
26 #include "slap.h"
27
28 int
29 do_delete(
30     Connection  *conn,
31     Operation   *op
32 )
33 {
34         char    *dn, *ndn;
35         Backend *be;
36         int rc;
37
38         Debug( LDAP_DEBUG_TRACE, "do_delete\n", 0, 0, 0 );
39
40         if( op->o_bind_in_progress ) {
41                 Debug( LDAP_DEBUG_ANY, "do_delete: SASL bind in progress.\n",
42                         0, 0, 0 );
43                 send_ldap_result( conn, op, LDAP_SASL_BIND_IN_PROGRESS,
44                         NULL, "SASL bind in progress", NULL, NULL );
45                 return LDAP_SASL_BIND_IN_PROGRESS;
46         }
47
48         /*
49          * Parse the delete request.  It looks like this:
50          *
51          *      DelRequest := DistinguishedName
52          */
53
54         if ( ber_scanf( op->o_ber, "a", &dn ) == LBER_ERROR ) {
55                 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
56                 send_ldap_disconnect( conn, op,
57                         LDAP_PROTOCOL_ERROR, "decoding error" );
58                 return -1;
59         }
60
61         ndn = ch_strdup( dn );
62
63         if(     dn_normalize( ndn ) == NULL ) {
64                 Debug( LDAP_DEBUG_ANY, "do_delete: invalid dn (%s)\n", dn, 0, 0 );
65                 send_ldap_result( conn, op, rc = LDAP_INVALID_DN_SYNTAX, NULL,
66                     "invalid DN", NULL, NULL );
67                 goto cleanup;
68         }
69
70         if( ( rc = get_ctrls( conn, op, 1 ) ) != LDAP_SUCCESS ) {
71                 Debug( LDAP_DEBUG_ANY, "do_add: get_ctrls failed\n", 0, 0, 0 );
72                 goto cleanup;
73         } 
74
75         Statslog( LDAP_DEBUG_STATS, "conn=%ld op=%d DEL dn=\"%s\"\n",
76                 op->o_connid, op->o_opid, dn, 0, 0 );
77
78         /*
79          * We could be serving multiple database backends.  Select the
80          * appropriate one, or send a referral to our "referral server"
81          * if we don't hold it.
82          */
83         if ( (be = select_backend( ndn )) == NULL ) {
84                 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
85                         NULL, NULL, default_referral, NULL );
86                 goto cleanup;
87         }
88
89         /* make sure this backend recongizes critical controls */
90         rc = backend_check_controls( be, conn, op ) ;
91
92         if( rc != LDAP_SUCCESS ) {
93                 send_ldap_result( conn, op, rc,
94                         NULL, NULL, NULL, NULL );
95                 goto cleanup;
96         }
97
98         if ( global_readonly || be->be_readonly ) {
99                 Debug( LDAP_DEBUG_ANY, "do_delete: database is read-only\n",
100                        0, 0, 0 );
101                 send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM,
102                                   NULL, "database is read-only", NULL, NULL );
103                 rc = LDAP_UNWILLING_TO_PERFORM;
104                 goto cleanup;
105         }
106
107         /* deref suffix alias if appropriate */
108         ndn = suffix_alias( be, ndn );
109
110         /*
111          * do the delete if 1 && (2 || 3)
112          * 1) there is a delete function implemented in this backend;
113          * 2) this backend is master for what it holds;
114          * 3) it's a replica and the dn supplied is the update_ndn.
115          */
116         if ( be->be_delete ) {
117                 /* do the update here */
118 #ifndef SLAPD_MULTIMASTER
119                 if ( be->be_update_ndn == NULL ||
120                         strcmp( be->be_update_ndn, op->o_ndn ) == 0 )
121 #endif
122                 {
123                         if ( (*be->be_delete)( be, conn, op, dn, ndn ) == 0 ) {
124 #ifdef SLAPD_MULTIMASTER
125                                 if (be->be_update_ndn == NULL ||
126                                         strcmp( be->be_update_ndn, op->o_ndn ))
127 #endif
128                                 {
129                                         replog( be, op, dn, NULL );
130                                 }
131                         }
132 #ifndef SLAPD_MULTIMASTER
133                 } else {
134                         send_ldap_result( conn, op, rc = LDAP_REFERRAL, NULL, NULL,
135                                 be->be_update_refs ? be->be_update_refs : default_referral, NULL );
136 #endif
137                 }
138
139         } else {
140                 send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
141                         NULL, "Function not implemented", NULL, NULL );
142         }
143 cleanup:
144         free( ndn );
145         free( dn );
146         return rc;
147 }