check consistency of referrals and result code (ITS#4861)

This commit is contained in:
Pierangelo Masarati 2007-03-08 17:57:49 +00:00
parent d07f85fc91
commit 6a9c44849c
4 changed files with 159 additions and 73 deletions

View file

@ -1673,18 +1673,46 @@ retry:;
if ( rc != LDAP_SUCCESS ) { if ( rc != LDAP_SUCCESS ) {
rs->sr_err = rc; rs->sr_err = rc;
} }
if ( refs != NULL ) {
int i;
for ( i = 0; refs[ i ] != NULL; i++ ) /* RFC 4511: referrals can only appear
/* count */ ; * if result code is LDAP_REFERRAL */
rs->sr_ref = op->o_tmpalloc( sizeof( struct berval ) * ( i + 1 ), if ( refs != NULL
op->o_tmpmemctx ); && refs[ 0 ] != NULL
for ( i = 0; refs[ i ] != NULL; i++ ) { && refs[ 0 ][ 0 ] != '\0' )
ber_str2bv( refs[ i ], 0, 0, &rs->sr_ref[ i ] ); {
if ( rs->sr_err != LDAP_REFERRAL ) {
Debug( LDAP_DEBUG_ANY,
"%s ldap_back_op_result: "
"got referrals with err=%d\n",
op->o_log_prefix,
rs->sr_err, 0 );
} else {
int i;
for ( i = 0; refs[ i ] != NULL; i++ )
/* count */ ;
rs->sr_ref = op->o_tmpalloc( sizeof( struct berval ) * ( i + 1 ),
op->o_tmpmemctx );
for ( i = 0; refs[ i ] != NULL; i++ ) {
ber_str2bv( refs[ i ], 0, 0, &rs->sr_ref[ i ] );
}
BER_BVZERO( &rs->sr_ref[ i ] );
} }
BER_BVZERO( &rs->sr_ref[ i ] );
} else if ( rs->sr_err == LDAP_REFERRAL ) {
Debug( LDAP_DEBUG_ANY,
"%s ldap_back_op_result: "
"got err=%d with null "
"or empty referrals\n",
op->o_log_prefix,
rs->sr_err, 0 );
rs->sr_err = LDAP_NO_SUCH_OBJECT;
} }
ber_memvfree( (void **)refs );
if ( ctrls != NULL ) { if ( ctrls != NULL ) {
rs->sr_ctrls = ctrls; rs->sr_ctrls = ctrls;
} }
@ -1739,8 +1767,6 @@ retry:;
rs->sr_text = NULL; rs->sr_text = NULL;
if ( rs->sr_ref ) { if ( rs->sr_ref ) {
assert( refs != NULL );
ber_memvfree( (void **)refs );
op->o_tmpfree( rs->sr_ref, op->o_tmpmemctx ); op->o_tmpfree( rs->sr_ref, op->o_tmpmemctx );
rs->sr_ref = NULL; rs->sr_ref = NULL;
} }

View file

@ -420,41 +420,52 @@ retry:
freetext = 1; freetext = 1;
} }
if ( references && references[ 0 ] && references[ 0 ][ 0 ] ) { /* RFC 4511: referrals can only appear
int cnt; * if result code is LDAP_REFERRAL */
if ( references
&& references[ 0 ]
&& references[ 0 ][ 0 ] )
{
if ( rs->sr_err != LDAP_REFERRAL ) { if ( rs->sr_err != LDAP_REFERRAL ) {
/* FIXME: error */
Debug( LDAP_DEBUG_ANY, Debug( LDAP_DEBUG_ANY,
"%s ldap_back_search: " "%s ldap_back_search: "
"got referrals with %d\n", "got referrals with err=%d\n",
op->o_log_prefix, op->o_log_prefix,
rs->sr_err, 0 ); rs->sr_err, 0 );
rs->sr_err = LDAP_REFERRAL;
}
for ( cnt = 0; references[ cnt ]; cnt++ ) } else {
/* NO OP */ ; int cnt;
for ( cnt = 0; references[ cnt ]; cnt++ )
/* NO OP */ ;
rs->sr_ref = op->o_tmpalloc( ( cnt + 1 ) * sizeof( struct berval ), rs->sr_ref = op->o_tmpalloc( ( cnt + 1 ) * sizeof( struct berval ),
op->o_tmpmemctx ); op->o_tmpmemctx );
for ( cnt = 0; references[ cnt ]; cnt++ ) { for ( cnt = 0; references[ cnt ]; cnt++ ) {
/* duplicating ...*/ /* duplicating ...*/
ber_str2bv( references[ cnt ], 0, 1, &rs->sr_ref[ cnt ] ); ber_str2bv( references[ cnt ], 0, 1, &rs->sr_ref[ cnt ] );
}
BER_BVZERO( &rs->sr_ref[ cnt ] );
} }
BER_BVZERO( &rs->sr_ref[ cnt ] );
} else if ( rs->sr_err == LDAP_REFERRAL ) {
Debug( LDAP_DEBUG_ANY,
"%s ldap_back_search: "
"got err=%d with null "
"or empty referrals\n",
op->o_log_prefix,
rs->sr_err, 0 );
rs->sr_err = LDAP_NO_SUCH_OBJECT;
} }
ber_memvfree( (void **)references );
if ( match.bv_val != NULL ) { if ( match.bv_val != NULL ) {
match.bv_len = strlen( match.bv_val ); match.bv_len = strlen( match.bv_val );
} }
/* cleanup */
if ( references ) {
ber_memvfree( (void **)references );
}
rc = 0; rc = 0;
break; break;
} }

