OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <string> | 5 #include <string> |
6 #include <map> | 6 #include <map> |
7 | 7 |
8 #include "sandbox/win/src/policy_low_level.h" | 8 #include "sandbox/win/src/policy_low_level.h" |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 | 10 |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 // This function get called from a simple state machine implemented in | 144 // This function get called from a simple state machine implemented in |
145 // AddStringMatch() which passes the current state (in state) and it passes | 145 // AddStringMatch() which passes the current state (in state) and it passes |
146 // true in last_call if AddStringMatch() has finished processing the input | 146 // true in last_call if AddStringMatch() has finished processing the input |
147 // pattern string and this would be the last call to generate any pending | 147 // pattern string and this would be the last call to generate any pending |
148 // opcode. The skip_count is the currently accumulated number of '?' seen so | 148 // opcode. The skip_count is the currently accumulated number of '?' seen so |
149 // far and once the associated opcode is generated this function sets it back | 149 // far and once the associated opcode is generated this function sets it back |
150 // to zero. | 150 // to zero. |
151 bool PolicyRule::GenStringOpcode(RuleType rule_type, | 151 bool PolicyRule::GenStringOpcode(RuleType rule_type, |
152 StringMatchOptions match_opts, | 152 StringMatchOptions match_opts, |
153 uint16 parameter, int state, bool last_call, | 153 uint16 parameter, int state, bool last_call, |
154 int* skip_count, std::wstring* fragment) { | 154 int* skip_count, base::string16* fragment) { |
155 | 155 |
156 // The last opcode must: | 156 // The last opcode must: |
157 // 1) Always clear the context. | 157 // 1) Always clear the context. |
158 // 2) Preserve the negation. | 158 // 2) Preserve the negation. |
159 // 3) Remove the 'OR' mode flag. | 159 // 3) Remove the 'OR' mode flag. |
160 uint32 options = kPolNone; | 160 uint32 options = kPolNone; |
161 if (last_call) { | 161 if (last_call) { |
162 if (IF_NOT == rule_type) { | 162 if (IF_NOT == rule_type) { |
163 options = kPolClearContext | kPolNegateEval; | 163 options = kPolClearContext | kPolNegateEval; |
164 } else { | 164 } else { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 StringMatchOptions match_opts) { | 219 StringMatchOptions match_opts) { |
220 if (done_) { | 220 if (done_) { |
221 // Do not allow to add more rules after generating the action opcode. | 221 // Do not allow to add more rules after generating the action opcode. |
222 return false; | 222 return false; |
223 } | 223 } |
224 | 224 |
225 const wchar_t* current_char = string; | 225 const wchar_t* current_char = string; |
226 uint32 last_char = kLastCharIsNone; | 226 uint32 last_char = kLastCharIsNone; |
227 int state = PENDING_NONE; | 227 int state = PENDING_NONE; |
228 int skip_count = 0; // counts how many '?' we have seen in a row. | 228 int skip_count = 0; // counts how many '?' we have seen in a row. |
229 std::wstring fragment; // accumulates the non-wildcard part of the string. | 229 base::string16 fragment; // accumulates the non-wildcard part. |
230 | 230 |
231 while (L'\0' != *current_char) { | 231 while (L'\0' != *current_char) { |
232 switch (*current_char) { | 232 switch (*current_char) { |
233 case L'*': | 233 case L'*': |
234 if (kLastCharIsWild & last_char) { | 234 if (kLastCharIsWild & last_char) { |
235 // '**' and '&*' is an error. | 235 // '**' and '&*' is an error. |
236 return false; | 236 return false; |
237 } | 237 } |
238 if (!GenStringOpcode(rule_type, match_opts, parameter, | 238 if (!GenStringOpcode(rule_type, match_opts, parameter, |
239 state, false, &skip_count, &fragment)) { | 239 state, false, &skip_count, &fragment)) { |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 | 339 |
340 return true; | 340 return true; |
341 } | 341 } |
342 | 342 |
343 PolicyRule::~PolicyRule() { | 343 PolicyRule::~PolicyRule() { |
344 delete [] reinterpret_cast<char*>(buffer_); | 344 delete [] reinterpret_cast<char*>(buffer_); |
345 delete opcode_factory_; | 345 delete opcode_factory_; |
346 } | 346 } |
347 | 347 |
348 } // namespace sandbox | 348 } // namespace sandbox |
OLD | NEW |