]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldap/delete.c
ITS#3647 additional hdb dn2idl fixes
[openldap] / servers / slapd / back-ldap / delete.c
1 /* delete.c - ldap backend delete function */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 2003-2005 The OpenLDAP Foundation.
6  * Portions Copyright 1999-2003 Howard Chu.
7  * Portions Copyright 2000-2003 Pierangelo Masarati.
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted only as authorized by the OpenLDAP
12  * Public License.
13  *
14  * A copy of this license is available in the file LICENSE in the
15  * top-level directory of the distribution or, alternatively, at
16  * <http://www.OpenLDAP.org/license.html>.
17  */
18 /* ACKNOWLEDGEMENTS:
19  * This work was initially developed by the Howard Chu for inclusion
20  * in OpenLDAP Software and subsequently enhanced by Pierangelo
21  * Masarati.
22  */
23
24 #include "portable.h"
25
26 #include <stdio.h>
27
28 #include <ac/string.h>
29 #include <ac/socket.h>
30
31 #include "slap.h"
32 #include "back-ldap.h"
33
34 int
35 ldap_back_delete(
36     Operation   *op,
37     SlapReply   *rs )
38 {
39         struct ldapinfo *li = (struct ldapinfo *) op->o_bd->be_private;
40         struct ldapconn *lc;
41         ber_int_t msgid;
42         dncookie dc;
43         int do_retry = 1;
44         int rc = LDAP_SUCCESS;
45 #ifdef LDAP_BACK_PROXY_AUTHZ 
46         LDAPControl **ctrls = NULL;
47 #endif /* LDAP_BACK_PROXY_AUTHZ */
48
49         struct berval mdn = BER_BVNULL;
50
51         lc = ldap_back_getconn( op, rs );
52         
53         if ( !lc || !ldap_back_dobind( lc, op, rs ) ) {
54                 return( -1 );
55         }
56
57         /*
58          * Rewrite the request dn, if needed
59          */
60         dc.rwmap = &li->rwmap;
61 #ifdef ENABLE_REWRITE
62         dc.conn = op->o_conn;
63         dc.rs = rs;
64         dc.ctx = "deleteDN";
65 #else
66         dc.tofrom = 1;
67         dc.normalized = 0;
68 #endif
69         if ( ldap_back_dn_massage( &dc, &op->o_req_ndn, &mdn ) ) {
70                 send_ldap_result( op, rs );
71                 return -1;
72         }
73
74 #ifdef LDAP_BACK_PROXY_AUTHZ
75         rc = ldap_back_proxy_authz_ctrl( lc, op, rs, &ctrls );
76         if ( rc != LDAP_SUCCESS ) {
77                 send_ldap_result( op, rs );
78                 rc = -1;
79                 goto cleanup;
80         }
81 #endif /* LDAP_BACK_PROXY_AUTHZ */
82
83 retry:
84         rs->sr_err = ldap_delete_ext( lc->ld, mdn.bv_val,
85 #ifdef LDAP_BACK_PROXY_AUTHZ
86                         ctrls,
87 #else /* ! LDAP_BACK_PROXY_AUTHZ */
88                         op->o_ctrls,
89 #endif /* ! LDAP_BACK_PROXY_AUTHZ */
90                         NULL, &msgid );
91         rc = ldap_back_op_result( lc, op, rs, msgid, 1 );
92         if ( rs->sr_err == LDAP_SERVER_DOWN && do_retry ) {
93                 do_retry = 0;
94                 if ( ldap_back_retry (lc, op, rs )) goto retry;
95         }
96
97 #ifdef LDAP_BACK_PROXY_AUTHZ
98 cleanup:
99         if ( ctrls && ctrls != op->o_ctrls ) {
100                 free( ctrls[ 0 ] );
101                 free( ctrls );
102         }
103 #endif /* LDAP_BACK_PROXY_AUTHZ */
104
105         if ( mdn.bv_val != op->o_req_ndn.bv_val ) {
106                 free( mdn.bv_val );
107         }
108
109         return rc;
110 }