int msc_candidate;
#define META_NOT_CANDIDATE ((ber_tag_t)0)
#define META_CANDIDATE ((ber_tag_t)1)
-#define META_LAST_CONN ((ber_tag_t)(-1))
LDAP *msc_ld;
struct berval msc_bound_ndn;
struct metainfo_t *msc_info;
} metasingleconn_t;
-#define META_LAST(msc) ((msc)->msc_candidate == META_LAST_CONN)
-
typedef struct metaconn_t {
struct slap_conn *mc_conn;
ldap_pvt_thread_mutex_t mc_mutex;
}
break;
}
+
+ } else {
+ rc = slap_map_api2result( rs );
}
rs->sr_err = rc;
{
metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
- metasingleconn_t *msc;
int bound = 0, i;
SlapReply *candidates = meta_back_candidates_get( op );
ldap_pvt_thread_mutex_lock( &mc->mc_mutex );
+ Debug( LDAP_DEBUG_TRACE,
+ "%s meta_back_dobind: conn=%ld\n",
+ op->o_log_prefix, mc->mc_conn->c_connid, 0 );
+
/*
* all the targets are bound as pseudoroot
*/
goto done;
}
- for ( i = 0, msc = &mc->mc_conns[ 0 ]; !META_LAST( msc ); ++i, ++msc ) {
- metatarget_t *mt = &mi->mi_targets[ i ];
- int rc;
+ for ( i = 0; i < mi->mi_ntargets; i++ ) {
+ metatarget_t *mt = &mi->mi_targets[ i ];
+ metasingleconn_t *msc = &mc->mc_conns[ i ];
+ int rc;
/*
- * Not a candidate or something wrong with this target ...
+ * Not a candidate
*/
- if ( msc->msc_ld == NULL ) {
+ if ( candidates[ i ].sr_tag != META_CANDIDATE ) {
continue;
}
+ assert( msc->msc_ld != NULL );
+
/*
* If the target is already bound it is skipped
*/
if ( msc->msc_bound == META_BOUND && mc->mc_auth_target == i ) {
++bound;
+
+ Debug( LDAP_DEBUG_TRACE, "%s meta_back_dobind[%d]: "
+ "authcTarget\n",
+ op->o_log_prefix, i, 0 );
continue;
}
* so better clear the handle
*/
candidates[ i ].sr_tag = META_NOT_CANDIDATE;
-#if 0
- ( void )meta_clear_one_candidate( msc );
-#endif
continue;
} /* else */
- candidates[ i ].sr_tag = META_CANDIDATE;
+ Debug( LDAP_DEBUG_TRACE, "%s meta_back_dobind[%d]: "
+ "(anonymous)\n",
+ op->o_log_prefix, i, 0 );
+
msc->msc_bound = META_ANONYMOUS;
++bound;
}
done:;
ldap_pvt_thread_mutex_unlock( &mc->mc_mutex );
- if ( bound == 0 && sendok & LDAP_BACK_SENDERR ) {
+ Debug( LDAP_DEBUG_TRACE,
+ "%s meta_back_dobind: conn=%ld bound=%d\n",
+ op->o_log_prefix, mc->mc_conn->c_connid, bound );
+
+ if ( bound == 0 && ( sendok & LDAP_BACK_SENDERR ) ) {
if ( rs->sr_err == LDAP_SUCCESS ) {
rs->sr_err = LDAP_BUSY;
}
SlapReply *rs,
int candidate )
{
+ metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
+
int i,
rerr = LDAP_SUCCESS;
- metasingleconn_t *msc;
char *rmsg = NULL;
char *rmatch = NULL;
int free_rmsg = 0,
free_rmatch = 0;
if ( candidate != META_TARGET_NONE ) {
- msc = &mc->mc_conns[ candidate ];
+ metasingleconn_t *msc = &mc->mc_conns[ candidate ];
rs->sr_err = LDAP_SUCCESS;
}
} else {
- for ( i = 0, msc = &mc->mc_conns[ 0 ]; !META_LAST( msc ); ++i, ++msc ) {
- char *msg = NULL;
- char *match = NULL;
+ for ( i = 0; i < mi->mi_ntargets; i++ ) {
+ metasingleconn_t *msc = &mc->mc_conns[ i ];
+ char *msg = NULL;
+ char *match = NULL;
rs->sr_err = LDAP_SUCCESS;
{
metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
metaconn_t *mc;
- metasingleconn_t *msc;
char *match = NULL,
*err = NULL;
struct berval mmatch = BER_BVNULL;
dc.rs = rs;
dc.ctx = "compareDN";
- for ( i = 0, msc = &mc->mc_conns[ 0 ]; !META_LAST( msc ); ++i, ++msc ) {
- struct berval mdn = BER_BVNULL;
- struct berval mapped_attr = op->orc_ava->aa_desc->ad_cname;
- struct berval mapped_value = op->orc_ava->aa_value;
+ for ( i = 0; i < mi->mi_ntargets; i++ ) {
+ metasingleconn_t *msc = &mc->mc_conns[ i ];
+ struct berval mdn = BER_BVNULL;
+ struct berval mapped_attr = op->orc_ava->aa_desc->ad_cname;
+ struct berval mapped_value = op->orc_ava->aa_value;
if ( candidates[ i ].sr_tag != META_CANDIDATE ) {
msgid[ i ] = -1;
/*
* FIXME: should we check for abandon?
*/
- for ( i = 0, msc = &mc->mc_conns[ 0 ]; !META_LAST( msc ); msc++, i++ ) {
- int lrc;
- LDAPMessage *res = NULL;
- struct timeval tv = { 0 };
+ for ( i = 0; i < mi->mi_ntargets; i++ ) {
+ metasingleconn_t *msc = &mc->mc_conns[ i ];
+ int lrc;
+ LDAPMessage *res = NULL;
+ struct timeval tv = { 0 };
tv.tv_sec = 0;
tv.tv_usec = 0;
{
metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
metaconn_t *mc;
- int ntargets = mi->mi_ntargets;
+ int i, ntargets = mi->mi_ntargets;
assert( ntargets > 0 );
/* malloc once only; leave an extra one for one-past-end */
mc = ( metaconn_t * )ch_malloc( sizeof( metaconn_t )
- + sizeof( metasingleconn_t ) * ( ntargets + 1 ) );
+ + sizeof( metasingleconn_t ) * ntargets );
if ( mc == NULL ) {
return NULL;
}
mc->mc_conns = ( metasingleconn_t * )&mc[ 1 ];
- /* FIXME: needed by META_LAST() */
- mc->mc_conns[ ntargets ].msc_candidate = META_LAST_CONN;
-
- for ( ; ntargets-- > 0; ) {
- mc->mc_conns[ ntargets ].msc_ld = NULL;
- BER_BVZERO( &mc->mc_conns[ ntargets ].msc_bound_ndn );
- BER_BVZERO( &mc->mc_conns[ ntargets ].msc_cred );
- mc->mc_conns[ ntargets ].msc_bound = META_UNBOUND;
- mc->mc_conns[ ntargets ].msc_info = mi;
+ 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 );
+ mc->mc_conns[ i ].msc_bound = META_UNBOUND;
+ mc->mc_conns[ i ].msc_info = mi;
}
mc->mc_auth_target = META_BOUND_NONE;
int cached = META_TARGET_NONE,
i = META_TARGET_NONE,
err = LDAP_SUCCESS,
- new_conn = 0;
+ new_conn = 0,
+ ncandidates = 0;
+
meta_op_type op_type = META_OP_REQUIRE_SINGLE;
int parent = 0,
&mc->mc_conns[ i ], sendok );
if ( lerr == LDAP_SUCCESS ) {
candidates[ i ].sr_tag = META_CANDIDATE;
+ ncandidates++;
} else {
return NULL;
}
- Debug( LDAP_DEBUG_CACHE,
+ Debug( LDAP_DEBUG_TRACE,
"==>meta_back_getconn: got target %d for ndn=\"%s\" from cache\n",
i, op->o_req_ndn.bv_val, 0 );
&mc->mc_conns[ i ], sendok );
if ( err == LDAP_SUCCESS ) {
candidates[ i ].sr_tag = META_CANDIDATE;
+ ncandidates++;
} else {
*/
} else {
- int ncandidates = 0;
-
/* Looks like we didn't get a bind. Open a new session... */
if ( !mc ) {
mc = metaconn_alloc( op );
candidates[ i ].sr_tag = META_CANDIDATE;
ncandidates++;
+ Debug( LDAP_DEBUG_TRACE, "%s: meta_back_init_one_conn(%d)\n",
+ op->o_log_prefix, i, 0 );
+
} else {
/*
*/
if ( err == 0 ) {
Debug( LDAP_DEBUG_TRACE,
- "%s meta_back_getconn: conn %ld inserted\n",
- op->o_log_prefix, mc->mc_conn->c_connid, 0 );
+ "%s meta_back_getconn: candidates=%d conn=%ld inserted\n",
+ op->o_log_prefix, ncandidates, mc->mc_conn->c_connid );
} else {
- Debug( LDAP_DEBUG_TRACE,
- "%s meta_back_getconn: conn %ld insert failed\n",
- op->o_log_prefix, mc->mc_conn->c_connid, 0 );
+ Debug( LDAP_DEBUG_ANY,
+ "%s meta_back_getconn: candidates=%d conn=%ld insert failed\n",
+ op->o_log_prefix, ncandidates, mc->mc_conn->c_connid );
rs->sr_err = LDAP_OTHER;
rs->sr_text = "Internal server error";
} else {
Debug( LDAP_DEBUG_TRACE,
- "%s meta_back_getconn: conn %ld fetched\n",
- op->o_log_prefix, mc->mc_conn->c_connid, 0 );
+ "%s meta_back_getconn: candidates=%d conn=%ld fetched\n",
+ op->o_log_prefix, ncandidates, mc->mc_conn->c_connid );
}
return mc;
void *v_mc )
{
metaconn_t *mc = v_mc;
- metasingleconn_t *msc;
+ int i, ntargets;
assert( mc->mc_conns != NULL );
- for ( msc = &mc->mc_conns[ 0 ]; !META_LAST( msc ); msc++ ) {
+ /* at least one must be present... */
+ ntargets = mc->mc_conns[ 0 ].msc_info->mi_ntargets;
+
+ for ( i = 0; i < ntargets; i++ ) {
+ metasingleconn_t *msc = &mc->mc_conns[ i ];
+
if ( msc->msc_ld != NULL ) {
ldap_unbind_ext_s( msc->msc_ld, NULL, NULL );
}
+
if ( !BER_BVISNULL( &msc->msc_bound_ndn ) ) {
ber_memfree( msc->msc_bound_ndn.bv_val );
}
+
if ( !BER_BVISNULL( &msc->msc_cred ) ) {
/* destroy sensitive data */
memset( msc->msc_cred.bv_val, 0, msc->msc_cred.bv_len );
{
metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
metaconn_t *mc;
- metasingleconn_t *msc;
struct timeval tv = { 0, 0 };
LDAPMessage *res = NULL, *e;
int rc = 0, sres = LDAP_SUCCESS;
/*
* Inits searches
*/
- for ( i = 0, msc = &mc->mc_conns[ 0 ]; !META_LAST( msc ); ++i, ++msc ) {
+ for ( i = 0; i < mi->mi_ntargets; i++ ) {
+ metasingleconn_t *msc = &mc->mc_conns[ i ];
+
candidates[ i ].sr_msgid = -1;
if ( candidates[ i ].sr_tag != META_CANDIDATE ) {
for ( rc = 0; ncandidates > 0; ) {
int gotit = 0, doabandon = 0;
- for ( i = 0, msc = &mc->mc_conns[ 0 ]; !META_LAST( msc ); msc++, i++ ) {
+ for ( i = 0; i < mi->mi_ntargets; i++ ) {
+ metasingleconn_t *msc = &mc->mc_conns[ i ];
+
if ( candidates[ i ].sr_msgid == -1 ) {
continue;
}
/* check for abandon */
if ( op->o_abandon || doabandon ) {
- for ( i = 0, msc = mc->mc_conns; !META_LAST( msc ); msc++, i++ ) {
+ for ( i = 0; i < mi->mi_ntargets; i++ ) {
+ metasingleconn_t *msc = &mc->mc_conns[ i ];
+
if ( candidates[ i ].sr_msgid != -1 ) {
ldap_abandon_ext( msc->msc_ld,
candidates[ i ].sr_msgid,