Commit 7e7ad5a7 authored by Hans Leidekker's avatar Hans Leidekker Committed by Alexandre Julliard

dpnet/tests: Register a firewall exception for the client test.

parent e017d9bc
TESTDLL = dpnet.dll TESTDLL = dpnet.dll
IMPORTS = dxguid uuid dpnet ole32 version IMPORTS = dxguid uuid dpnet ole32 oleaut32 version advapi32
C_SRCS = \ C_SRCS = \
address.c \ address.c \
......
...@@ -22,6 +22,9 @@ ...@@ -22,6 +22,9 @@
#include <dplay8.h> #include <dplay8.h>
#include <dplobby8.h> #include <dplobby8.h>
#include <winver.h>
#define COBJMACROS
#include <netfw.h>
#include "wine/test.h" #include "wine/test.h"
static IDirectPlay8Peer* peer = NULL; static IDirectPlay8Peer* peer = NULL;
...@@ -606,6 +609,127 @@ static void test_cleanup_dp_peer(void) ...@@ -606,6 +609,127 @@ static void test_cleanup_dp_peer(void)
CoUninitialize(); CoUninitialize();
} }
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 %08x\n", hr );
if (hr != S_OK) goto done;
hr = INetFwMgr_get_LocalPolicy( mgr, &policy );
ok( hr == S_OK, "got %08x\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 %08x\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 )
{
static const WCHAR testW[] = {'d','p','n','e','t','_','t','e','s','t',0};
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 %08x\n", hr );
if (hr != S_OK) goto done;
hr = INetFwMgr_get_LocalPolicy( mgr, &policy );
ok( hr == S_OK, "got %08x\n", hr );
if (hr != S_OK) goto done;
hr = INetFwPolicy_get_CurrentProfile( policy, &profile );
if (hr != S_OK) goto done;
INetFwProfile_get_AuthorizedApplications( profile, &apps );
ok( hr == S_OK, "got %08x\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 %08x\n", hr );
if (hr != S_OK) goto done;
hr = INetFwAuthorizedApplication_put_ProcessImageFileName( app, image );
if (hr != S_OK) goto done;
name = SysAllocString( testW );
hr = INetFwAuthorizedApplication_put_Name( app, name );
SysFreeString( name );
ok( hr == S_OK, "got %08x\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 */ /* taken from programs/winetest/main.c */
static BOOL is_stub_dll(const char *filename) static BOOL is_stub_dll(const char *filename)
{ {
...@@ -634,6 +758,8 @@ static BOOL is_stub_dll(const char *filename) ...@@ -634,6 +758,8 @@ static BOOL is_stub_dll(const char *filename)
START_TEST(client) START_TEST(client)
{ {
BOOL firewall_enabled;
if (!winetest_interactive && if (!winetest_interactive &&
(is_stub_dll("c:\\windows\\system32\\dpnet.dll") || (is_stub_dll("c:\\windows\\system32\\dpnet.dll") ||
is_stub_dll("c:\\windows\\syswow64\\dpnet.dll"))) is_stub_dll("c:\\windows\\syswow64\\dpnet.dll")))
...@@ -642,8 +768,23 @@ START_TEST(client) ...@@ -642,8 +768,23 @@ START_TEST(client)
return; return;
} }
if(!test_init_dp()) if ((firewall_enabled = is_firewall_enabled()) && !is_process_elevated())
{
skip("no privileges, skipping tests to avoid firewall dialog\n");
return; return;
}
if (firewall_enabled)
{
HRESULT hr = set_firewall(APP_ADD);
if (hr != S_OK)
{
skip("can't authorize app in firewall %08x\n", hr);
return;
}
}
if (!test_init_dp()) goto done;
test_enum_service_providers(); test_enum_service_providers();
test_enum_hosts(); test_enum_hosts();
...@@ -659,4 +800,7 @@ START_TEST(client) ...@@ -659,4 +800,7 @@ START_TEST(client)
test_get_sp_caps_peer(); test_get_sp_caps_peer();
test_player_info_peer(); test_player_info_peer();
test_cleanup_dp_peer(); test_cleanup_dp_peer();
done:
if (firewall_enabled) set_firewall(APP_REMOVE);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment