Home | History | Annotate | Line # | Download | only in back-asyncmeta
init.c revision 1.1.1.2
      1      1.1  christos /*	$NetBSD: init.c,v 1.1.1.2 2025/09/05 21:09:48 christos Exp $	*/
      2      1.1  christos 
      3      1.1  christos /* init.c - initialization of a back-asyncmeta database */
      4      1.1  christos /* $OpenLDAP$ */
      5      1.1  christos /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
      6      1.1  christos  *
      7  1.1.1.2  christos  * Copyright 2016-2024 The OpenLDAP Foundation.
      8      1.1  christos  * Portions Copyright 2016 Symas Corporation.
      9      1.1  christos  * All rights reserved.
     10      1.1  christos  *
     11      1.1  christos  * Redistribution and use in source and binary forms, with or without
     12      1.1  christos  * modification, are permitted only as authorized by the OpenLDAP
     13      1.1  christos  * Public License.
     14      1.1  christos  *
     15      1.1  christos  * A copy of this license is available in the file LICENSE in the
     16      1.1  christos  * top-level directory of the distribution or, alternatively, at
     17      1.1  christos  * <http://www.OpenLDAP.org/license.html>.
     18      1.1  christos  */
     19      1.1  christos 
     20      1.1  christos /* ACKNOWLEDGEMENTS:
     21      1.1  christos  * This work was developed by Symas Corporation
     22      1.1  christos  * based on back-meta module for inclusion in OpenLDAP Software.
     23      1.1  christos  * This work was sponsored by Ericsson. */
     24      1.1  christos 
     25      1.1  christos #include <sys/cdefs.h>
     26      1.1  christos __RCSID("$NetBSD: init.c,v 1.1.1.2 2025/09/05 21:09:48 christos Exp $");
     27      1.1  christos 
     28      1.1  christos #include "portable.h"
     29      1.1  christos 
     30      1.1  christos #include <stdio.h>
     31      1.1  christos 
     32      1.1  christos #include <ac/string.h>
     33      1.1  christos #include <ac/socket.h>
     34      1.1  christos 
     35      1.1  christos #include "slap.h"
     36      1.1  christos #include "slap-config.h"
     37      1.1  christos #include "../back-ldap/back-ldap.h"
     38      1.1  christos #include "back-asyncmeta.h"
     39      1.1  christos 
     40      1.1  christos int asyncmeta_debug;
     41      1.1  christos 
     42      1.1  christos int
     43      1.1  christos asyncmeta_back_open(
     44      1.1  christos 	BackendInfo	*bi )
     45      1.1  christos {
     46      1.1  christos 	/* FIXME: need to remove the pagedResults, and likely more... */
     47      1.1  christos 	bi->bi_controls = slap_known_controls;
     48      1.1  christos 
     49      1.1  christos 	return 0;
     50      1.1  christos }
     51      1.1  christos 
     52      1.1  christos int
     53      1.1  christos asyncmeta_back_initialize(
     54      1.1  christos 	BackendInfo	*bi )
     55      1.1  christos {
     56      1.1  christos 	int rc;
     57      1.1  christos 	struct berval debugbv = BER_BVC("asyncmeta");
     58      1.1  christos 
     59      1.1  christos 	rc = slap_loglevel_get( &debugbv, &asyncmeta_debug );
     60      1.1  christos 	if ( rc ) {
     61      1.1  christos 		return rc;
     62      1.1  christos 	}
     63      1.1  christos 
     64      1.1  christos 	bi->bi_flags =
     65      1.1  christos #if 0
     66      1.1  christos 	/* this is not (yet) set essentially because back-meta does not
     67      1.1  christos 	 * directly support extended operations... */
     68      1.1  christos #ifdef LDAP_DYNAMIC_OBJECTS
     69      1.1  christos 		/* this is set because all the support a proxy has to provide
     70      1.1  christos 		 * is the capability to forward the refresh exop, and to
     71      1.1  christos 		 * pass thru entries that contain the dynamicObject class
     72      1.1  christos 		 * and the entryTtl attribute */
     73      1.1  christos 		SLAP_BFLAG_DYNAMIC |
     74      1.1  christos #endif /* LDAP_DYNAMIC_OBJECTS */
     75      1.1  christos #endif
     76      1.1  christos 
     77      1.1  christos 		/* back-meta recognizes RFC4525 increment;
     78      1.1  christos 		 * let the remote server complain, if needed (ITS#5912) */
     79      1.1  christos 		SLAP_BFLAG_INCREMENT;
     80      1.1  christos 
     81      1.1  christos 	bi->bi_open = asyncmeta_back_open;
     82      1.1  christos 	bi->bi_config = 0;
     83      1.1  christos 	bi->bi_close = 0;
     84      1.1  christos 	bi->bi_destroy = 0;
     85      1.1  christos 
     86      1.1  christos 	bi->bi_db_init = asyncmeta_back_db_init;
     87      1.1  christos 	bi->bi_db_config = config_generic_wrapper;
     88      1.1  christos 	bi->bi_db_open = asyncmeta_back_db_open;
     89      1.1  christos 	bi->bi_db_close = asyncmeta_back_db_close;
     90      1.1  christos 	bi->bi_db_destroy = asyncmeta_back_db_destroy;
     91      1.1  christos 
     92      1.1  christos 	bi->bi_op_bind = asyncmeta_back_bind;
     93      1.1  christos 	bi->bi_op_unbind = 0;
     94      1.1  christos 	bi->bi_op_search = asyncmeta_back_search;
     95      1.1  christos 	bi->bi_op_compare = asyncmeta_back_compare;
     96      1.1  christos 	bi->bi_op_modify = asyncmeta_back_modify;
     97      1.1  christos 	bi->bi_op_modrdn = asyncmeta_back_modrdn;
     98      1.1  christos 	bi->bi_op_add = asyncmeta_back_add;
     99      1.1  christos 	bi->bi_op_delete = asyncmeta_back_delete;
    100      1.1  christos 	bi->bi_op_abandon = 0;
    101      1.1  christos 
    102      1.1  christos 	bi->bi_extended = 0;
    103      1.1  christos 
    104      1.1  christos 	bi->bi_chk_referrals = 0;
    105      1.1  christos 
    106      1.1  christos 	bi->bi_connection_init = 0;
    107      1.1  christos 	bi->bi_connection_destroy =  0 /* asyncmeta_back_conn_destroy */;
    108      1.1  christos 
    109      1.1  christos 	return asyncmeta_back_init_cf( bi );
    110      1.1  christos }
    111      1.1  christos 
    112      1.1  christos int
    113      1.1  christos asyncmeta_back_db_init(
    114      1.1  christos 	Backend		*be,
    115      1.1  christos 	ConfigReply	*cr)
    116      1.1  christos {
    117      1.1  christos 	a_metainfo_t	*mi;
    118      1.1  christos 	int		i;
    119      1.1  christos 	BackendInfo	*bi;
    120      1.1  christos 
    121      1.1  christos 	bi = backend_info( "ldap" );
    122      1.1  christos 	if ( !bi || !bi->bi_extra ) {
    123      1.1  christos 		Debug( LDAP_DEBUG_ANY,
    124      1.1  christos 			"asyncmeta_back_db_init: needs back-ldap\n" );
    125      1.1  christos 		return 1;
    126      1.1  christos 	}
    127      1.1  christos 
    128      1.1  christos 	mi = ch_calloc( 1, sizeof( a_metainfo_t ) );
    129      1.1  christos 	if ( mi == NULL ) {
    130      1.1  christos 		return -1;
    131      1.1  christos 	}
    132      1.1  christos 
    133      1.1  christos 	/* set default flags */
    134      1.1  christos 	mi->mi_flags =
    135      1.1  christos 		META_BACK_F_DEFER_ROOTDN_BIND
    136      1.1  christos 		| META_BACK_F_PROXYAUTHZ_ALWAYS
    137      1.1  christos 		| META_BACK_F_PROXYAUTHZ_ANON
    138      1.1  christos 		| META_BACK_F_PROXYAUTHZ_NOANON;
    139      1.1  christos 
    140      1.1  christos 	/*
    141      1.1  christos 	 * At present the default is no default target;
    142      1.1  christos 	 * this may change
    143      1.1  christos 	 */
    144      1.1  christos 	mi->mi_defaulttarget = META_DEFAULT_TARGET_NONE;
    145      1.1  christos 	mi->mi_bind_timeout.tv_sec = 0;
    146      1.1  christos 	mi->mi_bind_timeout.tv_usec = META_BIND_TIMEOUT;
    147      1.1  christos 
    148      1.1  christos 	mi->mi_rebind_f = asyncmeta_back_default_rebind;
    149      1.1  christos 	mi->mi_urllist_f = asyncmeta_back_default_urllist;
    150      1.1  christos 
    151      1.1  christos 	ldap_pvt_thread_mutex_init( &mi->mi_cache.mutex );
    152      1.1  christos 
    153      1.1  christos 	/* safe default */
    154      1.1  christos 	mi->mi_nretries = META_RETRY_DEFAULT;
    155      1.1  christos 	mi->mi_version = LDAP_VERSION3;
    156      1.1  christos 
    157      1.1  christos 	for ( i = 0; i < SLAP_OP_LAST; i++ ) {
    158      1.1  christos 		mi->mi_timeout[ i ] = META_BACK_CFG_DEFAULT_OPS_TIMEOUT;
    159      1.1  christos 	}
    160      1.1  christos 
    161      1.1  christos 	for ( i = LDAP_BACK_PCONN_FIRST; i < LDAP_BACK_PCONN_LAST; i++ ) {
    162      1.1  christos 		mi->mi_conn_priv[ i ].mic_num = 0;
    163      1.1  christos 		LDAP_TAILQ_INIT( &mi->mi_conn_priv[ i ].mic_priv );
    164      1.1  christos 	}
    165      1.1  christos 	mi->mi_conn_priv_max = LDAP_BACK_CONN_PRIV_DEFAULT;
    166      1.1  christos 
    167      1.1  christos 	mi->mi_ldap_extra = (ldap_extra_t *)bi->bi_extra;
    168      1.1  christos 	ldap_pvt_thread_mutex_init( &mi->mi_mc_mutex);
    169      1.1  christos 
    170      1.1  christos 	be->be_private = mi;
    171      1.1  christos 	be->be_cf_ocs = be->bd_info->bi_cf_ocs;
    172      1.1  christos 
    173      1.1  christos 	return 0;
    174      1.1  christos }
    175      1.1  christos 
    176      1.1  christos int
    177      1.1  christos asyncmeta_target_finish(
    178      1.1  christos 	a_metainfo_t *mi,
    179      1.1  christos 	a_metatarget_t *mt,
    180      1.1  christos 	const char *log,
    181      1.1  christos 	char *msg,
    182      1.1  christos 	size_t msize
    183      1.1  christos )
    184      1.1  christos {
    185      1.1  christos 	slap_bindconf	sb = { BER_BVNULL };
    186      1.1  christos 	int rc;
    187      1.1  christos 
    188      1.1  christos 	ber_str2bv( mt->mt_uri, 0, 0, &sb.sb_uri );
    189      1.1  christos 	sb.sb_version = mt->mt_version;
    190      1.1  christos 	sb.sb_method = LDAP_AUTH_SIMPLE;
    191      1.1  christos 	BER_BVSTR( &sb.sb_binddn, "" );
    192      1.1  christos 
    193      1.1  christos 	if ( META_BACK_TGT_T_F_DISCOVER( mt ) ) {
    194      1.1  christos 		rc = slap_discover_feature( &sb,
    195      1.1  christos 				slap_schema.si_ad_supportedFeatures->ad_cname.bv_val,
    196      1.1  christos 				LDAP_FEATURE_ABSOLUTE_FILTERS );
    197      1.1  christos 		if ( rc == LDAP_COMPARE_TRUE ) {
    198      1.1  christos 			mt->mt_flags |= LDAP_BACK_F_T_F;
    199      1.1  christos 		}
    200      1.1  christos 	}
    201      1.1  christos 
    202      1.1  christos 	if ( META_BACK_TGT_CANCEL_DISCOVER( mt ) ) {
    203      1.1  christos 		rc = slap_discover_feature( &sb,
    204      1.1  christos 				slap_schema.si_ad_supportedExtension->ad_cname.bv_val,
    205      1.1  christos 				LDAP_EXOP_CANCEL );
    206      1.1  christos 		if ( rc == LDAP_COMPARE_TRUE ) {
    207      1.1  christos 			mt->mt_flags |= LDAP_BACK_F_CANCEL_EXOP;
    208      1.1  christos 		}
    209      1.1  christos 	}
    210      1.1  christos 
    211      1.1  christos 	if ( !( mt->mt_idassert_flags & LDAP_BACK_AUTH_OVERRIDE )
    212      1.1  christos 		|| mt->mt_idassert_authz != NULL )
    213      1.1  christos 	{
    214      1.1  christos 		mi->mi_flags &= ~META_BACK_F_PROXYAUTHZ_ALWAYS;
    215      1.1  christos 	}
    216      1.1  christos 
    217      1.1  christos 	if ( ( mt->mt_idassert_flags & LDAP_BACK_AUTH_AUTHZ_ALL )
    218      1.1  christos 		&& !( mt->mt_idassert_flags & LDAP_BACK_AUTH_PRESCRIPTIVE ) )
    219      1.1  christos 	{
    220      1.1  christos 		Debug(LDAP_DEBUG_ANY,
    221      1.1  christos 		      "%s: inconsistent idassert configuration " "(likely authz=\"*\" used with \"non-prescriptive\" flag) (target %s)\n",
    222      1.1  christos 		      log, mt->mt_uri );
    223      1.1  christos 		return 1;
    224      1.1  christos 	}
    225      1.1  christos 
    226      1.1  christos 	if ( !( mt->mt_idassert_flags & LDAP_BACK_AUTH_AUTHZ_ALL ) )
    227      1.1  christos 	{
    228      1.1  christos 		mi->mi_flags &= ~META_BACK_F_PROXYAUTHZ_ANON;
    229      1.1  christos 	}
    230      1.1  christos 
    231      1.1  christos 	if ( ( mt->mt_idassert_flags & LDAP_BACK_AUTH_PRESCRIPTIVE ) )
    232      1.1  christos 	{
    233      1.1  christos 		mi->mi_flags &= ~META_BACK_F_PROXYAUTHZ_NOANON;
    234      1.1  christos 	}
    235      1.1  christos 
    236      1.1  christos 	return 0;
    237      1.1  christos }
    238      1.1  christos 
    239      1.1  christos int
    240      1.1  christos asyncmeta_back_db_open(
    241      1.1  christos 	Backend		*be,
    242      1.1  christos 	ConfigReply	*cr )
    243      1.1  christos {
    244      1.1  christos 	a_metainfo_t	*mi = (a_metainfo_t *)be->be_private;
    245      1.1  christos 	char msg[SLAP_TEXT_BUFLEN];
    246      1.1  christos 	int		i;
    247      1.1  christos 
    248  1.1.1.2  christos 	mi->mi_disabled = 0;
    249      1.1  christos 	if ( mi->mi_ntargets == 0 ) {
    250      1.1  christos 
    251      1.1  christos 		Debug( LDAP_DEBUG_ANY,
    252      1.1  christos 			"asyncmeta_back_db_open: no targets defined\n" );
    253      1.1  christos 	}
    254  1.1.1.2  christos 
    255      1.1  christos 	for ( i = 0; i < mi->mi_ntargets; i++ ) {
    256      1.1  christos 		a_metatarget_t	*mt = mi->mi_targets[ i ];
    257      1.1  christos 		if ( asyncmeta_target_finish( mi, mt,
    258  1.1.1.2  christos 					      "asyncmeta_back_db_open", msg, sizeof( msg ))) {
    259      1.1  christos 			return 1;
    260  1.1.1.2  christos 		}
    261  1.1.1.2  christos 	}
    262  1.1.1.2  christos 
    263  1.1.1.2  christos 	if ( mi->mi_conns == NULL ) {
    264  1.1.1.2  christos 		mi->mi_num_conns = (mi->mi_max_target_conns == 0) ? META_BACK_CFG_MAX_TARGET_CONNS : mi->mi_max_target_conns;
    265  1.1.1.2  christos 		assert(mi->mi_num_conns > 0);
    266  1.1.1.2  christos 		mi->mi_conns = ch_calloc( mi->mi_num_conns, sizeof( a_metaconn_t ));
    267  1.1.1.2  christos 		for (i = 0; i < mi->mi_num_conns; i++) {
    268  1.1.1.2  christos 			a_metaconn_t *mc = &mi->mi_conns[i];
    269  1.1.1.2  christos 			ldap_pvt_thread_mutex_init( &mc->mc_om_mutex);
    270  1.1.1.2  christos 			mc->mc_authz_target = META_BOUND_NONE;
    271  1.1.1.2  christos 
    272  1.1.1.2  christos 			if ( mi->mi_ntargets > 0 ) {
    273  1.1.1.2  christos 				mc->mc_conns = ch_calloc( mi->mi_ntargets, sizeof( a_metasingleconn_t ));
    274  1.1.1.2  christos 			} else {
    275  1.1.1.2  christos 				mc->mc_conns = NULL;
    276  1.1.1.2  christos 			}
    277  1.1.1.2  christos 
    278  1.1.1.2  christos 			mc->mc_info = mi;
    279  1.1.1.2  christos 			LDAP_STAILQ_INIT( &mc->mc_om_list );
    280  1.1.1.2  christos 		}
    281  1.1.1.2  christos 
    282  1.1.1.2  christos 
    283  1.1.1.2  christos 		ber_dupbv ( &mi->mi_suffix, &be->be_suffix[0] );
    284  1.1.1.2  christos 
    285  1.1.1.2  christos 		if ( ( slapMode & SLAP_SERVER_MODE ) && mi->mi_ntargets > 0 ) {
    286  1.1.1.2  christos 			ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
    287  1.1.1.2  christos 			mi->mi_task = ldap_pvt_runqueue_insert( &slapd_rq, 1,
    288  1.1.1.2  christos 													asyncmeta_timeout_loop, mi, "asyncmeta_timeout_loop", mi->mi_suffix.bv_val );
    289  1.1.1.2  christos 			ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
    290  1.1.1.2  christos 		}
    291      1.1  christos 	}
    292      1.1  christos 	return 0;
    293      1.1  christos }
    294      1.1  christos 
    295      1.1  christos /*
    296      1.1  christos  * asyncmeta_back_conn_free()
    297      1.1  christos  *
    298      1.1  christos  * actually frees a connection; the reference count must be 0,
    299      1.1  christos  * and it must not (or no longer) be in the cache.
    300      1.1  christos  */
    301      1.1  christos void
    302      1.1  christos asyncmeta_back_conn_free(
    303      1.1  christos 	void 		*v_mc )
    304      1.1  christos {
    305      1.1  christos 	a_metaconn_t		*mc = v_mc;
    306      1.1  christos 
    307      1.1  christos 	assert( mc != NULL );
    308      1.1  christos 	ldap_pvt_thread_mutex_destroy( &mc->mc_om_mutex );
    309      1.1  christos 	free( mc );
    310      1.1  christos }
    311      1.1  christos 
    312  1.1.1.2  christos void
    313      1.1  christos asyncmeta_back_clear_miconns( a_metainfo_t *mi )
    314      1.1  christos {
    315      1.1  christos 	int i, j;
    316      1.1  christos 	a_metaconn_t *mc;
    317  1.1.1.2  christos 	if ( mi->mi_conns != NULL ) {
    318  1.1.1.2  christos 		for (i = 0; i < mi->mi_num_conns; i++) {
    319  1.1.1.2  christos 			mc = &mi->mi_conns[i];
    320  1.1.1.2  christos 			for (j = 0; j < mi->mi_ntargets; j ++) {
    321  1.1.1.2  christos 				asyncmeta_clear_one_msc(NULL, mc, j, 1, __FUNCTION__);
    322  1.1.1.2  christos 			}
    323  1.1.1.2  christos 
    324  1.1.1.2  christos 			if ( mc->mc_conns )
    325  1.1.1.2  christos 				free( mc->mc_conns );
    326  1.1.1.2  christos 			ldap_pvt_thread_mutex_destroy( &mc->mc_om_mutex );
    327      1.1  christos 		}
    328  1.1.1.2  christos 		free(mi->mi_conns);
    329      1.1  christos 	}
    330  1.1.1.2  christos 	mi->mi_conns = NULL;
    331  1.1.1.2  christos 	mi->mi_num_conns = 0;
    332      1.1  christos }
    333      1.1  christos 
    334  1.1.1.2  christos void
    335      1.1  christos asyncmeta_target_free(
    336      1.1  christos 	a_metatarget_t	*mt )
    337      1.1  christos {
    338      1.1  christos 	if ( mt->mt_uri ) {
    339      1.1  christos 		free( mt->mt_uri );
    340      1.1  christos 		ldap_pvt_thread_mutex_destroy( &mt->mt_uri_mutex );
    341      1.1  christos 	}
    342      1.1  christos 	if ( mt->mt_subtree ) {
    343      1.1  christos 		asyncmeta_subtree_destroy( mt->mt_subtree );
    344      1.1  christos 		mt->mt_subtree = NULL;
    345      1.1  christos 	}
    346      1.1  christos 	if ( mt->mt_filter ) {
    347      1.1  christos 		asyncmeta_filter_destroy( mt->mt_filter );
    348      1.1  christos 		mt->mt_filter = NULL;
    349      1.1  christos 	}
    350      1.1  christos 	if ( !BER_BVISNULL( &mt->mt_psuffix ) ) {
    351      1.1  christos 		free( mt->mt_psuffix.bv_val );
    352      1.1  christos 	}
    353      1.1  christos 	if ( !BER_BVISNULL( &mt->mt_nsuffix ) ) {
    354      1.1  christos 		free( mt->mt_nsuffix.bv_val );
    355      1.1  christos 	}
    356      1.1  christos 	if ( !BER_BVISNULL( &mt->mt_binddn ) ) {
    357      1.1  christos 		free( mt->mt_binddn.bv_val );
    358      1.1  christos 	}
    359      1.1  christos 	if ( !BER_BVISNULL( &mt->mt_bindpw ) ) {
    360      1.1  christos 		free( mt->mt_bindpw.bv_val );
    361      1.1  christos 	}
    362      1.1  christos 	if ( !BER_BVISNULL( &mt->mt_idassert_authcID ) ) {
    363      1.1  christos 		ch_free( mt->mt_idassert_authcID.bv_val );
    364      1.1  christos 	}
    365      1.1  christos 	if ( !BER_BVISNULL( &mt->mt_idassert_authcDN ) ) {
    366      1.1  christos 		ch_free( mt->mt_idassert_authcDN.bv_val );
    367      1.1  christos 	}
    368      1.1  christos 	if ( !BER_BVISNULL( &mt->mt_idassert_passwd ) ) {
    369      1.1  christos 		ch_free( mt->mt_idassert_passwd.bv_val );
    370      1.1  christos 	}
    371      1.1  christos 	if ( !BER_BVISNULL( &mt->mt_idassert_authzID ) ) {
    372      1.1  christos 		ch_free( mt->mt_idassert_authzID.bv_val );
    373      1.1  christos 	}
    374      1.1  christos 	if ( !BER_BVISNULL( &mt->mt_idassert_sasl_mech ) ) {
    375      1.1  christos 		ch_free( mt->mt_idassert_sasl_mech.bv_val );
    376      1.1  christos 	}
    377      1.1  christos 	if ( !BER_BVISNULL( &mt->mt_idassert_sasl_realm ) ) {
    378      1.1  christos 		ch_free( mt->mt_idassert_sasl_realm.bv_val );
    379      1.1  christos 	}
    380      1.1  christos 	if ( mt->mt_idassert_authz != NULL ) {
    381      1.1  christos 		ber_bvarray_free( mt->mt_idassert_authz );
    382      1.1  christos 	}
    383      1.1  christos 	if ( !BER_BVISNULL( &mt->mt_lsuffixm )) {
    384      1.1  christos 		ch_free( mt->mt_lsuffixm.bv_val );
    385      1.1  christos 	}
    386      1.1  christos 	if ( !BER_BVISNULL( &mt->mt_rsuffixm )) {
    387      1.1  christos 		ch_free( mt->mt_rsuffixm.bv_val );
    388      1.1  christos 	}
    389      1.1  christos 	free( mt );
    390      1.1  christos }
    391      1.1  christos 
    392      1.1  christos int
    393      1.1  christos asyncmeta_back_db_close(
    394      1.1  christos 	Backend		*be,
    395      1.1  christos 	ConfigReply	*cr )
    396      1.1  christos {
    397      1.1  christos 	a_metainfo_t	*mi;
    398      1.1  christos 
    399      1.1  christos 	if ( be->be_private ) {
    400      1.1  christos 		mi = ( a_metainfo_t * )be->be_private;
    401  1.1.1.2  christos 		mi->mi_disabled = 1;
    402  1.1.1.2  christos 		/* there are no pending ops so we can free up the connections and stop the timeout loop
    403  1.1.1.2  christos 		 * else timeout_loop will clear up the ops and connections and not reschedule */
    404  1.1.1.2  christos 		if ( asyncmeta_db_has_pending_ops( mi ) == 0 ) {
    405  1.1.1.2  christos 				ldap_pvt_thread_mutex_lock( &mi->mi_mc_mutex );
    406  1.1.1.2  christos 				asyncmeta_back_clear_miconns(mi);
    407  1.1.1.2  christos 				ldap_pvt_thread_mutex_unlock( &mi->mi_mc_mutex );
    408  1.1.1.2  christos 				if ( mi->mi_task != NULL ) {
    409  1.1.1.2  christos 					ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
    410  1.1.1.2  christos 					if ( ldap_pvt_runqueue_isrunning( &slapd_rq, mi->mi_task )) {
    411  1.1.1.2  christos 						ldap_pvt_runqueue_stoptask( &slapd_rq,  mi->mi_task);
    412  1.1.1.2  christos 					}
    413  1.1.1.2  christos 					ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
    414  1.1.1.2  christos 					mi->mi_task = NULL;
    415  1.1.1.2  christos 				}
    416      1.1  christos 		}
    417      1.1  christos 	}
    418      1.1  christos 	return 0;
    419      1.1  christos }
    420      1.1  christos 
    421      1.1  christos int
    422      1.1  christos asyncmeta_back_db_destroy(
    423      1.1  christos 	Backend		*be,
    424      1.1  christos 	ConfigReply	*cr )
    425      1.1  christos {
    426      1.1  christos 	a_metainfo_t	*mi;
    427      1.1  christos 
    428      1.1  christos 	if ( be->be_private ) {
    429      1.1  christos 		int i;
    430      1.1  christos 
    431      1.1  christos 		mi = ( a_metainfo_t * )be->be_private;
    432      1.1  christos 		/*
    433      1.1  christos 		 * Destroy the per-target stuff (assuming there's at
    434      1.1  christos 		 * least one ...)
    435      1.1  christos 		 */
    436      1.1  christos 		if ( mi->mi_targets != NULL ) {
    437      1.1  christos 			for ( i = 0; i < mi->mi_ntargets; i++ ) {
    438      1.1  christos 				a_metatarget_t	*mt = mi->mi_targets[ i ];
    439      1.1  christos 
    440      1.1  christos 				if ( META_BACK_TGT_QUARANTINE( mt ) ) {
    441      1.1  christos 					if ( mt->mt_quarantine.ri_num != mi->mi_quarantine.ri_num )
    442      1.1  christos 					{
    443      1.1  christos 						mi->mi_ldap_extra->retry_info_destroy( &mt->mt_quarantine );
    444      1.1  christos 					}
    445      1.1  christos 
    446      1.1  christos 					ldap_pvt_thread_mutex_destroy( &mt->mt_quarantine_mutex );
    447      1.1  christos 				}
    448      1.1  christos 
    449      1.1  christos 				asyncmeta_target_free( mt );
    450      1.1  christos 			}
    451      1.1  christos 
    452      1.1  christos 			free( mi->mi_targets );
    453      1.1  christos 		}
    454      1.1  christos 
    455      1.1  christos 		ldap_pvt_thread_mutex_lock( &mi->mi_cache.mutex );
    456      1.1  christos 		if ( mi->mi_cache.tree ) {
    457      1.1  christos 			ldap_avl_free( mi->mi_cache.tree, asyncmeta_dncache_free );
    458      1.1  christos 		}
    459      1.1  christos 
    460      1.1  christos 		ldap_pvt_thread_mutex_unlock( &mi->mi_cache.mutex );
    461      1.1  christos 		ldap_pvt_thread_mutex_destroy( &mi->mi_cache.mutex );
    462      1.1  christos 
    463      1.1  christos 		if ( mi->mi_candidates != NULL ) {
    464      1.1  christos 			ber_memfree_x( mi->mi_candidates, NULL );
    465      1.1  christos 		}
    466      1.1  christos 
    467      1.1  christos 		if ( META_BACK_QUARANTINE( mi ) ) {
    468      1.1  christos 			mi->mi_ldap_extra->retry_info_destroy( &mi->mi_quarantine );
    469      1.1  christos 		}
    470      1.1  christos 
    471      1.1  christos 		ldap_pvt_thread_mutex_lock( &mi->mi_mc_mutex );
    472      1.1  christos 		asyncmeta_back_clear_miconns(mi);
    473      1.1  christos 		ldap_pvt_thread_mutex_unlock( &mi->mi_mc_mutex );
    474      1.1  christos 		ldap_pvt_thread_mutex_destroy( &mi->mi_mc_mutex );
    475      1.1  christos 
    476      1.1  christos 		free( be->be_private );
    477      1.1  christos 	}
    478      1.1  christos 	return 0;
    479      1.1  christos }
    480      1.1  christos 
    481      1.1  christos #if SLAPD_ASYNCMETA == SLAPD_MOD_DYNAMIC
    482      1.1  christos 
    483      1.1  christos /* conditionally define the init_module() function */
    484      1.1  christos SLAP_BACKEND_INIT_MODULE( asyncmeta )
    485      1.1  christos 
    486      1.1  christos #endif /* SLAPD_ASYNCMETA == SLAPD_MOD_DYNAMIC */
    487