2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1999-2005 The OpenLDAP Foundation.
5 * Portions Copyright 2001-2003 Pierangelo Masarati.
6 * Portions Copyright 1999-2003 Howard Chu.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted only as authorized by the OpenLDAP
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>.
18 * This work was initially developed by the Howard Chu for inclusion
19 * in OpenLDAP Software and subsequently enhanced by Pierangelo
28 #include <ac/socket.h>
29 #include <ac/string.h>
34 #include "../back-ldap/back-ldap.h"
35 #include "back-meta.h"
38 * Set PRINT_CONNTREE larger than 0 to dump the connection tree (debug only)
40 #define PRINT_CONNTREE 0
45 * compares two struct metaconn based on the value of the conn pointer;
53 metaconn_t *mc1 = ( metaconn_t * )c1;
54 metaconn_t *mc2 = ( metaconn_t * )c2;
56 return SLAP_PTRCMP( mc1->mc_conn, mc2->mc_conn );
62 * returns -1 in case a duplicate struct metaconn has been inserted;
70 metaconn_t *mc1 = ( metaconn_t * )c1;
71 metaconn_t *mc2 = ( metaconn_t * )c2;
73 return( ( mc1->mc_conn == mc2->mc_conn ) ? -1 : 0 );
77 * Debug stuff (got it from libavl)
79 #if PRINT_CONNTREE > 0
81 ravl_print( Avlnode *root, int depth )
89 ravl_print( root->avl_right, depth + 1 );
91 for ( i = 0; i < depth; i++ ) {
95 printf( "c(%d) %d\n", ( ( metaconn_t * )root->avl_data )->mc_conn->c_connid, root->avl_bf );
97 ravl_print( root->avl_left, depth + 1 );
101 myprint( Avlnode *root )
103 printf( "********\n" );
106 printf( "\tNULL\n" );
108 ravl_print( root, 0 );
111 printf( "********\n" );
113 #endif /* PRINT_CONNTREE */
121 * Allocates a connection structure, making room for all the referenced targets
127 metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
129 int i, ntargets = mi->mi_ntargets;
131 assert( ntargets > 0 );
133 /* malloc all in one */
134 mc = ( metaconn_t * )ch_malloc( sizeof( metaconn_t )
135 + sizeof( metasingleconn_t ) * ntargets );
140 for ( i = 0; i < ntargets; i++ ) {
141 mc->mc_conns[ i ].msc_ld = NULL;
142 BER_BVZERO( &mc->mc_conns[ i ].msc_bound_ndn );
143 BER_BVZERO( &mc->mc_conns[ i ].msc_cred );
144 mc->mc_conns[ i ].msc_bound = META_UNBOUND;
145 mc->mc_conns[ i ].msc_info = mi;
148 mc->mc_auth_target = META_BOUND_NONE;
149 ldap_pvt_thread_mutex_init( &mc->mc_mutex );
156 * meta_back_conn_free
165 assert( mc != NULL );
166 assert( mc->mc_refcnt == 0 );
168 ldap_pvt_thread_mutex_destroy( &mc->mc_mutex );
177 metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
179 assert( mc != NULL );
181 ldap_pvt_thread_mutex_lock( &mi->mi_conn_mutex );
183 if ( --mc->mc_refcnt == 0 ) {
184 meta_back_conn_free( mc );
187 ldap_pvt_thread_mutex_unlock( &mi->mi_conn_mutex );
191 * meta_back_init_one_conn
193 * Initializes one connection
196 meta_back_init_one_conn(
200 metasingleconn_t *msc,
201 ldap_back_send_t sendok )
203 metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
210 if ( msc->msc_ld != NULL ) {
211 return rs->sr_err = LDAP_SUCCESS;
215 * Attempts to initialize the connection to the target ds
217 rs->sr_err = ldap_initialize( &msc->msc_ld, mt->mt_uri );
218 if ( rs->sr_err != LDAP_SUCCESS ) {
223 * Set LDAP version. This will always succeed: If the client
224 * bound with a particular version, then so can we.
226 vers = op->o_conn->c_protocol;
227 ldap_set_option( msc->msc_ld, LDAP_OPT_PROTOCOL_VERSION, &vers );
229 /* automatically chase referrals ("chase-referrals"/"dont-chase-referrals" statement) */
230 if ( LDAP_BACK_CHASE_REFERRALS( mi ) ) {
231 ldap_set_option( msc->msc_ld, LDAP_OPT_REFERRALS, LDAP_OPT_ON );
235 /* start TLS ("tls [try-]{start|propagate}" statement) */
236 if ( ( LDAP_BACK_USE_TLS( mi ) || ( op->o_conn->c_is_tls && LDAP_BACK_PROPAGATE_TLS( mi ) ) )
237 && !ldap_is_ldaps_url( mt->mt_uri ) )
239 #ifdef SLAP_STARTTLS_ASYNCHRONOUS
241 * use asynchronous StartTLS; in case, chase referral
242 * FIXME: OpenLDAP does not return referral on StartTLS yet
246 rs->sr_err = ldap_start_tls( msc->msc_ld, NULL, NULL, &msgid );
247 if ( rs->sr_err == LDAP_SUCCESS ) {
248 LDAPMessage *res = NULL;
249 int rc, nretries = mt->mt_nretries;
250 struct timeval tv = { 0, 0 };
253 rc = ldap_result( msc->msc_ld, msgid, LDAP_MSG_ALL, &tv, &res );
255 rs->sr_err = LDAP_OTHER;
257 } else if ( rc == 0 ) {
258 if ( nretries != 0 ) {
259 if ( nretries > 0 ) {
266 rs->sr_err = LDAP_OTHER;
268 } else if ( rc == LDAP_RES_EXTENDED ) {
269 struct berval *data = NULL;
271 rs->sr_err = ldap_parse_extended_result( msc->msc_ld, res,
273 if ( rs->sr_err == LDAP_SUCCESS ) {
274 rs->sr_err = ldap_result2error( msc->msc_ld, res, 1 );
277 /* FIXME: in case a referral
278 * is returned, should we try
279 * using it instead of the
281 if ( rs->sr_err == LDAP_SUCCESS ) {
282 ldap_install_tls( msc->msc_ld );
284 } else if ( rs->sr_err == LDAP_REFERRAL ) {
285 rs->sr_err = LDAP_OTHER;
286 rs->sr_text = "unwilling to chase referral returned by Start TLS exop";
290 if ( data->bv_val ) {
291 ber_memfree( data->bv_val );
298 rs->sr_err = LDAP_OTHER;
305 #else /* ! SLAP_STARTTLS_ASYNCHRONOUS */
307 * use synchronous StartTLS
309 rs->sr_err = ldap_start_tls_s( msc->msc_ld, NULL, NULL );
310 #endif /* ! SLAP_STARTTLS_ASYNCHRONOUS */
312 /* if StartTLS is requested, only attempt it if the URL
313 * is not "ldaps://"; this may occur not only in case
314 * of misconfiguration, but also when used in the chain
315 * overlay, where the "uri" can be parsed out of a referral */
316 if ( rs->sr_err == LDAP_SERVER_DOWN
317 || ( rs->sr_err != LDAP_SUCCESS && LDAP_BACK_TLS_CRITICAL( mi ) ) )
319 ldap_unbind_ext_s( msc->msc_ld, NULL, NULL );
323 #endif /* HAVE_TLS */
326 * Set the network timeout if set
328 if ( mi->mi_network_timeout != 0 ) {
329 struct timeval network_timeout;
331 network_timeout.tv_usec = 0;
332 network_timeout.tv_sec = mi->mi_network_timeout;
334 ldap_set_option( msc->msc_ld, LDAP_OPT_NETWORK_TIMEOUT,
335 (void *)&network_timeout );
339 * If the connection DN is not null, an attempt to rewrite it is made
341 if ( !BER_BVISEMPTY( &op->o_conn->c_dn ) ) {
343 dc.conn = op->o_conn;
348 * Rewrite the bind dn if needed
350 if ( ldap_back_dn_massage( &dc, &op->o_conn->c_dn,
351 &msc->msc_bound_ndn ) )
356 /* copy the DN idf needed */
357 if ( msc->msc_bound_ndn.bv_val == op->o_conn->c_dn.bv_val ) {
358 ber_dupbv( &msc->msc_bound_ndn, &op->o_conn->c_dn );
361 assert( !BER_BVISNULL( &msc->msc_bound_ndn ) );
364 ber_str2bv( "", 0, 1, &msc->msc_bound_ndn );
367 msc->msc_bound = META_UNBOUND;
370 if ( rs->sr_err == LDAP_SUCCESS ) {
372 * Sets a cookie for the rewrite session
374 ( void )rewrite_session_init( mt->mt_rwmap.rwm_rw, op->o_conn );
377 rs->sr_err = slap_map_api2result( rs );
378 if ( sendok & LDAP_BACK_SENDERR ) {
379 send_ldap_result( op, rs );
390 * Retries one connection
398 ldap_back_send_t sendok )
400 metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
401 metatarget_t *mt = &mi->mi_targets[ candidate ];
402 int rc = LDAP_UNAVAILABLE;
403 metasingleconn_t *msc = &mc->mc_conns[ candidate ];
406 ldap_pvt_thread_mutex_lock( &mi->mi_conn_mutex );
408 assert( mc->mc_refcnt > 0 );
410 if ( mc->mc_refcnt == 1 ) {
411 while ( ldap_pvt_thread_mutex_trylock( &mc->mc_mutex ) ) {
412 ldap_pvt_thread_mutex_unlock( &mi->mi_conn_mutex );
413 ldap_pvt_thread_yield();
417 ldap_unbind_ext_s( msc->msc_ld, NULL, NULL );
421 ( void )rewrite_session_delete( mt->mt_rwmap.rwm_rw, op->o_conn );
423 /* mc here must be the regular mc, reset and ready for init */
424 rc = meta_back_init_one_conn( op, rs, mt, msc, sendok );
426 if ( rc == LDAP_SUCCESS ) {
427 rc = meta_back_single_dobind( op, rs, mc, candidate,
428 sendok, mt->mt_nretries, 0 );
431 ldap_pvt_thread_mutex_unlock( &mc->mc_mutex );
434 ldap_pvt_thread_mutex_unlock( &mi->mi_conn_mutex );
436 return rc == LDAP_SUCCESS ? 1 : 0;
440 * callback for unique candidate selection
443 meta_back_conn_cb( Operation *op, SlapReply *rs )
445 assert( op->o_tag == LDAP_REQ_SEARCH );
447 switch ( rs->sr_type ) {
449 ((int *)op->o_callback->sc_private)[0] = (int)op->o_private;
465 meta_back_get_candidate(
470 metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
474 * tries to get a unique candidate
475 * (takes care of default target)
477 candidate = meta_back_select_unique_candidate( mi, ndn );
480 * if any is found, inits the connection
482 if ( candidate == META_TARGET_NONE ) {
483 rs->sr_err = LDAP_NO_SUCH_OBJECT;
484 rs->sr_text = "no suitable candidate target found";
486 } else if ( candidate == META_TARGET_MULTIPLE ) {
489 SlapReply rs2 = { 0 };
490 slap_callback cb2 = { 0 };
493 /* try to get a unique match for the request ndn
494 * among the multiple candidates available */
495 op2.o_tag = LDAP_REQ_SEARCH;
497 op2.o_req_ndn = *ndn;
498 op2.ors_scope = LDAP_SCOPE_BASE;
499 op2.ors_deref = LDAP_DEREF_NEVER;
500 op2.ors_attrs = slap_anlist_no_attrs;
501 op2.ors_attrsonly = 0;
502 op2.ors_limit = NULL;
504 op2.ors_tlimit = SLAP_NO_LIMIT;
506 f.f_choice = LDAP_FILTER_PRESENT;
507 f.f_desc = slap_schema.si_ad_objectClass;
509 BER_BVSTR( &op2.ors_filterstr, "(objectClass=*)" );
511 op2.o_callback = &cb2;
512 cb2.sc_response = meta_back_conn_cb;
513 cb2.sc_private = (void *)&candidate;
515 rc = op->o_bd->be_search( &op2, &rs2 );
517 switch ( rs2.sr_err ) {
520 rs->sr_err = rs2.sr_err;
523 case LDAP_SIZELIMIT_EXCEEDED:
524 /* if multiple candidates can serve the operation,
525 * and a default target is defined, and it is
526 * a candidate, try using it (FIXME: YMMV) */
527 if ( mi->mi_defaulttarget != META_DEFAULT_TARGET_NONE
528 && meta_back_is_candidate( &mi->mi_targets[ mi->mi_defaulttarget ].mt_nsuffix,
529 ndn, op->o_tag == LDAP_REQ_SEARCH ? op->ors_scope : LDAP_SCOPE_BASE ) )
531 candidate = mi->mi_defaulttarget;
532 rs->sr_err = LDAP_SUCCESS;
536 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
537 rs->sr_text = "cannot select unique candidate target";
543 rs->sr_err = LDAP_SUCCESS;
550 meta_back_candidates_keyfree(
554 metacandidates_t *mc = (metacandidates_t *)data;
556 ber_memfree_x( mc->mc_candidates, NULL );
557 ber_memfree_x( data, NULL );
561 meta_back_candidates_get( Operation *op )
563 metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
564 metacandidates_t *mc;
566 if ( op->o_threadctx ) {
569 ldap_pvt_thread_pool_getkey( op->o_threadctx,
570 meta_back_candidates_keyfree, &data, NULL );
571 mc = (metacandidates_t *)data;
574 mc = mi->mi_candidates;
578 mc = ch_calloc( sizeof( metacandidates_t ), 1 );
579 mc->mc_ntargets = mi->mi_ntargets;
580 mc->mc_candidates = ch_calloc( sizeof( SlapReply ), mc->mc_ntargets );
581 if ( op->o_threadctx ) {
585 ldap_pvt_thread_pool_setkey( op->o_threadctx,
586 meta_back_candidates_keyfree, data,
587 meta_back_candidates_keyfree );
590 mi->mi_candidates = mc;
593 } else if ( mc->mc_ntargets < mi->mi_ntargets ) {
594 /* NOTE: in the future, may want to allow back-config
595 * to add/remove targets from back-meta... */
596 mc->mc_ntargets = mi->mi_ntargets;
597 mc->mc_candidates = ch_realloc( mc->mc_candidates,
598 sizeof( SlapReply ) * mc->mc_ntargets );
601 return mc->mc_candidates;
607 * Prepares the connection structure
611 * - determine what DN is being requested:
613 * op requires candidate checks
615 * add unique parent of o_req_ndn
616 * bind unique^*[/all] o_req_ndn [no check]
617 * compare unique^+ o_req_ndn
618 * delete unique o_req_ndn
619 * modify unique o_req_ndn
620 * search any o_req_ndn
621 * modrdn unique[, unique] o_req_ndn[, orr_nnewSup]
623 * - for ops that require the candidate to be unique, in case of multiple
624 * occurrences an internal search with sizeLimit=1 is performed
625 * if a unique candidate can actually be determined. If none is found,
626 * the operation aborts; if multiple are found, the default target
627 * is used if defined and candidate; otherwise the operation aborts.
629 * *^note: actually, the bind operation is handled much like a search;
630 * i.e. the bind is broadcast to all candidate targets.
632 * +^note: actually, the compare operation is handled much like a search;
633 * i.e. the compare is broadcast to all candidate targets, while checking
634 * that exactly none (noSuchObject) or one (TRUE/FALSE/UNDEFINED) is
642 ldap_back_send_t sendok )
644 metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
645 metaconn_t *mc = NULL,
647 int cached = META_TARGET_NONE,
648 i = META_TARGET_NONE,
654 meta_op_type op_type = META_OP_REQUIRE_SINGLE;
657 struct berval ndn = op->o_req_ndn,
660 SlapReply *candidates = meta_back_candidates_get( op );
662 /* Searches for a metaconn in the avl tree */
663 mc_curr.mc_conn = op->o_conn;
664 ldap_pvt_thread_mutex_lock( &mi->mi_conn_mutex );
665 mc = (metaconn_t *)avl_find( mi->mi_conntree,
666 (caddr_t)&mc_curr, meta_back_conn_cmp );
670 ldap_pvt_thread_mutex_unlock( &mi->mi_conn_mutex );
672 switch ( op->o_tag ) {
674 /* if we go to selection, the entry must not exist,
675 * and we must be able to resolve the parent */
677 dnParent( &ndn, &pndn );
680 case LDAP_REQ_MODRDN:
681 /* if nnewSuperior is not NULL, it must resolve
682 * to the same candidate as the req_ndn */
683 if ( op->orr_nnewSup ) {
689 /* if bound as rootdn, the backend must bind to all targets
690 * with the administrative identity */
691 if ( op->orb_method == LDAP_AUTH_SIMPLE && be_isroot_pw( op ) ) {
692 op_type = META_OP_REQUIRE_ALL;
696 case LDAP_REQ_DELETE:
697 case LDAP_REQ_MODIFY:
698 /* just a unique candidate */
701 case LDAP_REQ_COMPARE:
702 case LDAP_REQ_SEARCH:
703 /* allow multiple candidates for the searchBase */
704 op_type = META_OP_ALLOW_MULTIPLE;
708 /* right now, just break (exop?) */
713 * require all connections ...
715 if ( op_type == META_OP_REQUIRE_ALL ) {
717 /* Looks like we didn't get a bind. Open a new session... */
719 mc = metaconn_alloc( op );
720 mc->mc_conn = op->o_conn;
724 for ( i = 0; i < mi->mi_ntargets; i++ ) {
727 * The target is activated; if needed, it is
730 int lerr = meta_back_init_one_conn( op, rs, &mi->mi_targets[ i ],
731 &mc->mc_conns[ i ], sendok );
732 if ( lerr == LDAP_SUCCESS ) {
733 candidates[ i ].sr_tag = META_CANDIDATE;
739 * FIXME: in case one target cannot
740 * be init'd, should the other ones
743 candidates[ i ].sr_tag = META_NOT_CANDIDATE;
749 if ( ncandidates == 0 ) {
751 meta_back_freeconn( op, mc );
754 meta_back_release_conn( op, mc );
757 rs->sr_err = LDAP_NO_SUCH_OBJECT;
758 rs->sr_text = "Unable to select valid candidates";
760 if ( sendok & LDAP_BACK_SENDERR ) {
761 if ( rs->sr_err == LDAP_NO_SUCH_OBJECT ) {
762 rs->sr_matched = op->o_bd->be_suffix[ 0 ].bv_val;
764 send_ldap_result( op, rs );
766 rs->sr_matched = NULL;
776 * looks in cache, if any
778 if ( mi->mi_cache.ttl != META_DNCACHE_DISABLED ) {
779 cached = i = meta_dncache_get_target( &mi->mi_cache, &op->o_req_ndn );
782 if ( op_type == META_OP_REQUIRE_SINGLE ) {
785 for ( j = 0; j < mi->mi_ntargets; j++ ) {
786 candidates[ j ].sr_tag = META_NOT_CANDIDATE;
790 * tries to get a unique candidate
791 * (takes care of default target)
793 if ( i == META_TARGET_NONE ) {
794 i = meta_back_get_candidate( op, rs, &ndn );
796 if ( rs->sr_err == LDAP_NO_SUCH_OBJECT && parent ) {
797 i = meta_back_get_candidate( op, rs, &pndn );
800 if ( rs->sr_err != LDAP_SUCCESS ) {
802 meta_back_freeconn( op, mc );
805 meta_back_release_conn( op, mc );
808 if ( sendok & LDAP_BACK_SENDERR ) {
809 if ( rs->sr_err == LDAP_NO_SUCH_OBJECT ) {
810 rs->sr_matched = op->o_bd->be_suffix[ 0 ].bv_val;
812 send_ldap_result( op, rs );
814 rs->sr_matched = NULL;
821 if ( newparent && meta_back_get_candidate( op, rs, op->orr_nnewSup ) != i )
824 meta_back_freeconn( op, mc );
827 meta_back_release_conn( op, mc );
830 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
831 rs->sr_text = "cross-target rename not supported";
832 if ( sendok & LDAP_BACK_SENDERR ) {
833 send_ldap_result( op, rs );
840 Debug( LDAP_DEBUG_TRACE,
841 "==>meta_back_getconn: got target %d for ndn=\"%s\" from cache\n",
842 i, op->o_req_ndn.bv_val, 0 );
845 /* Retries searching for a metaconn in the avl tree
846 * the reason is that the connection might have been
847 * created by meta_back_get_candidate() */
848 mc_curr.mc_conn = op->o_conn;
849 ldap_pvt_thread_mutex_lock( &mi->mi_conn_mutex );
850 mc = (metaconn_t *)avl_find( mi->mi_conntree,
851 (caddr_t)&mc_curr, meta_back_conn_cmp );
855 ldap_pvt_thread_mutex_unlock( &mi->mi_conn_mutex );
857 /* Looks like we didn't get a bind. Open a new session... */
859 mc = metaconn_alloc( op );
860 mc->mc_conn = op->o_conn;
866 * Clear all other candidates
868 ( void )meta_clear_unused_candidates( op, i );
871 * The target is activated; if needed, it is
872 * also init'd. In case of error, meta_back_init_one_conn
873 * sends the appropriate result.
875 err = meta_back_init_one_conn( op, rs, &mi->mi_targets[ i ],
876 &mc->mc_conns[ i ], sendok );
877 if ( err != LDAP_SUCCESS ) {
879 * FIXME: in case one target cannot
880 * be init'd, should the other ones
883 candidates[ i ].sr_tag = META_NOT_CANDIDATE;
885 (void)meta_clear_one_candidate( &mc->mc_conns[ i ] );
886 meta_back_freeconn( op, mc );
889 meta_back_release_conn( op, mc );
894 candidates[ i ].sr_tag = META_CANDIDATE;
902 * if no unique candidate ...
906 /* Looks like we didn't get a bind. Open a new session... */
908 mc = metaconn_alloc( op );
909 mc->mc_conn = op->o_conn;
913 for ( i = 0; i < mi->mi_ntargets; i++ ) {
915 || meta_back_is_candidate( &mi->mi_targets[ i ].mt_nsuffix,
916 mi->mi_targets[ i ].mt_scope,
917 &op->o_req_ndn, LDAP_SCOPE_SUBTREE ) )
921 * The target is activated; if needed, it is
924 int lerr = meta_back_init_one_conn( op, rs,
925 &mi->mi_targets[ i ],
926 &mc->mc_conns[ i ], sendok );
927 if ( lerr == LDAP_SUCCESS ) {
928 candidates[ i ].sr_tag = META_CANDIDATE;
931 Debug( LDAP_DEBUG_TRACE, "%s: meta_back_init_one_conn(%d)\n",
932 op->o_log_prefix, i, 0 );
937 * FIXME: in case one target cannot
938 * be init'd, should the other ones
942 ( void )meta_clear_one_candidate( &mc->mc_conns[ i ] );
944 candidates[ i ].sr_tag = META_NOT_CANDIDATE;
947 Debug( LDAP_DEBUG_ANY, "%s: meta_back_init_one_conn(%d) failed: %d\n",
948 op->o_log_prefix, i, lerr );
955 ( void )meta_clear_one_candidate( &mc->mc_conns[ i ] );
957 candidates[ i ].sr_tag = META_NOT_CANDIDATE;
961 if ( ncandidates == 0 ) {
963 meta_back_freeconn( op, mc );
966 meta_back_release_conn( op, mc );
969 rs->sr_err = LDAP_NO_SUCH_OBJECT;
970 rs->sr_text = "Unable to select valid candidates";
972 if ( sendok & LDAP_BACK_SENDERR ) {
973 if ( rs->sr_err == LDAP_NO_SUCH_OBJECT ) {
974 rs->sr_matched = op->o_bd->be_suffix[ 0 ].bv_val;
976 send_ldap_result( op, rs );
978 rs->sr_matched = NULL;
986 /* clear out meta_back_init_one_conn non-fatal errors */
987 rs->sr_err = LDAP_SUCCESS;
993 * Inserts the newly created metaconn in the avl tree
995 ldap_pvt_thread_mutex_lock( &mi->mi_conn_mutex );
996 err = avl_insert( &mi->mi_conntree, ( caddr_t )mc,
997 meta_back_conn_cmp, meta_back_conn_dup );
999 #if PRINT_CONNTREE > 0
1000 myprint( mi->mi_conntree );
1001 #endif /* PRINT_CONNTREE */
1003 ldap_pvt_thread_mutex_unlock( &mi->mi_conn_mutex );
1006 * Err could be -1 in case a duplicate metaconn is inserted
1008 * FIXME: what if the same client issues more than one
1009 * asynchronous operations?
1012 Debug( LDAP_DEBUG_ANY,
1013 "%s meta_back_getconn: candidates=%d conn=%ld insert failed\n",
1014 op->o_log_prefix, ncandidates, mc->mc_conn->c_connid );
1016 rs->sr_err = LDAP_OTHER;
1017 rs->sr_text = "Internal server error";
1018 meta_back_freeconn( op, mc );
1019 if ( sendok & LDAP_BACK_SENDERR ) {
1020 send_ldap_result( op, rs );
1026 Debug( LDAP_DEBUG_TRACE,
1027 "%s meta_back_getconn: candidates=%d conn=%ld inserted\n",
1028 op->o_log_prefix, ncandidates, mc->mc_conn->c_connid );
1031 Debug( LDAP_DEBUG_TRACE,
1032 "%s meta_back_getconn: candidates=%d conn=%ld fetched\n",
1033 op->o_log_prefix, ncandidates, mc->mc_conn->c_connid );
1040 meta_back_release_conn(
1044 metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
1046 assert( mc != NULL );
1048 ldap_pvt_thread_mutex_lock( &mi->mi_conn_mutex );
1049 assert( mc->mc_refcnt > 0 );
1051 ldap_pvt_thread_mutex_unlock( &mi->mi_conn_mutex );