From 177c051f0f98cdb34d37d76fad4f32cdc18cd2f4 Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Sat, 25 Mar 2006 08:16:19 +0000 Subject: [PATCH] use asynchronous API; note that an endless loop may occur (ITS#4450; no fix yet) --- libraries/libldap/request.c | 45 ++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/libraries/libldap/request.c b/libraries/libldap/request.c index c2c80cd715..9a16858d93 100644 --- a/libraries/libldap/request.c +++ b/libraries/libldap/request.c @@ -422,6 +422,9 @@ ldap_new_connection( LDAP *ld, LDAPURLDesc *srvlist, int use_ldsb, ldap_free_urldesc( srvfunc ); } } else { + int msgid, rc; + struct berval passwd = BER_BVNULL; + savedefconn = ld->ld_defconn; ++lc->lconn_refcnt; /* avoid premature free */ ld->ld_defconn = lc; @@ -431,8 +434,42 @@ ldap_new_connection( LDAP *ld, LDAPURLDesc *srvlist, int use_ldsb, 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 ) { + rc = ldap_sasl_bind( ld, "", LDAP_SASL_SIMPLE, &passwd, + NULL, NULL, &msgid ); + if ( rc != LDAP_SUCCESS ) { err = -1; + + } else { + for ( err = 1; err > 0; ) { + struct timeval tv = { 0, 100000 }; + LDAPMessage *res = NULL; + + switch ( ldap_result( ld, msgid, LDAP_MSG_ALL, &tv, &res ) ) { + case -1: + err = -1; + break; + + case 0: +#ifdef LDAP_R_COMPILE + ldap_pvt_thread_yield(); +#endif + break; + + case LDAP_RES_BIND: + rc = ldap_parse_result( ld, res, &err, NULL, NULL, NULL, NULL, 1 ); + if ( rc != LDAP_SUCCESS ) { + err = -1; + + } else if ( err != LDAP_SUCCESS ) { + err = -1; + } + /* else err == LDAP_SUCCESS == 0 */ + break; + + default: + assert( 0 ); + } + } } #ifdef LDAP_R_COMPILE ldap_pvt_thread_mutex_lock( &ld->ld_res_mutex ); @@ -876,7 +913,13 @@ ldap_chase_v3referrals( LDAP *ld, LDAPRequest *lr, char **refs, int sref, char * if ( len == lp->lr_dn.bv_len ) { if ( len && strncmp( srv->lud_dn, lp->lr_dn.bv_val, len )) + { + /* FIXME: if different DNs are requested + * for the same connection, this causes + * an endless loop, because lp is never + * changed */ continue; + } looped = 1; break; } -- 2.39.5