aboutsummaryrefslogtreecommitdiffstats
path: root/policy/policy_util.cc
diff options
context:
space:
mode:
authorIgor <igorcov@chromium.org>2017-09-20 15:56:08 +0200
committerSen Jiang <senj@google.com>2018-01-11 14:09:03 -0800
commit0cd09dcb4449e0afcaf74cbbd5a993846e906e51 (patch)
tree952188b7d5d0bc6cf1601731a7aadd1f7cf4345e /policy/policy_util.cc
parentb91af3b238d0e3dc69a736f4977b65ce6bb264ff (diff)
downloadplatform_external_libbrillo-0cd09dcb4449e0afcaf74cbbd5a993846e906e51.tar.gz
platform_external_libbrillo-0cd09dcb4449e0afcaf74cbbd5a993846e906e51.tar.bz2
platform_external_libbrillo-0cd09dcb4449e0afcaf74cbbd5a993846e906e51.zip
libbrillo: policy: Increase resilience for policy readandroid-wear-8.0.0_r1
The policy files will be stored with indexes as suffix to improve resilience to disk corruptions. This change makes it possible to read the policy data from new files and validate them. Design doc: https://docs.google.com/document/d/1RdUKb-deQCBiyc6Dpdf4RDBEPV-feb5WHu7uzY1YozQ/edit#heading=h.h0q5njx6l4xf BUG=chromium:764337 TEST=Manual CQ-DEPEND=CL:681939, CL:819250, CL:819353, CL:819412 Change-Id: I10f31d307925c6ccef3cfd0887a71b7c774139e2 Reviewed-on: https://chromium-review.googlesource.com/674935 Commit-Ready: Igor <igorcov@chromium.org> Tested-by: Igor <igorcov@chromium.org> Reviewed-by: Maksim Ivanov <emaxx@chromium.org> Reviewed-by: Dan Erat <derat@chromium.org> (cherry picked from commit d213a401f639649b3e38f6def5782ae2f1322fce) Merged-In: I10f31d307925c6ccef3cfd0887a71b7c774139e2
Diffstat (limited to 'policy/policy_util.cc')
-rw-r--r--policy/policy_util.cc41
1 files changed, 41 insertions, 0 deletions
diff --git a/policy/policy_util.cc b/policy/policy_util.cc
new file mode 100644
index 0000000..8c17fc2
--- /dev/null
+++ b/policy/policy_util.cc
@@ -0,0 +1,41 @@
+// Copyright 2017 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "policy/policy_util.h"
+
+#include <base/files/file_util.h>
+#include <base/logging.h>
+
+namespace policy {
+
+LoadPolicyResult LoadPolicyFromPath(
+ const base::FilePath& policy_path,
+ std::string* policy_data_str_out,
+ enterprise_management::PolicyFetchResponse* policy_out) {
+ DCHECK(policy_data_str_out);
+ DCHECK(policy_out);
+ if (!base::PathExists(policy_path)) {
+ return LoadPolicyResult::kFileNotFound;
+ }
+
+ if (!base::ReadFileToString(policy_path, policy_data_str_out)) {
+ PLOG(ERROR) << "Could not read policy off disk at " << policy_path.value();
+ return LoadPolicyResult::kFailedToReadFile;
+ }
+
+ if (policy_data_str_out->empty()) {
+ LOG(ERROR) << "Empty policy file at " << policy_path.value();
+ return LoadPolicyResult::kEmptyFile;
+ }
+
+ if (!policy_out->ParseFromString(*policy_data_str_out)) {
+ LOG(ERROR) << "Policy on disk could not be parsed, file: "
+ << policy_path.value();
+ return LoadPolicyResult::kInvalidPolicyData;
+ }
+
+ return LoadPolicyResult::kSuccess;
+}
+
+} // namespace policy