From 29baa08422fa7b86049b6d8a9b5383f69b76b4a1 Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Mon, 30 Aug 2004 02:59:22 +0000 Subject: [PATCH] find_connections fix (ITS#3280) from HEAD Add ldap_pvt_url_scheme_port() --- include/ldap_pvt.h | 4 ++++ libraries/libldap/request.c | 28 ++++++++++++++++++---------- libraries/libldap/url.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 10 deletions(-) diff --git a/include/ldap_pvt.h b/include/ldap_pvt.h index 8785f9ac17..f218223acf 100644 --- a/include/ldap_pvt.h +++ b/include/ldap_pvt.h @@ -35,6 +35,10 @@ LDAP_F ( int ) ldap_pvt_url_scheme2tls LDAP_P(( const char * )); +LDAP_F ( int ) +ldap_pvt_url_scheme_port LDAP_P(( + const char *, int )); + struct ldap_url_desc; /* avoid pulling in */ LDAP_F( int ) diff --git a/libraries/libldap/request.c b/libraries/libldap/request.c index deb583eeb7..bf5cb8edce 100644 --- a/libraries/libldap/request.c +++ b/libraries/libldap/request.c @@ -448,20 +448,28 @@ find_connection( LDAP *ld, LDAPURLDesc *srv, int any ) */ { 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; } } diff --git a/libraries/libldap/url.c b/libraries/libldap/url.c index 206f16aafb..1615a77ae5 100644 --- a/libraries/libldap/url.c +++ b/libraries/libldap/url.c @@ -78,6 +78,34 @@ int ldap_pvt_url_scheme2proto( const char *scheme ) return -1; } +int ldap_pvt_url_scheme_port( const char *scheme, int port ) +{ + assert( scheme ); + + if( port ) return port; + if( scheme == NULL ) return port; + + if( strcmp("ldap", scheme) == 0 ) { + return LDAP_PORT; + } + + if( strcmp("ldapi", scheme) == 0 ) { + return -1; + } + + if( strcmp("ldaps", scheme) == 0 ) { + return LDAPS_PORT; + } + +#ifdef LDAP_CONNECTIONLESS + if( strcmp("cldap", scheme) == 0 ) { + return LDAP_PORT; + } +#endif + + return -1; +} + int ldap_pvt_url_scheme2tls( const char *scheme ) { -- 2.39.2