]> git.sur5r.net Git - openldap/commitdiff
Pass LDAPURLDescs to connect functions instead of host/port
authorHoward Chu <hyc@openldap.org>
Fri, 15 Aug 2008 22:53:47 +0000 (22:53 +0000)
committerHoward Chu <hyc@openldap.org>
Fri, 15 Aug 2008 22:53:47 +0000 (22:53 +0000)
include/ldap.h
libraries/libldap/ldap-int.h
libraries/libldap/open.c
libraries/libldap/os-ip.c
libraries/libldap/os-local.c

index 840378c449d6493d00de1e4fd3c3f13f970d1f51..7f87330daef95f2a21d0f1b3fcd937e7dfc13e84 100644 (file)
@@ -127,7 +127,7 @@ LDAP_BEGIN_DECL
 
 /* OpenLDAP TLS options */
 #define LDAP_OPT_X_TLS                         0x6000
-#define LDAP_OPT_X_TLS_CTX                     0x6001  /* OpenSSL CTX */
+#define LDAP_OPT_X_TLS_CTX                     0x6001  /* OpenSSL CTX* */
 #define LDAP_OPT_X_TLS_CACERTFILE      0x6002
 #define LDAP_OPT_X_TLS_CACERTDIR       0x6003
 #define LDAP_OPT_X_TLS_CERTFILE                0x6004
@@ -136,7 +136,7 @@ LDAP_BEGIN_DECL
 /* #define LDAP_OPT_X_TLS_PROTOCOL             0x6007 */
 #define LDAP_OPT_X_TLS_CIPHER_SUITE    0x6008
 #define LDAP_OPT_X_TLS_RANDOM_FILE     0x6009
-#define LDAP_OPT_X_TLS_SSL_CTX         0x600a
+#define LDAP_OPT_X_TLS_SSL_CTX         0x600a  /* OpenSSL SSL* */
 #define LDAP_OPT_X_TLS_CRLCHECK                0x600b
 #define LDAP_OPT_X_TLS_CONNECT_CB      0x600c
 #define LDAP_OPT_X_TLS_CONNECT_ARG     0x600d
@@ -889,7 +889,7 @@ struct ldap_conncb;
 struct sockaddr;
 
 /* Called after a connection is established */
-typedef void (ldap_conn_add_f) LDAP_P(( LDAP *ld, Sockbuf *sb, const char *name, struct sockaddr *addr,
+typedef int (ldap_conn_add_f) LDAP_P(( LDAP *ld, Sockbuf *sb, LDAPURLDesc *srv, struct sockaddr *addr,
        struct ldap_conncb *ctx ));
 /* Called before a connection is closed */
 typedef void (ldap_conn_del_f) LDAP_P(( LDAP *ld, Sockbuf *sb, struct ldap_conncb *ctx ));
index 4b61a212455a186a8ba345c6c2134ba51cc9b80b..e9e1921de460356c227439907e6029afa5b2061f 100644 (file)
@@ -512,7 +512,7 @@ LDAP_F (void) ldap_int_ip_init( void );
 LDAP_F (int) ldap_int_timeval_dup( struct timeval **dest,
        const struct timeval *tm );
 LDAP_F (int) ldap_connect_to_host( LDAP *ld, Sockbuf *sb,
-       int proto, const char *host, int port, int async );
+       int proto, LDAPURLDesc *srv, int async );
 LDAP_F (int) ldap_int_poll( LDAP *ld, ber_socket_t s,
        struct timeval *tvp );
 
@@ -532,14 +532,14 @@ LDAP_F (int) ldap_is_read_ready( LDAP *ld, Sockbuf *sb );
 LDAP_F (int) ldap_is_write_ready( LDAP *ld, Sockbuf *sb );
 
 LDAP_F (int) ldap_int_connect_cbs( LDAP *ld, Sockbuf *sb,
-       ber_socket_t *s, const char *name, struct sockaddr *addr );
+       ber_socket_t *s, LDAPURLDesc *srv, struct sockaddr *addr );
 
 /*
  * in os-local.c
  */
 #ifdef LDAP_PF_LOCAL
 LDAP_F (int) ldap_connect_to_path( LDAP *ld, Sockbuf *sb,
-       const char *path, int async );
+       LDAPURLDesc *srv, int async );
 #endif /* LDAP_PF_LOCAL */
 
 /*
index 8bc8c39350e8dd3151f42ee117b700ea9d772d8c..cda6e86423ad7fd766fb8bffb9187dfe8bfb78c6 100644 (file)
@@ -344,27 +344,10 @@ ldap_int_open_connection(
 
        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_" );
@@ -376,19 +359,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
@@ -407,7 +380,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,
index bda0f18a2296957a49c525208f82587800a5ad55..b5beacf2529c04bf099e557219a7c345974862d6 100644 (file)
@@ -425,7 +425,7 @@ ldap_pvt_inet_aton( const char *host, struct in_addr *in)
 #endif
 
 int
-ldap_int_connect_cbs(LDAP *ld, Sockbuf *sb, ber_socket_t *s, const char *host, struct sockaddr *addr)
+ldap_int_connect_cbs(LDAP *ld, Sockbuf *sb, ber_socket_t *s, LDAPURLDesc *srv, struct sockaddr *addr)
 {
        struct ldapoptions *lo;
        ldaplist *ll;
@@ -438,7 +438,7 @@ ldap_int_connect_cbs(LDAP *ld, Sockbuf *sb, ber_socket_t *s, const char *host, s
        lo = &ld->ld_options;
        for (ll = lo->ldo_conn_cbs; ll; ll = ll->ll_next) {
                cb = ll->ll_data;
-               rc = cb->lc_add( ld, sb, host, addr, cb );
+               rc = cb->lc_add( ld, sb, srv, addr, cb );
                /* on any failure, call the teardown functions for anything
                 * that previously succeeded
                 */
