| 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/policy_util.h" | 5 #include "chromeos/network/policy_util.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "chromeos/network/network_profile.h" | 11 #include "chromeos/network/network_profile.h" |
| 12 #include "chromeos/network/network_ui_data.h" | 12 #include "chromeos/network/network_ui_data.h" |
| 13 #include "chromeos/network/onc/onc_merger.h" | 13 #include "chromeos/network/onc/onc_merger.h" |
| 14 #include "chromeos/network/onc/onc_normalizer.h" | 14 #include "chromeos/network/onc/onc_normalizer.h" |
| 15 #include "chromeos/network/onc/onc_signature.h" | 15 #include "chromeos/network/onc/onc_signature.h" |
| 16 #include "chromeos/network/onc/onc_translator.h" | 16 #include "chromeos/network/onc/onc_translator.h" |
| 17 #include "chromeos/network/onc/onc_utils.h" | 17 #include "chromeos/network/onc/onc_utils.h" |
| 18 #include "chromeos/network/shill_property_util.h" | 18 #include "chromeos/network/shill_property_util.h" |
| 19 #include "components/onc/onc_constants.h" | 19 #include "components/onc/onc_constants.h" |
| 20 #include "third_party/cros_system_api/dbus/service_constants.h" | 20 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 21 | 21 |
| 22 namespace chromeos { | 22 namespace chromeos { |
| 23 | 23 |
| 24 namespace policy_util { | 24 namespace policy_util { |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 // This fake credential contains a random postfix which is extremly unlikely to | 28 // This fake credential contains a random postfix which is extremely unlikely to |
| 29 // be used by any user. | 29 // be used by any user. |
| 30 const char kFakeCredential[] = "FAKE_CREDENTIAL_VPaJDV9x"; | 30 const char kFakeCredential[] = "FAKE_CREDENTIAL_VPaJDV9x"; |
| 31 | 31 |
| 32 | 32 |
| 33 // Removes all kFakeCredential values from sensitive fields (determined by | 33 // Removes all kFakeCredential values from sensitive fields (determined by |
| 34 // onc::FieldIsCredential) of |onc_object|. | 34 // onc::FieldIsCredential) of |onc_object|. |
| 35 void RemoveFakeCredentials( | 35 void RemoveFakeCredentials( |
| 36 const onc::OncValueSignature& signature, | 36 const onc::OncValueSignature& signature, |
| 37 base::DictionaryValue* onc_object) { | 37 base::DictionaryValue* onc_object) { |
| 38 base::DictionaryValue::Iterator it(*onc_object); | 38 base::DictionaryValue::Iterator it(*onc_object); |
| 39 while (!it.IsAtEnd()) { | 39 while (!it.IsAtEnd()) { |
| 40 base::Value* value = NULL; | 40 base::Value* value = NULL; |
| 41 std::string field_name = it.key(); | 41 std::string field_name = it.key(); |
| 42 // We need the non-const entry to remove nested values but DictionaryValue | 42 // We need the non-const entry to remove nested values but DictionaryValue |
| 43 // has no non-const iterator. | 43 // has no non-const iterator. |
| 44 onc_object->GetWithoutPathExpansion(field_name, &value); | 44 onc_object->GetWithoutPathExpansion(field_name, &value); |
| 45 // Advance before delete. | 45 // Advance before delete. |
| 46 it.Advance(); | 46 it.Advance(); |
| 47 | 47 |
| 48 // If |value| is a dictionary, recurse. | 48 // If |value| is a dictionary, recurse. |
| 49 base::DictionaryValue* nested_object = NULL; | 49 base::DictionaryValue* nested_object = NULL; |
| 50 if (value->GetAsDictionary(&nested_object)) { | 50 if (value->GetAsDictionary(&nested_object)) { |
| 51 const onc::OncFieldSignature* field_signature = | 51 const onc::OncFieldSignature* field_signature = |
| 52 onc::GetFieldSignature(signature, field_name); | 52 onc::GetFieldSignature(signature, field_name); |
| 53 if (field_signature) | 53 if (field_signature) |
| 54 RemoveFakeCredentials(*field_signature->value_signature, nested_object); | 54 RemoveFakeCredentials(*field_signature->value_signature, nested_object); |
| 55 else | 55 else |
| 56 LOG(ERROR) << "ONC has unrecoginzed field: " << field_name; | 56 LOG(ERROR) << "ONC has unrecognized field: " << field_name; |
| 57 continue; | 57 continue; |
| 58 } | 58 } |
| 59 | 59 |
| 60 // If |value| is a string, check if it is a fake credential. | 60 // If |value| is a string, check if it is a fake credential. |
| 61 std::string string_value; | 61 std::string string_value; |
| 62 if (value->GetAsString(&string_value) && | 62 if (value->GetAsString(&string_value) && |
| 63 onc::FieldIsCredential(signature, field_name)) { | 63 onc::FieldIsCredential(signature, field_name)) { |
| 64 if (string_value == kFakeCredential) { | 64 if (string_value == kFakeCredential) { |
| 65 // The value wasn't modified by the UI, thus we remove the field to keep | 65 // The value wasn't modified by the UI, thus we remove the field to keep |
| 66 // the existing value that is stored in Shill. | 66 // the existing value that is stored in Shill. |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 global_network_policy.GetBooleanWithoutPathExpansion( | 281 global_network_policy.GetBooleanWithoutPathExpansion( |
| 282 ::onc::global_network_config::kAllowOnlyPolicyNetworksToAutoconnect, | 282 ::onc::global_network_config::kAllowOnlyPolicyNetworksToAutoconnect, |
| 283 &only_policy_autoconnect); | 283 &only_policy_autoconnect); |
| 284 if (!only_policy_autoconnect) | 284 if (!only_policy_autoconnect) |
| 285 return; | 285 return; |
| 286 | 286 |
| 287 bool old_autoconnect = false; | 287 bool old_autoconnect = false; |
| 288 if (shill_dictionary.GetBooleanWithoutPathExpansion( | 288 if (shill_dictionary.GetBooleanWithoutPathExpansion( |
| 289 shill::kAutoConnectProperty, &old_autoconnect) && | 289 shill::kAutoConnectProperty, &old_autoconnect) && |
| 290 !old_autoconnect) { | 290 !old_autoconnect) { |
| 291 // Autoconnect is already explictly disabled. No need to set it again. | 291 // Autoconnect is already explicitly disabled. No need to set it again. |
| 292 return; | 292 return; |
| 293 } | 293 } |
| 294 | 294 |
| 295 // If autconnect is not explicitly set yet, it might automatically be enabled | 295 // If autoconnect is not explicitly set yet, it might automatically be enabled |
| 296 // by Shill. To prevent that, disable it explicitly. | 296 // by Shill. To prevent that, disable it explicitly. |
| 297 shill_properties_to_update->SetBooleanWithoutPathExpansion( | 297 shill_properties_to_update->SetBooleanWithoutPathExpansion( |
| 298 shill::kAutoConnectProperty, false); | 298 shill::kAutoConnectProperty, false); |
| 299 } | 299 } |
| 300 | 300 |
| 301 std::unique_ptr<base::DictionaryValue> CreateShillConfiguration( | 301 std::unique_ptr<base::DictionaryValue> CreateShillConfiguration( |
| 302 const NetworkProfile& profile, | 302 const NetworkProfile& profile, |
| 303 const std::string& guid, | 303 const std::string& guid, |
| 304 const base::DictionaryValue* global_policy, | 304 const base::DictionaryValue* global_policy, |
| 305 const base::DictionaryValue* network_policy, | 305 const base::DictionaryValue* network_policy, |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 shill_property_util::SetUIData(*ui_data, shill_dictionary.get()); | 391 shill_property_util::SetUIData(*ui_data, shill_dictionary.get()); |
| 392 | 392 |
| 393 VLOG(2) << "Created Shill properties: " << *shill_dictionary; | 393 VLOG(2) << "Created Shill properties: " << *shill_dictionary; |
| 394 | 394 |
| 395 return shill_dictionary; | 395 return shill_dictionary; |
| 396 } | 396 } |
| 397 | 397 |
| 398 const base::DictionaryValue* FindMatchingPolicy( | 398 const base::DictionaryValue* FindMatchingPolicy( |
| 399 const GuidToPolicyMap& policies, | 399 const GuidToPolicyMap& policies, |
| 400 const base::DictionaryValue& actual_network) { | 400 const base::DictionaryValue& actual_network) { |
| 401 for (GuidToPolicyMap::const_iterator it = policies.begin(); | 401 for (auto it = policies.begin(); it != policies.end(); ++it) { |
| 402 it != policies.end(); ++it) { | |
| 403 if (IsPolicyMatching(*it->second, actual_network)) | 402 if (IsPolicyMatching(*it->second, actual_network)) |
| 404 return it->second; | 403 return it->second.get(); |
| 405 } | 404 } |
| 406 return NULL; | 405 return NULL; |
| 407 } | 406 } |
| 408 | 407 |
| 409 } // namespace policy_util | 408 } // namespace policy_util |
| 410 | 409 |
| 411 } // namespace chromeos | 410 } // namespace chromeos |
| OLD | NEW |