OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/installer/util/advanced_firewall_manager_win.h" | 5 #include "chrome/installer/util/advanced_firewall_manager_win.h" |
6 | 6 |
7 #include <objbase.h> | 7 #include <objbase.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include "base/guid.h" | 10 #include "base/guid.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "base/win/scoped_bstr.h" | 15 #include "base/win/scoped_bstr.h" |
16 #include "base/win/scoped_variant.h" | 16 #include "base/win/scoped_variant.h" |
17 | 17 |
18 namespace installer { | 18 namespace installer { |
19 | 19 |
20 AdvancedFirewallManager::AdvancedFirewallManager() {} | 20 AdvancedFirewallManager::AdvancedFirewallManager() {} |
21 | 21 |
22 AdvancedFirewallManager::~AdvancedFirewallManager() {} | 22 AdvancedFirewallManager::~AdvancedFirewallManager() {} |
23 | 23 |
24 bool AdvancedFirewallManager::Init(const base::string16& app_name, | 24 bool AdvancedFirewallManager::Init(const base::string16& app_name, |
25 const base::FilePath& app_path) { | 25 const base::FilePath& app_path) { |
26 firewall_rules_ = NULL; | 26 firewall_rules_ = NULL; |
27 HRESULT hr = firewall_policy_.CreateInstance(CLSID_NetFwPolicy2); | 27 HRESULT hr = ::CoCreateInstance(CLSID_NetFwPolicy2, nullptr, CLSCTX_ALL, |
| 28 IID_PPV_ARGS(&firewall_policy_)); |
28 if (FAILED(hr)) { | 29 if (FAILED(hr)) { |
29 DLOG(ERROR) << logging::SystemErrorCodeToString(hr); | 30 DLOG(ERROR) << logging::SystemErrorCodeToString(hr); |
30 firewall_policy_ = NULL; | 31 firewall_policy_ = NULL; |
31 return false; | 32 return false; |
32 } | 33 } |
33 hr = firewall_policy_->get_Rules(firewall_rules_.GetAddressOf()); | 34 hr = firewall_policy_->get_Rules(firewall_rules_.GetAddressOf()); |
34 if (FAILED(hr)) { | 35 if (FAILED(hr)) { |
35 DLOG(ERROR) << logging::SystemErrorCodeToString(hr); | 36 DLOG(ERROR) << logging::SystemErrorCodeToString(hr); |
36 firewall_rules_ = NULL; | 37 firewall_rules_ = NULL; |
37 return false; | 38 return false; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 DeleteRule(rules[i]); | 121 DeleteRule(rules[i]); |
121 } | 122 } |
122 } | 123 } |
123 | 124 |
124 base::win::ScopedComPtr<INetFwRule> AdvancedFirewallManager::CreateUDPRule( | 125 base::win::ScopedComPtr<INetFwRule> AdvancedFirewallManager::CreateUDPRule( |
125 const base::string16& rule_name, | 126 const base::string16& rule_name, |
126 const base::string16& description, | 127 const base::string16& description, |
127 uint16_t port) { | 128 uint16_t port) { |
128 base::win::ScopedComPtr<INetFwRule> udp_rule; | 129 base::win::ScopedComPtr<INetFwRule> udp_rule; |
129 | 130 |
130 HRESULT hr = udp_rule.CreateInstance(CLSID_NetFwRule); | 131 HRESULT hr = ::CoCreateInstance(CLSID_NetFwRule, nullptr, CLSCTX_ALL, |
| 132 IID_PPV_ARGS(&udp_rule)); |
131 if (FAILED(hr)) { | 133 if (FAILED(hr)) { |
132 DLOG(ERROR) << logging::SystemErrorCodeToString(hr); | 134 DLOG(ERROR) << logging::SystemErrorCodeToString(hr); |
133 return base::win::ScopedComPtr<INetFwRule>(); | 135 return base::win::ScopedComPtr<INetFwRule>(); |
134 } | 136 } |
135 | 137 |
136 udp_rule->put_Name(base::win::ScopedBstr(rule_name.c_str())); | 138 udp_rule->put_Name(base::win::ScopedBstr(rule_name.c_str())); |
137 udp_rule->put_Description(base::win::ScopedBstr(description.c_str())); | 139 udp_rule->put_Description(base::win::ScopedBstr(description.c_str())); |
138 udp_rule->put_ApplicationName( | 140 udp_rule->put_ApplicationName( |
139 base::win::ScopedBstr(app_path_.value().c_str())); | 141 base::win::ScopedBstr(app_path_.value().c_str())); |
140 udp_rule->put_Protocol(NET_FW_IP_PROTOCOL_UDP); | 142 udp_rule->put_Protocol(NET_FW_IP_PROTOCOL_UDP); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 !base::FilePath::CompareEqualIgnoreCase(static_cast<BSTR>(path), | 196 !base::FilePath::CompareEqualIgnoreCase(static_cast<BSTR>(path), |
195 app_path_.value())) { | 197 app_path_.value())) { |
196 continue; | 198 continue; |
197 } | 199 } |
198 | 200 |
199 rules->push_back(rule); | 201 rules->push_back(rule); |
200 } | 202 } |
201 } | 203 } |
202 | 204 |
203 } // namespace installer | 205 } // namespace installer |
OLD | NEW |