]> git.sur5r.net Git - openldap/blob - servers/slapd/back-meta/delete.c
StartTLS (ITS#3507) + chain overlay fixes and improvements
[openldap] / servers / slapd / back-meta / delete.c
1 /* $OpenLDAP$ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3  *
4  * Copyright 1999-2005 The OpenLDAP Foundation.
5  * Portions Copyright 2001-2003 Pierangelo Masarati.
6  * Portions Copyright 1999-2003 Howard Chu.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted only as authorized by the OpenLDAP
11  * Public License.
12  *
13  * A copy of this license is available in the file LICENSE in the
14  * top-level directory of the distribution or, alternatively, at
15  * <http://www.OpenLDAP.org/license.html>.
16  */
17 /* ACKNOWLEDGEMENTS:
18  * This work was initially developed by the Howard Chu for inclusion
19  * in OpenLDAP Software and subsequently enhanced by Pierangelo
20  * Masarati.
21  */
22
23 #include "portable.h"
24
25 #include <stdio.h>
26
27 #include <ac/string.h>
28 #include <ac/socket.h>
29
30 #include "slap.h"
31 #include "../back-ldap/back-ldap.h"
32 #include "back-meta.h"
33
34 int
35 meta_back_delete( Operation *op, SlapReply *rs )
36 {
37         struct metainfo *li = ( struct metainfo * )op->o_bd->be_private;
38         struct metaconn *lc;
39         int candidate = -1;
40         struct berval mdn = BER_BVNULL;
41         dncookie dc;
42
43         lc = meta_back_getconn( op, rs, META_OP_REQUIRE_SINGLE,
44                         &op->o_req_ndn, &candidate );
45         if ( !lc ) {
46                 send_ldap_result( op, rs );
47                 return -1;
48         }
49         
50         if ( !meta_back_dobind( lc, op ) ) {
51                 rs->sr_err = LDAP_UNAVAILABLE;
52
53         } else if ( !meta_back_is_valid( lc, candidate ) ) {
54                 rs->sr_err = LDAP_OTHER;
55         }
56
57         if ( rs->sr_err != LDAP_SUCCESS ) {
58                 send_ldap_result( op, rs );
59                 return -1;
60         }
61
62         /*
63          * Rewrite the compare dn, if needed
64          */
65         dc.rwmap = &li->targets[ candidate ]->mt_rwmap;
66         dc.conn = op->o_conn;
67         dc.rs = rs;
68         dc.ctx = "deleteDN";
69
70         if ( ldap_back_dn_massage( &dc, &op->o_req_dn, &mdn ) ) {
71                 send_ldap_result( op, rs );
72                 return -1;
73         }
74
75         (void)ldap_delete_ext_s( lc->mc_conns[ candidate ].msc_ld, mdn.bv_val,
76                         NULL, NULL );
77
78         if ( mdn.bv_val != op->o_req_dn.bv_val ) {
79                 free( mdn.bv_val );
80                 BER_BVZERO( &mdn );
81         }
82         
83         return meta_back_op_result( lc, op, rs );
84 }
85