-- v4: 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 8602dd51e42..1118d21e49b 100644 --- a/include/Makefile.in +++ b/include/Makefile.in @@ -860,6 +860,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 ba0f73194f6..6dbc57871da 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/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/wsdapi/tests/discovery.c | 151 +++------------------------------- 1 file changed, 11 insertions(+), 140 deletions(-)
diff --git a/dlls/wsdapi/tests/discovery.c b/dlls/wsdapi/tests/discovery.c index 01b28a3c1ad..ac5e7509147 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,14 @@ 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; + BOOL authorized;
- if (firewall_enabled) + if (!(authorized = 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 +1286,5 @@ START_TEST(discovery) UnPublish_tests();
CoUninitialize(); - if (firewall_enabled) set_firewall(APP_REMOVE); + if (authorized) winetest_set_firewall(L"wsdapi_test", WINETEST_FW_APP_REMOVE); }
From: Hans Leidekker hans@codeweavers.com
--- dlls/rpcrt4/tests/rpc.c | 145 ++-------------------------------- dlls/rpcrt4/tests/server.c | 154 ++----------------------------------- 2 files changed, 15 insertions(+), 284 deletions(-)
diff --git a/dlls/rpcrt4/tests/rpc.c b/dlls/rpcrt4/tests/rpc.c index a4653fd603f..e21fa6702d7 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,12 @@ 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(); + BOOL authorized;
test_UuidEqual(); test_UuidFromString(); @@ -1260,12 +1139,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 +1146,10 @@ START_TEST( rpc ) test_RpcServerInqDefaultPrincName(); test_RpcServerRegisterAuthInfo();
- if (firewall_enabled) + if (!(authorized = 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 +1157,5 @@ START_TEST( rpc ) test_endpoint_mapper(ncacn_np, np_address); test_endpoint_mapper(ncalrpc, NULL);
- if (firewall_enabled) set_firewall(APP_REMOVE); + if (authorized) 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..c1051028662 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,12 @@ 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; + BOOL authorized;
InitFunctionPointers(); set_mixed_interface(); @@ -2655,28 +2535,10 @@ START_TEST(server) } else { - if (firewall_enabled) - { - 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"); - } - } - - if (!firewall_enabled) server(); + if (!(authorized = winetest_set_firewall(L"rpcrt4_test:server", WINETEST_FW_APP_ADD))) + skip("can't authorize app in firewall, skipping server tests\n"); + else + server();
/* Those tests cause occasional crashes on winxp and win2k3 */ if (GetProcAddress(GetModuleHandleA("rpcrt4.dll"), "RpcExceptionFilter")) @@ -2685,7 +2547,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); + if (authorized) 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=129077
Your paranoid android.
=== w7u_2qxl (32 bit report) ===
rpcrt4: 0518:server: unhandled exception c0000005 at 75DA4793 server.c:1228: unhandled exception c0000005 in child process 0518 04b4:server: unhandled exception c0000005 at 75DA4793 server.c:1228: unhandled exception c0000005 in child process 04b4 0110:server: unhandled exception c0000005 at 75DA4793 server.c:1228: unhandled exception c0000005 in child process 0110 0580:server: unhandled exception c0000005 at 75DA4793 server.c:1228: unhandled exception c0000005 in child process 0580 server.c:2224: Test failed: WaitForSingleObject server.c:2242: Test failed: RpcServerRegisterIf() failed: 87 04f0:server: unhandled exception c0000005 at 75DA4793 server.c:1228: unhandled exception c0000005 in child process 04f0
=== w7u_el (32 bit report) ===
rpcrt4: 0a84:server: unhandled exception c0000005 at 754C4793 server.c:1228: unhandled exception c0000005 in child process 0a84 0a98:server: unhandled exception c0000005 at 754C4793 server.c:1228: unhandled exception c0000005 in child process 0a98 0ab0:server: unhandled exception c0000005 at 754C4793 server.c:1228: unhandled exception c0000005 in child process 0ab0 0abc:server: unhandled exception c0000005 at 754C4793 server.c:1228: unhandled exception c0000005 in child process 0abc server.c:2224: Test failed: WaitForSingleObject server.c:2242: Test failed: RpcServerRegisterIf() failed: 87 0acc:server: unhandled exception c0000005 at 754C4793 server.c:1228: unhandled exception c0000005 in child process 0acc
=== w8 (32 bit report) ===
rpcrt4: 0b0c:server: unhandled exception c0000005 at 7640E2E1 server.c:1228: unhandled exception c0000005 in child process 0b0c 0b1c:server: unhandled exception c0000005 at 7640E2E1 server.c:1228: unhandled exception c0000005 in child process 0b1c 0b40:server: unhandled exception c0000005 at 7640E2E1 server.c:1228: unhandled exception c0000005 in child process 0b40 0b50:server: unhandled exception c0000005 at 7640E2E1 server.c:1228: unhandled exception c0000005 in child process 0b50 server.c:2224: Test failed: WaitForSingleObject server.c:2242: Test failed: RpcServerRegisterIf() failed: 87 0bc8:server: unhandled exception c0000005 at 7640E2E1 server.c:1228: unhandled exception c0000005 in child process 0bc8
=== w864 (32 bit report) ===
rpcrt4: 0bc0:server: unhandled exception c0000005 at 759D7C18 server.c:1228: unhandled exception c0000005 in child process 0bc0 0bc8:server: unhandled exception c0000005 at 759D7C18 server.c:1228: unhandled exception c0000005 in child process 0bc8 0be0:server: unhandled exception c0000005 at 759D7C18 server.c:1228: unhandled exception c0000005 in child process 0be0 0be8:server: unhandled exception c0000005 at 759D7C18 server.c:1228: unhandled exception c0000005 in child process 0be8 server.c:2224: Test failed: WaitForSingleObject server.c:2242: Test failed: RpcServerRegisterIf() failed: 87 05ac:server: unhandled exception c0000005 at 759D7C18 server.c:1228: unhandled exception c0000005 in child process 05ac
=== w1064v1507 (32 bit report) ===
rpcrt4: 08b8:server: unhandled exception c0000005 at 756E68E0 server.c:1228: unhandled exception c0000005 in child process 08b8 01d0:server: unhandled exception c0000005 at 756E68E0 server.c:1228: unhandled exception c0000005 in child process 01d0 09b0:server: unhandled exception c0000005 at 756E68E0 server.c:1228: unhandled exception c0000005 in child process 09b0 09a0:server: unhandled exception c0000005 at 756E68E0 server.c:1228: unhandled exception c0000005 in child process 09a0 server.c:2224: Test failed: WaitForSingleObject server.c:2242: Test failed: RpcServerRegisterIf() failed: 87 0760:server: unhandled exception c0000005 at 756E68E0 server.c:1228: unhandled exception c0000005 in child process 0760
=== w864 (64 bit report) ===
rpcrt4: 0b9c:server: unhandled exception c0000005 at 00007FFDCD53C8E9 server.c:1228: unhandled exception c0000005 in child process 0b9c 0bf4:server: unhandled exception c0000005 at 00007FFDCD53C8E9 server.c:1228: unhandled exception c0000005 in child process 0bf4 0808:server: unhandled exception c0000005 at 00007FFDCD53C8E9 server.c:1228: unhandled exception c0000005 in child process 0808 0534:server: unhandled exception c0000005 at 00007FFDCD53C8E9 server.c:1228: unhandled exception c0000005 in child process 0534 server.c:2224: Test failed: WaitForSingleObject server.c:2242: Test failed: RpcServerRegisterIf() failed: 87 054c:server: unhandled exception c0000005 at 00007FFDCD53C8E9 server.c:1228: unhandled exception c0000005 in child process 054c
=== w1064v1507 (64 bit report) ===
rpcrt4: 0c90:server: unhandled exception c0000005 at 00007FFC1249E16E server.c:1228: unhandled exception c0000005 in child process 0c90 0a00:server: unhandled exception c0000005 at 00007FFC1249E16E server.c:1228: unhandled exception c0000005 in child process 0a00 0188:server: unhandled exception c0000005 at 00007FFC1249E16E server.c:1228: unhandled exception c0000005 in child process 0188 0760:server: unhandled exception c0000005 at 00007FFC1249E16E server.c:1228: unhandled exception c0000005 in child process 0760 server.c:2224: Test failed: WaitForSingleObject server.c:2242: Test failed: RpcServerRegisterIf() failed: 87 0f8c:server: unhandled exception c0000005 at 00007FFC1249E16E server.c:1228: unhandled exception c0000005 in child process 0f8c