| 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 <set> | 7 #include <set> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 &profile_path); | 142 &profile_path); |
| 143 const NetworkProfile* profile = | 143 const NetworkProfile* profile = |
| 144 network_profile_handler_->GetProfileForPath(profile_path); | 144 network_profile_handler_->GetProfileForPath(profile_path); |
| 145 if (!profile) | 145 if (!profile) |
| 146 NET_LOG_ERROR("No profile for service: " + profile_path, service_path); | 146 NET_LOG_ERROR("No profile for service: " + profile_path, service_path); |
| 147 | 147 |
| 148 scoped_ptr<NetworkUIData> ui_data = | 148 scoped_ptr<NetworkUIData> ui_data = |
| 149 shill_property_util::GetUIDataFromProperties(*shill_properties); | 149 shill_property_util::GetUIDataFromProperties(*shill_properties); |
| 150 | 150 |
| 151 const base::DictionaryValue* user_settings = NULL; | 151 const base::DictionaryValue* user_settings = NULL; |
| 152 const base::DictionaryValue* shared_settings = NULL; | |
| 153 | 152 |
| 154 if (ui_data && profile) { | 153 if (ui_data && profile) { |
| 155 if (profile->type() == NetworkProfile::TYPE_SHARED) | 154 user_settings = ui_data->user_settings(); |
| 156 shared_settings = ui_data->user_settings(); | |
| 157 else if (profile->type() == NetworkProfile::TYPE_USER) | |
| 158 user_settings = ui_data->user_settings(); | |
| 159 else | |
| 160 NOTREACHED(); | |
| 161 } else if (profile) { | 155 } else if (profile) { |
| 162 NET_LOG_ERROR("Service contains empty or invalid UIData", service_path); | 156 NET_LOG_ERROR("Service contains empty or invalid UIData", service_path); |
| 163 // TODO(pneubeck): add a conversion of user configured entries of old | 157 // TODO(pneubeck): add a conversion of user configured entries of old |
| 164 // ChromeOS versions. We will have to use a heuristic to determine which | 158 // ChromeOS versions. We will have to use a heuristic to determine which |
| 165 // properties _might_ be user configured. | 159 // properties _might_ be user configured. |
| 166 } | 160 } |
| 167 | 161 |
| 168 scoped_ptr<base::DictionaryValue> active_settings( | 162 scoped_ptr<base::DictionaryValue> active_settings( |
| 169 onc::TranslateShillServiceToONCPart( | 163 onc::TranslateShillServiceToONCPart( |
| 170 *shill_properties, | 164 *shill_properties, |
| 171 &onc::kNetworkWithStateSignature)); | 165 &onc::kNetworkWithStateSignature)); |
| 172 | 166 |
| 173 std::string guid; | 167 std::string guid; |
| 174 active_settings->GetStringWithoutPathExpansion(::onc::network_config::kGUID, | 168 active_settings->GetStringWithoutPathExpansion(::onc::network_config::kGUID, |
| 175 &guid); | 169 &guid); |
| 176 | 170 |
| 177 const base::DictionaryValue* user_policy = NULL; | 171 const base::DictionaryValue* network_policy = NULL; |
| 178 const base::DictionaryValue* device_policy = NULL; | 172 const base::DictionaryValue* global_policy = NULL; |
| 179 if (!guid.empty() && profile) { | 173 if (profile) { |
| 180 const Policies* policies = GetPoliciesForProfile(*profile); | 174 const Policies* policies = GetPoliciesForProfile(*profile); |
| 181 if (!policies) { | 175 if (!policies) { |
| 182 InvokeErrorCallback( | 176 InvokeErrorCallback( |
| 183 service_path, error_callback, kPoliciesNotInitialized); | 177 service_path, error_callback, kPoliciesNotInitialized); |
| 184 return; | 178 return; |
| 185 } | 179 } |
| 186 const base::DictionaryValue* policy = | 180 if (!guid.empty()) |
| 187 GetByGUID(policies->per_network_config, guid); | 181 network_policy = GetByGUID(policies->per_network_config, guid); |
| 188 if (profile->type() == NetworkProfile::TYPE_SHARED) | 182 global_policy = &policies->global_network_config; |
| 189 device_policy = policy; | |
| 190 else if (profile->type() == NetworkProfile::TYPE_USER) | |
| 191 user_policy = policy; | |
| 192 else | |
| 193 NOTREACHED(); | |
| 194 } | 183 } |
| 195 | 184 |
| 196 // This call also removes credentials from policies. | 185 scoped_ptr<base::DictionaryValue> augmented_properties( |
| 197 scoped_ptr<base::DictionaryValue> augmented_properties = | 186 policy_util::CreateManagedONC(global_policy, |
| 198 onc::MergeSettingsAndPoliciesToAugmented( | 187 network_policy, |
| 199 onc::kNetworkConfigurationSignature, | 188 user_settings, |
| 200 user_policy, | 189 active_settings.get(), |
| 201 device_policy, | 190 profile)); |
| 202 user_settings, | |
| 203 shared_settings, | |
| 204 active_settings.get()); | |
| 205 callback.Run(service_path, *augmented_properties); | 191 callback.Run(service_path, *augmented_properties); |
| 206 } | 192 } |
| 207 | 193 |
| 208 // GetProperties | 194 // GetProperties |
| 209 | 195 |
| 210 void ManagedNetworkConfigurationHandlerImpl::GetProperties( | 196 void ManagedNetworkConfigurationHandlerImpl::GetProperties( |
| 211 const std::string& service_path, | 197 const std::string& service_path, |
| 212 const network_handler::DictionaryResultCallback& callback, | 198 const network_handler::DictionaryResultCallback& callback, |
| 213 const network_handler::ErrorCallback& error_callback) { | 199 const network_handler::ErrorCallback& error_callback) { |
| 214 network_configuration_handler_->GetProperties( | 200 network_configuration_handler_->GetProperties( |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 user_settings, | 276 user_settings, |
| 291 &validation_result); | 277 &validation_result); |
| 292 | 278 |
| 293 if (validation_result == onc::Validator::INVALID) { | 279 if (validation_result == onc::Validator::INVALID) { |
| 294 InvokeErrorCallback(service_path, error_callback, kInvalidUserSettings); | 280 InvokeErrorCallback(service_path, error_callback, kInvalidUserSettings); |
| 295 return; | 281 return; |
| 296 } | 282 } |
| 297 if (validation_result == onc::Validator::VALID_WITH_WARNINGS) | 283 if (validation_result == onc::Validator::VALID_WITH_WARNINGS) |
| 298 LOG(WARNING) << "Validation of ONC user settings produced warnings."; | 284 LOG(WARNING) << "Validation of ONC user settings produced warnings."; |
| 299 | 285 |
| 300 const base::DictionaryValue* policy = | 286 const base::DictionaryValue* network_policy = |
| 301 GetByGUID(policies->per_network_config, guid); | 287 GetByGUID(policies->per_network_config, guid); |
| 302 VLOG(2) << "This configuration is " << (policy ? "" : "not ") << "managed."; | 288 VLOG(2) << "This configuration is " << (network_policy ? "" : "not ") |
| 289 << "managed."; |
| 303 | 290 |
| 304 scoped_ptr<base::DictionaryValue> shill_dictionary( | 291 scoped_ptr<base::DictionaryValue> shill_dictionary( |
| 305 policy_util::CreateShillConfiguration( | 292 policy_util::CreateShillConfiguration(*profile, |
| 306 *profile, guid, policy, validated_user_settings.get())); | 293 guid, |
| 294 &policies->global_network_config, |
| 295 network_policy, |
| 296 validated_user_settings.get())); |
| 307 | 297 |
| 308 network_configuration_handler_->SetProperties( | 298 network_configuration_handler_->SetProperties( |
| 309 service_path, *shill_dictionary, callback, error_callback); | 299 service_path, *shill_dictionary, callback, error_callback); |
| 310 } | 300 } |
| 311 | 301 |
| 312 void ManagedNetworkConfigurationHandlerImpl::CreateConfiguration( | 302 void ManagedNetworkConfigurationHandlerImpl::CreateConfiguration( |
| 313 const std::string& userhash, | 303 const std::string& userhash, |
| 314 const base::DictionaryValue& properties, | 304 const base::DictionaryValue& properties, |
| 315 const network_handler::StringResultCallback& callback, | 305 const network_handler::StringResultCallback& callback, |
| 316 const network_handler::ErrorCallback& error_callback) const { | 306 const network_handler::ErrorCallback& error_callback) const { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 334 } | 324 } |
| 335 | 325 |
| 336 // TODO(pneubeck): In case of WiFi, check that no other configuration for the | 326 // TODO(pneubeck): In case of WiFi, check that no other configuration for the |
| 337 // same {SSID, mode, security} exists. We don't support such multiple | 327 // same {SSID, mode, security} exists. We don't support such multiple |
| 338 // configurations, yet. | 328 // configurations, yet. |
| 339 | 329 |
| 340 // Generate a new GUID for this configuration. Ignore the maybe provided GUID | 330 // Generate a new GUID for this configuration. Ignore the maybe provided GUID |
| 341 // in |properties| as it is not our own and from an untrusted source. | 331 // in |properties| as it is not our own and from an untrusted source. |
| 342 std::string guid = base::GenerateGUID(); | 332 std::string guid = base::GenerateGUID(); |
| 343 scoped_ptr<base::DictionaryValue> shill_dictionary( | 333 scoped_ptr<base::DictionaryValue> shill_dictionary( |
| 344 policy_util::CreateShillConfiguration( | 334 policy_util::CreateShillConfiguration(*profile, |
| 345 *profile, guid, NULL /*no policy*/, &properties)); | 335 guid, |
| 336 NULL, // no global policy |
| 337 NULL, // no network policy |
| 338 &properties)); |
| 346 | 339 |
| 347 network_configuration_handler_->CreateConfiguration( | 340 network_configuration_handler_->CreateConfiguration( |
| 348 *shill_dictionary, callback, error_callback); | 341 *shill_dictionary, callback, error_callback); |
| 349 } | 342 } |
| 350 | 343 |
| 351 void ManagedNetworkConfigurationHandlerImpl::RemoveConfiguration( | 344 void ManagedNetworkConfigurationHandlerImpl::RemoveConfiguration( |
| 352 const std::string& service_path, | 345 const std::string& service_path, |
| 353 const base::Closure& callback, | 346 const base::Closure& callback, |
| 354 const network_handler::ErrorCallback& error_callback) const { | 347 const network_handler::ErrorCallback& error_callback) const { |
| 355 network_configuration_handler_->RemoveConfiguration( | 348 network_configuration_handler_->RemoveConfiguration( |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 717 scoped_ptr<base::DictionaryValue> network_properties, | 710 scoped_ptr<base::DictionaryValue> network_properties, |
| 718 GetDevicePropertiesCallback send_callback, | 711 GetDevicePropertiesCallback send_callback, |
| 719 const std::string& error_name, | 712 const std::string& error_name, |
| 720 scoped_ptr<base::DictionaryValue> error_data) { | 713 scoped_ptr<base::DictionaryValue> error_data) { |
| 721 NET_LOG_ERROR("Error getting device properties", service_path); | 714 NET_LOG_ERROR("Error getting device properties", service_path); |
| 722 send_callback.Run(service_path, network_properties.Pass()); | 715 send_callback.Run(service_path, network_properties.Pass()); |
| 723 } | 716 } |
| 724 | 717 |
| 725 | 718 |
| 726 } // namespace chromeos | 719 } // namespace chromeos |
| OLD | NEW |