| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/managed_network_configuration_handler.h" | 5 #include "chromeos/network/managed_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" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 const network_handler::ErrorCallback& error_callback) { | 80 const network_handler::ErrorCallback& error_callback) { |
| 81 network_event_log::AddEntry(kLogModule, error_name, error_message); | 81 network_event_log::AddEntry(kLogModule, error_name, error_message); |
| 82 error_callback.Run( | 82 error_callback.Run( |
| 83 error_name, | 83 error_name, |
| 84 make_scoped_ptr( | 84 make_scoped_ptr( |
| 85 network_handler::CreateErrorData(service_path, | 85 network_handler::CreateErrorData(service_path, |
| 86 error_name, | 86 error_name, |
| 87 error_message))); | 87 error_message))); |
| 88 } | 88 } |
| 89 | 89 |
| 90 // Returns the NetworkUIData parsed from the UIData property of | |
| 91 // |shill_dictionary|. If parsing fails or the field doesn't exist, returns | |
| 92 // NULL. | |
| 93 scoped_ptr<NetworkUIData> GetUIData( | |
| 94 const base::DictionaryValue& shill_dictionary) { | |
| 95 std::string ui_data_blob; | |
| 96 if (shill_dictionary.GetStringWithoutPathExpansion( | |
| 97 flimflam::kUIDataProperty, | |
| 98 &ui_data_blob) && | |
| 99 !ui_data_blob.empty()) { | |
| 100 scoped_ptr<base::DictionaryValue> ui_data_dict = | |
| 101 onc::ReadDictionaryFromJson(ui_data_blob); | |
| 102 if (ui_data_dict) | |
| 103 return make_scoped_ptr(new NetworkUIData(*ui_data_dict)); | |
| 104 else | |
| 105 LOG(ERROR) << "UIData is not a valid JSON dictionary."; | |
| 106 } | |
| 107 return scoped_ptr<NetworkUIData>(); | |
| 108 } | |
| 109 | |
| 110 // Sets the UIData property in |shill_dictionary| to the serialization of | 90 // Sets the UIData property in |shill_dictionary| to the serialization of |
| 111 // |ui_data|. | 91 // |ui_data|. |
| 112 void SetUIData(const NetworkUIData& ui_data, | 92 void SetUIData(const NetworkUIData& ui_data, |
| 113 base::DictionaryValue* shill_dictionary) { | 93 base::DictionaryValue* shill_dictionary) { |
| 114 base::DictionaryValue ui_data_dict; | 94 base::DictionaryValue ui_data_dict; |
| 115 ui_data.FillDictionary(&ui_data_dict); | 95 ui_data.FillDictionary(&ui_data_dict); |
| 116 std::string ui_data_blob; | 96 std::string ui_data_blob; |
| 117 base::JSONWriter::Write(&ui_data_dict, &ui_data_blob); | 97 base::JSONWriter::Write(&ui_data_dict, &ui_data_blob); |
| 118 shill_dictionary->SetStringWithoutPathExpansion(flimflam::kUIDataProperty, | 98 shill_dictionary->SetStringWithoutPathExpansion(flimflam::kUIDataProperty, |
| 119 ui_data_blob); | 99 ui_data_blob); |
| 120 } | 100 } |
| 121 | 101 |
| 122 // A dummy callback to ignore the result of Shill calls. | 102 // A dummy callback to ignore the result of Shill calls. |
| 123 void IgnoreString(const std::string& str) { | 103 void IgnoreString(const std::string& str) { |
| 124 } | 104 } |
| 125 | 105 |
| 126 void LogErrorWithDict(const tracked_objects::Location& from_where, | 106 void LogErrorWithDict(const tracked_objects::Location& from_where, |
| 127 const std::string& error_name, | 107 const std::string& error_name, |
| 128 const scoped_ptr<base::DictionaryValue> error_data) { | 108 scoped_ptr<base::DictionaryValue> error_data) { |
| 129 LOG(ERROR) << from_where.ToString() << ": " << error_name; | 109 LOG(ERROR) << from_where.ToString() << ": " << error_name; |
| 130 } | 110 } |
| 131 | 111 |
| 132 void LogErrorMessage(const tracked_objects::Location& from_where, | 112 void LogErrorMessage(const tracked_objects::Location& from_where, |
| 133 const std::string& error_name, | 113 const std::string& error_name, |
| 134 const std::string& error_message) { | 114 const std::string& error_message) { |
| 135 LOG(ERROR) << from_where.ToString() << ": " << error_message; | 115 LOG(ERROR) << from_where.ToString() << ": " << error_message; |
| 136 } | 116 } |
| 137 | 117 |
| 138 // Removes all kFakeCredential values from sensitive fields (determined by | 118 // Removes all kFakeCredential values from sensitive fields (determined by |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 | 201 |
| 222 scoped_ptr<base::DictionaryValue> shill_dictionary( | 202 scoped_ptr<base::DictionaryValue> shill_dictionary( |
| 223 onc::TranslateONCObjectToShill(&onc::kNetworkConfigurationSignature, | 203 onc::TranslateONCObjectToShill(&onc::kNetworkConfigurationSignature, |
| 224 *effective)); | 204 *effective)); |
| 225 | 205 |
| 226 shill_dictionary->SetStringWithoutPathExpansion(flimflam::kProfileProperty, | 206 shill_dictionary->SetStringWithoutPathExpansion(flimflam::kProfileProperty, |
| 227 profile.path); | 207 profile.path); |
| 228 | 208 |
| 229 scoped_ptr<NetworkUIData> ui_data; | 209 scoped_ptr<NetworkUIData> ui_data; |
| 230 if (policy) | 210 if (policy) |
| 231 ui_data = CreateUIDataFromONC(onc_source, *policy); | 211 ui_data = NetworkUIData::CreateFromONC(onc_source, *policy); |
| 232 else | 212 else |
| 233 ui_data.reset(new NetworkUIData()); | 213 ui_data.reset(new NetworkUIData()); |
| 234 | 214 |
| 235 if (settings) { | 215 if (settings) { |
| 236 // Shill doesn't know that sensitive data is contained in the UIData | 216 // Shill doesn't know that sensitive data is contained in the UIData |
| 237 // property and might write it into logs or other insecure places. Thus, we | 217 // property and might write it into logs or other insecure places. Thus, we |
| 238 // have to remove or mask credentials. | 218 // have to remove or mask credentials. |
| 239 // | 219 // |
| 240 // Shill's GetProperties doesn't return credentials. Masking credentials | 220 // Shill's GetProperties doesn't return credentials. Masking credentials |
| 241 // instead of just removing them, allows remembering if a credential is set | 221 // instead of just removing them, allows remembering if a credential is set |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 delete g_configuration_handler_instance; | 318 delete g_configuration_handler_instance; |
| 339 g_configuration_handler_instance = NULL; | 319 g_configuration_handler_instance = NULL; |
| 340 } | 320 } |
| 341 | 321 |
| 342 // static | 322 // static |
| 343 ManagedNetworkConfigurationHandler* ManagedNetworkConfigurationHandler::Get() { | 323 ManagedNetworkConfigurationHandler* ManagedNetworkConfigurationHandler::Get() { |
| 344 CHECK(g_configuration_handler_instance); | 324 CHECK(g_configuration_handler_instance); |
| 345 return g_configuration_handler_instance; | 325 return g_configuration_handler_instance; |
| 346 } | 326 } |
| 347 | 327 |
| 328 // static |
| 329 scoped_ptr<NetworkUIData> ManagedNetworkConfigurationHandler::GetUIData( |
| 330 const base::DictionaryValue& shill_dictionary) { |
| 331 std::string ui_data_blob; |
| 332 if (shill_dictionary.GetStringWithoutPathExpansion( |
| 333 flimflam::kUIDataProperty, |
| 334 &ui_data_blob) && |
| 335 !ui_data_blob.empty()) { |
| 336 scoped_ptr<base::DictionaryValue> ui_data_dict = |
| 337 onc::ReadDictionaryFromJson(ui_data_blob); |
| 338 if (ui_data_dict) |
| 339 return make_scoped_ptr(new NetworkUIData(*ui_data_dict)); |
| 340 else |
| 341 LOG(ERROR) << "UIData is not a valid JSON dictionary."; |
| 342 } |
| 343 VLOG(2) << "JSON dictionary has no UIData blob: " << shill_dictionary; |
| 344 return scoped_ptr<NetworkUIData>(); |
| 345 } |
| 346 |
| 348 void ManagedNetworkConfigurationHandler::GetManagedProperties( | 347 void ManagedNetworkConfigurationHandler::GetManagedProperties( |
| 349 const std::string& userhash, | 348 const std::string& userhash, |
| 350 const std::string& service_path, | 349 const std::string& service_path, |
| 351 const network_handler::DictionaryResultCallback& callback, | 350 const network_handler::DictionaryResultCallback& callback, |
| 352 const network_handler::ErrorCallback& error_callback) { | 351 const network_handler::ErrorCallback& error_callback) { |
| 353 if (!GetPoliciesForUser(userhash) || !GetPoliciesForUser(std::string())) { | 352 if (!GetPoliciesForUser(userhash) || !GetPoliciesForUser(std::string())) { |
| 354 RunErrorCallback(service_path, | 353 RunErrorCallback(service_path, |
| 355 kPoliciesNotInitialized, | 354 kPoliciesNotInitialized, |
| 356 kPoliciesNotInitializedMessage, | 355 kPoliciesNotInitializedMessage, |
| 357 error_callback); | 356 error_callback); |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 533 | 532 |
| 534 scoped_ptr<base::DictionaryValue> shill_dictionary( | 533 scoped_ptr<base::DictionaryValue> shill_dictionary( |
| 535 CreateShillConfiguration(*profile, guid, policy, &user_settings)); | 534 CreateShillConfiguration(*profile, guid, policy, &user_settings)); |
| 536 | 535 |
| 537 NetworkConfigurationHandler::Get()->SetProperties(service_path, | 536 NetworkConfigurationHandler::Get()->SetProperties(service_path, |
| 538 *shill_dictionary, | 537 *shill_dictionary, |
| 539 callback, | 538 callback, |
| 540 error_callback); | 539 error_callback); |
| 541 } | 540 } |
| 542 | 541 |
| 543 void ManagedNetworkConfigurationHandler::Connect( | |
| 544 const std::string& service_path, | |
| 545 const base::Closure& callback, | |
| 546 const network_handler::ErrorCallback& error_callback) const { | |
| 547 NetworkConfigurationHandler::Get()->Connect(service_path, | |
| 548 callback, | |
| 549 error_callback); | |
| 550 } | |
| 551 | |
| 552 void ManagedNetworkConfigurationHandler::Disconnect( | |
| 553 const std::string& service_path, | |
| 554 const base::Closure& callback, | |
| 555 const network_handler::ErrorCallback& error_callback) const { | |
| 556 NetworkConfigurationHandler::Get()->Disconnect(service_path, | |
| 557 callback, | |
| 558 error_callback); | |
| 559 } | |
| 560 | |
| 561 void ManagedNetworkConfigurationHandler::CreateConfiguration( | 542 void ManagedNetworkConfigurationHandler::CreateConfiguration( |
| 562 const std::string& userhash, | 543 const std::string& userhash, |
| 563 const base::DictionaryValue& properties, | 544 const base::DictionaryValue& properties, |
| 564 const network_handler::StringResultCallback& callback, | 545 const network_handler::StringResultCallback& callback, |
| 565 const network_handler::ErrorCallback& error_callback) const { | 546 const network_handler::ErrorCallback& error_callback) const { |
| 566 const GuidToPolicyMap* policies = GetPoliciesForUser(userhash); | 547 const GuidToPolicyMap* policies = GetPoliciesForUser(userhash); |
| 567 if (!policies) { | 548 if (!policies) { |
| 568 RunErrorCallback("", | 549 RunErrorCallback("", |
| 569 kPoliciesNotInitialized, | 550 kPoliciesNotInitialized, |
| 570 kPoliciesNotInitializedMessage, | 551 kPoliciesNotInitializedMessage, |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 950 | 931 |
| 951 ManagedNetworkConfigurationHandler::~ManagedNetworkConfigurationHandler() { | 932 ManagedNetworkConfigurationHandler::~ManagedNetworkConfigurationHandler() { |
| 952 profile_handler_->RemoveObserver(this); | 933 profile_handler_->RemoveObserver(this); |
| 953 for (UserToPoliciesMap::iterator it = policies_by_user_.begin(); | 934 for (UserToPoliciesMap::iterator it = policies_by_user_.begin(); |
| 954 it != policies_by_user_.end(); ++it) { | 935 it != policies_by_user_.end(); ++it) { |
| 955 STLDeleteValues(&it->second); | 936 STLDeleteValues(&it->second); |
| 956 } | 937 } |
| 957 } | 938 } |
| 958 | 939 |
| 959 } // namespace chromeos | 940 } // namespace chromeos |
| OLD | NEW |