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