mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-01-12 10:54:48 +08:00
cleanup and streamline response handling
This commit is contained in:
parent
968da1cb14
commit
f449ee6500
@ -117,6 +117,10 @@ meta_search_dobind_init(
|
|||||||
/* for some reason (e.g. because formerly in "binding"
|
/* for some reason (e.g. because formerly in "binding"
|
||||||
* state, with eventual connection expiration or invalidation)
|
* state, with eventual connection expiration or invalidation)
|
||||||
* it was not initialized as expected */
|
* it was not initialized as expected */
|
||||||
|
|
||||||
|
Debug( LDAP_DEBUG_ANY, "%s meta_search_dobind_init[%d] ld=NULL\n",
|
||||||
|
op->o_log_prefix, candidate, 0 );
|
||||||
|
|
||||||
rc = meta_back_init_one_conn( op, rs, *mcp, candidate,
|
rc = meta_back_init_one_conn( op, rs, *mcp, candidate,
|
||||||
LDAP_BACK_CONN_ISPRIV( *mcp ), LDAP_BACK_DONTSEND );
|
LDAP_BACK_CONN_ISPRIV( *mcp ), LDAP_BACK_DONTSEND );
|
||||||
switch ( rc ) {
|
switch ( rc ) {
|
||||||
@ -175,6 +179,8 @@ meta_search_dobind_init(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert( msc->msc_ld != NULL );
|
||||||
|
|
||||||
rc = ldap_sasl_bind( msc->msc_ld, binddn.bv_val, LDAP_SASL_SIMPLE, &cred,
|
rc = ldap_sasl_bind( msc->msc_ld, binddn.bv_val, LDAP_SASL_SIMPLE, &cred,
|
||||||
NULL, NULL, &candidates[ candidate ].sr_msgid );
|
NULL, NULL, &candidates[ candidate ].sr_msgid );
|
||||||
switch ( rc ) {
|
switch ( rc ) {
|
||||||
@ -182,8 +188,8 @@ meta_search_dobind_init(
|
|||||||
META_BINDING_SET( &candidates[ candidate ] );
|
META_BINDING_SET( &candidates[ candidate ] );
|
||||||
return META_SEARCH_BINDING;
|
return META_SEARCH_BINDING;
|
||||||
|
|
||||||
down:;
|
|
||||||
case LDAP_SERVER_DOWN:
|
case LDAP_SERVER_DOWN:
|
||||||
|
down:;
|
||||||
/* This is the worst thing that could happen:
|
/* This is the worst thing that could happen:
|
||||||
* the search will wait until the retry is over. */
|
* the search will wait until the retry is over. */
|
||||||
if ( meta_back_retry( op, rs, mcp, candidate, LDAP_BACK_DONTSEND ) ) {
|
if ( meta_back_retry( op, rs, mcp, candidate, LDAP_BACK_DONTSEND ) ) {
|
||||||
@ -197,8 +203,8 @@ down:;
|
|||||||
}
|
}
|
||||||
/* fall thru */
|
/* fall thru */
|
||||||
|
|
||||||
other:;
|
|
||||||
default:
|
default:
|
||||||
|
other:;
|
||||||
rs->sr_err = rc;
|
rs->sr_err = rc;
|
||||||
rc = slap_map_api2result( rs );
|
rc = slap_map_api2result( rs );
|
||||||
|
|
||||||
@ -243,7 +249,7 @@ meta_search_dobind_result(
|
|||||||
/* FIXME: matched? referrals? response controls? */
|
/* FIXME: matched? referrals? response controls? */
|
||||||
rc = ldap_parse_result( msc->msc_ld, res,
|
rc = ldap_parse_result( msc->msc_ld, res,
|
||||||
&candidates[ candidate ].sr_err,
|
&candidates[ candidate ].sr_err,
|
||||||
NULL, NULL, NULL, NULL, 1 );
|
NULL, NULL, NULL, NULL, 0 );
|
||||||
if ( rc != LDAP_SUCCESS ) {
|
if ( rc != LDAP_SUCCESS ) {
|
||||||
candidates[ candidate ].sr_err = rc;
|
candidates[ candidate ].sr_err = rc;
|
||||||
}
|
}
|
||||||
@ -525,7 +531,6 @@ meta_back_search( Operation *op, SlapReply *rs )
|
|||||||
metaconn_t *mc;
|
metaconn_t *mc;
|
||||||
struct timeval tv = { 0, 0 };
|
struct timeval tv = { 0, 0 };
|
||||||
time_t stoptime = (time_t)-1;
|
time_t stoptime = (time_t)-1;
|
||||||
LDAPMessage *res = NULL, *e;
|
|
||||||
int rc = 0, sres = LDAP_SUCCESS;
|
int rc = 0, sres = LDAP_SUCCESS;
|
||||||
char *matched = NULL;
|
char *matched = NULL;
|
||||||
int last = 0, ncandidates = 0,
|
int last = 0, ncandidates = 0,
|
||||||
@ -678,6 +683,7 @@ meta_back_search( Operation *op, SlapReply *rs )
|
|||||||
|
|
||||||
for ( i = 0; i < mi->mi_ntargets; i++ ) {
|
for ( i = 0; i < mi->mi_ntargets; i++ ) {
|
||||||
metasingleconn_t *msc = &mc->mc_conns[ i ];
|
metasingleconn_t *msc = &mc->mc_conns[ i ];
|
||||||
|
LDAPMessage *res = NULL, *msg;
|
||||||
|
|
||||||
if ( candidates[ i ].sr_msgid == META_MSGID_IGNORE ) {
|
if ( candidates[ i ].sr_msgid == META_MSGID_IGNORE ) {
|
||||||
continue;
|
continue;
|
||||||
@ -721,7 +727,7 @@ meta_back_search( Operation *op, SlapReply *rs )
|
|||||||
switch ( meta_back_search_start( op, rs, &dc, &mc, i, candidates ) )
|
switch ( meta_back_search_start( op, rs, &dc, &mc, i, candidates ) )
|
||||||
{
|
{
|
||||||
case META_SEARCH_CANDIDATE:
|
case META_SEARCH_CANDIDATE:
|
||||||
goto get_result;
|
break;
|
||||||
|
|
||||||
/* means that failed but onerr == continue */
|
/* means that failed but onerr == continue */
|
||||||
case META_SEARCH_NOT_CANDIDATE:
|
case META_SEARCH_NOT_CANDIDATE:
|
||||||
@ -765,9 +771,8 @@ meta_back_search( Operation *op, SlapReply *rs )
|
|||||||
* get a LDAP_TIMELIMIT_EXCEEDED from
|
* get a LDAP_TIMELIMIT_EXCEEDED from
|
||||||
* one of them ...
|
* one of them ...
|
||||||
*/
|
*/
|
||||||
get_result:;
|
|
||||||
rc = ldap_result( msc->msc_ld, candidates[ i ].sr_msgid,
|
rc = ldap_result( msc->msc_ld, candidates[ i ].sr_msgid,
|
||||||
LDAP_MSG_ONE, &tv, &res );
|
LDAP_MSG_RECEIVED, &tv, &res );
|
||||||
switch ( rc ) {
|
switch ( rc ) {
|
||||||
case 0:
|
case 0:
|
||||||
/* FIXME: res should not need to be freed */
|
/* FIXME: res should not need to be freed */
|
||||||
@ -785,7 +790,7 @@ really_bad:;
|
|||||||
switch ( meta_back_search_start( op, rs, &dc, &mc, i, candidates ) )
|
switch ( meta_back_search_start( op, rs, &dc, &mc, i, candidates ) )
|
||||||
{
|
{
|
||||||
case META_SEARCH_CANDIDATE:
|
case META_SEARCH_CANDIDATE:
|
||||||
goto get_result;
|
break;
|
||||||
|
|
||||||
/* means that failed but onerr == continue */
|
/* means that failed but onerr == continue */
|
||||||
case META_SEARCH_NOT_CANDIDATE:
|
case META_SEARCH_NOT_CANDIDATE:
|
||||||
@ -837,7 +842,14 @@ really_bad:;
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for ( msg = ldap_first_message( msc->msc_ld, res );
|
||||||
|
msg != NULL;
|
||||||
|
msg = ldap_next_message( msc->msc_ld, msg ) )
|
||||||
|
{
|
||||||
|
rc = ldap_msgtype( msg );
|
||||||
if ( rc == LDAP_RES_SEARCH_ENTRY ) {
|
if ( rc == LDAP_RES_SEARCH_ENTRY ) {
|
||||||
|
LDAPMessage *e;
|
||||||
|
|
||||||
if ( candidates[ i ].sr_type == REP_INTERMEDIATE ) {
|
if ( candidates[ i ].sr_type == REP_INTERMEDIATE ) {
|
||||||
/* don't retry any more... */
|
/* don't retry any more... */
|
||||||
candidates[ i ].sr_type = REP_RESULT;
|
candidates[ i ].sr_type = REP_RESULT;
|
||||||
@ -845,12 +857,10 @@ really_bad:;
|
|||||||
|
|
||||||
is_ok++;
|
is_ok++;
|
||||||
|
|
||||||
e = ldap_first_entry( msc->msc_ld, res );
|
e = ldap_first_entry( msc->msc_ld, msg );
|
||||||
savepriv = op->o_private;
|
savepriv = op->o_private;
|
||||||
op->o_private = (void *)i;
|
op->o_private = (void *)i;
|
||||||
rs->sr_err = meta_send_entry( op, rs, mc, i, e );
|
rs->sr_err = meta_send_entry( op, rs, mc, i, e );
|
||||||
ldap_msgfree( res );
|
|
||||||
res = NULL;
|
|
||||||
|
|
||||||
switch ( rs->sr_err ) {
|
switch ( rs->sr_err ) {
|
||||||
case LDAP_SIZELIMIT_EXCEEDED:
|
case LDAP_SIZELIMIT_EXCEEDED:
|
||||||
@ -859,10 +869,14 @@ really_bad:;
|
|||||||
send_ldap_result( op, rs );
|
send_ldap_result( op, rs );
|
||||||
op->o_private = savepriv;
|
op->o_private = savepriv;
|
||||||
rs->sr_err = LDAP_SUCCESS;
|
rs->sr_err = LDAP_SUCCESS;
|
||||||
|
ldap_msgfree( res );
|
||||||
|
res = NULL;
|
||||||
goto finish;
|
goto finish;
|
||||||
|
|
||||||
case LDAP_UNAVAILABLE:
|
case LDAP_UNAVAILABLE:
|
||||||
rs->sr_err = LDAP_OTHER;
|
rs->sr_err = LDAP_OTHER;
|
||||||
|
ldap_msgfree( res );
|
||||||
|
res = NULL;
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
op->o_private = savepriv;
|
op->o_private = savepriv;
|
||||||
@ -872,28 +886,6 @@ really_bad:;
|
|||||||
tv.tv_sec = 0;
|
tv.tv_sec = 0;
|
||||||
tv.tv_usec = 0;
|
tv.tv_usec = 0;
|
||||||
|
|
||||||
#if 0
|
|
||||||
/*
|
|
||||||
* If scope is BASE, we need to jump out
|
|
||||||
* as soon as one entry is found; if
|
|
||||||
* the target pool is properly crafted,
|
|
||||||
* this should correspond to the sole
|
|
||||||
* entry that has the base DN
|
|
||||||
*/
|
|
||||||
/* FIXME: this defeats the purpose of
|
|
||||||
* doing a search with scope == base and
|
|
||||||
* sizelimit = 1 to determine if a
|
|
||||||
* candidate is actually unique */
|
|
||||||
if ( op->ors_scope == LDAP_SCOPE_BASE
|
|
||||||
&& rs->sr_nentries > 0 )
|
|
||||||
{
|
|
||||||
doabandon = 1;
|
|
||||||
ncandidates = 0;
|
|
||||||
sres = LDAP_SUCCESS;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
} else if ( rc == LDAP_RES_SEARCH_REFERENCE ) {
|
} else if ( rc == LDAP_RES_SEARCH_REFERENCE ) {
|
||||||
char **references = NULL;
|
char **references = NULL;
|
||||||
int cnt;
|
int cnt;
|
||||||
@ -905,9 +897,8 @@ really_bad:;
|
|||||||
|
|
||||||
is_ok++;
|
is_ok++;
|
||||||
|
|
||||||
rc = ldap_parse_reference( msc->msc_ld, res,
|
rc = ldap_parse_reference( msc->msc_ld, msg,
|
||||||
&references, &rs->sr_ctrls, 1 );
|
&references, &rs->sr_ctrls, 0 );
|
||||||
res = NULL;
|
|
||||||
|
|
||||||
if ( rc != LDAP_SUCCESS ) {
|
if ( rc != LDAP_SUCCESS ) {
|
||||||
continue;
|
continue;
|
||||||
@ -925,7 +916,6 @@ really_bad:;
|
|||||||
#endif /* ! ENABLE_REWRITE */
|
#endif /* ! ENABLE_REWRITE */
|
||||||
|
|
||||||
/* FIXME: merge all and return at the end */
|
/* FIXME: merge all and return at the end */
|
||||||
|
|
||||||
for ( cnt = 0; references[ cnt ]; cnt++ )
|
for ( cnt = 0; references[ cnt ]; cnt++ )
|
||||||
;
|
;
|
||||||
|
|
||||||
@ -978,20 +968,21 @@ really_bad:;
|
|||||||
*/
|
*/
|
||||||
/* FIXME: response controls? */
|
/* FIXME: response controls? */
|
||||||
rs->sr_err = ldap_parse_result( msc->msc_ld,
|
rs->sr_err = ldap_parse_result( msc->msc_ld,
|
||||||
res,
|
msg,
|
||||||
&candidates[ i ].sr_err,
|
&candidates[ i ].sr_err,
|
||||||
(char **)&candidates[ i ].sr_matched,
|
(char **)&candidates[ i ].sr_matched,
|
||||||
NULL /* (char **)&candidates[ i ].sr_text */ ,
|
NULL /* (char **)&candidates[ i ].sr_text */ ,
|
||||||
&references,
|
&references,
|
||||||
NULL /* &candidates[ i ].sr_ctrls (unused) */ ,
|
NULL /* &candidates[ i ].sr_ctrls (unused) */ ,
|
||||||
1 );
|
0 );
|
||||||
res = NULL;
|
|
||||||
if ( rs->sr_err != LDAP_SUCCESS ) {
|
if ( rs->sr_err != LDAP_SUCCESS ) {
|
||||||
ldap_get_option( msc->msc_ld,
|
ldap_get_option( msc->msc_ld,
|
||||||
LDAP_OPT_RESULT_CODE,
|
LDAP_OPT_RESULT_CODE,
|
||||||
&rs->sr_err );
|
&rs->sr_err );
|
||||||
sres = slap_map_api2result( rs );
|
sres = slap_map_api2result( rs );
|
||||||
candidates[ i ].sr_type = REP_RESULT;
|
candidates[ i ].sr_type = REP_RESULT;
|
||||||
|
ldap_msgfree( res );
|
||||||
|
res = NULL;
|
||||||
goto really_bad;
|
goto really_bad;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1007,7 +998,8 @@ really_bad:;
|
|||||||
dc.target = mi->mi_targets[ i ];
|
dc.target = mi->mi_targets[ i ];
|
||||||
if ( !ldap_back_dn_massage( &dc, &match, &mmatch ) ) {
|
if ( !ldap_back_dn_massage( &dc, &match, &mmatch ) ) {
|
||||||
if ( mmatch.bv_val == match.bv_val ) {
|
if ( mmatch.bv_val == match.bv_val ) {
|
||||||
candidates[ i ].sr_matched = ch_strdup( mmatch.bv_val );
|
candidates[ i ].sr_matched
|
||||||
|
= ch_strdup( mmatch.bv_val );
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
candidates[ i ].sr_matched = mmatch.bv_val;
|
candidates[ i ].sr_matched = mmatch.bv_val;
|
||||||
@ -1102,6 +1094,8 @@ really_bad:;
|
|||||||
op->o_private = (void *)i;
|
op->o_private = (void *)i;
|
||||||
send_ldap_result( op, rs );
|
send_ldap_result( op, rs );
|
||||||
op->o_private = savepriv;
|
op->o_private = savepriv;
|
||||||
|
ldap_msgfree( res );
|
||||||
|
res = NULL;
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -1112,6 +1106,8 @@ really_bad:;
|
|||||||
op->o_private = (void *)i;
|
op->o_private = (void *)i;
|
||||||
send_ldap_result( op, rs );
|
send_ldap_result( op, rs );
|
||||||
op->o_private = savepriv;
|
op->o_private = savepriv;
|
||||||
|
ldap_msgfree( res );
|
||||||
|
res = NULL;
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -1130,7 +1126,7 @@ really_bad:;
|
|||||||
} else if ( rc == LDAP_RES_BIND ) {
|
} else if ( rc == LDAP_RES_BIND ) {
|
||||||
meta_search_candidate_t retcode;
|
meta_search_candidate_t retcode;
|
||||||
|
|
||||||
retcode = meta_search_dobind_result( op, rs, &mc, i, candidates, res );
|
retcode = meta_search_dobind_result( op, rs, &mc, i, candidates, msg );
|
||||||
if ( retcode == META_SEARCH_CANDIDATE ) {
|
if ( retcode == META_SEARCH_CANDIDATE ) {
|
||||||
candidates[ i ].sr_msgid = META_MSGID_IGNORE;
|
candidates[ i ].sr_msgid = META_MSGID_IGNORE;
|
||||||
retcode = meta_back_search_start( op, rs, &dc, &mc, i, candidates );
|
retcode = meta_back_search_start( op, rs, &dc, &mc, i, candidates );
|
||||||
@ -1138,7 +1134,7 @@ really_bad:;
|
|||||||
|
|
||||||
switch ( retcode ) {
|
switch ( retcode ) {
|
||||||
case META_SEARCH_CANDIDATE:
|
case META_SEARCH_CANDIDATE:
|
||||||
goto get_result;
|
break;
|
||||||
|
|
||||||
/* means that failed but onerr == continue */
|
/* means that failed but onerr == continue */
|
||||||
case META_SEARCH_NOT_CANDIDATE:
|
case META_SEARCH_NOT_CANDIDATE:
|
||||||
@ -1151,6 +1147,8 @@ really_bad:;
|
|||||||
op->o_private = (void *)i;
|
op->o_private = (void *)i;
|
||||||
send_ldap_result( op, rs );
|
send_ldap_result( op, rs );
|
||||||
op->o_private = savepriv;
|
op->o_private = savepriv;
|
||||||
|
ldap_msgfree( res );
|
||||||
|
res = NULL;
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -1162,10 +1160,16 @@ really_bad:;
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
assert( 0 );
|
assert( 0 );
|
||||||
|
ldap_msgfree( res );
|
||||||
|
res = NULL;
|
||||||
goto really_bad;
|
goto really_bad;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ldap_msgfree( res );
|
||||||
|
res = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* check for abandon */
|
/* check for abandon */
|
||||||
if ( op->o_abandon || doabandon ) {
|
if ( op->o_abandon || doabandon ) {
|
||||||
for ( i = 0; i < mi->mi_ntargets; i++ ) {
|
for ( i = 0; i < mi->mi_ntargets; i++ ) {
|
||||||
|
Loading…
Reference in New Issue
Block a user