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;
}
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;
}
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 ) {
#ifndef LDAP_NULL_IS_NULL
if ( match.bv_val[ 0 ] == '\0' ) {
}
#endif /* LDAP_NULL_IS_NULL */
- /* cleanup */
- if ( references ) {
- ber_memvfree( (void **)references );
- }
-
rc = 0;
break;
}
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;
}
int gotit = 0,
doabandon = 0,
alreadybound = ncandidates;
- time_t curr_time = 0;
/* check timeout */
if ( timeout && lastres_time > 0
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;
}
/* add references to array */
- if ( references ) {
- BerVarray sr_ref;
- int cnt;
+ /* 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 {
+ BerVarray sr_ref;
+ int cnt;
- for ( cnt = 0; references[ cnt ]; cnt++ )
- ;
+ for ( cnt = 0; references[ cnt ]; cnt++ )
+ ;
- sr_ref = ch_calloc( sizeof( struct berval ), cnt + 1 );
+ 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 ] );
+ 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 );
+ ( void )ldap_back_referral_result_rewrite( &dc, sr_ref );
- /* cleanup */
- ber_memvfree( (void **)references );
-
- if ( rs->sr_v2ref == NULL ) {
- rs->sr_v2ref = 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 ] );
+ } else {
+ for ( cnt = 0; !BER_BVISNULL( &sr_ref[ cnt ] ); cnt++ ) {
+ ber_bvarray_add( &rs->sr_v2ref, &sr_ref[ cnt ] );
+ }
+ ber_memfree( sr_ref );
}
- 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 ( StatslogTest( LDAP_DEBUG_TRACE | LDAP_DEBUG_ANY ) ) {