static LDAPConn *find_connection LDAP_P(( LDAP *ld, LDAPURLDesc *srv, int any ));
static void use_connection LDAP_P(( LDAP *ld, LDAPConn *lc ));
-
-static BerElement *re_encode_request LDAP_P((
- LDAP *ld,
+static BerElement *
+re_encode_request( LDAP *ld,
BerElement *origber,
- ber_int_t msgid,
- char **dnp,
- int *type));
-
+ ber_int_t msgid,
+ LDAPURLDesc *srv,
+ int *type );
BerElement *
ldap_alloc_ber_with_options( LDAP *ld )
*/
/* For references we don't want old dn if new dn empty */
- if ( sref && srv->lud_dn == NULL )
+ if ( sref && srv->lud_dn == NULL ) {
srv->lud_dn = LDAP_STRDUP( "" );
+ }
if (( ber = re_encode_request( ld, origreq->lr_ber,
- ++ld->ld_msgid, &srv->lud_dn, &rinfo.ri_request )) == NULL ) {
+ ++ld->ld_msgid, srv, &rinfo.ri_request )) == NULL ) {
ld->ld_errno = LDAP_ENCODING_ERROR;
rc = -1;
goto done;
int
ldap_chase_referrals( LDAP *ld, LDAPRequest *lr, char **errstrp, int *hadrefp )
{
- int rc, count, len, newdn;
- char *p, *ports, *ref, *tmpref, *refdn, *unfollowed;
+ int rc, count, len;
+ char *p, *ref, *unfollowed;
LDAPRequest *origreq;
LDAPURLDesc *srv;
BerElement *ber;
/* find original request */
for ( origreq = lr; origreq->lr_parent != NULL;
origreq = origreq->lr_parent ) {
- ;
+ /* empty */;
}
unfollowed = NULL;
/* parse out & follow referrals */
for ( ref = p; rc == 0 && ref != NULL; ref = p ) {
-
if (( p = strchr( ref, '\n' )) != NULL ) {
*p++ = '\0';
} else {
p = NULL;
}
- /* copy the complete referral for rebind process */
- rinfo.ri_url = LDAP_STRDUP( ref );
-
- ldap_pvt_hex_unescape( ref );
- len = strlen( ref );
+ rc = ldap_url_parse_ext( ref, &srv );
- /* FIXME: we should use the URL Parser */
-
- if ( len > LDAP_LDAP_REF_STR_LEN && strncasecmp( ref,
- LDAP_LDAP_REF_STR, LDAP_LDAP_REF_STR_LEN ) == 0 ) {
- Debug( LDAP_DEBUG_TRACE,
- "chasing LDAP referral: <%s>\n", ref, 0, 0 );
- tmpref = ref + LDAP_LDAP_REF_STR_LEN;
- } else {
+ if ( rc != LDAP_URL_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE,
"ignoring unknown referral <%s>\n", ref, 0, 0 );
rc = ldap_append_referral( ld, &unfollowed, ref );
*hadrefp = 1;
- LDAP_FREE( rinfo.ri_url );
- rinfo.ri_url = NULL;
continue;
}
+ if( srv->lud_dn != NULL && srv->lud_dn == '\0' ) {
+ LDAP_FREE( srv->lud_dn );
+ srv->lud_dn = NULL;
+ }
+
+ Debug( LDAP_DEBUG_TRACE,
+ "chasing LDAP referral: <%s>\n", ref, 0, 0 );
+
*hadrefp = 1;
- if (( refdn = strchr( tmpref, '/' )) != NULL ) {
- *refdn++ = '\0';
- newdn = refdn[0] != '?' && refdn[0] != '\0';
- if( !newdn ) refdn = NULL;
- } else {
- newdn = 0;
- }
+ ber = re_encode_request( ld, origreq->lr_ber,
+ ++ld->ld_msgid, srv, &rinfo.ri_request );
- if (( ber = re_encode_request( ld, origreq->lr_ber,
- ++ld->ld_msgid, &refdn, &rinfo.ri_request )) == NULL ) {
- return( -1 );
+ if( ber == NULL ) {
+ return -1 ;
}
- if (( srv = (LDAPURLDesc *)LDAP_CALLOC( 1,
- sizeof( LDAPURLDesc ))) == NULL ) {
- ber_free( ber, 1 );
- ld->ld_errno = LDAP_NO_MEMORY;
- return( -1 );
- }
+ /* copy the complete referral for rebind process */
+ rinfo.ri_url = LDAP_STRDUP( ref );
- if (( srv->lud_scheme = LDAP_STRDUP("ldap")) == NULL ) {
- LDAP_FREE( (char *)srv );
- ber_free( ber, 1 );
- ld->ld_errno = LDAP_NO_MEMORY;
- return( -1 );
- }
+ rinfo.ri_msgid = origreq->lr_origid;
- if (( srv->lud_host = LDAP_STRDUP( tmpref )) == NULL ) {
- LDAP_FREE( (char *)srv );
- ber_free( ber, 1 );
- ld->ld_errno = LDAP_NO_MEMORY;
- return( -1 );
- }
+ rc = ldap_send_server_request( ld, ber, ld->ld_msgid,
+ lr, srv, NULL, &rinfo );
- if (( ports = strchr( srv->lud_host, ':' )) != NULL ) {
- *ports++ = '\0';
- srv->lud_port = atoi( ports );
- } else {
- srv->lud_port = (LDAP_INT_GLOBAL_OPT())->ldo_defport;
- }
+ LDAP_FREE( rinfo.ri_url );
- rinfo.ri_msgid = origreq->lr_origid;
- if ( srv != NULL && ldap_send_server_request( ld, ber, ld->ld_msgid,
- lr, srv, NULL, &rinfo ) >= 0 ) {
+ if( rc >= 0 ) {
++count;
} else {
Debug( LDAP_DEBUG_ANY,
ldap_err2string( ld->ld_errno ), 0, 0 );
rc = ldap_append_referral( ld, &unfollowed, ref );
}
- LDAP_FREE( rinfo.ri_url);
-
- if (srv != NULL)
- ldap_free_urllist(srv);
- if ( !newdn && refdn != NULL ) {
- LDAP_FREE( refdn );
- }
+ ldap_free_urllist(srv);
}
LDAP_FREE( *errstrp );
static BerElement *
-re_encode_request( LDAP *ld, BerElement *origber, ber_int_t msgid, char **dnp, int *type )
+re_encode_request( LDAP *ld,
+ BerElement *origber,
+ ber_int_t msgid,
+ LDAPURLDesc *srv,
+ int *type )
{
/*
* XXX this routine knows way too much about how the lber library works!
ber_int_t along;
ber_tag_t tag;
ber_int_t ver;
+ ber_int_t scope;
int rc;
BerElement tmpber, *ber;
char *orig_dn;
+ char *dn;
Debug( LDAP_DEBUG_TRACE,
"re_encode_request: new msgid %ld, new dn <%s>\n",
- (long) msgid, ( *dnp == NULL ) ? "NONE" : *dnp, 0 );
+ (long) msgid,
+ ( srv == NULL || srv->lud_dn == NULL) ? "NONE" : srv->lud_dn, 0 );
tmpber = *origber;
/* delete requests don't have a DN wrapping sequence */
rc = ber_scanf( &tmpber, "a", &orig_dn );
+ } else if ( tag == LDAP_REQ_SEARCH ) {
+ /* search requests need to be re-scope-ed */
+ rc = ber_scanf( &tmpber, "{ae" /*"}"*/, &orig_dn, &scope );
+
+ if( srv->lud_scope == LDAP_SCOPE_DEFAULT &&
+ scope != LDAP_SCOPE_SUBTREE )
+ {
+ scope = LDAP_SCOPE_BASE;
+ }
+
} else {
rc = ber_scanf( &tmpber, "{a" /*}*/, &orig_dn );
}
return NULL;
}
- if ( *dnp == NULL ) {
- *dnp = orig_dn;
- } else {
- LDAP_FREE( orig_dn );
+ if (( ber = ldap_alloc_ber_with_options( ld )) == NULL ) {
+ return NULL;
}
- if (( ber = ldap_alloc_ber_with_options( ld )) == NULL ) {
- return( NULL );
+ if ( srv->lud_dn == NULL ) {
+ dn = orig_dn;
+ } else {
+ dn = srv->lud_dn;
}
if ( tag == LDAP_REQ_BIND ) {
- rc = ber_printf( ber, "{it{is" /*}}*/, msgid, tag, ver, *dnp );
+ rc = ber_printf( ber, "{it{is" /*}}*/, msgid, tag, ver, dn );
} else if ( tag == LDAP_REQ_DELETE ) {
- rc = ber_printf( ber, "{itsN}", msgid, tag, *dnp );
+ rc = ber_printf( ber, "{itsN}", msgid, tag, dn );
+ } else if ( tag == LDAP_REQ_SEARCH ) {
+ rc = ber_printf( ber, "{it{se" /*}}*/, msgid, tag, dn, scope );
} else {
- rc = ber_printf( ber, "{it{s" /*}}*/, msgid, tag, *dnp );
+ rc = ber_printf( ber, "{it{s" /*}}*/, msgid, tag, dn );
}
+ LDAP_FREE( orig_dn );
+
if ( rc == -1 ) {
ld->ld_errno = LDAP_ENCODING_ERROR;
ber_free( ber, 1 );
- return( NULL );
+ return NULL;
}
if ( tag != LDAP_REQ_DELETE && (
{
ld->ld_errno = LDAP_ENCODING_ERROR;
ber_free( ber, 1 );
- return( NULL );
+ return NULL;
}
#ifdef LDAP_DEBUG
#endif /* LDAP_DEBUG */
*type = tag; /* return request type */
- return( ber );
+ return ber;
}