From 57ed8f645810a858b33c294afad72fd2add674d4 Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Fri, 1 Sep 2000 23:03:17 +0000 Subject: [PATCH] Fix port defaulting --- libraries/libldap/ldap-int.h | 3 ++- libraries/libldap/open.c | 16 +++++++--------- libraries/libldap/options.c | 3 ++- libraries/libldap/url.c | 12 ++++++++++-- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/libraries/libldap/ldap-int.h b/libraries/libldap/ldap-int.h index 6c862a3b0e..3c8ed21289 100644 --- a/libraries/libldap/ldap-int.h +++ b/libraries/libldap/ldap-int.h @@ -496,7 +496,8 @@ LDAP_F (int) ldap_url_parselist LDAP_P(( LDAP_F (int) ldap_url_parsehosts LDAP_P(( LDAPURLDesc **ludlist, - const char *hosts )); + const char *hosts, + int port )); LDAP_F (char *) ldap_url_list2hosts LDAP_P(( LDAPURLDesc *ludlist )); diff --git a/libraries/libldap/open.c b/libraries/libldap/open.c index 6f68e25c50..658c86fac2 100644 --- a/libraries/libldap/open.c +++ b/libraries/libldap/open.c @@ -257,19 +257,17 @@ ldap_int_open_connection( Debug( LDAP_DEBUG_TRACE, "ldap_int_open_connection\n", 0, 0, 0 ); - port = srv->lud_port; - if (port == 0) - port = ld->ld_options.ldo_defport; - port = htons( (short) port ); - - addr = 0; - if ( srv->lud_host == NULL || *srv->lud_host == 0 ) - addr = htonl( INADDR_LOOPBACK ); - switch ( ldap_pvt_url_scheme2proto( srv->lud_scheme ) ) { case LDAP_PROTO_TCP: + port = htons( (short) srv->lud_port ); + + addr = 0; + if ( srv->lud_host == NULL || *srv->lud_host == 0 ) + addr = htonl( INADDR_LOOPBACK ); + rc = ldap_connect_to_host( ld, conn->lconn_sb, 0, srv->lud_host, addr, port, async ); + if ( rc == -1 ) return rc; ber_sockbuf_add_io( conn->lconn_sb, &ber_sockbuf_io_tcp, LBER_SBIOD_LEVEL_PROVIDER, NULL ); diff --git a/libraries/libldap/options.c b/libraries/libldap/options.c index 515f906b98..041897494d 100644 --- a/libraries/libldap/options.c +++ b/libraries/libldap/options.c @@ -465,7 +465,8 @@ ldap_set_option( int rc = LDAP_OPT_SUCCESS; if(host != NULL) { - rc = ldap_url_parsehosts(&ludlist, host); + rc = ldap_url_parsehosts( &ludlist, host, + lo->ldo_defport ? lo->ldo_defport : LDAP_PORT ); } else if(ld == NULL) { /* diff --git a/libraries/libldap/url.c b/libraries/libldap/url.c index e6cf9e0753..ccb7eca613 100644 --- a/libraries/libldap/url.c +++ b/libraries/libldap/url.c @@ -272,7 +272,7 @@ ldap_url_parse( LDAP_CONST char *url_in, LDAPURLDesc **ludpp ) ludp->lud_next = NULL; ludp->lud_host = NULL; - ludp->lud_port = 0; + ludp->lud_port = LDAP_PORT; ludp->lud_dn = NULL; ludp->lud_attrs = NULL; ludp->lud_filter = NULL; @@ -287,6 +287,10 @@ ldap_url_parse( LDAP_CONST char *url_in, LDAPURLDesc **ludpp ) return LDAP_URL_ERR_MEM; } + if( strcasecmp( ludp->lud_scheme, "ldaps" ) == 0 ) { + ludp->lud_port = LDAPS_PORT; + } + /* scan forward for '/' that marks end of hostport and begin. of dn */ p = strchr( url, '/' ); @@ -659,7 +663,10 @@ ldap_url_parselist (LDAPURLDesc **ludlist, const char *url ) } int -ldap_url_parsehosts (LDAPURLDesc **ludlist, const char *hosts ) +ldap_url_parsehosts( + LDAPURLDesc **ludlist, + const char *hosts, + int port ) { int i; LDAPURLDesc *ludp; @@ -686,6 +693,7 @@ ldap_url_parsehosts (LDAPURLDesc **ludlist, const char *hosts ) *ludlist = NULL; return LDAP_NO_MEMORY; } + ludp->lud_port = port; ludp->lud_host = specs[i]; specs[i] = NULL; p = strchr(ludp->lud_host, ':'); -- 2.39.2