mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-12-23 16:19:35 -05:00
check consistency of referrals and result code (ITS#4861)
This commit is contained in:
parent
d07f85fc91
commit
6a9c44849c
4 changed files with 159 additions and 73 deletions
|
|
@ -1673,18 +1673,46 @@ retry:;
|
|||
if ( rc != LDAP_SUCCESS ) {
|
||||
rs->sr_err = rc;
|
||||
}
|
||||
if ( refs != NULL ) {
|
||||
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 ] );
|
||||
/* 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 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 ) {
|
||||
rs->sr_ctrls = ctrls;
|
||||
}
|
||||
|
|
@ -1739,8 +1767,6 @@ retry:;
|
|||
rs->sr_text = NULL;
|
||||
|
||||
if ( rs->sr_ref ) {
|
||||
assert( refs != NULL );
|
||||
ber_memvfree( (void **)refs );
|
||||
op->o_tmpfree( rs->sr_ref, op->o_tmpmemctx );
|
||||
rs->sr_ref = NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -420,41 +420,52 @@ retry:
|
|||
freetext = 1;
|
||||
}
|
||||
|
||||
if ( references && references[ 0 ] && references[ 0 ][ 0 ] ) {
|
||||
int cnt;
|
||||
|
||||
/* RFC 4511: referrals can only appear
|
||||
* if result code is LDAP_REFERRAL */
|
||||
if ( references
|
||||
&& references[ 0 ]
|
||||
&& references[ 0 ][ 0 ] )
|
||||
{
|
||||
if ( rs->sr_err != LDAP_REFERRAL ) {
|
||||
/* FIXME: error */
|
||||
Debug( LDAP_DEBUG_ANY,
|
||||
"%s ldap_back_search: "
|
||||
"got referrals with %d\n",
|
||||
"got referrals with err=%d\n",
|
||||
op->o_log_prefix,
|
||||
rs->sr_err, 0 );
|
||||
rs->sr_err = LDAP_REFERRAL;
|
||||
}
|
||||
|
||||
for ( cnt = 0; references[ cnt ]; cnt++ )
|
||||
/* NO OP */ ;
|
||||
} else {
|
||||
int cnt;
|
||||
|
||||
for ( cnt = 0; references[ cnt ]; cnt++ )
|
||||
/* NO OP */ ;
|
||||
|
||||
rs->sr_ref = op->o_tmpalloc( ( cnt + 1 ) * sizeof( struct berval ),
|
||||
op->o_tmpmemctx );
|
||||
rs->sr_ref = op->o_tmpalloc( ( cnt + 1 ) * sizeof( struct berval ),
|
||||
op->o_tmpmemctx );
|
||||
|
||||
for ( cnt = 0; references[ cnt ]; cnt++ ) {
|
||||
/* duplicating ...*/
|
||||
ber_str2bv( references[ cnt ], 0, 1, &rs->sr_ref[ cnt ] );
|
||||
for ( cnt = 0; references[ cnt ]; cnt++ ) {
|
||||
/* duplicating ...*/
|
||||
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 ) {
|
||||
match.bv_len = strlen( match.bv_val );
|
||||
}
|
||||
|
||||
/* cleanup */
|
||||
if ( references ) {
|
||||
ber_memvfree( (void **)references );
|
||||
}
|
||||
|
||||
rc = 0;
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1018,18 +1018,46 @@ retry:;
|
|||
if ( rc != LDAP_SUCCESS ) {
|
||||
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++ )
|
||||
/* 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 ] );
|
||||
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 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 ) {
|
||||
rs->sr_ctrls = ctrls;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -870,7 +870,6 @@ getconn:;
|
|||
int gotit = 0,
|
||||
doabandon = 0,
|
||||
alreadybound = ncandidates;
|
||||
time_t curr_time = 0;
|
||||
|
||||
/* check timeout */
|
||||
if ( timeout && lastres_time > 0
|
||||
|
|
@ -1243,16 +1242,15 @@ really_bad:;
|
|||
NULL /* &candidates[ i ].sr_ctrls (unused) */ ,
|
||||
0 );
|
||||
if ( rs->sr_err != LDAP_SUCCESS ) {
|
||||
ldap_get_option( msc->msc_ld,
|
||||
LDAP_OPT_ERROR_NUMBER,
|
||||
&rs->sr_err );
|
||||
sres = slap_map_api2result( rs );
|
||||
sres = slap_map_api2result( &candidates[ i ] );
|
||||
candidates[ i ].sr_type = REP_RESULT;
|
||||
ldap_msgfree( res );
|
||||
res = NULL;
|
||||
goto really_bad;
|
||||
}
|
||||
|
||||
rs->sr_err = candidates[ i ].sr_err;
|
||||
|
||||
/* massage matchedDN if need be */
|
||||
if ( candidates[ i ].sr_matched != NULL ) {
|
||||
struct berval match, mmatch;
|
||||
|
|
@ -1278,37 +1276,60 @@ really_bad:;
|
|||
}
|
||||
|
||||
/* add references to array */
|
||||
if ( references ) {
|
||||
BerVarray sr_ref;
|
||||
int cnt;
|
||||
|
||||
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 );
|
||||
|
||||
/* cleanup */
|
||||
ber_memvfree( (void **)references );
|
||||
|
||||
if ( rs->sr_v2ref == NULL ) {
|
||||
rs->sr_v2ref = sr_ref;
|
||||
/* RFC 4511: referrals can only appear
|
||||
* if result code is LDAP_REFERRAL */
|
||||
if ( references != NULL
|
||||
&& references[ 0 ] != NULL
|
||||
&& references[ 0 ][ 0 ] != '\0' )
|
||||
{
|
||||
if ( rs->sr_err != LDAP_REFERRAL ) {
|
||||
Debug( LDAP_DEBUG_ANY,
|
||||
"%s meta_back_search[%ld]: "
|
||||
"got referrals with err=%d\n",
|
||||
op->o_log_prefix,
|
||||
i, rs->sr_err );
|
||||
|
||||
} else {
|
||||
for ( cnt = 0; !BER_BVISNULL( &sr_ref[ cnt ] ); cnt++ ) {
|
||||
ber_bvarray_add( &rs->sr_v2ref, &sr_ref[ cnt ] );
|
||||
}
|
||||
ber_memfree( sr_ref );
|
||||
}
|
||||
}
|
||||
BerVarray sr_ref;
|
||||
int cnt;
|
||||
|
||||
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 );
|
||||
|
||||
if ( LogTest( LDAP_DEBUG_TRACE | LDAP_DEBUG_ANY ) ) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue