]> git.sur5r.net Git - openldap/blob - servers/slapd/delete.c
merged with autoconf branch
[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 "portable.h"
14
15 #include <stdio.h>
16
17 #include <ac/string.h>
18 #include <ac/socket.h>
19
20 #include "slap.h"
21
22 extern Backend  *select_backend();
23 extern char     *suffixAlias();
24
25 extern char     *default_referral;
26
27 void
28 do_delete(
29     Connection  *conn,
30     Operation   *op
31 )
32 {
33         char    *dn, *odn;
34         Backend *be;
35
36         Debug( LDAP_DEBUG_TRACE, "do_delete\n", 0, 0, 0 );
37
38         /*
39          * Parse the delete request.  It looks like this:
40          *
41          *      DelRequest := DistinguishedName
42          */
43
44         if ( ber_scanf( op->o_ber, "a", &dn ) == LBER_ERROR ) {
45                 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
46                 send_ldap_result( conn, op, LDAP_PROTOCOL_ERROR, NULL, "" );
47                 return;
48         }
49         odn = strdup( dn );
50         dn_normalize( dn );
51
52         Debug( LDAP_DEBUG_ARGS, "do_delete: dn (%s)\n", dn, 0, 0 );
53
54         Debug( LDAP_DEBUG_STATS, "DEL dn=\"%s\"\n", dn, 0, 0 );
55
56         /*
57          * We could be serving multiple database backends.  Select the
58          * appropriate one, or send a referral to our "referral server"
59          * if we don't hold it.
60          */
61         if ( (be = select_backend( dn )) == NULL ) {
62                 free( dn );
63                 free( odn );
64                 send_ldap_result( conn, op, LDAP_PARTIAL_RESULTS, NULL,
65                     default_referral );
66                 return;
67         }
68
69         /* alias suffix if approp */
70         dn = suffixAlias ( dn, op, be );
71
72         /*
73          * do the delete if 1 && (2 || 3)
74          * 1) there is a delete function implemented in this backend;
75          * 2) this backend is master for what it holds;
76          * 3) it's a replica and the dn supplied is the updatedn.
77          */
78         if ( be->be_delete != NULL ) {
79                 /* do the update here */
80                 if ( be->be_updatedn == NULL || strcasecmp( be->be_updatedn,
81                     op->o_dn ) == 0 ) {
82                         if ( (*be->be_delete)( be, conn, op, dn ) == 0 ) {
83                                 replog( be, LDAP_REQ_DELETE, odn, NULL, 0 );
84                         }
85                 } else {
86                         send_ldap_result( conn, op, LDAP_PARTIAL_RESULTS, NULL,
87                             default_referral );
88                 }
89         } else {
90                 send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
91                     "Function not implemented" );
92         }
93
94         free( dn );
95         free( odn );
96 }