break;
}
-#ifdef HAVE_CYRUS_SASL
- if( sasl_host != NULL ) {
- ldap_int_sasl_open( ld, conn, sasl_host, sasl_ssf );
- }
-#endif
-
ber_sockbuf_add_io( conn->lconn_sb, &ber_sockbuf_io_readahead,
LBER_SBIOD_LEVEL_PROVIDER, NULL );
{
++conn->lconn_refcnt; /* avoid premature free */
- rc = ldap_int_tls_start( ld, conn );
+ rc = ldap_int_tls_start( ld, conn, srv );
--conn->lconn_refcnt;
}
#endif
+#ifdef HAVE_CYRUS_SASL
+ if( sasl_host != NULL ) {
+ ldap_int_sasl_open( ld, conn, sasl_host, sasl_ssf );
+ }
+#endif
+
#ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
if ( conn->lconn_krbinstance == NULL ) {
char *c;
if ( ctx_arg ) {
ctx = (SSL_CTX *) ctx_arg;
} else {
- if ( ldap_pvt_tls_init_def_ctx() < 0 )
- return NULL;
+ if ( ldap_pvt_tls_init_def_ctx() < 0 ) return NULL;
ctx = tls_def_ctx;
}
ldap_int_tls_connect( LDAP *ld, LDAPConn *conn )
{
Sockbuf *sb = conn->lconn_sb;
- void *ctx = ld->ld_defconn->lconn_tls_ctx;
-
int err;
SSL *ssl;
if ( HAS_TLS( sb ) ) {
ber_sockbuf_ctrl( sb, LBER_SB_OPT_GET_SSL, (void *)&ssl );
+
} else {
+ void *ctx = ld->ld_defconn
+ ? ld->ld_defconn->lconn_tls_ctx : NULL;
+
ssl = alloc_handle( ctx );
- if ( ssl == NULL )
- return -1;
+
+ if ( ssl == NULL ) return -1;
+
#ifdef LDAP_DEBUG
ber_sockbuf_add_io( sb, &ber_sockbuf_io_debug,
LBER_SBIOD_LEVEL_TRANSPORT, (void *)"tls_" );
#endif
ber_sockbuf_add_io( sb, &ldap_pvt_sockbuf_io_tls,
LBER_SBIOD_LEVEL_TRANSPORT, (void *)ssl );
+
+ if( ctx == NULL ) {
+ conn->lconn_tls_ctx = tls_def_ctx;
+ }
}
err = SSL_connect( ssl );
errno = WSAGetLastError();
#endif
if ( err <= 0 ) {
- if ( update_flags( sb, ssl, err ))
+ if ( update_flags( sb, ssl, err )) {
return 1;
+ }
if ((err = ERR_peek_error())) {
char buf[256];
ld->ld_error = LDAP_STRDUP(ERR_error_string(err, buf));
#endif
return -1;
}
+
return 0;
}
}
int
-ldap_int_tls_start ( LDAP *ld, LDAPConn *conn )
+ldap_int_tls_start ( LDAP *ld, LDAPConn *conn, LDAPURLDesc *srv )
{
Sockbuf *sb = conn->lconn_sb;
- char *host = conn->lconn_server->lud_host;
void *ctx = ld->ld_defconn->lconn_tls_ctx;
-
+ char *host;
char *peer_cert_cn;
void *ssl;
+ if( srv ) {
+ host = srv->lud_host;
+ } else {
+ host = conn->lconn_server->lud_host;
+ }
+
(void) ldap_pvt_tls_init();
/*
ber_bvfree( rspdata );
}
- rc = ldap_int_tls_start( ld, ld->ld_defconn );
+ rc = ldap_int_tls_start( ld, ld->ld_defconn, NULL );
#else
rc = LDAP_NOT_SUPPORTED;
#endif