allow to muck with referrals while chasing...

This commit is contained in:
Pierangelo Masarati 2005-05-28 14:29:08 +00:00
parent 42062dc417
commit eb005a9872
4 changed files with 79 additions and 2 deletions

View file

@ -726,6 +726,17 @@ ldap_set_rebind_proc LDAP_P((
LDAP_REBIND_PROC *rebind_proc,
void *params ));
/* V3 referral selection Function Callback Prototype */
typedef int (LDAP_NEXTREF_PROC) LDAP_P((
LDAP *ld, char ***refsp, int *cntp,
void *params ));
LDAP_F( int )
ldap_set_nextref_proc LDAP_P((
LDAP *ld,
LDAP_NEXTREF_PROC *nextref_proc,
void *params ));
/*
* in controls.c:
*/

View file

@ -198,6 +198,8 @@ struct ldapoptions {
/* LDAP rebind callback function */
LDAP_REBIND_PROC *ldo_rebind_proc;
void *ldo_rebind_params;
LDAP_NEXTREF_PROC *ldo_nextref_proc;
void *ldo_nextref_params;
LDAP_BOOLEANS ldo_booleans; /* boolean options */
};
@ -311,8 +313,10 @@ struct ldap {
#define ld_sctrls ld_options.ldo_sctrls
#define ld_cctrls ld_options.ldo_cctrls
#define ld_rebind_proc ld_options.ldo_rebind_proc
#define ld_rebind_proc ld_options.ldo_rebind_proc
#define ld_rebind_params ld_options.ldo_rebind_params
#define ld_nextref_proc ld_options.ldo_nextref_proc
#define ld_nextref_params ld_options.ldo_nextref_params
#define ld_version ld_options.ldo_version

View file

@ -28,6 +28,9 @@
#define LDAP_OPT_REBIND_PROC 0x4e814d
#define LDAP_OPT_REBIND_PARAMS 0x4e814e
#define LDAP_OPT_NEXTREF_PROC 0x4e815d
#define LDAP_OPT_NEXTREF_PARAMS 0x4e815e
static const LDAPAPIFeatureInfo features[] = {
#ifdef LDAP_API_FEATURE_X_OPENLDAP
{ /* OpenLDAP Extensions API Feature */
@ -454,6 +457,14 @@ ldap_set_option(
case LDAP_OPT_REBIND_PARAMS: {
lo->ldo_rebind_params = (void *)invalue;
} return LDAP_OPT_SUCCESS;
/* Only accessed from inside this function by ldap_set_nextref_proc() */
case LDAP_OPT_NEXTREF_PROC: {
lo->ldo_nextref_proc = (LDAP_NEXTREF_PROC *)invalue;
} return LDAP_OPT_SUCCESS;
case LDAP_OPT_NEXTREF_PARAMS: {
lo->ldo_nextref_params = (void *)invalue;
} return LDAP_OPT_SUCCESS;
}
if(invalue == NULL) {
@ -670,3 +681,14 @@ ldap_set_rebind_proc( LDAP *ld, LDAP_REBIND_PROC *proc, void *params )
rc = ldap_set_option( ld, LDAP_OPT_REBIND_PARAMS, (void *)params );
return rc;
}
int
ldap_set_nextref_proc( LDAP *ld, LDAP_NEXTREF_PROC *proc, void *params )
{
int rc;
rc = ldap_set_option( ld, LDAP_OPT_NEXTREF_PROC, (void *)proc );
if( rc != LDAP_OPT_SUCCESS ) return rc;
rc = ldap_set_option( ld, LDAP_OPT_NEXTREF_PARAMS, (void *)params );
return rc;
}

View file

@ -657,6 +657,36 @@ ldap_free_request( LDAP *ld, LDAPRequest *lr )
ldap_free_request_int( ld, lr );
}
/*
* call first time with *cntp = -1
* when returns *cntp == -1, no referrals are left
*
* NOTE: may replace *refsp, or shuffle the contents
* of the original array.
*/
static int ldap_int_nextref(
LDAP *ld,
char ***refsp,
int *cntp,
void *params )
{
assert( refsp != NULL );
assert( *refsp != NULL );
assert( cntp != NULL );
if ( *cntp < -1 ) {
*cntp = -1;
return -1;
}
(*cntp)++;
if ( (*refsp)[ *cntp ] == NULL ) {
*cntp = -1;
}
return 0;
}
/*
* Chase v3 referrals
@ -718,8 +748,18 @@ ldap_chase_v3referrals( LDAP *ld, LDAPRequest *lr, char **refs, int sref, char *
refarray = refs;
refs = NULL;
if ( ld->ld_nextref_proc == NULL ) {
ld->ld_nextref_proc = ldap_int_nextref;
}
/* parse out & follow referrals */
for( i=0; refarray[i] != NULL; i++) {
i = -1;
for ( ld->ld_nextref_proc( ld, &refarray, &i, ld->ld_nextref_params );
i != -1;
ld->ld_nextref_proc( ld, &refarray, &i, ld->ld_nextref_params ) )
{
/* Parse the referral URL */
if (( rc = ldap_url_parse_ext( refarray[i], &srv)) != LDAP_SUCCESS) {
ld->ld_errno = rc;