]> git.sur5r.net Git - openldap/blob - servers/slapd/delete.c
Added ndn to replog args, eliminate unnecessary dn_normalize in replog.
[openldap] / servers / slapd / delete.c
1 /* $OpenLDAP$ */
2 /*
3  * Copyright 1998-2000 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 = NULL;
35         const char *text;
36         Backend *be;
37         int rc;
38         int manageDSAit;
39
40 #ifdef NEW_LOGGING
41         LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
42                    "do_delete: conn %d\n", conn->c_connid ));
43 #else
44         Debug( LDAP_DEBUG_TRACE, "do_delete\n", 0, 0, 0 );
45 #endif
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 #ifdef NEW_LOGGING
55                 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
56                            "do_delete: conn: %d  ber_scanf failed\n", conn->c_connid ));
57 #else
58                 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
59 #endif
60                 send_ldap_disconnect( conn, op,
61                         LDAP_PROTOCOL_ERROR, "decoding error" );
62                 return SLAPD_DISCONNECT;
63         }
64
65         if( ( rc = get_ctrls( conn, op, 1 ) ) != LDAP_SUCCESS ) {
66 #ifdef NEW_LOGGING
67                 LDAP_LOG(( "oepration", LDAP_LEVEL_ERR,
68                            "do_delete: conn %d  get_ctrls failed\n", conn->c_connid ));
69 #else
70                 Debug( LDAP_DEBUG_ANY, "do_delete: get_ctrls failed\n", 0, 0, 0 );
71 #endif
72                 goto cleanup;
73         } 
74
75         ndn = ch_strdup( dn );
76
77         if(     dn_normalize( ndn ) == NULL ) {
78 #ifdef NEW_LOGGING
79                 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
80                            "do_delete: conn %d  invalid dn (%s).\n", conn->c_connid, dn ));
81 #else
82                 Debug( LDAP_DEBUG_ANY, "do_delete: invalid dn (%s)\n", dn, 0, 0 );
83 #endif
84                 send_ldap_result( conn, op, rc = LDAP_INVALID_DN_SYNTAX, NULL,
85                     "invalid DN", NULL, NULL );
86                 goto cleanup;
87         }
88
89         if( *ndn == '\0' ) {
90 #ifdef NEW_LOGGING
91                 LDAP_LOG(( "operation", LDAP_LEVEL_INFO, "do_delete: conn %d: "
92                         "Attempt to delete root DSE.\n", conn->c_connid ));
93 #else
94                 Debug( LDAP_DEBUG_ANY, "do_delete: root dse!\n", 0, 0, 0 );
95 #endif
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 );
99                 goto cleanup;
100
101 #ifdef SLAPD_SCHEMA_DN
102         } else if ( strcasecmp( ndn, SLAPD_SCHEMA_DN ) == 0 ) {
103 #ifdef NEW_LOGGING
104                 LDAP_LOG(( "operation", LDAP_LEVEL_INFO, "do_delete: conn %d: "
105                         "Attempt to delete subschema subentry.\n", conn->c_connid ));
106 #else
107                 Debug( LDAP_DEBUG_ANY, "do_delete: subschema subentry!\n", 0, 0, 0 );
108 #endif
109                 /* protocolError would likely be a more appropriate error */
110                 send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
111                         NULL, "cannot delete the root DSE", NULL, NULL );
112                 goto cleanup;
113
114 #endif
115         }
116
117         Statslog( LDAP_DEBUG_STATS, "conn=%ld op=%d DEL dn=\"%s\"\n",
118                 op->o_connid, op->o_opid, dn, 0, 0 );
119
120         manageDSAit = get_manageDSAit( op );
121
122         /*
123          * We could be serving multiple database backends.  Select the
124          * appropriate one, or send a referral to our "referral server"
125          * if we don't hold it.
126          */
127         if ( (be = select_backend( ndn, manageDSAit )) == NULL ) {
128                 struct berval **ref = referral_rewrite( default_referral,
129                         NULL, dn, LDAP_SCOPE_DEFAULT );
130
131                 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
132                         NULL, NULL, ref ? ref : default_referral, NULL );
133
134                 ber_bvecfree( ref );
135                 goto cleanup;
136         }
137
138         /* check restrictions */
139         rc = backend_check_restrictions( be, conn, op, NULL, &text ) ;
140         if( rc != LDAP_SUCCESS ) {
141                 send_ldap_result( conn, op, rc,
142                         NULL, text, NULL, NULL );
143                 goto cleanup;
144         }
145
146         /* check for referrals */
147         rc = backend_check_referrals( be, conn, op, dn, ndn );
148         if ( rc != LDAP_SUCCESS ) {
149                 goto cleanup;
150         }
151
152         /* deref suffix alias if appropriate */
153         ndn = suffix_alias( be, ndn );
154
155         /*
156          * do the delete if 1 && (2 || 3)
157          * 1) there is a delete function implemented in this backend;
158          * 2) this backend is master for what it holds;
159          * 3) it's a replica and the dn supplied is the update_ndn.
160          */
161         if ( be->be_delete ) {
162                 /* do the update here */
163 #ifndef SLAPD_MULTIMASTER
164                 int repl_user = be_isupdate( be, op->o_ndn );
165                 if ( be->be_update_ndn == NULL || repl_user )
166 #endif
167                 {
168                         if ( (*be->be_delete)( be, conn, op, dn, ndn ) == 0 ) {
169 #ifdef SLAPD_MULTIMASTER
170                                 if (be->be_update_ndn == NULL || !repl_user )
171 #endif
172                                 {
173                                         replog( be, op, dn, ndn, NULL );
174                                 }
175                         }
176 #ifndef SLAPD_MULTIMASTER
177                 } else {
178                         struct berval **defref = be->be_update_refs
179                                 ? be->be_update_refs : default_referral;
180                         struct berval **ref = referral_rewrite( default_referral,
181                                 NULL, dn, LDAP_SCOPE_DEFAULT );
182
183                         send_ldap_result( conn, op, rc = LDAP_REFERRAL, NULL, NULL,
184                                 ref ? ref : defref, NULL );
185
186                         ber_bvecfree( ref );
187 #endif
188                 }
189
190         } else {
191                 send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
192                         NULL, "operation not supported within namingContext", NULL, NULL );
193         }
194 cleanup:
195         if( ndn != NULL ) free( ndn );
196         free( dn );
197         return rc;
198 }