-- v2: rpcrt4/tests: Use common code to set the firewall. wsdapi/tests: Use common code to set the firewall. dpnet/tests: Use common code to set the firewall. dplayx/tests: Use common code to set the firewall. 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: Hans Leidekker hans@codeweavers.com
--- dlls/dplayx/tests/dplayx.c | 176 ++----------------------------------- 1 file changed, 5 insertions(+), 171 deletions(-)
diff --git a/dlls/dplayx/tests/dplayx.c b/dlls/dplayx/tests/dplayx.c index 6cc149bac95..e870ad38469 100644 --- a/dlls/dplayx/tests/dplayx.c +++ b/dlls/dplayx/tests/dplayx.c @@ -18,12 +18,12 @@ */
#define COBJMACROS -#include "wine/test.h" #include <stdio.h> #define INITGUID #include <dplay.h> #include <dplobby.h> -#include <netfw.h> +#include "wine/test.h" +#include "wine/test_fw.h"
static HRESULT (WINAPI *pDirectPlayEnumerateA)( LPDPENUMDPCALLBACKA, void* ); static HRESULT (WINAPI *pDirectPlayEnumerateW)( LPDPENUMDPCALLBACKW, void* ); @@ -6711,160 +6711,6 @@ static void test_COM_dplobby(void) ok(refcount == 0, "refcount == %lu, expected 0\n", refcount); }
-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 %08lx\n", hr ); - if (hr != S_OK) goto done; - - hr = INetFwMgr_get_LocalPolicy( mgr, &policy ); - ok( hr == S_OK, "got %08lx\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 %08lx\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 ); - WCHAR path[MAX_PATH]; - - if (!GetModuleFileNameW( NULL, image, MAX_PATH )) - { - SysFreeString( image ); - return E_FAIL; - } - - if(!GetSystemDirectoryW(path, MAX_PATH)) - { - SysFreeString( image ); - return E_FAIL; - } - lstrcatW( path, L"\dplaysvr.exe" ); - - init = CoInitializeEx( 0, COINIT_APARTMENTTHREADED ); - - hr = CoCreateInstance( &CLSID_NetFwMgr, NULL, CLSCTX_INPROC_SERVER, &IID_INetFwMgr, - (void **)&mgr ); - ok( hr == S_OK, "got %08lx\n", hr ); - if (hr != S_OK) goto done; - - hr = INetFwMgr_get_LocalPolicy( mgr, &policy ); - ok( hr == S_OK, "got %08lx\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 %08lx\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 %08lx\n", hr ); - if (hr != S_OK) goto done; - - hr = INetFwAuthorizedApplication_put_ProcessImageFileName( app, image ); - if (hr != S_OK) goto done; - - name = SysAllocString( L"dplay_client" ); - hr = INetFwAuthorizedApplication_put_Name( app, name ); - SysFreeString( name ); - ok( hr == S_OK, "got %08lx\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; - if (hr != S_OK) goto done; - - INetFwAuthorizedApplication_Release( app ); - hr = CoCreateInstance( &CLSID_NetFwAuthorizedApplication, NULL, CLSCTX_INPROC_SERVER, - &IID_INetFwAuthorizedApplication, (void **)&app ); - ok( hr == S_OK, "got %08lx\n", hr ); - if (hr != S_OK) goto done; - - SysFreeString( image ); - image = SysAllocString( path ); - hr = INetFwAuthorizedApplication_put_ProcessImageFileName( app, image ); - if (hr != S_OK) goto done; - - name = SysAllocString( L"dplay_server" ); - hr = INetFwAuthorizedApplication_put_Name( app, name ); - SysFreeString( name ); - ok( hr == S_OK, "got %08lx\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; -} - /* taken from programs/winetest/main.c */ static BOOL is_stub_dll(const char *filename) { @@ -6894,8 +6740,6 @@ static BOOL is_stub_dll(const char *filename)
START_TEST(dplayx) { - BOOL firewall_enabled; - HRESULT hr; char path[MAX_PATH]; HMODULE module;
@@ -6912,22 +6756,12 @@ START_TEST(dplayx) return; }
- if ((firewall_enabled = is_firewall_enabled()) && !is_process_elevated()) + if (!winetest_set_firewall(L"dplay_server", WINETEST_FW_APP_ADD)) { - skip("no privileges, skipping tests to avoid firewall dialog\n"); + skip("can't authorize app in firewall\n"); return; }
- if (firewall_enabled) - { - hr = set_firewall(APP_ADD); - if (hr != S_OK) - { - skip("can't authorize app in firewall %08lx\n", hr); - return; - } - } - CoInitialize( NULL );
module = LoadLibraryA("dplayx.dll"); @@ -6991,5 +6825,5 @@ START_TEST(dplayx) done: FreeLibrary(module); CoUninitialize(); - if (firewall_enabled) set_firewall(APP_REMOVE); + winetest_set_firewall(L"dplay_server", WINETEST_FW_APP_REMOVE); }
From: Hans Leidekker hans@codeweavers.com
--- dlls/wsdapi/tests/discovery.c | 151 +++------------------------------- 1 file changed, 10 insertions(+), 141 deletions(-)
diff --git a/dlls/wsdapi/tests/discovery.c b/dlls/wsdapi/tests/discovery.c index 01b28a3c1ad..0eda092b4f7 100644 --- a/dlls/wsdapi/tests/discovery.c +++ b/dlls/wsdapi/tests/discovery.c @@ -21,18 +21,18 @@
#define COBJMACROS
+#include <stdio.h> +#include <windows.h> #include <winsock2.h> #include <ws2tcpip.h> -#include <windows.h> +#include <iphlpapi.h>
-#include "wine/test.h" -#include "wine/heap.h" #include "initguid.h" #include "objbase.h" #include "wsdapi.h" -#include <netfw.h> -#include <iphlpapi.h> -#include <stdio.h> +#include "wine/heap.h" +#include "wine/test.h" +#include "wine/test_fw.h"
#define SEND_ADDRESS_IPV4 "239.255.255.250" #define SEND_ADDRESS_IPV6 "FF02::C" @@ -1268,143 +1268,12 @@ after_unpublish_test: WSACleanup(); }
-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 %08lx\n", hr ); - if (hr != S_OK) goto done; - - hr = INetFwMgr_get_LocalPolicy( mgr, &policy ); - ok( hr == S_OK, "got %08lx\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 %08lx\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 %08lx\n", hr ); - if (hr != S_OK) goto done; - - hr = INetFwMgr_get_LocalPolicy( mgr, &policy ); - ok( hr == S_OK, "got %08lx\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 %08lx\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 %08lx\n", hr ); - if (hr != S_OK) goto done; - - hr = INetFwAuthorizedApplication_put_ProcessImageFileName( app, image ); - if (hr != S_OK) goto done; - - name = SysAllocString( L"wsdapi_test" ); - hr = INetFwAuthorizedApplication_put_Name( app, name ); - SysFreeString( name ); - ok( hr == S_OK, "got %08lx\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(discovery) { - BOOL firewall_enabled = is_firewall_enabled(); - HRESULT hr; - - if (firewall_enabled) + if (!winetest_set_firewall(L"wsdapi_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 %08lx\n", hr); - return; - } + skip("can't authorize app in firewall\n"); + return; }
CoInitialize(NULL); @@ -1415,5 +1284,5 @@ START_TEST(discovery) UnPublish_tests();
CoUninitialize(); - if (firewall_enabled) set_firewall(APP_REMOVE); + winetest_set_firewall(L"wsdapi_test", WINETEST_FW_APP_REMOVE); }
From: Hans Leidekker hans@codeweavers.com
--- dlls/dpnet/tests/client.c | 19 +--- dlls/dpnet/tests/dpnet_test.h | 9 -- dlls/dpnet/tests/server.c | 165 +--------------------------------- dlls/dpnet/tests/thread.c | 22 ++--- 4 files changed, 16 insertions(+), 199 deletions(-)
diff --git a/dlls/dpnet/tests/client.c b/dlls/dpnet/tests/client.c index 2f7d6335a97..ba6ae1e9742 100644 --- a/dlls/dpnet/tests/client.c +++ b/dlls/dpnet/tests/client.c @@ -25,6 +25,7 @@ #include <winver.h> #define COBJMACROS #include "wine/test.h" +#include "wine/test_fw.h"
#include "dpnet_test.h"
@@ -963,7 +964,6 @@ static void test_cleanup_dp_peer(void)
START_TEST(client) { - BOOL firewall_enabled; HRESULT hr; char path[MAX_PATH];
@@ -980,22 +980,12 @@ START_TEST(client) return; }
- if ((firewall_enabled = is_firewall_enabled()) && !is_process_elevated()) + if (!winetest_set_firewall(L"dpnet_client", WINETEST_FW_APP_ADD)) { - skip("no privileges, skipping tests to avoid firewall dialog\n"); + skip("can't authorize app in firewall\n"); return; }
- if (firewall_enabled) - { - hr = set_firewall(APP_ADD); - if (hr != S_OK) - { - skip("can't authorize app in firewall %08lx\n", hr); - return; - } - } - hr = CoInitialize(0); ok(hr == S_OK, "CoInitialize failed with %lx\n", hr);
@@ -1028,7 +1018,6 @@ START_TEST(client) CloseHandle(enumevent);
done: - if (firewall_enabled) set_firewall(APP_REMOVE); - + winetest_set_firewall(L"dpnet_client", WINETEST_FW_APP_REMOVE); CoUninitialize(); } diff --git a/dlls/dpnet/tests/dpnet_test.h b/dlls/dpnet/tests/dpnet_test.h index 1de25590bdc..b95dacf4f1c 100644 --- a/dlls/dpnet/tests/dpnet_test.h +++ b/dlls/dpnet/tests/dpnet_test.h @@ -18,15 +18,6 @@ #ifndef __DPNET_PRIVATE_H__ #define __DPNET_PRIVATE_H__
-enum firewall_op -{ - APP_ADD, - APP_REMOVE -}; - -extern BOOL is_firewall_enabled(void) DECLSPEC_HIDDEN; -extern BOOL is_process_elevated(void) DECLSPEC_HIDDEN; -extern HRESULT set_firewall( enum firewall_op op ) DECLSPEC_HIDDEN; extern BOOL is_stub_dll(const char *filename) DECLSPEC_HIDDEN;
#endif diff --git a/dlls/dpnet/tests/server.c b/dlls/dpnet/tests/server.c index 94a9da0d47f..7f92f7e0f3e 100644 --- a/dlls/dpnet/tests/server.c +++ b/dlls/dpnet/tests/server.c @@ -21,8 +21,8 @@
#include <dplay8.h> #define COBJMACROS -#include <netfw.h> #include "wine/test.h" +#include "wine/test_fw.h"
#include "dpnet_test.h"
@@ -269,152 +269,6 @@ static void test_enum_service_providers(void) IDirectPlay8Server_Release(server); }
-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; -} - -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 %08lx\n", hr ); - if (hr != S_OK) goto done; - - hr = INetFwMgr_get_LocalPolicy( mgr, &policy ); - ok( hr == S_OK, "got %08lx\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 %08lx\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); -} - -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 ); - WCHAR path[MAX_PATH]; - - if (!GetModuleFileNameW( NULL, image, MAX_PATH )) - { - SysFreeString( image ); - return E_FAIL; - } - - if(!GetSystemDirectoryW(path, MAX_PATH)) - { - SysFreeString( image ); - return E_FAIL; - } - lstrcatW(path, L"\dpnsvr.exe"); - - init = CoInitializeEx( 0, COINIT_APARTMENTTHREADED ); - - hr = CoCreateInstance( &CLSID_NetFwMgr, NULL, CLSCTX_INPROC_SERVER, &IID_INetFwMgr, - (void **)&mgr ); - ok( hr == S_OK, "got %08lx\n", hr ); - if (hr != S_OK) goto done; - - hr = INetFwMgr_get_LocalPolicy( mgr, &policy ); - ok( hr == S_OK, "got %08lx\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 %08lx\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 %08lx\n", hr ); - if (hr != S_OK) goto done; - - hr = INetFwAuthorizedApplication_put_ProcessImageFileName( app, image ); - if (hr != S_OK) goto done; - - name = SysAllocString( L"dpnet_client" ); - hr = INetFwAuthorizedApplication_put_Name( app, name ); - SysFreeString( name ); - ok( hr == S_OK, "got %08lx\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; - if (hr != S_OK) goto done; - - INetFwAuthorizedApplication_Release( app ); - hr = CoCreateInstance( &CLSID_NetFwAuthorizedApplication, NULL, CLSCTX_INPROC_SERVER, - &IID_INetFwAuthorizedApplication, (void **)&app ); - ok( hr == S_OK, "got %08lx\n", hr ); - if (hr != S_OK) goto done; - - SysFreeString( image ); - image = SysAllocString( path ); - hr = INetFwAuthorizedApplication_put_ProcessImageFileName( app, image ); - if (hr != S_OK) goto done; - - name = SysAllocString( L"dpnet_server" ); - hr = INetFwAuthorizedApplication_put_Name( app, name ); - SysFreeString( name ); - ok( hr == S_OK, "got %08lx\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 ); - -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; -} - /* taken from programs/winetest/main.c */ BOOL is_stub_dll(const char *filename) { @@ -445,7 +299,6 @@ BOOL is_stub_dll(const char *filename) START_TEST(server) { HRESULT hr; - BOOL firewall_enabled; char path[MAX_PATH];
if(!GetSystemDirectoryA(path, MAX_PATH)) @@ -461,22 +314,12 @@ START_TEST(server) return; }
- if ((firewall_enabled = is_firewall_enabled()) && !is_process_elevated()) + if (!winetest_set_firewall(L"dpnet_server", WINETEST_FW_APP_ADD)) { - skip("no privileges, skipping tests to avoid firewall dialog\n"); + skip("can't authorize app in firewall\n"); return; }
- if (firewall_enabled) - { - HRESULT hr = set_firewall(APP_ADD); - if (hr != S_OK) - { - skip("can't authorize app in firewall %08lx\n", hr); - return; - } - } - hr = CoInitialize(0); ok( hr == S_OK, "failed to init com\n"); if (hr != S_OK) @@ -489,5 +332,5 @@ START_TEST(server) CoUninitialize();
done: - if (firewall_enabled) set_firewall(APP_REMOVE); + winetest_set_firewall(L"dpnet_server", WINETEST_FW_APP_REMOVE); } diff --git a/dlls/dpnet/tests/thread.c b/dlls/dpnet/tests/thread.c index 76d71b8f940..1e5c9d0a547 100644 --- a/dlls/dpnet/tests/thread.c +++ b/dlls/dpnet/tests/thread.c @@ -15,11 +15,14 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ + #define WIN32_LEAN_AND_MEAN #include <stdio.h>
#include <dplay8.h> +#define COBJMACROS #include "wine/test.h" +#include "wine/test_fw.h"
#include "dpnet_test.h"
@@ -241,7 +244,6 @@ static void test_singleton(void) START_TEST(thread) { HRESULT hr; - BOOL firewall_enabled; char path[MAX_PATH];
if(!GetSystemDirectoryA(path, MAX_PATH)) @@ -257,30 +259,22 @@ START_TEST(thread) return; }
- if ((firewall_enabled = is_firewall_enabled()) && !is_process_elevated()) + if (!winetest_set_firewall(L"dpnet_thread", WINETEST_FW_APP_ADD)) { - skip("no privileges, skipping tests to avoid firewall dialog\n"); + skip("can't authorize app in firewall\n"); return; }
- if (firewall_enabled) - { - HRESULT hr = set_firewall(APP_ADD); - if (hr != S_OK) - { - skip("can't authorize app in firewall %08lx\n", hr); - return; - } - } - hr = CoInitialize(0); ok(hr == S_OK, "failed to init com\n"); if(hr != S_OK) - return; + goto done;
create_threadpool(); test_enum_hosts(); test_singleton();
CoUninitialize(); +done: + winetest_set_firewall(L"dpnet_thread", WINETEST_FW_APP_REMOVE); }
From: Hans Leidekker hans@codeweavers.com
--- dlls/rpcrt4/tests/rpc.c | 144 ++--------------------------------- dlls/rpcrt4/tests/server.c | 151 ++----------------------------------- 2 files changed, 14 insertions(+), 281 deletions(-)
diff --git a/dlls/rpcrt4/tests/rpc.c b/dlls/rpcrt4/tests/rpc.c index a4653fd603f..38754db957d 100644 --- a/dlls/rpcrt4/tests/rpc.c +++ b/dlls/rpcrt4/tests/rpc.c @@ -25,7 +25,6 @@ #define COBJMACROS #include <ntstatus.h> #define WIN32_NO_STATUS -#include "wine/test.h" #include <windef.h> #include <winbase.h> #include <winnt.h> @@ -34,11 +33,11 @@ #include <oleauto.h> #include <ntsecapi.h> #include <initguid.h> -#include <netfw.h> - #include "rpc.h" #include "rpcdce.h" #include "secext.h" +#include "wine/test.h" +#include "wine/test_fw.h"
typedef unsigned int unsigned32; typedef struct twr_t @@ -1124,132 +1123,11 @@ static void test_endpoint_mapper(RPC_CSTR protseq, RPC_CSTR address) ok(status == RPC_S_OK, "%s: RpcBindingVectorFree failed with error %lu\n", protseq, status); }
-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 %08lx\n", hr ); - if (hr != S_OK) goto done; - - hr = INetFwMgr_get_LocalPolicy( mgr, &policy ); - ok( hr == S_OK, "got %08lx\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 %08lx\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); -} - -enum firewall_op -{ - APP_ADD, - APP_REMOVE -}; - -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 %08lx\n", hr ); - if (hr != S_OK) goto done; - - hr = INetFwMgr_get_LocalPolicy( mgr, &policy ); - ok( hr == S_OK, "got %08lx\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 %08lx\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 %08lx\n", hr ); - if (hr != S_OK) goto done; - - hr = INetFwAuthorizedApplication_put_ProcessImageFileName( app, image ); - if (hr != S_OK) goto done; - - name = SysAllocString( L"rpcrt4_test" ); - hr = INetFwAuthorizedApplication_put_Name( app, name ); - SysFreeString( name ); - ok( hr == S_OK, "got %08lx\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( rpc ) { static unsigned char ncacn_np[] = "ncacn_np"; static unsigned char ncalrpc[] = "ncalrpc"; static unsigned char np_address[] = "."; - BOOL firewall_enabled = is_firewall_enabled();
test_UuidEqual(); test_UuidFromString(); @@ -1260,12 +1138,6 @@ START_TEST( rpc ) test_RpcStringBindingParseA(); test_RpcExceptionFilter();
- if (firewall_enabled && !is_process_elevated()) - { - skip("no privileges, skipping tests to avoid firewall dialog\n"); - return; - } - test_towers(); test_RpcStringBindingFromBinding(); test_RpcBindingFree(); @@ -1273,14 +1145,10 @@ START_TEST( rpc ) test_RpcServerInqDefaultPrincName(); test_RpcServerRegisterAuthInfo();
- if (firewall_enabled) + if (!winetest_set_firewall(L"rpcrt4_test:rpc", WINETEST_FW_APP_ADD)) { - HRESULT hr = set_firewall(APP_ADD); - if (hr != S_OK) - { - skip("can't authorize app in firewall %08lx\n", hr); - return; - } + skip("can't authorize app in firewall\n"); + return; }
test_rpc_ncacn_ip_tcp(); @@ -1288,5 +1156,5 @@ START_TEST( rpc ) test_endpoint_mapper(ncacn_np, np_address); test_endpoint_mapper(ncalrpc, NULL);
- if (firewall_enabled) set_firewall(APP_REMOVE); + winetest_set_firewall(L"rpcrt4_test:rpc", WINETEST_FW_APP_REMOVE); } diff --git a/dlls/rpcrt4/tests/server.c b/dlls/rpcrt4/tests/server.c index 8e87a468f86..38352ca3f73 100644 --- a/dlls/rpcrt4/tests/server.c +++ b/dlls/rpcrt4/tests/server.c @@ -24,8 +24,6 @@ #include <oleauto.h> #include <secext.h> #include <rpcdce.h> -#include <netfw.h> -#include "wine/test.h" #include "server.h" #define SKIP_TYPE_DECLS #include "server_interp.h" @@ -34,6 +32,8 @@ #include <stddef.h> #include <stdio.h> #include <stdlib.h> +#include "wine/test.h" +#include "wine/test_fw.h"
#define PORT "4114" #define PIPE "\pipe\wine_rpcrt4_test" @@ -2491,132 +2491,11 @@ static void test_reconnect(void) ok(RPC_S_OK == RpcBindingFree(&IMixedServer_IfHandle), "RpcBindingFree\n"); }
-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 %08lx\n", hr ); - if (hr != S_OK) goto done; - - hr = INetFwMgr_get_LocalPolicy( mgr, &policy ); - ok( hr == S_OK, "got %08lx\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 %08lx\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); -} - -enum firewall_op -{ - APP_ADD, - APP_REMOVE -}; - -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 %08lx\n", hr ); - if (hr != S_OK) goto done; - - hr = INetFwMgr_get_LocalPolicy( mgr, &policy ); - ok( hr == S_OK, "got %08lx\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 %08lx\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 %08lx\n", hr ); - if (hr != S_OK) goto done; - - hr = INetFwAuthorizedApplication_put_ProcessImageFileName( app, image ); - if (hr != S_OK) goto done; - - name = SysAllocString( L"rpcrt4_test" ); - hr = INetFwAuthorizedApplication_put_Name( app, name ); - SysFreeString( name ); - ok( hr == S_OK, "got %08lx\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(server) { ULONG size = 0; int argc; char **argv; - BOOL firewall_enabled = is_firewall_enabled(), firewall_disabled = FALSE;
InitFunctionPointers(); set_mixed_interface(); @@ -2655,28 +2534,14 @@ START_TEST(server) } else { - if (firewall_enabled) + if (!winetest_set_firewall(L"rpcrt4_test:server", WINETEST_FW_APP_ADD)) { - if (is_process_elevated()) - { - HRESULT hr = set_firewall(APP_ADD); - if (hr == S_OK) - { - firewall_enabled = FALSE; - firewall_disabled = TRUE; - } - else - { - skip("can't authorize app in firewall %08lx\n", hr); - } - } - else - { - trace("no privileges, skipping tests to avoid firewall dialog\n"); - } + skip("can't authorize app in firewall\n"); + HeapFree(GetProcessHeap(), 0, domain_and_user); + return; }
- if (!firewall_enabled) server(); + server();
/* Those tests cause occasional crashes on winxp and win2k3 */ if (GetProcAddress(GetModuleHandleA("rpcrt4.dll"), "RpcExceptionFilter")) @@ -2685,7 +2550,7 @@ START_TEST(server) win_skip("Skipping reconnect tests on too old Windows version\n");
run_client("test listen"); - if (firewall_disabled) set_firewall(APP_REMOVE); + winetest_set_firewall(L"rpcrt4_test:server", WINETEST_FW_APP_REMOVE); }
HeapFree(GetProcessHeap(), 0, domain_and_user);
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=128567
Your paranoid android.
=== w864 (64 bit report) ===
dplayx: dplayx.c:6563: Test failed: DirectPlay create failed: 80040154, expected CLASS_E_NOAGGREGATION dplayx.c:6570: Test failed: DirectPlay create failed: 80040154, expected E_NOINTERFACE dplayx.c:6575: Test failed: DirectPlay create failed: 80040154, expected S_OK 0b44:dplayx: unhandled exception c0000005 at 0000000000420B6F
=== w1064v1507 (64 bit report) ===
dplayx: dplayx.c:6563: Test failed: DirectPlay create failed: 80040154, expected CLASS_E_NOAGGREGATION dplayx.c:6570: Test failed: DirectPlay create failed: 80040154, expected E_NOINTERFACE dplayx.c:6575: Test failed: DirectPlay create failed: 80040154, expected S_OK 0448:dplayx: unhandled exception c0000005 at 0000000000420B6F
=== w1064v1809 (64 bit report) ===
dplayx: dplayx.c:6563: Test failed: DirectPlay create failed: 80040154, expected CLASS_E_NOAGGREGATION dplayx.c:6570: Test failed: DirectPlay create failed: 80040154, expected E_NOINTERFACE dplayx.c:6575: Test failed: DirectPlay create failed: 80040154, expected S_OK 0618:dplayx: unhandled exception c0000005 at 0000000000420B6F
=== w1064_2qxl (64 bit report) ===
dplayx: dplayx.c:6563: Test failed: DirectPlay create failed: 80040154, expected CLASS_E_NOAGGREGATION dplayx.c:6570: Test failed: DirectPlay create failed: 80040154, expected E_NOINTERFACE dplayx.c:6575: Test failed: DirectPlay create failed: 80040154, expected S_OK 1d24:dplayx: unhandled exception c0000005 at 0000000000420B6F
=== w1064_tsign (64 bit report) ===
dplayx: dplayx.c:6563: Test failed: DirectPlay create failed: 80040154, expected CLASS_E_NOAGGREGATION dplayx.c:6570: Test failed: DirectPlay create failed: 80040154, expected E_NOINTERFACE dplayx.c:6575: Test failed: DirectPlay create failed: 80040154, expected S_OK 0008:dplayx: unhandled exception c0000005 at 0000000000420B6F
=== w10pro64 (64 bit report) ===
dplayx: dplayx.c:6563: Test failed: DirectPlay create failed: 80040154, expected CLASS_E_NOAGGREGATION dplayx.c:6570: Test failed: DirectPlay create failed: 80040154, expected E_NOINTERFACE dplayx.c:6575: Test failed: DirectPlay create failed: 80040154, expected S_OK 0420:dplayx: unhandled exception c0000005 at 0000000000420B6F
=== w10pro64_en_AE_u8 (64 bit report) ===
dplayx: dplayx.c:6563: Test failed: DirectPlay create failed: 80040154, expected CLASS_E_NOAGGREGATION dplayx.c:6570: Test failed: DirectPlay create failed: 80040154, expected E_NOINTERFACE dplayx.c:6575: Test failed: DirectPlay create failed: 80040154, expected S_OK 2340:dplayx: unhandled exception c0000005 at 0000000000420B6F
=== w10pro64_ar (64 bit report) ===
dplayx: dplayx.c:6563: Test failed: DirectPlay create failed: 80040154, expected CLASS_E_NOAGGREGATION dplayx.c:6570: Test failed: DirectPlay create failed: 80040154, expected E_NOINTERFACE dplayx.c:6575: Test failed: DirectPlay create failed: 80040154, expected S_OK 2340:dplayx: unhandled exception c0000005 at 0000000000420B6F
=== w10pro64_ja (64 bit report) ===
dplayx: dplayx.c:6563: Test failed: DirectPlay create failed: 80040154, expected CLASS_E_NOAGGREGATION dplayx.c:6570: Test failed: DirectPlay create failed: 80040154, expected E_NOINTERFACE dplayx.c:6575: Test failed: DirectPlay create failed: 80040154, expected S_OK 0608:dplayx: unhandled exception c0000005 at 0000000000420B6F
=== w10pro64_zh_CN (64 bit report) ===
dplayx: dplayx.c:6563: Test failed: DirectPlay create failed: 80040154, expected CLASS_E_NOAGGREGATION dplayx.c:6570: Test failed: DirectPlay create failed: 80040154, expected E_NOINTERFACE dplayx.c:6575: Test failed: DirectPlay create failed: 80040154, expected S_OK 18a8:dplayx: unhandled exception c0000005 at 0000000000420B6F
=== w7u_2qxl (32 bit report) ===
rpcrt4: 006c:server: unhandled exception c0000005 at 75964793 server.c:1228: unhandled exception c0000005 in child process 006c 0534:server: unhandled exception c0000005 at 75964793 server.c:1228: unhandled exception c0000005 in child process 0534 0470:server: unhandled exception c0000005 at 75964793 server.c:1228: unhandled exception c0000005 in child process 0470 0208:server: unhandled exception c0000005 at 75964793 server.c:1228: unhandled exception c0000005 in child process 0208 server.c:2224: Test failed: WaitForSingleObject server.c:2242: Test failed: RpcServerRegisterIf() failed: 87 07c8:server: unhandled exception c0000005 at 75964793 server.c:1228: unhandled exception c0000005 in child process 07c8
=== w7u_el (32 bit report) ===
rpcrt4: 0a7c:server: unhandled exception c0000005 at 754C4793 server.c:1228: unhandled exception c0000005 in child process 0a7c 0a94:server: unhandled exception c0000005 at 754C4793 server.c:1228: unhandled exception c0000005 in child process 0a94 0aac:server: unhandled exception c0000005 at 754C4793 server.c:1228: unhandled exception c0000005 in child process 0aac 0ab8:server: unhandled exception c0000005 at 754C4793 server.c:1228: unhandled exception c0000005 in child process 0ab8 server.c:2224: Test failed: WaitForSingleObject server.c:2242: Test failed: RpcServerRegisterIf() failed: 87 0ac4:server: unhandled exception c0000005 at 754C4793 server.c:1228: unhandled exception c0000005 in child process 0ac4
=== w8 (32 bit report) ===
rpcrt4: 0aa8:server: unhandled exception c0000005 at 7640E2E1 server.c:1228: unhandled exception c0000005 in child process 0aa8 0abc:server: unhandled exception c0000005 at 7640E2E1 server.c:1228: unhandled exception c0000005 in child process 0abc 0ad8:server: unhandled exception c0000005 at 7640E2E1 server.c:1228: unhandled exception c0000005 in child process 0ad8 0b08:server: unhandled exception c0000005 at 7640E2E1 server.c:1228: unhandled exception c0000005 in child process 0b08 server.c:2224: Test failed: WaitForSingleObject server.c:2242: Test failed: RpcServerRegisterIf() failed: 87 0bac:server: unhandled exception c0000005 at 7640E2E1 server.c:1228: unhandled exception c0000005 in child process 0bac
=== w864 (32 bit report) ===
rpcrt4: 0be4:server: unhandled exception c0000005 at 759D7C18 server.c:1228: unhandled exception c0000005 in child process 0be4 0bec:server: unhandled exception c0000005 at 759D7C18 server.c:1228: unhandled exception c0000005 in child process 0bec 080c:server: unhandled exception c0000005 at 759D7C18 server.c:1228: unhandled exception c0000005 in child process 080c 0534:server: unhandled exception c0000005 at 759D7C18 server.c:1228: unhandled exception c0000005 in child process 0534 server.c:2224: Test failed: WaitForSingleObject server.c:2242: Test failed: RpcServerRegisterIf() failed: 87 0580:server: unhandled exception c0000005 at 759D7C18 server.c:1228: unhandled exception c0000005 in child process 0580
=== w1064v1507 (32 bit report) ===
rpcrt4: 05d8:server: unhandled exception c0000005 at 756E68E0 server.c:1228: unhandled exception c0000005 in child process 05d8 0bb8:server: unhandled exception c0000005 at 756E68E0 server.c:1228: unhandled exception c0000005 in child process 0bb8 0964:server: unhandled exception c0000005 at 756E68E0 server.c:1228: unhandled exception c0000005 in child process 0964 0cf8:server: unhandled exception c0000005 at 756E68E0 server.c:1228: unhandled exception c0000005 in child process 0cf8 server.c:2224: Test failed: WaitForSingleObject server.c:2242: Test failed: RpcServerRegisterIf() failed: 87 0f4c:server: unhandled exception c0000005 at 756E68E0 server.c:1228: unhandled exception c0000005 in child process 0f4c
=== w864 (64 bit report) ===
rpcrt4: 0bcc:server: unhandled exception c0000005 at 00007FFDCD53C8E9 server.c:1228: unhandled exception c0000005 in child process 0bcc 0be0:server: unhandled exception c0000005 at 00007FFDCD53C8E9 server.c:1228: unhandled exception c0000005 in child process 0be0 0bf4:server: unhandled exception c0000005 at 00007FFDCD53C8E9 server.c:1228: unhandled exception c0000005 in child process 0bf4 0bfc:server: unhandled exception c0000005 at 00007FFDCD53C8E9 server.c:1228: unhandled exception c0000005 in child process 0bfc server.c:2224: Test failed: WaitForSingleObject server.c:2242: Test failed: RpcServerRegisterIf() failed: 87 0120:server: unhandled exception c0000005 at 00007FFDCD53C8E9 server.c:1228: unhandled exception c0000005 in child process 0120
=== w1064v1507 (64 bit report) ===
rpcrt4: 0c9c:server: unhandled exception c0000005 at 00007FFC1249E16E server.c:1228: unhandled exception c0000005 in child process 0c9c 0b88:server: unhandled exception c0000005 at 00007FFC1249E16E server.c:1228: unhandled exception c0000005 in child process 0b88 0ae4:server: unhandled exception c0000005 at 00007FFC1249E16E server.c:1228: unhandled exception c0000005 in child process 0ae4 0180:server: unhandled exception c0000005 at 00007FFC1249E16E server.c:1228: unhandled exception c0000005 in child process 0180 server.c:2224: Test failed: WaitForSingleObject server.c:2242: Test failed: RpcServerRegisterIf() failed: 87 08f0:server: unhandled exception c0000005 at 00007FFC1249E16E server.c:1228: unhandled exception c0000005 in child process 08f0
=== w1064_2qxl (64 bit report) ===
rpcrt4: server.c:2265: Test failed: RpcBindingFree
Jinoh Kang (@iamahuman) commented about include/wine/test_fw.h:
- 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"
```suggestion:-2+0 #define COBJMACROS #include "windef.h" #include "winbase.h" #include "initguid.h" #include "netfw.h" ```
I left the COBJMACROS define out because the test may need it earlier. It may also need to include initguid.h earlier or not at all, to avoid linker errors when another file already includes it.
I left the COBJMACROS define out because the test may need it earlier.
IMHO a redefinition won't hurt, since C permits redefinition of a macro with the same definition.
It may also need to include initguid.h earlier or not at all, to avoid linker errors when another file already includes it.
Right, the test might import the GUID symbols via another source.
On Mon Jan 23 16:44:21 2023 +0000, Jinoh Kang wrote:
I left the COBJMACROS define out because the test may need it earlier.
IMHO a redefinition won't hurt, since C permits redefinition of a macro with the same definition.
It may also need to include initguid.h earlier or not at all, to avoid
linker errors when another file already includes it. Right, the test might import the GUID symbols via another source.
A redefinition won't hurt, but I do think it's more clear to have an explicit define at the top level.
Jinoh Kang (@iamahuman) commented about include/wine/test_fw.h:
+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 );
There is an [anecdotal evidence][1] that claims that you cannot use `SysAllocStringLen` without having COM initialized first; I'm not sure if I can trust it, so take it with a grain of salt.
[1]: https://stackoverflow.com/questions/40330569/sysallocstring-sysfreestring-co...
On Tue Jan 24 17:06:45 2023 +0000, Jinoh Kang wrote:
There is an [anecdotal evidence][1] that claims that you cannot use `SysAllocStringLen` without having COM initialized first; I'm not sure if I can trust it, so take it with a grain of salt. [1]: https://stackoverflow.com/questions/40330569/sysallocstring-sysfreestring-co...
I don't trust it :-)
On Thu Jan 26 11:37:18 2023 +0000, Hans Leidekker wrote:
I don't trust it :-)
We've had oleaut32 tests that don't load COM for ages. I don't think this is a concern.