OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chromeos/network/network_configuration_handler.h" | 5 #include "chromeos/network/network_configuration_handler.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/format_macros.h" | 11 #include "base/format_macros.h" |
| 12 #include "base/json/json_writer.h" |
12 #include "base/logging.h" | 13 #include "base/logging.h" |
13 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
14 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
15 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
16 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
17 #include "base/values.h" | 18 #include "base/values.h" |
18 #include "chromeos/dbus/dbus_thread_manager.h" | 19 #include "chromeos/dbus/dbus_thread_manager.h" |
19 #include "chromeos/dbus/shill_manager_client.h" | 20 #include "chromeos/dbus/shill_manager_client.h" |
20 #include "chromeos/dbus/shill_profile_client.h" | 21 #include "chromeos/dbus/shill_profile_client.h" |
21 #include "chromeos/dbus/shill_service_client.h" | 22 #include "chromeos/dbus/shill_service_client.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 std::string name = NetworkState::GetNameFromProperties(properties); | 60 std::string name = NetworkState::GetNameFromProperties(properties); |
60 if (!name.empty()) { | 61 if (!name.empty()) { |
61 properties_copy->SetStringWithoutPathExpansion( | 62 properties_copy->SetStringWithoutPathExpansion( |
62 flimflam::kNameProperty, name); | 63 flimflam::kNameProperty, name); |
63 } | 64 } |
64 network_handler::GetPropertiesCallback( | 65 network_handler::GetPropertiesCallback( |
65 callback, error_callback, service_path, call_status, | 66 callback, error_callback, service_path, call_status, |
66 *properties_copy.get()); | 67 *properties_copy.get()); |
67 } | 68 } |
68 | 69 |
| 70 void SetNetworkProfileErrorCallback( |
| 71 const std::string& service_path, |
| 72 const std::string& profile_path, |
| 73 const network_handler::ErrorCallback& error_callback, |
| 74 const std::string& dbus_error_name, |
| 75 const std::string& dbus_error_message) { |
| 76 network_handler::ShillErrorCallbackFunction( |
| 77 "Config.SetNetworkProfile Failed: " + profile_path, |
| 78 service_path, error_callback, |
| 79 dbus_error_name, dbus_error_message); |
| 80 } |
| 81 |
| 82 bool IsPassphrase(const std::string& key) { |
| 83 return key == flimflam::kEapPrivateKeyPasswordProperty || |
| 84 key == flimflam::kEapPasswordProperty || |
| 85 key == flimflam::kL2tpIpsecPasswordProperty || |
| 86 key == flimflam::kOpenVPNPasswordProperty || |
| 87 key == flimflam::kPassphraseProperty || |
| 88 key == flimflam::kOpenVPNOTPProperty || |
| 89 key == flimflam::kEapPrivateKeyProperty || |
| 90 key == flimflam::kEapPrivateKeyPasswordProperty || |
| 91 key == flimflam::kEapPinProperty || |
| 92 key == flimflam::kApnPasswordProperty; |
| 93 } |
| 94 |
| 95 void LogConfigProperties(const std::string& desc, |
| 96 const std::string& path, |
| 97 const base::DictionaryValue& properties) { |
| 98 for (base::DictionaryValue::Iterator iter(properties); |
| 99 !iter.IsAtEnd(); iter.Advance()) { |
| 100 std::string v = "******"; |
| 101 if (!IsPassphrase(iter.key())) |
| 102 base::JSONWriter::Write(&iter.value(), &v); |
| 103 NET_LOG_DEBUG(desc, path + "." + iter.key() + "=" + v); |
| 104 } |
| 105 } |
| 106 |
69 } // namespace | 107 } // namespace |
70 | 108 |
71 // Helper class to request from Shill the profile entries associated with a | 109 // Helper class to request from Shill the profile entries associated with a |
72 // Service and delete the service from each profile. Triggers either | 110 // Service and delete the service from each profile. Triggers either |
73 // |callback| on success or |error_callback| on failure, and calls | 111 // |callback| on success or |error_callback| on failure, and calls |
74 // |handler|->ProfileEntryDeleterCompleted() on completion to delete itself. | 112 // |handler|->ProfileEntryDeleterCompleted() on completion to delete itself. |
75 class NetworkConfigurationHandler::ProfileEntryDeleter | 113 class NetworkConfigurationHandler::ProfileEntryDeleter |
76 : public base::SupportsWeakPtr<ProfileEntryDeleter> { | 114 : public base::SupportsWeakPtr<ProfileEntryDeleter> { |
77 public: | 115 public: |
78 ProfileEntryDeleter(NetworkConfigurationHandler* handler, | 116 ProfileEntryDeleter(NetworkConfigurationHandler* handler, |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 dbus::ObjectPath(service_path), | 219 dbus::ObjectPath(service_path), |
182 base::Bind(&GetPropertiesCallback, | 220 base::Bind(&GetPropertiesCallback, |
183 callback, error_callback, service_path)); | 221 callback, error_callback, service_path)); |
184 } | 222 } |
185 | 223 |
186 void NetworkConfigurationHandler::SetProperties( | 224 void NetworkConfigurationHandler::SetProperties( |
187 const std::string& service_path, | 225 const std::string& service_path, |
188 const base::DictionaryValue& properties, | 226 const base::DictionaryValue& properties, |
189 const base::Closure& callback, | 227 const base::Closure& callback, |
190 const network_handler::ErrorCallback& error_callback) { | 228 const network_handler::ErrorCallback& error_callback) { |
| 229 if (properties.empty()) { |
| 230 if (!callback.is_null()) |
| 231 callback.Run(); |
| 232 return; |
| 233 } |
191 NET_LOG_USER("SetProperties", service_path); | 234 NET_LOG_USER("SetProperties", service_path); |
| 235 LogConfigProperties("SetProperty", service_path, properties); |
| 236 |
192 DBusThreadManager::Get()->GetShillServiceClient()->SetProperties( | 237 DBusThreadManager::Get()->GetShillServiceClient()->SetProperties( |
193 dbus::ObjectPath(service_path), | 238 dbus::ObjectPath(service_path), |
194 properties, | 239 properties, |
195 base::Bind(&NetworkConfigurationHandler::SetPropertiesSuccessCallback, | 240 base::Bind(&NetworkConfigurationHandler::SetPropertiesSuccessCallback, |
196 AsWeakPtr(), service_path, callback), | 241 AsWeakPtr(), service_path, callback), |
197 base::Bind(&NetworkConfigurationHandler::SetPropertiesErrorCallback, | 242 base::Bind(&NetworkConfigurationHandler::SetPropertiesErrorCallback, |
198 AsWeakPtr(), service_path, error_callback)); | 243 AsWeakPtr(), service_path, error_callback)); |
199 } | 244 } |
200 | 245 |
201 void NetworkConfigurationHandler::ClearProperties( | 246 void NetworkConfigurationHandler::ClearProperties( |
202 const std::string& service_path, | 247 const std::string& service_path, |
203 const std::vector<std::string>& names, | 248 const std::vector<std::string>& names, |
204 const base::Closure& callback, | 249 const base::Closure& callback, |
205 const network_handler::ErrorCallback& error_callback) { | 250 const network_handler::ErrorCallback& error_callback) { |
| 251 if (names.empty()) { |
| 252 if (!callback.is_null()) |
| 253 callback.Run(); |
| 254 return; |
| 255 } |
206 NET_LOG_USER("ClearProperties", service_path); | 256 NET_LOG_USER("ClearProperties", service_path); |
| 257 for (std::vector<std::string>::const_iterator iter = names.begin(); |
| 258 iter != names.end(); ++iter) { |
| 259 NET_LOG_DEBUG("ClearProperty", service_path + "." + *iter); |
| 260 } |
207 DBusThreadManager::Get()->GetShillServiceClient()->ClearProperties( | 261 DBusThreadManager::Get()->GetShillServiceClient()->ClearProperties( |
208 dbus::ObjectPath(service_path), | 262 dbus::ObjectPath(service_path), |
209 names, | 263 names, |
210 base::Bind(&NetworkConfigurationHandler::ClearPropertiesSuccessCallback, | 264 base::Bind(&NetworkConfigurationHandler::ClearPropertiesSuccessCallback, |
211 AsWeakPtr(), service_path, names, callback, error_callback), | 265 AsWeakPtr(), service_path, names, callback, error_callback), |
212 base::Bind(&NetworkConfigurationHandler::ClearPropertiesErrorCallback, | 266 base::Bind(&NetworkConfigurationHandler::ClearPropertiesErrorCallback, |
213 AsWeakPtr(), service_path, error_callback)); | 267 AsWeakPtr(), service_path, error_callback)); |
214 } | 268 } |
215 | 269 |
216 void NetworkConfigurationHandler::CreateConfiguration( | 270 void NetworkConfigurationHandler::CreateConfiguration( |
217 const base::DictionaryValue& properties, | 271 const base::DictionaryValue& properties, |
218 const network_handler::StringResultCallback& callback, | 272 const network_handler::StringResultCallback& callback, |
219 const network_handler::ErrorCallback& error_callback) { | 273 const network_handler::ErrorCallback& error_callback) { |
220 ShillManagerClient* manager = | 274 ShillManagerClient* manager = |
221 DBusThreadManager::Get()->GetShillManagerClient(); | 275 DBusThreadManager::Get()->GetShillManagerClient(); |
222 | |
223 std::string type; | 276 std::string type; |
224 properties.GetStringWithoutPathExpansion(flimflam::kTypeProperty, &type); | 277 properties.GetStringWithoutPathExpansion(flimflam::kTypeProperty, &type); |
| 278 |
| 279 NET_LOG_USER("CreateConfiguration", type); |
| 280 LogConfigProperties("Configure", type, properties); |
| 281 |
225 // Shill supports ConfigureServiceForProfile only for network type WiFi. In | 282 // Shill supports ConfigureServiceForProfile only for network type WiFi. In |
226 // all other cases, we have to rely on GetService for now. This is | 283 // all other cases, we have to rely on GetService for now. This is |
227 // unproblematic for VPN (user profile only), but will lead to inconsistencies | 284 // unproblematic for VPN (user profile only), but will lead to inconsistencies |
228 // with WiMax, for example. | 285 // with WiMax, for example. |
229 if (type == flimflam::kTypeWifi) { | 286 if (type == flimflam::kTypeWifi) { |
230 std::string profile; | 287 std::string profile; |
231 properties.GetStringWithoutPathExpansion(flimflam::kProfileProperty, | 288 properties.GetStringWithoutPathExpansion(flimflam::kProfileProperty, |
232 &profile); | 289 &profile); |
233 manager->ConfigureServiceForProfile( | 290 manager->ConfigureServiceForProfile( |
234 dbus::ObjectPath(profile), | 291 dbus::ObjectPath(profile), |
(...skipping 23 matching lines...) Expand all Loading... |
258 "RemoveConfiguration In-Progress", service_path, error_callback); | 315 "RemoveConfiguration In-Progress", service_path, error_callback); |
259 return; | 316 return; |
260 } | 317 } |
261 NET_LOG_USER("Remove Configuration", service_path); | 318 NET_LOG_USER("Remove Configuration", service_path); |
262 ProfileEntryDeleter* deleter = | 319 ProfileEntryDeleter* deleter = |
263 new ProfileEntryDeleter(this, service_path, callback, error_callback); | 320 new ProfileEntryDeleter(this, service_path, callback, error_callback); |
264 profile_entry_deleters_[service_path] = deleter; | 321 profile_entry_deleters_[service_path] = deleter; |
265 deleter->Run(); | 322 deleter->Run(); |
266 } | 323 } |
267 | 324 |
| 325 void NetworkConfigurationHandler::SetNetworkProfile( |
| 326 const std::string& service_path, |
| 327 const std::string& profile_path, |
| 328 const base::Closure& callback, |
| 329 const network_handler::ErrorCallback& error_callback) { |
| 330 NET_LOG_USER("SetNetworkProfile", service_path + ": " + profile_path); |
| 331 base::StringValue profile_path_value(profile_path); |
| 332 DBusThreadManager::Get()->GetShillServiceClient()->SetProperty( |
| 333 dbus::ObjectPath(service_path), |
| 334 flimflam::kProfileProperty, |
| 335 profile_path_value, |
| 336 callback, |
| 337 base::Bind(&SetNetworkProfileErrorCallback, |
| 338 service_path, profile_path, error_callback)); |
| 339 } |
| 340 |
268 // NetworkConfigurationHandler Private methods | 341 // NetworkConfigurationHandler Private methods |
269 | 342 |
270 NetworkConfigurationHandler::NetworkConfigurationHandler() | 343 NetworkConfigurationHandler::NetworkConfigurationHandler() |
271 : network_state_handler_(NULL) { | 344 : network_state_handler_(NULL) { |
272 } | 345 } |
273 | 346 |
274 NetworkConfigurationHandler::~NetworkConfigurationHandler() { | 347 NetworkConfigurationHandler::~NetworkConfigurationHandler() { |
275 STLDeleteContainerPairSecondPointers( | 348 STLDeleteContainerPairSecondPointers( |
276 profile_entry_deleters_.begin(), profile_entry_deleters_.end()); | 349 profile_entry_deleters_.begin(), profile_entry_deleters_.end()); |
277 } | 350 } |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 | 449 |
377 // static | 450 // static |
378 NetworkConfigurationHandler* NetworkConfigurationHandler::InitializeForTest( | 451 NetworkConfigurationHandler* NetworkConfigurationHandler::InitializeForTest( |
379 NetworkStateHandler* network_state_handler) { | 452 NetworkStateHandler* network_state_handler) { |
380 NetworkConfigurationHandler* handler = new NetworkConfigurationHandler(); | 453 NetworkConfigurationHandler* handler = new NetworkConfigurationHandler(); |
381 handler->Init(network_state_handler); | 454 handler->Init(network_state_handler); |
382 return handler; | 455 return handler; |
383 } | 456 } |
384 | 457 |
385 } // namespace chromeos | 458 } // namespace chromeos |
OLD | NEW |