1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // This file provides a parser for PReg files which are used for storing group
6 // policy settings in the file system. The file format is documented here:
7 //
8 // http://msdn.microsoft.com/en-us/library/windows/desktop/aa374407(v=vs.85).aspx
9 
10 #ifndef COMPONENTS_POLICY_CORE_COMMON_PREG_PARSER_H_
11 #define COMPONENTS_POLICY_CORE_COMMON_PREG_PARSER_H_
12 
13 #include <memory>
14 #include <vector>
15 
16 #include "base/strings/string16.h"
17 #include "components/policy/core/common/policy_load_status.h"
18 #include "components/policy/policy_export.h"
19 
20 namespace base {
21 class FilePath;
22 }
23 
24 namespace policy {
25 
26 class RegistryDict;
27 
28 namespace preg_parser {
29 
30 // The magic header in PReg files: ASCII "PReg" + version (0x0001).
31 POLICY_EXPORT extern const char kPRegFileHeader[8];
32 
33 // Reads the PReg file at |file_path| and writes the registry data to |dict|.
34 // |root| specifies the registry subtree the caller is interested in, everything
35 // else gets ignored. It may be empty if all keys should be returned, but it
36 // must NOT end with a backslash.
37 POLICY_EXPORT bool ReadFile(const base::FilePath& file_path,
38                             const base::string16& root,
39                             RegistryDict* dict,
40                             PolicyLoadStatusSampler* status);
41 
42 // Similar to ReadFile, but reads from |preg_data| of length |preg_data_size|
43 // instead of a file. |debug_name| is printed out along with error messages.
44 // Used internally and for testing only. All other callers should use ReadFile
45 // instead.
46 POLICY_EXPORT bool ReadDataInternal(const uint8_t* preg_data,
47                                     size_t preg_data_size,
48                                     const base::string16& root,
49                                     RegistryDict* dict,
50                                     PolicyLoadStatusSampler* status,
51                                     const std::string& debug_name);
52 
53 }  // namespace preg_parser
54 }  // namespace policy
55 
56 #endif  // COMPONENTS_POLICY_CORE_COMMON_PREG_PARSER_H_
57