]> git.sur5r.net Git - openldap/blob - servers/slapd/delete.c
Rework BER decoding with lieu of LDAPv3 controls (coming soon).
[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 #ifdef GET_CTRLS
46         if( get_ctrls( conn, op, 1 ) == -1 ) {
47                 free( ndn );
48                 Debug( LDAP_DEBUG_ANY, "do_add: get_ctrls failed\n", 0, 0, 0 );
49                 return;
50         } 
51 #endif
52
53         Debug( LDAP_DEBUG_ARGS, "do_delete: dn (%s)\n", ndn, 0, 0 );
54
55         dn_normalize_case( ndn );
56
57         Debug( LDAP_DEBUG_STATS, "DEL dn=\"%s\"\n", ndn, 0, 0 );
58
59         /*
60          * We could be serving multiple database backends.  Select the
61          * appropriate one, or send a referral to our "referral server"
62          * if we don't hold it.
63          */
64         if ( (be = select_backend( ndn )) == NULL ) {
65                 free( ndn );
66                 send_ldap_result( conn, op, LDAP_PARTIAL_RESULTS, NULL,
67                     default_referral );
68                 return;
69         }
70
71         /* alias suffix if approp */
72         ndn = suffixAlias( ndn, op, be );
73
74         /*
75          * do the delete if 1 && (2 || 3)
76          * 1) there is a delete function implemented in this backend;
77          * 2) this backend is master for what it holds;
78          * 3) it's a replica and the dn supplied is the update_ndn.
79          */
80         if ( be->be_delete ) {
81                 /* do the update here */
82                 if ( be->be_update_ndn == NULL ||
83                         strcmp( be->be_update_ndn, op->o_ndn ) == 0 )
84                 {
85                         if ( (*be->be_delete)( be, conn, op, ndn ) == 0 ) {
86                                 replog( be, LDAP_REQ_DELETE, ndn, NULL, 0 );
87                         }
88                 } else {
89                         send_ldap_result( conn, op, LDAP_PARTIAL_RESULTS, NULL,
90                             default_referral );
91                 }
92         } else {
93                 send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
94                     "Function not implemented" );
95         }
96
97         free( ndn );
98 }