diff --git a/webrtc/BUILD.gn b/webrtc/BUILD.gn index e241a57176..cca6a6b0bf 100644 --- a/webrtc/BUILD.gn +++ b/webrtc/BUILD.gn @@ -453,7 +453,6 @@ if (rtc_include_tests) { "base/win32regkey_unittest.cc", "base/win32window_unittest.cc", "base/win32windowpicker_unittest.cc", - "base/winfirewall_unittest.cc", ] } diff --git a/webrtc/base/BUILD.gn b/webrtc/base/BUILD.gn index e830cd5388..6b9bf0df72 100644 --- a/webrtc/base/BUILD.gn +++ b/webrtc/base/BUILD.gn @@ -616,8 +616,6 @@ rtc_static_library("rtc_base") { "win32window.h", "win32windowpicker.cc", "win32windowpicker.h", - "winfirewall.cc", - "winfirewall.h", "winping.cc", "winping.h", ] diff --git a/webrtc/base/base.gyp b/webrtc/base/base.gyp index b09cccf6f1..ea6939f11e 100644 --- a/webrtc/base/base.gyp +++ b/webrtc/base/base.gyp @@ -604,8 +604,6 @@ 'win32window.h', 'win32windowpicker.cc', 'win32windowpicker.h', - 'winfirewall.cc', - 'winfirewall.h', 'winping.cc', 'winping.h', ], diff --git a/webrtc/base/winfirewall.cc b/webrtc/base/winfirewall.cc deleted file mode 100644 index 97e6d15181..0000000000 --- a/webrtc/base/winfirewall.cc +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Copyright 2004 The WebRTC Project Authors. All rights reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include "webrtc/base/winfirewall.h" - -#include "webrtc/base/win32.h" - -#include -#include - -#define RELEASE(lpUnk) do { \ - if ((lpUnk) != NULL) { \ - (lpUnk)->Release(); \ - (lpUnk) = NULL; \ - } \ -} while (0) - -namespace rtc { - -////////////////////////////////////////////////////////////////////// -// WinFirewall -////////////////////////////////////////////////////////////////////// - -WinFirewall::WinFirewall() : mgr_(NULL), policy_(NULL), profile_(NULL) { -} - -WinFirewall::~WinFirewall() { - Shutdown(); -} - -bool WinFirewall::Initialize(HRESULT* result) { - if (mgr_) { - if (result) { - *result = S_OK; - } - return true; - } - - HRESULT hr = CoCreateInstance(__uuidof(NetFwMgr), - 0, CLSCTX_INPROC_SERVER, - __uuidof(INetFwMgr), - reinterpret_cast(&mgr_)); - if (SUCCEEDED(hr) && (mgr_ != NULL)) - hr = mgr_->get_LocalPolicy(&policy_); - if (SUCCEEDED(hr) && (policy_ != NULL)) - hr = policy_->get_CurrentProfile(&profile_); - - if (result) - *result = hr; - return SUCCEEDED(hr) && (profile_ != NULL); -} - -void WinFirewall::Shutdown() { - RELEASE(profile_); - RELEASE(policy_); - RELEASE(mgr_); -} - -bool WinFirewall::Enabled() const { - if (!profile_) - return false; - - VARIANT_BOOL fwEnabled = VARIANT_FALSE; - profile_->get_FirewallEnabled(&fwEnabled); - return (fwEnabled != VARIANT_FALSE); -} - -bool WinFirewall::QueryAuthorized(const char* filename, bool* authorized) - const { - return QueryAuthorizedW(ToUtf16(filename).c_str(), authorized); -} - -bool WinFirewall::QueryAuthorizedW(const wchar_t* filename, bool* authorized) - const { - *authorized = false; - bool success = false; - - if (!profile_) - return false; - - _bstr_t bfilename = filename; - - INetFwAuthorizedApplications* apps = NULL; - HRESULT hr = profile_->get_AuthorizedApplications(&apps); - if (SUCCEEDED(hr) && (apps != NULL)) { - INetFwAuthorizedApplication* app = NULL; - hr = apps->Item(bfilename, &app); - if (SUCCEEDED(hr) && (app != NULL)) { - VARIANT_BOOL fwEnabled = VARIANT_FALSE; - hr = app->get_Enabled(&fwEnabled); - app->Release(); - - if (SUCCEEDED(hr)) { - success = true; - *authorized = (fwEnabled != VARIANT_FALSE); - } - } else if (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) { - // No entry in list of authorized apps - success = true; - } else { - // Unexpected error - } - apps->Release(); - } - - return success; -} - -bool WinFirewall::AddApplication(const char* filename, - const char* friendly_name, - bool authorized, - HRESULT* result) { - return AddApplicationW(ToUtf16(filename).c_str(), - ToUtf16(friendly_name).c_str(), authorized, result); -} - -bool WinFirewall::AddApplicationW(const wchar_t* filename, - const wchar_t* friendly_name, - bool authorized, - HRESULT* result) { - INetFwAuthorizedApplications* apps = NULL; - HRESULT hr = profile_->get_AuthorizedApplications(&apps); - if (SUCCEEDED(hr) && (apps != NULL)) { - INetFwAuthorizedApplication* app = NULL; - hr = CoCreateInstance(__uuidof(NetFwAuthorizedApplication), - 0, CLSCTX_INPROC_SERVER, - __uuidof(INetFwAuthorizedApplication), - reinterpret_cast(&app)); - if (SUCCEEDED(hr) && (app != NULL)) { - _bstr_t bstr = filename; - hr = app->put_ProcessImageFileName(bstr); - bstr = friendly_name; - if (SUCCEEDED(hr)) - hr = app->put_Name(bstr); - if (SUCCEEDED(hr)) - hr = app->put_Enabled(authorized ? VARIANT_TRUE : VARIANT_FALSE); - if (SUCCEEDED(hr)) - hr = apps->Add(app); - app->Release(); - } - apps->Release(); - } - if (result) - *result = hr; - return SUCCEEDED(hr); -} - -} // namespace rtc diff --git a/webrtc/base/winfirewall.h b/webrtc/base/winfirewall.h deleted file mode 100644 index a74631bafc..0000000000 --- a/webrtc/base/winfirewall.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2004 The WebRTC Project Authors. All rights reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#ifndef WEBRTC_BASE_WINFIREWALL_H_ -#define WEBRTC_BASE_WINFIREWALL_H_ - -#ifndef _HRESULT_DEFINED -#define _HRESULT_DEFINED -typedef long HRESULT; // Can't forward declare typedef, but don't need all win -#endif // !_HRESULT_DEFINED - -struct INetFwMgr; -struct INetFwPolicy; -struct INetFwProfile; - -namespace rtc { - -////////////////////////////////////////////////////////////////////// -// WinFirewall -////////////////////////////////////////////////////////////////////// - -class WinFirewall { - public: - WinFirewall(); - ~WinFirewall(); - - bool Initialize(HRESULT* result); - void Shutdown(); - - bool Enabled() const; - bool QueryAuthorized(const char* filename, bool* authorized) const; - bool QueryAuthorizedW(const wchar_t* filename, bool* authorized) const; - - bool AddApplication(const char* filename, const char* friendly_name, - bool authorized, HRESULT* result); - bool AddApplicationW(const wchar_t* filename, const wchar_t* friendly_name, - bool authorized, HRESULT* result); - - private: - INetFwMgr* mgr_; - INetFwPolicy* policy_; - INetFwProfile* profile_; -}; - -////////////////////////////////////////////////////////////////////// - -} // namespace rtc - -#endif // WEBRTC_BASE_WINFIREWALL_H_ diff --git a/webrtc/base/winfirewall_unittest.cc b/webrtc/base/winfirewall_unittest.cc deleted file mode 100644 index e5c3d6ac18..0000000000 --- a/webrtc/base/winfirewall_unittest.cc +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2010 The WebRTC Project Authors. All rights reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include "webrtc/base/gunit.h" -#include "webrtc/base/winfirewall.h" - -#include - -namespace rtc { - -TEST(WinFirewallTest, ReadStatus) { - ::CoInitialize(NULL); - WinFirewall fw; - HRESULT hr; - bool authorized; - - EXPECT_FALSE(fw.QueryAuthorized("bogus.exe", &authorized)); - EXPECT_TRUE(fw.Initialize(&hr)); - EXPECT_EQ(S_OK, hr); - - EXPECT_TRUE(fw.QueryAuthorized("bogus.exe", &authorized)); - - // Unless we mock out INetFwMgr we can't really have an expectation either way - // about whether we're authorized. It will depend on the settings of the - // machine running the test. Same goes for AddApplication. - - fw.Shutdown(); - EXPECT_FALSE(fw.QueryAuthorized("bogus.exe", &authorized)); - - ::CoUninitialize(); -} - -} // namespace rtc