Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: sandbox/tests/common/controller.cc

Issue 9960045: Add sandbox support for associating peer processes (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sandbox/tests/common/controller.h ('k') | sandbox/tests/integration_tests/integration_tests.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/tests/common/controller.h" 5 #include "sandbox/tests/common/controller.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/process.h"
10 #include "base/process_util.h"
9 #include "base/sys_string_conversions.h" 11 #include "base/sys_string_conversions.h"
10 #include "base/win/windows_version.h" 12 #include "base/win/windows_version.h"
11 #include "sandbox/src/sandbox_factory.h" 13 #include "sandbox/src/sandbox_factory.h"
12 #include "sandbox/src/sandbox_utils.h" 14 #include "sandbox/src/sandbox_utils.h"
13 15
14 namespace { 16 namespace {
15 17
16 static const int kDefaultTimeout = 3000; 18 static const int kDefaultTimeout = 3000;
17 19
18 // Constructs a full path to a file inside the system32 folder. 20 // Constructs a full path to a file inside the system32 folder.
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 return NULL; 84 return NULL;
83 85
84 is_initialized = true; 86 is_initialized = true;
85 } 87 }
86 88
87 return broker; 89 return broker;
88 } 90 }
89 91
90 TestRunner::TestRunner(JobLevel job_level, TokenLevel startup_token, 92 TestRunner::TestRunner(JobLevel job_level, TokenLevel startup_token,
91 TokenLevel main_token) 93 TokenLevel main_token)
92 : is_init_(false), is_async_(false), target_process_id_(0) { 94 : is_init_(false), is_async_(false), no_sandbox_(false),
95 target_process_id_(0) {
93 Init(job_level, startup_token, main_token); 96 Init(job_level, startup_token, main_token);
94 } 97 }
95 98
96 TestRunner::TestRunner() 99 TestRunner::TestRunner()
97 : is_init_(false), is_async_(false), target_process_id_(0) { 100 : is_init_(false), is_async_(false), no_sandbox_(false),
101 target_process_id_(0) {
98 Init(JOB_LOCKDOWN, USER_RESTRICTED_SAME_ACCESS, USER_LOCKDOWN); 102 Init(JOB_LOCKDOWN, USER_RESTRICTED_SAME_ACCESS, USER_LOCKDOWN);
99 } 103 }
100 104
101 void TestRunner::Init(JobLevel job_level, TokenLevel startup_token, 105 void TestRunner::Init(JobLevel job_level, TokenLevel startup_token,
102 TokenLevel main_token) { 106 TokenLevel main_token) {
103 broker_ = NULL; 107 broker_ = NULL;
104 policy_ = NULL; 108 policy_ = NULL;
105 timeout_ = kDefaultTimeout; 109 timeout_ = kDefaultTimeout;
106 state_ = AFTER_REVERT; 110 state_ = AFTER_REVERT;
107 is_async_= false; 111 is_async_= false;
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 // Get the path to the sandboxed process. 206 // Get the path to the sandboxed process.
203 wchar_t prog_name[MAX_PATH]; 207 wchar_t prog_name[MAX_PATH];
204 GetModuleFileNameW(NULL, prog_name, MAX_PATH); 208 GetModuleFileNameW(NULL, prog_name, MAX_PATH);
205 209
206 // Launch the sandboxed process. 210 // Launch the sandboxed process.
207 ResultCode result = SBOX_ALL_OK; 211 ResultCode result = SBOX_ALL_OK;
208 PROCESS_INFORMATION target = {0}; 212 PROCESS_INFORMATION target = {0};
209 213
210 std::wstring arguments(L"\""); 214 std::wstring arguments(L"\"");
211 arguments += prog_name; 215 arguments += prog_name;
212 arguments += L"\" -child "; 216 arguments += L"\" -child";
217 arguments += no_sandbox_ ? L"-no-sandbox " : L" ";
213 arguments += command; 218 arguments += command;
214 219
215 result = broker_->SpawnTarget(prog_name, arguments.c_str(), policy_, 220 if (no_sandbox_) {
216 &target); 221 STARTUPINFO startup_info = {sizeof(STARTUPINFO)};
222 if (!::CreateProcessW(prog_name, &arguments[0], NULL, NULL, FALSE, 0,
223 NULL, NULL, &startup_info, &target)) {
224 return SBOX_ERROR_GENERIC;
225 }
226 broker_->AddTargetPeer(target.hProcess);
227 } else {
228 result = broker_->SpawnTarget(prog_name, arguments.c_str(), policy_,
229 &target);
230 }
217 231
218 if (SBOX_ALL_OK != result) 232 if (SBOX_ALL_OK != result)
219 return SBOX_TEST_FAILED_TO_RUN_TEST; 233 return SBOX_TEST_FAILED_TO_RUN_TEST;
220 234
221 ::ResumeThread(target.hThread); 235 ::ResumeThread(target.hThread);
222 236
223 // For an asynchronous run we don't bother waiting. 237 // For an asynchronous run we don't bother waiting.
224 if (is_async_) { 238 if (is_async_) {
225 target_process_.Set(target.hProcess); 239 target_process_.Set(target.hProcess);
226 target_process_id_ = target.dwProcessId; 240 target_process_id_ = target.dwProcessId;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 ::GetProcAddress(module, command_name.c_str())); 311 ::GetProcAddress(module, command_name.c_str()));
298 if (!command) 312 if (!command)
299 return SBOX_TEST_FAILED_TO_EXECUTE_COMMAND; 313 return SBOX_TEST_FAILED_TO_EXECUTE_COMMAND;
300 314
301 if (BEFORE_INIT == state) 315 if (BEFORE_INIT == state)
302 return command(argc - 4, argv + 4); 316 return command(argc - 4, argv + 4);
303 else if (EVERY_STATE == state) 317 else if (EVERY_STATE == state)
304 command(argc - 4, argv + 4); 318 command(argc - 4, argv + 4);
305 319
306 TargetServices* target = SandboxFactory::GetTargetServices(); 320 TargetServices* target = SandboxFactory::GetTargetServices();
307 if (!target) 321 if (target) {
322 if (SBOX_ALL_OK != target->Init())
323 return SBOX_TEST_FAILED_TO_EXECUTE_COMMAND;
324
325 if (BEFORE_REVERT == state)
326 return command(argc - 4, argv + 4);
327 else if (EVERY_STATE == state)
328 command(argc - 4, argv + 4);
329
330 target->LowerToken();
331 } else if (0 != _wcsicmp(argv[1], L"-child-no-sandbox")) {
308 return SBOX_TEST_FAILED_TO_EXECUTE_COMMAND; 332 return SBOX_TEST_FAILED_TO_EXECUTE_COMMAND;
333 }
309 334
310 if (SBOX_ALL_OK != target->Init())
311 return SBOX_TEST_FAILED_TO_EXECUTE_COMMAND;
312
313 if (BEFORE_REVERT == state)
314 return command(argc - 4, argv + 4);
315 else if (EVERY_STATE == state)
316 command(argc - 4, argv + 4);
317
318 target->LowerToken();
319 return command(argc - 4, argv + 4); 335 return command(argc - 4, argv + 4);
320 } 336 }
321 337
322 } // namespace sandbox 338 } // namespace sandbox
OLDNEW
« no previous file with comments | « sandbox/tests/common/controller.h ('k') | sandbox/tests/integration_tests/integration_tests.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698