From 8064bb6ef18965ba5aa7fd4c2f24f385a72d2993 Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Sat, 28 Aug 2004 03:53:31 +0000 Subject: [PATCH] A better find_connection() port fix --- include/ldap_pvt.h | 4 ++++ libraries/libldap/request.c | 8 ++++++-- libraries/libldap/url.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 2 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 fec28e0d1c..305dc945dd 100644 --- a/libraries/libldap/request.c +++ b/libraries/libldap/request.c @@ -452,9 +452,13 @@ find_connection( LDAP *ld, LDAPURLDesc *srv, int any ) for ( lc = ld->ld_conns; lc != NULL; lc = lc->lconn_next ) { lcu = lc->lconn_server; - lcu_port = lcu->lud_port ? lcu->lud_port : LDAP_PORT; + lcu_port = ldap_pvt_url_scheme_port( lcu->lud_scheme, + lcu->lud_port ); + for ( lsu = srv; lsu != NULL; lsu = lsu->lud_next ) { - lsu_port = lsu->lud_port ? lsu->lud_port : LDAP_PORT; + lsu_port = ldap_pvt_url_scheme_port( lsu->lud_scheme, + lsu->lud_port ); + if ( lcu->lud_host != NULL && *lcu->lud_host != '\0' && lsu->lud_host != NULL && *lsu->lud_host != '\0' && strcasecmp( lsu->lud_host, lcu->lud_host ) == 0 diff --git a/libraries/libldap/url.c b/libraries/libldap/url.c index 6b520d5c4c..a0f7dab38d 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.5