View file

@ -1018,18 +1018,46 @@ retry:;
if ( rc != LDAP_SUCCESS ) { if ( rc != LDAP_SUCCESS ) {
rs->sr_err = rc; rs->sr_err = rc;
} }
if ( refs != NULL ) {
int i; /* RFC 4511: referrals can only appear
* if result code is LDAP_REFERRAL */
if ( refs != NULL
&& refs[ 0 ] != NULL
&& refs[ 0 ][ 0 ] != '\0' )
{
if ( rs->sr_err != LDAP_REFERRAL ) {
Debug( LDAP_DEBUG_ANY,
"%s meta_back_op_result[%d]: "
"got referrals with err=%d\n",
op->o_log_prefix,
candidate, rs->sr_err );
} else {
int i;
for ( i = 0; refs[ i ] != NULL; i++ ) for ( i = 0; refs[ i ] != NULL; i++ )
/* count */ ; /* count */ ;
rs->sr_ref = op->o_tmpalloc( sizeof( struct berval ) * ( i + 1 ), rs->sr_ref = op->o_tmpalloc( sizeof( struct berval ) * ( i + 1 ),
op->o_tmpmemctx ); op->o_tmpmemctx );
for ( i = 0; refs[ i ] != NULL; i++ ) { for ( i = 0; refs[ i ] != NULL; i++ ) {
ber_str2bv( refs[ i ], 0, 0, &rs->sr_ref[ i ] ); ber_str2bv( refs[ i ], 0, 0, &rs->sr_ref[ i ] );
}
BER_BVZERO( &rs->sr_ref[ i ] );
} }
BER_BVZERO( &rs->sr_ref[ i ] );
} else if ( rs->sr_err == LDAP_REFERRAL ) {
Debug( LDAP_DEBUG_ANY,
"%s meta_back_op_result[%d]: "
"got err=%d with null "
"or empty referrals\n",
op->o_log_prefix,
candidate, rs->sr_err );
rs->sr_err = LDAP_NO_SUCH_OBJECT;
} }
ber_memvfree( (void **)refs );
if ( ctrls != NULL ) { if ( ctrls != NULL ) {
rs->sr_ctrls = ctrls; rs->sr_ctrls = ctrls;
} }

View file

