dpnet/tests: Register firewall exceptions for the server test.
Signed-off-by: Hans Leidekker <hans@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
7e7ad5a79d
commit
0aaf1d9f6c
|
@ -20,6 +20,8 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#include <dplay8.h>
|
||||
#define COBJMACROS
|
||||
#include <netfw.h>
|
||||
#include "wine/test.h"
|
||||
|
||||
/* {CD0C3D4B-E15E-4CF2-9EA8-6E1D6548C5A5} */
|
||||
|
@ -180,6 +182,164 @@ static void test_server_info(void)
|
|||
}
|
||||
}
|
||||
|
||||
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 dpnsvrW[] =
|
||||
{'c',':','\\','w','i','n','d','o','w','s','\\','s','y','s','t','e','m','3','2','\\',
|
||||
'd','p','n','s','v','r','.','e','x','e',0};
|
||||
static const WCHAR dpnsvr_wow64W[] =
|
||||
{'c',':','\\','w','i','n','d','o','w','s','\\','s','y','s','w','o','w','6','4','\\',
|
||||
'd','p','n','s','v','r','.','e','x','e',0};
|
||||
static const WCHAR clientW[] =
|
||||
{'d','p','n','e','t','_','c','l','i','e','n','t',0};
|
||||
static const WCHAR serverW[] =
|
||||
{'d','p','n','e','t','_','s','e','r','v','e','r',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 );
|
||||
BOOL is_wow64;
|
||||
|
||||
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( clientW );
|
||||
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;
|
||||
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 %08x\n", hr );
|
||||
if (hr != S_OK) goto done;
|
||||
|
||||
SysFreeString( image );
|
||||
IsWow64Process( GetCurrentProcess(), &is_wow64 );
|
||||
image = is_wow64 ? SysAllocString( dpnsvr_wow64W ) : SysAllocString( dpnsvrW );
|
||||
hr = INetFwAuthorizedApplication_put_ProcessImageFileName( app, image );
|
||||
if (hr != S_OK) goto done;
|
||||
|
||||
name = SysAllocString( serverW );
|
||||
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 */
|
||||
static BOOL is_stub_dll(const char *filename)
|
||||
{
|
||||
|
@ -209,6 +369,7 @@ static BOOL is_stub_dll(const char *filename)
|
|||
START_TEST(server)
|
||||
{
|
||||
HRESULT hr;
|
||||
BOOL firewall_enabled;
|
||||
|
||||
if (!winetest_interactive &&
|
||||
(is_stub_dll("c:\\windows\\system32\\dpnet.dll") ||
|
||||
|
@ -218,13 +379,32 @@ START_TEST(server)
|
|||
return;
|
||||
}
|
||||
|
||||
if ((firewall_enabled = is_firewall_enabled()) && !is_process_elevated())
|
||||
{
|
||||
skip("no privileges, skipping tests to avoid firewall dialog\n");
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
hr = CoInitialize(0);
|
||||
ok( hr == S_OK, "failed to init com\n");
|
||||
if (hr != S_OK)
|
||||
return;
|
||||
goto done;
|
||||
|
||||
create_server();
|
||||
test_server_info();
|
||||
|
||||
CoUninitialize();
|
||||
|
||||
done:
|
||||
if (firewall_enabled) set_firewall(APP_REMOVE);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue