From e338733c97c93d217383a3fd7e23cf09d9883cb5 Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Tue, 22 Jun 2010 23:26:06 +0000 Subject: [PATCH] don't risk leaving around client library error codes; try to return additional information --- servers/slapd/back-meta/bind.c | 7 +++++-- servers/slapd/back-meta/conn.c | 1 + servers/slapd/back-meta/search.c | 23 +++++++++++++++++------ 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/servers/slapd/back-meta/bind.c b/servers/slapd/back-meta/bind.c index 5c56ec4274..7c89bee189 100644 --- a/servers/slapd/back-meta/bind.c +++ b/servers/slapd/back-meta/bind.c @@ -425,6 +425,7 @@ retry:; if ( rc != LDAP_SUCCESS ) { rs->sr_err = rc; } + rs->sr_err = slap_map_api2result( rs ); break; } } @@ -1042,10 +1043,12 @@ retry:; rc = ldap_parse_result( msc->msc_ld, res, &rs->sr_err, &matched, &text, &refs, &ctrls, 1 ); res = NULL; - rs->sr_text = text; - if ( rc != LDAP_SUCCESS ) { + if ( rc == LDAP_SUCCESS ) { + rs->sr_text = text; + } else { rs->sr_err = rc; } + rs->sr_err = slap_map_api2result( rs ); /* RFC 4511: referrals can only appear * if result code is LDAP_REFERRAL */ diff --git a/servers/slapd/back-meta/conn.c b/servers/slapd/back-meta/conn.c index 7fa6ce65b9..ca5b7932c3 100644 --- a/servers/slapd/back-meta/conn.c +++ b/servers/slapd/back-meta/conn.c @@ -485,6 +485,7 @@ retry:; if ( rs->sr_err == LDAP_SUCCESS ) { rs->sr_err = err; } + rs->sr_err = slap_map_api2result( rs ); /* FIXME: in case a referral * is returned, should we try diff --git a/servers/slapd/back-meta/search.c b/servers/slapd/back-meta/search.c index c328c57a73..740266c7fc 100644 --- a/servers/slapd/back-meta/search.c +++ b/servers/slapd/back-meta/search.c @@ -387,10 +387,8 @@ meta_search_dobind_result( NULL, NULL, NULL, NULL, 0 ); if ( rc != LDAP_SUCCESS ) { candidates[ candidate ].sr_err = rc; - - } else { - rc = slap_map_api2result( &candidates[ candidate ] ); } + rc = slap_map_api2result( &candidates[ candidate ] ); ldap_pvt_thread_mutex_lock( &mi->mi_conninfo.lai_mutex ); LDAP_BACK_CONN_BINDING_CLEAR( msc ); @@ -688,6 +686,7 @@ meta_back_search( Operation *op, SlapReply *rs ) int is_ok = 0; void *savepriv; SlapReply *candidates = NULL; + int do_taint = 0; /* * controls are set in ldap_back_dobind() @@ -1292,11 +1291,12 @@ really_bad:; msg, &candidates[ i ].sr_err, (char **)&candidates[ i ].sr_matched, - NULL /* (char **)&candidates[ i ].sr_text */ , + (char **)&candidates[ i ].sr_text, &references, NULL /* &candidates[ i ].sr_ctrls (unused) */ , 0 ); if ( rs->sr_err != LDAP_SUCCESS ) { + candidates[ i ].sr_err = rs->sr_err; sres = slap_map_api2result( &candidates[ i ] ); candidates[ i ].sr_type = REP_RESULT; ldap_msgfree( res ); @@ -1438,9 +1438,12 @@ really_bad:; if ( rs->sr_nentries == op->ors_slimit || META_BACK_ONERR_STOP( mi ) ) { + char *save_text = rs->sr_text; savepriv = op->o_private; op->o_private = (void *)i; + rs->sr_text = candidates[ i ].sr_text; send_ldap_result( op, rs ); + rs->sr_text = save_text; op->o_private = savepriv; ldap_msgfree( res ); res = NULL; @@ -1451,9 +1454,12 @@ really_bad:; default: candidates[ i ].sr_err = rs->sr_err; if ( META_BACK_ONERR_STOP( mi ) ) { + char *save_text = rs->sr_text; savepriv = op->o_private; op->o_private = (void *)i; + rs->sr_text = candidates[ i ].sr_text; send_ldap_result( op, rs ); + rs->sr_text = save_text; op->o_private = savepriv; ldap_msgfree( res ); res = NULL; @@ -1801,12 +1807,17 @@ finish:; && op->o_time > mc->mc_conns[ i ].msc_time ) { /* don't let anyone else use this expired connection */ - LDAP_BACK_CONN_TAINTED_SET( mc ); + do_taint++; } } if ( mc ) { - meta_back_release_conn( mi, mc ); + ldap_pvt_thread_mutex_lock( &mi->mi_conninfo.lai_mutex ); + if ( do_taint ) { + LDAP_BACK_CONN_TAINTED_SET( mc ); + } + meta_back_release_conn_lock( mi, mc, 0 ); + ldap_pvt_thread_mutex_unlock( &mi->mi_conninfo.lai_mutex ); } return rs->sr_err; -- 2.39.5