From: Howard Chu Date: Fri, 15 Aug 2008 22:53:47 +0000 (+0000) Subject: Pass LDAPURLDescs to connect functions instead of host/port X-Git-Tag: ACLCHECK_0~1420 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=0dbeb1d87bd711408133c549e17ff8689a04508c;p=openldap Pass LDAPURLDescs to connect functions instead of host/port --- diff --git a/include/ldap.h b/include/ldap.h index 840378c449..7f87330dae 100644 --- a/include/ldap.h +++ b/include/ldap.h @@ -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 )); diff --git a/libraries/libldap/ldap-int.h b/libraries/libldap/ldap-int.h index 4b61a21245..e9e1921de4 100644 --- a/libraries/libldap/ldap-int.h +++ b/libraries/libldap/ldap-int.h @@ -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 */ /* diff --git a/libraries/libldap/open.c b/libraries/libldap/open.c index 8bc8c39350..cda6e86423 100644 --- a/libraries/libldap/open.c +++ b/libraries/libldap/open.c @@ -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, diff --git a/libraries/libldap/os-ip.c b/libraries/libldap/os-ip.c index bda0f18a22..b5beacf252 100644 --- a/libraries/libldap/os-ip.c +++ b/libraries/libldap/os-ip.c @@ -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 diff --git a/libraries/libldap/os-local.c b/libraries/libldap/os-local.c index 3a05f90c03..047151e626 100644 --- a/libraries/libldap/os-local.c +++ b/libraries/libldap/os-local.c @@ -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; }