| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/win/tests/common/controller.h" | 5 #include "sandbox/win/tests/common/controller.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/memory/shared_memory.h" | 9 #include "base/memory/shared_memory.h" |
| 10 #include "base/process/process.h" | 10 #include "base/process/process.h" |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 if (!policy_) | 129 if (!policy_) |
| 130 return; | 130 return; |
| 131 | 131 |
| 132 policy_->SetJobLevel(job_level, 0); | 132 policy_->SetJobLevel(job_level, 0); |
| 133 policy_->SetTokenLevel(startup_token, main_token); | 133 policy_->SetTokenLevel(startup_token, main_token); |
| 134 | 134 |
| 135 is_init_ = true; | 135 is_init_ = true; |
| 136 } | 136 } |
| 137 | 137 |
| 138 TargetPolicy* TestRunner::GetPolicy() { | 138 TargetPolicy* TestRunner::GetPolicy() { |
| 139 return policy_; | 139 return policy_.get(); |
| 140 } | 140 } |
| 141 | 141 |
| 142 TestRunner::~TestRunner() { | 142 TestRunner::~TestRunner() { |
| 143 if (target_process_.IsValid() && kill_on_destruction_) | 143 if (target_process_.IsValid() && kill_on_destruction_) |
| 144 ::TerminateProcess(target_process_.Get(), 0); | 144 ::TerminateProcess(target_process_.Get(), 0); |
| 145 | |
| 146 if (policy_) | |
| 147 policy_->Release(); | |
| 148 } | 145 } |
| 149 | 146 |
| 150 bool TestRunner::AddRule(TargetPolicy::SubSystem subsystem, | 147 bool TestRunner::AddRule(TargetPolicy::SubSystem subsystem, |
| 151 TargetPolicy::Semantics semantics, | 148 TargetPolicy::Semantics semantics, |
| 152 const wchar_t* pattern) { | 149 const wchar_t* pattern) { |
| 153 if (!is_init_) | 150 if (!is_init_) |
| 154 return false; | 151 return false; |
| 155 | 152 |
| 156 return (SBOX_ALL_OK == policy_->AddRule(subsystem, semantics, pattern)); | 153 return (SBOX_ALL_OK == policy_->AddRule(subsystem, semantics, pattern)); |
| 157 } | 154 } |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 if (no_sandbox_) { | 232 if (no_sandbox_) { |
| 236 STARTUPINFO startup_info = {sizeof(STARTUPINFO)}; | 233 STARTUPINFO startup_info = {sizeof(STARTUPINFO)}; |
| 237 if (!::CreateProcessW(prog_name, &arguments[0], NULL, NULL, FALSE, 0, | 234 if (!::CreateProcessW(prog_name, &arguments[0], NULL, NULL, FALSE, 0, |
| 238 NULL, NULL, &startup_info, &target)) { | 235 NULL, NULL, &startup_info, &target)) { |
| 239 return SBOX_ERROR_GENERIC; | 236 return SBOX_ERROR_GENERIC; |
| 240 } | 237 } |
| 241 } else { | 238 } else { |
| 242 result = broker_->SpawnTarget(prog_name, arguments.c_str(), policy_, | 239 result = broker_->SpawnTarget(prog_name, arguments.c_str(), policy_, |
| 243 &warning_result, &last_error, &target); | 240 &warning_result, &last_error, &target); |
| 244 } | 241 } |
| 245 if (release_policy_in_run_) { | 242 if (release_policy_in_run_) |
| 246 policy_->Release(); | |
| 247 policy_ = nullptr; | 243 policy_ = nullptr; |
| 248 } | |
| 249 | 244 |
| 250 if (SBOX_ALL_OK != result) | 245 if (SBOX_ALL_OK != result) |
| 251 return SBOX_TEST_FAILED_TO_RUN_TEST; | 246 return SBOX_TEST_FAILED_TO_RUN_TEST; |
| 252 | 247 |
| 253 ::ResumeThread(target.hThread); | 248 ::ResumeThread(target.hThread); |
| 254 | 249 |
| 255 // For an asynchronous run we don't bother waiting. | 250 // For an asynchronous run we don't bother waiting. |
| 256 if (is_async_) { | 251 if (is_async_) { |
| 257 target_process_.Set(target.hProcess); | 252 target_process_.Set(target.hProcess); |
| 258 target_process_id_ = target.dwProcessId; | 253 target_process_id_ = target.dwProcessId; |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 | 367 |
| 373 target->LowerToken(); | 368 target->LowerToken(); |
| 374 } else if (0 != _wcsicmp(argv[1], L"-child-no-sandbox")) { | 369 } else if (0 != _wcsicmp(argv[1], L"-child-no-sandbox")) { |
| 375 return SBOX_TEST_FAILED_TO_EXECUTE_COMMAND; | 370 return SBOX_TEST_FAILED_TO_EXECUTE_COMMAND; |
| 376 } | 371 } |
| 377 | 372 |
| 378 return command(argc - 4, argv + 4); | 373 return command(argc - 4, argv + 4); |
| 379 } | 374 } |
| 380 | 375 |
| 381 } // namespace sandbox | 376 } // namespace sandbox |
| OLD | NEW |