diff --git a/network.h b/network.h index 10118210..afeb4347 100644 --- a/network.h +++ b/network.h @@ -304,7 +304,7 @@ struct iploop { void* child; // void* thread; }; -int map_ip_to_loopback(struct iploop *ipl, char** addr, int n, bool tia_portal); +int map_ip_to_loopback(struct iploop *ipl, char** addr, int n, char** addrTia, int nTia); int unmap_ip_from_loopback(struct iploop* ipl); #endif diff --git a/ssh.c b/ssh.c index 75980256..683cf9ae 100644 --- a/ssh.c +++ b/ssh.c @@ -881,8 +881,6 @@ static const char *ssh_init(Seat *seat, Backend **backend_handle, const char *p; Ssh *ssh; - bool tia_portal = false; - ssh = snew(Ssh); memset(ssh, 0, sizeof(Ssh)); @@ -912,9 +910,11 @@ static const char *ssh_init(Seat *seat, Backend **backend_handle, /* Map IP to loopback if SSH tunnel flag set. */ if (conf_get_bool(ssh->conf, CONF_lport_loopback)) { int nbAddr = 0; + int nbTia = 0; char* key, *val; bool addr_limit_reached = false; char *loopback_addr[MAX_IPLOOP_ADDR]; + char *tia_addr[MAX_IPLOOP_ADDR]; for (val = conf_get_str_strs(ssh->conf, CONF_portfwd, NULL, &key); val != NULL; val = conf_get_str_strs(ssh->conf, CONF_portfwd, key, &key)) { @@ -922,6 +922,8 @@ static const char *ssh_init(Seat *seat, Backend **backend_handle, char address_family, type; char *saddr; + bool tia_portal = false; + kp = key; address_family = 'A'; @@ -957,22 +959,37 @@ static const char *ssh_init(Seat *seat, Backend **backend_handle, addr_limit_reached = true; } if (nbAddr < MAX_IPLOOP_ADDR) { + char * saddr_tia = saddr; bool already_in = false; for (int idx = 0; idx < nbAddr; idx++) { if (nullstrcmp(loopback_addr[idx], saddr) == 0) { already_in = true; + saddr_tia = loopback_addr[idx]; } } if (!already_in) { loopback_addr[nbAddr++] = saddr; } + else + { + sfree(saddr); + } + + if (tia_portal) + { + tia_addr[nbTia++] = saddr_tia; + } } } } - if (map_ip_to_loopback(&ssh->ipl, loopback_addr, nbAddr, tia_portal) != 0) { + if (map_ip_to_loopback(&ssh->ipl, loopback_addr, nbAddr, tia_addr, nbTia) != 0) { seat_connection_fatal(ssh->seat, "Cannot map IP(s) to loopback"); } + + for (int idx = 0; idx < nbAddr; idx++) { + sfree(loopback_addr[idx]); + } } p = connect_to_host(ssh, host, port, realhost, nodelay, keepalive); diff --git a/windows/VS2015-WAB/iploop/iploop.cpp b/windows/VS2015-WAB/iploop/iploop.cpp index a0d46a17..309f6eae 100644 --- a/windows/VS2015-WAB/iploop/iploop.cpp +++ b/windows/VS2015-WAB/iploop/iploop.cpp @@ -58,6 +58,29 @@ bool RaiseEndEvent(LPCTSTR lpszBaseEventName, LPCTSTR lpszMsgBoxTitle) return true; } + +std::vector STRSplitIntoVector(_In_ LPCTSTR lpsz, + _In_ LPCTSTR lpszDelimit) +{ + tstring str = lpsz; + + std::vector ret; + + if (lpsz && lpszDelimit) + { + LPTSTR lpszNextToken = nullptr; + LPTSTR lpszToken = ::_tcstok_s(&str.front(), lpszDelimit, &lpszNextToken); + while (lpszToken) + { + ret.push_back(lpszToken); + lpszToken = ::_tcstok_s(nullptr, lpszDelimit, &lpszNextToken); + } // while (lpszToken) + } // if (lpsz && lpszDelimit) + + return ret; +} // std::vector STRSplitIntoVector(_In_ LPCTSTR lpsz, + // _In_ LPCTSTR lpszDelimit) + int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPTSTR lpCmdLine, @@ -67,6 +90,7 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, // TODO: Place code here. OutputDebugString(lpCmdLine); + OutputDebugString(TEXT("\n")); // Initialize global strings LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); @@ -77,8 +101,9 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, MessageBox(NULL, _T("Cannot parse command line!"), szTitle, MB_ICONERROR | MB_OK); return FALSE; } - if (nArgs < 2) { - MessageBox(NULL, _T("iploop event_name ip1 [ip2 [...]] [/tia] [/parent process_id] [/window parent_wnd] [/begin-standalone | /end-standalone]"), szTitle, MB_ICONERROR | MB_OK); + if (nArgs < 3) { + MessageBox(NULL, _T("iploop.exe event_name addr1,[addr2[,...]] [/service name,port,addr1[,addr2[,...]] [/parent process_id] [/window parent_wnd] [/begin-standalone | /end-standalone]"), szTitle, MB_ICONERROR | MB_OK); + LocalFree(szArglistW); return FALSE; } @@ -86,7 +111,16 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, parameters.strEventNameBase = szArglistW[0]; parameters.dwGUIThreadId = GetCurrentThreadId(); - for (int i = 1; i < nArgs; ++i) + { + std::vector ips = STRSplitIntoVector(szArglistW[1], _T(",")); + + for (tstring& ip : ips) + { + parameters.vecstrIPs.emplace_back(std::move(ip)); + } + } + + for (int i = 2; i < nArgs; ++i) { if (!lstrcmpi(szArglistW[i], L"/begin-standalone")) { @@ -116,11 +150,39 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, return FALSE; } } - else if (!lstrcmpi(szArglistW[i], L"/tia")) + else if (StrStrI(szArglistW[i], L"/service") == szArglistW[i]) { - OutputDebugStringW(L"_tWinMain(): Enable TIA portal support."); + if (i < nArgs - 1) + { + ++i; + + std::vector items = STRSplitIntoVector(szArglistW[i], _T(",")); + + if (items.size() < 2) + { + MessageBox(NULL, _T("Please provide name and IP port of service!"), szTitle, MB_ICONERROR | MB_OK); + LocalFree(szArglistW); + return FALSE; + } + + std::vector vecstrServiceIPs; + + for (int i = 2, c = items.size(); i < c; i++) + { + vecstrServiceIPs.emplace_back(std::move(items[i])); + } - parameters.bTiaPortalSupport = true; + parameters.spService = std::make_unique(); + parameters.spService->strName = std::move(items[0]); + parameters.spService->usPort = _ttoi(items[1].c_str()); + parameters.spService->vecstrIPs = std::move(vecstrServiceIPs); + } + else + { + MessageBox(NULL, _T("Please provide service parameters!"), szTitle, MB_ICONERROR | MB_OK); + LocalFree(szArglistW); + return FALSE; + } } else if (!lstrcmpi(szArglistW[i], L"/window")) { @@ -132,7 +194,7 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, DWORD dwParentWnd = 0; iss >> dwParentWnd; hwndParent = reinterpret_cast(dwParentWnd); - } + } else { MessageBox(NULL, _T("Please provide handle of parent window!"), szTitle, MB_ICONERROR | MB_OK); @@ -149,9 +211,14 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, LocalFree(szArglistW); return FALSE; } - else if (std::find(parameters.vecstrIPs.begin(), parameters.vecstrIPs.end(), szArglistW[i]) == parameters.vecstrIPs.end()) + else { - parameters.vecstrIPs.emplace_back(szArglistW[i]); + std::wstring strMessageW; + strMessageW = L"Unknown command-line parameter: "; + strMessageW += szArglistW[i]; + MessageBoxW(NULL, strMessageW.c_str(), szTitle, MB_ICONERROR | MB_OK); + LocalFree(szArglistW); + return FALSE; } } diff --git a/windows/VS2015-WAB/iploop/iploop.h b/windows/VS2015-WAB/iploop/iploop.h index 6e24aae9..c684b15f 100644 --- a/windows/VS2015-WAB/iploop/iploop.h +++ b/windows/VS2015-WAB/iploop/iploop.h @@ -2,13 +2,32 @@ #include "resource.h" +#if defined(_UNICODE) || defined(UNICODE) + +using tstring = std::wstring; + +#else // #if defined(_UNICODE) || defined(UNICODE) + +using tstring = std::string; + +#endif // #if defined(_UNICODE) || defined(UNICODE) + +struct ManagedService +{ + tstring strName; + + unsigned short usPort = 0; + + std::vector vecstrIPs; +}; + struct IPLoopThreadParameter { std::wstring strEventNameBase; std::vector vecstrIPs; - bool bTiaPortalSupport = false; + std::unique_ptr spService; HANDLE hParentProcess = NULL; diff --git a/windows/VS2015-WAB/iploop/iploop.vcxproj b/windows/VS2015-WAB/iploop/iploop.vcxproj index b0257585..d9e94d54 100644 --- a/windows/VS2015-WAB/iploop/iploop.vcxproj +++ b/windows/VS2015-WAB/iploop/iploop.vcxproj @@ -91,12 +91,12 @@ Level3 true _CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) - true + false Windows true - Iphlpapi.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;psapi.lib;%(AdditionalDependencies) + Iphlpapi.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;psapi.lib;shlwapi.lib;%(AdditionalDependencies) RequireAdministrator @@ -127,7 +127,7 @@ true true _CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) - true + false MultiThreaded @@ -135,7 +135,7 @@ true true true - Iphlpapi.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;psapi.lib;%(AdditionalDependencies) + Iphlpapi.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;psapi.lib;shlwapi.lib;%(AdditionalDependencies) RequireAdministrator diff --git a/windows/VS2015-WAB/iploop/iploop_thread.cpp b/windows/VS2015-WAB/iploop/iploop_thread.cpp index b3c1aed2..8e2dd378 100644 --- a/windows/VS2015-WAB/iploop/iploop_thread.cpp +++ b/windows/VS2015-WAB/iploop/iploop_thread.cpp @@ -6,6 +6,7 @@ // Windows Header Files #include +#include #include #include #include @@ -35,9 +36,9 @@ static const wchar_t* appname = L"WALLIX PuTYY IP Loopback Manager"; //static char szSvcLocalAddressAndPortA[] = "0.0.0.0:102"; static TCHAR szSvcLocalAddress[] = _T("0.0.0.0"); -static unsigned short usSvcLocalPort = 102; +//static unsigned short usSvcLocalPort = 102; -static wchar_t szSvcNameW[] = L"s7oiehsx64"; +//static wchar_t szSvcNameW[] = L"s7oiehsx64"; /* class ListeningPortPresenceChecker @@ -248,38 +249,21 @@ class ListeningPortPresenceChecker }; */ -#if defined(_UNICODE) || defined(UNICODE) - -using tstring = std::wstring; - -#else // #if defined(_UNICODE) || defined(UNICODE) - -using tstring = std::string; - -#endif // #if defined(_UNICODE) || defined(UNICODE) - class ListeningPortPresenceChecker2 { - tstring m_strLocalAddress; - - unsigned short m_usLocalPort = 0; + std::vector& m_rstrvecLocalAddresses; - bool m_bIsListeningPortFound = false; + unsigned short const m_usLocalPort; public: - ListeningPortPresenceChecker2(LPCTSTR pszLocalAddress, unsigned short usLocalPort) : - m_strLocalAddress(pszLocalAddress), m_usLocalPort(usLocalPort) {} + ListeningPortPresenceChecker2(std::vector& rvecstrLocalAddresses, unsigned short usLocalPort) : + m_rstrvecLocalAddresses(rvecstrLocalAddresses), m_usLocalPort(usLocalPort) {} bool IsInProgress() const { return false; } - bool IsListeningPortFound() const - { - return m_bIsListeningPortFound; - } - private: static TCHAR * rep_inet_ntoa(struct in_addr ina, TCHAR * out_buf, @@ -298,8 +282,8 @@ class ListeningPortPresenceChecker2 static void STRTrimTrailingNullCharacters(_Inout_ tstring& rstr) { - size_t const ulPos = rstr.find_last_not_of(_T('\0')); - rstr.resize((std::string::npos == ulPos) ? 0 : ulPos + 1); + size_t const ulPos = _tcslen(rstr.c_str()); + rstr.resize(ulPos); } // void STRTrimTrailingNullCharacters(_Inout_ tstring& rstr) static LPCTSTR NETGetTCPConnectionStateName(_In_ DWORD dwState) @@ -433,18 +417,33 @@ class ListeningPortPresenceChecker2 continue; case MIB_TCP_STATE_LISTEN: - if (!m_strLocalAddress.compare(local_address) && - htons((unsigned short)MIB_TCPRow_Owner_PID.dwLocalPort) == m_usLocalPort) + if (htons((unsigned short)MIB_TCPRow_Owner_PID.dwLocalPort) == m_usLocalPort) { - m_bIsListeningPortFound = true; + m_rstrvecLocalAddresses.erase(std::remove_if( + m_rstrvecLocalAddresses.begin(), + m_rstrvecLocalAddresses.end(), + [local_address, this](tstring& rstrLocalAddress) { + bool retval = rstrLocalAddress.compare(local_address) == 0; + + if (retval) + { + ::SendLogLine( + _T("ListeningPortPresenceChecker2::Start(): ") + _T("Listening port found: %s:%u"), + local_address.c_str(), m_usLocalPort); + } + + return retval; + } + ), m_rstrvecLocalAddresses.end()); } /* - else { + for (auto rstrLocalAddress : m_rstrvecLocalAddresses) { ::SendLogLine( _T("ListeningPortPresenceChecker2::Start(): ") _T("ExpectedAddr=%s GotAddr=%s ") _T("ExpectedPort=%u GotPort=%u"), - m_strLocalAddress.c_str(), local_address.c_str(), + rstrLocalAddress.c_str(), local_address.c_str(), m_usLocalPort, htons((unsigned short)MIB_TCPRow_Owner_PID.dwLocalPort)); } */ @@ -474,7 +473,7 @@ class ListeningPortPresenceChecker2 } }; -VOID __stdcall DoStartSvc() +VOID __stdcall DoStartSvc(LPCTSTR lpszServiceName) { SERVICE_STATUS_PROCESS ssStatus; DWORD dwOldCheckPoint; @@ -499,7 +498,7 @@ VOID __stdcall DoStartSvc() SC_HANDLE schService = OpenServiceW( schSCManager, // SCM database - szSvcNameW, // name of service + lpszServiceName, // name of service SERVICE_ALL_ACCESS); // full access if (schService == NULL) @@ -782,7 +781,7 @@ BOOL __stdcall StopDependentServices(SC_HANDLE schSCManager, SC_HANDLE schServic return TRUE; } -VOID __stdcall DoStopSvc() +VOID __stdcall DoStopSvc(LPCTSTR lpszServiceName) { SERVICE_STATUS_PROCESS ssp; DWORD dwStartTime = GetTickCount(); @@ -807,7 +806,7 @@ VOID __stdcall DoStopSvc() SC_HANDLE schService = OpenService( schSCManager, // SCM database - szSvcNameW, // name of service + lpszServiceName, // name of service SERVICE_STOP | SERVICE_QUERY_STATUS | SERVICE_ENUMERATE_DEPENDENTS); @@ -942,7 +941,7 @@ int WINAPI_wWinMain(IPLoopThreadParameter const* const lpThreadParameters) { } ULONG* NTEContexts = (ULONG*)HeapAlloc(heap, HEAP_GENERATE_EXCEPTIONS, sizeof(ULONG) * lpThreadParameters->vecstrIPs.size()); if (NULL == NTEContexts) { - SendLogLine(L"IPLoopMain(): Cannot allocate NTE Contexts! LastError=0x%X", GetLastError()); + SendLogLine(L"IPLoopMain(): Cannot allocate NTE Contexts! LastError=0x%X", GetLastError()); return 1; } @@ -1005,11 +1004,11 @@ int WINAPI_wWinMain(IPLoopThreadParameter const* const lpThreadParameters) { class ServiceGuard { public: - ServiceGuard() + ServiceGuard(LPCTSTR lpszServiceName) : m_strServiceName(lpszServiceName) { ::SendLogLine(L"ServiceGuard::ServiceGuard(): Stop service ..."); - ::DoStopSvc(); + ::DoStopSvc(m_strServiceName.c_str()); ::SendLogLine(L"ServiceGuard::ServiceGuard(): Stop service done."); } @@ -1018,20 +1017,25 @@ int WINAPI_wWinMain(IPLoopThreadParameter const* const lpThreadParameters) { { ::SendLogLine(L"ServiceGuard::~ServiceGuard(): Start service ..."); - ::DoStartSvc(); + ::DoStartSvc(m_strServiceName.c_str()); ::SendLogLine(L"ServiceGuard::~ServiceGuard(): Start service done."); } + + private: + tstring const m_strServiceName; }; std::unique_ptr service_guard_sp; - if (lpThreadParameters->bTiaPortalSupport) + + if (lpThreadParameters->spService && !lpThreadParameters->spService->vecstrIPs.empty()) { SendLogLine(L"IPLoopMain(): Check the presence of the service local address ..."); // ListeningPortPresenceChecker listening_port_presence_checker(szSvcLocalAddressAndPortA); - ListeningPortPresenceChecker2 listening_port_presence_checker(szSvcLocalAddress, usSvcLocalPort); + std::vector vecstrSvcLocalAddressesCP({ szSvcLocalAddress }); + ListeningPortPresenceChecker2 listening_port_presence_checker(vecstrSvcLocalAddressesCP, lpThreadParameters->spService->usPort); listening_port_presence_checker.Start(); while (listening_port_presence_checker.IsInProgress()) @@ -1039,18 +1043,19 @@ int WINAPI_wWinMain(IPLoopThreadParameter const* const lpThreadParameters) { Sleep(1000); listening_port_presence_checker.CheckResult(); } - if (listening_port_presence_checker.IsListeningPortFound()) + if (vecstrSvcLocalAddressesCP.empty()) { SendLogLine(L"IPLoopMain(): The service local address is present."); - service_guard_sp = std::make_unique(); + service_guard_sp = std::make_unique(lpThreadParameters->spService->strName.c_str()); SendLogLine(L"IPLoopMain(): Check the nonpresence of the service local address ..."); while (true) { // ListeningPortPresenceChecker listening_port_nonpresence_checker(szSvcLocalAddressAndPortA); - ListeningPortPresenceChecker2 listening_port_nonpresence_checker(szSvcLocalAddress, usSvcLocalPort); + std::vector vecstrSvcLocalAddressesCNP({ szSvcLocalAddress }); + ListeningPortPresenceChecker2 listening_port_nonpresence_checker(vecstrSvcLocalAddressesCNP, lpThreadParameters->spService->usPort); listening_port_nonpresence_checker.Start(); while (listening_port_nonpresence_checker.IsInProgress()) @@ -1058,7 +1063,7 @@ int WINAPI_wWinMain(IPLoopThreadParameter const* const lpThreadParameters) { Sleep(1000); listening_port_nonpresence_checker.CheckResult(); } - if (!listening_port_nonpresence_checker.IsListeningPortFound()) + if (!vecstrSvcLocalAddressesCNP.empty()) { SendLogLine(L"IPLoopMain(): The local address of the service is no longer present."); @@ -1072,13 +1077,14 @@ int WINAPI_wWinMain(IPLoopThreadParameter const* const lpThreadParameters) { } } - tstring strWALLIXPuTTYLocalAddress; +// std::vector strWALLIXPuTTYLocalAddresses; - std::string strWALLIXPuTTYLocalAddressAndPortA; +// std::string strWALLIXPuTTYLocalAddressAndPortA; for (size_t i = 0; i < lpThreadParameters->vecstrIPs.size(); i++) { SendLogLine(L"IPLoopMain(): Hostname=\"%s\" (%d)", lpThreadParameters->vecstrIPs[i].c_str(), i); +/* if (service_guard_sp) { SendLogLine(L"IPLoopMain(): Generate WALLIX-PuTTY local address."); @@ -1095,6 +1101,7 @@ int WINAPI_wWinMain(IPLoopThreadParameter const* const lpThreadParameters) { SendLogLine(L"IPLoopMain(): WALLIXPuTTYLocalAddress=\"%s\"", strWALLIXPuTTYLocalAddressAndPortW.c_str()); } +*/ PADDRINFOW resAddr; DWORD ret = GetAddrInfoW(lpThreadParameters->vecstrIPs[i].c_str(), NULL, &hints, &resAddr); @@ -1125,7 +1132,7 @@ int WINAPI_wWinMain(IPLoopThreadParameter const* const lpThreadParameters) { CloseHandle(event_p2i); SendLogLine(L"IPLoopMain(): IP address is already mapped to loopback interface!"); } - else + else { unmap(NTEContexts, nbContexts); if (event_i2p) { @@ -1145,6 +1152,8 @@ int WINAPI_wWinMain(IPLoopThreadParameter const* const lpThreadParameters) { SendLogLine(L"IPLoopMain(): Wait for event (P2I) ..."); + std::vector vecstrExpectedTiaIPs = lpThreadParameters->spService->vecstrIPs; + while (true) { if (service_guard_sp) @@ -1152,7 +1161,7 @@ int WINAPI_wWinMain(IPLoopThreadParameter const* const lpThreadParameters) { SendLogLine(L"IPLoopMain(): Check the presence of the WALLIX-PuTTY local address ..."); // ListeningPortPresenceChecker listening_port_presence_checker(strWALLIXPuTTYLocalAddressAndPortA.c_str()); - ListeningPortPresenceChecker2 listening_port_presence_checker(strWALLIXPuTTYLocalAddress.c_str(), 102); + ListeningPortPresenceChecker2 listening_port_presence_checker(vecstrExpectedTiaIPs, 102); listening_port_presence_checker.Start(); while (listening_port_presence_checker.IsInProgress()) @@ -1160,25 +1169,37 @@ int WINAPI_wWinMain(IPLoopThreadParameter const* const lpThreadParameters) { Sleep(1000); listening_port_presence_checker.CheckResult(); } - if (listening_port_presence_checker.IsListeningPortFound()) + if (vecstrExpectedTiaIPs.empty()) { - SendLogLine(L"IPLoopMain(): The WALLIX-PuTTY local address is present."); + SendLogLine(L"IPLoopMain(): The WALLIX-PuTTY local addresses are present."); service_guard_sp.reset(nullptr); } else { - SendLogLine(L"IPLoopMain(): The WALLIX-PuTTY local address is not present."); + Sleep(1000); } } - DWORD const dwWaitResult = WaitForSingleObject(event_p2i, 1000); + DWORD dwHandleCount = 1; + HANDLE Handles[2]{ event_p2i }; + if (lpThreadParameters->hParentProcess) { + Handles[dwHandleCount++] = lpThreadParameters->hParentProcess; + } +// DWORD const dwWaitResult = WaitForSingleObject(event_p2i, 1000); + DWORD const dwWaitResult = WaitForMultipleObjects(dwHandleCount, Handles, FALSE, 1000); if (WAIT_OBJECT_0 == dwWaitResult) { SendLogLine(L"IPLoopMain(): Event (P2I) signaled."); break; } + if (WAIT_OBJECT_0 + 1 == dwWaitResult) + { + SendLogLine(L"IPLoopMain(): Parent process exited."); + + break; + } else if (WAIT_TIMEOUT != dwWaitResult) { SendLogLine(L"IPLoopMain(): Event (P2I) not signaled!", GetLastError()); diff --git a/windows/VS2015-WAB/iploop/stdafx.h b/windows/VS2015-WAB/iploop/stdafx.h index 450d3945..2b49c7f5 100644 --- a/windows/VS2015-WAB/iploop/stdafx.h +++ b/windows/VS2015-WAB/iploop/stdafx.h @@ -11,6 +11,8 @@ // Windows Header Files: #include #include +#include + // C RunTime Header Files #include diff --git a/windows/winnet.c b/windows/winnet.c index 4c2bb263..3840d3a3 100644 --- a/windows/winnet.c +++ b/windows/winnet.c @@ -1918,7 +1918,7 @@ int unmap_ip_from_loopback(struct iploop *ipl) { return ret == FALSE; } -int map_ip_to_loopback(struct iploop *ipl, char** addr, int n, bool tia_portal) { +int map_ip_to_loopback(struct iploop *ipl, char** addr, int n, char** addrTia, int nTia) { OutputDebugStringW(L"map_ip_to_loopback(): ..."); @@ -1991,15 +1991,16 @@ int map_ip_to_loopback(struct iploop *ipl, char** addr, int n, bool tia_portal) #define MAX_HOSTNAME 255 + wchar_t szServiceNamePort[] = L" /service s7oiehsx64,102,"; + size_t size = wcslen(eventNameBase); for (int i = 0; i < n; i++) { size += 1 + /*strlen(addr[i])*/MAX_HOSTNAME; } size += 1; - if (tia_portal) - { - size += 5; // "/tia" - } + + size += _tcslen(szServiceNamePort) + nTia * (1 + MAX_HOSTNAME); + size += 1; BOOL bWALLIX_UT_DEBUG = FALSE; { @@ -2022,8 +2023,11 @@ int map_ip_to_loopback(struct iploop *ipl, char** addr, int n, bool tia_portal) wchar_t *szCmdline = (wchar_t *)malloc((size + 256) * sizeof(wchar_t)); wcscpy(szCmdline, eventNameBase); - for (int i = 0; i < n; i++) { - wcscat(szCmdline, L" "); + wcscat(szCmdline, L" "); + for (int i = 0; i < n; i++) { + if (i) { + wcscat(szCmdline, L","); + } wchar_t tmpaddr[MAX_HOSTNAME] = { 0 }; if (MultiByteToWideChar(CP_ACP, 0, addr[i], -1, tmpaddr, _countof(tmpaddr)) == 0) { DWORD err = GetLastError(); @@ -2033,10 +2037,21 @@ int map_ip_to_loopback(struct iploop *ipl, char** addr, int n, bool tia_portal) wcscat(szCmdline, tmpaddr); } - if (tia_portal) - { - wcscat(szCmdline, L" /tia"); - } + for (int i = 0; i < nTia; i++) { + if (i) { + wcscat(szCmdline, L","); + } + else { + wcscat(szCmdline, szServiceNamePort); + } + wchar_t tmpaddr[MAX_HOSTNAME] = { 0 }; + if (MultiByteToWideChar(CP_ACP, 0, addrTia[i], -1, tmpaddr, _countof(tmpaddr)) == 0) { + DWORD err = GetLastError(); + free(szCmdline); + return err; + } + wcscat(szCmdline, tmpaddr); + } if (bWALLIX_UT_DEBUG) { @@ -2061,7 +2076,7 @@ int map_ip_to_loopback(struct iploop *ipl, char** addr, int n, bool tia_portal) } SHELLEXECUTEINFOW ShellExecuteInfoW; - + ZeroMemory(&ShellExecuteInfoW, sizeof(ShellExecuteInfoW)); ShellExecuteInfoW.cbSize = sizeof(ShellExecuteInfoW); @@ -2073,7 +2088,7 @@ int map_ip_to_loopback(struct iploop *ipl, char** addr, int n, bool tia_portal) ShellExecuteInfoW.lpDirectory = dirName; ShellExecuteInfoW.nShow = SW_SHOWNA; - // Create the child process. + // Create the child process. ShellExecuteExW(&ShellExecuteInfoW); DWORD err = ShellExecuteInfoW.hInstApp; if (err < 32) {