ReactOS 0.4.16-dev-321-g63bb46a
policy.c
Go to the documentation of this file.
1/*
2 * Copyright 2016 Alistair Leslie-Hughes
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 */
18#define COBJMACROS
19#include <stdio.h>
20
21#include "windows.h"
22#include "ole2.h"
23#include "oleauto.h"
24#include "olectl.h"
25#include "dispex.h"
26
27#include "wine/test.h"
28
29#include "netfw.h"
30#include "natupnp.h"
31
32static void test_policy2_rules(INetFwPolicy2 *policy2)
33{
34 HRESULT hr;
35 INetFwRules *rules, *rules2;
36 INetFwServiceRestriction *restriction;
37
38 hr = INetFwPolicy2_QueryInterface(policy2, &IID_INetFwRules, (void**)&rules);
39 ok(hr == E_NOINTERFACE, "got 0x%08x\n", hr);
40
41 hr = INetFwPolicy2_get_Rules(policy2, &rules);
42 ok(hr == S_OK, "got %08x\n", hr);
43
44 hr = INetFwPolicy2_get_Rules(policy2, &rules2);
45 ok(hr == S_OK, "got %08x\n", hr);
46 ok(rules == rules2, "Different pointers\n");
47
48 hr = INetFwPolicy2_get_ServiceRestriction(policy2, &restriction);
49 todo_wine ok(hr == S_OK, "got %08x\n", hr);
50 if(hr == S_OK)
51 {
52 INetFwRules *rules3;
53
54 hr = INetFwServiceRestriction_get_Rules(restriction, &rules3);
55 ok(hr == S_OK, "got %08x\n", hr);
56 ok(rules != rules3, "same pointers\n");
57
58 if(rules3)
59 INetFwRules_Release(rules3);
60 INetFwServiceRestriction_Release(restriction);
61 }
62
63 hr = INetFwRules_get__NewEnum(rules, NULL);
64 ok(hr == E_POINTER, "got %08x\n", hr);
65
66 INetFwRules_Release(rules);
67 INetFwRules_Release(rules2);
68}
69
70static void test_interfaces(void)
71{
72 INetFwMgr *manager;
74 INetFwPolicy2 *policy2;
75 HRESULT hr;
76
77 hr = CoCreateInstance(&CLSID_NetFwMgr, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
78 &IID_INetFwMgr, (void**)&manager);
79 ok(hr == S_OK, "NetFwMgr create failed: %08x\n", hr);
80
81 hr = INetFwMgr_QueryInterface(manager, &IID_INetFwPolicy, (void**)&policy);
82 ok(hr == E_NOINTERFACE, "got 0x%08x\n", hr);
83
84 hr = INetFwMgr_QueryInterface(manager, &IID_INetFwPolicy2, (void**)&policy2);
85 ok(hr == E_NOINTERFACE, "got 0x%08x\n", hr);
86
87 hr = INetFwMgr_get_LocalPolicy(manager, &policy);
88 ok(hr == S_OK, "got 0x%08x\n", hr);
89
90 hr = INetFwPolicy_QueryInterface(policy, &IID_INetFwPolicy2, (void**)&policy2);
91 ok(hr == E_NOINTERFACE, "got 0x%08x\n", hr);
92
93 INetFwPolicy_Release(policy);
94
95 hr = CoCreateInstance(&CLSID_NetFwPolicy2, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
96 &IID_INetFwPolicy2, (void**)&policy2);
97 if(hr == S_OK)
98 {
99 test_policy2_rules(policy2);
100
101 INetFwPolicy2_Release(policy2);
102 }
103 else
104 win_skip("NetFwPolicy2 object is not supported: %08x\n", hr);
105
106 INetFwMgr_Release(manager);
107}
108
110{
112 static WCHAR empty[] = {0};
114 WCHAR fullpath[MAX_PATH];
115 WCHAR netpath[MAX_PATH];
117 HRESULT hr;
118 BSTR bstr;
119 DWORD sz;
120
121 hr = CoCreateInstance(&CLSID_NetFwAuthorizedApplication, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
122 &IID_INetFwAuthorizedApplication, (void**)&app);
123 ok(hr == S_OK, "got: %08x\n", hr);
124
126 ok(hr, "GetModuleFileName failed: %u\n", GetLastError());
127
128 hr = INetFwAuthorizedApplication_get_ProcessImageFileName(app, NULL);
129 ok(hr == E_POINTER, "got: %08x\n", hr);
130
131 hr = INetFwAuthorizedApplication_get_ProcessImageFileName(app, &bstr);
132 ok(hr == S_OK || hr == HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY), "got: %08x\n", hr);
133 ok(!bstr, "got: %s\n", wine_dbgstr_w(bstr));
134
135 hr = INetFwAuthorizedApplication_put_ProcessImageFileName(app, NULL);
136 ok(hr == E_INVALIDARG || hr == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), "got: %08x\n", hr);
137
138 hr = INetFwAuthorizedApplication_put_ProcessImageFileName(app, empty);
139 ok(hr == E_INVALIDARG || hr == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), "got: %08x\n", hr);
140
141 bstr = SysAllocString(image);
142 hr = INetFwAuthorizedApplication_put_ProcessImageFileName(app, bstr);
143 ok(hr == S_OK, "got: %08x\n", hr);
144 SysFreeString(bstr);
145
146 GetFullPathNameW(image, ARRAY_SIZE(fullpath), fullpath, NULL);
147 GetLongPathNameW(fullpath, fullpath, ARRAY_SIZE(fullpath));
148
149 info = (UNIVERSAL_NAME_INFOW *)&netpath;
150 sz = sizeof(netpath);
152 if (hr != NO_ERROR)
153 {
154 info->lpUniversalName = netpath + sizeof(*info)/sizeof(WCHAR);
155 lstrcpyW(info->lpUniversalName, fullpath);
156 }
157
158 hr = INetFwAuthorizedApplication_get_ProcessImageFileName(app, &bstr);
159 ok(hr == S_OK, "got: %08x\n", hr);
160 ok(!lstrcmpW(bstr,info->lpUniversalName), "expected %s, got %s\n",
161 wine_dbgstr_w(info->lpUniversalName), wine_dbgstr_w(bstr));
162 SysFreeString(bstr);
163
164 INetFwAuthorizedApplication_Release(app);
165}
166
167static void test_IUPnPNAT(void)
168{
169 IUPnPNAT *nat;
170 IStaticPortMappingCollection *static_ports;
172 INATEventManager *manager;
173 IProvideClassInfo *provider;
174 HRESULT hr;
175
176 hr = CoCreateInstance(&CLSID_UPnPNAT, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER, &IID_IUPnPNAT, (void**)&nat);
177 ok(hr == S_OK, "got: %08x\n", hr);
178
179 hr = IUPnPNAT_QueryInterface(nat, &IID_IProvideClassInfo, (void**)&provider);
180 ok(hr == E_NOINTERFACE, "got: %08x\n", hr);
181
182 hr = IUPnPNAT_get_StaticPortMappingCollection(nat, &static_ports);
183 todo_wine ok(hr == S_OK, "got: %08x\n", hr);
184 if(hr == S_OK && static_ports)
185 IStaticPortMappingCollection_Release(static_ports);
186
187 hr = IUPnPNAT_get_DynamicPortMappingCollection(nat, &dync_ports);
188 ok(hr == S_OK || hr == E_NOTIMPL /* Windows 8.1 */, "got: %08x\n", hr);
189 if(hr == S_OK && dync_ports)
190 IDynamicPortMappingCollection_Release(dync_ports);
191
192 hr = IUPnPNAT_get_NATEventManager(nat, &manager);
193 todo_wine ok(hr == S_OK, "got: %08x\n", hr);
194 if(hr == S_OK && manager)
195 INATEventManager_Release(manager);
196
197 IUPnPNAT_Release(nat);
198}
199
201{
202 INetFwMgr *manager;
203 HRESULT hr;
204
206
207 hr = CoCreateInstance(&CLSID_NetFwMgr, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
208 &IID_INetFwMgr, (void**)&manager);
209 if(FAILED(hr))
210 {
211 win_skip("NetFwMgr object is not supported: %08x\n", hr);
213 return;
214 }
215
216 INetFwMgr_Release(manager);
217
221
223}
WINBASEAPI _Check_return_ _Out_ AppPolicyProcessTerminationMethod * policy
Definition: appmodel.h:47
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
#define ARRAY_SIZE(A)
Definition: main.h:20
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define NO_ERROR
Definition: dderror.h:5
#define E_INVALIDARG
Definition: ddrawi.h:101
#define E_NOTIMPL
Definition: ddrawi.h:99
#define NULL
Definition: types.h:112
static const WCHAR empty[]
Definition: main.c:47
OLECHAR * BSTR
Definition: compat.h:2293
#define MAX_PATH
Definition: compat.h:34
#define lstrcpyW
Definition: compat.h:749
DWORD WINAPI GetModuleFileNameW(HINSTANCE hModule, LPWSTR lpFilename, DWORD nSize)
Definition: loader.c:600
DWORD WINAPI GetLongPathNameW(IN LPCWSTR lpszShortPath, OUT LPWSTR lpszLongPath, IN DWORD cchBuffer)
Definition: path.c:1456
DWORD WINAPI GetFullPathNameW(IN LPCWSTR lpFileName, IN DWORD nBufferLength, OUT LPWSTR lpBuffer, OUT LPWSTR *lpFilePart)
Definition: path.c:1106
int WINAPI lstrcmpW(LPCWSTR str1, LPCWSTR str2)
Definition: locale.c:4243
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
Definition: compobj.c:3325
HRESULT WINAPI CoInitialize(LPVOID lpReserved)
Definition: compobj.c:1964
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: compobj.c:2067
unsigned long DWORD
Definition: ntddk_ex.h:95
#define S_OK
Definition: intsafe.h:52
#define FAILED(hr)
Definition: intsafe.h:51
#define wine_dbgstr_w
Definition: kernel32.h:34
static void test_IUPnPNAT(void)
Definition: policy.c:167
static void test_policy2_rules(INetFwPolicy2 *policy2)
Definition: policy.c:32
static void test_NetFwAuthorizedApplication(void)
Definition: policy.c:109
static void test_interfaces(void)
Definition: policy.c:70
#define todo_wine
Definition: custom.c:89
BSTR WINAPI SysAllocString(LPCOLESTR str)
Definition: oleaut.c:238
void WINAPI DECLSPEC_HOTPATCH SysFreeString(BSTR str)
Definition: oleaut.c:271
const GUID IID_IProvideClassInfo
#define win_skip
Definition: test.h:163
HRESULT hr
Definition: shlfolder.c:183
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define E_NOINTERFACE
Definition: winerror.h:2364
#define ERROR_PATH_NOT_FOUND
Definition: winerror.h:106
#define HRESULT_FROM_WIN32(x)
Definition: winerror.h:92
#define E_POINTER
Definition: winerror.h:2365
#define UNIVERSAL_NAME_INFO_LEVEL
Definition: winnetwk.h:151
DWORD WINAPI WNetGetUniversalNameW(LPCWSTR lpLocalPath, DWORD dwInfoLevel, LPVOID lpBuffer, LPDWORD lpBufferSize)
Definition: wnet.c:2779
__wchar_t WCHAR
Definition: xmlstorage.h:180