From 3583b4b5de1fe99daf30c733ab49f1b602a8aef7 Mon Sep 17 00:00:00 2001 From: imaginos Date: Wed, 2 Apr 2008 16:15:24 +0000 Subject: [PATCH] fix state bug when connecting to a remote host thats ssl, results from a hostname that resolves to multiple ip's git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1013 726aef4b-f618-498e-8847-2d620e286838 --- Csocket.cpp | 13 ++++++++++--- Csocket.h | 12 ++++++++---- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/Csocket.cpp b/Csocket.cpp index 4089be6f..c7072105 100644 --- a/Csocket.cpp +++ b/Csocket.cpp @@ -28,7 +28,7 @@ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * -* $Revision: 1.78 $ +* $Revision: 1.79 $ */ #include "Csocket.h" @@ -654,6 +654,10 @@ bool Csock::Connect( const CS_STRING & sBindHost, bool bSkipSetup ) { if( m_bSkipConnect ) { // this was already called, so skipping now. this is to allow easy pass through + if ( m_eConState != CST_OK ) + { + m_eConState = ( GetSSL() ? CST_CONNECTSSL : CST_OK ); + } return( true ); } // bind to a hostname if requested @@ -725,7 +729,9 @@ bool Csock::Connect( const CS_STRING & sBindHost, bool bSkipSetup ) } if ( m_eConState != CST_OK ) - m_eConState = CST_OK; + { + m_eConState = ( GetSSL() ? CST_CONNECTSSL : CST_OK ); + } return( true ); } @@ -1114,7 +1120,6 @@ bool Csock::ConnectSSL( const CS_STRING & sBindhost ) if ( m_iReadSock == -1 ) if ( !Connect( sBindhost ) ) return( false ); - if ( !m_ssl ) if ( !SSLClientSetup() ) return( false ); @@ -1142,6 +1147,8 @@ bool Csock::ConnectSSL( const CS_STRING & sBindhost ) set_blocking( m_iReadSock ); } + if ( m_eConState != CST_OK ) + m_eConState = CST_OK; return( bPass ); #else return( false ); diff --git a/Csocket.h b/Csocket.h index b733419e..2801be2b 100644 --- a/Csocket.h +++ b/Csocket.h @@ -28,7 +28,7 @@ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * -* $Revision: 1.189 $ +* $Revision: 1.190 $ */ // note to compile with win32 need to link to winsock2, using gcc its -lws2_32 @@ -464,7 +464,8 @@ public: CST_BINDVHOST = 1, CST_DESTDNS = 2, CST_CONNECT = 3, - CST_OK = 4 + CST_CONNECTSSL = 4, + CST_OK = 5 }; enum ECloseType @@ -1369,6 +1370,7 @@ public: if ( pcSock->GetConState() == T::CST_DESTDNS ) { + if ( !pcSock->SetupVHost() ) if ( pcSock->DNSLookup( T::DNS_DEST ) == ETIMEDOUT ) { pcSock->SockError( EADDRNOTAVAIL ); @@ -1376,7 +1378,6 @@ public: continue; } } - if ( pcSock->GetConState() == T::CST_CONNECT ) { if ( !pcSock->Connect( pcSock->GetBindHost(), true ) ) @@ -1389,7 +1390,10 @@ public: DelSock( a-- ); continue; } + } #ifdef HAVE_LIBSSL + if( pcSock->GetConState() == T::CST_CONNECTSSL ) + { if ( pcSock->GetSSL() ) { if ( !pcSock->ConnectSSL() ) @@ -1403,8 +1407,8 @@ public: continue; } } -#endif /* HAVE_LIBSSL */ } +#endif /* HAVE_LIBSSL */ } std::map mpeSocks;