| 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 "components/policy/core/common/preg_parser_win.h" | 5 #include "components/policy/core/common/preg_parser_win.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <iterator> | 10 #include <iterator> |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 subdict = new RegistryDict(); | 169 subdict = new RegistryDict(); |
| 170 dict->SetKey(name, make_scoped_ptr(subdict)); | 170 dict->SetKey(name, make_scoped_ptr(subdict)); |
| 171 } | 171 } |
| 172 dict = subdict; | 172 dict = subdict; |
| 173 } | 173 } |
| 174 | 174 |
| 175 if (value.empty()) | 175 if (value.empty()) |
| 176 return; | 176 return; |
| 177 | 177 |
| 178 std::string value_name(base::UTF16ToUTF8(value)); | 178 std::string value_name(base::UTF16ToUTF8(value)); |
| 179 if (!StartsWithASCII(value_name, kActionTriggerPrefix, true)) { | 179 if (!base::StartsWithASCII(value_name, kActionTriggerPrefix, true)) { |
| 180 scoped_ptr<base::Value> value; | 180 scoped_ptr<base::Value> value; |
| 181 if (DecodePRegValue(type, data, &value)) | 181 if (DecodePRegValue(type, data, &value)) |
| 182 dict->SetValue(value_name, value.Pass()); | 182 dict->SetValue(value_name, value.Pass()); |
| 183 return; | 183 return; |
| 184 } | 184 } |
| 185 | 185 |
| 186 std::string action_trigger(base::StringToLowerASCII(value_name.substr( | 186 std::string action_trigger(base::StringToLowerASCII(value_name.substr( |
| 187 arraysize(kActionTriggerPrefix) - 1))); | 187 arraysize(kActionTriggerPrefix) - 1))); |
| 188 if (action_trigger == kActionTriggerDeleteValues) { | 188 if (action_trigger == kActionTriggerDeleteValues) { |
| 189 std::vector<std::string> values; | 189 std::vector<std::string> values; |
| 190 Tokenize(DecodePRegStringValue(data), ";", &values); | 190 Tokenize(DecodePRegStringValue(data), ";", &values); |
| 191 for (std::vector<std::string>::const_iterator value(values.begin()); | 191 for (std::vector<std::string>::const_iterator value(values.begin()); |
| 192 value != values.end(); ++value) { | 192 value != values.end(); ++value) { |
| 193 dict->RemoveValue(*value); | 193 dict->RemoveValue(*value); |
| 194 } | 194 } |
| 195 } else if (StartsWithASCII(action_trigger, kActionTriggerDeleteKeys, true)) { | 195 } else if (base::StartsWithASCII(action_trigger, kActionTriggerDeleteKeys, |
| 196 true)) { |
| 196 std::vector<std::string> keys; | 197 std::vector<std::string> keys; |
| 197 Tokenize(DecodePRegStringValue(data), ";", &keys); | 198 Tokenize(DecodePRegStringValue(data), ";", &keys); |
| 198 for (std::vector<std::string>::const_iterator key(keys.begin()); | 199 for (std::vector<std::string>::const_iterator key(keys.begin()); |
| 199 key != keys.end(); ++key) { | 200 key != keys.end(); ++key) { |
| 200 dict->RemoveKey(*key); | 201 dict->RemoveKey(*key); |
| 201 } | 202 } |
| 202 } else if (StartsWithASCII(action_trigger, kActionTriggerDel, true)) { | 203 } else if (base::StartsWithASCII(action_trigger, kActionTriggerDel, true)) { |
| 203 dict->RemoveValue( | 204 dict->RemoveValue( |
| 204 value_name.substr(arraysize(kActionTriggerPrefix) - 1 + | 205 value_name.substr(arraysize(kActionTriggerPrefix) - 1 + |
| 205 arraysize(kActionTriggerDel) - 1)); | 206 arraysize(kActionTriggerDel) - 1)); |
| 206 } else if (StartsWithASCII(action_trigger, kActionTriggerDelVals, true)) { | 207 } else if (base::StartsWithASCII(action_trigger, kActionTriggerDelVals, |
| 208 true)) { |
| 207 // Delete all values. | 209 // Delete all values. |
| 208 dict->ClearValues(); | 210 dict->ClearValues(); |
| 209 } else if (StartsWithASCII(action_trigger, kActionTriggerSecureKey, true) || | 211 } else if (base::StartsWithASCII(action_trigger, kActionTriggerSecureKey, |
| 210 StartsWithASCII(action_trigger, kActionTriggerSoft, true)) { | 212 true) || |
| 213 base::StartsWithASCII(action_trigger, kActionTriggerSoft, true)) { |
| 211 // Doesn't affect values. | 214 // Doesn't affect values. |
| 212 } else { | 215 } else { |
| 213 LOG(ERROR) << "Bad action trigger " << value_name; | 216 LOG(ERROR) << "Bad action trigger " << value_name; |
| 214 } | 217 } |
| 215 } | 218 } |
| 216 | 219 |
| 217 bool ReadFile(const base::FilePath& file_path, | 220 bool ReadFile(const base::FilePath& file_path, |
| 218 const base::string16& root, | 221 const base::string16& root, |
| 219 RegistryDict* dict, | 222 RegistryDict* dict, |
| 220 PolicyLoadStatusSample* status) { | 223 PolicyLoadStatusSample* status) { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 data.resize(size); | 291 data.resize(size); |
| 289 if (!ReadFieldBinary(&cursor, end, size, vector_as_array(&data))) | 292 if (!ReadFieldBinary(&cursor, end, size, vector_as_array(&data))) |
| 290 break; | 293 break; |
| 291 current = NextChar(&cursor, end); | 294 current = NextChar(&cursor, end); |
| 292 } | 295 } |
| 293 | 296 |
| 294 if (current != kDelimBracketClose) | 297 if (current != kDelimBracketClose) |
| 295 break; | 298 break; |
| 296 | 299 |
| 297 // Process the record if it is within the |root| subtree. | 300 // Process the record if it is within the |root| subtree. |
| 298 if (StartsWith(key_name, root, false)) | 301 if (base::StartsWith(key_name, root, false)) |
| 299 HandleRecord(key_name.substr(root.size()), value, type, data, dict); | 302 HandleRecord(key_name.substr(root.size()), value, type, data, dict); |
| 300 } | 303 } |
| 301 | 304 |
| 302 LOG(ERROR) << "Error parsing " << file_path.value() << " at offset " | 305 LOG(ERROR) << "Error parsing " << file_path.value() << " at offset " |
| 303 << reinterpret_cast<const uint8*>(cursor - 1) - mapped_file.data(); | 306 << reinterpret_cast<const uint8*>(cursor - 1) - mapped_file.data(); |
| 304 status->Add(POLICY_LOAD_STATUS_PARSE_ERROR); | 307 status->Add(POLICY_LOAD_STATUS_PARSE_ERROR); |
| 305 return false; | 308 return false; |
| 306 } | 309 } |
| 307 | 310 |
| 308 } // namespace preg_parser | 311 } // namespace preg_parser |
| 309 } // namespace policy | 312 } // namespace policy |
| OLD | NEW |