MCPcopy Create free account
hub / github.com/ModOrganizer2/modorganizer / getWindowsFirewall

Function getWindowsFirewall

src/envsecurity.cpp:338–389  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

336}
337
338std::optional<SecurityProduct> getWindowsFirewall()
339{
340 HRESULT hr = 0;
341
342 COMPtr<INetFwPolicy2> policy;
343
344 {
345 void* rawPolicy = nullptr;
346
347 hr = CoCreateInstance(__uuidof(NetFwPolicy2), nullptr, CLSCTX_INPROC_SERVER,
348 __uuidof(INetFwPolicy2), &rawPolicy);
349
350 if (FAILED(hr) || !rawPolicy) {
351 log::error("CoCreateInstance for NetFwPolicy2 failed, {}",
352 formatSystemMessage(hr));
353
354 return {};
355 }
356
357 policy.reset(static_cast<INetFwPolicy2*>(rawPolicy));
358 }
359
360 VARIANT_BOOL enabledVariant;
361
362 if (policy) {
363 hr = policy->get_FirewallEnabled(NET_FW_PROFILE2_PUBLIC, &enabledVariant);
364 if (FAILED(hr)) {
365 // EPT_S_NOT_REGISTERED is "There are no more endpoints available from the
366 // endpoint mapper", which seems to happen sometimes on Windows 7 when the
367 // firewall has been disabled, so treat it as such and don't log it
368 //
369 // however the user reported the error was actually 0x800706d9, not just
370 // 0x6d9 (1753, what EPT_S_NOT_REGISTERED is defined to), so this is
371 // testing for both because it's not clear which it is and nobody can
372 // reproduce it
373 if (hr != EPT_S_NOT_REGISTERED && hr != 0x800706d9) {
374 // don't log as error
375 log::debug("get_FirewallEnabled failed, {}", formatSystemMessage(hr));
376 }
377
378 return {};
379 }
380 }
381
382 const auto enabled = (enabledVariant != VARIANT_FALSE);
383 if (!enabled) {
384 return {};
385 }
386
387 return SecurityProduct({}, "Windows Firewall", WSC_SECURITY_PROVIDER_FIREWALL, true,
388 true);
389}
390
391std::vector<SecurityProduct> getSecurityProducts()
392{

Callers 1

getSecurityProductsFunction · 0.85

Calls 2

SecurityProductClass · 0.70
resetMethod · 0.45

Tested by

no test coverage detected