2016-01-31 02:14:29 +08:00
|
|
|
/* delete.c - delete request handler for back-asyncmeta */
|
|
|
|
/* $OpenLDAP$ */
|
|
|
|
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
|
|
|
*
|
2020-01-10 00:50:21 +08:00
|
|
|
* Copyright 2016-2020 The OpenLDAP Foundation.
|
2016-01-31 02:14:29 +08:00
|
|
|
* Portions Copyright 2016 Symas Corporation.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted only as authorized by the OpenLDAP
|
|
|
|
* Public License.
|
|
|
|
*
|
|
|
|
* A copy of this license is available in the file LICENSE in the
|
|
|
|
* top-level directory of the distribution or, alternatively, at
|
|
|
|
* <http://www.OpenLDAP.org/license.html>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* ACKNOWLEDGEMENTS:
|
|
|
|
+ * This work was developed by Symas Corporation
|
|
|
|
+ * based on back-meta module for inclusion in OpenLDAP Software.
|
|
|
|
+ * This work was sponsored by Ericsson. */
|
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <ac/string.h>
|
|
|
|
#include <ac/socket.h>
|
|
|
|
#include "slap.h"
|
|
|
|
#include "../../../libraries/liblber/lber-int.h"
|
|
|
|
#include "../../../libraries/libldap/ldap-int.h"
|
2019-02-18 23:08:52 +08:00
|
|
|
#include "../back-ldap/back-ldap.h"
|
|
|
|
#include "back-asyncmeta.h"
|
2016-01-31 02:14:29 +08:00
|
|
|
|
|
|
|
meta_search_candidate_t
|
|
|
|
asyncmeta_back_delete_start(Operation *op,
|
|
|
|
SlapReply *rs,
|
|
|
|
a_metaconn_t *mc,
|
|
|
|
bm_context_t *bc,
|
2019-02-18 23:08:52 +08:00
|
|
|
int candidate,
|
|
|
|
int do_lock)
|
2016-01-31 02:14:29 +08:00
|
|
|
{
|
|
|
|
a_metainfo_t *mi = mc->mc_info;
|
|
|
|
a_metatarget_t *mt = mi->mi_targets[ candidate ];
|
|
|
|
struct berval mdn = BER_BVNULL;
|
|
|
|
a_dncookie dc;
|
2019-02-18 23:08:52 +08:00
|
|
|
int rc = 0;
|
2016-01-31 02:14:29 +08:00
|
|
|
LDAPControl **ctrls = NULL;
|
|
|
|
meta_search_candidate_t retcode = META_SEARCH_CANDIDATE;
|
|
|
|
BerElement *ber = NULL;
|
|
|
|
a_metasingleconn_t *msc = &mc->mc_conns[ candidate ];
|
|
|
|
SlapReply *candidates = bc->candidates;
|
|
|
|
ber_int_t msgid;
|
|
|
|
|
2019-02-18 23:08:52 +08:00
|
|
|
dc.op = op;
|
2016-01-31 02:14:29 +08:00
|
|
|
dc.target = mt;
|
2019-02-18 23:08:52 +08:00
|
|
|
dc.memctx = op->o_tmpmemctx;
|
|
|
|
dc.to_from = MASSAGE_REQ;
|
2016-01-31 02:14:29 +08:00
|
|
|
|
2019-02-18 23:08:52 +08:00
|
|
|
asyncmeta_dn_massage( &dc, &op->o_req_dn, &mdn );
|
2016-01-31 02:14:29 +08:00
|
|
|
|
2019-02-18 23:08:52 +08:00
|
|
|
asyncmeta_set_msc_time(msc);
|
2016-01-31 02:14:29 +08:00
|
|
|
ctrls = op->o_ctrls;
|
2019-02-18 23:08:52 +08:00
|
|
|
if ( asyncmeta_controls_add( op, rs, mc, candidate, bc->is_root, &ctrls ) != LDAP_SUCCESS )
|
2016-01-31 02:14:29 +08:00
|
|
|
{
|
|
|
|
candidates[ candidate ].sr_msgid = META_MSGID_IGNORE;
|
|
|
|
retcode = META_SEARCH_ERR;
|
|
|
|
goto done;
|
|
|
|
}
|
2019-02-18 23:08:52 +08:00
|
|
|
/* someone might have reset the connection */
|
|
|
|
if (!( LDAP_BACK_CONN_ISBOUND( msc )
|
|
|
|
|| LDAP_BACK_CONN_ISANON( msc )) || msc->msc_ld == NULL ) {
|
|
|
|
Debug( asyncmeta_debug, "msc %p not initialized at %s:%d\n", msc, __FILE__, __LINE__ );
|
|
|
|
goto error_unavailable;
|
|
|
|
}
|
2016-01-31 02:14:29 +08:00
|
|
|
ber = ldap_build_delete_req( msc->msc_ld, mdn.bv_val, ctrls, NULL, &msgid);
|
2019-02-18 23:08:52 +08:00
|
|
|
|
|
|
|
if (!ber) {
|
|
|
|
Debug( asyncmeta_debug, "%s asyncmeta_back_delete_start: Operation encoding failed with errno %d\n",
|
|
|
|
op->o_log_prefix, msc->msc_ld->ld_errno );
|
|
|
|
rs->sr_err = LDAP_OPERATIONS_ERROR;
|
|
|
|
rs->sr_text = "Failed to encode proxied request";
|
|
|
|
retcode = META_SEARCH_ERR;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2016-01-31 02:14:29 +08:00
|
|
|
if (ber) {
|
2019-02-18 23:08:52 +08:00
|
|
|
struct timeval tv = {0, mt->mt_network_timeout*1000};
|
|
|
|
ber_socket_t s;
|
|
|
|
if (!( LDAP_BACK_CONN_ISBOUND( msc )
|
|
|
|
|| LDAP_BACK_CONN_ISANON( msc )) || msc->msc_ld == NULL ) {
|
|
|
|
Debug( asyncmeta_debug, "msc %p not initialized at %s:%d\n", msc, __FILE__, __LINE__ );
|
|
|
|
goto error_unavailable;
|
|
|
|
}
|
|
|
|
|
|
|
|
ldap_get_option( msc->msc_ld, LDAP_OPT_DESC, &s );
|
|
|
|
if (s < 0) {
|
|
|
|
Debug( asyncmeta_debug, "msc %p not initialized at %s:%d\n", msc, __FILE__, __LINE__ );
|
|
|
|
goto error_unavailable;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = ldap_int_poll( msc->msc_ld, s, &tv, 1);
|
|
|
|
if (rc < 0) {
|
|
|
|
Debug( asyncmeta_debug, "msc %p not writable within network timeout %s:%d\n", msc, __FILE__, __LINE__ );
|
|
|
|
if ((msc->msc_result_time + META_BACK_RESULT_INTERVAL) < slap_get_time()) {
|
|
|
|
rc = LDAP_SERVER_DOWN;
|
|
|
|
} else {
|
|
|
|
goto error_unavailable;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
candidates[ candidate ].sr_msgid = msgid;
|
|
|
|
rc = ldap_send_initial_request( msc->msc_ld, LDAP_REQ_DELETE,
|
|
|
|
mdn.bv_val, ber, msgid );
|
|
|
|
if (rc == msgid)
|
|
|
|
rc = LDAP_SUCCESS;
|
|
|
|
else
|
|
|
|
rc = LDAP_SERVER_DOWN;
|
|
|
|
ber = NULL;
|
|
|
|
}
|
2016-01-31 02:14:29 +08:00
|
|
|
|
|
|
|
switch ( rc ) {
|
|
|
|
case LDAP_SUCCESS:
|
|
|
|
retcode = META_SEARCH_CANDIDATE;
|
|
|
|
asyncmeta_set_msc_time(msc);
|
2019-02-18 23:08:52 +08:00
|
|
|
goto done;
|
2016-01-31 02:14:29 +08:00
|
|
|
|
|
|
|
case LDAP_SERVER_DOWN:
|
2019-02-18 23:08:52 +08:00
|
|
|
/* do not lock if called from asyncmeta_handle_bind_result. Also do not reset the connection */
|
|
|
|
if (do_lock > 0) {
|
|
|
|
ldap_pvt_thread_mutex_lock( &mc->mc_om_mutex);
|
|
|
|
asyncmeta_reset_msc(NULL, mc, candidate, 0, __FUNCTION__);
|
|
|
|
ldap_pvt_thread_mutex_unlock( &mc->mc_om_mutex);
|
2016-01-31 02:14:29 +08:00
|
|
|
}
|
2019-02-18 23:08:52 +08:00
|
|
|
/* fall though*/
|
2016-01-31 02:14:29 +08:00
|
|
|
default:
|
2019-02-18 23:08:52 +08:00
|
|
|
Debug( asyncmeta_debug, "msc %p ldap_send_initial_request failed. %s:%d\n", msc, __FILE__, __LINE__ );
|
|
|
|
goto error_unavailable;
|
2016-01-31 02:14:29 +08:00
|
|
|
}
|
|
|
|
}
|
2019-02-18 23:08:52 +08:00
|
|
|
|
|
|
|
error_unavailable:
|
|
|
|
if (ber)
|
|
|
|
ber_free(ber, 1);
|
|
|
|
switch (bc->nretries[candidate]) {
|
|
|
|
case -1: /* nretries = forever */
|
|
|
|
retcode = META_SEARCH_NEED_BIND;
|
|
|
|
ldap_pvt_thread_yield();
|
|
|
|
break;
|
|
|
|
case 0: /* no retries left */
|
|
|
|
candidates[ candidate ].sr_msgid = META_MSGID_IGNORE;
|
|
|
|
rs->sr_err = LDAP_UNAVAILABLE;
|
|
|
|
rs->sr_text = "Unable to send delete request to target";
|
|
|
|
retcode = META_SEARCH_ERR;
|
|
|
|
break;
|
|
|
|
default: /* more retries left - try to rebind and go again */
|
|
|
|
retcode = META_SEARCH_NEED_BIND;
|
|
|
|
bc->nretries[candidate]--;
|
|
|
|
ldap_pvt_thread_yield();
|
|
|
|
break;
|
|
|
|
}
|
2016-01-31 02:14:29 +08:00
|
|
|
done:
|
|
|
|
(void)mi->mi_ldap_extra->controls_free( op, rs, &ctrls );
|
|
|
|
|
|
|
|
if ( mdn.bv_val != op->o_req_dn.bv_val ) {
|
2019-02-18 23:08:52 +08:00
|
|
|
op->o_tmpfree( mdn.bv_val, op->o_tmpmemctx );
|
2016-01-31 02:14:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "%s <<< asyncmeta_back_delete_start[%p]=%d\n", op->o_log_prefix, msc, candidates[candidate].sr_msgid );
|
|
|
|
return retcode;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
asyncmeta_back_delete( Operation *op, SlapReply *rs )
|
|
|
|
{
|
|
|
|
a_metainfo_t *mi = ( a_metainfo_t * )op->o_bd->be_private;
|
|
|
|
a_metatarget_t *mt;
|
|
|
|
a_metaconn_t *mc;
|
|
|
|
int rc, candidate = -1;
|
2019-02-18 23:08:52 +08:00
|
|
|
void *thrctx = op->o_threadctx;
|
2016-01-31 02:14:29 +08:00
|
|
|
bm_context_t *bc;
|
|
|
|
SlapReply *candidates;
|
2019-02-18 23:08:52 +08:00
|
|
|
time_t current_time = slap_get_time();
|
|
|
|
|
|
|
|
int max_pending_ops = (mi->mi_max_pending_ops == 0) ? META_BACK_CFG_MAX_PENDING_OPS : mi->mi_max_pending_ops;
|
2016-01-31 02:14:29 +08:00
|
|
|
|
2019-02-18 23:08:52 +08:00
|
|
|
Debug(LDAP_DEBUG_TRACE, "==> asyncmeta_back_delete: %s\n",
|
2019-02-16 00:49:52 +08:00
|
|
|
op->o_req_dn.bv_val );
|
2016-01-31 02:14:29 +08:00
|
|
|
|
2019-02-18 23:08:52 +08:00
|
|
|
if (current_time > op->o_time) {
|
|
|
|
Debug(asyncmeta_debug, "==> asyncmeta_back_delete[%s]: o_time:[%ld], current time: [%ld]\n",
|
|
|
|
op->o_log_prefix, op->o_time, current_time );
|
|
|
|
}
|
|
|
|
|
|
|
|
asyncmeta_new_bm_context(op, rs, &bc, mi->mi_ntargets, mi );
|
2016-01-31 02:14:29 +08:00
|
|
|
if (bc == NULL) {
|
|
|
|
rs->sr_err = LDAP_OTHER;
|
2019-02-18 23:08:52 +08:00
|
|
|
send_ldap_result(op, rs);
|
2016-01-31 02:14:29 +08:00
|
|
|
return rs->sr_err;
|
|
|
|
}
|
|
|
|
|
|
|
|
candidates = bc->candidates;
|
|
|
|
mc = asyncmeta_getconn( op, rs, candidates, &candidate, LDAP_BACK_DONTSEND, 0);
|
|
|
|
if ( !mc || rs->sr_err != LDAP_SUCCESS) {
|
2019-02-18 23:08:52 +08:00
|
|
|
send_ldap_result(op, rs);
|
2016-01-31 02:14:29 +08:00
|
|
|
return rs->sr_err;
|
|
|
|
}
|
|
|
|
|
|
|
|
mt = mi->mi_targets[ candidate ];
|
|
|
|
bc->timeout = mt->mt_timeout[ SLAP_OP_DELETE ];
|
|
|
|
bc->retrying = LDAP_BACK_RETRYING;
|
|
|
|
bc->sendok = ( LDAP_BACK_SENDRESULT | bc->retrying );
|
|
|
|
bc->stoptime = op->o_time + bc->timeout;
|
2019-02-18 23:08:52 +08:00
|
|
|
bc->bc_active = 1;
|
|
|
|
|
|
|
|
if (mc->pending_ops >= max_pending_ops) {
|
|
|
|
rs->sr_err = LDAP_BUSY;
|
|
|
|
rs->sr_text = "Maximum pending ops limit exceeded";
|
|
|
|
send_ldap_result(op, rs);
|
|
|
|
return rs->sr_err;
|
|
|
|
}
|
2016-01-31 02:14:29 +08:00
|
|
|
|
|
|
|
ldap_pvt_thread_mutex_lock( &mc->mc_om_mutex);
|
|
|
|
rc = asyncmeta_add_message_queue(mc, bc);
|
2019-02-18 23:08:52 +08:00
|
|
|
mc->mc_conns[candidate].msc_active++;
|
2016-01-31 02:14:29 +08:00
|
|
|
ldap_pvt_thread_mutex_unlock( &mc->mc_om_mutex);
|
|
|
|
|
|
|
|
if (rc != LDAP_SUCCESS) {
|
|
|
|
rs->sr_err = LDAP_BUSY;
|
|
|
|
rs->sr_text = "Maximum pending ops limit exceeded";
|
2019-02-18 23:08:52 +08:00
|
|
|
send_ldap_result(op, rs);
|
|
|
|
ldap_pvt_thread_mutex_lock( &mc->mc_om_mutex);
|
|
|
|
mc->mc_conns[candidate].msc_active--;
|
|
|
|
ldap_pvt_thread_mutex_unlock( &mc->mc_om_mutex);
|
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
|
|
|
|
retry:
|
|
|
|
if (bc->timeout && bc->stoptime < slap_get_time()) {
|
|
|
|
int timeout_err;
|
|
|
|
timeout_err = op->o_protocol >= LDAP_VERSION3 ?
|
|
|
|
LDAP_ADMINLIMIT_EXCEEDED : LDAP_OTHER;
|
|
|
|
rs->sr_err = timeout_err;
|
|
|
|
rs->sr_text = "Operation timed out before it was sent to target";
|
|
|
|
asyncmeta_error_cleanup(op, rs, bc, mc, candidate);
|
2016-01-31 02:14:29 +08:00
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = asyncmeta_dobind_init_with_retry(op, rs, bc, mc, candidate);
|
|
|
|
switch (rc)
|
|
|
|
{
|
|
|
|
case META_SEARCH_CANDIDATE:
|
|
|
|
/* target is already bound, just send the request */
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "%s asyncmeta_back_delete: "
|
2019-02-18 23:08:52 +08:00
|
|
|
"cnd=\"%d\"\n", op->o_log_prefix, candidate );
|
2016-01-31 02:14:29 +08:00
|
|
|
|
2019-02-18 23:08:52 +08:00
|
|
|
rc = asyncmeta_back_delete_start( op, rs, mc, bc, candidate, 1);
|
2016-01-31 02:14:29 +08:00
|
|
|
if (rc == META_SEARCH_ERR) {
|
2019-02-18 23:08:52 +08:00
|
|
|
asyncmeta_error_cleanup(op, rs, bc, mc, candidate);
|
2016-01-31 02:14:29 +08:00
|
|
|
goto finish;
|
|
|
|
|
2019-02-18 23:08:52 +08:00
|
|
|
} else if (rc == META_SEARCH_NEED_BIND) {
|
|
|
|
goto retry;
|
2016-01-31 02:14:29 +08:00
|
|
|
}
|
2019-02-18 23:08:52 +08:00
|
|
|
break;
|
2016-01-31 02:14:29 +08:00
|
|
|
case META_SEARCH_NOT_CANDIDATE:
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "%s asyncmeta_back_delete: NOT_CANDIDATE "
|
2019-02-18 23:08:52 +08:00
|
|
|
"cnd=\"%d\"\n", op->o_log_prefix, candidate );
|
|
|
|
asyncmeta_error_cleanup(op, rs, bc, mc, candidate);
|
2016-01-31 02:14:29 +08:00
|
|
|
goto finish;
|
|
|
|
|
|
|
|
case META_SEARCH_NEED_BIND:
|
|
|
|
case META_SEARCH_BINDING:
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "%s asyncmeta_back_delete: BINDING "
|
2019-02-18 23:08:52 +08:00
|
|
|
"cnd=\"%d\" %p\n", op->o_log_prefix, candidate , &mc->mc_conns[candidate]);
|
2016-01-31 02:14:29 +08:00
|
|
|
/* Todo add the context to the message queue but do not send the request
|
|
|
|
the receiver must send this when we are done binding */
|
|
|
|
/* question - how would do receiver know to which targets??? */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case META_SEARCH_ERR:
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "%s asyncmeta_back_delete: ERR "
|
2019-02-18 23:08:52 +08:00
|
|
|
"cnd=\"%d\"\n", op->o_log_prefix, candidate );
|
|
|
|
asyncmeta_error_cleanup(op, rs, bc, mc, candidate);
|
2016-01-31 02:14:29 +08:00
|
|
|
goto finish;
|
|
|
|
default:
|
|
|
|
assert( 0 );
|
|
|
|
break;
|
|
|
|
}
|
2019-02-18 23:08:52 +08:00
|
|
|
|
2016-01-31 02:14:29 +08:00
|
|
|
ldap_pvt_thread_mutex_lock( &mc->mc_om_mutex);
|
2019-02-18 23:08:52 +08:00
|
|
|
mc->mc_conns[candidate].msc_active--;
|
2016-02-29 20:01:12 +08:00
|
|
|
asyncmeta_start_one_listener(mc, candidates, bc, candidate);
|
2019-02-18 23:08:52 +08:00
|
|
|
bc->bc_active--;
|
|
|
|
asyncmeta_memctx_toggle(thrctx);
|
2016-01-31 02:14:29 +08:00
|
|
|
ldap_pvt_thread_mutex_unlock( &mc->mc_om_mutex);
|
2019-02-18 23:08:52 +08:00
|
|
|
rs->sr_err = SLAPD_ASYNCOP;
|
2016-01-31 02:14:29 +08:00
|
|
|
finish:
|
|
|
|
return rs->sr_err;
|
|
|
|
}
|