From: Pierangelo Masarati Date: Wed, 31 Aug 2005 01:55:34 +0000 (+0000) Subject: save target errors for later evaluation X-Git-Tag: OPENLDAP_REL_ENG_2_2_MP~528 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=a2ea1edb48e799568afefd1eaf551834675f7b28;p=openldap save target errors for later evaluation --- diff --git a/servers/slapd/back-meta/bind.c b/servers/slapd/back-meta/bind.c index d3861a4176..424210da02 100644 --- a/servers/slapd/back-meta/bind.c +++ b/servers/slapd/back-meta/bind.c @@ -488,6 +488,7 @@ retry:; } } else { + rs->sr_err = rc; rc = slap_map_api2result( rs ); } @@ -580,8 +581,6 @@ meta_back_dobind( } if ( rc != LDAP_SUCCESS ) { - rs->sr_err = slap_map_api2result( rs ); - Debug( LDAP_DEBUG_ANY, "%s meta_back_dobind[%d]: " "(anonymous) err=%d\n", op->o_log_prefix, i, rc ); @@ -593,7 +592,8 @@ meta_back_dobind( * due to technical reasons (remote host down?) * so better clear the handle */ - candidates[ i ].sr_tag = META_NOT_CANDIDATE; + /* leave the target candidate, but record the error for later use */ + candidates[ i ].sr_err = rc; if ( META_BACK_ONERR_STOP( mi ) ) { bound = 0; goto done; @@ -666,8 +666,8 @@ meta_back_op_result( int i, rerr = LDAP_SUCCESS; char *rmsg = NULL, - *save_rmsg = NULL, - *rmatch = NULL, + *rmatch = NULL; + const char *save_rmsg = NULL, *save_rmatch = NULL; void *rmatch_ctx = NULL; diff --git a/servers/slapd/back-meta/conn.c b/servers/slapd/back-meta/conn.c index 5f10ce40d2..6184946c8d 100644 --- a/servers/slapd/back-meta/conn.c +++ b/servers/slapd/back-meta/conn.c @@ -547,6 +547,8 @@ meta_back_get_candidate( return candidate; } +static void *meta_back_candidates_dummy; + static void meta_back_candidates_keyfree( void *key, @@ -568,7 +570,7 @@ meta_back_candidates_get( Operation *op ) void *data = NULL; ldap_pvt_thread_pool_getkey( op->o_threadctx, - meta_back_candidates_keyfree, &data, NULL ); + &meta_back_candidates_dummy, &data, NULL ); mc = (metacandidates_t *)data; } else { @@ -584,7 +586,7 @@ meta_back_candidates_get( Operation *op ) data = (void *)mc; ldap_pvt_thread_pool_setkey( op->o_threadctx, - meta_back_candidates_keyfree, data, + &meta_back_candidates_dummy, data, meta_back_candidates_keyfree ); } else { @@ -728,9 +730,11 @@ meta_back_getconn( * The target is activated; if needed, it is * also init'd */ - int lerr = meta_back_init_one_conn( op, rs, &mi->mi_targets[ i ], - &mc->mc_conns[ i ], sendok ); - if ( lerr == LDAP_SUCCESS ) { + candidates[ i ].sr_err = + meta_back_init_one_conn( op, rs, + &mi->mi_targets[ i ], + &mc->mc_conns[ i ], sendok ); + if ( candidates[ i ].sr_err == LDAP_SUCCESS ) { candidates[ i ].sr_tag = META_CANDIDATE; ncandidates++; @@ -742,7 +746,7 @@ meta_back_getconn( * be tried? */ candidates[ i ].sr_tag = META_NOT_CANDIDATE; - err = lerr; + err = candidates[ i ].sr_err; continue; } } @@ -892,6 +896,7 @@ meta_back_getconn( return NULL; } + candidates[ i ].sr_err = LDAP_SUCCESS; candidates[ i ].sr_tag = META_CANDIDATE; ncandidates++; @@ -927,6 +932,7 @@ meta_back_getconn( &mc->mc_conns[ i ], sendok ); if ( lerr == LDAP_SUCCESS ) { candidates[ i ].sr_tag = META_CANDIDATE; + candidates[ i ].sr_err = LDAP_SUCCESS; ncandidates++; Debug( LDAP_DEBUG_TRACE, "%s: meta_back_init_one_conn(%d)\n", @@ -942,7 +948,8 @@ meta_back_getconn( if ( new_conn ) { ( void )meta_clear_one_candidate( &mc->mc_conns[ i ] ); } - candidates[ i ].sr_tag = META_NOT_CANDIDATE; + /* leave the target candidate, but record the error for later use */ + candidates[ i ].sr_err = lerr; err = lerr; Debug( LDAP_DEBUG_ANY, "%s: meta_back_init_one_conn(%d) failed: %d\n", diff --git a/servers/slapd/back-meta/search.c b/servers/slapd/back-meta/search.c index edf3975be4..55edc25767 100644 --- a/servers/slapd/back-meta/search.c +++ b/servers/slapd/back-meta/search.c @@ -272,17 +272,17 @@ meta_back_search( Operation *op, SlapReply *rs ) metasingleconn_t *msc = &mc->mc_conns[ i ]; candidates[ i ].sr_msgid = -1; - - if ( candidates[ i ].sr_tag != META_CANDIDATE ) { - continue; - } - - candidates[ i ].sr_err = LDAP_SUCCESS; candidates[ i ].sr_matched = NULL; candidates[ i ].sr_text = NULL; candidates[ i ].sr_ref = NULL; candidates[ i ].sr_ctrls = NULL; + if ( candidates[ i ].sr_tag != META_CANDIDATE + || candidates[ i ].sr_err != LDAP_SUCCESS ) + { + continue; + } + switch ( meta_back_search_start( op, rs, &dc, msc, i, candidates ) ) { case 0: @@ -333,9 +333,20 @@ meta_back_search( Operation *op, SlapReply *rs ) op->o_log_prefix, op->o_req_dn.bv_val, op->ors_scope ); - send_ldap_error( op, rs, LDAP_NO_SUCH_OBJECT, NULL ); - + /* FIXME: we're sending the first error we encounter; + * maybe we should pick the worst... */ rc = LDAP_NO_SUCH_OBJECT; + for ( i = 0; i < mi->mi_ntargets; i++ ) { + if ( candidates[ i ].sr_tag == META_CANDIDATE + && candidates[ i ].sr_err != LDAP_SUCCESS ) + { + rc = candidates[ i ].sr_err; + break; + } + } + + send_ldap_error( op, rs, rc, NULL ); + goto finish; }