2003-11-27 14:35:14 +08:00
|
|
|
/* $OpenLDAP$ */
|
|
|
|
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
|
|
|
*
|
2005-01-02 04:49:32 +08:00
|
|
|
* Copyright 1999-2005 The OpenLDAP Foundation.
|
2003-12-09 01:41:40 +08:00
|
|
|
* Portions Copyright 2001-2003 Pierangelo Masarati.
|
|
|
|
* Portions Copyright 1999-2003 Howard Chu.
|
2003-11-27 14:35:14 +08:00
|
|
|
* All rights reserved.
|
2001-05-12 08:51:28 +08:00
|
|
|
*
|
2003-11-27 14:35:14 +08:00
|
|
|
* 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 initially developed by the Howard Chu for inclusion
|
|
|
|
* in OpenLDAP Software and subsequently enhanced by Pierangelo
|
|
|
|
* Masarati.
|
|
|
|
*/
|
2001-05-12 08:51:28 +08:00
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2005-07-04 07:28:35 +08:00
|
|
|
#include <ac/errno.h>
|
2001-05-12 08:51:28 +08:00
|
|
|
#include <ac/socket.h>
|
|
|
|
#include <ac/string.h>
|
|
|
|
|
|
|
|
|
|
|
|
#define AVL_INTERNAL
|
|
|
|
#include "slap.h"
|
|
|
|
#include "../back-ldap/back-ldap.h"
|
|
|
|
#include "back-meta.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set PRINT_CONNTREE larger than 0 to dump the connection tree (debug only)
|
|
|
|
*/
|
|
|
|
#define PRINT_CONNTREE 0
|
|
|
|
|
|
|
|
/*
|
|
|
|
* meta_back_conn_cmp
|
|
|
|
*
|
|
|
|
* compares two struct metaconn based on the value of the conn pointer;
|
|
|
|
* used by avl stuff
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
meta_back_conn_cmp(
|
|
|
|
const void *c1,
|
2005-04-21 11:17:31 +08:00
|
|
|
const void *c2 )
|
2001-05-12 08:51:28 +08:00
|
|
|
{
|
2005-04-23 05:43:52 +08:00
|
|
|
metaconn_t *mc1 = ( metaconn_t * )c1;
|
|
|
|
metaconn_t *mc2 = ( metaconn_t * )c2;
|
2005-09-25 02:39:26 +08:00
|
|
|
int rc;
|
2001-05-12 08:51:28 +08:00
|
|
|
|
2005-09-25 02:39:26 +08:00
|
|
|
/* If local DNs don't match, it is definitely not a match */
|
|
|
|
rc = ber_bvcmp( &mc1->mc_local_ndn, &mc2->mc_local_ndn );
|
|
|
|
if ( rc ) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* For shared sessions, conn is NULL. Only explicitly
|
|
|
|
* bound sessions will have non-NULL conn.
|
|
|
|
*/
|
2005-04-21 11:17:31 +08:00
|
|
|
return SLAP_PTRCMP( mc1->mc_conn, mc2->mc_conn );
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* meta_back_conn_dup
|
|
|
|
*
|
|
|
|
* returns -1 in case a duplicate struct metaconn has been inserted;
|
|
|
|
* used by avl stuff
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
meta_back_conn_dup(
|
|
|
|
void *c1,
|
2005-04-21 11:17:31 +08:00
|
|
|
void *c2 )
|
2001-05-12 08:51:28 +08:00
|
|
|
{
|
2005-04-23 05:43:52 +08:00
|
|
|
metaconn_t *mc1 = ( metaconn_t * )c1;
|
|
|
|
metaconn_t *mc2 = ( metaconn_t * )c2;
|
2001-05-12 08:51:28 +08:00
|
|
|
|
2005-09-25 02:39:26 +08:00
|
|
|
/* Cannot have more than one shared session with same DN */
|
|
|
|
if ( dn_match( &mc1->mc_local_ndn, &mc2->mc_local_ndn ) &&
|
|
|
|
mc1->mc_conn == mc2->mc_conn )
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Debug stuff (got it from libavl)
|
|
|
|
*/
|
|
|
|
#if PRINT_CONNTREE > 0
|
|
|
|
static void
|
|
|
|
ravl_print( Avlnode *root, int depth )
|
|
|
|
{
|
2005-09-25 02:39:26 +08:00
|
|
|
int i;
|
|
|
|
metaconn_t *mc = (metaconn_t *)root->avl_data;
|
2001-05-12 08:51:28 +08:00
|
|
|
|
|
|
|
if ( root == 0 ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-01-08 17:20:54 +08:00
|
|
|
ravl_print( root->avl_right, depth + 1 );
|
2001-05-12 08:51:28 +08:00
|
|
|
|
|
|
|
for ( i = 0; i < depth; i++ ) {
|
|
|
|
printf( " " );
|
|
|
|
}
|
|
|
|
|
2005-09-25 02:39:26 +08:00
|
|
|
printf( "c(%d%s%s) %d\n",
|
|
|
|
LDAP_BACK_PCONN_ID( mc->mc_conn ),
|
|
|
|
BER_BVISNULL( &mc->mc_local_ndn ) ? "" : ": ",
|
|
|
|
BER_BVISNULL( &mc->mc_local_ndn ) ? "" : mc->mc_local_ndn.bv_val,
|
|
|
|
root->avl_bf );
|
2001-05-12 08:51:28 +08:00
|
|
|
|
2005-01-08 17:20:54 +08:00
|
|
|
ravl_print( root->avl_left, depth + 1 );
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
myprint( Avlnode *root )
|
|
|
|
{
|
|
|
|
printf( "********\n" );
|
|
|
|
|
|
|
|
if ( root == 0 ) {
|
|
|
|
printf( "\tNULL\n" );
|
|
|
|
} else {
|
|
|
|
ravl_print( root, 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
printf( "********\n" );
|
|
|
|
}
|
|
|
|
#endif /* PRINT_CONNTREE */
|
|
|
|
/*
|
|
|
|
* End of debug stuff
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* metaconn_alloc
|
|
|
|
*
|
|
|
|
* Allocates a connection structure, making room for all the referenced targets
|
|
|
|
*/
|
2005-04-23 05:43:52 +08:00
|
|
|
static metaconn_t *
|
|
|
|
metaconn_alloc(
|
2005-05-05 07:57:55 +08:00
|
|
|
Operation *op )
|
2001-05-12 08:51:28 +08:00
|
|
|
{
|
2005-05-05 07:57:55 +08:00
|
|
|
metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
|
2005-04-23 05:43:52 +08:00
|
|
|
metaconn_t *mc;
|
2005-05-06 01:34:11 +08:00
|
|
|
int i, ntargets = mi->mi_ntargets;
|
2001-05-12 08:51:28 +08:00
|
|
|
|
|
|
|
assert( ntargets > 0 );
|
|
|
|
|
2005-06-20 06:41:12 +08:00
|
|
|
/* malloc all in one */
|
2005-04-23 05:43:52 +08:00
|
|
|
mc = ( metaconn_t * )ch_malloc( sizeof( metaconn_t )
|
2005-05-06 01:34:11 +08:00
|
|
|
+ sizeof( metasingleconn_t ) * ntargets );
|
2005-04-21 11:17:31 +08:00
|
|
|
if ( mc == NULL ) {
|
2001-05-12 08:51:28 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
2005-04-21 02:52:10 +08:00
|
|
|
|
2005-05-06 01:34:11 +08:00
|
|
|
for ( i = 0; i < ntargets; i++ ) {
|
|
|
|
mc->mc_conns[ i ].msc_ld = NULL;
|
|
|
|
BER_BVZERO( &mc->mc_conns[ i ].msc_bound_ndn );
|
|
|
|
BER_BVZERO( &mc->mc_conns[ i ].msc_cred );
|
2005-09-25 02:39:26 +08:00
|
|
|
LDAP_BACK_CONN_ISBOUND_CLEAR( &mc->mc_conns[ i ] );
|
2005-05-06 01:34:11 +08:00
|
|
|
mc->mc_conns[ i ].msc_info = mi;
|
2003-04-18 18:02:00 +08:00
|
|
|
}
|
|
|
|
|
2005-09-25 02:39:26 +08:00
|
|
|
BER_BVZERO( &mc->mc_local_ndn );
|
|
|
|
mc->msc_mscflags = 0;
|
|
|
|
mc->mc_authz_target = META_BOUND_NONE;
|
2005-04-21 11:17:31 +08:00
|
|
|
ldap_pvt_thread_mutex_init( &mc->mc_mutex );
|
2005-07-04 07:28:35 +08:00
|
|
|
mc->mc_refcnt = 1;
|
2001-05-12 08:51:28 +08:00
|
|
|
|
2005-04-21 11:17:31 +08:00
|
|
|
return mc;
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2005-04-21 11:17:31 +08:00
|
|
|
* meta_back_conn_free
|
2001-05-12 08:51:28 +08:00
|
|
|
*
|
|
|
|
* clears a metaconn
|
|
|
|
*/
|
2005-07-05 06:41:54 +08:00
|
|
|
|
2005-04-21 11:17:31 +08:00
|
|
|
void
|
2005-04-23 05:43:52 +08:00
|
|
|
meta_back_conn_free(
|
|
|
|
metaconn_t *mc )
|
2001-05-12 08:51:28 +08:00
|
|
|
{
|
2005-07-05 06:41:54 +08:00
|
|
|
assert( mc != NULL );
|
|
|
|
assert( mc->mc_refcnt == 0 );
|
2005-04-21 11:17:31 +08:00
|
|
|
|
2005-09-25 02:39:26 +08:00
|
|
|
if ( !BER_BVISNULL( &mc->mc_local_ndn ) ) {
|
|
|
|
free( mc->mc_local_ndn.bv_val );
|
|
|
|
}
|
|
|
|
|
2005-04-21 11:17:31 +08:00
|
|
|
ldap_pvt_thread_mutex_destroy( &mc->mc_mutex );
|
|
|
|
free( mc );
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
|
|
|
|
2005-07-05 06:41:54 +08:00
|
|
|
static void
|
|
|
|
meta_back_freeconn(
|
|
|
|
Operation *op,
|
|
|
|
metaconn_t *mc )
|
|
|
|
{
|
|
|
|
metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
|
|
|
|
|
|
|
|
assert( mc != NULL );
|
|
|
|
|
2005-08-07 08:35:11 +08:00
|
|
|
ldap_pvt_thread_mutex_lock( &mi->mi_conn_mutex );
|
2005-07-05 06:41:54 +08:00
|
|
|
|
|
|
|
if ( --mc->mc_refcnt == 0 ) {
|
|
|
|
meta_back_conn_free( mc );
|
|
|
|
}
|
|
|
|
|
|
|
|
ldap_pvt_thread_mutex_unlock( &mi->mi_conn_mutex );
|
|
|
|
}
|
|
|
|
|
2001-05-12 08:51:28 +08:00
|
|
|
/*
|
2005-04-21 11:17:31 +08:00
|
|
|
* meta_back_init_one_conn
|
2001-05-12 08:51:28 +08:00
|
|
|
*
|
|
|
|
* Initializes one connection
|
|
|
|
*/
|
2005-04-23 05:43:52 +08:00
|
|
|
int
|
2005-04-21 11:17:31 +08:00
|
|
|
meta_back_init_one_conn(
|
2005-04-23 05:43:52 +08:00
|
|
|
Operation *op,
|
|
|
|
SlapReply *rs,
|
|
|
|
metatarget_t *mt,
|
|
|
|
metasingleconn_t *msc,
|
|
|
|
ldap_back_send_t sendok )
|
2001-05-12 08:51:28 +08:00
|
|
|
{
|
2005-04-23 05:43:52 +08:00
|
|
|
metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
|
2003-04-06 00:53:57 +08:00
|
|
|
int vers;
|
2003-04-08 03:01:48 +08:00
|
|
|
dncookie dc;
|
2001-05-12 08:51:28 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Already init'ed
|
|
|
|
*/
|
2005-04-21 11:17:31 +08:00
|
|
|
if ( msc->msc_ld != NULL ) {
|
2005-07-19 19:16:24 +08:00
|
|
|
return rs->sr_err = LDAP_SUCCESS;
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Attempts to initialize the connection to the target ds
|
|
|
|
*/
|
2005-04-23 05:43:52 +08:00
|
|
|
rs->sr_err = ldap_initialize( &msc->msc_ld, mt->mt_uri );
|
2003-04-06 00:53:57 +08:00
|
|
|
if ( rs->sr_err != LDAP_SUCCESS ) {
|
2005-02-05 23:55:27 +08:00
|
|
|
goto error_return;
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
2003-01-24 06:45:17 +08:00
|
|
|
|
2001-05-12 08:51:28 +08:00
|
|
|
/*
|
|
|
|
* Set LDAP version. This will always succeed: If the client
|
|
|
|
* bound with a particular version, then so can we.
|
|
|
|
*/
|
2003-04-04 05:35:54 +08:00
|
|
|
vers = op->o_conn->c_protocol;
|
2005-04-21 11:17:31 +08:00
|
|
|
ldap_set_option( msc->msc_ld, LDAP_OPT_PROTOCOL_VERSION, &vers );
|
2005-02-05 19:33:32 +08:00
|
|
|
|
|
|
|
/* automatically chase referrals ("chase-referrals"/"dont-chase-referrals" statement) */
|
2005-04-21 11:17:31 +08:00
|
|
|
if ( LDAP_BACK_CHASE_REFERRALS( mi ) ) {
|
|
|
|
ldap_set_option( msc->msc_ld, LDAP_OPT_REFERRALS, LDAP_OPT_ON );
|
2005-02-05 19:33:32 +08:00
|
|
|
}
|
2001-05-12 08:51:28 +08:00
|
|
|
|
2005-02-28 01:20:04 +08:00
|
|
|
#ifdef HAVE_TLS
|
2005-07-19 19:16:24 +08:00
|
|
|
/* start TLS ("tls [try-]{start|propagate}" statement) */
|
2005-04-21 11:17:31 +08:00
|
|
|
if ( ( LDAP_BACK_USE_TLS( mi ) || ( op->o_conn->c_is_tls && LDAP_BACK_PROPAGATE_TLS( mi ) ) )
|
2005-04-23 05:43:52 +08:00
|
|
|
&& !ldap_is_ldaps_url( mt->mt_uri ) )
|
2005-02-05 23:55:27 +08:00
|
|
|
{
|
2005-04-16 10:25:41 +08:00
|
|
|
#ifdef SLAP_STARTTLS_ASYNCHRONOUS
|
2005-02-28 01:20:04 +08:00
|
|
|
/*
|
2005-07-19 19:16:24 +08:00
|
|
|
* use asynchronous StartTLS; in case, chase referral
|
|
|
|
* FIXME: OpenLDAP does not return referral on StartTLS yet
|
2005-02-28 01:20:04 +08:00
|
|
|
*/
|
|
|
|
int msgid;
|
2005-02-05 23:55:27 +08:00
|
|
|
|
2005-04-21 11:17:31 +08:00
|
|
|
rs->sr_err = ldap_start_tls( msc->msc_ld, NULL, NULL, &msgid );
|
2005-02-28 01:20:04 +08:00
|
|
|
if ( rs->sr_err == LDAP_SUCCESS ) {
|
|
|
|
LDAPMessage *res = NULL;
|
2005-04-26 02:56:56 +08:00
|
|
|
int rc, nretries = mt->mt_nretries;
|
2005-09-25 02:39:26 +08:00
|
|
|
struct timeval tv;
|
|
|
|
|
|
|
|
LDAP_BACK_TV_SET( &tv );
|
2005-02-05 23:55:27 +08:00
|
|
|
|
2005-02-28 01:20:04 +08:00
|
|
|
retry:;
|
2005-04-21 11:17:31 +08:00
|
|
|
rc = ldap_result( msc->msc_ld, msgid, LDAP_MSG_ALL, &tv, &res );
|
2005-02-05 23:55:27 +08:00
|
|
|
if ( rc < 0 ) {
|
|
|
|
rs->sr_err = LDAP_OTHER;
|
|
|
|
|
|
|
|
} else if ( rc == 0 ) {
|
2005-04-26 02:56:56 +08:00
|
|
|
if ( nretries != 0 ) {
|
|
|
|
if ( nretries > 0 ) {
|
|
|
|
nretries--;
|
|
|
|
}
|
2005-09-25 02:39:26 +08:00
|
|
|
LDAP_BACK_TV_SET( &tv );
|
2005-02-05 23:55:27 +08:00
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
rs->sr_err = LDAP_OTHER;
|
|
|
|
|
2005-02-28 01:20:04 +08:00
|
|
|
} else if ( rc == LDAP_RES_EXTENDED ) {
|
|
|
|
struct berval *data = NULL;
|
2005-02-05 23:55:27 +08:00
|
|
|
|
2005-04-21 11:17:31 +08:00
|
|
|
rs->sr_err = ldap_parse_extended_result( msc->msc_ld, res,
|
2005-02-28 01:20:04 +08:00
|
|
|
NULL, &data, 0 );
|
|
|
|
if ( rs->sr_err == LDAP_SUCCESS ) {
|
2005-04-21 11:17:31 +08:00
|
|
|
rs->sr_err = ldap_result2error( msc->msc_ld, res, 1 );
|
2005-02-28 01:20:04 +08:00
|
|
|
res = NULL;
|
|
|
|
|
2005-02-05 23:55:27 +08:00
|
|
|
/* FIXME: in case a referral
|
|
|
|
* is returned, should we try
|
|
|
|
* using it instead of the
|
|
|
|
* configured URI? */
|
2005-02-28 01:20:04 +08:00
|
|
|
if ( rs->sr_err == LDAP_SUCCESS ) {
|
2005-04-21 11:17:31 +08:00
|
|
|
ldap_install_tls( msc->msc_ld );
|
2005-02-28 01:20:04 +08:00
|
|
|
|
2005-02-05 23:55:27 +08:00
|
|
|
} else if ( rs->sr_err == LDAP_REFERRAL ) {
|
|
|
|
rs->sr_err = LDAP_OTHER;
|
|
|
|
rs->sr_text = "unwilling to chase referral returned by Start TLS exop";
|
|
|
|
}
|
|
|
|
|
2005-02-28 01:20:04 +08:00
|
|
|
if ( data ) {
|
|
|
|
if ( data->bv_val ) {
|
|
|
|
ber_memfree( data->bv_val );
|
|
|
|
}
|
|
|
|
ber_memfree( data );
|
|
|
|
}
|
2005-02-05 23:55:27 +08:00
|
|
|
}
|
2005-02-28 01:20:04 +08:00
|
|
|
|
|
|
|
} else {
|
|
|
|
rs->sr_err = LDAP_OTHER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( res != NULL ) {
|
|
|
|
ldap_msgfree( res );
|
2005-02-05 23:55:27 +08:00
|
|
|
}
|
|
|
|
}
|
2005-04-16 10:25:41 +08:00
|
|
|
#else /* ! SLAP_STARTTLS_ASYNCHRONOUS */
|
2005-02-28 01:20:04 +08:00
|
|
|
/*
|
|
|
|
* use synchronous StartTLS
|
|
|
|
*/
|
2005-04-21 11:17:31 +08:00
|
|
|
rs->sr_err = ldap_start_tls_s( msc->msc_ld, NULL, NULL );
|
2005-04-16 10:25:41 +08:00
|
|
|
#endif /* ! SLAP_STARTTLS_ASYNCHRONOUS */
|
2005-02-05 23:55:27 +08:00
|
|
|
|
|
|
|
/* if StartTLS is requested, only attempt it if the URL
|
|
|
|
* is not "ldaps://"; this may occur not only in case
|
|
|
|
* of misconfiguration, but also when used in the chain
|
|
|
|
* overlay, where the "uri" can be parsed out of a referral */
|
|
|
|
if ( rs->sr_err == LDAP_SERVER_DOWN
|
2005-04-21 11:17:31 +08:00
|
|
|
|| ( rs->sr_err != LDAP_SUCCESS && LDAP_BACK_TLS_CRITICAL( mi ) ) )
|
2005-02-05 23:55:27 +08:00
|
|
|
{
|
2005-04-21 11:17:31 +08:00
|
|
|
ldap_unbind_ext_s( msc->msc_ld, NULL, NULL );
|
2005-02-05 23:55:27 +08:00
|
|
|
goto error_return;
|
|
|
|
}
|
|
|
|
}
|
2005-02-28 01:20:04 +08:00
|
|
|
#endif /* HAVE_TLS */
|
2005-02-05 23:55:27 +08:00
|
|
|
|
2003-05-03 19:30:38 +08:00
|
|
|
/*
|
|
|
|
* Set the network timeout if set
|
|
|
|
*/
|
2005-04-21 11:17:31 +08:00
|
|
|
if ( mi->mi_network_timeout != 0 ) {
|
2005-01-08 17:20:54 +08:00
|
|
|
struct timeval network_timeout;
|
2003-05-03 19:30:38 +08:00
|
|
|
|
|
|
|
network_timeout.tv_usec = 0;
|
2005-04-21 11:17:31 +08:00
|
|
|
network_timeout.tv_sec = mi->mi_network_timeout;
|
2003-05-03 19:30:38 +08:00
|
|
|
|
2005-04-21 11:17:31 +08:00
|
|
|
ldap_set_option( msc->msc_ld, LDAP_OPT_NETWORK_TIMEOUT,
|
2005-01-08 17:20:54 +08:00
|
|
|
(void *)&network_timeout );
|
2003-05-03 19:30:38 +08:00
|
|
|
}
|
|
|
|
|
2001-05-12 08:51:28 +08:00
|
|
|
/*
|
2005-01-08 17:20:54 +08:00
|
|
|
* If the connection DN is not null, an attempt to rewrite it is made
|
2001-05-12 08:51:28 +08:00
|
|
|
*/
|
2005-02-05 23:55:27 +08:00
|
|
|
if ( !BER_BVISEMPTY( &op->o_conn->c_dn ) ) {
|
2005-05-05 07:57:55 +08:00
|
|
|
dc.target = mt;
|
2003-04-08 03:01:48 +08:00
|
|
|
dc.conn = op->o_conn;
|
|
|
|
dc.rs = rs;
|
2004-03-11 05:11:14 +08:00
|
|
|
dc.ctx = "bindDN";
|
2001-12-27 20:17:54 +08:00
|
|
|
|
2001-05-12 08:51:28 +08:00
|
|
|
/*
|
|
|
|
* Rewrite the bind dn if needed
|
|
|
|
*/
|
2003-04-18 18:02:00 +08:00
|
|
|
if ( ldap_back_dn_massage( &dc, &op->o_conn->c_dn,
|
2005-04-21 11:17:31 +08:00
|
|
|
&msc->msc_bound_ndn ) )
|
2005-01-08 17:20:54 +08:00
|
|
|
{
|
2005-02-05 23:55:27 +08:00
|
|
|
goto error_return;
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
2001-12-27 20:17:54 +08:00
|
|
|
|
2004-03-06 23:01:16 +08:00
|
|
|
/* copy the DN idf needed */
|
2005-04-21 11:17:31 +08:00
|
|
|
if ( msc->msc_bound_ndn.bv_val == op->o_conn->c_dn.bv_val ) {
|
|
|
|
ber_dupbv( &msc->msc_bound_ndn, &op->o_conn->c_dn );
|
2004-03-06 23:01:16 +08:00
|
|
|
}
|
|
|
|
|
2005-04-21 11:17:31 +08:00
|
|
|
assert( !BER_BVISNULL( &msc->msc_bound_ndn ) );
|
2001-12-27 20:17:54 +08:00
|
|
|
|
2001-05-12 08:51:28 +08:00
|
|
|
} else {
|
2005-04-21 11:17:31 +08:00
|
|
|
ber_str2bv( "", 0, 1, &msc->msc_bound_ndn );
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
|
|
|
|
2005-09-25 02:39:26 +08:00
|
|
|
LDAP_BACK_CONN_ISBOUND_CLEAR( msc );
|
2001-05-12 08:51:28 +08:00
|
|
|
|
2005-02-05 23:55:27 +08:00
|
|
|
error_return:;
|
2005-07-19 19:16:24 +08:00
|
|
|
if ( rs->sr_err == LDAP_SUCCESS ) {
|
|
|
|
/*
|
|
|
|
* Sets a cookie for the rewrite session
|
|
|
|
*/
|
|
|
|
( void )rewrite_session_init( mt->mt_rwmap.rwm_rw, op->o_conn );
|
|
|
|
|
|
|
|
} else {
|
2005-02-05 23:55:27 +08:00
|
|
|
rs->sr_err = slap_map_api2result( rs );
|
|
|
|
if ( sendok & LDAP_BACK_SENDERR ) {
|
|
|
|
send_ldap_result( op, rs );
|
|
|
|
rs->sr_text = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rs->sr_err;
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
|
|
|
|
2005-04-21 11:17:31 +08:00
|
|
|
/*
|
|
|
|
* meta_back_retry
|
|
|
|
*
|
|
|
|
* Retries one connection
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
meta_back_retry(
|
2005-04-23 05:43:52 +08:00
|
|
|
Operation *op,
|
|
|
|
SlapReply *rs,
|
|
|
|
metaconn_t *mc,
|
|
|
|
int candidate,
|
|
|
|
ldap_back_send_t sendok )
|
2005-04-21 11:17:31 +08:00
|
|
|
{
|
2005-04-23 05:43:52 +08:00
|
|
|
metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
|
2005-05-05 07:57:55 +08:00
|
|
|
metatarget_t *mt = &mi->mi_targets[ candidate ];
|
2005-07-05 06:41:54 +08:00
|
|
|
int rc = LDAP_UNAVAILABLE;
|
2005-04-23 05:43:52 +08:00
|
|
|
metasingleconn_t *msc = &mc->mc_conns[ candidate ];
|
2005-04-21 11:17:31 +08:00
|
|
|
|
2005-07-05 06:41:54 +08:00
|
|
|
retry_lock:;
|
2005-08-07 08:35:11 +08:00
|
|
|
ldap_pvt_thread_mutex_lock( &mi->mi_conn_mutex );
|
2005-04-21 11:17:31 +08:00
|
|
|
|
2005-07-05 06:41:54 +08:00
|
|
|
assert( mc->mc_refcnt > 0 );
|
2005-04-21 11:17:31 +08:00
|
|
|
|
2005-07-05 06:41:54 +08:00
|
|
|
if ( mc->mc_refcnt == 1 ) {
|
2005-08-07 08:35:11 +08:00
|
|
|
while ( ldap_pvt_thread_mutex_trylock( &mc->mc_mutex ) ) {
|
|
|
|
ldap_pvt_thread_mutex_unlock( &mi->mi_conn_mutex );
|
|
|
|
ldap_pvt_thread_yield();
|
|
|
|
goto retry_lock;
|
|
|
|
}
|
2005-04-21 11:17:31 +08:00
|
|
|
|
2005-07-05 06:41:54 +08:00
|
|
|
ldap_unbind_ext_s( msc->msc_ld, NULL, NULL );
|
|
|
|
msc->msc_ld = NULL;
|
2005-09-25 02:39:26 +08:00
|
|
|
LDAP_BACK_CONN_ISBOUND_CLEAR( msc );
|
2005-04-21 11:17:31 +08:00
|
|
|
|
2005-07-19 22:24:26 +08:00
|
|
|
( void )rewrite_session_delete( mt->mt_rwmap.rwm_rw, op->o_conn );
|
|
|
|
|
2005-07-05 06:41:54 +08:00
|
|
|
/* mc here must be the regular mc, reset and ready for init */
|
|
|
|
rc = meta_back_init_one_conn( op, rs, mt, msc, sendok );
|
|
|
|
|
|
|
|
if ( rc == LDAP_SUCCESS ) {
|
|
|
|
rc = meta_back_single_dobind( op, rs, mc, candidate,
|
|
|
|
sendok, mt->mt_nretries, 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
ldap_pvt_thread_mutex_unlock( &mc->mc_mutex );
|
|
|
|
}
|
|
|
|
|
|
|
|
ldap_pvt_thread_mutex_unlock( &mi->mi_conn_mutex );
|
2005-04-21 11:17:31 +08:00
|
|
|
|
|
|
|
return rc == LDAP_SUCCESS ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
2005-04-16 10:25:41 +08:00
|
|
|
/*
|
|
|
|
* callback for unique candidate selection
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
meta_back_conn_cb( Operation *op, SlapReply *rs )
|
|
|
|
{
|
|
|
|
assert( op->o_tag == LDAP_REQ_SEARCH );
|
|
|
|
|
|
|
|
switch ( rs->sr_type ) {
|
|
|
|
case REP_SEARCH:
|
2005-09-25 02:39:26 +08:00
|
|
|
((long *)op->o_callback->sc_private)[0] = (long)op->o_private;
|
2005-04-16 10:25:41 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case REP_SEARCHREF:
|
|
|
|
case REP_RESULT:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return rs->sr_err;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
meta_back_get_candidate(
|
|
|
|
Operation *op,
|
|
|
|
SlapReply *rs,
|
|
|
|
struct berval *ndn )
|
|
|
|
{
|
2005-04-23 05:43:52 +08:00
|
|
|
metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
|
2005-04-16 10:25:41 +08:00
|
|
|
int candidate;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* tries to get a unique candidate
|
|
|
|
* (takes care of default target)
|
|
|
|
*/
|
2005-04-21 11:17:31 +08:00
|
|
|
candidate = meta_back_select_unique_candidate( mi, ndn );
|
2005-04-16 10:25:41 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* if any is found, inits the connection
|
|
|
|
*/
|
|
|
|
if ( candidate == META_TARGET_NONE ) {
|
|
|
|
rs->sr_err = LDAP_NO_SUCH_OBJECT;
|
|
|
|
rs->sr_text = "no suitable candidate target found";
|
|
|
|
|
|
|
|
} else if ( candidate == META_TARGET_MULTIPLE ) {
|
|
|
|
Filter f = { 0 };
|
|
|
|
Operation op2 = *op;
|
|
|
|
SlapReply rs2 = { 0 };
|
|
|
|
slap_callback cb2 = { 0 };
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
/* try to get a unique match for the request ndn
|
|
|
|
* among the multiple candidates available */
|
|
|
|
op2.o_tag = LDAP_REQ_SEARCH;
|
|
|
|
op2.o_req_dn = *ndn;
|
|
|
|
op2.o_req_ndn = *ndn;
|
|
|
|
op2.ors_scope = LDAP_SCOPE_BASE;
|
|
|
|
op2.ors_deref = LDAP_DEREF_NEVER;
|
|
|
|
op2.ors_attrs = slap_anlist_no_attrs;
|
|
|
|
op2.ors_attrsonly = 0;
|
|
|
|
op2.ors_limit = NULL;
|
|
|
|
op2.ors_slimit = 1;
|
|
|
|
op2.ors_tlimit = SLAP_NO_LIMIT;
|
|
|
|
|
|
|
|
f.f_choice = LDAP_FILTER_PRESENT;
|
|
|
|
f.f_desc = slap_schema.si_ad_objectClass;
|
|
|
|
op2.ors_filter = &f;
|
|
|
|
BER_BVSTR( &op2.ors_filterstr, "(objectClass=*)" );
|
|
|
|
|
|
|
|
op2.o_callback = &cb2;
|
|
|
|
cb2.sc_response = meta_back_conn_cb;
|
|
|
|
cb2.sc_private = (void *)&candidate;
|
|
|
|
|
|
|
|
rc = op->o_bd->be_search( &op2, &rs2 );
|
|
|
|
|
|
|
|
switch ( rs2.sr_err ) {
|
|
|
|
case LDAP_SUCCESS:
|
|
|
|
default:
|
|
|
|
rs->sr_err = rs2.sr_err;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LDAP_SIZELIMIT_EXCEEDED:
|
|
|
|
/* if multiple candidates can serve the operation,
|
|
|
|
* and a default target is defined, and it is
|
|
|
|
* a candidate, try using it (FIXME: YMMV) */
|
2005-04-21 11:17:31 +08:00
|
|
|
if ( mi->mi_defaulttarget != META_DEFAULT_TARGET_NONE
|
2005-05-05 07:57:55 +08:00
|
|
|
&& meta_back_is_candidate( &mi->mi_targets[ mi->mi_defaulttarget ].mt_nsuffix,
|
2005-08-17 16:34:49 +08:00
|
|
|
mi->mi_targets[ mi->mi_defaulttarget ].mt_scope,
|
2005-04-21 11:17:31 +08:00
|
|
|
ndn, op->o_tag == LDAP_REQ_SEARCH ? op->ors_scope : LDAP_SCOPE_BASE ) )
|
2005-04-16 10:25:41 +08:00
|
|
|
{
|
2005-04-21 11:17:31 +08:00
|
|
|
candidate = mi->mi_defaulttarget;
|
2005-04-16 10:25:41 +08:00
|
|
|
rs->sr_err = LDAP_SUCCESS;
|
|
|
|
rs->sr_text = NULL;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
|
|
|
|
rs->sr_text = "cannot select unique candidate target";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2005-08-17 16:25:10 +08:00
|
|
|
|
|
|
|
} else {
|
|
|
|
rs->sr_err = LDAP_SUCCESS;
|
2005-04-16 10:25:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return candidate;
|
|
|
|
}
|
|
|
|
|
2005-08-31 09:55:34 +08:00
|
|
|
static void *meta_back_candidates_dummy;
|
|
|
|
|
2005-04-16 10:25:41 +08:00
|
|
|
static void
|
2005-06-20 06:41:12 +08:00
|
|
|
meta_back_candidates_keyfree(
|
2005-04-23 05:43:52 +08:00
|
|
|
void *key,
|
|
|
|
void *data )
|
2005-04-16 10:25:41 +08:00
|
|
|
{
|
2005-06-20 06:41:12 +08:00
|
|
|
metacandidates_t *mc = (metacandidates_t *)data;
|
|
|
|
|
|
|
|
ber_memfree_x( mc->mc_candidates, NULL );
|
2005-04-16 10:25:41 +08:00
|
|
|
ber_memfree_x( data, NULL );
|
|
|
|
}
|
|
|
|
|
2005-04-22 06:22:43 +08:00
|
|
|
SlapReply *
|
2005-04-16 10:25:41 +08:00
|
|
|
meta_back_candidates_get( Operation *op )
|
|
|
|
{
|
2005-06-20 06:41:12 +08:00
|
|
|
metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
|
|
|
|
metacandidates_t *mc;
|
2005-04-16 10:25:41 +08:00
|
|
|
|
|
|
|
if ( op->o_threadctx ) {
|
2005-06-20 06:41:12 +08:00
|
|
|
void *data = NULL;
|
|
|
|
|
2005-04-16 10:25:41 +08:00
|
|
|
ldap_pvt_thread_pool_getkey( op->o_threadctx,
|
2005-08-31 09:55:34 +08:00
|
|
|
&meta_back_candidates_dummy, &data, NULL );
|
2005-06-20 06:41:12 +08:00
|
|
|
mc = (metacandidates_t *)data;
|
|
|
|
|
2005-04-16 10:25:41 +08:00
|
|
|
} else {
|
2005-06-20 06:41:12 +08:00
|
|
|
mc = mi->mi_candidates;
|
2005-04-16 10:25:41 +08:00
|
|
|
}
|
|
|
|
|
2005-06-20 06:41:12 +08:00
|
|
|
if ( mc == NULL ) {
|
|
|
|
mc = ch_calloc( sizeof( metacandidates_t ), 1 );
|
|
|
|
mc->mc_ntargets = mi->mi_ntargets;
|
|
|
|
mc->mc_candidates = ch_calloc( sizeof( SlapReply ), mc->mc_ntargets );
|
2005-04-16 10:25:41 +08:00
|
|
|
if ( op->o_threadctx ) {
|
2005-06-20 06:41:12 +08:00
|
|
|
void *data = NULL;
|
|
|
|
|
|
|
|
data = (void *)mc;
|
2005-04-16 10:25:41 +08:00
|
|
|
ldap_pvt_thread_pool_setkey( op->o_threadctx,
|
2005-08-31 09:55:34 +08:00
|
|
|
&meta_back_candidates_dummy, data,
|
2005-06-20 06:41:12 +08:00
|
|
|
meta_back_candidates_keyfree );
|
2005-04-16 10:25:41 +08:00
|
|
|
|
|
|
|
} else {
|
2005-06-20 06:41:12 +08:00
|
|
|
mi->mi_candidates = mc;
|
2005-04-16 10:25:41 +08:00
|
|
|
}
|
2005-06-20 06:41:12 +08:00
|
|
|
|
|
|
|
} else if ( mc->mc_ntargets < mi->mi_ntargets ) {
|
|
|
|
/* NOTE: in the future, may want to allow back-config
|
|
|
|
* to add/remove targets from back-meta... */
|
|
|
|
mc->mc_ntargets = mi->mi_ntargets;
|
|
|
|
mc->mc_candidates = ch_realloc( mc->mc_candidates,
|
|
|
|
sizeof( SlapReply ) * mc->mc_ntargets );
|
2005-04-16 10:25:41 +08:00
|
|
|
}
|
|
|
|
|
2005-06-20 06:41:12 +08:00
|
|
|
return mc->mc_candidates;
|
2005-04-16 10:25:41 +08:00
|
|
|
}
|
|
|
|
|
2001-05-12 08:51:28 +08:00
|
|
|
/*
|
|
|
|
* meta_back_getconn
|
|
|
|
*
|
|
|
|
* Prepares the connection structure
|
|
|
|
*
|
2005-04-16 10:25:41 +08:00
|
|
|
* RATIONALE:
|
|
|
|
*
|
|
|
|
* - determine what DN is being requested:
|
|
|
|
*
|
|
|
|
* op requires candidate checks
|
|
|
|
*
|
|
|
|
* add unique parent of o_req_ndn
|
|
|
|
* bind unique^*[/all] o_req_ndn [no check]
|
|
|
|
* compare unique^+ o_req_ndn
|
|
|
|
* delete unique o_req_ndn
|
|
|
|
* modify unique o_req_ndn
|
|
|
|
* search any o_req_ndn
|
|
|
|
* modrdn unique[, unique] o_req_ndn[, orr_nnewSup]
|
|
|
|
*
|
|
|
|
* - for ops that require the candidate to be unique, in case of multiple
|
|
|
|
* occurrences an internal search with sizeLimit=1 is performed
|
|
|
|
* if a unique candidate can actually be determined. If none is found,
|
|
|
|
* the operation aborts; if multiple are found, the default target
|
|
|
|
* is used if defined and candidate; otherwise the operation aborts.
|
|
|
|
*
|
|
|
|
* *^note: actually, the bind operation is handled much like a search;
|
|
|
|
* i.e. the bind is broadcast to all candidate targets.
|
|
|
|
*
|
|
|
|
* +^note: actually, the compare operation is handled much like a search;
|
|
|
|
* i.e. the compare is broadcast to all candidate targets, while checking
|
|
|
|
* that exactly none (noSuchObject) or one (TRUE/FALSE/UNDEFINED) is
|
|
|
|
* returned.
|
2001-05-12 08:51:28 +08:00
|
|
|
*/
|
2005-04-23 05:43:52 +08:00
|
|
|
metaconn_t *
|
2001-05-12 08:51:28 +08:00
|
|
|
meta_back_getconn(
|
2005-04-23 05:43:52 +08:00
|
|
|
Operation *op,
|
|
|
|
SlapReply *rs,
|
|
|
|
int *candidate,
|
|
|
|
ldap_back_send_t sendok )
|
2001-05-12 08:51:28 +08:00
|
|
|
{
|
2005-04-23 05:43:52 +08:00
|
|
|
metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
|
2005-07-05 06:41:54 +08:00
|
|
|
metaconn_t *mc = NULL,
|
|
|
|
mc_curr = { 0 };
|
2005-01-08 17:20:54 +08:00
|
|
|
int cached = META_TARGET_NONE,
|
|
|
|
i = META_TARGET_NONE,
|
|
|
|
err = LDAP_SUCCESS,
|
2005-05-06 01:34:11 +08:00
|
|
|
new_conn = 0,
|
|
|
|
ncandidates = 0;
|
|
|
|
|
2001-05-12 08:51:28 +08:00
|
|
|
|
2005-04-16 10:25:41 +08:00
|
|
|
meta_op_type op_type = META_OP_REQUIRE_SINGLE;
|
|
|
|
int parent = 0,
|
|
|
|
newparent = 0;
|
2005-04-21 11:17:31 +08:00
|
|
|
struct berval ndn = op->o_req_ndn,
|
|
|
|
pndn;
|
2005-04-16 10:25:41 +08:00
|
|
|
|
2005-04-22 06:22:43 +08:00
|
|
|
SlapReply *candidates = meta_back_candidates_get( op );
|
2005-04-16 10:25:41 +08:00
|
|
|
|
2005-09-25 02:39:26 +08:00
|
|
|
/* Internal searches are privileged and shared. So is root. */
|
|
|
|
/* FIXME: there seem to be concurrency issues */
|
|
|
|
if ( op->o_do_not_cache || be_isroot( op ) ) {
|
|
|
|
mc_curr.mc_local_ndn = op->o_bd->be_rootndn;
|
|
|
|
LDAP_BACK_CONN_ISPRIV_SET( &mc_curr );
|
|
|
|
mc_curr.mc_conn = LDAP_BACK_PCONN_SET( op );
|
|
|
|
|
|
|
|
} else {
|
|
|
|
mc_curr.mc_local_ndn = op->o_ndn;
|
|
|
|
|
|
|
|
/* Explicit binds must not be shared */
|
|
|
|
if ( op->o_tag == LDAP_REQ_BIND || SLAP_IS_AUTHZ_BACKEND( op ) ) {
|
|
|
|
mc_curr.mc_conn = op->o_conn;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
mc_curr.mc_conn = LDAP_BACK_PCONN_SET( op );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-05-12 08:51:28 +08:00
|
|
|
/* Searches for a metaconn in the avl tree */
|
2005-08-07 08:35:11 +08:00
|
|
|
ldap_pvt_thread_mutex_lock( &mi->mi_conn_mutex );
|
2005-04-23 05:43:52 +08:00
|
|
|
mc = (metaconn_t *)avl_find( mi->mi_conntree,
|
2005-04-21 11:17:31 +08:00
|
|
|
(caddr_t)&mc_curr, meta_back_conn_cmp );
|
2005-07-05 06:41:54 +08:00
|
|
|
if ( mc ) {
|
|
|
|
mc->mc_refcnt++;
|
|
|
|
}
|
2005-04-21 11:17:31 +08:00
|
|
|
ldap_pvt_thread_mutex_unlock( &mi->mi_conn_mutex );
|
2005-04-16 10:25:41 +08:00
|
|
|
|
|
|
|
switch ( op->o_tag ) {
|
|
|
|
case LDAP_REQ_ADD:
|
|
|
|
/* if we go to selection, the entry must not exist,
|
|
|
|
* and we must be able to resolve the parent */
|
|
|
|
parent = 1;
|
2005-04-21 11:17:31 +08:00
|
|
|
dnParent( &ndn, &pndn );
|
2005-04-16 10:25:41 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LDAP_REQ_MODRDN:
|
|
|
|
/* if nnewSuperior is not NULL, it must resolve
|
|
|
|
* to the same candidate as the req_ndn */
|
|
|
|
if ( op->orr_nnewSup ) {
|
|
|
|
newparent = 1;
|
|
|
|
}
|
|
|
|
break;
|
2001-05-12 08:51:28 +08:00
|
|
|
|
2005-04-16 10:25:41 +08:00
|
|
|
case LDAP_REQ_BIND:
|
|
|
|
/* if bound as rootdn, the backend must bind to all targets
|
|
|
|
* with the administrative identity */
|
|
|
|
if ( op->orb_method == LDAP_AUTH_SIMPLE && be_isroot_pw( op ) ) {
|
|
|
|
op_type = META_OP_REQUIRE_ALL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LDAP_REQ_DELETE:
|
|
|
|
case LDAP_REQ_MODIFY:
|
|
|
|
/* just a unique candidate */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LDAP_REQ_COMPARE:
|
|
|
|
case LDAP_REQ_SEARCH:
|
|
|
|
/* allow multiple candidates for the searchBase */
|
|
|
|
op_type = META_OP_ALLOW_MULTIPLE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* right now, just break (exop?) */
|
|
|
|
break;
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
|
|
|
|
2005-01-08 17:20:54 +08:00
|
|
|
/*
|
|
|
|
* require all connections ...
|
|
|
|
*/
|
|
|
|
if ( op_type == META_OP_REQUIRE_ALL ) {
|
2005-04-16 10:25:41 +08:00
|
|
|
|
|
|
|
/* Looks like we didn't get a bind. Open a new session... */
|
2005-07-05 06:41:54 +08:00
|
|
|
if ( mc == NULL ) {
|
2005-05-05 07:57:55 +08:00
|
|
|
mc = metaconn_alloc( op );
|
2005-09-25 02:39:26 +08:00
|
|
|
mc->mc_conn = mc_curr.mc_conn;
|
|
|
|
ber_dupbv( &mc->mc_local_ndn, &mc_curr.mc_local_ndn );
|
2005-04-16 10:25:41 +08:00
|
|
|
new_conn = 1;
|
|
|
|
}
|
|
|
|
|
2005-04-21 11:17:31 +08:00
|
|
|
for ( i = 0; i < mi->mi_ntargets; i++ ) {
|
2005-09-25 02:39:26 +08:00
|
|
|
metatarget_t *mt = &mi->mi_targets[ i ];
|
|
|
|
metasingleconn_t *msc = &mc->mc_conns[ i ];
|
2005-01-08 17:20:54 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The target is activated; if needed, it is
|
|
|
|
* also init'd
|
|
|
|
*/
|
2005-09-25 02:39:26 +08:00
|
|
|
candidates[ i ].sr_err = meta_back_init_one_conn( op,
|
|
|
|
rs, mt, msc, sendok );
|
2005-08-31 09:55:34 +08:00
|
|
|
if ( candidates[ i ].sr_err == LDAP_SUCCESS ) {
|
2005-04-22 06:22:43 +08:00
|
|
|
candidates[ i ].sr_tag = META_CANDIDATE;
|
2005-05-06 01:34:11 +08:00
|
|
|
ncandidates++;
|
2005-09-25 02:39:26 +08:00
|
|
|
|
|
|
|
if ( LDAP_BACK_CONN_ISPRIV( &mc_curr ) ) {
|
|
|
|
ber_dupbv( &msc->msc_cred, &mt->mt_pseudorootpw );
|
|
|
|
ber_dupbv( &msc->msc_bound_ndn, &mt->mt_pseudorootdn );
|
|
|
|
LDAP_BACK_CONN_ISPRIV_SET( msc );
|
|
|
|
|
|
|
|
} else {
|
|
|
|
BER_BVZERO( &msc->msc_cred );
|
|
|
|
BER_BVZERO( &msc->msc_bound_ndn );
|
|
|
|
if ( !BER_BVISEMPTY( &op->o_ndn )
|
|
|
|
&& SLAP_IS_AUTHZ_BACKEND( op )
|
|
|
|
&& i == mc->mc_authz_target )
|
|
|
|
{
|
|
|
|
ber_dupbv( &msc->msc_bound_ndn, &op->o_ndn );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-21 11:17:31 +08:00
|
|
|
} else {
|
2005-01-08 17:20:54 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* FIXME: in case one target cannot
|
|
|
|
* be init'd, should the other ones
|
|
|
|
* be tried?
|
|
|
|
*/
|
2005-04-22 06:22:43 +08:00
|
|
|
candidates[ i ].sr_tag = META_NOT_CANDIDATE;
|
2005-08-31 09:55:34 +08:00
|
|
|
err = candidates[ i ].sr_err;
|
2005-01-08 17:20:54 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2005-06-29 07:22:48 +08:00
|
|
|
|
|
|
|
if ( ncandidates == 0 ) {
|
|
|
|
if ( new_conn ) {
|
2005-07-05 06:41:54 +08:00
|
|
|
meta_back_freeconn( op, mc );
|
|
|
|
|
|
|
|
} else {
|
|
|
|
meta_back_release_conn( op, mc );
|
2005-06-29 07:22:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
rs->sr_err = LDAP_NO_SUCH_OBJECT;
|
|
|
|
rs->sr_text = "Unable to select valid candidates";
|
|
|
|
|
|
|
|
if ( sendok & LDAP_BACK_SENDERR ) {
|
|
|
|
if ( rs->sr_err == LDAP_NO_SUCH_OBJECT ) {
|
|
|
|
rs->sr_matched = op->o_bd->be_suffix[ 0 ].bv_val;
|
|
|
|
}
|
|
|
|
send_ldap_result( op, rs );
|
|
|
|
rs->sr_text = NULL;
|
|
|
|
rs->sr_matched = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-01-08 17:20:54 +08:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2001-05-12 08:51:28 +08:00
|
|
|
/*
|
|
|
|
* looks in cache, if any
|
|
|
|
*/
|
2005-04-21 11:17:31 +08:00
|
|
|
if ( mi->mi_cache.ttl != META_DNCACHE_DISABLED ) {
|
|
|
|
cached = i = meta_dncache_get_target( &mi->mi_cache, &op->o_req_ndn );
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( op_type == META_OP_REQUIRE_SINGLE ) {
|
2005-09-25 02:39:26 +08:00
|
|
|
metatarget_t *mt = NULL;
|
|
|
|
metasingleconn_t *msc = NULL;
|
|
|
|
|
|
|
|
int j;
|
2001-05-12 08:51:28 +08:00
|
|
|
|
2005-04-22 06:22:43 +08:00
|
|
|
for ( j = 0; j < mi->mi_ntargets; j++ ) {
|
|
|
|
candidates[ j ].sr_tag = META_NOT_CANDIDATE;
|
|
|
|
}
|
2005-04-16 10:25:41 +08:00
|
|
|
|
2001-05-12 08:51:28 +08:00
|
|
|
/*
|
|
|
|
* tries to get a unique candidate
|
2005-04-16 10:25:41 +08:00
|
|
|
* (takes care of default target)
|
2001-05-12 08:51:28 +08:00
|
|
|
*/
|
2005-01-08 17:20:54 +08:00
|
|
|
if ( i == META_TARGET_NONE ) {
|
2005-04-16 10:25:41 +08:00
|
|
|
i = meta_back_get_candidate( op, rs, &ndn );
|
2001-05-12 08:51:28 +08:00
|
|
|
|
2005-04-21 11:17:31 +08:00
|
|
|
if ( rs->sr_err == LDAP_NO_SUCH_OBJECT && parent ) {
|
|
|
|
i = meta_back_get_candidate( op, rs, &pndn );
|
|
|
|
}
|
|
|
|
|
2005-04-16 10:25:41 +08:00
|
|
|
if ( rs->sr_err != LDAP_SUCCESS ) {
|
2005-08-31 23:11:25 +08:00
|
|
|
if ( mc != NULL ) {
|
2005-08-17 16:25:10 +08:00
|
|
|
meta_back_release_conn( op, mc );
|
|
|
|
}
|
|
|
|
|
2005-04-16 10:25:41 +08:00
|
|
|
if ( sendok & LDAP_BACK_SENDERR ) {
|
2005-06-29 07:22:48 +08:00
|
|
|
if ( rs->sr_err == LDAP_NO_SUCH_OBJECT ) {
|
|
|
|
rs->sr_matched = op->o_bd->be_suffix[ 0 ].bv_val;
|
|
|
|
}
|
2005-04-16 10:25:41 +08:00
|
|
|
send_ldap_result( op, rs );
|
|
|
|
rs->sr_text = NULL;
|
2005-06-29 07:22:48 +08:00
|
|
|
rs->sr_matched = NULL;
|
2005-04-16 10:25:41 +08:00
|
|
|
}
|
2005-08-17 16:25:10 +08:00
|
|
|
|
2005-04-16 10:25:41 +08:00
|
|
|
return NULL;
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
2005-04-16 10:25:41 +08:00
|
|
|
}
|
2001-05-12 08:51:28 +08:00
|
|
|
|
2005-04-16 10:25:41 +08:00
|
|
|
if ( newparent && meta_back_get_candidate( op, rs, op->orr_nnewSup ) != i )
|
|
|
|
{
|
2005-08-31 23:11:25 +08:00
|
|
|
if ( mc != NULL ) {
|
2005-08-17 16:25:10 +08:00
|
|
|
meta_back_release_conn( op, mc );
|
|
|
|
}
|
|
|
|
|
2005-04-16 10:25:41 +08:00
|
|
|
rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
|
|
|
|
rs->sr_text = "cross-target rename not supported";
|
|
|
|
if ( sendok & LDAP_BACK_SENDERR ) {
|
|
|
|
send_ldap_result( op, rs );
|
|
|
|
rs->sr_text = NULL;
|
|
|
|
}
|
2005-08-17 16:25:10 +08:00
|
|
|
|
2001-05-12 08:51:28 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
2005-04-16 10:25:41 +08:00
|
|
|
|
2005-05-06 01:34:11 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
2005-01-08 17:20:54 +08:00
|
|
|
"==>meta_back_getconn: got target %d for ndn=\"%s\" from cache\n",
|
2005-04-16 10:25:41 +08:00
|
|
|
i, op->o_req_ndn.bv_val, 0 );
|
|
|
|
|
2005-07-05 06:41:54 +08:00
|
|
|
if ( mc == NULL ) {
|
|
|
|
/* Retries searching for a metaconn in the avl tree
|
|
|
|
* the reason is that the connection might have been
|
|
|
|
* created by meta_back_get_candidate() */
|
2005-08-07 08:35:11 +08:00
|
|
|
ldap_pvt_thread_mutex_lock( &mi->mi_conn_mutex );
|
2005-07-05 06:41:54 +08:00
|
|
|
mc = (metaconn_t *)avl_find( mi->mi_conntree,
|
|
|
|
(caddr_t)&mc_curr, meta_back_conn_cmp );
|
|
|
|
if ( mc != NULL ) {
|
|
|
|
mc->mc_refcnt++;
|
|
|
|
}
|
|
|
|
ldap_pvt_thread_mutex_unlock( &mi->mi_conn_mutex );
|
2005-04-16 10:25:41 +08:00
|
|
|
|
2005-07-05 06:41:54 +08:00
|
|
|
/* Looks like we didn't get a bind. Open a new session... */
|
|
|
|
if ( mc == NULL ) {
|
|
|
|
mc = metaconn_alloc( op );
|
2005-09-25 02:39:26 +08:00
|
|
|
mc->mc_conn = mc_curr.mc_conn;
|
|
|
|
ber_dupbv( &mc->mc_local_ndn, &mc_curr.mc_local_ndn );
|
2005-07-05 06:41:54 +08:00
|
|
|
new_conn = 1;
|
|
|
|
}
|
2005-04-16 10:25:41 +08:00
|
|
|
}
|
2001-05-14 07:44:22 +08:00
|
|
|
|
2001-05-12 08:51:28 +08:00
|
|
|
/*
|
|
|
|
* Clear all other candidates
|
|
|
|
*/
|
2005-04-23 05:43:52 +08:00
|
|
|
( void )meta_clear_unused_candidates( op, i );
|
2001-05-12 08:51:28 +08:00
|
|
|
|
2005-09-25 02:39:26 +08:00
|
|
|
mt = &mi->mi_targets[ i ];
|
|
|
|
msc = &mc->mc_conns[ i ];
|
|
|
|
|
2001-05-12 08:51:28 +08:00
|
|
|
/*
|
|
|
|
* The target is activated; if needed, it is
|
2005-04-21 11:17:31 +08:00
|
|
|
* also init'd. In case of error, meta_back_init_one_conn
|
2001-05-17 07:06:15 +08:00
|
|
|
* sends the appropriate result.
|
2001-05-12 08:51:28 +08:00
|
|
|
*/
|
2005-09-25 02:39:26 +08:00
|
|
|
err = meta_back_init_one_conn( op, rs, mt, msc, sendok );
|
2005-07-04 07:28:35 +08:00
|
|
|
if ( err != LDAP_SUCCESS ) {
|
2001-05-12 08:51:28 +08:00
|
|
|
/*
|
|
|
|
* FIXME: in case one target cannot
|
|
|
|
* be init'd, should the other ones
|
|
|
|
* be tried?
|
|
|
|
*/
|
2005-04-22 06:22:43 +08:00
|
|
|
candidates[ i ].sr_tag = META_NOT_CANDIDATE;
|
2005-04-16 10:25:41 +08:00
|
|
|
if ( new_conn ) {
|
2005-09-25 02:39:26 +08:00
|
|
|
(void)meta_clear_one_candidate( msc );
|
2005-07-05 06:41:54 +08:00
|
|
|
meta_back_freeconn( op, mc );
|
|
|
|
|
|
|
|
} else {
|
|
|
|
meta_back_release_conn( op, mc );
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-08-31 09:55:34 +08:00
|
|
|
candidates[ i ].sr_err = LDAP_SUCCESS;
|
2005-07-04 07:28:35 +08:00
|
|
|
candidates[ i ].sr_tag = META_CANDIDATE;
|
|
|
|
ncandidates++;
|
|
|
|
|
2001-05-12 08:51:28 +08:00
|
|
|
if ( candidate ) {
|
|
|
|
*candidate = i;
|
|
|
|
}
|
|
|
|
|
2005-09-25 02:39:26 +08:00
|
|
|
if ( LDAP_BACK_CONN_ISPRIV( &mc_curr ) ) {
|
|
|
|
ber_dupbv( &msc->msc_cred, &mt->mt_pseudorootpw );
|
|
|
|
ber_dupbv( &msc->msc_bound_ndn, &mt->mt_pseudorootdn );
|
|
|
|
LDAP_BACK_CONN_ISPRIV_SET( msc );
|
|
|
|
|
|
|
|
} else {
|
|
|
|
BER_BVZERO( &msc->msc_cred );
|
|
|
|
BER_BVZERO( &msc->msc_bound_ndn );
|
|
|
|
if ( !BER_BVISEMPTY( &op->o_ndn )
|
|
|
|
&& SLAP_IS_AUTHZ_BACKEND( op )
|
|
|
|
&& i == mc->mc_authz_target )
|
|
|
|
{
|
|
|
|
ber_dupbv( &msc->msc_bound_ndn, &op->o_ndn );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-05-12 08:51:28 +08:00
|
|
|
/*
|
|
|
|
* if no unique candidate ...
|
|
|
|
*/
|
|
|
|
} else {
|
2005-04-16 10:25:41 +08:00
|
|
|
|
|
|
|
/* Looks like we didn't get a bind. Open a new session... */
|
2005-07-05 06:41:54 +08:00
|
|
|
if ( mc == NULL ) {
|
2005-05-05 07:57:55 +08:00
|
|
|
mc = metaconn_alloc( op );
|
2005-09-25 02:39:26 +08:00
|
|
|
mc->mc_conn = mc_curr.mc_conn;
|
|
|
|
ber_dupbv( &mc->mc_local_ndn, &mc_curr.mc_local_ndn );
|
2005-04-16 10:25:41 +08:00
|
|
|
new_conn = 1;
|
|
|
|
}
|
|
|
|
|
2005-04-21 11:17:31 +08:00
|
|
|
for ( i = 0; i < mi->mi_ntargets; i++ ) {
|
2005-09-25 02:39:26 +08:00
|
|
|
metatarget_t *mt = &mi->mi_targets[ i ];
|
|
|
|
metasingleconn_t *msc = &mc->mc_conns[ i ];
|
|
|
|
|
2001-05-12 08:51:28 +08:00
|
|
|
if ( i == cached
|
2005-09-25 02:39:26 +08:00
|
|
|
|| meta_back_is_candidate( &mt->mt_nsuffix,
|
|
|
|
mt->mt_scope,
|
|
|
|
&op->o_req_ndn,
|
|
|
|
LDAP_SCOPE_SUBTREE ) )
|
2005-01-08 17:20:54 +08:00
|
|
|
{
|
2001-05-12 08:51:28 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The target is activated; if needed, it is
|
|
|
|
* also init'd
|
|
|
|
*/
|
2005-04-21 11:17:31 +08:00
|
|
|
int lerr = meta_back_init_one_conn( op, rs,
|
2005-09-25 02:39:26 +08:00
|
|
|
mt, msc, sendok );
|
2005-04-21 11:17:31 +08:00
|
|
|
if ( lerr == LDAP_SUCCESS ) {
|
2005-04-22 06:22:43 +08:00
|
|
|
candidates[ i ].sr_tag = META_CANDIDATE;
|
2005-08-31 09:55:34 +08:00
|
|
|
candidates[ i ].sr_err = LDAP_SUCCESS;
|
2005-04-26 02:56:56 +08:00
|
|
|
ncandidates++;
|
2005-04-21 11:17:31 +08:00
|
|
|
|
2005-09-25 02:39:26 +08:00
|
|
|
if ( LDAP_BACK_CONN_ISPRIV( &mc_curr ) ) {
|
|
|
|
ber_dupbv( &msc->msc_cred, &mt->mt_pseudorootpw );
|
|
|
|
ber_dupbv( &msc->msc_bound_ndn, &mt->mt_pseudorootdn );
|
|
|
|
LDAP_BACK_CONN_ISPRIV_SET( msc );
|
|
|
|
|
|
|
|
} else {
|
|
|
|
BER_BVZERO( &msc->msc_cred );
|
|
|
|
BER_BVZERO( &msc->msc_bound_ndn );
|
|
|
|
if ( !BER_BVISEMPTY( &op->o_ndn )
|
|
|
|
&& SLAP_IS_AUTHZ_BACKEND( op )
|
|
|
|
&& i == mc->mc_authz_target )
|
|
|
|
{
|
|
|
|
ber_dupbv( &msc->msc_bound_ndn, &op->o_ndn );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-06 01:34:11 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "%s: meta_back_init_one_conn(%d)\n",
|
|
|
|
op->o_log_prefix, i, 0 );
|
|
|
|
|
2005-04-21 11:17:31 +08:00
|
|
|
} else {
|
2001-05-12 08:51:28 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* FIXME: in case one target cannot
|
|
|
|
* be init'd, should the other ones
|
|
|
|
* be tried?
|
|
|
|
*/
|
2005-04-26 02:56:56 +08:00
|
|
|
if ( new_conn ) {
|
2005-09-25 02:39:26 +08:00
|
|
|
( void )meta_clear_one_candidate( msc );
|
2005-04-26 02:56:56 +08:00
|
|
|
}
|
2005-08-31 09:55:34 +08:00
|
|
|
/* leave the target candidate, but record the error for later use */
|
|
|
|
candidates[ i ].sr_err = lerr;
|
2001-05-12 08:51:28 +08:00
|
|
|
err = lerr;
|
2005-04-21 11:17:31 +08:00
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_ANY, "%s: meta_back_init_one_conn(%d) failed: %d\n",
|
|
|
|
op->o_log_prefix, i, lerr );
|
|
|
|
|
2001-05-12 08:51:28 +08:00
|
|
|
continue;
|
|
|
|
}
|
2005-04-16 10:25:41 +08:00
|
|
|
|
|
|
|
} else {
|
2005-04-26 02:56:56 +08:00
|
|
|
if ( new_conn ) {
|
2005-09-25 02:39:26 +08:00
|
|
|
( void )meta_clear_one_candidate( msc );
|
2005-04-26 02:56:56 +08:00
|
|
|
}
|
2005-04-22 06:22:43 +08:00
|
|
|
candidates[ i ].sr_tag = META_NOT_CANDIDATE;
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
|
|
|
}
|
2005-04-26 02:56:56 +08:00
|
|
|
|
|
|
|
if ( ncandidates == 0 ) {
|
|
|
|
if ( new_conn ) {
|
2005-07-05 06:41:54 +08:00
|
|
|
meta_back_freeconn( op, mc );
|
|
|
|
|
|
|
|
} else {
|
|
|
|
meta_back_release_conn( op, mc );
|
2005-04-26 02:56:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
rs->sr_err = LDAP_NO_SUCH_OBJECT;
|
|
|
|
rs->sr_text = "Unable to select valid candidates";
|
|
|
|
|
|
|
|
if ( sendok & LDAP_BACK_SENDERR ) {
|
2005-06-29 07:22:48 +08:00
|
|
|
if ( rs->sr_err == LDAP_NO_SUCH_OBJECT ) {
|
|
|
|
rs->sr_matched = op->o_bd->be_suffix[ 0 ].bv_val;
|
|
|
|
}
|
2005-04-26 02:56:56 +08:00
|
|
|
send_ldap_result( op, rs );
|
|
|
|
rs->sr_text = NULL;
|
2005-06-29 07:22:48 +08:00
|
|
|
rs->sr_matched = NULL;
|
2005-04-26 02:56:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
|
|
|
|
2005-01-08 17:20:54 +08:00
|
|
|
done:;
|
2005-04-21 11:17:31 +08:00
|
|
|
/* clear out meta_back_init_one_conn non-fatal errors */
|
2003-04-04 05:35:54 +08:00
|
|
|
rs->sr_err = LDAP_SUCCESS;
|
|
|
|
rs->sr_text = NULL;
|
|
|
|
|
2001-05-12 08:51:28 +08:00
|
|
|
if ( new_conn ) {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Inserts the newly created metaconn in the avl tree
|
|
|
|
*/
|
2005-08-07 08:35:11 +08:00
|
|
|
ldap_pvt_thread_mutex_lock( &mi->mi_conn_mutex );
|
2005-04-21 11:17:31 +08:00
|
|
|
err = avl_insert( &mi->mi_conntree, ( caddr_t )mc,
|
2001-05-12 08:51:28 +08:00
|
|
|
meta_back_conn_cmp, meta_back_conn_dup );
|
|
|
|
|
|
|
|
#if PRINT_CONNTREE > 0
|
2005-04-21 11:17:31 +08:00
|
|
|
myprint( mi->mi_conntree );
|
2001-05-12 08:51:28 +08:00
|
|
|
#endif /* PRINT_CONNTREE */
|
|
|
|
|
2005-04-21 11:17:31 +08:00
|
|
|
ldap_pvt_thread_mutex_unlock( &mi->mi_conn_mutex );
|
2001-05-12 08:51:28 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Err could be -1 in case a duplicate metaconn is inserted
|
2005-07-05 06:41:54 +08:00
|
|
|
*
|
|
|
|
* FIXME: what if the same client issues more than one
|
|
|
|
* asynchronous operations?
|
2001-05-12 08:51:28 +08:00
|
|
|
*/
|
2005-07-04 07:28:35 +08:00
|
|
|
if ( err != 0 ) {
|
2005-05-06 01:34:11 +08:00
|
|
|
Debug( LDAP_DEBUG_ANY,
|
|
|
|
"%s meta_back_getconn: candidates=%d conn=%ld insert failed\n",
|
2005-09-25 02:39:26 +08:00
|
|
|
op->o_log_prefix, ncandidates,
|
|
|
|
LDAP_BACK_PCONN_ID( mc->mc_conn ) );
|
2005-04-22 20:59:30 +08:00
|
|
|
|
2003-04-04 05:35:54 +08:00
|
|
|
rs->sr_err = LDAP_OTHER;
|
|
|
|
rs->sr_text = "Internal server error";
|
2005-07-05 06:41:54 +08:00
|
|
|
meta_back_freeconn( op, mc );
|
2005-04-16 10:25:41 +08:00
|
|
|
if ( sendok & LDAP_BACK_SENDERR ) {
|
|
|
|
send_ldap_result( op, rs );
|
|
|
|
rs->sr_text = NULL;
|
|
|
|
}
|
2001-05-12 08:51:28 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
2005-01-08 17:20:54 +08:00
|
|
|
|
2005-07-04 07:28:35 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
"%s meta_back_getconn: candidates=%d conn=%ld inserted\n",
|
2005-09-25 02:39:26 +08:00
|
|
|
op->o_log_prefix, ncandidates,
|
|
|
|
LDAP_BACK_PCONN_ID( mc->mc_conn ) );
|
2005-07-04 07:28:35 +08:00
|
|
|
|
2001-05-12 08:51:28 +08:00
|
|
|
} else {
|
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
2005-05-06 01:34:11 +08:00
|
|
|
"%s meta_back_getconn: candidates=%d conn=%ld fetched\n",
|
2005-09-25 02:39:26 +08:00
|
|
|
op->o_log_prefix, ncandidates,
|
|
|
|
LDAP_BACK_PCONN_ID( mc->mc_conn ) );
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
|
|
|
|
2005-04-21 11:17:31 +08:00
|
|
|
return mc;
|
2001-05-12 08:51:28 +08:00
|
|
|
}
|
|
|
|
|
2005-07-05 06:41:54 +08:00
|
|
|
void
|
|
|
|
meta_back_release_conn(
|
|
|
|
Operation *op,
|
|
|
|
metaconn_t *mc )
|
|
|
|
{
|
|
|
|
metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
|
|
|
|
|
|
|
|
assert( mc != NULL );
|
|
|
|
|
2005-08-07 08:35:11 +08:00
|
|
|
ldap_pvt_thread_mutex_lock( &mi->mi_conn_mutex );
|
2005-07-05 06:41:54 +08:00
|
|
|
assert( mc->mc_refcnt > 0 );
|
|
|
|
mc->mc_refcnt--;
|
|
|
|
ldap_pvt_thread_mutex_unlock( &mi->mi_conn_mutex );
|
|
|
|
}
|