#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "components/policy/core/common/schema.h"
#include <limits.h>
#include <stddef.h>
#include <algorithm>
#include <climits>
#include <map>
#include <memory>
#include <ostream>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include "base/check_op.h"
#include "base/compiler_specific.h"
#include "base/containers/contains.h"
#include "base/containers/flat_set.h"
#include "base/json/json_reader.h"
#include "base/memory/ptr_util.h"
#include "base/notreached.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/types/expected.h"
#include "base/types/expected_macros.h"
#include "base/values.h"
#include "components/policy/core/common/json_schema_constants.h"
#include "components/policy/core/common/schema_internal.h"
#include "third_party/re2/src/re2/re2.h"
schema;
namespace policy {
PropertiesNode;
PropertyNode;
RestrictionNode;
SchemaData;
SchemaNode;
std::string ErrorPathToString(const std::string& policy_name,
PolicyErrorPath error_path) { … }
const char kSensitiveValueMask[] = …;
namespace {
struct ReferencesAndIDs { … };
struct StorageSizes { … };
const short kInvalid = …;
struct SchemaKeyToValueType { … };
const SchemaKeyToValueType kSchemaTypesToValueTypes[] = …;
const SchemaKeyToValueType* kSchemaTypesToValueTypesEnd = …;
const SchemaKeyToValueType kAttributesAndTypesForArray[] = …;
const SchemaKeyToValueType* kAttributesAndTypesForArrayEnd = …;
const SchemaKeyToValueType kAttributesAndTypesForBoolean[] = …;
const SchemaKeyToValueType* kAttributesAndTypesForBooleanEnd = …;
const SchemaKeyToValueType kAttributesAndTypesForInteger[] = …;
const SchemaKeyToValueType* kAttributesAndTypesForIntegerEnd = …;
const SchemaKeyToValueType kAttributesAndTypesForNumber[] = …;
const SchemaKeyToValueType* kAttributesAndTypesForNumberEnd = …;
const SchemaKeyToValueType kAttributesAndTypesForObject[] = …;
const SchemaKeyToValueType* kAttributesAndTypesForObjectEnd = …;
const SchemaKeyToValueType kAttributesAndTypesForRef[] = …;
const SchemaKeyToValueType* kAttributesAndTypesForRefEnd = …;
const SchemaKeyToValueType kAttributesAndTypesForString[] = …;
const SchemaKeyToValueType* kAttributesAndTypesForStringEnd = …;
bool CompareToString(const SchemaKeyToValueType& entry,
const std::string& key) { … }
bool MapSchemaKeyToValueType(const std::string& schema_key,
const SchemaKeyToValueType* begin,
const SchemaKeyToValueType* end,
base::Value::Type* value_type) { … }
bool SchemaTypeToValueType(const std::string& schema_type,
base::Value::Type* value_type) { … }
bool StrategyAllowUnknown(SchemaOnErrorStrategy strategy) { … }
bool StrategyAllowInvalidListEntry(SchemaOnErrorStrategy strategy) { … }
bool StrategyAllowUnknownWithoutWarning(SchemaOnErrorStrategy strategy) { … }
void SchemaErrorFound(PolicyErrorPath* out_error_path,
std::string* out_error,
const std::string& msg) { … }
void AddListIndexPrefixToPath(int index, PolicyErrorPath* path) { … }
void AddDictKeyPrefixToPath(const std::string& key, PolicyErrorPath* path) { … }
bool IgnoreUnknownAttributes(int options) { … }
bool CheckType(const base::Value* value, base::Value::Type expected_type) { … }
bool IsValidType(const std::string& type) { … }
base::expected<void, std::string> ValidateAttributesAndTypes(
const base::Value::Dict& dict,
const std::string& type,
int options) { … }
base::expected<void, std::string> ValidateEnum(const base::Value* enum_list,
const std::string& type) { … }
base::expected<void, std::string> IsValidSchema(const base::Value::Dict& dict,
int options);
base::expected<void, std::string> ValidateProperties(
const base::Value::Dict& properties,
int options) { … }
base::expected<void, std::string> IsFieldTypeObject(
const base::Value& field,
const std::string& field_name) { … }
base::expected<void, std::string> IsValidSchema(const base::Value::Dict& dict,
int options) { … }
}
class Schema::InternalStorage
: public base::RefCountedThreadSafe<InternalStorage> { … };
Schema::InternalStorage::InternalStorage() = default;
Schema::InternalStorage::~InternalStorage() = default;
scoped_refptr<const Schema::InternalStorage> Schema::InternalStorage::Wrap(
const SchemaData* data) { … }
base::expected<scoped_refptr<const Schema::InternalStorage>, std::string>
Schema::InternalStorage::ParseSchema(const base::Value::Dict& schema) { … }
re2::RE2* Schema::InternalStorage::CompileRegex(
const std::string& pattern) const { … }
void Schema::InternalStorage::DetermineStorageSizes(
const base::Value::Dict& schema,
StorageSizes* sizes) { … }
base::expected<void, std::string> Schema::InternalStorage::Parse(
const base::Value::Dict& schema,
short* index,
ReferencesAndIDs* references_and_ids) { … }
base::expected<void, std::string> Schema::InternalStorage::ParseDictionary(
const base::Value::Dict& schema,
SchemaNode* schema_node,
ReferencesAndIDs* references_and_ids) { … }
base::expected<void, std::string> Schema::InternalStorage::ParseList(
const base::Value::Dict& schema,
SchemaNode* schema_node,
ReferencesAndIDs* references_and_ids) { … }
base::expected<void, std::string> Schema::InternalStorage::ParseEnum(
const base::Value::Dict& schema,
base::Value::Type type,
SchemaNode* schema_node) { … }
base::expected<void, std::string> Schema::InternalStorage::ParseRangedInt(
const base::Value::Dict& schema,
SchemaNode* schema_node) { … }
base::expected<void, std::string> Schema::InternalStorage::ParseStringPattern(
const base::Value::Dict& schema,
SchemaNode* schema_node) { … }
bool Schema::InternalStorage::ResolveReferences(
const ReferencesAndIDs& references_and_ids,
std::string* error) { … }
void Schema::InternalStorage::FindSensitiveChildren() { … }
bool Schema::InternalStorage::FindSensitiveChildrenRecursive(
int index,
std::set<int>* handled_schema_nodes) { … }
Schema::Iterator::Iterator(const scoped_refptr<const InternalStorage>& storage,
const PropertiesNode* node) { … }
Schema::Iterator::Iterator(const Iterator& iterator)
: … { … }
Schema::Iterator::~Iterator() = default;
Schema::Iterator& Schema::Iterator::operator=(const Iterator& iterator) { … }
bool Schema::Iterator::IsAtEnd() const { … }
void Schema::Iterator::Advance() { … }
const char* Schema::Iterator::key() const { … }
Schema Schema::Iterator::schema() const { … }
Schema::Schema() : … { … }
Schema::Schema(const scoped_refptr<const InternalStorage>& storage,
const SchemaNode* node)
: … { … }
Schema::Schema(const Schema& schema)
: … { … }
Schema::~Schema() = default;
Schema& Schema::operator=(const Schema& schema) { … }
Schema Schema::Wrap(const SchemaData* data) { … }
bool Schema::Validate(const base::Value& value,
SchemaOnErrorStrategy strategy,
PolicyErrorPath* out_error_path,
std::string* out_error) const { … }
bool Schema::Normalize(base::Value* value,
SchemaOnErrorStrategy strategy,
PolicyErrorPath* out_error_path,
std::string* out_error,
bool* out_changed) const { … }
void Schema::MaskSensitiveValues(base::Value* value) const { … }
base::expected<Schema, std::string> Schema::Parse(const std::string& content) { … }
base::expected<base::Value::Dict, std::string> Schema::ParseToDictAndValidate(
const std::string& schema,
int validator_options) { … }
base::Value::Type Schema::type() const { … }
Schema::Iterator Schema::GetPropertiesIterator() const { … }
namespace {
bool CompareKeys(const PropertyNode& node, const std::string& key) { … }
}
Schema Schema::GetKnownProperty(const std::string& key) const { … }
Schema Schema::GetAdditionalProperties() const { … }
SchemaList Schema::GetPatternProperties(const std::string& key) const { … }
std::vector<std::string> Schema::GetRequiredProperties() const { … }
Schema Schema::GetProperty(const std::string& key) const { … }
SchemaList Schema::GetMatchingProperties(const std::string& key) const { … }
Schema Schema::GetItems() const { … }
bool Schema::ValidateIntegerRestriction(int index, int value) const { … }
bool Schema::ValidateStringRestriction(int index, const char* str) const { … }
void Schema::MaskSensitiveValuesRecursive(base::Value* value) const { … }
Schema Schema::GetValidationSchema() const { … }
bool Schema::IsSensitiveValue() const { … }
bool Schema::HasSensitiveChildren() const { … }
}