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