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 "base/win/scoped_process_information.h" | 5 #include "base/win/scoped_process_information.h" |
6 #include "base/win/windows_version.h" | 6 #include "base/win/windows_version.h" |
7 #include "sandbox/win/src/sandbox.h" | 7 #include "sandbox/win/src/sandbox.h" |
8 #include "sandbox/win/src/sandbox_factory.h" | 8 #include "sandbox/win/src/sandbox_factory.h" |
9 #include "sandbox/win/src/sandbox_utils.h" | 9 #include "sandbox/win/src/sandbox_utils.h" |
10 #include "sandbox/win/src/target_services.h" | 10 #include "sandbox/win/src/target_services.h" |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 return ::GetLastError(); | 143 return ::GetLastError(); |
144 | 144 |
145 return SBOX_TEST_SUCCEEDED; | 145 return SBOX_TEST_SUCCEEDED; |
146 } | 146 } |
147 | 147 |
148 // Tests that we can call CreateProcess. | 148 // Tests that we can call CreateProcess. |
149 SBOX_TESTS_COMMAND int PolicyTargetTest_process(int argc, wchar_t **argv) { | 149 SBOX_TESTS_COMMAND int PolicyTargetTest_process(int argc, wchar_t **argv) { |
150 // Use default values to create a new process. | 150 // Use default values to create a new process. |
151 STARTUPINFO startup_info = {0}; | 151 STARTUPINFO startup_info = {0}; |
152 startup_info.cb = sizeof(startup_info); | 152 startup_info.cb = sizeof(startup_info); |
153 PROCESS_INFORMATION temp_process_info = {}; | 153 base::win::ScopedProcessInformation process_info; |
154 if (!::CreateProcessW(L"foo.exe", L"foo.exe", NULL, NULL, FALSE, 0, | 154 if (!::CreateProcessW(L"foo.exe", L"foo.exe", NULL, NULL, FALSE, 0, |
155 NULL, NULL, &startup_info, &temp_process_info)) | 155 NULL, NULL, &startup_info, process_info.Receive())) |
156 return SBOX_TEST_SUCCEEDED; | 156 return SBOX_TEST_SUCCEEDED; |
157 base::win::ScopedProcessInformation process_info(temp_process_info); | |
158 return SBOX_TEST_FAILED; | 157 return SBOX_TEST_FAILED; |
159 } | 158 } |
160 | 159 |
161 TEST(PolicyTargetTest, SetInformationThread) { | 160 TEST(PolicyTargetTest, SetInformationThread) { |
162 TestRunner runner; | 161 TestRunner runner; |
163 if (base::win::GetVersion() >= base::win::VERSION_XP) { | 162 if (base::win::GetVersion() >= base::win::VERSION_XP) { |
164 runner.SetTestState(BEFORE_REVERT); | 163 runner.SetTestState(BEFORE_REVERT); |
165 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"PolicyTargetTest_token")); | 164 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"PolicyTargetTest_token")); |
166 } | 165 } |
167 | 166 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 arguments += prog_name; | 232 arguments += prog_name; |
234 arguments += L"\" -child 0 wait"; // Don't care about the "state" argument. | 233 arguments += L"\" -child 0 wait"; // Don't care about the "state" argument. |
235 | 234 |
236 // Launch the app. | 235 // Launch the app. |
237 ResultCode result = SBOX_ALL_OK; | 236 ResultCode result = SBOX_ALL_OK; |
238 base::win::ScopedProcessInformation target; | 237 base::win::ScopedProcessInformation target; |
239 | 238 |
240 TargetPolicy* policy = broker->CreatePolicy(); | 239 TargetPolicy* policy = broker->CreatePolicy(); |
241 policy->SetAlternateDesktop(false); | 240 policy->SetAlternateDesktop(false); |
242 policy->SetTokenLevel(USER_INTERACTIVE, USER_LOCKDOWN); | 241 policy->SetTokenLevel(USER_INTERACTIVE, USER_LOCKDOWN); |
243 PROCESS_INFORMATION temp_process_info = {}; | |
244 result = broker->SpawnTarget(prog_name, arguments.c_str(), policy, | 242 result = broker->SpawnTarget(prog_name, arguments.c_str(), policy, |
245 &temp_process_info); | 243 target.Receive()); |
246 policy->Release(); | 244 policy->Release(); |
247 | 245 |
248 EXPECT_EQ(SBOX_ALL_OK, result); | 246 EXPECT_EQ(SBOX_ALL_OK, result); |
249 if (result == SBOX_ALL_OK) | |
250 target.Set(temp_process_info); | |
251 | 247 |
252 EXPECT_EQ(1, ::ResumeThread(target.thread_handle())); | 248 EXPECT_EQ(1, ::ResumeThread(target.thread_handle())); |
253 | 249 |
254 EXPECT_EQ(WAIT_TIMEOUT, ::WaitForSingleObject(target.process_handle(), 2000)); | 250 EXPECT_EQ(WAIT_TIMEOUT, ::WaitForSingleObject(target.process_handle(), 2000)); |
255 | 251 |
256 EXPECT_NE(::GetThreadDesktop(target.thread_id()), | 252 EXPECT_NE(::GetThreadDesktop(target.thread_id()), |
257 ::GetThreadDesktop(::GetCurrentThreadId())); | 253 ::GetThreadDesktop(::GetCurrentThreadId())); |
258 | 254 |
259 std::wstring desktop_name = policy->GetAlternateDesktop(); | 255 std::wstring desktop_name = policy->GetAlternateDesktop(); |
260 HDESK desk = ::OpenDesktop(desktop_name.c_str(), 0, FALSE, DESKTOP_ENUMERATE); | 256 HDESK desk = ::OpenDesktop(desktop_name.c_str(), 0, FALSE, DESKTOP_ENUMERATE); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 arguments += prog_name; | 292 arguments += prog_name; |
297 arguments += L"\" -child 0 wait"; // Don't care about the "state" argument. | 293 arguments += L"\" -child 0 wait"; // Don't care about the "state" argument. |
298 | 294 |
299 // Launch the app. | 295 // Launch the app. |
300 ResultCode result = SBOX_ALL_OK; | 296 ResultCode result = SBOX_ALL_OK; |
301 base::win::ScopedProcessInformation target; | 297 base::win::ScopedProcessInformation target; |
302 | 298 |
303 TargetPolicy* policy = broker->CreatePolicy(); | 299 TargetPolicy* policy = broker->CreatePolicy(); |
304 policy->SetAlternateDesktop(true); | 300 policy->SetAlternateDesktop(true); |
305 policy->SetTokenLevel(USER_INTERACTIVE, USER_LOCKDOWN); | 301 policy->SetTokenLevel(USER_INTERACTIVE, USER_LOCKDOWN); |
306 PROCESS_INFORMATION temp_process_info = {}; | |
307 result = broker->SpawnTarget(prog_name, arguments.c_str(), policy, | 302 result = broker->SpawnTarget(prog_name, arguments.c_str(), policy, |
308 &temp_process_info); | 303 target.Receive()); |
309 policy->Release(); | 304 policy->Release(); |
310 | 305 |
311 EXPECT_EQ(SBOX_ALL_OK, result); | 306 EXPECT_EQ(SBOX_ALL_OK, result); |
312 if (result == SBOX_ALL_OK) | |
313 target.Set(temp_process_info); | |
314 | 307 |
315 EXPECT_EQ(1, ::ResumeThread(target.thread_handle())); | 308 EXPECT_EQ(1, ::ResumeThread(target.thread_handle())); |
316 | 309 |
317 EXPECT_EQ(WAIT_TIMEOUT, ::WaitForSingleObject(target.process_handle(), 2000)); | 310 EXPECT_EQ(WAIT_TIMEOUT, ::WaitForSingleObject(target.process_handle(), 2000)); |
318 | 311 |
319 EXPECT_NE(::GetThreadDesktop(target.thread_id()), | 312 EXPECT_NE(::GetThreadDesktop(target.thread_id()), |
320 ::GetThreadDesktop(::GetCurrentThreadId())); | 313 ::GetThreadDesktop(::GetCurrentThreadId())); |
321 | 314 |
322 std::wstring desktop_name = policy->GetAlternateDesktop(); | 315 std::wstring desktop_name = policy->GetAlternateDesktop(); |
323 ASSERT_FALSE(desktop_name.empty()); | 316 ASSERT_FALSE(desktop_name.empty()); |
(...skipping 11 matching lines...) Expand all Loading... |
335 | 328 |
336 ::WaitForSingleObject(target.process_handle(), INFINITE); | 329 ::WaitForSingleObject(target.process_handle(), INFINITE); |
337 | 330 |
338 // Close the desktop handle. | 331 // Close the desktop handle. |
339 temp_policy = broker->CreatePolicy(); | 332 temp_policy = broker->CreatePolicy(); |
340 temp_policy->DestroyAlternateDesktop(); | 333 temp_policy->DestroyAlternateDesktop(); |
341 temp_policy->Release(); | 334 temp_policy->Release(); |
342 } | 335 } |
343 | 336 |
344 } // namespace sandbox | 337 } // namespace sandbox |
OLD | NEW |