]> git.sur5r.net Git - openldap/commitdiff
Fix port defaulting
authorKurt Zeilenga <kurt@openldap.org>
Fri, 1 Sep 2000 23:03:17 +0000 (23:03 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Fri, 1 Sep 2000 23:03:17 +0000 (23:03 +0000)
libraries/libldap/ldap-int.h
libraries/libldap/open.c
libraries/libldap/options.c
libraries/libldap/url.c

index 6c862a3b0e0fce7bead13cc7c3c73279b0543ac6..3c8ed212891801bc94fa692b9bc2b877cc0a231d 100644 (file)
@@ -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 ));
index 6f68e25c5055e425efb711b433a48214e0135cf8..658c86fac20b0e8c4b94fe8471385113f691ee45 100644 (file)
@@ -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 );
index 515f906b9845b2efa7bbef4cfd041c937347a8d5..041897494dc6c9fa1ae8140e4883b34a69962b0e 100644 (file)
@@ -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) {
                                /*
index e6cf9e07532cf7798a6ad2f0675c6c5768df8e3c..ccb7eca61335ca6267887896b1fc4b84be3467d0 100644 (file)
@@ -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, ':');