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