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