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 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 return true; | 464 return true; |
465 } | 465 } |
466 | 466 |
467 bool Validator::ValidateNetworkConfiguration(base::DictionaryValue* result) { | 467 bool Validator::ValidateNetworkConfiguration(base::DictionaryValue* result) { |
468 using namespace ::onc::network_config; | 468 using namespace ::onc::network_config; |
469 | 469 |
470 const char* const kValidTypes[] = { | 470 const char* const kValidTypes[] = { |
471 ::onc::network_type::kEthernet, ::onc::network_type::kVPN, | 471 ::onc::network_type::kEthernet, ::onc::network_type::kVPN, |
472 ::onc::network_type::kWiFi, ::onc::network_type::kCellular}; | 472 ::onc::network_type::kWiFi, ::onc::network_type::kCellular}; |
473 const std::vector<const char*> valid_types(toVector(kValidTypes)); | 473 const std::vector<const char*> valid_types(toVector(kValidTypes)); |
| 474 const char* const kValidIPConfigTypes[] = {kIPConfigTypeDHCP, |
| 475 kIPConfigTypeStatic}; |
| 476 const std::vector<const char*> valid_ipconfig_types( |
| 477 toVector(kValidIPConfigTypes)); |
474 if (FieldExistsAndHasNoValidValue(*result, kType, valid_types) || | 478 if (FieldExistsAndHasNoValidValue(*result, kType, valid_types) || |
| 479 FieldExistsAndHasNoValidValue(*result, kIPConfigType, |
| 480 valid_ipconfig_types) || |
475 FieldExistsAndIsEmpty(*result, kGUID)) { | 481 FieldExistsAndIsEmpty(*result, kGUID)) { |
476 return false; | 482 return false; |
477 } | 483 } |
478 | 484 |
479 if (!CheckGuidIsUniqueAndAddToSet(*result, kGUID, &network_guids_)) | 485 if (!CheckGuidIsUniqueAndAddToSet(*result, kGUID, &network_guids_)) |
480 return false; | 486 return false; |
481 | 487 |
482 bool all_required_exist = RequireField(*result, kGUID); | 488 bool all_required_exist = RequireField(*result, kGUID); |
483 | 489 |
484 bool remove = false; | 490 bool remove = false; |
485 result->GetBooleanWithoutPathExpansion(::onc::kRemove, &remove); | 491 result->GetBooleanWithoutPathExpansion(::onc::kRemove, &remove); |
486 if (!remove) { | 492 if (!remove) { |
487 all_required_exist &= | 493 all_required_exist &= |
488 RequireField(*result, kName) && RequireField(*result, kType); | 494 RequireField(*result, kName) && RequireField(*result, kType); |
489 | 495 |
| 496 std::string ipconfig_type; |
| 497 result->GetStringWithoutPathExpansion(kIPConfigType, &ipconfig_type); |
| 498 if (ipconfig_type == kIPConfigTypeStatic) |
| 499 all_required_exist &= RequireField(*result, kStaticIPConfig); |
| 500 |
490 std::string type; | 501 std::string type; |
491 result->GetStringWithoutPathExpansion(kType, &type); | 502 result->GetStringWithoutPathExpansion(kType, &type); |
492 | 503 |
493 // Prohibit anything but WiFi and Ethernet for device-level policy (which | 504 // Prohibit anything but WiFi and Ethernet for device-level policy (which |
494 // corresponds to shared networks). See also http://crosbug.com/28741. | 505 // corresponds to shared networks). See also http://crosbug.com/28741. |
495 if (onc_source_ == ::onc::ONC_SOURCE_DEVICE_POLICY && !type.empty() && | 506 if (onc_source_ == ::onc::ONC_SOURCE_DEVICE_POLICY && !type.empty() && |
496 type != ::onc::network_type::kWiFi && | 507 type != ::onc::network_type::kWiFi && |
497 type != ::onc::network_type::kEthernet) { | 508 type != ::onc::network_type::kEthernet) { |
498 error_or_warning_found_ = true; | 509 error_or_warning_found_ = true; |
499 LOG(ERROR) << MessageHeader() << "Networks of type '" | 510 LOG(ERROR) << MessageHeader() << "Networks of type '" |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
844 } | 855 } |
845 | 856 |
846 std::string Validator::MessageHeader() { | 857 std::string Validator::MessageHeader() { |
847 std::string path = path_.empty() ? "toplevel" : JoinString(path_, "."); | 858 std::string path = path_.empty() ? "toplevel" : JoinString(path_, "."); |
848 std::string message = "At " + path + ": "; | 859 std::string message = "At " + path + ": "; |
849 return message; | 860 return message; |
850 } | 861 } |
851 | 862 |
852 } // namespace onc | 863 } // namespace onc |
853 } // namespace chromeos | 864 } // namespace chromeos |
OLD | NEW |