]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/tls.c
Don't pass NULL hostname to ldap_pvt_tls_check_hostname, use "localhost"
[openldap] / libraries / libldap / tls.c
index c4a683edc26f6ba33f22e18cf34e9d626fad2c8b..97db901a5e94bd0844e36eb5648674bdc73cb087 100644 (file)
@@ -866,13 +866,13 @@ ldap_int_tls_config( LDAP *ld, int option, const char *arg )
        case LDAP_OPT_X_TLS_CERTFILE:
        case LDAP_OPT_X_TLS_KEYFILE:
        case LDAP_OPT_X_TLS_RANDOM_FILE:
-               return ldap_pvt_tls_set_option( NULL, option, (void *) arg );
+               return ldap_pvt_tls_set_option( ld, option, (void *) arg );
 
        case LDAP_OPT_X_TLS_REQUIRE_CERT:
                i = ( ( strcasecmp( arg, "on" ) == 0 ) ||
                      ( strcasecmp( arg, "yes" ) == 0) ||
                      ( strcasecmp( arg, "true" ) == 0 ) );
-               return ldap_pvt_tls_set_option( NULL, option, (void *) &i );
+               return ldap_pvt_tls_set_option( ld, option, (void *) &i );
 
        case LDAP_OPT_X_TLS:
                i = -1;
@@ -1046,10 +1046,8 @@ int
 ldap_int_tls_start ( LDAP *ld, LDAPConn *conn, LDAPURLDesc *srv )
 {
        Sockbuf *sb = conn->lconn_sb;
-       void *ctx = ld->ld_defconn->lconn_tls_ctx;
        char *host;
        void *ssl;
-       int ret;
 
        if( srv ) {
                host = srv->lud_host;
@@ -1063,19 +1061,23 @@ ldap_int_tls_start ( LDAP *ld, LDAPConn *conn, LDAPURLDesc *srv )
         * Fortunately, the lib uses blocking io...
         */
        if ( ldap_int_tls_connect( ld, conn ) < 0 ) {
-               return LDAP_CONNECT_ERROR;
+               ld->ld_errno = LDAP_CONNECT_ERROR;
+               return (ld->ld_errno);
        }
 
        ssl = (void *) ldap_pvt_tls_sb_ctx( sb );
        assert( ssl != NULL );
 
        /* 
-        * compare host with name(s) in certificate 
+        * compare host with name(s) in certificate. avoid NULL host
         */
 
-       ret = ldap_pvt_tls_check_hostname( ssl, host );
-       if (ret != LDAP_SUCCESS)
-               return ret;
+       if( host == NULL )
+               host = "localhost";
+       ld->ld_errno = ldap_pvt_tls_check_hostname( ssl, host );
+       if (ld->ld_errno != LDAP_SUCCESS) {
+               return ld->ld_errno;
+       }
 
        /*
         * set SASL properties to TLS ssf and authid
@@ -1088,7 +1090,7 @@ ldap_int_tls_start ( LDAP *ld, LDAPConn *conn, LDAPURLDesc *srv )
                ssf = ldap_pvt_tls_get_strength( ssl );
                authid = ldap_pvt_tls_get_peer( ssl );
 
-               (void) ldap_int_sasl_external( ld, authid, ssf );
+               (void) ldap_int_sasl_external( ld, conn, authid, ssf );
        }
 
        return LDAP_SUCCESS;