]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldap/delete.c
31667a801e1130c059936c7f5e7e75fb3f562b36
[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-2017 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         ldapinfo_t              *li = (ldapinfo_t *)op->o_bd->be_private;
40
41         ldapconn_t              *lc = NULL;
42         ber_int_t               msgid;
43         LDAPControl             **ctrls = NULL;
44         ldap_back_send_t        retrying = LDAP_BACK_RETRYING;
45         int                     rc = LDAP_SUCCESS;
46
47         if ( !ldap_back_dobind( &lc, op, rs, LDAP_BACK_SENDERR ) ) {
48                 return rs->sr_err;
49         }
50
51 retry:
52         ctrls = op->o_ctrls;
53         rc = ldap_back_controls_add( op, rs, lc, &ctrls );
54         if ( rc != LDAP_SUCCESS ) {
55                 send_ldap_result( op, rs );
56                 goto cleanup;
57         }
58
59         rs->sr_err = ldap_delete_ext( lc->lc_ld, op->o_req_dn.bv_val,
60                         ctrls, NULL, &msgid );
61         rc = ldap_back_op_result( lc, op, rs, msgid,
62                 li->li_timeout[ SLAP_OP_DELETE ],
63                 ( LDAP_BACK_SENDRESULT | retrying ) );
64         if ( rs->sr_err == LDAP_UNAVAILABLE && retrying ) {
65                 retrying &= ~LDAP_BACK_RETRYING;
66                 if ( ldap_back_retry( &lc, op, rs, LDAP_BACK_SENDERR ) ) {
67                         /* if the identity changed, there might be need to re-authz */
68                         (void)ldap_back_controls_free( op, rs, &ctrls );
69                         goto retry;
70                 }
71         }
72
73         ldap_pvt_thread_mutex_lock( &li->li_counter_mutex );
74         ldap_pvt_mp_add( li->li_ops_completed[ SLAP_OP_DELETE ], 1 );
75         ldap_pvt_thread_mutex_unlock( &li->li_counter_mutex );
76
77 cleanup:
78         (void)ldap_back_controls_free( op, rs, &ctrls );
79
80         if ( lc != NULL ) {
81                 ldap_back_release_conn( li, lc );
82         }
83
84         return rs->sr_err;
85 }