/* $OpenLDAP$ */
/*
- * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
+ * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
/* Portions
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,
+ int sref,
+ LDAPURLDesc *srv,
+ int *type );
BerElement *
ldap_alloc_ber_with_options( LDAP *ld )
}
Debug( LDAP_DEBUG_TRACE,
- "ldap_delayed_open successful, ld_host is %s\n",
- ( ld->ld_host == NULL ) ? "(null)" : ld->ld_host, 0, 0 );
+ "ldap_open_defconn: successful\n",
+ 0, 0, 0 );
}
{
servers = NULL;
}
+#ifdef LDAP_CONNECTIONLESS
+ if (LDAP_IS_UDP(ld)) {
+ if (msgtype == LDAP_REQ_BIND) {
+ if (ld->ld_options.ldo_cldapdn)
+ ldap_memfree(ld->ld_options.ldo_cldapdn);
+ ld->ld_options.ldo_cldapdn = ldap_strdup(dn);
+ return 0;
+ }
+ if (msgtype != LDAP_REQ_ABANDON && msgtype != LDAP_REQ_SEARCH)
+ return LDAP_PARAM_ERROR;
+ }
+#endif
rc = ldap_send_server_request( ld, ber, ld->ld_msgid, NULL,
servers, NULL, NULL );
if (servers)
lr->lr_origid = parentreq->lr_origid;
lr->lr_parentcnt = parentreq->lr_parentcnt + 1;
lr->lr_parent = parentreq;
- lr->lr_refnext = parentreq->lr_refnext;
- parentreq->lr_refnext = lr;
+ lr->lr_refnext = parentreq->lr_child;
+ parentreq->lr_child = lr;
} else { /* original request */
lr->lr_origid = lr->lr_msgid;
}
{
LDAPConn *lc;
LDAPURLDesc *srv;
- Sockbuf *sb;
+ Sockbuf *sb = NULL;
Debug( LDAP_DEBUG_TRACE, "ldap_new_connection\n", 0, 0, 0 );
/*
*/
lc->lconn_rebind_inprogress = 1;
/* V3 rebind function */
- if ( ld->ld_rebindproc != NULL) {
+ if ( ld->ld_rebind_proc != NULL) {
LDAPURLDesc *srvfunc;
if( ( srvfunc = ldap_url_dup( srvlist)) == NULL) {
ld->ld_errno = LDAP_NO_MEMORY;
++lc->lconn_refcnt; /* avoid premature free */
ld->ld_defconn = lc;
- Debug( LDAP_DEBUG_TRACE, "Call application rebindproc\n", 0, 0, 0);
- err = (*ld->ld_rebindproc)( ld, bind->ri_url, bind->ri_request, bind->ri_msgid);
+ Debug( LDAP_DEBUG_TRACE, "Call application rebind_proc\n", 0, 0, 0);
+ err = (*ld->ld_rebind_proc)( ld,
+ bind->ri_url, bind->ri_request, bind->ri_msgid,
+ ld->ld_rebind_params );
ld->ld_defconn = savedefconn;
--lc->lconn_refcnt;
for ( lc = ld->ld_conns; lc != NULL; lc = lc->lconn_next ) {
for ( ls = srv; ls != NULL; ls = ls->lud_next ) {
if ( lc->lconn_server->lud_host != NULL &&
- ls->lud_host != NULL && strcasecmp(
- ls->lud_host, lc->lconn_server->lud_host ) == 0
+ *lc->lconn_server->lud_host != '\0' &&
+ ls->lud_host != NULL && *ls->lud_host != '\0' &&
+ strcasecmp( ls->lud_host, lc->lconn_server->lud_host ) == 0
&& ls->lud_port == lc->lconn_server->lud_port ) {
- return( lc );
+ return lc;
}
if ( !any ) {
break;
}
}
- return( NULL );
+ return NULL;
}
}
#endif /* LDAP_DEBUG */
-
void
-ldap_free_request( LDAP *ld, LDAPRequest *lr )
+ldap_free_request_int( LDAP *ld, LDAPRequest *lr )
{
- LDAPRequest *tmplr, *nextlr;
-
- Debug( LDAP_DEBUG_TRACE, "ldap_free_request (origid %d, msgid %d)\n",
- lr->lr_origid, lr->lr_msgid, 0 );
-
- if ( lr->lr_parent != NULL ) {
- --lr->lr_parent->lr_outrefcnt;
- } else {
- /* free all referrals (child requests) */
- for ( tmplr = lr->lr_refnext; tmplr != NULL; tmplr = nextlr ) {
- nextlr = tmplr->lr_refnext;
- ldap_free_request( ld, tmplr );
- }
- }
-
if ( lr->lr_prev == NULL ) {
ld->ld_requests = lr->lr_next;
} else {
LDAP_FREE( lr );
}
+void
+ldap_free_request( LDAP *ld, LDAPRequest *lr )
+{
+ LDAPRequest **ttmplr;
+
+ Debug( LDAP_DEBUG_TRACE, "ldap_free_request (origid %d, msgid %d)\n",
+ lr->lr_origid, lr->lr_msgid, 0 );
+
+ if ( lr->lr_parent != NULL ) {
+ --lr->lr_parent->lr_outrefcnt;
+ for ( ttmplr = &lr->lr_parent->lr_child; *ttmplr && *ttmplr != lr; ttmplr = &(*ttmplr)->lr_refnext );
+ if ( *ttmplr == lr )
+ *ttmplr = lr->lr_refnext;
+ } else {
+ /* free all referrals (child requests) */
+ while ( lr->lr_child )
+ ldap_free_request( ld, lr->lr_child );
+ }
+ ldap_free_request_int( ld, lr );
+}
+
+
/*
* Chase v3 referrals
*
* (IN) lr = LDAP Request structure
* (IN) refs = array of pointers to referral strings that we will chase
* The array will be free'd by this function when no longer needed
+ * (IN) sref != 0 if following search reference
* (OUT) errstrp = Place to return a string of referrals which could not be followed
* (OUT) hadrefp = 1 if sucessfully followed referral
*
* Return value - number of referrals followed
*/
int
-ldap_chase_v3referrals( LDAP *ld, LDAPRequest *lr, char **refs, char **errstrp, int *hadrefp )
+ldap_chase_v3referrals( LDAP *ld, LDAPRequest *lr, char **refs, int sref, char **errstrp, int *hadrefp )
{
char *unfollowed;
int unfollowedcnt = 0;
}
/* find original request */
- for ( origreq = lr; origreq->lr_parent != NULL; origreq = origreq->lr_parent ) {
- ;
+ for ( origreq = lr;
+ origreq->lr_parent != NULL;
+ origreq = origreq->lr_parent )
+ {
+ /* empty */ ;
}
refarray = refs;
/* parse out & follow referrals */
for( i=0; refarray[i] != NULL; i++) {
/* Parse the referral URL */
- if (( rc = ldap_url_parse( refarray[i], &srv)) != LDAP_SUCCESS) {
+ if (( rc = ldap_url_parse_ext( refarray[i], &srv)) != LDAP_SUCCESS) {
ld->ld_errno = rc;
rc = -1;
goto done;
}
+ if( srv->lud_crit_exts ) {
+ /* we do not support any extensions */
+ ld->ld_errno = LDAP_NOT_SUPPORTED;
+ rc = -1;
+ goto done;
+ }
+
/* treat ldap://hostpart and ldap://hostpart/ the same */
if ( srv->lud_dn && srv->lud_dn[0] == '\0' ) {
LDAP_FREE( srv->lud_dn );
* if two search references come in one behind the other
* for the same server with different contexts.
*/
- Debug( LDAP_DEBUG_TRACE, "ldap_chase_v3referrals: queue referral \"%s\"\n",
+ Debug( LDAP_DEBUG_TRACE,
+ "ldap_chase_v3referrals: queue referral \"%s\"\n",
refarray[i], 0, 0);
if( lc->lconn_rebind_queue == NULL ) {
/* Create a referral list */
- if( (lc->lconn_rebind_queue = (char ***)LDAP_MALLOC( sizeof(void *) * 2)) == NULL) {
+ lc->lconn_rebind_queue =
+ (char ***) LDAP_MALLOC( sizeof(void *) * 2);
+
+ if( lc->lconn_rebind_queue == NULL) {
ld->ld_errno = LDAP_NO_MEMORY;
rc = -1;
goto done;
}
+
lc->lconn_rebind_queue[0] = refarray;
lc->lconn_rebind_queue[1] = NULL;
refarray = NULL;
+
} else {
/* Count how many referral arrays we already have */
for( j = 0; lc->lconn_rebind_queue[j] != NULL; j++) {
- ;
+ /* empty */;
}
+
/* Add the new referral to the list */
- if( (lc->lconn_rebind_queue = (char ***)LDAP_REALLOC(
- lc->lconn_rebind_queue, sizeof(void *) * (j + 2))) == NULL) {
+ lc->lconn_rebind_queue = (char ***) LDAP_REALLOC(
+ lc->lconn_rebind_queue, sizeof(void *) * (j + 2));
+
+ if( lc->lconn_rebind_queue == NULL ) {
ld->ld_errno = LDAP_NO_MEMORY;
rc = -1;
goto done;
lc->lconn_rebind_queue[j+1] = NULL;
refarray = NULL;
}
+
/* We have queued the referral/reference, now just return */
rc = 0;
*hadrefp = 1;
* Note: In the future we also need to replace the filter if one
* was provided with the search reference
*/
- if (( ber = re_encode_request( ld, origreq->lr_ber,
- ++ld->ld_msgid, &srv->lud_dn, &rinfo.ri_request )) == NULL ) {
+
+ /* For references we don't want old dn if new dn empty */
+ if ( sref && srv->lud_dn == NULL ) {
+ srv->lud_dn = LDAP_STRDUP( "" );
+ }
+
+ ber = re_encode_request( ld, origreq->lr_ber, ++ld->ld_msgid,
+ sref, srv, &rinfo.ri_request );
+
+ if( ber == NULL ) {
ld->ld_errno = LDAP_ENCODING_ERROR;
rc = -1;
goto done;
}
- Debug( LDAP_DEBUG_TRACE, "ldap_chase_v3referral: msgid %d, url \"%s\"\n",
+ Debug( LDAP_DEBUG_TRACE,
+ "ldap_chase_v3referral: msgid %d, url \"%s\"\n",
lr->lr_msgid, refarray[i], 0);
/* Send the new request to the server - may require a bind */
* XXX merging of errors in this routine needs to be improved
*/
int
-ldap_chase_referrals( LDAP *ld, LDAPRequest *lr, char **errstrp, int *hadrefp )
+ldap_chase_referrals( LDAP *ld,
+ LDAPRequest *lr,
+ char **errstrp,
+ int sref,
+ 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;
len = strlen( *errstrp );
for ( p = *errstrp; len >= LDAP_REF_STR_LEN; ++p, --len ) {
- if (( *p == 'R' || *p == 'r' ) && strncasecmp( p,
- LDAP_REF_STR, LDAP_REF_STR_LEN ) == 0 ) {
+ if ( strncasecmp( p, LDAP_REF_STR, LDAP_REF_STR_LEN ) == 0 ) {
*p = '\0';
p += LDAP_REF_STR_LEN;
break;
/* 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;
}
- ldap_pvt_hex_unescape( ref );
- len = strlen( ref );
-
- /* FIXME: we should use the URL Parser */
+ rc = ldap_url_parse_ext( ref, &srv );
- 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 );
continue;
}
- /* copy the complete referral for rebind process */
- rinfo.ri_url = LDAP_STRDUP( ref );
+ 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, sref, 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,
+ int sref,
+ LDAPURLDesc *srv,
+ int *type )
{
-/*
- * XXX this routine knows way too much about how the lber library works!
- */
+ /*
+ * 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 ) {
+ /* use the scope provided in reference */
+ scope = srv->lud_scope;
+
+ } else if ( sref && scope != LDAP_SCOPE_SUBTREE ) {
+ /* use scope implied by previous operation */
+ /* base -> base */
+ /* one -> base */
+ /* subtree -> 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;
}
LDAPRequest *
ldap_find_request_by_msgid( LDAP *ld, ber_int_t msgid )
{
- LDAPRequest *lr;
+ LDAPRequest *lr;
for ( lr = ld->ld_requests; lr != NULL; lr = lr->lr_next ) {
if( lr->lr_status == LDAP_REQST_COMPLETED ) {