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 "config.h" 20 #include <stdarg.h> 21 #include <stdio.h> 22 23 #define COBJMACROS 24 25 #include "windef.h" 26 #include "winbase.h" 27 #include "winuser.h" 28 #include "ole2.h" 29 #include "netfw.h" 30 31 #include "wine/debug.h" 32 #include "wine/unicode.h" 33 #include "hnetcfg_private.h" 34 35 WINE_DEFAULT_DEBUG_CHANNEL(hnetcfg); 36 37 typedef struct fw_app 38 { 39 INetFwAuthorizedApplication INetFwAuthorizedApplication_iface; 40 LONG refs; 41 BSTR filename; 42 } fw_app; 43 44 static inline fw_app *impl_from_INetFwAuthorizedApplication( INetFwAuthorizedApplication *iface ) 45 { 46 return CONTAINING_RECORD(iface, fw_app, INetFwAuthorizedApplication_iface); 47 } 48 49 static ULONG WINAPI fw_app_AddRef( 50 INetFwAuthorizedApplication *iface ) 51 { 52 fw_app *fw_app = impl_from_INetFwAuthorizedApplication( iface ); 53 return InterlockedIncrement( &fw_app->refs ); 54 } 55 56 static ULONG WINAPI fw_app_Release( 57 INetFwAuthorizedApplication *iface ) 58 { 59 fw_app *fw_app = impl_from_INetFwAuthorizedApplication( iface ); 60 LONG refs = InterlockedDecrement( &fw_app->refs ); 61 if (!refs) 62 { 63 TRACE("destroying %p\n", fw_app); 64 if (fw_app->filename) SysFreeString( fw_app->filename ); 65 HeapFree( GetProcessHeap(), 0, fw_app ); 66 } 67 return refs; 68 } 69 70 static HRESULT WINAPI fw_app_QueryInterface( 71 INetFwAuthorizedApplication *iface, 72 REFIID riid, 73 void **ppvObject ) 74 { 75 fw_app *This = impl_from_INetFwAuthorizedApplication( iface ); 76 77 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject ); 78 79 if ( IsEqualGUID( riid, &IID_INetFwAuthorizedApplication ) || 80 IsEqualGUID( riid, &IID_IDispatch ) || 81 IsEqualGUID( riid, &IID_IUnknown ) ) 82 { 83 *ppvObject = iface; 84 } 85 else 86 { 87 FIXME("interface %s not implemented\n", debugstr_guid(riid)); 88 return E_NOINTERFACE; 89 } 90 INetFwAuthorizedApplication_AddRef( iface ); 91 return S_OK; 92 } 93 94 static HRESULT WINAPI fw_app_GetTypeInfoCount( 95 INetFwAuthorizedApplication *iface, 96 UINT *pctinfo ) 97 { 98 fw_app *This = impl_from_INetFwAuthorizedApplication( iface ); 99 100 TRACE("%p %p\n", This, pctinfo); 101 *pctinfo = 1; 102 return S_OK; 103 } 104 105 static ITypeLib *typelib; 106 static ITypeInfo *typeinfo[last_tid]; 107 108 static REFIID tid_id[] = 109 { 110 &IID_INetFwAuthorizedApplication, 111 &IID_INetFwAuthorizedApplications, 112 &IID_INetFwMgr, 113 &IID_INetFwOpenPort, 114 &IID_INetFwOpenPorts, 115 &IID_INetFwPolicy, 116 &IID_INetFwPolicy2, 117 &IID_INetFwProfile 118 }; 119 120 HRESULT get_typeinfo( enum type_id tid, ITypeInfo **ret ) 121 { 122 HRESULT hr; 123 124 if (!typelib) 125 { 126 ITypeLib *lib; 127 128 hr = LoadRegTypeLib( &LIBID_NetFwPublicTypeLib, 1, 0, LOCALE_SYSTEM_DEFAULT, &lib ); 129 if (FAILED(hr)) 130 { 131 ERR("LoadRegTypeLib failed: %08x\n", hr); 132 return hr; 133 } 134 if (InterlockedCompareExchangePointer( (void **)&typelib, lib, NULL )) 135 ITypeLib_Release( lib ); 136 } 137 if (!typeinfo[tid]) 138 { 139 ITypeInfo *info; 140 141 hr = ITypeLib_GetTypeInfoOfGuid( typelib, tid_id[tid], &info ); 142 if (FAILED(hr)) 143 { 144 ERR("GetTypeInfoOfGuid(%s) failed: %08x\n", debugstr_guid(tid_id[tid]), hr); 145 return hr; 146 } 147 if (InterlockedCompareExchangePointer( (void **)(typeinfo + tid), info, NULL )) 148 ITypeInfo_Release( info ); 149 } 150 *ret = typeinfo[tid]; 151 ITypeInfo_AddRef(typeinfo[tid]); 152 return S_OK; 153 } 154 155 void release_typelib(void) 156 { 157 unsigned i; 158 159 for (i = 0; i < sizeof(typeinfo)/sizeof(*typeinfo); i++) 160 if (typeinfo[i]) 161 ITypeInfo_Release(typeinfo[i]); 162 163 if (typelib) 164 ITypeLib_Release(typelib); 165 } 166 167 static HRESULT WINAPI fw_app_GetTypeInfo( 168 INetFwAuthorizedApplication *iface, 169 UINT iTInfo, 170 LCID lcid, 171 ITypeInfo **ppTInfo ) 172 { 173 fw_app *This = impl_from_INetFwAuthorizedApplication( iface ); 174 175 TRACE("%p %u %u %p\n", This, iTInfo, lcid, ppTInfo); 176 return get_typeinfo( INetFwAuthorizedApplication_tid, ppTInfo ); 177 } 178 179 static HRESULT WINAPI fw_app_GetIDsOfNames( 180 INetFwAuthorizedApplication *iface, 181 REFIID riid, 182 LPOLESTR *rgszNames, 183 UINT cNames, 184 LCID lcid, 185 DISPID *rgDispId ) 186 { 187 fw_app *This = impl_from_INetFwAuthorizedApplication( iface ); 188 ITypeInfo *typeinfo; 189 HRESULT hr; 190 191 TRACE("%p %s %p %u %u %p\n", This, debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId); 192 193 hr = get_typeinfo( INetFwAuthorizedApplication_tid, &typeinfo ); 194 if (SUCCEEDED(hr)) 195 { 196 hr = ITypeInfo_GetIDsOfNames( typeinfo, rgszNames, cNames, rgDispId ); 197 ITypeInfo_Release( typeinfo ); 198 } 199 return hr; 200 } 201 202 static HRESULT WINAPI fw_app_Invoke( 203 INetFwAuthorizedApplication *iface, 204 DISPID dispIdMember, 205 REFIID riid, 206 LCID lcid, 207 WORD wFlags, 208 DISPPARAMS *pDispParams, 209 VARIANT *pVarResult, 210 EXCEPINFO *pExcepInfo, 211 UINT *puArgErr ) 212 { 213 fw_app *This = impl_from_INetFwAuthorizedApplication( iface ); 214 ITypeInfo *typeinfo; 215 HRESULT hr; 216 217 TRACE("%p %d %s %d %d %p %p %p %p\n", This, dispIdMember, debugstr_guid(riid), 218 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr); 219 220 hr = get_typeinfo( INetFwAuthorizedApplication_tid, &typeinfo ); 221 if (SUCCEEDED(hr)) 222 { 223 hr = ITypeInfo_Invoke( typeinfo, &This->INetFwAuthorizedApplication_iface, dispIdMember, 224 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr ); 225 ITypeInfo_Release( typeinfo ); 226 } 227 return hr; 228 } 229 230 static HRESULT WINAPI fw_app_get_Name( 231 INetFwAuthorizedApplication *iface, 232 BSTR *name ) 233 { 234 fw_app *This = impl_from_INetFwAuthorizedApplication( iface ); 235 236 FIXME("%p, %p\n", This, name); 237 return E_NOTIMPL; 238 } 239 240 static HRESULT WINAPI fw_app_put_Name( 241 INetFwAuthorizedApplication *iface, 242 BSTR name ) 243 { 244 fw_app *This = impl_from_INetFwAuthorizedApplication( iface ); 245 246 FIXME("%p, %s\n", This, debugstr_w(name)); 247 return S_OK; 248 } 249 250 static HRESULT WINAPI fw_app_get_ProcessImageFileName( 251 INetFwAuthorizedApplication *iface, 252 BSTR *imageFileName ) 253 { 254 fw_app *This = impl_from_INetFwAuthorizedApplication( iface ); 255 256 FIXME("%p, %p\n", This, imageFileName); 257 258 if (!imageFileName) 259 return E_INVALIDARG; 260 261 if (!This->filename) 262 { 263 *imageFileName = NULL; 264 return S_OK; 265 } 266 267 *imageFileName = SysAllocString( This->filename ); 268 return *imageFileName ? S_OK : E_OUTOFMEMORY; 269 } 270 271 static HRESULT WINAPI fw_app_put_ProcessImageFileName( 272 INetFwAuthorizedApplication *iface, 273 BSTR imageFileName ) 274 { 275 fw_app *This = impl_from_INetFwAuthorizedApplication( iface ); 276 277 FIXME("%p, %s\n", This, debugstr_w(imageFileName)); 278 279 if (!imageFileName) 280 { 281 This->filename = NULL; 282 return S_OK; 283 } 284 285 This->filename = SysAllocString( imageFileName ); 286 return This->filename ? S_OK : E_OUTOFMEMORY; 287 } 288 289 static HRESULT WINAPI fw_app_get_IpVersion( 290 INetFwAuthorizedApplication *iface, 291 NET_FW_IP_VERSION *ipVersion ) 292 { 293 fw_app *This = impl_from_INetFwAuthorizedApplication( iface ); 294 295 TRACE("%p, %p\n", This, ipVersion); 296 297 if (!ipVersion) 298 return E_POINTER; 299 *ipVersion = NET_FW_IP_VERSION_ANY; 300 return S_OK; 301 } 302 303 static HRESULT WINAPI fw_app_put_IpVersion( 304 INetFwAuthorizedApplication *iface, 305 NET_FW_IP_VERSION ipVersion ) 306 { 307 fw_app *This = impl_from_INetFwAuthorizedApplication( iface ); 308 309 TRACE("%p, %u\n", This, ipVersion); 310 return S_OK; 311 } 312 313 static HRESULT WINAPI fw_app_get_Scope( 314 INetFwAuthorizedApplication *iface, 315 NET_FW_SCOPE *scope ) 316 { 317 fw_app *This = impl_from_INetFwAuthorizedApplication( iface ); 318 319 FIXME("%p, %p\n", This, scope); 320 return E_NOTIMPL; 321 } 322 323 static HRESULT WINAPI fw_app_put_Scope( 324 INetFwAuthorizedApplication *iface, 325 NET_FW_SCOPE scope ) 326 { 327 fw_app *This = impl_from_INetFwAuthorizedApplication( iface ); 328 329 FIXME("%p, %u\n", This, scope); 330 return S_OK; 331 } 332 333 static HRESULT WINAPI fw_app_get_RemoteAddresses( 334 INetFwAuthorizedApplication *iface, 335 BSTR *remoteAddrs ) 336 { 337 fw_app *This = impl_from_INetFwAuthorizedApplication( iface ); 338 339 FIXME("%p, %p\n", This, remoteAddrs); 340 return E_NOTIMPL; 341 } 342 343 static HRESULT WINAPI fw_app_put_RemoteAddresses( 344 INetFwAuthorizedApplication *iface, 345 BSTR remoteAddrs ) 346 { 347 fw_app *This = impl_from_INetFwAuthorizedApplication( iface ); 348 349 FIXME("%p, %s\n", This, debugstr_w(remoteAddrs)); 350 return E_NOTIMPL; 351 } 352 353 static HRESULT WINAPI fw_app_get_Enabled( 354 INetFwAuthorizedApplication *iface, 355 VARIANT_BOOL *enabled ) 356 { 357 fw_app *This = impl_from_INetFwAuthorizedApplication( iface ); 358 359 FIXME("%p, %p\n", This, enabled); 360 361 *enabled = VARIANT_FALSE; 362 return S_OK; 363 } 364 365 static HRESULT WINAPI fw_app_put_Enabled( 366 INetFwAuthorizedApplication *iface, 367 VARIANT_BOOL enabled ) 368 { 369 fw_app *This = impl_from_INetFwAuthorizedApplication( iface ); 370 371 FIXME("%p, %d\n", This, enabled); 372 return S_OK; 373 } 374 375 static const struct INetFwAuthorizedApplicationVtbl fw_app_vtbl = 376 { 377 fw_app_QueryInterface, 378 fw_app_AddRef, 379 fw_app_Release, 380 fw_app_GetTypeInfoCount, 381 fw_app_GetTypeInfo, 382 fw_app_GetIDsOfNames, 383 fw_app_Invoke, 384 fw_app_get_Name, 385 fw_app_put_Name, 386 fw_app_get_ProcessImageFileName, 387 fw_app_put_ProcessImageFileName, 388 fw_app_get_IpVersion, 389 fw_app_put_IpVersion, 390 fw_app_get_Scope, 391 fw_app_put_Scope, 392 fw_app_get_RemoteAddresses, 393 fw_app_put_RemoteAddresses, 394 fw_app_get_Enabled, 395 fw_app_put_Enabled 396 }; 397 398 HRESULT NetFwAuthorizedApplication_create( IUnknown *pUnkOuter, LPVOID *ppObj ) 399 { 400 fw_app *fa; 401 402 TRACE("(%p,%p)\n", pUnkOuter, ppObj); 403 404 fa = HeapAlloc( GetProcessHeap(), 0, sizeof(*fa) ); 405 if (!fa) return E_OUTOFMEMORY; 406 407 fa->INetFwAuthorizedApplication_iface.lpVtbl = &fw_app_vtbl; 408 fa->refs = 1; 409 fa->filename = NULL; 410 411 *ppObj = &fa->INetFwAuthorizedApplication_iface; 412 413 TRACE("returning iface %p\n", *ppObj); 414 return S_OK; 415 } 416 typedef struct fw_apps 417 { 418 INetFwAuthorizedApplications INetFwAuthorizedApplications_iface; 419 LONG refs; 420 } fw_apps; 421 422 static inline fw_apps *impl_from_INetFwAuthorizedApplications( INetFwAuthorizedApplications *iface ) 423 { 424 return CONTAINING_RECORD(iface, fw_apps, INetFwAuthorizedApplications_iface); 425 } 426 427 static ULONG WINAPI fw_apps_AddRef( 428 INetFwAuthorizedApplications *iface ) 429 { 430 fw_apps *fw_apps = impl_from_INetFwAuthorizedApplications( iface ); 431 return InterlockedIncrement( &fw_apps->refs ); 432 } 433 434 static ULONG WINAPI fw_apps_Release( 435 INetFwAuthorizedApplications *iface ) 436 { 437 fw_apps *fw_apps = impl_from_INetFwAuthorizedApplications( iface ); 438 LONG refs = InterlockedDecrement( &fw_apps->refs ); 439 if (!refs) 440 { 441 TRACE("destroying %p\n", fw_apps); 442 HeapFree( GetProcessHeap(), 0, fw_apps ); 443 } 444 return refs; 445 } 446 447 static HRESULT WINAPI fw_apps_QueryInterface( 448 INetFwAuthorizedApplications *iface, 449 REFIID riid, 450 void **ppvObject ) 451 { 452 fw_apps *This = impl_from_INetFwAuthorizedApplications( iface ); 453 454 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject ); 455 456 if ( IsEqualGUID( riid, &IID_INetFwAuthorizedApplications ) || 457 IsEqualGUID( riid, &IID_IDispatch ) || 458 IsEqualGUID( riid, &IID_IUnknown ) ) 459 { 460 *ppvObject = iface; 461 } 462 else 463 { 464 FIXME("interface %s not implemented\n", debugstr_guid(riid)); 465 return E_NOINTERFACE; 466 } 467 INetFwAuthorizedApplications_AddRef( iface ); 468 return S_OK; 469 } 470 471 static HRESULT WINAPI fw_apps_GetTypeInfoCount( 472 INetFwAuthorizedApplications *iface, 473 UINT *pctinfo ) 474 { 475 fw_apps *This = impl_from_INetFwAuthorizedApplications( iface ); 476 477 FIXME("%p %p\n", This, pctinfo); 478 return E_NOTIMPL; 479 } 480 481 static HRESULT WINAPI fw_apps_GetTypeInfo( 482 INetFwAuthorizedApplications *iface, 483 UINT iTInfo, 484 LCID lcid, 485 ITypeInfo **ppTInfo ) 486 { 487 fw_apps *This = impl_from_INetFwAuthorizedApplications( iface ); 488 489 TRACE("%p %u %u %p\n", This, iTInfo, lcid, ppTInfo); 490 return get_typeinfo( INetFwAuthorizedApplications_tid, ppTInfo ); 491 } 492 493 static HRESULT WINAPI fw_apps_GetIDsOfNames( 494 INetFwAuthorizedApplications *iface, 495 REFIID riid, 496 LPOLESTR *rgszNames, 497 UINT cNames, 498 LCID lcid, 499 DISPID *rgDispId ) 500 { 501 fw_apps *This = impl_from_INetFwAuthorizedApplications( iface ); 502 ITypeInfo *typeinfo; 503 HRESULT hr; 504 505 TRACE("%p %s %p %u %u %p\n", This, debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId); 506 507 hr = get_typeinfo( INetFwAuthorizedApplications_tid, &typeinfo ); 508 if (SUCCEEDED(hr)) 509 { 510 hr = ITypeInfo_GetIDsOfNames( typeinfo, rgszNames, cNames, rgDispId ); 511 ITypeInfo_Release( typeinfo ); 512 } 513 return hr; 514 } 515 516 static HRESULT WINAPI fw_apps_Invoke( 517 INetFwAuthorizedApplications *iface, 518 DISPID dispIdMember, 519 REFIID riid, 520 LCID lcid, 521 WORD wFlags, 522 DISPPARAMS *pDispParams, 523 VARIANT *pVarResult, 524 EXCEPINFO *pExcepInfo, 525 UINT *puArgErr ) 526 { 527 fw_apps *This = impl_from_INetFwAuthorizedApplications( iface ); 528 ITypeInfo *typeinfo; 529 HRESULT hr; 530 531 TRACE("%p %d %s %d %d %p %p %p %p\n", This, dispIdMember, debugstr_guid(riid), 532 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr); 533 534 hr = get_typeinfo( INetFwAuthorizedApplications_tid, &typeinfo ); 535 if (SUCCEEDED(hr)) 536 { 537 hr = ITypeInfo_Invoke( typeinfo, &This->INetFwAuthorizedApplications_iface, dispIdMember, 538 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr ); 539 ITypeInfo_Release( typeinfo ); 540 } 541 return hr; 542 } 543 544 static HRESULT WINAPI fw_apps_get_Count( 545 INetFwAuthorizedApplications *iface, 546 LONG *count ) 547 { 548 fw_apps *This = impl_from_INetFwAuthorizedApplications( iface ); 549 550 FIXME("%p, %p\n", This, count); 551 return E_NOTIMPL; 552 } 553 554 static HRESULT WINAPI fw_apps_Add( 555 INetFwAuthorizedApplications *iface, 556 INetFwAuthorizedApplication *app ) 557 { 558 fw_apps *This = impl_from_INetFwAuthorizedApplications( iface ); 559 560 FIXME("%p, %p\n", This, app); 561 return S_OK; 562 } 563 564 static HRESULT WINAPI fw_apps_Remove( 565 INetFwAuthorizedApplications *iface, 566 BSTR imageFileName ) 567 { 568 fw_apps *This = impl_from_INetFwAuthorizedApplications( iface ); 569 570 FIXME("%p, %s\n", This, debugstr_w(imageFileName)); 571 return S_OK; 572 } 573 574 static HRESULT WINAPI fw_apps_Item( 575 INetFwAuthorizedApplications *iface, 576 BSTR imageFileName, 577 INetFwAuthorizedApplication **app ) 578 { 579 fw_apps *This = impl_from_INetFwAuthorizedApplications( iface ); 580 581 TRACE("%p, %s, %p\n", This, debugstr_w(imageFileName), app); 582 return NetFwAuthorizedApplication_create( NULL, (void **)app ); 583 } 584 585 static HRESULT WINAPI fw_apps_get__NewEnum( 586 INetFwAuthorizedApplications *iface, 587 IUnknown **newEnum ) 588 { 589 fw_apps *This = impl_from_INetFwAuthorizedApplications( iface ); 590 591 FIXME("%p, %p\n", This, newEnum); 592 return E_NOTIMPL; 593 } 594 595 static const struct INetFwAuthorizedApplicationsVtbl fw_apps_vtbl = 596 { 597 fw_apps_QueryInterface, 598 fw_apps_AddRef, 599 fw_apps_Release, 600 fw_apps_GetTypeInfoCount, 601 fw_apps_GetTypeInfo, 602 fw_apps_GetIDsOfNames, 603 fw_apps_Invoke, 604 fw_apps_get_Count, 605 fw_apps_Add, 606 fw_apps_Remove, 607 fw_apps_Item, 608 fw_apps_get__NewEnum 609 }; 610 611 HRESULT NetFwAuthorizedApplications_create( IUnknown *pUnkOuter, LPVOID *ppObj ) 612 { 613 fw_apps *fa; 614 615 TRACE("(%p,%p)\n", pUnkOuter, ppObj); 616 617 fa = HeapAlloc( GetProcessHeap(), 0, sizeof(*fa) ); 618 if (!fa) return E_OUTOFMEMORY; 619 620 fa->INetFwAuthorizedApplications_iface.lpVtbl = &fw_apps_vtbl; 621 fa->refs = 1; 622 623 *ppObj = &fa->INetFwAuthorizedApplications_iface; 624 625 TRACE("returning iface %p\n", *ppObj); 626 return S_OK; 627 } 628