| 1 |
/* $OpenLDAP$ */ |
| 2 |
/* This work is part of OpenLDAP Software <http://www.openldap.org/>. |
| 3 |
* |
| 4 |
* Copyright 1999-2024 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 |
metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private; |
| 38 |
metatarget_t *mt; |
| 39 |
metaconn_t *mc = NULL; |
| 40 |
int candidate = -1; |
| 41 |
struct berval mdn = BER_BVNULL; |
| 42 |
dncookie dc; |
| 43 |
int msgid; |
| 44 |
ldap_back_send_t retrying = LDAP_BACK_RETRYING; |
| 45 |
LDAPControl **ctrls = NULL; |
| 46 |
SlapReply *candidates = NULL; |
| 47 |
|
| 48 |
candidates = meta_back_candidates_get( op ); |
| 49 |
mc = meta_back_getconn( op, rs, &candidate, LDAP_BACK_SENDERR, candidates ); |
| 50 |
if ( !mc || !meta_back_dobind( op, rs, mc, LDAP_BACK_SENDERR, candidates ) ) { |
| 51 |
op->o_tmpfree( candidates, op->o_tmpmemctx ); |
| 52 |
return rs->sr_err; |
| 53 |
} |
| 54 |
|
| 55 |
assert( mc->mc_conns[ candidate ].msc_ld != NULL ); |
| 56 |
|
| 57 |
/* |
| 58 |
* Rewrite the compare dn, if needed |
| 59 |
*/ |
| 60 |
mt = mi->mi_targets[ candidate ]; |
| 61 |
dc.target = mt; |
| 62 |
dc.conn = op->o_conn; |
| 63 |
dc.rs = rs; |
| 64 |
dc.ctx = "deleteDN"; |
| 65 |
|
| 66 |
if ( ldap_back_dn_massage( &dc, &op->o_req_dn, &mdn ) ) { |
| 67 |
send_ldap_result( op, rs ); |
| 68 |
goto cleanup; |
| 69 |
} |
| 70 |
|
| 71 |
retry:; |
| 72 |
ctrls = op->o_ctrls; |
| 73 |
if ( meta_back_controls_add( op, rs, mc, candidate, &ctrls ) != LDAP_SUCCESS ) |
| 74 |
{ |
| 75 |
send_ldap_result( op, rs ); |
| 76 |
goto cleanup; |
| 77 |
} |
| 78 |
|
| 79 |
rs->sr_err = ldap_delete_ext( mc->mc_conns[ candidate ].msc_ld, |
| 80 |
mdn.bv_val, ctrls, NULL, &msgid ); |
| 81 |
rs->sr_err = meta_back_op_result( mc, op, rs, candidate, msgid, |
| 82 |
mt->mt_timeout[ SLAP_OP_DELETE ], ( LDAP_BACK_SENDRESULT | retrying ) ); |
| 83 |
if ( rs->sr_err == LDAP_UNAVAILABLE && retrying ) { |
| 84 |
retrying &= ~LDAP_BACK_RETRYING; |
| 85 |
if ( meta_back_retry( op, rs, &mc, candidate, LDAP_BACK_SENDERR, candidates ) ) { |
| 86 |
/* if the identity changed, there might be need to re-authz */ |
| 87 |
(void)mi->mi_ldap_extra->controls_free( op, rs, &ctrls ); |
| 88 |
goto retry; |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
cleanup:; |
| 93 |
(void)mi->mi_ldap_extra->controls_free( op, rs, &ctrls ); |
| 94 |
|
| 95 |
if ( mdn.bv_val != op->o_req_dn.bv_val ) { |
| 96 |
free( mdn.bv_val ); |
| 97 |
BER_BVZERO( &mdn ); |
| 98 |
} |
| 99 |
|
| 100 |
if ( mc ) { |
| 101 |
meta_back_release_conn( mi, mc ); |
| 102 |
} |
| 103 |
|
| 104 |
op->o_tmpfree( candidates, op->o_tmpmemctx ); |
| 105 |
return rs->sr_err; |
| 106 |
} |
| 107 |
|