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);