]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/open.c
ITS#6689
[openldap] / libraries / libldap / open.c
index 9939a87df581b288da467b392099e75ed0e6c53a..1bc86e39a718d160eee2a8f03180bb135328b5c7 100644 (file)
@@ -1,7 +1,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1998-2007 The OpenLDAP Foundation.
+ * Copyright 1998-2010 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -82,7 +82,7 @@ ldap_open( LDAP_CONST char *host, int port )
        }
 
        Debug( LDAP_DEBUG_TRACE, "ldap_open: %s\n",
-               ld == NULL ? "succeeded" : "failed", 0, 0 );
+               ld != NULL ? "succeeded" : "failed", 0, 0 );
 
        return ld;
 }
@@ -123,6 +123,7 @@ ldap_create( LDAP **ldp )
        ld->ld_options.ldo_sctrls = NULL;
        ld->ld_options.ldo_cctrls = NULL;
        ld->ld_options.ldo_defludp = NULL;
+       ld->ld_options.ldo_conn_cbs = NULL;
 
 #ifdef HAVE_CYRUS_SASL
        ld->ld_options.ldo_def_sasl_mech = gopts->ldo_def_sasl_mech
@@ -270,6 +271,8 @@ ldap_init_fd(
                ldap_unbind_ext( ld, NULL, NULL );
                return( LDAP_NO_MEMORY );
        }
+       if( url )
+               conn->lconn_server = ldap_url_dup( ld->ld_options.ldo_defludp );
        ber_sockbuf_ctrl( conn->lconn_sb, LBER_SB_OPT_SET_FD, &fd );
        ld->ld_defconn = conn;
        ++ld->ld_defconn->lconn_refcnt; /* so it never gets closed/freed */
@@ -336,34 +339,16 @@ ldap_int_open_connection(
        int async )
 {
        int rc = -1;
-       char *host;
-       int port, proto;
+       int proto;
 
        Debug( LDAP_DEBUG_TRACE, "ldap_int_open_connection\n", 0, 0, 0 );
 
        switch ( proto = ldap_pvt_url_scheme2proto( srv->lud_scheme ) ) {
                case LDAP_PROTO_TCP:
-                       port = srv->lud_port;
-
-                       if ( srv->lud_host == NULL || *srv->lud_host == 0 ) {
-                               host = NULL;
-                       } else {
-                               host = srv->lud_host;
-                       }
-
-                       if( !port ) {
-                               if( strcmp(srv->lud_scheme, "ldaps") == 0 ) {
-                                       port = LDAPS_PORT;
-                               } else {
-                                       port = LDAP_PORT;
-                               }
-                       }
-
                        rc = ldap_connect_to_host( ld, conn->lconn_sb,
-                               proto, host, port, async );
+                               proto, srv, async );
 
                        if ( rc == -1 ) return rc;
-
 #ifdef LDAP_DEBUG
                        ber_sockbuf_add_io( conn->lconn_sb, &ber_sockbuf_io_debug,
                                LBER_SBIOD_LEVEL_PROVIDER, (void *)"tcp_" );
@@ -375,19 +360,9 @@ ldap_int_open_connection(
 
 #ifdef LDAP_CONNECTIONLESS
                case LDAP_PROTO_UDP:
-                       port = srv->lud_port;
-
-                       if ( srv->lud_host == NULL || *srv->lud_host == 0 ) {
-                               host = NULL;
-                       } else {
-                               host = srv->lud_host;
-                       }
-
-                       if( !port ) port = LDAP_PORT;
-
                        LDAP_IS_UDP(ld) = 1;
                        rc = ldap_connect_to_host( ld, conn->lconn_sb,
-                               proto, host, port, async );
+                               proto, srv, async );
 
                        if ( rc == -1 ) return rc;
 #ifdef LDAP_DEBUG
@@ -406,7 +381,7 @@ ldap_int_open_connection(
 #ifdef LDAP_PF_LOCAL
                        /* only IPC mechanism supported is PF_LOCAL (PF_UNIX) */
                        rc = ldap_connect_to_path( ld, conn->lconn_sb,
-                               srv->lud_host, async );
+                               srv, async );
                        if ( rc == -1 ) return rc;
 #ifdef LDAP_DEBUG
                        ber_sockbuf_add_io( conn->lconn_sb, &ber_sockbuf_io_debug,