[PATCH 0/4] MR2000: ws2_32/tests: Try to disable firewall before testing with any addr.
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 -- https://gitlab.winehq.org/wine/wine/-/merge_requests/2000
From: Hans Leidekker <hans(a)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); +} -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/2000
From: Jinoh Kang <jinoh.kang.kr(a)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()); -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/2000
From: Jinoh Kang <jinoh.kang.kr(a)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(); -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/2000
From: Jinoh Kang <jinoh.kang.kr(a)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/sock.c | 64 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 60 insertions(+), 4 deletions(-) diff --git a/dlls/ws2_32/tests/sock.c b/dlls/ws2_32/tests/sock.c index 5e5916373f1..2b698239c86 100644 --- a/dlls/ws2_32/tests/sock.c +++ b/dlls/ws2_32/tests/sock.c @@ -162,6 +162,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 +2042,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 +2165,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 +2264,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 +2445,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 +13737,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 +13748,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(); -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/2000
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 full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=128636 Your paranoid android. === build (build log) === ../wine/dlls/ws2_32/tests/sock.c:13758:56: error: ���WINETEST_FW_APP_ADD��� undeclared (first use in this function) ../wine/dlls/ws2_32/tests/sock.c:13763:48: error: ���WINETEST_FW_APP_REMOVE��� undeclared (first use in this function) Makefile:190932: recipe for target 'dlls/ws2_32/tests/i386-windows/sock.o' failed Task: The exe32 Wine build failed === debian11 (build log) === ../wine/dlls/ws2_32/tests/sock.c:13758:56: error: ���WINETEST_FW_APP_ADD��� undeclared (first use in this function) ../wine/dlls/ws2_32/tests/sock.c:13763:48: error: ���WINETEST_FW_APP_REMOVE��� undeclared (first use in this function) Task: The win32 Wine build failed === debian11b (build log) === ../wine/dlls/ws2_32/tests/sock.c:13758:56: error: ���WINETEST_FW_APP_ADD��� undeclared (first use in this function) ../wine/dlls/ws2_32/tests/sock.c:13763:48: error: ���WINETEST_FW_APP_REMOVE��� undeclared (first use in this function) Task: The wow64 Wine build failed
This merge request was approved by Jinoh Kang. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/2000
participants (4)
-
Hans Leidekker -
Jinoh Kang -
Jinoh Kang (@iamahuman) -
Marvin