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