test_reuseaddr and test_exclusiveaddruse bind to the wildcard address (0.0.0.0 or [::]). This may trigger a firewall alert on Windows 7, and the alert UI window may interfere with user32:msg tests.
Fix this by trying to disable the firewall, and skipping the wildcard address tests if it fails.
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=53891 Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=54202
-- v2: ws2_32/tests: Try to disable firewall before testing with any addr. ws2_32/tests: Factor out test_exclusiveaddruse from test_reuseaddr. ws2_32/tests: Do ANY address tests in a separate loop in test_reuseaddr. webservices/tests: Move firewall code to a common header.
From: Hans Leidekker hans@codeweavers.com
--- dlls/webservices/tests/channel.c | 140 ++----------------------------- include/Makefile.in | 1 + include/wine/test_fw.h | 131 +++++++++++++++++++++++++++++ 3 files changed, 137 insertions(+), 135 deletions(-) create mode 100644 include/wine/test_fw.h
diff --git a/dlls/webservices/tests/channel.c b/dlls/webservices/tests/channel.c index 7e0a9becbc5..cecb766d63b 100644 --- a/dlls/webservices/tests/channel.c +++ b/dlls/webservices/tests/channel.c @@ -22,8 +22,8 @@ #include "winsock2.h" #include "webservices.h" #include "initguid.h" -#include "netfw.h" #include "wine/test.h" +#include "wine/test_fw.h"
static void test_WsCreateChannel(void) { @@ -1410,132 +1410,10 @@ static HANDLE start_listener( struct listener_info *info ) return thread; }
-enum firewall_op -{ - APP_ADD, - APP_REMOVE -}; - -static BOOL is_process_elevated(void) -{ - HANDLE token; - if (OpenProcessToken( GetCurrentProcess(), TOKEN_QUERY, &token )) - { - TOKEN_ELEVATION_TYPE type; - DWORD size; - BOOL ret; - - ret = GetTokenInformation( token, TokenElevationType, &type, sizeof(type), &size ); - CloseHandle( token ); - return (ret && type == TokenElevationTypeFull); - } - return FALSE; -} - -static BOOL is_firewall_enabled(void) -{ - HRESULT hr, init; - INetFwMgr *mgr = NULL; - INetFwPolicy *policy = NULL; - INetFwProfile *profile = NULL; - VARIANT_BOOL enabled = VARIANT_FALSE; - - init = CoInitializeEx( 0, COINIT_APARTMENTTHREADED ); - - hr = CoCreateInstance( &CLSID_NetFwMgr, NULL, CLSCTX_INPROC_SERVER, &IID_INetFwMgr, - (void **)&mgr ); - ok( hr == S_OK, "got %#lx\n", hr ); - if (hr != S_OK) goto done; - - hr = INetFwMgr_get_LocalPolicy( mgr, &policy ); - ok( hr == S_OK, "got %#lx\n", hr ); - if (hr != S_OK) goto done; - - hr = INetFwPolicy_get_CurrentProfile( policy, &profile ); - if (hr != S_OK) goto done; - - hr = INetFwProfile_get_FirewallEnabled( profile, &enabled ); - ok( hr == S_OK, "got %#lx\n", hr ); - -done: - if (policy) INetFwPolicy_Release( policy ); - if (profile) INetFwProfile_Release( profile ); - if (mgr) INetFwMgr_Release( mgr ); - if (SUCCEEDED( init )) CoUninitialize(); - return (enabled == VARIANT_TRUE); -} - -static HRESULT set_firewall( enum firewall_op op ) -{ - HRESULT hr, init; - INetFwMgr *mgr = NULL; - INetFwPolicy *policy = NULL; - INetFwProfile *profile = NULL; - INetFwAuthorizedApplication *app = NULL; - INetFwAuthorizedApplications *apps = NULL; - BSTR name, image = SysAllocStringLen( NULL, MAX_PATH ); - - if (!GetModuleFileNameW( NULL, image, MAX_PATH )) - { - SysFreeString( image ); - return E_FAIL; - } - init = CoInitializeEx( 0, COINIT_APARTMENTTHREADED ); - - hr = CoCreateInstance( &CLSID_NetFwMgr, NULL, CLSCTX_INPROC_SERVER, &IID_INetFwMgr, - (void **)&mgr ); - ok( hr == S_OK, "got %#lx\n", hr ); - if (hr != S_OK) goto done; - - hr = INetFwMgr_get_LocalPolicy( mgr, &policy ); - ok( hr == S_OK, "got %#lx\n", hr ); - if (hr != S_OK) goto done; - - hr = INetFwPolicy_get_CurrentProfile( policy, &profile ); - if (hr != S_OK) goto done; - - hr = INetFwProfile_get_AuthorizedApplications( profile, &apps ); - ok( hr == S_OK, "got %#lx\n", hr ); - if (hr != S_OK) goto done; - - hr = CoCreateInstance( &CLSID_NetFwAuthorizedApplication, NULL, CLSCTX_INPROC_SERVER, - &IID_INetFwAuthorizedApplication, (void **)&app ); - ok( hr == S_OK, "got %#lx\n", hr ); - if (hr != S_OK) goto done; - - hr = INetFwAuthorizedApplication_put_ProcessImageFileName( app, image ); - if (hr != S_OK) goto done; - - name = SysAllocString( L"webservices_test" ); - hr = INetFwAuthorizedApplication_put_Name( app, name ); - SysFreeString( name ); - ok( hr == S_OK, "got %#lx\n", hr ); - if (hr != S_OK) goto done; - - if (op == APP_ADD) - hr = INetFwAuthorizedApplications_Add( apps, app ); - else if (op == APP_REMOVE) - hr = INetFwAuthorizedApplications_Remove( apps, image ); - else - hr = E_INVALIDARG; - -done: - if (app) INetFwAuthorizedApplication_Release( app ); - if (apps) INetFwAuthorizedApplications_Release( apps ); - if (policy) INetFwPolicy_Release( policy ); - if (profile) INetFwProfile_Release( profile ); - if (mgr) INetFwMgr_Release( mgr ); - if (SUCCEEDED( init )) CoUninitialize(); - SysFreeString( image ); - return hr; -} - START_TEST(channel) { - BOOL firewall_enabled = is_firewall_enabled(); struct listener_info info; HANDLE thread; - HRESULT hr; unsigned int i; static const struct test { @@ -1558,18 +1436,10 @@ START_TEST(channel) { WS_TCP_CHANNEL_BINDING, WS_CHANNEL_TYPE_DUPLEX_SESSION, NULL, client_duplex_session_dict, listener_socket_proc, 4096 }, };
- if (firewall_enabled) + if (!winetest_set_firewall( L"webservices_test", WINETEST_FW_APP_ADD )) { - if (!is_process_elevated()) - { - skip( "no privileges, skipping tests to avoid firewall dialog\n" ); - return; - } - if ((hr = set_firewall( APP_ADD )) != S_OK) - { - skip( "can't authorize app in firewall %#lx\n", hr ); - return; - } + skip( "can't authorize app in firewall\n" ); + return; }
test_WsCreateChannel(); @@ -1598,5 +1468,5 @@ START_TEST(channel) CloseHandle( thread ); }
- if (firewall_enabled) set_firewall( APP_REMOVE ); + winetest_set_firewall( L"webservices_test", WINETEST_FW_APP_REMOVE ); } diff --git a/include/Makefile.in b/include/Makefile.in index 54cbf4d955c..0aa8b5278e1 100644 --- a/include/Makefile.in +++ b/include/Makefile.in @@ -857,6 +857,7 @@ SOURCES = \ wine/strmbase.h \ wine/svcctl.idl \ wine/test.h \ + wine/test_fw.h \ wine/unixlib.h \ wine/vulkan.h \ wine/vulkan_driver.h \ diff --git a/include/wine/test_fw.h b/include/wine/test_fw.h new file mode 100644 index 00000000000..634b1c41fb3 --- /dev/null +++ b/include/wine/test_fw.h @@ -0,0 +1,131 @@ +/* + * Copyright 2023 Hans Leidekker for CodeWeavers + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include "windef.h" +#include "winbase.h" +#include "netfw.h" + +static BOOL winetest_is_process_elevated(void) +{ + HANDLE token; + BOOL ret; + TOKEN_ELEVATION_TYPE type; + DWORD size; + + if (!OpenProcessToken( GetCurrentProcess(), TOKEN_QUERY, &token )) return FALSE; + ret = GetTokenInformation( token, TokenElevationType, &type, sizeof(type), &size ); + CloseHandle( token ); + return (ret && type == TokenElevationTypeFull); +} + +static BOOL winetest_is_firewall_enabled(void) +{ + HRESULT hr, init; + INetFwMgr *mgr = NULL; + INetFwPolicy *policy = NULL; + INetFwProfile *profile = NULL; + VARIANT_BOOL enabled = VARIANT_FALSE; + + init = CoInitializeEx( 0, COINIT_APARTMENTTHREADED ); + + hr = CoCreateInstance( &CLSID_NetFwMgr, NULL, CLSCTX_INPROC_SERVER, &IID_INetFwMgr, (void **)&mgr ); + if (hr != S_OK) goto done; + + hr = INetFwMgr_get_LocalPolicy( mgr, &policy ); + if (hr != S_OK) goto done; + + hr = INetFwPolicy_get_CurrentProfile( policy, &profile ); + if (hr != S_OK) goto done; + + hr = INetFwProfile_get_FirewallEnabled( profile, &enabled ); + +done: + if (policy) INetFwPolicy_Release( policy ); + if (profile) INetFwProfile_Release( profile ); + if (mgr) INetFwMgr_Release( mgr ); + if (SUCCEEDED( init )) CoUninitialize(); + return (enabled == VARIANT_TRUE); +} + +enum winetest_firewall_op +{ + WINETEST_FW_APP_ADD, + WINETEST_FW_APP_REMOVE +}; + +static BOOL winetest_set_firewall( const WCHAR *name, enum winetest_firewall_op op ) +{ + HRESULT hr, init; + INetFwMgr *mgr = NULL; + INetFwPolicy *policy = NULL; + INetFwProfile *profile = NULL; + INetFwAuthorizedApplication *app = NULL; + INetFwAuthorizedApplications *apps = NULL; + BSTR str, image = SysAllocStringLen( NULL, MAX_PATH ); + + if (!winetest_is_firewall_enabled()) return TRUE; + if (!winetest_is_process_elevated()) return FALSE; + + if (!GetModuleFileNameW( NULL, image, MAX_PATH )) + { + SysFreeString( image ); + return E_FAIL; + } + init = CoInitializeEx( 0, COINIT_APARTMENTTHREADED ); + + hr = CoCreateInstance( &CLSID_NetFwMgr, NULL, CLSCTX_INPROC_SERVER, &IID_INetFwMgr, (void **)&mgr ); + if (hr != S_OK) goto done; + + hr = INetFwMgr_get_LocalPolicy( mgr, &policy ); + if (hr != S_OK) goto done; + + hr = INetFwPolicy_get_CurrentProfile( policy, &profile ); + if (hr != S_OK) goto done; + + hr = INetFwProfile_get_AuthorizedApplications( profile, &apps ); + if (hr != S_OK) goto done; + + hr = CoCreateInstance( &CLSID_NetFwAuthorizedApplication, NULL, CLSCTX_INPROC_SERVER, + &IID_INetFwAuthorizedApplication, (void **)&app ); + if (hr != S_OK) goto done; + + hr = INetFwAuthorizedApplication_put_ProcessImageFileName( app, image ); + if (hr != S_OK) goto done; + + str = SysAllocString( name ); + hr = INetFwAuthorizedApplication_put_Name( app, str ); + SysFreeString( str ); + if (hr != S_OK) goto done; + + if (op == WINETEST_FW_APP_ADD) + hr = INetFwAuthorizedApplications_Add( apps, app ); + else if (op == WINETEST_FW_APP_REMOVE) + hr = INetFwAuthorizedApplications_Remove( apps, image ); + else + hr = E_INVALIDARG; + +done: + if (app) INetFwAuthorizedApplication_Release( app ); + if (apps) INetFwAuthorizedApplications_Release( apps ); + if (policy) INetFwPolicy_Release( policy ); + if (profile) INetFwProfile_Release( profile ); + if (mgr) INetFwMgr_Release( mgr ); + if (SUCCEEDED( init )) CoUninitialize(); + SysFreeString( image ); + return (hr == S_OK); +}
From: Jinoh Kang jinoh.kang.kr@gmail.com
--- dlls/ws2_32/tests/sock.c | 7 +++++++ 1 file changed, 7 insertions(+)
diff --git a/dlls/ws2_32/tests/sock.c b/dlls/ws2_32/tests/sock.c index 6f2bcb73a06..860604bc8a2 100644 --- a/dlls/ws2_32/tests/sock.c +++ b/dlls/ws2_32/tests/sock.c @@ -2253,6 +2253,13 @@ static void test_reuseaddr(void) closesocket(s3); closesocket(s4);
+ winetest_pop_context(); + } + + for (i = 0; i < ARRAY_SIZE(tests); ++i) + { + winetest_push_context("test with any %u", i); + /* Test binding and listening on any addr together with loopback, any addr first. */ s1 = socket(tests[i].domain, SOCK_STREAM, 0); ok(s1 != INVALID_SOCKET, "got error %d.\n", WSAGetLastError());
From: Jinoh Kang jinoh.kang.kr@gmail.com
--- dlls/ws2_32/tests/sock.c | 277 ++++++++++++++++++++++----------------- 1 file changed, 155 insertions(+), 122 deletions(-)
diff --git a/dlls/ws2_32/tests/sock.c b/dlls/ws2_32/tests/sock.c index 860604bc8a2..5e5916373f1 100644 --- a/dlls/ws2_32/tests/sock.c +++ b/dlls/ws2_32/tests/sock.c @@ -2031,131 +2031,11 @@ static void test_reuseaddr(void) { AF_INET, (struct sockaddr *)&saddr_in_any, (struct sockaddr *)&saddr_in_loopback, sizeof(saddr_in_any) }, { AF_INET6, (struct sockaddr *)&saddr_in6_any, (struct sockaddr *)&saddr_in6_loopback, sizeof(saddr_in6_any) }, }; - static const struct - { - struct - { - int domain; - struct sockaddr *addr; - socklen_t addrlen; - BOOL exclusive; - } - s[2]; - int error; - } - tests_exclusive[] = - { - { - {{ AF_INET, (struct sockaddr *)&saddr_in_any, sizeof(saddr_in_any), TRUE, }, - { AF_INET, (struct sockaddr *)&saddr_in_loopback, sizeof(saddr_in_loopback), FALSE, }}, - WSAEACCES, - }, - { - {{ AF_INET6, (struct sockaddr *)&saddr_in6_any, sizeof(saddr_in6_any), TRUE, }, - { AF_INET, (struct sockaddr *)&saddr_in_loopback, sizeof(saddr_in_loopback), FALSE, }}, - WSAEACCES, - }, - { - {{ AF_INET, (struct sockaddr *)&saddr_in_any, sizeof(saddr_in_any), FALSE, }, - { AF_INET, (struct sockaddr *)&saddr_in_loopback, sizeof(saddr_in_loopback), TRUE, }}, - NOERROR, - }, - { - {{ AF_INET, (struct sockaddr *)&saddr_in_any, sizeof(saddr_in_any), TRUE, }, - { AF_INET, (struct sockaddr *)&saddr_in_loopback, sizeof(saddr_in_loopback), TRUE, }}, - WSAEACCES, - }, - { - {{ AF_INET, (struct sockaddr *)&saddr_in_loopback, sizeof(saddr_in_loopback), TRUE, }, - { AF_INET, (struct sockaddr *)&saddr_in_any, sizeof(saddr_in_any), FALSE, }}, - NOERROR, - }, - { - {{ AF_INET, (struct sockaddr *)&saddr_in_loopback, sizeof(saddr_in_loopback), FALSE, }, - { AF_INET, (struct sockaddr *)&saddr_in_any, sizeof(saddr_in_any), TRUE, }}, - WSAEADDRINUSE, - }, - { - {{ AF_INET, (struct sockaddr *)&saddr_in_loopback, sizeof(saddr_in_loopback), FALSE, }, - { AF_INET6, (struct sockaddr *)&saddr_in6_any, sizeof(saddr_in6_any), TRUE, }}, - WSAEADDRINUSE, - }, - { - {{ AF_INET6, (struct sockaddr *)&saddr_in6_loopback, sizeof(saddr_in6_loopback), FALSE, }, - { AF_INET, (struct sockaddr *)&saddr_in_any, sizeof(saddr_in_any), TRUE, }}, - NOERROR, - }, - { - {{ AF_INET6, (struct sockaddr *)&saddr_in6_loopback, sizeof(saddr_in6_loopback), TRUE, }, - { AF_INET, (struct sockaddr *)&saddr_in_loopback, sizeof(saddr_in_loopback), TRUE, }}, - NOERROR, - }, - { - {{ AF_INET6, (struct sockaddr *)&saddr_in6_loopback_v4mapped, sizeof(saddr_in6_loopback_v4mapped), FALSE, }, - { AF_INET, (struct sockaddr *)&saddr_in_any, sizeof(saddr_in_any), TRUE, }}, - WSAEADDRINUSE, - }, - { - {{ AF_INET6, (struct sockaddr *)&saddr_in6_any, sizeof(saddr_in6_any), TRUE, }, - { AF_INET, (struct sockaddr *)&saddr_in_any, sizeof(saddr_in_any), FALSE, }}, - WSAEACCES, - }, - { - {{ AF_INET6, (struct sockaddr *)&saddr_in6_any, sizeof(saddr_in6_any), FALSE, }, - { AF_INET, (struct sockaddr *)&saddr_in_any, sizeof(saddr_in_any), TRUE, }}, - NOERROR, - }, - { - {{ AF_INET, (struct sockaddr *)&saddr_in_any, sizeof(saddr_in_any), FALSE, }, - { AF_INET, (struct sockaddr *)&saddr_in_any, sizeof(saddr_in_any), TRUE, }}, - WSAEADDRINUSE, - }, - { - {{ AF_INET, (struct sockaddr *)&saddr_in_any, sizeof(saddr_in_any), FALSE, }, - { AF_INET, (struct sockaddr *)&saddr_in_any, sizeof(saddr_in_any), FALSE, }}, - WSAEADDRINUSE, - }, - { - {{ AF_INET6, (struct sockaddr *)&saddr_in6_any, sizeof(saddr_in6_any), FALSE, }, - { AF_INET, (struct sockaddr *)&saddr_in_any, sizeof(saddr_in_any), FALSE, }}, - NOERROR, - }, - { - {{ AF_INET6, (struct sockaddr *)&saddr_in6_any_v4mapped, sizeof(saddr_in6_any_v4mapped), FALSE, }, - { AF_INET, (struct sockaddr *)&saddr_in_any, sizeof(saddr_in_any), FALSE, }}, - WSAEADDRINUSE, - }, - { - {{ AF_INET6, (struct sockaddr *)&saddr_in6_loopback_v4mapped, sizeof(saddr_in6_loopback_v4mapped), FALSE, }, - { AF_INET, (struct sockaddr *)&saddr_in_loopback, sizeof(saddr_in_loopback), FALSE, }}, - WSAEADDRINUSE, - }, - { - {{ AF_INET, (struct sockaddr *)&saddr_in_loopback, sizeof(saddr_in_loopback), FALSE, }, - { AF_INET6, (struct sockaddr *)&saddr_in6_loopback_v4mapped, sizeof(saddr_in6_loopback_v4mapped), FALSE, }}, - WSAEADDRINUSE, - }, - { - {{ AF_INET6, (struct sockaddr *)&saddr_in6_loopback, sizeof(saddr_in6_loopback), TRUE, }, - { AF_INET, (struct sockaddr *)&saddr_in_loopback, sizeof(saddr_in_loopback), TRUE, }}, - NOERROR, - }, - { - {{ AF_INET, (struct sockaddr *)&saddr_in_loopback, sizeof(saddr_in_loopback), TRUE, }, - { AF_INET, (struct sockaddr *)&saddr_in_loopback, sizeof(saddr_in_loopback), FALSE, }}, - WSAEADDRINUSE, - }, - { - {{ AF_INET, (struct sockaddr *)&saddr_in_loopback, sizeof(saddr_in_loopback), FALSE, }, - { AF_INET, (struct sockaddr *)&saddr_in_loopback, sizeof(saddr_in_loopback), TRUE, }}, - WSAEADDRINUSE, - }, - };
- unsigned int rc, reuse, value; + unsigned int rc, reuse; struct sockaddr saddr; SOCKET s1, s2, s3, s4; - unsigned int i, j; + unsigned int i; int size;
saddr_in_any.sin_family = AF_INET; @@ -2347,6 +2227,158 @@ static void test_reuseaddr(void)
winetest_pop_context(); } +} + +static void test_exclusiveaddruse(void) +{ + static struct sockaddr_in6 saddr_in6_any, saddr_in6_loopback; + static struct sockaddr_in6 saddr_in6_any_v4mapped, saddr_in6_loopback_v4mapped; + static struct sockaddr_in saddr_in_any, saddr_in_loopback; + + static const struct + { + struct + { + int domain; + struct sockaddr *addr; + socklen_t addrlen; + BOOL exclusive; + } + s[2]; + int error; + } + tests_exclusive[] = + { + { + {{ AF_INET, (struct sockaddr *)&saddr_in_any, sizeof(saddr_in_any), TRUE, }, + { AF_INET, (struct sockaddr *)&saddr_in_loopback, sizeof(saddr_in_loopback), FALSE, }}, + WSAEACCES, + }, + { + {{ AF_INET6, (struct sockaddr *)&saddr_in6_any, sizeof(saddr_in6_any), TRUE, }, + { AF_INET, (struct sockaddr *)&saddr_in_loopback, sizeof(saddr_in_loopback), FALSE, }}, + WSAEACCES, + }, + { + {{ AF_INET, (struct sockaddr *)&saddr_in_any, sizeof(saddr_in_any), FALSE, }, + { AF_INET, (struct sockaddr *)&saddr_in_loopback, sizeof(saddr_in_loopback), TRUE, }}, + NOERROR, + }, + { + {{ AF_INET, (struct sockaddr *)&saddr_in_any, sizeof(saddr_in_any), TRUE, }, + { AF_INET, (struct sockaddr *)&saddr_in_loopback, sizeof(saddr_in_loopback), TRUE, }}, + WSAEACCES, + }, + { + {{ AF_INET, (struct sockaddr *)&saddr_in_loopback, sizeof(saddr_in_loopback), TRUE, }, + { AF_INET, (struct sockaddr *)&saddr_in_any, sizeof(saddr_in_any), FALSE, }}, + NOERROR, + }, + { + {{ AF_INET, (struct sockaddr *)&saddr_in_loopback, sizeof(saddr_in_loopback), FALSE, }, + { AF_INET, (struct sockaddr *)&saddr_in_any, sizeof(saddr_in_any), TRUE, }}, + WSAEADDRINUSE, + }, + { + {{ AF_INET, (struct sockaddr *)&saddr_in_loopback, sizeof(saddr_in_loopback), FALSE, }, + { AF_INET6, (struct sockaddr *)&saddr_in6_any, sizeof(saddr_in6_any), TRUE, }}, + WSAEADDRINUSE, + }, + { + {{ AF_INET6, (struct sockaddr *)&saddr_in6_loopback, sizeof(saddr_in6_loopback), FALSE, }, + { AF_INET, (struct sockaddr *)&saddr_in_any, sizeof(saddr_in_any), TRUE, }}, + NOERROR, + }, + { + {{ AF_INET6, (struct sockaddr *)&saddr_in6_loopback, sizeof(saddr_in6_loopback), TRUE, }, + { AF_INET, (struct sockaddr *)&saddr_in_loopback, sizeof(saddr_in_loopback), TRUE, }}, + NOERROR, + }, + { + {{ AF_INET6, (struct sockaddr *)&saddr_in6_loopback_v4mapped, sizeof(saddr_in6_loopback_v4mapped), FALSE, }, + { AF_INET, (struct sockaddr *)&saddr_in_any, sizeof(saddr_in_any), TRUE, }}, + WSAEADDRINUSE, + }, + { + {{ AF_INET6, (struct sockaddr *)&saddr_in6_any, sizeof(saddr_in6_any), TRUE, }, + { AF_INET, (struct sockaddr *)&saddr_in_any, sizeof(saddr_in_any), FALSE, }}, + WSAEACCES, + }, + { + {{ AF_INET6, (struct sockaddr *)&saddr_in6_any, sizeof(saddr_in6_any), FALSE, }, + { AF_INET, (struct sockaddr *)&saddr_in_any, sizeof(saddr_in_any), TRUE, }}, + NOERROR, + }, + { + {{ AF_INET, (struct sockaddr *)&saddr_in_any, sizeof(saddr_in_any), FALSE, }, + { AF_INET, (struct sockaddr *)&saddr_in_any, sizeof(saddr_in_any), TRUE, }}, + WSAEADDRINUSE, + }, + { + {{ AF_INET, (struct sockaddr *)&saddr_in_any, sizeof(saddr_in_any), FALSE, }, + { AF_INET, (struct sockaddr *)&saddr_in_any, sizeof(saddr_in_any), FALSE, }}, + WSAEADDRINUSE, + }, + { + {{ AF_INET6, (struct sockaddr *)&saddr_in6_any, sizeof(saddr_in6_any), FALSE, }, + { AF_INET, (struct sockaddr *)&saddr_in_any, sizeof(saddr_in_any), FALSE, }}, + NOERROR, + }, + { + {{ AF_INET6, (struct sockaddr *)&saddr_in6_any_v4mapped, sizeof(saddr_in6_any_v4mapped), FALSE, }, + { AF_INET, (struct sockaddr *)&saddr_in_any, sizeof(saddr_in_any), FALSE, }}, + WSAEADDRINUSE, + }, + { + {{ AF_INET6, (struct sockaddr *)&saddr_in6_loopback_v4mapped, sizeof(saddr_in6_loopback_v4mapped), FALSE, }, + { AF_INET, (struct sockaddr *)&saddr_in_loopback, sizeof(saddr_in_loopback), FALSE, }}, + WSAEADDRINUSE, + }, + { + {{ AF_INET, (struct sockaddr *)&saddr_in_loopback, sizeof(saddr_in_loopback), FALSE, }, + { AF_INET6, (struct sockaddr *)&saddr_in6_loopback_v4mapped, sizeof(saddr_in6_loopback_v4mapped), FALSE, }}, + WSAEADDRINUSE, + }, + { + {{ AF_INET6, (struct sockaddr *)&saddr_in6_loopback, sizeof(saddr_in6_loopback), TRUE, }, + { AF_INET, (struct sockaddr *)&saddr_in_loopback, sizeof(saddr_in_loopback), TRUE, }}, + NOERROR, + }, + { + {{ AF_INET, (struct sockaddr *)&saddr_in_loopback, sizeof(saddr_in_loopback), TRUE, }, + { AF_INET, (struct sockaddr *)&saddr_in_loopback, sizeof(saddr_in_loopback), FALSE, }}, + WSAEADDRINUSE, + }, + { + {{ AF_INET, (struct sockaddr *)&saddr_in_loopback, sizeof(saddr_in_loopback), FALSE, }, + { AF_INET, (struct sockaddr *)&saddr_in_loopback, sizeof(saddr_in_loopback), TRUE, }}, + WSAEADDRINUSE, + }, + }; + + unsigned int rc, value; + SOCKET s1; + unsigned int i, j; + + saddr_in_any.sin_family = AF_INET; + saddr_in_any.sin_port = htons(SERVERPORT + 1); + saddr_in_any.sin_addr.s_addr = htonl(INADDR_ANY); + saddr_in_loopback = saddr_in_any; + saddr_in_loopback.sin_addr.s_addr = htonl(INADDR_LOOPBACK); + + saddr_in6_any.sin6_family = AF_INET6; + saddr_in6_any.sin6_port = htons(SERVERPORT + 1); + memset( &saddr_in6_any.sin6_addr, 0, sizeof(saddr_in6_any.sin6_addr) ); + saddr_in6_loopback = saddr_in6_any; + inet_pton(AF_INET6, "::1", &saddr_in6_loopback.sin6_addr); + + saddr_in6_loopback_v4mapped = saddr_in6_any; + rc = inet_pton(AF_INET6, "::ffff:127.0.0.1", &saddr_in6_loopback_v4mapped.sin6_addr); + ok(rc, "got error %d.\n", WSAGetLastError()); + + saddr_in6_any_v4mapped = saddr_in6_any; + rc = inet_pton(AF_INET6, "::ffff:0.0.0.0", &saddr_in6_any_v4mapped.sin6_addr); + ok(rc, "got error %d.\n", WSAGetLastError());
/* SO_REUSEADDR and SO_EXCLUSIVEADDRUSE are mutually exclusive. */ s1 = socket(AF_INET, SOCK_STREAM, 0); @@ -13674,6 +13706,7 @@ START_TEST( sock )
test_set_getsockopt(); test_reuseaddr(); + test_exclusiveaddruse(); test_ip_pktinfo(); test_ipv4_cmsg(); test_ipv6_cmsg();
From: Jinoh Kang jinoh.kang.kr@gmail.com
test_reuseaddr and test_exclusiveaddruse bind to the wildcard address (0.0.0.0 or [::]). This may trigger a firewall alert on Windows 7, and the alert UI window may interfere with user32:msg tests.
Fix this by trying to disable the firewall, and skipping the wildcard address tests if it fails.
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=53891 Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=54202 --- dlls/ws2_32/tests/Makefile.in | 2 +- dlls/ws2_32/tests/sock.c | 67 ++++++++++++++++++++++++++++++++--- 2 files changed, 64 insertions(+), 5 deletions(-)
diff --git a/dlls/ws2_32/tests/Makefile.in b/dlls/ws2_32/tests/Makefile.in index b1b10c1636e..f9b4ac0d556 100644 --- a/dlls/ws2_32/tests/Makefile.in +++ b/dlls/ws2_32/tests/Makefile.in @@ -1,5 +1,5 @@ TESTDLL = ws2_32.dll -IMPORTS = iphlpapi ws2_32 user32 +IMPORTS = iphlpapi ws2_32 user32 ole32 oleaut32 advapi32
C_SRCS = \ afd.c \ diff --git a/dlls/ws2_32/tests/sock.c b/dlls/ws2_32/tests/sock.c index 5e5916373f1..c440cf78d03 100644 --- a/dlls/ws2_32/tests/sock.c +++ b/dlls/ws2_32/tests/sock.c @@ -23,6 +23,7 @@
#include <ntstatus.h> #define WIN32_NO_STATUS +#define COBJMACROS #include <winsock2.h> #include <windows.h> #include <winternl.h> @@ -33,7 +34,9 @@ #include <mswsock.h> #include <mstcpip.h> #include <stdio.h> +#include <initguid.h> #include "wine/test.h" +#include "wine/test_fw.h"
#define MAX_CLIENTS 4 /* Max number of clients */ #define FIRST_CHAR 'A' /* First character in transferred pattern */ @@ -162,6 +165,35 @@ static GUID WSARecvMsg_GUID = WSAID_WSARECVMSG; static SOCKET setup_server_socket(struct sockaddr_in *addr, int *len); static SOCKET setup_connector_socket(const struct sockaddr_in *addr, int len, BOOL nonblock);
+static BOOL is_loopback_addr(const struct sockaddr *saddr) +{ + if (saddr->sa_family == AF_INET) + { + const struct sockaddr_in *sa_in = (const struct sockaddr_in *)saddr; + return sa_in->sin_addr.s_addr == htonl(INADDR_LOOPBACK); + } + + if (saddr->sa_family == AF_INET6) + { + static const BYTE in6_loopback[16] = + { + /* ::1 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, + }; + static const BYTE in6_loopback_v4mapped[16] = + { + /* ::ffff:127.0.0.1 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x01, + }; + const struct sockaddr_in6 *sa_in6 = (const struct sockaddr_in6 *)saddr; + return memcmp(&sa_in6->sin6_addr, in6_loopback, 16) == 0 || + memcmp(&sa_in6->sin6_addr, in6_loopback_v4mapped, 16) == 0; + } + + ok(0, "unexpected family %d\n", saddr->sa_family); + return FALSE; +} + static void tcp_socketpair_flags(SOCKET *src, SOCKET *dst, DWORD flags) { SOCKET server = INVALID_SOCKET; @@ -2013,7 +2045,7 @@ static void test_set_getsockopt(void) } }
-static void test_reuseaddr(void) +static void test_reuseaddr(BOOL loopback_only) { static struct sockaddr_in6 saddr_in6_any, saddr_in6_loopback; static struct sockaddr_in6 saddr_in6_any_v4mapped, saddr_in6_loopback_v4mapped; @@ -2136,6 +2168,12 @@ static void test_reuseaddr(void) winetest_pop_context(); }
+ if (loopback_only) + { + skip("Loopback only mode: skipping tests with any addr\n"); + return; + } + for (i = 0; i < ARRAY_SIZE(tests); ++i) { winetest_push_context("test with any %u", i); @@ -2229,7 +2267,7 @@ static void test_reuseaddr(void) } }
-static void test_exclusiveaddruse(void) +static void test_exclusiveaddruse(BOOL loopback_only) { static struct sockaddr_in6 saddr_in6_any, saddr_in6_loopback; static struct sockaddr_in6 saddr_in6_any_v4mapped, saddr_in6_loopback_v4mapped; @@ -2410,6 +2448,13 @@ static void test_exclusiveaddruse(void) { SOCKET s[2];
+ if (loopback_only && !(is_loopback_addr(tests_exclusive[i].s[0].addr) && + is_loopback_addr(tests_exclusive[i].s[1].addr))) + { + skip("Loopback only mode: skipping test %d\n", i); + continue; + } + winetest_push_context("test %u", i);
for (j = 0; j < 2; ++j) @@ -13695,6 +13740,7 @@ static void test_connect_udp(void)
START_TEST( sock ) { + BOOL fw_set_ok; int i;
/* Leave these tests at the beginning. They depend on WSAStartup not having been @@ -13705,8 +13751,21 @@ START_TEST( sock ) Init();
test_set_getsockopt(); - test_reuseaddr(); - test_exclusiveaddruse(); + + /* Keep the firewall-exempt region as small as possible. + * + * We don't want to skip _all_ tests if the firewall initialization fails. + * It's useful to test socket behaviour as an unprivileged process even if + * the firewall is enabled. + */ + fw_set_ok = winetest_set_firewall( L"ws2_32_test", WINETEST_FW_APP_ADD ); + test_reuseaddr(!fw_set_ok); + test_exclusiveaddruse(!fw_set_ok); + if (fw_set_ok) + { + winetest_set_firewall( L"ws2_32_test", WINETEST_FW_APP_REMOVE ); + } + test_ip_pktinfo(); test_ipv4_cmsg(); test_ipv6_cmsg();
Hi,
It looks like your patch introduced the new failures shown below. Please investigate and fix them before resubmitting your patch. If they are not new, fixing them anyway would help a lot. Otherwise please ask for the known failures list to be updated.
The tests also ran into some preexisting test failures. If you know how to fix them that would be helpful. See the TestBot job for the details:
The full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=128637
Your paranoid android.
=== w864 (64 bit report) ===
ws2_32: sock.c:2479: Test failed: test 1: got error 10047. sock.c:2484: Test failed: test 1: got rc 0, error 0, expected error 10013. sock.c:2484: Test failed: test 6: got rc -1, error 10047, expected error 10048. sock.c:2479: Test failed: test 7: got error 10047. sock.c:2479: Test failed: test 8: got error 10047. sock.c:2479: Test failed: test 9: got error 10047. sock.c:2484: Test failed: test 9: got rc 0, error 0, expected error 10048. sock.c:2479: Test failed: test 10: got error 10047. sock.c:2484: Test failed: test 10: got rc 0, error 0, expected error 10013. sock.c:2479: Test failed: test 11: got error 10047. sock.c:2479: Test failed: test 14: got error 10047. sock.c:2479: Test failed: test 15: got error 10047. sock.c:2484: Test failed: test 15: got rc 0, error 0, expected error 10048. sock.c:2479: Test failed: test 16: got error 10047. sock.c:2484: Test failed: test 16: got rc 0, error 0, expected error 10048. sock.c:2484: Test failed: test 17: got rc -1, error 10047, expected error 10048. sock.c:2479: Test failed: test 18: got error 10047.
=== w1064v1507 (64 bit report) ===
ws2_32: sock.c:2479: Test failed: test 1: got error 10047. sock.c:2484: Test failed: test 1: got rc 0, error 0, expected error 10013. sock.c:2484: Test failed: test 6: got rc -1, error 10047, expected error 10048. sock.c:2479: Test failed: test 7: got error 10047. sock.c:2479: Test failed: test 8: got error 10047. sock.c:2479: Test failed: test 9: got error 10047. sock.c:2484: Test failed: test 9: got rc 0, error 0, expected error 10048. sock.c:2479: Test failed: test 10: got error 10047. sock.c:2484: Test failed: test 10: got rc 0, error 0, expected error 10013. sock.c:2479: Test failed: test 11: got error 10047. sock.c:2479: Test failed: test 14: got error 10047. sock.c:2479: Test failed: test 15: got error 10047. sock.c:2484: Test failed: test 15: got rc 0, error 0, expected error 10048. sock.c:2479: Test failed: test 16: got error 10047. sock.c:2484: Test failed: test 16: got rc 0, error 0, expected error 10048. sock.c:2484: Test failed: test 17: got rc -1, error 10047, expected error 10048. sock.c:2479: Test failed: test 18: got error 10047.
=== w1064v1809 (64 bit report) ===
ws2_32: sock.c:2479: Test failed: test 1: got error 10047. sock.c:2484: Test failed: test 1: got rc 0, error 0, expected error 10013. sock.c:2484: Test failed: test 6: got rc -1, error 10047, expected error 10048. sock.c:2479: Test failed: test 7: got error 10047. sock.c:2479: Test failed: test 8: got error 10047. sock.c:2479: Test failed: test 9: got error 10047. sock.c:2484: Test failed: test 9: got rc 0, error 0, expected error 10048. sock.c:2479: Test failed: test 10: got error 10047. sock.c:2484: Test failed: test 10: got rc 0, error 0, expected error 10013. sock.c:2479: Test failed: test 11: got error 10047. sock.c:2479: Test failed: test 14: got error 10047. sock.c:2479: Test failed: test 15: got error 10047. sock.c:2484: Test failed: test 15: got rc 0, error 0, expected error 10048. sock.c:2479: Test failed: test 16: got error 10047. sock.c:2484: Test failed: test 16: got rc 0, error 0, expected error 10048. sock.c:2484: Test failed: test 17: got rc -1, error 10047, expected error 10048. sock.c:2479: Test failed: test 18: got error 10047.
=== w1064_2qxl (64 bit report) ===
ws2_32: sock.c:2479: Test failed: test 1: got error 10047. sock.c:2484: Test failed: test 1: got rc 0, error 0, expected error 10013. sock.c:2484: Test failed: test 6: got rc -1, error 10047, expected error 10048. sock.c:2479: Test failed: test 7: got error 10047. sock.c:2479: Test failed: test 8: got error 10047. sock.c:2479: Test failed: test 9: got error 10047. sock.c:2484: Test failed: test 9: got rc 0, error 0, expected error 10048. sock.c:2479: Test failed: test 10: got error 10047. sock.c:2484: Test failed: test 10: got rc 0, error 0, expected error 10013. sock.c:2479: Test failed: test 11: got error 10047. sock.c:2479: Test failed: test 14: got error 10047. sock.c:2479: Test failed: test 15: got error 10047. sock.c:2484: Test failed: test 15: got rc 0, error 0, expected error 10048. sock.c:2479: Test failed: test 16: got error 10047. sock.c:2484: Test failed: test 16: got rc 0, error 0, expected error 10048. sock.c:2484: Test failed: test 17: got rc -1, error 10047, expected error 10048. sock.c:2479: Test failed: test 18: got error 10047.
=== w1064_adm (64 bit report) ===
ws2_32: sock.c:193: Test failed: unexpected family 0 sock.c:193: Test failed: unexpected family 0 sock.c:193: Test failed: unexpected family 0 sock.c:193: Test failed: unexpected family 0 sock.c:193: Test failed: unexpected family 0 sock.c:193: Test failed: unexpected family 0 sock.c:193: Test failed: unexpected family 0 sock.c:193: Test failed: unexpected family 0 sock.c:193: Test failed: unexpected family 0 sock.c:193: Test failed: unexpected family 0 sock.c:193: Test failed: unexpected family 0 sock.c:193: Test failed: unexpected family 0
=== w1064_tsign (64 bit report) ===
ws2_32: sock.c:2479: Test failed: test 1: got error 10047. sock.c:2484: Test failed: test 1: got rc 0, error 0, expected error 10013. sock.c:2484: Test failed: test 6: got rc -1, error 10047, expected error 10048. sock.c:2479: Test failed: test 7: got error 10047. sock.c:2479: Test failed: test 8: got error 10047. sock.c:2479: Test failed: test 9: got error 10047. sock.c:2484: Test failed: test 9: got rc 0, error 0, expected error 10048. sock.c:2479: Test failed: test 10: got error 10047. sock.c:2484: Test failed: test 10: got rc 0, error 0, expected error 10013. sock.c:2479: Test failed: test 11: got error 10047. sock.c:2479: Test failed: test 14: got error 10047. sock.c:2479: Test failed: test 15: got error 10047. sock.c:2484: Test failed: test 15: got rc 0, error 0, expected error 10048. sock.c:2479: Test failed: test 16: got error 10047. sock.c:2484: Test failed: test 16: got rc 0, error 0, expected error 10048. sock.c:2484: Test failed: test 17: got rc -1, error 10047, expected error 10048. sock.c:2479: Test failed: test 18: got error 10047.
=== w10pro64 (64 bit report) ===
ws2_32: sock.c:2479: Test failed: test 1: got error 10047. sock.c:2484: Test failed: test 1: got rc 0, error 0, expected error 10013. sock.c:2484: Test failed: test 6: got rc -1, error 10047, expected error 10048. sock.c:2479: Test failed: test 7: got error 10047. sock.c:2479: Test failed: test 8: got error 10047. sock.c:2479: Test failed: test 9: got error 10047. sock.c:2484: Test failed: test 9: got rc 0, error 0, expected error 10048. sock.c:2479: Test failed: test 10: got error 10047. sock.c:2484: Test failed: test 10: got rc 0, error 0, expected error 10013. sock.c:2479: Test failed: test 11: got error 10047. sock.c:2479: Test failed: test 14: got error 10047. sock.c:2479: Test failed: test 15: got error 10047. sock.c:2484: Test failed: test 15: got rc 0, error 0, expected error 10048. sock.c:2479: Test failed: test 16: got error 10047. sock.c:2484: Test failed: test 16: got rc 0, error 0, expected error 10048. sock.c:2484: Test failed: test 17: got rc -1, error 10047, expected error 10048. sock.c:2479: Test failed: test 18: got error 10047.
=== w10pro64_en_AE_u8 (64 bit report) ===
ws2_32: sock.c:2479: Test failed: test 1: got error 10047. sock.c:2484: Test failed: test 1: got rc 0, error 0, expected error 10013. sock.c:2484: Test failed: test 6: got rc -1, error 10047, expected error 10048. sock.c:2479: Test failed: test 7: got error 10047. sock.c:2479: Test failed: test 8: got error 10047. sock.c:2479: Test failed: test 9: got error 10047. sock.c:2484: Test failed: test 9: got rc 0, error 0, expected error 10048. sock.c:2479: Test failed: test 10: got error 10047. sock.c:2484: Test failed: test 10: got rc 0, error 0, expected error 10013. sock.c:2479: Test failed: test 11: got error 10047. sock.c:2479: Test failed: test 14: got error 10047. sock.c:2479: Test failed: test 15: got error 10047. sock.c:2484: Test failed: test 15: got rc 0, error 0, expected error 10048. sock.c:2479: Test failed: test 16: got error 10047. sock.c:2484: Test failed: test 16: got rc 0, error 0, expected error 10048. sock.c:2484: Test failed: test 17: got rc -1, error 10047, expected error 10048. sock.c:2479: Test failed: test 18: got error 10047.
=== w10pro64_ar (64 bit report) ===
ws2_32: sock.c:2479: Test failed: test 1: got error 10047. sock.c:2484: Test failed: test 1: got rc 0, error 0, expected error 10013. sock.c:2484: Test failed: test 6: got rc -1, error 10047, expected error 10048. sock.c:2479: Test failed: test 7: got error 10047. sock.c:2479: Test failed: test 8: got error 10047. sock.c:2479: Test failed: test 9: got error 10047. sock.c:2484: Test failed: test 9: got rc 0, error 0, expected error 10048. sock.c:2479: Test failed: test 10: got error 10047. sock.c:2484: Test failed: test 10: got rc 0, error 0, expected error 10013. sock.c:2479: Test failed: test 11: got error 10047. sock.c:2479: Test failed: test 14: got error 10047. sock.c:2479: Test failed: test 15: got error 10047. sock.c:2484: Test failed: test 15: got rc 0, error 0, expected error 10048. sock.c:2479: Test failed: test 16: got error 10047. sock.c:2484: Test failed: test 16: got rc 0, error 0, expected error 10048. sock.c:2484: Test failed: test 17: got rc -1, error 10047, expected error 10048. sock.c:2479: Test failed: test 18: got error 10047.
=== w10pro64_ja (64 bit report) ===
ws2_32: sock.c:2479: Test failed: test 1: got error 10047. sock.c:2484: Test failed: test 1: got rc 0, error 0, expected error 10013. sock.c:2484: Test failed: test 6: got rc -1, error 10047, expected error 10048. sock.c:2479: Test failed: test 7: got error 10047. sock.c:2479: Test failed: test 8: got error 10047. sock.c:2479: Test failed: test 9: got error 10047. sock.c:2484: Test failed: test 9: got rc 0, error 0, expected error 10048. sock.c:2479: Test failed: test 10: got error 10047. sock.c:2484: Test failed: test 10: got rc 0, error 0, expected error 10013. sock.c:2479: Test failed: test 11: got error 10047. sock.c:2479: Test failed: test 14: got error 10047. sock.c:2479: Test failed: test 15: got error 10047. sock.c:2484: Test failed: test 15: got rc 0, error 0, expected error 10048. sock.c:2479: Test failed: test 16: got error 10047. sock.c:2484: Test failed: test 16: got rc 0, error 0, expected error 10048. sock.c:2484: Test failed: test 17: got rc -1, error 10047, expected error 10048. sock.c:2479: Test failed: test 18: got error 10047.
=== w10pro64_zh_CN (64 bit report) ===
ws2_32: sock.c:2479: Test failed: test 1: got error 10047. sock.c:2484: Test failed: test 1: got rc 0, error 0, expected error 10013. sock.c:2484: Test failed: test 6: got rc -1, error 10047, expected error 10048. sock.c:2479: Test failed: test 7: got error 10047. sock.c:2479: Test failed: test 8: got error 10047. sock.c:2479: Test failed: test 9: got error 10047. sock.c:2484: Test failed: test 9: got rc 0, error 0, expected error 10048. sock.c:2479: Test failed: test 10: got error 10047. sock.c:2484: Test failed: test 10: got rc 0, error 0, expected error 10013. sock.c:2479: Test failed: test 11: got error 10047. sock.c:2479: Test failed: test 14: got error 10047. sock.c:2479: Test failed: test 15: got error 10047. sock.c:2484: Test failed: test 15: got rc 0, error 0, expected error 10048. sock.c:2479: Test failed: test 16: got error 10047. sock.c:2484: Test failed: test 16: got rc 0, error 0, expected error 10048. sock.c:2484: Test failed: test 17: got rc -1, error 10047, expected error 10048. sock.c:2479: Test failed: test 18: got error 10047.
This merge request was approved by Jinoh Kang.
Let's wait for merge request 1987 first, please.
This merge request was closed by Jinoh Kang.