OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/onc/onc_validator.h" | 5 #include "chromeos/network/onc/onc_validator.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 return true; | 515 return true; |
516 } | 516 } |
517 | 517 |
518 bool Validator::ValidateNetworkConfiguration(base::DictionaryValue* result) { | 518 bool Validator::ValidateNetworkConfiguration(base::DictionaryValue* result) { |
519 using namespace ::onc::network_config; | 519 using namespace ::onc::network_config; |
520 | 520 |
521 const char* const kValidTypes[] = { | 521 const char* const kValidTypes[] = { |
522 ::onc::network_type::kEthernet, ::onc::network_type::kVPN, | 522 ::onc::network_type::kEthernet, ::onc::network_type::kVPN, |
523 ::onc::network_type::kWiFi, ::onc::network_type::kCellular}; | 523 ::onc::network_type::kWiFi, ::onc::network_type::kCellular}; |
524 const std::vector<const char*> valid_types(toVector(kValidTypes)); | 524 const std::vector<const char*> valid_types(toVector(kValidTypes)); |
| 525 const char* const kValidIPConfigTypes[] = {kIPConfigTypeDHCP, |
| 526 kIPConfigTypeStatic}; |
| 527 const std::vector<const char*> valid_ipconfig_types( |
| 528 toVector(kValidIPConfigTypes)); |
525 if (FieldExistsAndHasNoValidValue(*result, kType, valid_types) || | 529 if (FieldExistsAndHasNoValidValue(*result, kType, valid_types) || |
| 530 FieldExistsAndHasNoValidValue(*result, kIPAddressConfigType, |
| 531 valid_ipconfig_types) || |
| 532 FieldExistsAndHasNoValidValue(*result, kNameServersConfigType, |
| 533 valid_ipconfig_types) || |
526 FieldExistsAndIsEmpty(*result, kGUID)) { | 534 FieldExistsAndIsEmpty(*result, kGUID)) { |
527 return false; | 535 return false; |
528 } | 536 } |
529 | 537 |
530 if (!CheckGuidIsUniqueAndAddToSet(*result, kGUID, &network_guids_)) | 538 if (!CheckGuidIsUniqueAndAddToSet(*result, kGUID, &network_guids_)) |
531 return false; | 539 return false; |
532 | 540 |
533 bool all_required_exist = RequireField(*result, kGUID); | 541 bool all_required_exist = RequireField(*result, kGUID); |
534 | 542 |
535 bool remove = false; | 543 bool remove = false; |
536 result->GetBooleanWithoutPathExpansion(::onc::kRemove, &remove); | 544 result->GetBooleanWithoutPathExpansion(::onc::kRemove, &remove); |
537 if (!remove) { | 545 if (!remove) { |
538 all_required_exist &= | 546 all_required_exist &= |
539 RequireField(*result, kName) && RequireField(*result, kType); | 547 RequireField(*result, kName) && RequireField(*result, kType); |
540 | 548 |
| 549 std::string ip_address_config_type, name_servers_config_type; |
| 550 result->GetStringWithoutPathExpansion(kIPAddressConfigType, |
| 551 &ip_address_config_type); |
| 552 result->GetStringWithoutPathExpansion(kNameServersConfigType, |
| 553 &name_servers_config_type); |
| 554 if (ip_address_config_type == kIPConfigTypeStatic || |
| 555 name_servers_config_type == kIPConfigTypeStatic) { |
| 556 // TODO(pneubeck): Add ValidateStaticIPConfig and confirm that the |
| 557 // correct properties are provided based on the config type. |
| 558 all_required_exist &= RequireField(*result, kStaticIPConfig); |
| 559 } |
| 560 |
541 std::string type; | 561 std::string type; |
542 result->GetStringWithoutPathExpansion(kType, &type); | 562 result->GetStringWithoutPathExpansion(kType, &type); |
543 | 563 |
544 // Prohibit anything but WiFi and Ethernet for device-level policy (which | 564 // Prohibit anything but WiFi and Ethernet for device-level policy (which |
545 // corresponds to shared networks). See also http://crosbug.com/28741. | 565 // corresponds to shared networks). See also http://crosbug.com/28741. |
546 if (onc_source_ == ::onc::ONC_SOURCE_DEVICE_POLICY && !type.empty() && | 566 if (onc_source_ == ::onc::ONC_SOURCE_DEVICE_POLICY && !type.empty() && |
547 type != ::onc::network_type::kWiFi && | 567 type != ::onc::network_type::kWiFi && |
548 type != ::onc::network_type::kEthernet) { | 568 type != ::onc::network_type::kEthernet) { |
549 error_or_warning_found_ = true; | 569 error_or_warning_found_ = true; |
550 LOG(ERROR) << MessageHeader() << "Networks of type '" | 570 LOG(ERROR) << MessageHeader() << "Networks of type '" |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
906 } | 926 } |
907 | 927 |
908 std::string Validator::MessageHeader() { | 928 std::string Validator::MessageHeader() { |
909 std::string path = path_.empty() ? "toplevel" : JoinString(path_, "."); | 929 std::string path = path_.empty() ? "toplevel" : JoinString(path_, "."); |
910 std::string message = "At " + path + ": "; | 930 std::string message = "At " + path + ": "; |
911 return message; | 931 return message; |
912 } | 932 } |
913 | 933 |
914 } // namespace onc | 934 } // namespace onc |
915 } // namespace chromeos | 935 } // namespace chromeos |
OLD | NEW |