Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "sandbox/mac/policy.h" | 5 #include "sandbox/mac/policy.h" |
| 6 | 6 |
| 7 namespace sandbox { | 7 namespace sandbox { |
| 8 | 8 |
| 9 Rule::Rule() | 9 Rule::Rule() |
| 10 : result(POLICY_DECISION_INVALID), | 10 : result(POLICY_DECISION_INVALID), |
| 11 substitute_port(MACH_PORT_NULL) { | 11 substitute_port(MACH_PORT_NULL) { |
| 12 } | 12 } |
| 13 | 13 |
| 14 Rule::Rule(PolicyDecision result) | 14 Rule::Rule(PolicyDecision result) |
| 15 : result(result), | 15 : result(result), |
| 16 substitute_port(MACH_PORT_NULL) { | 16 substitute_port(MACH_PORT_NULL) { |
| 17 } | 17 } |
| 18 | 18 |
| 19 Rule::Rule(mach_port_t override_port) | 19 Rule::Rule(mach_port_t override_port) |
| 20 : result(POLICY_SUBSTITUTE_PORT), | 20 : result(POLICY_SUBSTITUTE_PORT), |
| 21 substitute_port(override_port) { | 21 substitute_port(override_port) { |
| 22 } | 22 } |
| 23 | 23 |
| 24 bool IsPolicyValid(const BootstrapSandboxPolicy& policy) { | 24 BootstrapSandboxPolicy::BootstrapSandboxPolicy() |
| 25 for (BootstrapSandboxPolicy::const_iterator it = policy.begin(); | 25 : default_rule(POLICY_DENY_ERROR) { |
| 26 it != policy.end(); | 26 } |
| 27 ++it) { | 27 |
| 28 const Rule& rule = it->second; | 28 BootstrapSandboxPolicy::~BootstrapSandboxPolicy() {} |
| 29 if (!(rule.result > POLICY_DECISION_INVALID && | 29 |
| 30 rule.result < POLICY_DECISION_LAST)) { | 30 static bool IsRuleValid(const Rule& rule) { |
| 31 if (!(rule.result > POLICY_DECISION_INVALID && | |
| 32 rule.result < POLICY_DECISION_LAST)) { | |
| 33 return false; | |
| 34 } | |
| 35 if (rule.result == POLICY_SUBSTITUTE_PORT) { | |
| 36 if (rule.substitute_port == MACH_PORT_NULL) | |
| 31 return false; | 37 return false; |
| 32 } | 38 } else { |
| 33 if (rule.result == POLICY_SUBSTITUTE_PORT) { | 39 if (rule.substitute_port != MACH_PORT_NULL) |
| 34 if (rule.substitute_port == MACH_PORT_NULL) | 40 return false; |
| 35 return false; | |
| 36 } else { | |
| 37 if (rule.substitute_port != MACH_PORT_NULL) | |
| 38 return false; | |
| 39 } | |
| 40 } | 41 } |
| 41 return true; | 42 return true; |
| 42 } | 43 } |
| 44 | |
| 45 bool IsPolicyValid(const BootstrapSandboxPolicy& policy) { | |
| 46 if (!IsRuleValid(policy.default_rule)) | |
| 47 return false; | |
| 48 | |
| 49 for (BootstrapSandboxPolicy::NamedRules::const_iterator it = | |
|
Mark Mentovai
2014/06/03 16:57:27
You can just write "for (const auto& kv : policy.r
Robert Sesek
2014/06/03 17:30:52
I like const auto&.
| |
| 50 policy.rules.begin(); | |
| 51 it != policy.rules.end(); | |
| 52 ++it) { | |
| 53 if (!IsRuleValid(it->second)) | |
| 54 return false; | |
| 55 } | |
| 56 return true; | |
| 57 } | |
| 43 | 58 |
| 44 } // namespace sandbox | 59 } // namespace sandbox |
| OLD | NEW |