/* $OpenLDAP$ */
-/*
- * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
- * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
+ *
+ * Copyright 1998-2005 The OpenLDAP Foundation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted only as authorized by the OpenLDAP
+ * Public License.
+ *
+ * A copy of this license is available in the file LICENSE in the
+ * top-level directory of the distribution or, alternatively, at
+ * <http://www.OpenLDAP.org/license.html>.
*/
-/* Portions
- * Copyright (c) 1995 Regents of the University of Michigan.
- * All rights reserved.
+/* Portions Copyright (c) 1995 Regents of the University of Michigan.
+ * All rights reserved.
*/
-/*---
- * This notice applies to changes, created by or for Novell, Inc.,
+/* This notice applies to changes, created by or for Novell, Inc.,
* to preexisting works for which notices appear elsewhere in this file.
*
* Copyright (C) 1999, 2000 Novell, Inc. All Rights Reserved.
* Modification to OpenLDAP source by Novell, Inc.
* April 2000 sfs Added code to chase V3 referrals
* request.c - sending of ldap requests; handling of referrals
+ *---
+ * Note: A verbatim copy of version 2.0.1 of the OpenLDAP Public License
+ * can be found in the file "build/LICENSE-2.0.1" in this distribution
+ * of OpenLDAP Software.
*/
#include "portable.h"
static LDAPConn *find_connection LDAP_P(( LDAP *ld, LDAPURLDesc *srv, int any ));
static void use_connection LDAP_P(( LDAP *ld, LDAPConn *lc ));
+static void ldap_free_request_int LDAP_P(( LDAP *ld, LDAPRequest *lr ));
static BerElement *
re_encode_request( LDAP *ld,
LDAP *ld,
ber_tag_t msgtype,
const char *dn,
- BerElement *ber )
+ BerElement *ber,
+ ber_int_t msgid)
{
LDAPURLDesc *servers;
int rc;
servers = NULL;
}
- rc = ldap_send_server_request( ld, ber, ld->ld_msgid, NULL,
- servers, NULL, 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
+#ifdef LDAP_R_COMPILE
+ ldap_pvt_thread_mutex_lock( &ld->ld_req_mutex );
+#endif
+ rc = ldap_send_server_request( ld, ber, msgid, NULL,
+ servers, NULL, NULL );
+#ifdef LDAP_R_COMPILE
+ ldap_pvt_thread_mutex_unlock( &ld->ld_req_mutex );
+#endif
if (servers)
ldap_free_urllist(servers);
return(rc);
}
+int
+ldap_int_flush_request(
+ LDAP *ld,
+ LDAPRequest *lr )
+{
+ LDAPConn *lc = lr->lr_conn;
+
+ if ( ber_flush( lc->lconn_sb, lr->lr_ber, 0 ) != 0 ) {
+ if ( errno == EAGAIN ) {
+ /* need to continue write later */
+ lr->lr_status = LDAP_REQST_WRITING;
+ ldap_mark_select_write( ld, lc->lconn_sb );
+ ld->ld_errno = LDAP_BUSY;
+ return -2;
+ } else {
+ ld->ld_errno = LDAP_SERVER_DOWN;
+ ldap_free_request( ld, lr );
+ ldap_free_connection( ld, lc, 0, 0 );
+ return( -1 );
+ }
+ } else {
+ if ( lr->lr_parent == NULL ) {
+ lr->lr_ber->ber_end = lr->lr_ber->ber_ptr;
+ lr->lr_ber->ber_ptr = lr->lr_ber->ber_buf;
+ }
+ lr->lr_status = LDAP_REQST_INPROGRESS;
+
+ /* sent -- waiting for a response */
+ ldap_mark_select_read( ld, lc->lconn_sb );
+ }
+ return 0;
+}
int
ldap_send_server_request(
LDAPreqinfo *bind )
{
LDAPRequest *lr;
- int incparent;
+ int incparent, rc;
Debug( LDAP_DEBUG_TRACE, "ldap_send_server_request\n", 0, 0, 0 );
if ( srvlist == NULL ) {
lc = ld->ld_defconn;
} else {
- if (( lc = find_connection( ld, srvlist, 1 )) ==
- NULL ) {
+ lc = find_connection( ld, srvlist, 1 );
+ if ( lc == NULL ) {
if ( (bind != NULL) && (parentreq != NULL) ) {
/* Remember the bind in the parent */
incparent = 1;
}
use_connection( ld, lc );
- if (( lr = (LDAPRequest *)LDAP_CALLOC( 1, sizeof( LDAPRequest ))) ==
- NULL ) {
+
+ /* If we still have an incomplete write, try to finish it before
+ * dealing with the new request. If we don't finish here, return
+ * LDAP_BUSY and let the caller retry later. We only allow a single
+ * request to be in WRITING state.
+ */
+ rc = 0;
+ if ( ld->ld_requests &&
+ ld->ld_requests->lr_status == LDAP_REQST_WRITING &&
+ ldap_int_flush_request( ld, ld->ld_requests ) < 0 )
+ {
+ rc = -1;
+ }
+ if ( rc ) return rc;
+
+ lr = (LDAPRequest *)LDAP_CALLOC( 1, sizeof( LDAPRequest ));
+ if ( lr == NULL ) {
ld->ld_errno = LDAP_NO_MEMORY;
ldap_free_connection( ld, lc, 0, 0 );
ber_free( ber, 1 );
++parentreq->lr_outrefcnt;
}
lr->lr_origid = parentreq->lr_origid;
- lr->lr_parentcnt = parentreq->lr_parentcnt + 1;
+ lr->lr_parentcnt = ++parentreq->lr_parentcnt;
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;
}
+ lr->lr_prev = NULL;
if (( lr->lr_next = ld->ld_requests ) != NULL ) {
lr->lr_next->lr_prev = lr;
}
ld->ld_requests = lr;
- lr->lr_prev = NULL;
-
- if ( ber_flush( lc->lconn_sb, ber, 0 ) != 0 ) {
-#ifdef notyet
- if ( errno == EWOULDBLOCK ) {
- /* need to continue write later */
- lr->lr_status = LDAP_REQST_WRITING;
- ldap_mark_select_write( ld, lc->lconn_sb );
- } else {
-#else /* notyet */
- ld->ld_errno = LDAP_SERVER_DOWN;
- ldap_free_request( ld, lr );
- ldap_free_connection( ld, lc, 0, 0 );
- return( -1 );
-#endif /* notyet */
-#ifdef notyet
- }
-#endif /* notyet */
- } else {
- if ( parentreq == NULL ) {
- ber->ber_end = ber->ber_ptr;
- ber->ber_ptr = ber->ber_buf;
- }
- /* sent -- waiting for a response */
- ldap_mark_select_read( ld, lc->lconn_sb );
+ ld->ld_errno = LDAP_SUCCESS;
+ if ( ldap_int_flush_request( ld, lr ) == -1 ) {
+ msgid = -1;
}
- ld->ld_errno = LDAP_SUCCESS;
return( msgid );
}
{
LDAPConn *lc;
LDAPURLDesc *srv;
- Sockbuf *sb = NULL;
- Debug( LDAP_DEBUG_TRACE, "ldap_new_connection\n", 0, 0, 0 );
+ Debug( LDAP_DEBUG_TRACE, "ldap_new_connection %d %d %d\n",
+ use_ldsb, connect, (bind != NULL) );
/*
* make a new LDAP server connection
* XXX open connection synchronously for now
*/
- if (( lc = (LDAPConn *)LDAP_CALLOC( 1, sizeof( LDAPConn ))) == NULL ||
- ( !use_ldsb && ( (sb = ber_sockbuf_alloc()) == NULL ))) {
- if ( lc != NULL ) {
- LDAP_FREE( (char *)lc );
- }
+ lc = (LDAPConn *)LDAP_CALLOC( 1, sizeof( LDAPConn ) );
+ if ( lc == NULL ) {
ld->ld_errno = LDAP_NO_MEMORY;
return( NULL );
}
+
+ if ( use_ldsb ) {
+ assert( ld->ld_sb != NULL );
+ lc->lconn_sb = ld->ld_sb;
- lc->lconn_sb = ( use_ldsb ) ? ld->ld_sb : sb;
+ } else {
+ lc->lconn_sb = ber_sockbuf_alloc();
+ if ( lc->lconn_sb == NULL ) {
+ LDAP_FREE( (char *)lc );
+ ld->ld_errno = LDAP_NO_MEMORY;
+ return( NULL );
+ }
+ }
if ( connect ) {
for ( srv = srvlist; srv != NULL; srv = srv->lud_next ) {
- if ( ldap_int_open_connection( ld, lc, srv, 0 ) != -1 ) {
+ if ( ldap_int_open_connection( ld, lc, srv, 0 ) != -1 )
+ {
break;
}
}
if ( !use_ldsb ) {
ber_sockbuf_free( lc->lconn_sb );
}
- LDAP_FREE( (char *)lc );
- ld->ld_errno = LDAP_SERVER_DOWN;
- return( NULL );
+ LDAP_FREE( (char *)lc );
+ ld->ld_errno = LDAP_SERVER_DOWN;
+ return( NULL );
}
- lc->lconn_server = ldap_url_dup(srv);
+ lc->lconn_server = ldap_url_dup( srv );
}
lc->lconn_status = LDAP_CONNST_CONNECTED;
int err = 0;
LDAPConn *savedefconn;
- /* Set flag to prevent additional referrals from being processed on this
+ /* Set flag to prevent additional referrals
+ * from being processed on this
* connection until the bind has completed
*/
lc->lconn_rebind_inprogress = 1;
/* V3 rebind function */
if ( ld->ld_rebind_proc != NULL) {
LDAPURLDesc *srvfunc;
- if( ( srvfunc = ldap_url_dup( srvlist)) == NULL) {
+
+ srvfunc = ldap_url_dup( srvlist );
+ if ( srvfunc == NULL ) {
ld->ld_errno = LDAP_NO_MEMORY;
err = -1;
} else {
ld->ld_defconn = lc;
Debug( LDAP_DEBUG_TRACE, "Call application rebind_proc\n", 0, 0, 0);
+#ifdef LDAP_R_COMPILE
+ ldap_pvt_thread_mutex_unlock( &ld->ld_req_mutex );
+ ldap_pvt_thread_mutex_unlock( &ld->ld_res_mutex );
+#endif
err = (*ld->ld_rebind_proc)( ld,
bind->ri_url, bind->ri_request, bind->ri_msgid,
ld->ld_rebind_params );
+#ifdef LDAP_R_COMPILE
+ ldap_pvt_thread_mutex_lock( &ld->ld_res_mutex );
+ ldap_pvt_thread_mutex_lock( &ld->ld_req_mutex );
+#endif
ld->ld_defconn = savedefconn;
--lc->lconn_refcnt;
- if( err != 0) {
- err = -1;
+ if ( err != 0 ) {
+ err = -1;
ldap_free_connection( ld, lc, 1, 0 );
lc = NULL;
+ }
+ ldap_free_urldesc( srvfunc );
}
- ldap_free_urldesc( srvfunc);
- }
} else {
savedefconn = ld->ld_defconn;
++lc->lconn_refcnt; /* avoid premature free */
ld->ld_defconn = lc;
Debug( LDAP_DEBUG_TRACE, "anonymous rebind via ldap_bind_s\n", 0, 0, 0);
+#ifdef LDAP_R_COMPILE
+ ldap_pvt_thread_mutex_unlock( &ld->ld_req_mutex );
+ ldap_pvt_thread_mutex_unlock( &ld->ld_res_mutex );
+#endif
if ( ldap_bind_s( ld, "", "", LDAP_AUTH_SIMPLE ) != LDAP_SUCCESS ) {
err = -1;
}
+#ifdef LDAP_R_COMPILE
+ ldap_pvt_thread_mutex_lock( &ld->ld_res_mutex );
+ ldap_pvt_thread_mutex_lock( &ld->ld_req_mutex );
+#endif
ld->ld_defconn = savedefconn;
--lc->lconn_refcnt;
- if ( err != 0 ) {
- ldap_free_connection( ld, lc, 1, 0 );
- lc = NULL;
+ if ( err != 0 ) {
+ ldap_free_connection( ld, lc, 1, 0 );
+ lc = NULL;
+ }
}
- }
- if( lc != NULL)
+ if ( lc != NULL )
lc->lconn_rebind_inprogress = 0;
}
*/
{
LDAPConn *lc;
- LDAPURLDesc *ls;
+ LDAPURLDesc *lcu, *lsu;
+ int lcu_port, lsu_port;
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 &&
- *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 ) {
+ lcu = lc->lconn_server;
+ lcu_port = ldap_pvt_url_scheme_port( lcu->lud_scheme,
+ lcu->lud_port );
+
+ for ( lsu = srv; lsu != NULL; lsu = lsu->lud_next ) {
+ lsu_port = ldap_pvt_url_scheme_port( lsu->lud_scheme,
+ lsu->lud_port );
+
+ if ( strcmp( lcu->lud_scheme, lsu->lud_scheme ) == 0
+ && lcu->lud_host != NULL && *lcu->lud_host != '\0'
+ && lsu->lud_host != NULL && *lsu->lud_host != '\0'
+ && strcasecmp( lsu->lud_host, lcu->lud_host ) == 0
+ && lsu_port == lcu_port )
+ {
return lc;
}
- if ( !any ) {
- break;
- }
+
+ if ( !any ) break;
}
}
{
LDAPConn *tmplc, *prevlc;
- Debug( LDAP_DEBUG_TRACE, "ldap_free_connection\n", 0, 0, 0 );
+ Debug( LDAP_DEBUG_TRACE,
+ "ldap_free_connection %d %d\n",
+ force, unbind, 0 );
if ( force || --lc->lconn_refcnt <= 0 ) {
if ( lc->lconn_status == LDAP_CONNST_CONNECTED ) {
}
}
- if( lc->lconn_ber != NULL ) {
+ if ( lc->lconn_ber != NULL ) {
ber_free( lc->lconn_ber, 1 );
}
ldap_int_sasl_close( ld, lc );
prevlc = NULL;
- for ( tmplc = ld->ld_conns; tmplc != NULL;
- tmplc = tmplc->lconn_next ) {
+ for ( tmplc = ld->ld_conns;
+ tmplc != NULL;
+ tmplc = tmplc->lconn_next )
+ {
if ( tmplc == lc ) {
if ( prevlc == NULL ) {
ld->ld_conns = tmplc->lconn_next;
LDAP_FREE( lc->lconn_krbinstance );
}
#endif
+
+ /* FIXME: is this at all possible? */
+ if ( force ) {
+ LDAPRequest *lr;
+
+ for ( lr = ld->ld_requests; lr; ) {
+ LDAPRequest *lr_next = lr->lr_next;
+
+ if ( lr->lr_conn == lc ) {
+ ldap_free_request_int( ld, lr );
+ }
+
+ lr = lr_next;
+ }
+ }
if ( lc->lconn_sb != ld->ld_sb ) {
ber_sockbuf_free( lc->lconn_sb );
}
- if( lc->lconn_rebind_queue != NULL) {
+ if ( lc->lconn_rebind_queue != NULL) {
int i;
- for( i = 0; lc->lconn_rebind_queue[i] != NULL; i++) {
- LDAP_VFREE(lc->lconn_rebind_queue[i]);
+ for( i = 0; lc->lconn_rebind_queue[i] != NULL; i++ ) {
+ LDAP_VFREE( lc->lconn_rebind_queue[i] );
}
- LDAP_FREE( lc->lconn_rebind_queue);
+ LDAP_FREE( lc->lconn_rebind_queue );
}
LDAP_FREE( lc );
- Debug( LDAP_DEBUG_TRACE, "ldap_free_connection: actually freed\n",
- 0, 0, 0 );
+ Debug( LDAP_DEBUG_TRACE,
+ "ldap_free_connection: actually freed\n",
+ 0, 0, 0 );
} else {
lc->lconn_lastused = time( NULL );
Debug( LDAP_DEBUG_TRACE, "ldap_free_connection: refcnt %d\n",
- lc->lconn_refcnt, 0, 0 );
+ lc->lconn_refcnt, 0, 0 );
}
}
LDAPRequest *lr;
LDAPMessage *lm, *l;
+#ifdef LDAP_R_COMPILE
+ ldap_pvt_thread_mutex_lock( &ld->ld_req_mutex );
+#endif
fprintf( stderr, "** Outstanding Requests:\n" );
if (( lr = ld->ld_requests ) == NULL ) {
fprintf( stderr, " Empty\n" );
fprintf( stderr, " outstanding referrals %d, parent count %d\n",
lr->lr_outrefcnt, lr->lr_parentcnt );
}
-
+#ifdef LDAP_R_COMPILE
+ ldap_pvt_thread_mutex_unlock( &ld->ld_req_mutex );
+#endif
fprintf( stderr, "** Response Queue:\n" );
if (( lm = ld->ld_responses ) == NULL ) {
fprintf( stderr, " Empty\n" );
}
#endif /* LDAP_DEBUG */
-
-void
-ldap_free_request( LDAP *ld, LDAPRequest *lr )
+static void
+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 ) {
+ /* free'ing the first request? */
+ assert( ld->ld_requests == lr );
ld->ld_requests = lr->lr_next;
+
} else {
lr->lr_prev->lr_next = lr->lr_next;
}
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 );
+
+ /* free all referrals (child requests) */
+ while ( lr->lr_child )
+ ldap_free_request( ld, lr->lr_child );
+
+ 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;
+ }
+ 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
*
ldap_chase_v3referrals( LDAP *ld, LDAPRequest *lr, char **refs, int sref, char **errstrp, int *hadrefp )
{
char *unfollowed;
- int unfollowedcnt = 0;
+ int unfollowedcnt = 0;
LDAPRequest *origreq;
LDAPURLDesc *srv = NULL;
BerElement *ber;
char **refarray = NULL;
LDAPConn *lc;
- int rc, count, i, j;
+ int rc, count, i, j, id;
LDAPreqinfo rinfo;
ld->ld_errno = LDAP_SUCCESS; /* optimistic */
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;
srv->lud_dn = LDAP_STRDUP( "" );
}
- ber = re_encode_request( ld, origreq->lr_ber, ++ld->ld_msgid,
+ LDAP_NEXT_MSGID( ld, id );
+ ber = re_encode_request( ld, origreq->lr_ber, id,
sref, srv, &rinfo.ri_request );
if( ber == NULL ) {
/* Send the new request to the server - may require a bind */
rinfo.ri_msgid = origreq->lr_origid;
rinfo.ri_url = refarray[i];
- if ( (rc = ldap_send_server_request( ld, ber, ld->ld_msgid,
- origreq, srv, NULL, &rinfo )) < 0 ) {
+#ifdef LDAP_R_COMPILE
+ ldap_pvt_thread_mutex_lock( &ld->ld_req_mutex );
+#endif
+ rc = ldap_send_server_request( ld, ber, id,
+ origreq, srv, NULL, &rinfo );
+#ifdef LDAP_R_COMPILE
+ ldap_pvt_thread_mutex_unlock( &ld->ld_req_mutex );
+#endif
+ if ( rc < 0 ) {
/* Failure, try next referral in the list */
Debug( LDAP_DEBUG_ANY, "Unable to chase referral \"%s\" (%s)\n",
refarray[i], ldap_err2string( ld->ld_errno ), 0);
}
} /* end for loop */
done:
- LDAP_VFREE(refarray);
- ldap_free_urllist(srv);
+ LDAP_VFREE( refarray );
+ ldap_free_urllist( srv );
LDAP_FREE( *errstrp );
- if( rc == 0) {
+ if( rc == 0 ) {
*errstrp = NULL;
LDAP_FREE( unfollowed );
return count;
int sref,
int *hadrefp )
{
- int rc, count, len;
+ int rc, count, id;
+ unsigned len;
char *p, *ref, *unfollowed;
LDAPRequest *origreq;
LDAPURLDesc *srv;
*hadrefp = 1;
+ LDAP_NEXT_MSGID( ld, id );
ber = re_encode_request( ld, origreq->lr_ber,
- ++ld->ld_msgid, sref, srv, &rinfo.ri_request );
+ id, sref, srv, &rinfo.ri_request );
if( ber == NULL ) {
return -1 ;
rinfo.ri_msgid = origreq->lr_origid;
- rc = ldap_send_server_request( ld, ber, ld->ld_msgid,
- lr, srv, NULL, &rinfo );
+#ifdef LDAP_R_COMPILE
+ ldap_pvt_thread_mutex_lock( &ld->ld_req_mutex );
+#endif
+ rc = ldap_send_server_request( ld, ber, id,
+ lr, srv, NULL, &rinfo );
+#ifdef LDAP_R_COMPILE
+ ldap_pvt_thread_mutex_unlock( &ld->ld_req_mutex );
+#endif
LDAP_FREE( rinfo.ri_url );
*/
ber_int_t along;
ber_tag_t tag;
+ ber_tag_t rtag;
ber_int_t ver;
ber_int_t scope;
int rc;
* tagged with the operation code. For delete, the provided DN
* is not wrapped by a sequence.
*/
- rc = ber_scanf( &tmpber, "{it", /*}*/ &along, &tag );
+ rtag = ber_scanf( &tmpber, "{it", /*}*/ &along, &tag );
- if ( rc == LBER_ERROR ) {
+ if ( rtag == LBER_ERROR ) {
ld->ld_errno = LDAP_DECODING_ERROR;
return( NULL );
}
assert( tag != 0);
if ( tag == LDAP_REQ_BIND ) {
/* bind requests have a version number before the DN & other stuff */
- rc = ber_scanf( &tmpber, "{ia" /*}*/, &ver, &orig_dn );
+ rtag = ber_scanf( &tmpber, "{ia" /*}*/, &ver, &orig_dn );
} else if ( tag == LDAP_REQ_DELETE ) {
/* delete requests don't have a DN wrapping sequence */
- rc = ber_scanf( &tmpber, "a", &orig_dn );
+ rtag = 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 );
+ rtag = 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 if ( sref ) {
+ /* use scope implied by previous operation
+ * base -> base
+ * one -> base
+ * subtree -> subtree
+ * subordinate -> subtree
+ */
+ switch( scope ) {
+ default:
+ case LDAP_SCOPE_BASE:
+ case LDAP_SCOPE_ONELEVEL:
+ scope = LDAP_SCOPE_BASE;
+ break;
+ case LDAP_SCOPE_SUBTREE:
+#ifdef LDAP_SCOPE_SUBORDINATE
+ case LDAP_SCOPE_SUBORDINATE:
+#endif
+ scope = LDAP_SCOPE_SUBTREE;
+ break;
+ }
}
} else {
- rc = ber_scanf( &tmpber, "{a" /*}*/, &orig_dn );
+ rtag = ber_scanf( &tmpber, "{a" /*}*/, &orig_dn );
}
- if( rc == LBER_ERROR ) {
+ if( rtag == LBER_ERROR ) {
ld->ld_errno = LDAP_DECODING_ERROR;
return NULL;
}
{
LDAPRequest *lr;
+#ifdef LDAP_R_COMPILE
+ ldap_pvt_thread_mutex_lock( &ld->ld_req_mutex );
+#endif
for ( lr = ld->ld_requests; lr != NULL; lr = lr->lr_next ) {
if( lr->lr_status == LDAP_REQST_COMPLETED ) {
continue; /* Skip completed requests */
break;
}
}
+#ifdef LDAP_R_COMPILE
+ ldap_pvt_thread_mutex_unlock( &ld->ld_req_mutex );
+#endif
return( lr );
}