| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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_impl.h" | 5 #include "chromeos/network/managed_network_configuration_handler_impl.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/guid.h" | 10 #include "base/guid.h" |
| 11 #include "base/json/json_writer.h" | |
| 12 #include "base/location.h" | 11 #include "base/location.h" |
| 13 #include "base/logging.h" | 12 #include "base/logging.h" |
| 14 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 15 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
| 16 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 17 #include "base/values.h" | 16 #include "base/values.h" |
| 18 #include "chromeos/dbus/dbus_method_call_status.h" | 17 #include "chromeos/dbus/dbus_method_call_status.h" |
| 19 #include "chromeos/dbus/dbus_thread_manager.h" | 18 #include "chromeos/dbus/dbus_thread_manager.h" |
| 20 #include "chromeos/dbus/shill_manager_client.h" | 19 #include "chromeos/dbus/shill_manager_client.h" |
| 21 #include "chromeos/dbus/shill_profile_client.h" | 20 #include "chromeos/dbus/shill_profile_client.h" |
| 22 #include "chromeos/dbus/shill_service_client.h" | 21 #include "chromeos/dbus/shill_service_client.h" |
| 23 #include "chromeos/network/network_configuration_handler.h" | 22 #include "chromeos/network/network_configuration_handler.h" |
| 24 #include "chromeos/network/network_event_log.h" | 23 #include "chromeos/network/network_event_log.h" |
| 25 #include "chromeos/network/network_policy_observer.h" | 24 #include "chromeos/network/network_policy_observer.h" |
| 26 #include "chromeos/network/network_profile.h" | 25 #include "chromeos/network/network_profile.h" |
| 27 #include "chromeos/network/network_profile_handler.h" | 26 #include "chromeos/network/network_profile_handler.h" |
| 28 #include "chromeos/network/network_state.h" | 27 #include "chromeos/network/network_state.h" |
| 29 #include "chromeos/network/network_state_handler.h" | 28 #include "chromeos/network/network_state_handler.h" |
| 30 #include "chromeos/network/network_ui_data.h" | 29 #include "chromeos/network/network_ui_data.h" |
| 31 #include "chromeos/network/onc/onc_constants.h" | 30 #include "chromeos/network/onc/onc_constants.h" |
| 32 #include "chromeos/network/onc/onc_merger.h" | 31 #include "chromeos/network/onc/onc_merger.h" |
| 33 #include "chromeos/network/onc/onc_normalizer.h" | 32 #include "chromeos/network/onc/onc_normalizer.h" |
| 34 #include "chromeos/network/onc/onc_signature.h" | 33 #include "chromeos/network/onc/onc_signature.h" |
| 35 #include "chromeos/network/onc/onc_translator.h" | 34 #include "chromeos/network/onc/onc_translator.h" |
| 36 #include "chromeos/network/onc/onc_utils.h" | 35 #include "chromeos/network/onc/onc_utils.h" |
| 37 #include "chromeos/network/onc/onc_validator.h" | 36 #include "chromeos/network/onc/onc_validator.h" |
| 37 #include "chromeos/network/shill_property_util.h" |
| 38 #include "dbus/object_path.h" | 38 #include "dbus/object_path.h" |
| 39 #include "third_party/cros_system_api/dbus/service_constants.h" | 39 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 40 | 40 |
| 41 namespace chromeos { | 41 namespace chromeos { |
| 42 | 42 |
| 43 namespace { | 43 namespace { |
| 44 | 44 |
| 45 // These are error strings used for error callbacks. None of these error | 45 // These are error strings used for error callbacks. None of these error |
| 46 // messages are user-facing: they should only appear in logs. | 46 // messages are user-facing: they should only appear in logs. |
| 47 const char kInvalidUserSettingsMessage[] = "User settings are invalid."; | 47 const char kInvalidUserSettingsMessage[] = "User settings are invalid."; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 77 const network_handler::ErrorCallback& error_callback) { | 77 const network_handler::ErrorCallback& error_callback) { |
| 78 NET_LOG_ERROR(error_name, error_message); | 78 NET_LOG_ERROR(error_name, error_message); |
| 79 error_callback.Run( | 79 error_callback.Run( |
| 80 error_name, | 80 error_name, |
| 81 make_scoped_ptr( | 81 make_scoped_ptr( |
| 82 network_handler::CreateErrorData(service_path, | 82 network_handler::CreateErrorData(service_path, |
| 83 error_name, | 83 error_name, |
| 84 error_message))); | 84 error_message))); |
| 85 } | 85 } |
| 86 | 86 |
| 87 // Sets the UIData property in |shill_dictionary| to the serialization of | |
| 88 // |ui_data|. | |
| 89 void SetUIData(const NetworkUIData& ui_data, | |
| 90 base::DictionaryValue* shill_dictionary) { | |
| 91 base::DictionaryValue ui_data_dict; | |
| 92 ui_data.FillDictionary(&ui_data_dict); | |
| 93 std::string ui_data_blob; | |
| 94 base::JSONWriter::Write(&ui_data_dict, &ui_data_blob); | |
| 95 shill_dictionary->SetStringWithoutPathExpansion(flimflam::kUIDataProperty, | |
| 96 ui_data_blob); | |
| 97 } | |
| 98 | |
| 99 void LogErrorWithDict(const tracked_objects::Location& from_where, | 87 void LogErrorWithDict(const tracked_objects::Location& from_where, |
| 100 const std::string& error_name, | 88 const std::string& error_name, |
| 101 scoped_ptr<base::DictionaryValue> error_data) { | 89 scoped_ptr<base::DictionaryValue> error_data) { |
| 102 LOG(ERROR) << from_where.ToString() << ": " << error_name; | 90 LOG(ERROR) << from_where.ToString() << ": " << error_name; |
| 103 } | 91 } |
| 104 | 92 |
| 105 void LogErrorMessage(const tracked_objects::Location& from_where, | 93 void LogErrorMessage(const tracked_objects::Location& from_where, |
| 106 const std::string& error_name, | 94 const std::string& error_name, |
| 107 const std::string& error_message) { | 95 const std::string& error_message) { |
| 108 LOG(ERROR) << from_where.ToString() << ": " << error_message; | 96 LOG(ERROR) << from_where.ToString() << ": " << error_message; |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 // Shill's GetProperties doesn't return credentials. Masking credentials | 207 // Shill's GetProperties doesn't return credentials. Masking credentials |
| 220 // instead of just removing them, allows remembering if a credential is set | 208 // instead of just removing them, allows remembering if a credential is set |
| 221 // or not. | 209 // or not. |
| 222 scoped_ptr<base::DictionaryValue> sanitized_settings( | 210 scoped_ptr<base::DictionaryValue> sanitized_settings( |
| 223 onc::MaskCredentialsInOncObject(onc::kNetworkConfigurationSignature, | 211 onc::MaskCredentialsInOncObject(onc::kNetworkConfigurationSignature, |
| 224 *settings, | 212 *settings, |
| 225 kFakeCredential)); | 213 kFakeCredential)); |
| 226 ui_data->set_user_settings(sanitized_settings.Pass()); | 214 ui_data->set_user_settings(sanitized_settings.Pass()); |
| 227 } | 215 } |
| 228 | 216 |
| 229 SetUIData(*ui_data, shill_dictionary.get()); | 217 shill_property_util::SetUIData(*ui_data, shill_dictionary.get()); |
| 230 | 218 |
| 231 VLOG(2) << "Created Shill properties: " << *shill_dictionary; | 219 VLOG(2) << "Created Shill properties: " << *shill_dictionary; |
| 232 | 220 |
| 233 return shill_dictionary.Pass(); | 221 return shill_dictionary.Pass(); |
| 234 } | 222 } |
| 235 | 223 |
| 236 // Returns true if |policy| matches |actual_network|, which must be part of a | 224 // Returns true if |policy| matches |actual_network|, which must be part of a |
| 237 // ONC NetworkConfiguration. This should be the only such matching function | 225 // ONC NetworkConfiguration. This should be the only such matching function |
| 238 // within Chrome. Shill does such matching in several functions for network | 226 // within Chrome. Shill does such matching in several functions for network |
| 239 // identification. For compatibility, we currently should stick to Shill's | 227 // identification. For compatibility, we currently should stick to Shill's |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 std::string profile_path; | 388 std::string profile_path; |
| 401 shill_properties.GetStringWithoutPathExpansion(flimflam::kProfileProperty, | 389 shill_properties.GetStringWithoutPathExpansion(flimflam::kProfileProperty, |
| 402 &profile_path); | 390 &profile_path); |
| 403 const NetworkProfile* profile = | 391 const NetworkProfile* profile = |
| 404 network_profile_handler_->GetProfileForPath(profile_path); | 392 network_profile_handler_->GetProfileForPath(profile_path); |
| 405 if (!profile) { | 393 if (!profile) { |
| 406 LOG(ERROR) << "No or no known profile received for service " | 394 LOG(ERROR) << "No or no known profile received for service " |
| 407 << service_path << "."; | 395 << service_path << "."; |
| 408 } | 396 } |
| 409 | 397 |
| 410 scoped_ptr<NetworkUIData> ui_data = GetUIData(shill_properties); | 398 scoped_ptr<NetworkUIData> ui_data = |
| 399 shill_property_util::GetUIData(shill_properties); |
| 411 | 400 |
| 412 const base::DictionaryValue* user_settings = NULL; | 401 const base::DictionaryValue* user_settings = NULL; |
| 413 const base::DictionaryValue* shared_settings = NULL; | 402 const base::DictionaryValue* shared_settings = NULL; |
| 414 | 403 |
| 415 if (ui_data && profile) { | 404 if (ui_data && profile) { |
| 416 if (profile->type() == NetworkProfile::TYPE_SHARED) | 405 if (profile->type() == NetworkProfile::TYPE_SHARED) |
| 417 shared_settings = ui_data->user_settings(); | 406 shared_settings = ui_data->user_settings(); |
| 418 else if (profile->type() == NetworkProfile::TYPE_USER) | 407 else if (profile->type() == NetworkProfile::TYPE_USER) |
| 419 user_settings = ui_data->user_settings(); | 408 user_settings = ui_data->user_settings(); |
| 420 else | 409 else |
| (...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 871 | 860 |
| 872 std::string old_guid; | 861 std::string old_guid; |
| 873 if (!onc_part->GetStringWithoutPathExpansion(onc::network_config::kGUID, | 862 if (!onc_part->GetStringWithoutPathExpansion(onc::network_config::kGUID, |
| 874 &old_guid)) { | 863 &old_guid)) { |
| 875 VLOG(1) << "Entry " << entry << " of profile " << profile_.ToDebugString() | 864 VLOG(1) << "Entry " << entry << " of profile " << profile_.ToDebugString() |
| 876 << " doesn't contain a GUID."; | 865 << " doesn't contain a GUID."; |
| 877 // This might be an entry of an older ChromeOS version. Assume it to be | 866 // This might be an entry of an older ChromeOS version. Assume it to be |
| 878 // unmanaged. | 867 // unmanaged. |
| 879 } | 868 } |
| 880 | 869 |
| 881 scoped_ptr<NetworkUIData> ui_data = GetUIData(entry_properties); | 870 scoped_ptr<NetworkUIData> ui_data = |
| 871 shill_property_util::GetUIData(entry_properties); |
| 882 if (!ui_data) { | 872 if (!ui_data) { |
| 883 VLOG(1) << "Entry " << entry << " of profile " << profile_.ToDebugString() | 873 VLOG(1) << "Entry " << entry << " of profile " << profile_.ToDebugString() |
| 884 << " contains no or no valid UIData."; | 874 << " contains no or no valid UIData."; |
| 885 // This might be an entry of an older ChromeOS version. Assume it to be | 875 // This might be an entry of an older ChromeOS version. Assume it to be |
| 886 // unmanaged. It's an inconsistency if there is a GUID but no UIData, thus | 876 // unmanaged. It's an inconsistency if there is a GUID but no UIData, thus |
| 887 // clear the GUID just in case. | 877 // clear the GUID just in case. |
| 888 old_guid.clear(); | 878 old_guid.clear(); |
| 889 } | 879 } |
| 890 | 880 |
| 891 bool was_managed = !old_guid.empty() && ui_data && | 881 bool was_managed = !old_guid.empty() && ui_data && |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1014 | 1004 |
| 1015 VLOG(1) << "Creating new configuration managed by policy " << *it | 1005 VLOG(1) << "Creating new configuration managed by policy " << *it |
| 1016 << " in profile " << profile_.ToDebugString() << "."; | 1006 << " in profile " << profile_.ToDebugString() << "."; |
| 1017 | 1007 |
| 1018 CreateAndWriteNewShillConfiguration( | 1008 CreateAndWriteNewShillConfiguration( |
| 1019 *it, *policy, NULL /* no user settings */); | 1009 *it, *policy, NULL /* no user settings */); |
| 1020 } | 1010 } |
| 1021 } | 1011 } |
| 1022 | 1012 |
| 1023 } // namespace chromeos | 1013 } // namespace chromeos |
| OLD | NEW |