Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Side by Side Diff: chromeos/network/onc/onc_validator.cc

Issue 11962048: This adds Cellular to the Shill to ONC translation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix some semantics Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 bool Validator::ValidateToplevelConfiguration( 380 bool Validator::ValidateToplevelConfiguration(
381 const base::DictionaryValue& onc_object, 381 const base::DictionaryValue& onc_object,
382 base::DictionaryValue* result) { 382 base::DictionaryValue* result) {
383 if (!ValidateObjectDefault(kToplevelConfigurationSignature, 383 if (!ValidateObjectDefault(kToplevelConfigurationSignature,
384 onc_object, result)) { 384 onc_object, result)) {
385 return false; 385 return false;
386 } 386 }
387 387
388 static const char* kValidTypes[] = 388 static const char* kValidTypes[] =
389 { kUnencryptedConfiguration, kEncryptedConfiguration, NULL }; 389 { kUnencryptedConfiguration, kEncryptedConfiguration, NULL };
390 if (FieldExistsAndHasNoValidValue(*result, kType, kValidTypes)) 390 if (FieldExistsAndHasNoValidValue(*result,
391 network_config::kType,
392 kValidTypes))
pneubeck (no reviews) 2013/01/18 10:27:41 toplevel_config::kType
Greg Spencer (Chromium) 2013/01/22 19:10:54 Done.
391 return false; 393 return false;
392 394
393 bool allRequiredExist = true; 395 bool allRequiredExist = true;
394 396
395 // Not part of the ONC spec yet: 397 // Not part of the ONC spec yet:
396 // We don't require the type field and default to UnencryptedConfiguration. 398 // We don't require the type field and default to UnencryptedConfiguration.
397 std::string type = kUnencryptedConfiguration; 399 std::string type = kUnencryptedConfiguration;
398 result->GetStringWithoutPathExpansion(kType, &type); 400 result->GetStringWithoutPathExpansion(network_config::kType, &type);
pneubeck (no reviews) 2013/01/18 10:27:41 here too
Greg Spencer (Chromium) 2013/01/22 19:10:54 Done.
399 if (type == kUnencryptedConfiguration && 401 if (type == kUnencryptedConfiguration &&
400 !result->HasKey(kNetworkConfigurations) && 402 !result->HasKey(kNetworkConfigurations) &&
401 !result->HasKey(kCertificates)) { 403 !result->HasKey(kCertificates)) {
402 error_or_warning_found_ = true; 404 error_or_warning_found_ = true;
403 std::string message = MessageHeader(error_on_missing_field_) + 405 std::string message = MessageHeader(error_on_missing_field_) +
404 "Neither the field '" + kNetworkConfigurations + "' nor '" + 406 "Neither the field '" + kNetworkConfigurations + "' nor '" +
405 kCertificates + "is present, but at least one is required."; 407 kCertificates + "is present, but at least one is required.";
406 if (error_on_missing_field_) 408 if (error_on_missing_field_)
407 LOG(ERROR) << message; 409 LOG(ERROR) << message;
408 else 410 else
409 LOG(WARNING) << message; 411 LOG(WARNING) << message;
410 allRequiredExist = false; 412 allRequiredExist = false;
411 } 413 }
412 414
413 return !error_on_missing_field_ || allRequiredExist; 415 return !error_on_missing_field_ || allRequiredExist;
414 } 416 }
415 417
416 bool Validator::ValidateNetworkConfiguration( 418 bool Validator::ValidateNetworkConfiguration(
417 const base::DictionaryValue& onc_object, 419 const base::DictionaryValue& onc_object,
418 base::DictionaryValue* result) { 420 base::DictionaryValue* result) {
419 if (!ValidateObjectDefault(kNetworkConfigurationSignature, 421 if (!ValidateObjectDefault(kNetworkConfigurationSignature,
pneubeck (no reviews) 2013/01/18 10:27:41 add using namespace onc::network_config;
Greg Spencer (Chromium) 2013/01/22 19:10:54 Done.
420 onc_object, result)) { 422 onc_object, result)) {
421 return false; 423 return false;
422 } 424 }
423 425
424 static const char* kValidTypes[] = { kEthernet, kVPN, kWiFi, NULL }; 426 static const char* kValidTypes[] = { network_type::kEthernet,
425 if (FieldExistsAndHasNoValidValue(*result, kType, kValidTypes)) 427 network_type::kVPN,
428 network_type::kWiFi,
429 NULL };
430 if (FieldExistsAndHasNoValidValue(*result,
431 network_config::kType,
432 kValidTypes))
426 return false; 433 return false;
427 434
428 bool allRequiredExist = RequireField(*result, kGUID); 435 bool allRequiredExist = RequireField(*result, network_config::kGUID);
429 436
430 bool remove = false; 437 bool remove = false;
431 result->GetBooleanWithoutPathExpansion(kRemove, &remove); 438 result->GetBooleanWithoutPathExpansion(kRemove, &remove);
432 if (!remove) { 439 if (!remove) {
433 allRequiredExist &= RequireField(*result, kName); 440 allRequiredExist &= RequireField(*result, network_config::kName);
434 allRequiredExist &= RequireField(*result, kType); 441 allRequiredExist &= RequireField(*result, network_config::kType);
435 442
436 std::string type; 443 std::string type;
437 result->GetStringWithoutPathExpansion(kType, &type); 444 result->GetStringWithoutPathExpansion(network_config::kType, &type);
438 445
439 // Prohibit anything but WiFi and Ethernet for device-level policy (which 446 // Prohibit anything but WiFi and Ethernet for device-level policy (which
440 // corresponds to shared networks). See also http://crosbug.com/28741. 447 // corresponds to shared networks). See also http://crosbug.com/28741.
441 if (onc_source_ == ONC_SOURCE_DEVICE_POLICY && 448 if (onc_source_ == ONC_SOURCE_DEVICE_POLICY &&
442 type != kWiFi && 449 type != network_type::kWiFi &&
443 type != kEthernet) { 450 type != network_type::kEthernet) {
444 error_or_warning_found_ = true; 451 error_or_warning_found_ = true;
445 LOG(ERROR) << ErrorHeader() << "Networks of type '" 452 LOG(ERROR) << ErrorHeader() << "Networks of type '"
446 << type << "' are prohibited in ONC device policies."; 453 << type << "' are prohibited in ONC device policies.";
447 return false; 454 return false;
448 } 455 }
449 allRequiredExist &= type.empty() || RequireField(*result, type); 456 allRequiredExist &= type.empty() || RequireField(*result, type);
pneubeck (no reviews) 2013/01/18 10:27:41 RequireField(*result, type) doesn't work anymore.
Greg Spencer (Chromium) 2013/01/22 19:10:54 Done.
450 } 457 }
451 458
452 return !error_on_missing_field_ || allRequiredExist; 459 return !error_on_missing_field_ || allRequiredExist;
453 } 460 }
454 461
455 bool Validator::ValidateEthernet( 462 bool Validator::ValidateEthernet(
456 const base::DictionaryValue& onc_object, 463 const base::DictionaryValue& onc_object,
457 base::DictionaryValue* result) { 464 base::DictionaryValue* result) {
458 using namespace onc::ethernet; 465 using namespace onc::ethernet;
459 if (!ValidateObjectDefault(kEthernetSignature, onc_object, result)) 466 if (!ValidateObjectDefault(kEthernetSignature, onc_object, result))
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 const base::DictionaryValue& onc_object, 739 const base::DictionaryValue& onc_object,
733 base::DictionaryValue* result) { 740 base::DictionaryValue* result) {
734 using namespace onc::certificate; 741 using namespace onc::certificate;
735 if (!ValidateObjectDefault(kCertificateSignature, onc_object, result)) 742 if (!ValidateObjectDefault(kCertificateSignature, onc_object, result))
736 return false; 743 return false;
737 744
738 static const char* kValidTypes[] = { kClient, kServer, kAuthority, NULL }; 745 static const char* kValidTypes[] = { kClient, kServer, kAuthority, NULL };
739 if (FieldExistsAndHasNoValidValue(*result, certificate::kType, kValidTypes)) 746 if (FieldExistsAndHasNoValidValue(*result, certificate::kType, kValidTypes))
740 return false; 747 return false;
741 748
742 bool allRequiredExist = RequireField(*result, kGUID); 749 bool allRequiredExist = RequireField(*result, network_config::kGUID);
pneubeck (no reviews) 2013/01/18 10:27:41 kGUID without namespace (with the 'using namespace
743 750
744 bool remove = false; 751 bool remove = false;
745 result->GetBooleanWithoutPathExpansion(kRemove, &remove); 752 result->GetBooleanWithoutPathExpansion(kRemove, &remove);
746 if (!remove) { 753 if (!remove) {
747 allRequiredExist &= RequireField(*result, certificate::kType); 754 allRequiredExist &= RequireField(*result, certificate::kType);
748 755
749 std::string type; 756 std::string type;
750 result->GetStringWithoutPathExpansion(certificate::kType, &type); 757 result->GetStringWithoutPathExpansion(certificate::kType, &type);
751 if (type == kClient) 758 if (type == kClient)
752 allRequiredExist &= RequireField(*result, kPKCS12); 759 allRequiredExist &= RequireField(*result, kPKCS12);
(...skipping 13 matching lines...) Expand all
766 } 773 }
767 774
768 std::string Validator::MessageHeader(bool is_error) { 775 std::string Validator::MessageHeader(bool is_error) {
769 std::string path = path_.empty() ? "toplevel" : JoinString(path_, "."); 776 std::string path = path_.empty() ? "toplevel" : JoinString(path_, ".");
770 std::string message = "At " + path + ": "; 777 std::string message = "At " + path + ": ";
771 return message; 778 return message;
772 } 779 }
773 780
774 } // namespace onc 781 } // namespace onc
775 } // namespace chromeos 782 } // namespace chromeos
OLDNEW
« chromeos/network/onc/onc_utils.cc ('K') | « chromeos/network/onc/onc_utils.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698