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