| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/policy/preg_parser_win.h" | 5 #include "chrome/browser/policy/preg_parser_win.h" |
| 6 | 6 |
| 7 #include <windows.h> |
| 8 |
| 7 #include <algorithm> | 9 #include <algorithm> |
| 8 #include <iterator> | 10 #include <iterator> |
| 9 | 11 #include <vector> |
| 10 #include <windows.h> | |
| 11 | 12 |
| 12 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
| 13 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 14 #include "base/files/memory_mapped_file.h" | 15 #include "base/files/memory_mapped_file.h" |
| 15 #include "base/logging.h" | 16 #include "base/logging.h" |
| 16 #include "base/stl_util.h" | 17 #include "base/stl_util.h" |
| 17 #include "base/string16.h" | 18 #include "base/string16.h" |
| 18 #include "base/string_util.h" | 19 #include "base/string_util.h" |
| 19 #include "base/sys_byteorder.h" | 20 #include "base/sys_byteorder.h" |
| 20 #include "base/utf_string_conversions.h" | 21 #include "base/utf_string_conversions.h" |
| 21 #include "base/values.h" | 22 #include "base/values.h" |
| 22 | 23 |
| 23 namespace policy { | 24 namespace policy { |
| 24 namespace preg_parser { | 25 namespace preg_parser { |
| 25 | 26 |
| 26 // The magic header in PReg files: ASCII "PReg" + version (0x0001). | 27 const char kPRegFileHeader[8] = |
| 27 const char kPolicyRegistryFileHeader[] = "PReg\x01\x00\x00\x00"; | 28 { 'P', 'R', 'e', 'g', '\x01', '\x00', '\x00', '\x00' }; |
| 28 | 29 |
| 29 // Maximum PReg file size we're willing to accept. | 30 // Maximum PReg file size we're willing to accept. |
| 30 const int64 kMaxPRegFileSize = 1024 * 1024 * 16; | 31 const int64 kMaxPRegFileSize = 1024 * 1024 * 16; |
| 31 | 32 |
| 32 // Constants for PReg file delimiters. | 33 // Constants for PReg file delimiters. |
| 33 const char16 kDelimBracketOpen = L'['; | 34 const char16 kDelimBracketOpen = L'['; |
| 34 const char16 kDelimBracketClose = L']'; | 35 const char16 kDelimBracketClose = L']'; |
| 35 const char16 kDelimSemicolon = L';'; | 36 const char16 kDelimSemicolon = L';'; |
| 36 | 37 |
| 37 // Registry path separator. | 38 // Registry path separator. |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 return false; | 222 return false; |
| 222 } | 223 } |
| 223 | 224 |
| 224 if (mapped_file.length() > kMaxPRegFileSize) { | 225 if (mapped_file.length() > kMaxPRegFileSize) { |
| 225 LOG(ERROR) << "PReg file " << file_path.value() << " too large: " | 226 LOG(ERROR) << "PReg file " << file_path.value() << " too large: " |
| 226 << mapped_file.length(); | 227 << mapped_file.length(); |
| 227 return false; | 228 return false; |
| 228 } | 229 } |
| 229 | 230 |
| 230 // Check the header. | 231 // Check the header. |
| 231 const int kHeaderSize = arraysize(kPolicyRegistryFileHeader) - 1; | 232 const int kHeaderSize = arraysize(kPRegFileHeader); |
| 232 if (mapped_file.length() < kHeaderSize || | 233 if (mapped_file.length() < kHeaderSize || |
| 233 memcmp(kPolicyRegistryFileHeader, mapped_file.data(), kHeaderSize) != 0) { | 234 memcmp(kPRegFileHeader, mapped_file.data(), kHeaderSize) != 0) { |
| 234 LOG(ERROR) << "Bad policy file " << file_path.value(); | 235 LOG(ERROR) << "Bad policy file " << file_path.value(); |
| 235 return false; | 236 return false; |
| 236 } | 237 } |
| 237 | 238 |
| 238 // Parse file contents, which is UCS-2 and little-endian. The latter I | 239 // Parse file contents, which is UCS-2 and little-endian. The latter I |
| 239 // couldn't find documentation on, but the example I saw were all | 240 // couldn't find documentation on, but the example I saw were all |
| 240 // little-endian. It'd be interesting to check on big-endian hardware. | 241 // little-endian. It'd be interesting to check on big-endian hardware. |
| 241 const uint8* cursor = mapped_file.data() + kHeaderSize; | 242 const uint8* cursor = mapped_file.data() + kHeaderSize; |
| 242 const uint8* end = mapped_file.data() + mapped_file.length(); | 243 const uint8* end = mapped_file.data() + mapped_file.length(); |
| 243 while (true) { | 244 while (true) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 HandleRecord(key_name.substr(root.size()), value, type, data, dict); | 294 HandleRecord(key_name.substr(root.size()), value, type, data, dict); |
| 294 } | 295 } |
| 295 | 296 |
| 296 LOG(ERROR) << "Error parsing " << file_path.value() << " at offset " | 297 LOG(ERROR) << "Error parsing " << file_path.value() << " at offset " |
| 297 << reinterpret_cast<const uint8*>(cursor - 1) - mapped_file.data(); | 298 << reinterpret_cast<const uint8*>(cursor - 1) - mapped_file.data(); |
| 298 return false; | 299 return false; |
| 299 } | 300 } |
| 300 | 301 |
| 301 } // namespace preg_parser | 302 } // namespace preg_parser |
| 302 } // namespace policy | 303 } // namespace policy |
| OLD | NEW |