@ -870,7 +870,6 @@ getconn:;
int gotit = 0, int gotit = 0,
doabandon = 0, doabandon = 0,
alreadybound = ncandidates; alreadybound = ncandidates;
time_t curr_time = 0;
/* check timeout */ /* check timeout */
if ( timeout && lastres_time > 0 if ( timeout && lastres_time > 0
@ -1243,16 +1242,15 @@ really_bad:;
NULL /* &candidates[ i ].sr_ctrls (unused) */ , NULL /* &candidates[ i ].sr_ctrls (unused) */ ,
0 ); 0 );
if ( rs->sr_err != LDAP_SUCCESS ) { if ( rs->sr_err != LDAP_SUCCESS ) {
ldap_get_option( msc->msc_ld, sres = slap_map_api2result( &candidates[ i ] );
LDAP_OPT_ERROR_NUMBER,
&rs->sr_err );
sres = slap_map_api2result( rs );
candidates[ i ].sr_type = REP_RESULT; candidates[ i ].sr_type = REP_RESULT;
ldap_msgfree( res ); ldap_msgfree( res );
res = NULL; res = NULL;
goto really_bad; goto really_bad;
} }
rs->sr_err = candidates[ i ].sr_err;
/* massage matchedDN if need be */ /* massage matchedDN if need be */
if ( candidates[ i ].sr_matched != NULL ) { if ( candidates[ i ].sr_matched != NULL ) {
struct berval match, mmatch; struct berval match, mmatch;
@ -1278,37 +1276,60 @@ really_bad:;
} }
/* add references to array */ /* add references to array */
if ( references ) { /* RFC 4511: referrals can only appear
BerVarray sr_ref; * if result code is LDAP_REFERRAL */
int cnt; if ( references != NULL
&& references[ 0 ] != NULL
for ( cnt = 0; references[ cnt ]; cnt++ ) && references[ 0 ][ 0 ] != '\0' )
; {
if ( rs->sr_err != LDAP_REFERRAL ) {
sr_ref = ch_calloc( sizeof( struct berval ), cnt + 1 ); Debug( LDAP_DEBUG_ANY,
"%s meta_back_search[%ld]: "
for ( cnt = 0; references[ cnt ]; cnt++ ) { "got referrals with err=%d\n",
ber_str2bv( references[ cnt ], 0, 1, &sr_ref[ cnt ] ); op->o_log_prefix,
} i, rs->sr_err );
BER_BVZERO( &sr_ref[ cnt ] );
( void )ldap_back_referral_result_rewrite( &dc, sr_ref );
/* cleanup */
ber_memvfree( (void **)references );
if ( rs->sr_v2ref == NULL ) {
rs->sr_v2ref = sr_ref;
} else { } else {
for ( cnt = 0; !BER_BVISNULL( &sr_ref[ cnt ] ); cnt++ ) { BerVarray sr_ref;
ber_bvarray_add( &rs->sr_v2ref, &sr_ref[ cnt ] ); int cnt;
}
ber_memfree( sr_ref ); for ( cnt = 0; references[ cnt ]; cnt++ )
} ;
}
sr_ref = ch_calloc( sizeof( struct berval ), cnt + 1 );
for ( cnt = 0; references[ cnt ]; cnt++ ) {
ber_str2bv( references[ cnt ], 0, 1, &sr_ref[ cnt ] );
}
BER_BVZERO( &sr_ref[ cnt ] );
( void )ldap_back_referral_result_rewrite( &dc, sr_ref );
if ( rs->sr_v2ref == NULL ) {
rs->sr_v2ref = sr_ref;
} else {
for ( cnt = 0; !BER_BVISNULL( &sr_ref[ cnt ] ); cnt++ ) {
ber_bvarray_add( &rs->sr_v2ref, &sr_ref[ cnt ] );
}
ber_memfree( sr_ref );
}
}
} else if ( rs->sr_err == LDAP_REFERRAL ) {
Debug( LDAP_DEBUG_ANY,
"%s meta_back_search[%ld]: "
"got err=%d with null "
"or empty referrals\n",
op->o_log_prefix,
i, rs->sr_err );
rs->sr_err = LDAP_NO_SUCH_OBJECT;
}
/* cleanup */
ber_memvfree( (void **)references );
rs->sr_err = candidates[ i ].sr_err;
sres = slap_map_api2result( rs ); sres = slap_map_api2result( rs );
if ( LogTest( LDAP_DEBUG_TRACE | LDAP_DEBUG_ANY ) ) { if ( LogTest( LDAP_DEBUG_TRACE | LDAP_DEBUG_ANY ) ) {