Index: chromeos/network/onc/onc_validator.cc |
diff --git a/chromeos/network/onc/onc_validator.cc b/chromeos/network/onc/onc_validator.cc |
index a57aeca2d6e77608b5532f9f853e2a33c7f4f2fa..c674653ab0bf8fdb8cbf687148ba47dfee0cc131 100644 |
--- a/chromeos/network/onc/onc_validator.cc |
+++ b/chromeos/network/onc/onc_validator.cc |
@@ -380,14 +380,20 @@ bool Validator::CertPatternInDevicePolicy(const std::string& cert_type) { |
bool Validator::ValidateToplevelConfiguration( |
const base::DictionaryValue& onc_object, |
base::DictionaryValue* result) { |
+ using namespace onc::toplevel_config; |
+ |
if (!ValidateObjectDefault(kToplevelConfigurationSignature, |
onc_object, result)) { |
return false; |
} |
static const char* kValidTypes[] = |
- { kUnencryptedConfiguration, kEncryptedConfiguration, NULL }; |
- if (FieldExistsAndHasNoValidValue(*result, kType, kValidTypes)) |
+ { kUnencryptedConfiguration, |
+ kEncryptedConfiguration, |
+ NULL }; |
+ if (FieldExistsAndHasNoValidValue(*result, |
+ kType, |
+ kValidTypes)) |
return false; |
bool allRequiredExist = true; |
@@ -401,8 +407,9 @@ bool Validator::ValidateToplevelConfiguration( |
!result->HasKey(kCertificates)) { |
error_or_warning_found_ = true; |
std::string message = MessageHeader(error_on_missing_field_) + |
- "Neither the field '" + kNetworkConfigurations + "' nor '" + |
- kCertificates + "is present, but at least one is required."; |
+ "Neither the field '" + kNetworkConfigurations + |
+ "' nor '" + kCertificates + |
+ "is present, but at least one is required."; |
if (error_on_missing_field_) |
LOG(ERROR) << message; |
else |
@@ -416,13 +423,20 @@ bool Validator::ValidateToplevelConfiguration( |
bool Validator::ValidateNetworkConfiguration( |
const base::DictionaryValue& onc_object, |
base::DictionaryValue* result) { |
+ using namespace onc::network_config; |
+ |
if (!ValidateObjectDefault(kNetworkConfigurationSignature, |
onc_object, result)) { |
return false; |
} |
- static const char* kValidTypes[] = { kEthernet, kVPN, kWiFi, NULL }; |
- if (FieldExistsAndHasNoValidValue(*result, kType, kValidTypes)) |
+ static const char* kValidTypes[] = { network_type::kEthernet, |
+ network_type::kVPN, |
+ network_type::kWiFi, |
+ NULL }; |
+ if (FieldExistsAndHasNoValidValue(*result, |
+ kType, |
+ kValidTypes)) |
return false; |
bool allRequiredExist = RequireField(*result, kGUID); |
@@ -439,14 +453,24 @@ bool Validator::ValidateNetworkConfiguration( |
// Prohibit anything but WiFi and Ethernet for device-level policy (which |
// corresponds to shared networks). See also http://crosbug.com/28741. |
if (onc_source_ == ONC_SOURCE_DEVICE_POLICY && |
- type != kWiFi && |
- type != kEthernet) { |
+ type != network_type::kWiFi && |
+ type != network_type::kEthernet) { |
error_or_warning_found_ = true; |
LOG(ERROR) << ErrorHeader() << "Networks of type '" |
<< type << "' are prohibited in ONC device policies."; |
return false; |
} |
- allRequiredExist &= type.empty() || RequireField(*result, type); |
+ |
+ if (type == network_type::kWiFi) |
+ allRequiredExist &= RequireField(*result, network_config::kWiFi); |
+ else if (type == network_type::kEthernet) |
+ allRequiredExist &= RequireField(*result, network_config::kEthernet); |
+ else if (type == network_type::kCellular) |
+ allRequiredExist &= RequireField(*result, network_config::kCellular); |
+ else if (type == network_type::kVPN) |
+ allRequiredExist &= RequireField(*result, network_config::kVPN); |
+ else |
+ LOG(ERROR) << "Unknown network type " << type << " encountered"; |
} |
return !error_on_missing_field_ || allRequiredExist; |
@@ -736,7 +760,7 @@ bool Validator::ValidateCertificate( |
return false; |
static const char* kValidTypes[] = { kClient, kServer, kAuthority, NULL }; |
- if (FieldExistsAndHasNoValidValue(*result, certificate::kType, kValidTypes)) |
+ if (FieldExistsAndHasNoValidValue(*result, kType, kValidTypes)) |
return false; |
bool allRequiredExist = RequireField(*result, kGUID); |
@@ -744,10 +768,10 @@ bool Validator::ValidateCertificate( |
bool remove = false; |
result->GetBooleanWithoutPathExpansion(kRemove, &remove); |
if (!remove) { |
- allRequiredExist &= RequireField(*result, certificate::kType); |
+ allRequiredExist &= RequireField(*result, kType); |
std::string type; |
- result->GetStringWithoutPathExpansion(certificate::kType, &type); |
+ result->GetStringWithoutPathExpansion(kType, &type); |
if (type == kClient) |
allRequiredExist &= RequireField(*result, kPKCS12); |
else if (type == kServer || type == kAuthority) |