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