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