| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <memory> |
| 5 #include <string> | 6 #include <string> |
| 6 #include <memory> | |
| 7 | 7 |
| 8 #include "base/scoped_handle_win.h" | 8 #include "base/win/scoped_handle.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | |
| 10 #include "sandbox/src/sandbox.h" | 9 #include "sandbox/src/sandbox.h" |
| 11 #include "sandbox/src/sandbox_policy.h" | 10 #include "sandbox/src/sandbox_policy.h" |
| 12 #include "sandbox/src/sandbox_factory.h" | 11 #include "sandbox/src/sandbox_factory.h" |
| 13 #include "sandbox/src/sandbox_utils.h" | 12 #include "sandbox/src/sandbox_utils.h" |
| 14 #include "sandbox/tests/common/controller.h" | 13 #include "sandbox/tests/common/controller.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 // While the shell API provides better calls than this home brew function | 18 // While the shell API provides better calls than this home brew function |
| 19 // we use GetSystemWindowsDirectoryW which does not query the registry so | 19 // we use GetSystemWindowsDirectoryW which does not query the registry so |
| 20 // it is safe to use after revert. | 20 // it is safe to use after revert. |
| 21 std::wstring MakeFullPathToSystem32(const wchar_t* name) { | 21 std::wstring MakeFullPathToSystem32(const wchar_t* name) { |
| 22 wchar_t windows_path[MAX_PATH] = {0}; | 22 wchar_t windows_path[MAX_PATH] = {0}; |
| 23 ::GetSystemWindowsDirectoryW(windows_path, MAX_PATH); | 23 ::GetSystemWindowsDirectoryW(windows_path, MAX_PATH); |
| 24 std::wstring full_path(windows_path); | 24 std::wstring full_path(windows_path); |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 std::wstring path = MakeFullPathToSystem32(argv[0]); | 171 std::wstring path = MakeFullPathToSystem32(argv[0]); |
| 172 | 172 |
| 173 PROCESS_INFORMATION pi = {0}; | 173 PROCESS_INFORMATION pi = {0}; |
| 174 STARTUPINFOW si = {sizeof(si)}; | 174 STARTUPINFOW si = {sizeof(si)}; |
| 175 | 175 |
| 176 if (!::CreateProcessW(path.c_str(), NULL, NULL, NULL, FALSE, CREATE_SUSPENDED, | 176 if (!::CreateProcessW(path.c_str(), NULL, NULL, NULL, FALSE, CREATE_SUSPENDED, |
| 177 NULL, NULL, &si, &pi)) { | 177 NULL, NULL, &si, &pi)) { |
| 178 return SBOX_TEST_FAILED; | 178 return SBOX_TEST_FAILED; |
| 179 } | 179 } |
| 180 | 180 |
| 181 ScopedHandle process(pi.hProcess); | 181 base::win::ScopedHandle process(pi.hProcess); |
| 182 ScopedHandle thread(pi.hThread); | 182 base::win::ScopedHandle thread(pi.hThread); |
| 183 | 183 |
| 184 HANDLE token = NULL; | 184 HANDLE token = NULL; |
| 185 BOOL result = ::OpenProcessToken(process.Get(), TOKEN_IMPERSONATE, &token); | 185 BOOL result = ::OpenProcessToken(process.Get(), TOKEN_IMPERSONATE, &token); |
| 186 DWORD error = ::GetLastError(); | 186 DWORD error = ::GetLastError(); |
| 187 | 187 |
| 188 ScopedHandle token_handle(token); | 188 base::win::ScopedHandle token_handle(token); |
| 189 | 189 |
| 190 if (!::TerminateProcess(process.Get(), 0)) | 190 if (!::TerminateProcess(process.Get(), 0)) |
| 191 return SBOX_TEST_FAILED; | 191 return SBOX_TEST_FAILED; |
| 192 | 192 |
| 193 if (result && token) | 193 if (result && token) |
| 194 return SBOX_TEST_SUCCEEDED; | 194 return SBOX_TEST_SUCCEEDED; |
| 195 | 195 |
| 196 if (ERROR_ACCESS_DENIED == error) | 196 if (ERROR_ACCESS_DENIED == error) |
| 197 return SBOX_TEST_DENIED; | 197 return SBOX_TEST_DENIED; |
| 198 | 198 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 ASSERT_TRUE(!exe_path.empty()); | 285 ASSERT_TRUE(!exe_path.empty()); |
| 286 EXPECT_TRUE(runner.AddRule(TargetPolicy::SUBSYS_PROCESS, | 286 EXPECT_TRUE(runner.AddRule(TargetPolicy::SUBSYS_PROCESS, |
| 287 TargetPolicy::PROCESS_ALL_EXEC, | 287 TargetPolicy::PROCESS_ALL_EXEC, |
| 288 exe_path.c_str())); | 288 exe_path.c_str())); |
| 289 | 289 |
| 290 EXPECT_EQ(SBOX_TEST_SUCCEEDED, | 290 EXPECT_EQ(SBOX_TEST_SUCCEEDED, |
| 291 runner.RunTest(L"Process_GetChildProcessToken findstr.exe")); | 291 runner.RunTest(L"Process_GetChildProcessToken findstr.exe")); |
| 292 } | 292 } |
| 293 | 293 |
| 294 } // namespace sandbox | 294 } // namespace sandbox |
| OLD | NEW |