@@ -456,7 +456,7 @@ ldap_int_connect_cbs(LDAP *ld, Sockbuf *sb, ber_socket_t *s, const char *host, s
        lo = LDAP_INT_GLOBAL_OPT();
        for (ll = lo->ldo_conn_cbs; ll; ll = ll->ll_next) {
                cb = ll->ll_data;
-               rc = cb->lc_add( ld, sb, host, addr, cb );
+               rc = cb->lc_add( ld, sb, srv, addr, cb );
                if ( rc ) {
                        ldaplist *l2;
                        for (l2 = lo->ldo_conn_cbs; l2 != ll; l2 = l2->ll_next) {
@@ -477,13 +477,13 @@ ldap_int_connect_cbs(LDAP *ld, Sockbuf *sb, ber_socket_t *s, const char *host, s
 
 int
 ldap_connect_to_host(LDAP *ld, Sockbuf *sb,
-       int proto,
-       const char *host, int port,
+       int proto, LDAPURLDesc *srv,
        int async )
 {
        int     rc;
-       int     socktype;
+       int     socktype, port;
        ber_socket_t            s = AC_SOCKET_INVALID;
+       char *host;
 
 #if defined( HAVE_GETADDRINFO ) && defined( HAVE_INET_NTOP )
        char serv[7];
@@ -498,8 +498,22 @@ ldap_connect_to_host(LDAP *ld, Sockbuf *sb,
        char *ha_buf=NULL;
 #endif
 
-       if( host == NULL ) host = "localhost";
-       
+       if ( srv->lud_host == NULL || *srv->lud_host == 0 ) {
+               host = "localhost";
+       } else {
+               host = srv->lud_host;
+       }
+
+       port = srv->lud_port;
+
+       if( !port ) {
+               if( strcmp(srv->lud_scheme, "ldaps") == 0 ) {
+                       port = LDAPS_PORT;
+               } else {
+                       port = LDAP_PORT;
+               }
+       }
+
        switch(proto) {
        case LDAP_PROTO_TCP: socktype = SOCK_STREAM;
                osip_debug( ld,
@@ -587,7 +601,7 @@ ldap_connect_to_host(LDAP *ld, Sockbuf *sb,
                rc = ldap_pvt_connect( ld, s,
                        sai->ai_addr, sai->ai_addrlen, async );
                if ( rc == 0 || rc == -2 ) {
-                       err = ldap_int_connect_cbs( ld, sb, &s, host, sai->ai_addr );
+                       err = ldap_int_connect_cbs( ld, sb, &s, srv, sai->ai_addr );
                        if ( err )
                                rc = err;
                        else
@@ -662,7 +676,7 @@ ldap_connect_to_host(LDAP *ld, Sockbuf *sb,
                        async);
    
                if ( (rc == 0) || (rc == -2) ) {
-                       i = ldap_int_connect_cbs( ld, sb, &s, host, (struct sockaddr *)&sin );
+                       i = ldap_int_connect_cbs( ld, sb, &s, srv, (struct sockaddr *)&sin );
                        if ( i )
                                rc = i;
                        else
index 3a05f90c03205f90d706aee1c6790caea3762ca6..047151e626b31ff00158fa16b425d0a1164f64aa 100644 (file)
@@ -319,11 +319,12 @@ sendcred:
 }
 
 int
-ldap_connect_to_path(LDAP *ld, Sockbuf *sb, const char *path, int async)
+ldap_connect_to_path(LDAP *ld, Sockbuf *sb, LDAPURLDesc *srv, int async)
 {
        struct sockaddr_un      server;
        ber_socket_t            s;
        int                     rc;
+       const char *path = srv->lud_host;
 
        oslocal_debug(ld, "ldap_connect_to_path\n",0,0,0);
 
@@ -351,7 +352,7 @@ ldap_connect_to_path(LDAP *ld, Sockbuf *sb, const char *path, int async)
 
        if (rc == 0) {
                int err;
-               err = ldap_int_connect_cbs( ld, sb, &s, path, (struct sockaddr *)&server );
+               err = ldap_int_connect_cbs( ld, sb, &s, srv, (struct sockaddr *)&server );
                if ( err )
                        rc = err;
        }