OLD | NEW |
1 // Copyright (c) 2010 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 #include <algorithm> | 5 #include <algorithm> |
5 #include <cctype> | 6 #include <cctype> |
6 | 7 |
7 #include <windows.h> | 8 #include <windows.h> |
8 #include <winioctl.h> | 9 #include <winioctl.h> |
9 | 10 |
10 #include "base/scoped_handle_win.h" | 11 #include "base/win/scoped_handle.h" |
11 #include "sandbox/src/nt_internals.h" | 12 #include "sandbox/src/nt_internals.h" |
12 #include "sandbox/src/sandbox.h" | 13 #include "sandbox/src/sandbox.h" |
13 #include "sandbox/src/sandbox_factory.h" | 14 #include "sandbox/src/sandbox_factory.h" |
14 #include "sandbox/src/sandbox_policy.h" | 15 #include "sandbox/src/sandbox_policy.h" |
15 #include "sandbox/src/win_utils.h" | 16 #include "sandbox/src/win_utils.h" |
16 #include "sandbox/tests/common/controller.h" | 17 #include "sandbox/tests/common/controller.h" |
17 #include "sandbox/tests/common/test_utils.h" | 18 #include "sandbox/tests/common/test_utils.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
19 | 20 |
20 #define BINDNTDLL(name) \ | 21 #define BINDNTDLL(name) \ |
21 name ## Function name = reinterpret_cast<name ## Function>( \ | 22 name ## Function name = reinterpret_cast<name ## Function>( \ |
22 ::GetProcAddress(::GetModuleHandle(L"ntdll.dll"), #name)) | 23 ::GetProcAddress(::GetModuleHandle(L"ntdll.dll"), #name)) |
23 | 24 |
24 namespace sandbox { | 25 namespace sandbox { |
25 | 26 |
26 const ULONG kSharing = FILE_SHARE_WRITE | FILE_SHARE_READ | FILE_SHARE_DELETE; | 27 const ULONG kSharing = FILE_SHARE_WRITE | FILE_SHARE_READ | FILE_SHARE_DELETE; |
27 | 28 |
28 // Creates a file using different desired access. Returns if the call succeeded | 29 // Creates a file using different desired access. Returns if the call succeeded |
29 // or not. The first argument in argv is the filename. If the second argument | 30 // or not. The first argument in argv is the filename. If the second argument |
30 // is "read", we try read only access. Otherwise we try read-write access. | 31 // is "read", we try read only access. Otherwise we try read-write access. |
31 SBOX_TESTS_COMMAND int File_Create(int argc, wchar_t **argv) { | 32 SBOX_TESTS_COMMAND int File_Create(int argc, wchar_t **argv) { |
32 if (argc != 2) | 33 if (argc != 2) |
33 return SBOX_TEST_FAILED_TO_EXECUTE_COMMAND; | 34 return SBOX_TEST_FAILED_TO_EXECUTE_COMMAND; |
34 | 35 |
35 bool read = (_wcsicmp(argv[0], L"Read") == 0); | 36 bool read = (_wcsicmp(argv[0], L"Read") == 0); |
36 | 37 |
37 if (read) { | 38 if (read) { |
38 ScopedHandle file1(CreateFile(argv[1], GENERIC_READ, kSharing, NULL, | 39 base::win::ScopedHandle file1(CreateFile( |
39 OPEN_EXISTING, 0, NULL)); | 40 argv[1], GENERIC_READ, kSharing, NULL, OPEN_EXISTING, 0, NULL)); |
40 ScopedHandle file2(CreateFile(argv[1], FILE_EXECUTE, kSharing, NULL, | 41 base::win::ScopedHandle file2(CreateFile( |
41 OPEN_EXISTING, 0, NULL)); | 42 argv[1], FILE_EXECUTE, kSharing, NULL, OPEN_EXISTING, 0, NULL)); |
42 | 43 |
43 if (file1.Get() && file2.Get()) | 44 if (file1.Get() && file2.Get()) |
44 return SBOX_TEST_SUCCEEDED; | 45 return SBOX_TEST_SUCCEEDED; |
45 return SBOX_TEST_DENIED; | 46 return SBOX_TEST_DENIED; |
46 } else { | 47 } else { |
47 ScopedHandle file1(CreateFile(argv[1], GENERIC_ALL, kSharing, NULL, | 48 base::win::ScopedHandle file1(CreateFile( |
48 OPEN_EXISTING, 0, NULL)); | 49 argv[1], GENERIC_ALL, kSharing, NULL, OPEN_EXISTING, 0, NULL)); |
49 ScopedHandle file2(CreateFile(argv[1], GENERIC_READ | FILE_WRITE_DATA, | 50 base::win::ScopedHandle file2(CreateFile( |
50 kSharing, NULL, OPEN_EXISTING, 0, NULL)); | 51 argv[1], GENERIC_READ | FILE_WRITE_DATA, kSharing, NULL, OPEN_EXISTING, |
| 52 0, NULL)); |
51 | 53 |
52 if (file1.Get() && file2.Get()) | 54 if (file1.Get() && file2.Get()) |
53 return SBOX_TEST_SUCCEEDED; | 55 return SBOX_TEST_SUCCEEDED; |
54 return SBOX_TEST_DENIED; | 56 return SBOX_TEST_DENIED; |
55 } | 57 } |
56 } | 58 } |
57 | 59 |
58 SBOX_TESTS_COMMAND int File_Win32Create(int argc, wchar_t **argv) { | 60 SBOX_TESTS_COMMAND int File_Win32Create(int argc, wchar_t **argv) { |
59 if (argc != 1) { | 61 if (argc != 1) { |
60 SBOX_TEST_FAILED_TO_EXECUTE_COMMAND; | 62 SBOX_TEST_FAILED_TO_EXECUTE_COMMAND; |
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
587 EXPECT_TRUE(INVALID_HANDLE_VALUE != dir); | 589 EXPECT_TRUE(INVALID_HANDLE_VALUE != dir); |
588 EXPECT_TRUE(DeleteReparsePoint(dir)); | 590 EXPECT_TRUE(DeleteReparsePoint(dir)); |
589 EXPECT_TRUE(::CloseHandle(dir)); | 591 EXPECT_TRUE(::CloseHandle(dir)); |
590 | 592 |
591 // Cleanup. | 593 // Cleanup. |
592 EXPECT_TRUE(::DeleteFile(temp_file_in_temp.c_str())); | 594 EXPECT_TRUE(::DeleteFile(temp_file_in_temp.c_str())); |
593 EXPECT_TRUE(::RemoveDirectory(subfolder.c_str())); | 595 EXPECT_TRUE(::RemoveDirectory(subfolder.c_str())); |
594 } | 596 } |
595 | 597 |
596 } // namespace sandbox | 598 } // namespace sandbox |
OLD | NEW |