f41800dd3e30a3e5e24c956958a8b7ae71a2f7b9
[reactos.git] / dll / win32 / hnetcfg / policy.c
1 /*
2 * Copyright 2009 Hans Leidekker for CodeWeavers
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
19 #include "hnetcfg_private.h"
20
21 typedef struct fw_policy
22 {
23 INetFwPolicy INetFwPolicy_iface;
24 LONG refs;
25 } fw_policy;
26
27 static inline fw_policy *impl_from_INetFwPolicy( INetFwPolicy *iface )
28 {
29 return CONTAINING_RECORD(iface, fw_policy, INetFwPolicy_iface);
30 }
31
32 typedef struct fw_policy2
33 {
34 INetFwPolicy2 INetFwPolicy2_iface;
35 LONG refs;
36 } fw_policy2;
37
38 static inline fw_policy2 *impl_from_INetFwPolicy2( INetFwPolicy2 *iface )
39 {
40 return CONTAINING_RECORD(iface, fw_policy2, INetFwPolicy2_iface);
41 }
42
43 static ULONG WINAPI fw_policy_AddRef(
44 INetFwPolicy *iface )
45 {
46 fw_policy *fw_policy = impl_from_INetFwPolicy( iface );
47 return InterlockedIncrement( &fw_policy->refs );
48 }
49
50 static ULONG WINAPI fw_policy_Release(
51 INetFwPolicy *iface )
52 {
53 fw_policy *fw_policy = impl_from_INetFwPolicy( iface );
54 LONG refs = InterlockedDecrement( &fw_policy->refs );
55 if (!refs)
56 {
57 TRACE("destroying %p\n", fw_policy);
58 HeapFree( GetProcessHeap(), 0, fw_policy );
59 }
60 return refs;
61 }
62
63 static HRESULT WINAPI fw_policy_QueryInterface(
64 INetFwPolicy *iface,
65 REFIID riid,
66 void **ppvObject )
67 {
68 fw_policy *This = impl_from_INetFwPolicy( iface );
69
70 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject );
71
72 if ( IsEqualGUID( riid, &IID_INetFwPolicy ) ||
73 IsEqualGUID( riid, &IID_IDispatch ) ||
74 IsEqualGUID( riid, &IID_IUnknown ) )
75 {
76 *ppvObject = iface;
77 }
78 else
79 {
80 FIXME("interface %s not implemented\n", debugstr_guid(riid));
81 return E_NOINTERFACE;
82 }
83 INetFwPolicy_AddRef( iface );
84 return S_OK;
85 }
86
87 static HRESULT WINAPI fw_policy_GetTypeInfoCount(
88 INetFwPolicy *iface,
89 UINT *pctinfo )
90 {
91 fw_policy *This = impl_from_INetFwPolicy( iface );
92
93 TRACE("%p %p\n", This, pctinfo);
94 *pctinfo = 1;
95 return S_OK;
96 }
97
98 static HRESULT WINAPI fw_policy_GetTypeInfo(
99 INetFwPolicy *iface,
100 UINT iTInfo,
101 LCID lcid,
102 ITypeInfo **ppTInfo )
103 {
104 fw_policy *This = impl_from_INetFwPolicy( iface );
105
106 TRACE("%p %u %u %p\n", This, iTInfo, lcid, ppTInfo);
107 return get_typeinfo( INetFwPolicy_tid, ppTInfo );
108 }
109
110 static HRESULT WINAPI fw_policy_GetIDsOfNames(
111 INetFwPolicy *iface,
112 REFIID riid,
113 LPOLESTR *rgszNames,
114 UINT cNames,
115 LCID lcid,
116 DISPID *rgDispId )
117 {
118 fw_policy *This = impl_from_INetFwPolicy( iface );
119 ITypeInfo *typeinfo;
120 HRESULT hr;
121
122 TRACE("%p %s %p %u %u %p\n", This, debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId);
123
124 hr = get_typeinfo( INetFwPolicy_tid, &typeinfo );
125 if (SUCCEEDED(hr))
126 {
127 hr = ITypeInfo_GetIDsOfNames( typeinfo, rgszNames, cNames, rgDispId );
128 ITypeInfo_Release( typeinfo );
129 }
130 return hr;
131 }
132
133 static HRESULT WINAPI fw_policy_Invoke(
134 INetFwPolicy *iface,
135 DISPID dispIdMember,
136 REFIID riid,
137 LCID lcid,
138 WORD wFlags,
139 DISPPARAMS *pDispParams,
140 VARIANT *pVarResult,
141 EXCEPINFO *pExcepInfo,
142 UINT *puArgErr )
143 {
144 fw_policy *This = impl_from_INetFwPolicy( iface );
145 ITypeInfo *typeinfo;
146 HRESULT hr;
147
148 TRACE("%p %d %s %d %d %p %p %p %p\n", This, dispIdMember, debugstr_guid(riid),
149 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
150
151 hr = get_typeinfo( INetFwPolicy_tid, &typeinfo );
152 if (SUCCEEDED(hr))
153 {
154 hr = ITypeInfo_Invoke( typeinfo, &This->INetFwPolicy_iface, dispIdMember,
155 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr );
156 ITypeInfo_Release( typeinfo );
157 }
158 return hr;
159 }
160
161 static HRESULT WINAPI fw_policy_get_CurrentProfile(
162 INetFwPolicy *iface,
163 INetFwProfile **profile )
164 {
165 fw_policy *This = impl_from_INetFwPolicy( iface );
166
167 TRACE("%p, %p\n", This, profile);
168 return NetFwProfile_create( NULL, (void **)profile );
169 }
170
171 static HRESULT WINAPI fw_policy_GetProfileByType(
172 INetFwPolicy *iface,
173 NET_FW_PROFILE_TYPE profileType,
174 INetFwProfile **profile )
175 {
176 fw_policy *This = impl_from_INetFwPolicy( iface );
177
178 FIXME("%p, %u, %p\n", This, profileType, profile);
179 return E_NOTIMPL;
180 }
181
182 static const struct INetFwPolicyVtbl fw_policy_vtbl =
183 {
184 fw_policy_QueryInterface,
185 fw_policy_AddRef,
186 fw_policy_Release,
187 fw_policy_GetTypeInfoCount,
188 fw_policy_GetTypeInfo,
189 fw_policy_GetIDsOfNames,
190 fw_policy_Invoke,
191 fw_policy_get_CurrentProfile,
192 fw_policy_GetProfileByType
193 };
194
195 HRESULT NetFwPolicy_create( IUnknown *pUnkOuter, LPVOID *ppObj )
196 {
197 fw_policy *fp;
198
199 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
200
201 fp = HeapAlloc( GetProcessHeap(), 0, sizeof(*fp) );
202 if (!fp) return E_OUTOFMEMORY;
203
204 fp->INetFwPolicy_iface.lpVtbl = &fw_policy_vtbl;
205 fp->refs = 1;
206
207 *ppObj = &fp->INetFwPolicy_iface;
208
209 TRACE("returning iface %p\n", *ppObj);
210 return S_OK;
211 }
212
213 static HRESULT WINAPI fwpolicy2_QueryInterface(INetFwPolicy2 *iface, REFIID riid, void **out)
214 {
215 fw_policy2 *This = impl_from_INetFwPolicy2( iface );
216
217 TRACE("%p %s %p\n", This, debugstr_guid( riid ), out );
218
219 if ( IsEqualGUID( riid, &IID_INetFwPolicy2 ) ||
220 IsEqualGUID( riid, &IID_IDispatch ) ||
221 IsEqualGUID( riid, &IID_IUnknown ) )
222 {
223 *out = iface;
224 }
225 else
226 {
227 FIXME("interface %s not implemented\n", debugstr_guid(riid));
228 return E_NOINTERFACE;
229 }
230 INetFwPolicy2_AddRef( iface );
231 return S_OK;
232 }
233
234 static ULONG WINAPI fwpolicy2_AddRef(INetFwPolicy2 *iface)
235 {
236 fw_policy2 *fw_policy = impl_from_INetFwPolicy2( iface );
237 return InterlockedIncrement( &fw_policy->refs );
238 }
239
240 static ULONG WINAPI fwpolicy2_Release(INetFwPolicy2 *iface)
241 {
242 fw_policy2 *fw_policy = impl_from_INetFwPolicy2( iface );
243 LONG refs = InterlockedDecrement( &fw_policy->refs );
244 if (!refs)
245 {
246 TRACE("destroying %p\n", fw_policy);
247 HeapFree( GetProcessHeap(), 0, fw_policy );
248 }
249 return refs;
250 }
251
252 static HRESULT WINAPI fwpolicy2_GetTypeInfoCount(INetFwPolicy2 *iface, UINT *pctinfo)
253 {
254 fw_policy2 *This = impl_from_INetFwPolicy2( iface );
255
256 TRACE("%p %p\n", This, pctinfo);
257 *pctinfo = 1;
258 return S_OK;
259 }
260
261 static HRESULT WINAPI fwpolicy2_GetTypeInfo(INetFwPolicy2 *iface, UINT iTInfo, LCID lcid, ITypeInfo **info)
262 {
263 fw_policy2 *This = impl_from_INetFwPolicy2( iface );
264
265 TRACE("%p %u %u %p\n", This, iTInfo, lcid, info);
266 return get_typeinfo( INetFwPolicy2_tid, info );
267 }
268
269 static HRESULT WINAPI fwpolicy2_GetIDsOfNames(INetFwPolicy2 *iface, REFIID riid, LPOLESTR *rgszNames,
270 UINT cNames, LCID lcid, DISPID *rgDispId)
271 {
272 fw_policy2 *This = impl_from_INetFwPolicy2( iface );
273 ITypeInfo *typeinfo;
274 HRESULT hr;
275
276 TRACE("%p %s %p %u %u %p\n", This, debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId);
277
278 hr = get_typeinfo( INetFwPolicy2_tid, &typeinfo );
279 if (SUCCEEDED(hr))
280 {
281 hr = ITypeInfo_GetIDsOfNames( typeinfo, rgszNames, cNames, rgDispId );
282 ITypeInfo_Release( typeinfo );
283 }
284 return hr;
285 }
286
287 static HRESULT WINAPI fwpolicy2_Invoke(INetFwPolicy2 *iface, DISPID dispIdMember, REFIID riid, LCID lcid,
288 WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
289 {
290 fw_policy2 *This = impl_from_INetFwPolicy2( iface );
291 ITypeInfo *typeinfo;
292 HRESULT hr;
293
294 TRACE("%p %d %s %d %d %p %p %p %p\n", This, dispIdMember, debugstr_guid(riid),
295 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
296
297 hr = get_typeinfo( INetFwPolicy2_tid, &typeinfo );
298 if (SUCCEEDED(hr))
299 {
300 hr = ITypeInfo_Invoke( typeinfo, &This->INetFwPolicy2_iface, dispIdMember,
301 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr );
302 ITypeInfo_Release( typeinfo );
303 }
304 return hr;
305 }
306
307 static HRESULT WINAPI fwpolicy2_get_CurrentProfileTypes(INetFwPolicy2 *iface, LONG *profile)
308 {
309 fw_policy2 *This = impl_from_INetFwPolicy2( iface );
310
311 FIXME("%p %p\n", This, profile);
312 return E_NOTIMPL;
313 }
314
315 static HRESULT WINAPI fwpolicy2_get_FirewallEnabled(INetFwPolicy2 *iface, NET_FW_PROFILE_TYPE2 profileType, VARIANT_BOOL *enabled)
316 {
317 fw_policy2 *This = impl_from_INetFwPolicy2( iface );
318
319 FIXME("%p %d %p\n", This, profileType, enabled);
320 return E_NOTIMPL;
321 }
322
323 static HRESULT WINAPI fwpolicy2_put_FirewallEnabled(INetFwPolicy2 *iface, NET_FW_PROFILE_TYPE2 profileType, VARIANT_BOOL enabled)
324 {
325 fw_policy2 *This = impl_from_INetFwPolicy2( iface );
326
327 FIXME("%p %d %d\n", This, profileType, enabled);
328 return E_NOTIMPL;
329 }
330
331 static HRESULT WINAPI fwpolicy2_get_ExcludedInterfaces(INetFwPolicy2 *iface, NET_FW_PROFILE_TYPE2 profileType, VARIANT *interfaces)
332 {
333 fw_policy2 *This = impl_from_INetFwPolicy2( iface );
334
335 FIXME("%p %d %p\n", This, profileType, interfaces);
336 return E_NOTIMPL;
337 }
338
339 static HRESULT WINAPI fwpolicy2_put_ExcludedInterfaces(INetFwPolicy2 *iface, NET_FW_PROFILE_TYPE2 profileType, VARIANT interfaces)
340 {
341 fw_policy2 *This = impl_from_INetFwPolicy2( iface );
342 FIXME("%p %d\n", This, profileType);
343 return E_NOTIMPL;
344 }
345
346 static HRESULT WINAPI fwpolicy2_get_BlockAllInboundTraffic(INetFwPolicy2 *iface, NET_FW_PROFILE_TYPE2 profileType, VARIANT_BOOL *block)
347 {
348 fw_policy2 *This = impl_from_INetFwPolicy2( iface );
349
350 FIXME("%p %d %p\n", This, profileType, block);
351 return E_NOTIMPL;
352 }
353
354 static HRESULT WINAPI fwpolicy2_put_BlockAllInboundTraffic(INetFwPolicy2 *iface, NET_FW_PROFILE_TYPE2 profileType, VARIANT_BOOL block)
355 {
356 fw_policy2 *This = impl_from_INetFwPolicy2( iface );
357
358 FIXME("%p %d %d\n", This, profileType, block);
359 return E_NOTIMPL;
360 }
361
362 static HRESULT WINAPI fwpolicy2_get_NotificationsDisabled(INetFwPolicy2 *iface, NET_FW_PROFILE_TYPE2 profileType, VARIANT_BOOL *disabled)
363 {
364 fw_policy2 *This = impl_from_INetFwPolicy2( iface );
365
366 FIXME("%p %d %p\n", This, profileType, disabled);
367 return E_NOTIMPL;
368 }
369
370 static HRESULT WINAPI fwpolicy2_put_NotificationsDisabled(INetFwPolicy2 *iface, NET_FW_PROFILE_TYPE2 profileType, VARIANT_BOOL disabled)
371 {
372 fw_policy2 *This = impl_from_INetFwPolicy2( iface );
373
374 FIXME("%p %d %d\n", This, profileType, disabled);
375 return E_NOTIMPL;
376 }
377
378 static HRESULT WINAPI fwpolicy2_get_UnicastResponsesToMulticastBroadcastDisabled(INetFwPolicy2 *iface, NET_FW_PROFILE_TYPE2 profileType, VARIANT_BOOL *disabled)
379 {
380 fw_policy2 *This = impl_from_INetFwPolicy2( iface );
381
382 FIXME("%p %d %p\n", This, profileType, disabled);
383 return E_NOTIMPL;
384 }
385
386 static HRESULT WINAPI fwpolicy2_put_UnicastResponsesToMulticastBroadcastDisabled(INetFwPolicy2 *iface, NET_FW_PROFILE_TYPE2 profileType, VARIANT_BOOL disabled)
387 {
388 fw_policy2 *This = impl_from_INetFwPolicy2( iface );
389
390 FIXME("%p %d %d\n", This, profileType, disabled);
391 return E_NOTIMPL;
392 }
393
394 static HRESULT WINAPI fwpolicy2_get_Rules(INetFwPolicy2 *iface, INetFwRules **rules)
395 {
396 fw_policy2 *This = impl_from_INetFwPolicy2( iface );
397
398 FIXME("%p %p\n", This, rules);
399 return E_NOTIMPL;
400 }
401
402 static HRESULT WINAPI fwpolicy2_get_ServiceRestriction(INetFwPolicy2 *iface, INetFwServiceRestriction **ServiceRestriction)
403 {
404 fw_policy2 *This = impl_from_INetFwPolicy2( iface );
405
406 FIXME("%p %p\n", This, ServiceRestriction);
407 return E_NOTIMPL;
408 }
409
410 static HRESULT WINAPI fwpolicy2_EnableRuleGroup(INetFwPolicy2 *iface, LONG bitmask, BSTR group, VARIANT_BOOL enable)
411 {
412 fw_policy2 *This = impl_from_INetFwPolicy2( iface );
413
414 FIXME("%p %d %s %d\n", This, bitmask, debugstr_w(group), enable);
415 return E_NOTIMPL;
416 }
417
418 static HRESULT WINAPI fwpolicy2_IsRuleGroupEnabled(INetFwPolicy2 *iface, LONG bitmask, BSTR group, VARIANT_BOOL *enabled)
419 {
420 fw_policy2 *This = impl_from_INetFwPolicy2( iface );
421
422 FIXME("%p %d %s %p\n", This, bitmask, debugstr_w(group), enabled);
423 return E_NOTIMPL;
424 }
425
426 static HRESULT WINAPI fwpolicy2_RestoreLocalFirewallDefaults(INetFwPolicy2 *iface)
427 {
428 fw_policy2 *This = impl_from_INetFwPolicy2( iface );
429
430 FIXME("%p\n", This);
431 return E_NOTIMPL;
432 }
433
434 static HRESULT WINAPI fwpolicy2_get_DefaultInboundAction(INetFwPolicy2 *iface, NET_FW_PROFILE_TYPE2 profileType, NET_FW_ACTION *action)
435 {
436 fw_policy2 *This = impl_from_INetFwPolicy2( iface );
437
438 FIXME("%p %d %p\n", This, profileType, action);
439 return E_NOTIMPL;
440 }
441
442 static HRESULT WINAPI fwpolicy2_put_DefaultInboundAction(INetFwPolicy2 *iface, NET_FW_PROFILE_TYPE2 profileType, NET_FW_ACTION action)
443 {
444 fw_policy2 *This = impl_from_INetFwPolicy2( iface );
445
446 FIXME("%p %d %d\n", This, profileType, action);
447 return E_NOTIMPL;
448 }
449
450 static HRESULT WINAPI fwpolicy2_get_DefaultOutboundAction(INetFwPolicy2 *iface, NET_FW_PROFILE_TYPE2 profileType, NET_FW_ACTION *action)
451 {
452 fw_policy2 *This = impl_from_INetFwPolicy2( iface );
453
454 FIXME("%p %d %p\n", This, profileType, action);
455 return E_NOTIMPL;
456 }
457
458 static HRESULT WINAPI fwpolicy2_put_DefaultOutboundAction(INetFwPolicy2 *iface, NET_FW_PROFILE_TYPE2 profileType, NET_FW_ACTION action)
459 {
460 fw_policy2 *This = impl_from_INetFwPolicy2( iface );
461
462 FIXME("%p %d %d\n", This, profileType, action);
463 return E_NOTIMPL;
464 }
465
466 static HRESULT WINAPI fwpolicy2_get_IsRuleGroupCurrentlyEnabled(INetFwPolicy2 *iface, BSTR group, VARIANT_BOOL *enabled)
467 {
468 fw_policy2 *This = impl_from_INetFwPolicy2( iface );
469
470 FIXME("%p %s %p\n", This, debugstr_w(group), enabled);
471 return E_NOTIMPL;
472 }
473
474 static HRESULT WINAPI fwpolicy2_get_LocalPolicyModifyState(INetFwPolicy2 *iface, NET_FW_MODIFY_STATE *modifyState)
475 {
476 fw_policy2 *This = impl_from_INetFwPolicy2( iface );
477
478 FIXME("%p %p\n", This, modifyState);
479 return E_NOTIMPL;
480 }
481
482 static const struct INetFwPolicy2Vtbl fw_policy2_vtbl =
483 {
484 fwpolicy2_QueryInterface,
485 fwpolicy2_AddRef,
486 fwpolicy2_Release,
487 fwpolicy2_GetTypeInfoCount,
488 fwpolicy2_GetTypeInfo,
489 fwpolicy2_GetIDsOfNames,
490 fwpolicy2_Invoke,
491 fwpolicy2_get_CurrentProfileTypes,
492 fwpolicy2_get_FirewallEnabled,
493 fwpolicy2_put_FirewallEnabled,
494 fwpolicy2_get_ExcludedInterfaces,
495 fwpolicy2_put_ExcludedInterfaces,
496 fwpolicy2_get_BlockAllInboundTraffic,
497 fwpolicy2_put_BlockAllInboundTraffic,
498 fwpolicy2_get_NotificationsDisabled,
499 fwpolicy2_put_NotificationsDisabled,
500 fwpolicy2_get_UnicastResponsesToMulticastBroadcastDisabled,
501 fwpolicy2_put_UnicastResponsesToMulticastBroadcastDisabled,
502 fwpolicy2_get_Rules,
503 fwpolicy2_get_ServiceRestriction,
504 fwpolicy2_EnableRuleGroup,
505 fwpolicy2_IsRuleGroupEnabled,
506 fwpolicy2_RestoreLocalFirewallDefaults,
507 fwpolicy2_get_DefaultInboundAction,
508 fwpolicy2_put_DefaultInboundAction,
509 fwpolicy2_get_DefaultOutboundAction,
510 fwpolicy2_put_DefaultOutboundAction,
511 fwpolicy2_get_IsRuleGroupCurrentlyEnabled,
512 fwpolicy2_get_LocalPolicyModifyState
513 };
514
515 HRESULT NetFwPolicy2_create( IUnknown *outer, void **obj )
516 {
517 fw_policy2 *fp;
518
519 TRACE("(%p,%p)\n", outer, obj);
520
521 fp = HeapAlloc( GetProcessHeap(), 0, sizeof(*fp) );
522 if (!fp) return E_OUTOFMEMORY;
523
524 fp->INetFwPolicy2_iface.lpVtbl = &fw_policy2_vtbl;
525 fp->refs = 1;
526
527 *obj = &fp->INetFwPolicy2_iface;
528
529 TRACE("returning iface %p\n", *obj);
530 return S_OK;
531 }