xref: /netbsd-src/external/bsd/openldap/dist/servers/slapd/back-asyncmeta/add.c (revision 549b59ed3ccf0d36d3097190a0db27b770f3a839)
1*549b59edSchristos /*	$NetBSD: add.c,v 1.2 2021/08/14 16:14:59 christos Exp $	*/
2e670fd5cSchristos 
3e670fd5cSchristos /* add.c - add request handler for back-asyncmeta */
4e670fd5cSchristos /* $OpenLDAP$ */
5e670fd5cSchristos /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
6e670fd5cSchristos  *
7e670fd5cSchristos  * Copyright 2016-2021 The OpenLDAP Foundation.
8e670fd5cSchristos  * Portions Copyright 2016 Symas Corporation.
9e670fd5cSchristos  * All rights reserved.
10e670fd5cSchristos  *
11e670fd5cSchristos  * Redistribution and use in source and binary forms, with or without
12e670fd5cSchristos  * modification, are permitted only as authorized by the OpenLDAP
13e670fd5cSchristos  * Public License.
14e670fd5cSchristos  *
15e670fd5cSchristos  * A copy of this license is available in the file LICENSE in the
16e670fd5cSchristos  * top-level directory of the distribution or, alternatively, at
17e670fd5cSchristos  * <http://www.OpenLDAP.org/license.html>.
18e670fd5cSchristos  */
19e670fd5cSchristos 
20e670fd5cSchristos /* ACKNOWLEDGEMENTS:
21e670fd5cSchristos  * This work was developed by Symas Corporation
22e670fd5cSchristos  * based on back-meta module for inclusion in OpenLDAP Software.
23e670fd5cSchristos  * This work was sponsored by Ericsson. */
24e670fd5cSchristos 
25e670fd5cSchristos 
26e670fd5cSchristos #include <sys/cdefs.h>
27*549b59edSchristos __RCSID("$NetBSD: add.c,v 1.2 2021/08/14 16:14:59 christos Exp $");
28e670fd5cSchristos 
29e670fd5cSchristos #include "portable.h"
30e670fd5cSchristos 
31e670fd5cSchristos #include <stdio.h>
32e670fd5cSchristos 
33e670fd5cSchristos #include <ac/string.h>
34e670fd5cSchristos #include <ac/socket.h>
35e670fd5cSchristos #include "slap.h"
36e670fd5cSchristos #include "../../../libraries/liblber/lber-int.h"
37e670fd5cSchristos #include "../../../libraries/libldap/ldap-int.h"
38e670fd5cSchristos #include "../back-ldap/back-ldap.h"
39e670fd5cSchristos #include "back-asyncmeta.h"
40e670fd5cSchristos #include "ldap_rq.h"
41e670fd5cSchristos 
42e670fd5cSchristos 
43e670fd5cSchristos int
asyncmeta_error_cleanup(Operation * op,SlapReply * rs,bm_context_t * bc,a_metaconn_t * mc,int candidate)44e670fd5cSchristos asyncmeta_error_cleanup(Operation *op,
45e670fd5cSchristos 			SlapReply *rs,
46e670fd5cSchristos 			bm_context_t *bc,
47e670fd5cSchristos 			a_metaconn_t *mc,
48e670fd5cSchristos 			int candidate)
49e670fd5cSchristos {
50e670fd5cSchristos 	ldap_pvt_thread_mutex_lock( &mc->mc_om_mutex);
51e670fd5cSchristos 	mc->mc_conns[candidate].msc_active--;
52e670fd5cSchristos 	if (asyncmeta_bc_in_queue(mc,bc) == NULL || bc->bc_active > 1) {
53e670fd5cSchristos 		bc->bc_active--;
54e670fd5cSchristos 		ldap_pvt_thread_mutex_unlock( &mc->mc_om_mutex);
55e670fd5cSchristos 		return LDAP_SUCCESS;
56e670fd5cSchristos 	}
57e670fd5cSchristos 	asyncmeta_drop_bc(mc, bc);
58e670fd5cSchristos 	slap_sl_mem_setctx(op->o_threadctx, op->o_tmpmemctx);
59e670fd5cSchristos 	ldap_pvt_thread_mutex_unlock( &mc->mc_om_mutex);
60e670fd5cSchristos 	send_ldap_result(op, rs);
61e670fd5cSchristos 	return LDAP_SUCCESS;
62e670fd5cSchristos }
63e670fd5cSchristos 
64e670fd5cSchristos meta_search_candidate_t
asyncmeta_back_add_start(Operation * op,SlapReply * rs,a_metaconn_t * mc,bm_context_t * bc,int candidate,int do_lock)65e670fd5cSchristos asyncmeta_back_add_start(Operation *op,
66e670fd5cSchristos 			 SlapReply *rs,
67e670fd5cSchristos 			 a_metaconn_t *mc,
68e670fd5cSchristos 			 bm_context_t *bc,
69e670fd5cSchristos 			 int candidate,
70e670fd5cSchristos 			 int do_lock)
71e670fd5cSchristos {
72e670fd5cSchristos 	int		isupdate;
73e670fd5cSchristos 	Attribute	*a;
74e670fd5cSchristos 	int i;
75e670fd5cSchristos 	LDAPMod		**attrs;
76e670fd5cSchristos 	a_dncookie	dc;
77e670fd5cSchristos 	a_metainfo_t	*mi = mc->mc_info;
78e670fd5cSchristos 	a_metatarget_t	*mt = mi->mi_targets[ candidate ];
79e670fd5cSchristos 	struct berval   mdn = {0, NULL};
80e670fd5cSchristos 	meta_search_candidate_t retcode = META_SEARCH_CANDIDATE;
81e670fd5cSchristos 	BerElement *ber = NULL;
82e670fd5cSchristos 	a_metasingleconn_t	*msc = &mc->mc_conns[ candidate ];
83e670fd5cSchristos 	SlapReply		*candidates = bc->candidates;
84e670fd5cSchristos 	ber_int_t	msgid;
85e670fd5cSchristos 	LDAPControl		**ctrls = NULL;
86e670fd5cSchristos 	int rc;
87e670fd5cSchristos 
88e670fd5cSchristos 	dc.op = op;
89e670fd5cSchristos 	dc.target = mt;
90e670fd5cSchristos 	dc.memctx = op->o_tmpmemctx;
91e670fd5cSchristos 	dc.to_from = MASSAGE_REQ;
92e670fd5cSchristos 	asyncmeta_dn_massage( &dc, &op->o_req_dn, &mdn );
93e670fd5cSchristos 
94e670fd5cSchristos 	/* Count number of attributes in entry ( +1 ) */
95e670fd5cSchristos 	for ( i = 1, a = op->ora_e->e_attrs; a; i++, a = a->a_next );
96e670fd5cSchristos 
97e670fd5cSchristos 	/* Create array of LDAPMods for ldap_add() */
98e670fd5cSchristos 	attrs = op->o_tmpalloc(sizeof( LDAPMod * )*i, op->o_tmpmemctx);
99e670fd5cSchristos 
100e670fd5cSchristos 	isupdate = be_shadow_update( op );
101e670fd5cSchristos 	for ( i = 0, a = op->ora_e->e_attrs; a; a = a->a_next ) {
102e670fd5cSchristos 		int j;
103e670fd5cSchristos 
104e670fd5cSchristos 		if ( !isupdate && !get_relax( op ) && a->a_desc->ad_type->sat_no_user_mod  )
105e670fd5cSchristos 		{
106e670fd5cSchristos 			continue;
107e670fd5cSchristos 		}
108e670fd5cSchristos 
109e670fd5cSchristos 		attrs[ i ] = op->o_tmpalloc( sizeof( LDAPMod ), op->o_tmpmemctx );
110e670fd5cSchristos 		if ( attrs[ i ] == NULL ) {
111e670fd5cSchristos 			continue;
112e670fd5cSchristos 		}
113e670fd5cSchristos 		attrs[ i ]->mod_op = LDAP_MOD_BVALUES;
114e670fd5cSchristos 		attrs[ i ]->mod_type = a->a_desc->ad_cname.bv_val;
115e670fd5cSchristos 		j = a->a_numvals;
116e670fd5cSchristos 		attrs[ i ]->mod_bvalues = op->o_tmpalloc( ( j + 1 ) * sizeof( struct berval * ), op->o_tmpmemctx );
117e670fd5cSchristos 		for (j=0; j<a->a_numvals; j++) {
118e670fd5cSchristos 			attrs[ i ]->mod_bvalues[ j ] = op->o_tmpalloc( sizeof( struct berval ), op->o_tmpmemctx );
119e670fd5cSchristos 			if ( a->a_desc->ad_type->sat_syntax == slap_schema.si_syn_distinguishedName )
120e670fd5cSchristos 				asyncmeta_dn_massage( &dc, &a->a_vals[ j ], attrs[ i ]->mod_bvalues[ j ] );
121e670fd5cSchristos 			else
122e670fd5cSchristos 				*attrs[ i ]->mod_bvalues[ j ] = a->a_vals[ j ];
123e670fd5cSchristos 		}
124e670fd5cSchristos 
125e670fd5cSchristos 		attrs[ i ]->mod_bvalues[ j ] = NULL;
126e670fd5cSchristos 		i++;
127e670fd5cSchristos 	}
128e670fd5cSchristos 	attrs[ i ] = NULL;
129e670fd5cSchristos 
130e670fd5cSchristos 	asyncmeta_set_msc_time(msc);
131e670fd5cSchristos 
132e670fd5cSchristos 	ctrls = op->o_ctrls;
133e670fd5cSchristos 	if ( asyncmeta_controls_add( op, rs, mc, candidate, bc->is_root, &ctrls ) != LDAP_SUCCESS )
134e670fd5cSchristos 	{
135e670fd5cSchristos 		candidates[ candidate ].sr_msgid = META_MSGID_IGNORE;
136e670fd5cSchristos 		retcode = META_SEARCH_ERR;
137e670fd5cSchristos 		goto done;
138e670fd5cSchristos 	}
139e670fd5cSchristos 	/* someone might have reset the connection */
140e670fd5cSchristos 	if (!( LDAP_BACK_CONN_ISBOUND( msc )
141e670fd5cSchristos 	       || LDAP_BACK_CONN_ISANON( msc )) || msc->msc_ld == NULL ) {
142e670fd5cSchristos 		Debug( asyncmeta_debug, "msc %p not initialized at %s:%d\n", msc, __FILE__, __LINE__ );
143e670fd5cSchristos 		goto error_unavailable;
144e670fd5cSchristos 	}
145e670fd5cSchristos 
146e670fd5cSchristos 	ber = ldap_build_add_req( msc->msc_ld, mdn.bv_val, attrs, ctrls, NULL, &msgid);
147e670fd5cSchristos 	if (!ber) {
148e670fd5cSchristos 		Debug( asyncmeta_debug, "%s asyncmeta_back_add_start: Operation encoding failed with errno %d\n",
149e670fd5cSchristos 		       op->o_log_prefix, msc->msc_ld->ld_errno );
150e670fd5cSchristos 		rs->sr_err = LDAP_OPERATIONS_ERROR;
151e670fd5cSchristos 		rs->sr_text = "Failed to encode proxied request";
152e670fd5cSchristos 		retcode = META_SEARCH_ERR;
153e670fd5cSchristos 		goto done;
154e670fd5cSchristos 	}
155e670fd5cSchristos 
156e670fd5cSchristos 	if (ber) {
157e670fd5cSchristos 		struct timeval tv = {0, mt->mt_network_timeout*1000};
158e670fd5cSchristos 		ber_socket_t s;
159e670fd5cSchristos 		if (!( LDAP_BACK_CONN_ISBOUND( msc )
160e670fd5cSchristos 		       || LDAP_BACK_CONN_ISANON( msc )) || msc->msc_ld == NULL ) {
161e670fd5cSchristos 			Debug( asyncmeta_debug, "msc %p not initialized at %s:%d\n", msc, __FILE__, __LINE__ );
162e670fd5cSchristos 			goto error_unavailable;
163e670fd5cSchristos 		}
164e670fd5cSchristos 		ldap_get_option( msc->msc_ld, LDAP_OPT_DESC, &s );
165e670fd5cSchristos 		if (s < 0) {
166e670fd5cSchristos 			Debug( asyncmeta_debug, "msc %p not initialized at %s:%d\n", msc, __FILE__, __LINE__ );
167e670fd5cSchristos 			goto error_unavailable;
168e670fd5cSchristos 		}
169e670fd5cSchristos 
170e670fd5cSchristos 		rc = ldap_int_poll( msc->msc_ld, s, &tv, 1);
171e670fd5cSchristos 		if (rc < 0) {
172e670fd5cSchristos 			Debug( asyncmeta_debug, "msc %p not writable within network timeout %s:%d\n", msc, __FILE__, __LINE__ );
173e670fd5cSchristos 			if ((msc->msc_result_time + META_BACK_RESULT_INTERVAL) < slap_get_time()) {
174e670fd5cSchristos 				rc = LDAP_SERVER_DOWN;
175e670fd5cSchristos 			} else {
176e670fd5cSchristos 				goto error_unavailable;
177e670fd5cSchristos 			}
178e670fd5cSchristos 		} else {
179e670fd5cSchristos 			candidates[ candidate ].sr_msgid = msgid;
180e670fd5cSchristos 			rc = ldap_send_initial_request( msc->msc_ld, LDAP_REQ_ADD,
181e670fd5cSchristos 							mdn.bv_val, ber, msgid );
182e670fd5cSchristos 			if (rc == msgid)
183e670fd5cSchristos 				rc = LDAP_SUCCESS;
184e670fd5cSchristos 			else
185e670fd5cSchristos 				rc = LDAP_SERVER_DOWN;
186e670fd5cSchristos 			ber = NULL;
187e670fd5cSchristos 		}
188e670fd5cSchristos 
189e670fd5cSchristos 		switch ( rc ) {
190e670fd5cSchristos 		case LDAP_SUCCESS:
191e670fd5cSchristos 			retcode = META_SEARCH_CANDIDATE;
192e670fd5cSchristos 			asyncmeta_set_msc_time(msc);
193e670fd5cSchristos 			goto done;
194e670fd5cSchristos 
195e670fd5cSchristos 		case LDAP_SERVER_DOWN:
196e670fd5cSchristos 			/* do not lock if called from asyncmeta_handle_bind_result. Also do not reset the connection */
197e670fd5cSchristos 			if (do_lock > 0) {
198e670fd5cSchristos 				ldap_pvt_thread_mutex_lock( &mc->mc_om_mutex);
199e670fd5cSchristos 				asyncmeta_reset_msc(NULL, mc, candidate, 0, __FUNCTION__);
200e670fd5cSchristos 				ldap_pvt_thread_mutex_unlock( &mc->mc_om_mutex);
201e670fd5cSchristos 			}
202e670fd5cSchristos 			/* fall though*/
203e670fd5cSchristos 		default:
204e670fd5cSchristos 			Debug( asyncmeta_debug, "msc %p ldap_send_initial_request failed. %s:%d\n", msc, __FILE__, __LINE__ );
205e670fd5cSchristos 			goto error_unavailable;
206e670fd5cSchristos 		}
207e670fd5cSchristos 	}
208e670fd5cSchristos 
209e670fd5cSchristos error_unavailable:
210e670fd5cSchristos 	if (ber)
211e670fd5cSchristos 		ber_free(ber, 1);
212e670fd5cSchristos 	switch (bc->nretries[candidate]) {
213e670fd5cSchristos 	case -1: /* nretries = forever */
214e670fd5cSchristos 		ldap_pvt_thread_yield();
215e670fd5cSchristos 		retcode = META_SEARCH_NEED_BIND;
216e670fd5cSchristos 		break;
217e670fd5cSchristos 	case 0: /* no retries left */
218e670fd5cSchristos 		candidates[ candidate ].sr_msgid = META_MSGID_IGNORE;
219e670fd5cSchristos 		rs->sr_err = LDAP_UNAVAILABLE;
220e670fd5cSchristos 		rs->sr_text = "Unable to send add request to target";
221e670fd5cSchristos 		retcode = META_SEARCH_ERR;
222e670fd5cSchristos 		break;
223e670fd5cSchristos 	default: /* more retries left - try to rebind and go again */
224e670fd5cSchristos 		retcode = META_SEARCH_NEED_BIND;
225e670fd5cSchristos 		bc->nretries[candidate]--;
226e670fd5cSchristos 		ldap_pvt_thread_yield();
227e670fd5cSchristos 		break;
228e670fd5cSchristos 	}
229e670fd5cSchristos 
230e670fd5cSchristos done:
231e670fd5cSchristos 	(void)mi->mi_ldap_extra->controls_free( op, rs, &ctrls );
232e670fd5cSchristos 
233e670fd5cSchristos 	if ( mdn.bv_val != op->o_req_dn.bv_val ) {
234e670fd5cSchristos 		op->o_tmpfree( mdn.bv_val, op->o_tmpmemctx );
235e670fd5cSchristos 	}
236e670fd5cSchristos 
237e670fd5cSchristos 	Debug( LDAP_DEBUG_TRACE, "%s <<< asyncmeta_back_add_start[%p]=%d\n", op->o_log_prefix, msc, candidates[candidate].sr_msgid );
238e670fd5cSchristos 	return retcode;
239e670fd5cSchristos }
240e670fd5cSchristos 
241e670fd5cSchristos 
242e670fd5cSchristos int
asyncmeta_back_add(Operation * op,SlapReply * rs)243e670fd5cSchristos asyncmeta_back_add( Operation *op, SlapReply *rs )
244e670fd5cSchristos {
245e670fd5cSchristos 	a_metainfo_t	*mi = ( a_metainfo_t * )op->o_bd->be_private;
246e670fd5cSchristos 	a_metatarget_t	*mt;
247e670fd5cSchristos 	a_metaconn_t	*mc;
248e670fd5cSchristos 	int		rc, candidate = -1;
249e670fd5cSchristos 	void *thrctx = op->o_threadctx;
250e670fd5cSchristos 	bm_context_t *bc;
251e670fd5cSchristos 	SlapReply *candidates;
252e670fd5cSchristos 	time_t current_time = slap_get_time();
253e670fd5cSchristos 	int max_pending_ops = (mi->mi_max_pending_ops == 0) ? META_BACK_CFG_MAX_PENDING_OPS : mi->mi_max_pending_ops;
254e670fd5cSchristos 
255e670fd5cSchristos 	Debug(LDAP_DEBUG_TRACE, "==> asyncmeta_back_add: %s\n",
256e670fd5cSchristos 	      op->o_req_dn.bv_val );
257e670fd5cSchristos 
258e670fd5cSchristos 	if (current_time > op->o_time) {
259e670fd5cSchristos 		Debug(asyncmeta_debug, "==> asyncmeta_back_add[%s]: o_time:[%ld], current time: [%ld]\n",
260e670fd5cSchristos 		      op->o_log_prefix, op->o_time, current_time );
261e670fd5cSchristos 	}
262e670fd5cSchristos 
263e670fd5cSchristos 	asyncmeta_new_bm_context(op, rs, &bc, mi->mi_ntargets, mi );
264e670fd5cSchristos 	if (bc == NULL) {
265e670fd5cSchristos 		rs->sr_err = LDAP_OTHER;
266e670fd5cSchristos 		send_ldap_result(op, rs);
267e670fd5cSchristos 		return rs->sr_err;
268e670fd5cSchristos 	}
269e670fd5cSchristos 
270e670fd5cSchristos 	candidates = bc->candidates;
271e670fd5cSchristos 	mc = asyncmeta_getconn( op, rs, candidates, &candidate, LDAP_BACK_DONTSEND, 0);
272e670fd5cSchristos 	if ( !mc || rs->sr_err != LDAP_SUCCESS) {
273e670fd5cSchristos 		send_ldap_result(op, rs);
274e670fd5cSchristos 		return rs->sr_err;
275e670fd5cSchristos 	}
276e670fd5cSchristos 
277e670fd5cSchristos 	mt = mi->mi_targets[ candidate ];
278e670fd5cSchristos 	bc->timeout = mt->mt_timeout[ SLAP_OP_ADD ];
279e670fd5cSchristos 	bc->retrying = LDAP_BACK_RETRYING;
280e670fd5cSchristos 	bc->sendok = ( LDAP_BACK_SENDRESULT | bc->retrying );
281e670fd5cSchristos 	bc->stoptime = op->o_time + bc->timeout;
282e670fd5cSchristos 	bc->bc_active = 1;
283e670fd5cSchristos 
284e670fd5cSchristos 	if (mc->pending_ops >= max_pending_ops) {
285e670fd5cSchristos 		rs->sr_err = LDAP_BUSY;
286e670fd5cSchristos 		rs->sr_text = "Maximum pending ops limit exceeded";
287e670fd5cSchristos 		send_ldap_result(op, rs);
288e670fd5cSchristos 		return rs->sr_err;
289e670fd5cSchristos 	}
290e670fd5cSchristos 
291e670fd5cSchristos 	ldap_pvt_thread_mutex_lock( &mc->mc_om_mutex);
292e670fd5cSchristos 	rc = asyncmeta_add_message_queue(mc, bc);
293e670fd5cSchristos 	mc->mc_conns[candidate].msc_active++;
294e670fd5cSchristos 	ldap_pvt_thread_mutex_unlock( &mc->mc_om_mutex);
295e670fd5cSchristos 
296e670fd5cSchristos 	if (rc != LDAP_SUCCESS) {
297e670fd5cSchristos 		rs->sr_err = LDAP_BUSY;
298e670fd5cSchristos 		rs->sr_text = "Maximum pending ops limit exceeded";
299e670fd5cSchristos 		send_ldap_result(op, rs);
300e670fd5cSchristos 		ldap_pvt_thread_mutex_lock( &mc->mc_om_mutex);
301e670fd5cSchristos 		mc->mc_conns[candidate].msc_active--;
302e670fd5cSchristos 		ldap_pvt_thread_mutex_unlock( &mc->mc_om_mutex);
303e670fd5cSchristos 		goto finish;
304e670fd5cSchristos 	}
305e670fd5cSchristos 
306e670fd5cSchristos retry:
307e670fd5cSchristos 	current_time = slap_get_time();
308e670fd5cSchristos 	if (bc->timeout && bc->stoptime < current_time) {
309e670fd5cSchristos 		int		timeout_err;
310e670fd5cSchristos 		timeout_err = op->o_protocol >= LDAP_VERSION3 ?
311e670fd5cSchristos 			LDAP_ADMINLIMIT_EXCEEDED : LDAP_OTHER;
312e670fd5cSchristos 		rs->sr_err = timeout_err;
313e670fd5cSchristos 		rs->sr_text = "Operation timed out before it was sent to target";
314e670fd5cSchristos 		asyncmeta_error_cleanup(op, rs, bc, mc, candidate);
315e670fd5cSchristos 		goto finish;
316e670fd5cSchristos 	}
317e670fd5cSchristos 
318e670fd5cSchristos 	rc = asyncmeta_dobind_init_with_retry(op, rs, bc, mc, candidate);
319e670fd5cSchristos 	switch (rc)
320e670fd5cSchristos 	{
321e670fd5cSchristos 	case META_SEARCH_CANDIDATE:
322e670fd5cSchristos 		/* target is already bound, just send the request */
323e670fd5cSchristos 		Debug(LDAP_DEBUG_TRACE , "%s asyncmeta_back_add:  "
324e670fd5cSchristos 		       "cnd=\"%d\"\n", op->o_log_prefix, candidate );
325e670fd5cSchristos 
326e670fd5cSchristos 		rc = asyncmeta_back_add_start( op, rs, mc, bc, candidate, 1);
327e670fd5cSchristos 		if (rc == META_SEARCH_ERR) {
328e670fd5cSchristos 			asyncmeta_error_cleanup(op, rs, bc, mc, candidate);
329e670fd5cSchristos 			goto finish;
330e670fd5cSchristos 
331e670fd5cSchristos 		} else if (rc == META_SEARCH_NEED_BIND) {
332e670fd5cSchristos 			goto retry;
333e670fd5cSchristos 		}
334e670fd5cSchristos 		break;
335e670fd5cSchristos 	case META_SEARCH_NOT_CANDIDATE:
336e670fd5cSchristos 		Debug( LDAP_DEBUG_TRACE, "%s asyncmeta_back_add: NOT_CANDIDATE "
337e670fd5cSchristos 		       "cnd=\"%d\"\n", op->o_log_prefix, candidate );
338e670fd5cSchristos 		asyncmeta_error_cleanup(op, rs, bc, mc, candidate);
339e670fd5cSchristos 		goto finish;
340e670fd5cSchristos 
341e670fd5cSchristos 	case META_SEARCH_NEED_BIND:
342e670fd5cSchristos 	case META_SEARCH_BINDING:
343e670fd5cSchristos 		Debug( LDAP_DEBUG_TRACE, "%s asyncmeta_back_add: BINDING "
344e670fd5cSchristos 		       "cnd=\"%d\" %p\n", op->o_log_prefix, candidate , &mc->mc_conns[candidate]);
345e670fd5cSchristos 		/* add the context to the message queue but do not send the request
346e670fd5cSchristos 		   the receiver must send this when we are done binding */
347e670fd5cSchristos 		break;
348e670fd5cSchristos 
349e670fd5cSchristos 	case META_SEARCH_ERR:
350e670fd5cSchristos 		Debug( LDAP_DEBUG_TRACE, "%s asyncmeta_back_add: ERR "
351e670fd5cSchristos 		       "cnd=\"%d\"\n", op->o_log_prefix, candidate );
352e670fd5cSchristos 		asyncmeta_error_cleanup(op, rs, bc, mc, candidate);
353e670fd5cSchristos 		goto finish;
354e670fd5cSchristos 	default:
355e670fd5cSchristos 		assert( 0 );
356e670fd5cSchristos 		break;
357e670fd5cSchristos 	}
358e670fd5cSchristos 
359e670fd5cSchristos 	ldap_pvt_thread_mutex_lock( &mc->mc_om_mutex);
360e670fd5cSchristos 	mc->mc_conns[candidate].msc_active--;
361e670fd5cSchristos 	asyncmeta_start_one_listener(mc, candidates, bc, candidate);
362e670fd5cSchristos 	bc->bc_active--;
363e670fd5cSchristos 	ldap_pvt_thread_mutex_unlock( &mc->mc_om_mutex);
364e670fd5cSchristos 	rs->sr_err = SLAPD_ASYNCOP;
365e670fd5cSchristos finish:
366e670fd5cSchristos 	return rs->sr_err;
367e670fd5cSchristos }
368