]> git.sur5r.net Git - openldap/blob - servers/slapd/delete.c
Fixed "faled" typo in debug message
[openldap] / servers / slapd / delete.c
1 /*
2  * Copyright (c) 1995 Regents of the University of Michigan.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted
6  * provided that this notice is preserved and that due credit is given
7  * to the University of Michigan at Ann Arbor. The name of the University
8  * may not be used to endorse or promote products derived from this
9  * software without specific prior written permission. This software
10  * is provided ``as is'' without express or implied warranty.
11  */
12
13 #include <stdio.h>
14 #include <string.h>
15 #include <sys/types.h>
16 #include <sys/socket.h>
17 #include "slap.h"
18
19 extern Backend  *select_backend();
20
21 extern char     *default_referral;
22
23 void
24 do_delete(
25     Connection  *conn,
26     Operation   *op
27 )
28 {
29         char    *dn, *odn;
30         Backend *be;
31
32         Debug( LDAP_DEBUG_TRACE, "do_delete\n", 0, 0, 0 );
33
34         /*
35          * Parse the delete request.  It looks like this:
36          *
37          *      DelRequest := DistinguishedName
38          */
39
40         if ( ber_scanf( op->o_ber, "a", &dn ) == LBER_ERROR ) {
41                 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
42                 send_ldap_result( conn, op, LDAP_PROTOCOL_ERROR, NULL, "" );
43                 return;
44         }
45         odn = strdup( dn );
46         dn_normalize( dn );
47
48         Debug( LDAP_DEBUG_ARGS, "do_delete: dn (%s)\n", dn, 0, 0 );
49
50         Debug( LDAP_DEBUG_STATS, "DEL dn=\"%s\"\n", dn, 0, 0 );
51
52         /*
53          * We could be serving multiple database backends.  Select the
54          * appropriate one, or send a referral to our "referral server"
55          * if we don't hold it.
56          */
57         if ( (be = select_backend( dn )) == NULL ) {
58                 free( dn );
59                 free( odn );
60                 send_ldap_result( conn, op, LDAP_PARTIAL_RESULTS, NULL,
61                     default_referral );
62                 return;
63         }
64
65         /*
66          * do the delete if 1 && (2 || 3)
67          * 1) there is a delete function implemented in this backend;
68          * 2) this backend is master for what it holds;
69          * 3) it's a replica and the dn supplied is the updatedn.
70          */
71         if ( be->be_delete != NULL ) {
72                 /* do the update here */
73                 if ( be->be_updatedn == NULL || strcasecmp( be->be_updatedn,
74                     op->o_dn ) == 0 ) {
75                         if ( (*be->be_delete)( be, conn, op, dn ) == 0 ) {
76                                 replog( be, LDAP_REQ_DELETE, odn, NULL, 0 );
77                         }
78                 } else {
79                         send_ldap_result( conn, op, LDAP_PARTIAL_RESULTS, NULL,
80                             default_referral );
81                 }
82         } else {
83                 send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
84                     "Function not implemented" );
85         }
86
87         free( dn );
88         free( odn );
89 }