mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-01-18 11:05:48 +08:00
Pass LDAPURLDescs to connect functions instead of host/port
This commit is contained in:
parent
46049f1d13
commit
0dbeb1d87b
@ -127,7 +127,7 @@ LDAP_BEGIN_DECL
|
|||||||
|
|
||||||
/* OpenLDAP TLS options */
|
/* OpenLDAP TLS options */
|
||||||
#define LDAP_OPT_X_TLS 0x6000
|
#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_CACERTFILE 0x6002
|
||||||
#define LDAP_OPT_X_TLS_CACERTDIR 0x6003
|
#define LDAP_OPT_X_TLS_CACERTDIR 0x6003
|
||||||
#define LDAP_OPT_X_TLS_CERTFILE 0x6004
|
#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_PROTOCOL 0x6007 */
|
||||||
#define LDAP_OPT_X_TLS_CIPHER_SUITE 0x6008
|
#define LDAP_OPT_X_TLS_CIPHER_SUITE 0x6008
|
||||||
#define LDAP_OPT_X_TLS_RANDOM_FILE 0x6009
|
#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_CRLCHECK 0x600b
|
||||||
#define LDAP_OPT_X_TLS_CONNECT_CB 0x600c
|
#define LDAP_OPT_X_TLS_CONNECT_CB 0x600c
|
||||||
#define LDAP_OPT_X_TLS_CONNECT_ARG 0x600d
|
#define LDAP_OPT_X_TLS_CONNECT_ARG 0x600d
|
||||||
@ -889,7 +889,7 @@ struct ldap_conncb;
|
|||||||
struct sockaddr;
|
struct sockaddr;
|
||||||
|
|
||||||
/* Called after a connection is established */
|
/* 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 ));
|
struct ldap_conncb *ctx ));
|
||||||
/* Called before a connection is closed */
|
/* Called before a connection is closed */
|
||||||
typedef void (ldap_conn_del_f) LDAP_P(( LDAP *ld, Sockbuf *sb, struct ldap_conncb *ctx ));
|
typedef void (ldap_conn_del_f) LDAP_P(( LDAP *ld, Sockbuf *sb, struct ldap_conncb *ctx ));
|
||||||
|
@ -512,7 +512,7 @@ LDAP_F (void) ldap_int_ip_init( void );
|
|||||||
LDAP_F (int) ldap_int_timeval_dup( struct timeval **dest,
|
LDAP_F (int) ldap_int_timeval_dup( struct timeval **dest,
|
||||||
const struct timeval *tm );
|
const struct timeval *tm );
|
||||||
LDAP_F (int) ldap_connect_to_host( LDAP *ld, Sockbuf *sb,
|
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,
|
LDAP_F (int) ldap_int_poll( LDAP *ld, ber_socket_t s,
|
||||||
struct timeval *tvp );
|
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_is_write_ready( LDAP *ld, Sockbuf *sb );
|
||||||
|
|
||||||
LDAP_F (int) ldap_int_connect_cbs( 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
|
* in os-local.c
|
||||||
*/
|
*/
|
||||||
#ifdef LDAP_PF_LOCAL
|
#ifdef LDAP_PF_LOCAL
|
||||||
LDAP_F (int) ldap_connect_to_path( LDAP *ld, Sockbuf *sb,
|
LDAP_F (int) ldap_connect_to_path( LDAP *ld, Sockbuf *sb,
|
||||||
const char *path, int async );
|
LDAPURLDesc *srv, int async );
|
||||||
#endif /* LDAP_PF_LOCAL */
|
#endif /* LDAP_PF_LOCAL */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -344,27 +344,10 @@ ldap_int_open_connection(
|
|||||||
|
|
||||||
switch ( proto = ldap_pvt_url_scheme2proto( srv->lud_scheme ) ) {
|
switch ( proto = ldap_pvt_url_scheme2proto( srv->lud_scheme ) ) {
|
||||||
case LDAP_PROTO_TCP:
|
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,
|
rc = ldap_connect_to_host( ld, conn->lconn_sb,
|
||||||
proto, host, port, async );
|
proto, srv, async );
|
||||||
|
|
||||||
if ( rc == -1 ) return rc;
|
if ( rc == -1 ) return rc;
|
||||||
|
|
||||||
#ifdef LDAP_DEBUG
|
#ifdef LDAP_DEBUG
|
||||||
ber_sockbuf_add_io( conn->lconn_sb, &ber_sockbuf_io_debug,
|
ber_sockbuf_add_io( conn->lconn_sb, &ber_sockbuf_io_debug,
|
||||||
LBER_SBIOD_LEVEL_PROVIDER, (void *)"tcp_" );
|
LBER_SBIOD_LEVEL_PROVIDER, (void *)"tcp_" );
|
||||||
@ -376,19 +359,9 @@ ldap_int_open_connection(
|
|||||||
|
|
||||||
#ifdef LDAP_CONNECTIONLESS
|
#ifdef LDAP_CONNECTIONLESS
|
||||||
case LDAP_PROTO_UDP:
|
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;
|
LDAP_IS_UDP(ld) = 1;
|
||||||
rc = ldap_connect_to_host( ld, conn->lconn_sb,
|
rc = ldap_connect_to_host( ld, conn->lconn_sb,
|
||||||
proto, host, port, async );
|
proto, srv, async );
|
||||||
|
|
||||||
if ( rc == -1 ) return rc;
|
if ( rc == -1 ) return rc;
|
||||||
#ifdef LDAP_DEBUG
|
#ifdef LDAP_DEBUG
|
||||||
@ -407,7 +380,7 @@ ldap_int_open_connection(
|
|||||||
#ifdef LDAP_PF_LOCAL
|
#ifdef LDAP_PF_LOCAL
|
||||||
/* only IPC mechanism supported is PF_LOCAL (PF_UNIX) */
|
/* only IPC mechanism supported is PF_LOCAL (PF_UNIX) */
|
||||||
rc = ldap_connect_to_path( ld, conn->lconn_sb,
|
rc = ldap_connect_to_path( ld, conn->lconn_sb,
|
||||||
srv->lud_host, async );
|
srv, async );
|
||||||
if ( rc == -1 ) return rc;
|
if ( rc == -1 ) return rc;
|
||||||
#ifdef LDAP_DEBUG
|
#ifdef LDAP_DEBUG
|
||||||
ber_sockbuf_add_io( conn->lconn_sb, &ber_sockbuf_io_debug,
|
ber_sockbuf_add_io( conn->lconn_sb, &ber_sockbuf_io_debug,
|
||||||
|
@ -425,7 +425,7 @@ ldap_pvt_inet_aton( const char *host, struct in_addr *in)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
int
|
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;
|
struct ldapoptions *lo;
|
||||||
ldaplist *ll;
|
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;
|
lo = &ld->ld_options;
|
||||||
for (ll = lo->ldo_conn_cbs; ll; ll = ll->ll_next) {
|
for (ll = lo->ldo_conn_cbs; ll; ll = ll->ll_next) {
|
||||||
cb = ll->ll_data;
|
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
|
/* on any failure, call the teardown functions for anything
|
||||||
* that previously succeeded
|
* 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();
|
lo = LDAP_INT_GLOBAL_OPT();
|
||||||
for (ll = lo->ldo_conn_cbs; ll; ll = ll->ll_next) {
|
for (ll = lo->ldo_conn_cbs; ll; ll = ll->ll_next) {
|
||||||
cb = ll->ll_data;
|
cb = ll->ll_data;
|
||||||
rc = cb->lc_add( ld, sb, host, addr, cb );
|
rc = cb->lc_add( ld, sb, srv, addr, cb );
|
||||||
if ( rc ) {
|
if ( rc ) {
|
||||||
ldaplist *l2;
|
ldaplist *l2;
|
||||||
for (l2 = lo->ldo_conn_cbs; l2 != ll; l2 = l2->ll_next) {
|
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
|
int
|
||||||
ldap_connect_to_host(LDAP *ld, Sockbuf *sb,
|
ldap_connect_to_host(LDAP *ld, Sockbuf *sb,
|
||||||
int proto,
|
int proto, LDAPURLDesc *srv,
|
||||||
const char *host, int port,
|
|
||||||
int async )
|
int async )
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
int socktype;
|
int socktype, port;
|
||||||
ber_socket_t s = AC_SOCKET_INVALID;
|
ber_socket_t s = AC_SOCKET_INVALID;
|
||||||
|
char *host;
|
||||||
|
|
||||||
#if defined( HAVE_GETADDRINFO ) && defined( HAVE_INET_NTOP )
|
#if defined( HAVE_GETADDRINFO ) && defined( HAVE_INET_NTOP )
|
||||||
char serv[7];
|
char serv[7];
|
||||||
@ -498,7 +498,21 @@ ldap_connect_to_host(LDAP *ld, Sockbuf *sb,
|
|||||||
char *ha_buf=NULL;
|
char *ha_buf=NULL;
|
||||||
#endif
|
#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) {
|
switch(proto) {
|
||||||
case LDAP_PROTO_TCP: socktype = SOCK_STREAM;
|
case LDAP_PROTO_TCP: socktype = SOCK_STREAM;
|
||||||
@ -587,7 +601,7 @@ ldap_connect_to_host(LDAP *ld, Sockbuf *sb,
|
|||||||
rc = ldap_pvt_connect( ld, s,
|
rc = ldap_pvt_connect( ld, s,
|
||||||
sai->ai_addr, sai->ai_addrlen, async );
|
sai->ai_addr, sai->ai_addrlen, async );
|
||||||
if ( rc == 0 || rc == -2 ) {
|
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 )
|
if ( err )
|
||||||
rc = err;
|
rc = err;
|
||||||
else
|
else
|
||||||
@ -662,7 +676,7 @@ ldap_connect_to_host(LDAP *ld, Sockbuf *sb,
|
|||||||
async);
|
async);
|
||||||
|
|
||||||
if ( (rc == 0) || (rc == -2) ) {
|
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 )
|
if ( i )
|
||||||
rc = i;
|
rc = i;
|
||||||
else
|
else
|
||||||
|
@ -319,11 +319,12 @@ sendcred:
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
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;
|
struct sockaddr_un server;
|
||||||
ber_socket_t s;
|
ber_socket_t s;
|
||||||
int rc;
|
int rc;
|
||||||
|
const char *path = srv->lud_host;
|
||||||
|
|
||||||
oslocal_debug(ld, "ldap_connect_to_path\n",0,0,0);
|
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) {
|
if (rc == 0) {
|
||||||
int err;
|
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 )
|
if ( err )
|
||||||
rc = err;
|
rc = err;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user