]> git.sur5r.net Git - openldap/blob - servers/slapd/delete.c
If dn2id returns ID but id2entry returns NULL, log it.
[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
66         /*
67          * do the delete if 1 && (2 || 3)
68          * 1) there is a delete function implemented in this backend;
69          * 2) this backend is master for what it holds;
70          * 3) it's a replica and the dn supplied is the update_ndn.
71          */
72         if ( be->be_delete != NULL ) {
73                 /* do the update here */
74                 if ( be->be_update_ndn == NULL ||
75                         strcmp( be->be_update_ndn, op->o_ndn ) == 0 )
76                 {
77                         if ( (*be->be_delete)( be, conn, op, ndn ) == 0 ) {
78                                 replog( be, LDAP_REQ_DELETE, ndn, NULL, 0 );
79                         }
80                 } else {
81                         send_ldap_result( conn, op, LDAP_PARTIAL_RESULTS, NULL,
82                             default_referral );
83                 }
84         } else {
85                 send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
86                     "Function not implemented" );
87         }
88
89         free( ndn );
90 }