ReactOS 0.4.17-dev-966-gf06eace
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
32#ifndef __REACTOS__
34{
35 IUnknown_AddRef(unk);
36 return IUnknown_Release(unk);
37}
38#endif
39
40static void test_policy2_rules(INetFwPolicy2 *policy2)
41{
42 HRESULT hr;
43 INetFwRules *rules, *rules2;
44 INetFwServiceRestriction *restriction;
45
46 hr = INetFwPolicy2_QueryInterface(policy2, &IID_INetFwRules, (void**)&rules);
47 ok(hr == E_NOINTERFACE, "got 0x%08lx\n", hr);
48
49 hr = INetFwPolicy2_get_Rules(policy2, &rules);
50 ok(hr == S_OK, "got %08lx\n", hr);
51
52 hr = INetFwPolicy2_get_Rules(policy2, &rules2);
53 ok(hr == S_OK, "got %08lx\n", hr);
54 ok(rules == rules2, "Different pointers\n");
55
56 hr = INetFwPolicy2_get_ServiceRestriction(policy2, &restriction);
57 todo_wine ok(hr == S_OK, "got %08lx\n", hr);
58 if(hr == S_OK)
59 {
60 INetFwRules *rules3;
61
62 hr = INetFwServiceRestriction_get_Rules(restriction, &rules3);
63 ok(hr == S_OK, "got %08lx\n", hr);
64 ok(rules != rules3, "same pointers\n");
65
66 if(rules3)
67 INetFwRules_Release(rules3);
68 INetFwServiceRestriction_Release(restriction);
69 }
70
71#ifndef __REACTOS__
72 hr = INetFwRules_get__NewEnum(rules, NULL);
73 ok(hr == E_POINTER, "got %08lx\n", hr);
74#endif
75
76 INetFwRules_Release(rules);
77 INetFwRules_Release(rules2);
78}
79
80static void test_interfaces(void)
81{
82 INetFwMgr *manager;
84 INetFwPolicy2 *policy2;
85 HRESULT hr;
86
87 hr = CoCreateInstance(&CLSID_NetFwMgr, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
88 &IID_INetFwMgr, (void**)&manager);
89 ok(hr == S_OK, "NetFwMgr create failed: %08lx\n", hr);
90
91 hr = INetFwMgr_QueryInterface(manager, &IID_INetFwPolicy, (void**)&policy);
92 ok(hr == E_NOINTERFACE, "got 0x%08lx\n", hr);
93
94 hr = INetFwMgr_QueryInterface(manager, &IID_INetFwPolicy2, (void**)&policy2);
95 ok(hr == E_NOINTERFACE, "got 0x%08lx\n", hr);
96
97 hr = INetFwMgr_get_LocalPolicy(manager, &policy);
98 ok(hr == S_OK, "got 0x%08lx\n", hr);
99
100 hr = INetFwPolicy_QueryInterface(policy, &IID_INetFwPolicy2, (void**)&policy2);
101 ok(hr == E_NOINTERFACE, "got 0x%08lx\n", hr);
102
103 INetFwPolicy_Release(policy);
104
105 hr = CoCreateInstance(&CLSID_NetFwPolicy2, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
106 &IID_INetFwPolicy2, (void**)&policy2);
107 if(hr == S_OK)
108 {
109 test_policy2_rules(policy2);
110
111 INetFwPolicy2_Release(policy2);
112 }
113 else
114 win_skip("NetFwPolicy2 object is not supported: %08lx\n", hr);
115
116 INetFwMgr_Release(manager);
117}
118
120{
122 static WCHAR empty[] = L"";
124 WCHAR fullpath[MAX_PATH];
125 WCHAR netpath[MAX_PATH];
127 HRESULT hr;
128 BSTR bstr;
129 DWORD sz;
130
131 hr = CoCreateInstance(&CLSID_NetFwAuthorizedApplication, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
132 &IID_INetFwAuthorizedApplication, (void**)&app);
133 ok(hr == S_OK, "got: %08lx\n", hr);
134
136 ok(hr, "GetModuleFileName failed: %lu\n", GetLastError());
137
138 hr = INetFwAuthorizedApplication_get_ProcessImageFileName(app, NULL);
139 ok(hr == E_POINTER, "got: %08lx\n", hr);
140
141 hr = INetFwAuthorizedApplication_get_ProcessImageFileName(app, &bstr);
142 ok(hr == S_OK || hr == HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY), "got: %08lx\n", hr);
143 ok(!bstr, "got: %s\n", wine_dbgstr_w(bstr));
144
145 hr = INetFwAuthorizedApplication_put_ProcessImageFileName(app, NULL);
146 ok(hr == E_INVALIDARG || hr == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), "got: %08lx\n", hr);
147
148 hr = INetFwAuthorizedApplication_put_ProcessImageFileName(app, empty);
149 ok(hr == E_INVALIDARG || hr == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), "got: %08lx\n", hr);
150
151 bstr = SysAllocString(image);
152 hr = INetFwAuthorizedApplication_put_ProcessImageFileName(app, bstr);
153 ok(hr == S_OK, "got: %08lx\n", hr);
154 SysFreeString(bstr);
155
156 GetFullPathNameW(image, ARRAY_SIZE(fullpath), fullpath, NULL);
157 GetLongPathNameW(fullpath, fullpath, ARRAY_SIZE(fullpath));
158
159 info = (UNIVERSAL_NAME_INFOW *)&netpath;
160 sz = sizeof(netpath);
162 if (hr != NO_ERROR)
163 {
164 info->lpUniversalName = netpath + sizeof(*info)/sizeof(WCHAR);
165 lstrcpyW(info->lpUniversalName, fullpath);
166 }
167
168 hr = INetFwAuthorizedApplication_get_ProcessImageFileName(app, &bstr);
169 ok(hr == S_OK, "got: %08lx\n", hr);
170 ok(!lstrcmpW(bstr,info->lpUniversalName), "expected %s, got %s\n",
171 wine_dbgstr_w(info->lpUniversalName), wine_dbgstr_w(bstr));
172 SysFreeString(bstr);
173
174 INetFwAuthorizedApplication_Release(app);
175}
176
177#ifndef __REACTOS__
179{
180 LONG i, count, count2, expected_count, external_port;
182 ULONG refcount, refcount2;
183 IEnumVARIANT *enum_ports;
184 IUnknown *unk;
185 ULONG fetched;
187 VARIANT var;
188 HRESULT hr;
189
190 refcount = get_refcount((IUnknown *)ports);
191 hr = IStaticPortMappingCollection_get__NewEnum(ports, &unk);
192 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
193
194 hr = IUnknown_QueryInterface(unk, &IID_IEnumVARIANT, (void **)&enum_ports);
195 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
196 IUnknown_Release( unk );
197
198 refcount2 = get_refcount((IUnknown *)ports);
199 ok(refcount2 == refcount, "Got unexpected refcount %lu, refcount2 %lu.\n", refcount, refcount2);
200
201 hr = IEnumVARIANT_Reset(enum_ports);
202 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
203
204 count = 0xdeadbeef;
205 hr = IStaticPortMappingCollection_get_Count(ports, &count);
206 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
207
208 hr = IStaticPortMappingCollection_get_Item(ports, 12345, (BSTR)L"UDP", &pm);
209 if (SUCCEEDED(hr))
210 {
212 IStaticPortMapping_Release(pm);
213 }
214 else
215 {
216 expected_count = count + 1;
217 }
218
219 hr = IStaticPortMappingCollection_Add(ports, 12345, (BSTR)L"udp", 12345, (BSTR)L"1.2.3.4",
220 VARIANT_TRUE, (BSTR)L"wine_test", &pm);
221 ok(hr == E_INVALIDARG, "Got unexpected hr %#lx.\n", hr);
222 hr = IStaticPortMappingCollection_Add(ports, 12345, (BSTR)L"UDP", 12345, (BSTR)L"1.2.3.4",
223 VARIANT_TRUE, (BSTR)L"wine_test", &pm);
224 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
225
226 hr = IStaticPortMappingCollection_get_Count(ports, &count2);
227 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
228 ok(count2 == expected_count, "Got unexpected count2 %lu, expected %lu.\n", count2, expected_count);
229
230 hr = IStaticPortMappingCollection_get_Item(ports, 12345, NULL, &pm);
231 ok(hr == E_INVALIDARG, "Got unexpected hr %#lx.\n", hr);
232
233 hr = IStaticPortMappingCollection_get_Item(ports, 12345, (BSTR)L"UDP", NULL);
234 ok(hr == E_POINTER, "Got unexpected hr %#lx.\n", hr);
235
236 hr = IStaticPortMappingCollection_get_Item(ports, 12345, (BSTR)L"udp", &pm);
237 ok(hr == E_INVALIDARG, "Got unexpected hr %#lx.\n", hr);
238
239 hr = IStaticPortMappingCollection_get_Item(ports, -1, (BSTR)L"UDP", &pm);
240 ok(hr == E_INVALIDARG, "Got unexpected hr %#lx.\n", hr);
241
242 hr = IStaticPortMappingCollection_get_Item(ports, 65536, (BSTR)L"UDP", &pm);
243 ok(hr == E_INVALIDARG, "Got unexpected hr %#lx.\n", hr);
244
245 hr = IStaticPortMappingCollection_get_Item(ports, 12346, (BSTR)L"UDP", &pm);
246 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "Got unexpected hr %#lx.\n", hr);
247
248 hr = IEnumVARIANT_Reset(enum_ports);
249 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
250
251 for (i = 0; i < count2; ++i)
252 {
254
255 fetched = 0xdeadbeef;
256 hr = IEnumVARIANT_Next(enum_ports, 1, &var, &fetched);
257 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
258 ok(fetched == 1, "Got unexpected fetched %lu.\n", fetched);
259 ok(V_VT(&var) == VT_DISPATCH, "Got unexpected variant type %u.\n", V_VT(&var));
260
261 hr = IDispatch_QueryInterface(V_DISPATCH(&var), &IID_IStaticPortMapping, (void **)&pm);
262 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
263
264 hr = IStaticPortMapping_get_Protocol(pm, &protocol);
265 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
266 external_port = 0xdeadbeef;
267 hr = IStaticPortMapping_get_ExternalPort(pm, &external_port);
268 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
269
270 ok(!wcscmp(protocol, L"UDP") || !wcscmp(protocol, L"TCP"), "Got unexpected protocol %s.\n",
272 hr = IStaticPortMappingCollection_get_Item(ports, external_port, protocol, &pm2);
273 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
274 ok(pm2 != pm, "Got same interface.\n");
275
276 IStaticPortMapping_Release(pm);
277 IStaticPortMapping_Release(pm2);
278
280
282 }
283 hr = IEnumVARIANT_Next(enum_ports, 1, &var, &fetched);
284 ok(hr == S_FALSE, "Got unexpected hr %#lx.\n", hr);
285
286 hr = IStaticPortMappingCollection_Remove(ports, 12345, (BSTR)L"UDP");
287 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
288
289 IEnumVARIANT_Release(enum_ports);
290}
291
292static void test_IUPnPNAT(void)
293{
294 IUPnPNAT *nat;
295 IStaticPortMappingCollection *static_ports;
297 INATEventManager *manager;
298 IProvideClassInfo *provider;
299 ULONG refcount, refcount2;
300 HRESULT hr;
301
302 hr = CoCreateInstance(&CLSID_UPnPNAT, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER, &IID_IUPnPNAT, (void**)&nat);
303 ok(hr == S_OK, "got: %08lx\n", hr);
304
305 hr = IUPnPNAT_QueryInterface(nat, &IID_IProvideClassInfo, (void**)&provider);
306 ok(hr == E_NOINTERFACE, "got: %08lx\n", hr);
307
308 refcount = get_refcount((IUnknown *)nat);
309 hr = IUPnPNAT_get_StaticPortMappingCollection(nat, &static_ports);
310
311 ok(hr == S_OK, "got: %08lx\n", hr);
312 if(hr == S_OK && static_ports)
313 {
314 refcount2 = get_refcount((IUnknown *)nat);
315 ok(refcount2 == refcount, "Got unexpected refcount %lu, refcount2 %lu.\n", refcount, refcount2);
317 IStaticPortMappingCollection_Release(static_ports);
318 }
319 else if (hr == S_OK)
320 {
321 skip( "UPNP gateway not found.\n" );
322 }
323 hr = IUPnPNAT_get_DynamicPortMappingCollection(nat, &dync_ports);
324 ok(hr == S_OK || hr == E_NOTIMPL /* Windows 8.1 */, "got: %08lx\n", hr);
325 if(hr == S_OK && dync_ports)
326 IDynamicPortMappingCollection_Release(dync_ports);
327
328 hr = IUPnPNAT_get_NATEventManager(nat, &manager);
329 todo_wine ok(hr == S_OK, "got: %08lx\n", hr);
330 if(hr == S_OK && manager)
331 INATEventManager_Release(manager);
332
333 IUPnPNAT_Release(nat);
334}
335#endif
336
338{
339 INetFwMgr *manager;
340 HRESULT hr;
341
343
344 hr = CoCreateInstance(&CLSID_NetFwMgr, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
345 &IID_INetFwMgr, (void**)&manager);
346 if(FAILED(hr))
347 {
348 win_skip("NetFwMgr object is not supported: %08lx\n", hr);
350 return;
351 }
352
353 INetFwMgr_Release(manager);
354
357#ifndef __REACTOS__ /* Causes hang, see https://reactos.org/testman/detail.php?id=92110046&prev=92100597 */
359#endif
360
362}
WINBASEAPI _Check_return_ _Out_ AppPolicyProcessTerminationMethod * policy
Definition: appmodel.h:78
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#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
HRESULT hr
Definition: delayimp.cpp:582
#define NULL
Definition: types.h:112
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: combase.c:2842
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, IUnknown *outer, DWORD cls_context, REFIID riid, void **obj)
Definition: combase.c:1685
static const WCHAR empty[1]
Definition: string.c:47
OLECHAR * BSTR
Definition: compat.h:2293
#define MAX_PATH
Definition: compat.h:34
#define lstrcpyW
Definition: compat.h:749
@ VT_DISPATCH
Definition: compat.h:2304
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:1555
DWORD WINAPI GetFullPathNameW(IN LPCWSTR lpFileName, IN DWORD nBufferLength, OUT LPWSTR lpBuffer, OUT LPWSTR *lpFilePart)
Definition: path.c:1164
int WINAPI lstrcmpW(LPCWSTR str1, LPCWSTR str2)
Definition: locale.c:4152
_ACRTIMP int __cdecl wcscmp(const wchar_t *, const wchar_t *)
Definition: wcs.c:1977
HRESULT WINAPI CoInitialize(LPVOID lpReserved)
Definition: compobj.c:531
#define L(x)
Definition: resources.c:13
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static int expected_count(int *sink)
#define S_OK
Definition: intsafe.h:52
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define FAILED(hr)
Definition: intsafe.h:51
#define debugstr_w
Definition: kernel32.h:32
#define wine_dbgstr_w
Definition: kernel32.h:34
static LPMONITOR2 pm2
Definition: localmon.c:46
static LPMONITOREX pm
Definition: localmon.c:45
#define win_skip
Definition: minitest.h:67
#define todo_wine
Definition: minitest.h:80
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
const char * var
Definition: shader.c:5879
static ULONG get_refcount(IUnknown *unk)
Definition: policy.c:33
static void test_IUPnPNAT(void)
Definition: policy.c:292
static void test_policy2_rules(INetFwPolicy2 *policy2)
Definition: policy.c:40
static void test_NetFwAuthorizedApplication(void)
Definition: policy.c:119
static void test_static_port_mapping_collection(IStaticPortMappingCollection *ports)
Definition: policy.c:178
static void test_interfaces(void)
Definition: policy.c:80
BSTR WINAPI SysAllocString(LPCOLESTR str)
Definition: oleaut.c:240
void WINAPI DECLSPEC_HOTPATCH SysFreeString(BSTR str)
Definition: oleaut.c:273
#define V_VT(A)
Definition: oleauto.h:211
#define V_DISPATCH(A)
Definition: oleauto.h:239
const GUID IID_IProvideClassInfo
short WCHAR
Definition: pedump.c:58
long LONG
Definition: pedump.c:60
Definition: image.c:84
uint32_t ULONG
Definition: typedefs.h:59
HRESULT WINAPI DECLSPEC_HOTPATCH VariantClear(VARIANTARG *pVarg)
Definition: variant.c:626
void WINAPI VariantInit(VARIANTARG *pVarg)
Definition: variant.c:547
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define S_FALSE
Definition: winerror.h:3451
static HRESULT HRESULT_FROM_WIN32(unsigned int x)
Definition: winerror.h:210
#define E_NOINTERFACE
Definition: winerror.h:3479
#define ERROR_PATH_NOT_FOUND
Definition: winerror.h:228
#define E_POINTER
Definition: winerror.h:3480
#define UNIVERSAL_NAME_INFO_LEVEL
Definition: winnetwk.h:151
DWORD WINAPI WNetGetUniversalNameW(LPCWSTR lpLocalPath, DWORD dwInfoLevel, LPVOID lpBuffer, LPDWORD lpBufferSize)
Definition: wnet.c:2779