]> git.sur5r.net Git - openldap/blob - servers/slapd/delete.c
import localtime -> gmtime change from -devel
[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 #include <string.h>
17 #include <sys/types.h>
18 #include <sys/socket.h>
19 #include "slap.h"
20
21 extern Backend  *select_backend();
22
23 extern char     *default_referral;
24
25 void
26 do_delete(
27     Connection  *conn,
28     Operation   *op
29 )
30 {
31         char    *dn, *odn;
32         Backend *be;
33
34         Debug( LDAP_DEBUG_TRACE, "do_delete\n", 0, 0, 0 );
35
36         /*
37          * Parse the delete request.  It looks like this:
38          *
39          *      DelRequest := DistinguishedName
40          */
41
42         if ( ber_scanf( op->o_ber, "a", &dn ) == LBER_ERROR ) {
43                 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
44                 send_ldap_result( conn, op, LDAP_PROTOCOL_ERROR, NULL, "" );
45                 return;
46         }
47         odn = strdup( dn );
48         dn_normalize( dn );
49
50         Debug( LDAP_DEBUG_ARGS, "do_delete: dn (%s)\n", dn, 0, 0 );
51
52         Debug( LDAP_DEBUG_STATS, "DEL dn=\"%s\"\n", dn, 0, 0 );
53
54         /*
55          * We could be serving multiple database backends.  Select the
56          * appropriate one, or send a referral to our "referral server"
57          * if we don't hold it.
58          */
59         if ( (be = select_backend( dn )) == NULL ) {
60                 free( dn );
61                 free( odn );
62                 send_ldap_result( conn, op, LDAP_PARTIAL_RESULTS, NULL,
63                     default_referral );
64                 return;
65         }
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 updatedn.
72          */
73         if ( be->be_delete != NULL ) {
74                 /* do the update here */
75                 if ( be->be_updatedn == NULL || strcasecmp( be->be_updatedn,
76                     op->o_dn ) == 0 ) {
77                         if ( (*be->be_delete)( be, conn, op, dn ) == 0 ) {
78                                 replog( be, LDAP_REQ_DELETE, odn, 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( dn );
90         free( odn );
91 }