| 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/strings/stringprintf.h" | 5 #include "base/strings/stringprintf.h" |
| 6 #include "sandbox/win/src/handle_policy.h" | 6 #include "sandbox/win/src/handle_policy.h" |
| 7 #include "sandbox/win/src/nt_internals.h" | 7 #include "sandbox/win/src/nt_internals.h" |
| 8 #include "sandbox/win/src/sandbox.h" | 8 #include "sandbox/win/src/sandbox.h" |
| 9 #include "sandbox/win/src/sandbox_factory.h" | 9 #include "sandbox/win/src/sandbox_factory.h" |
| 10 #include "sandbox/win/src/sandbox_policy.h" | 10 #include "sandbox/win/src/sandbox_policy.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 base::win::ScopedHandle test_event; | 32 base::win::ScopedHandle test_event; |
| 33 test_event.Set(::CreateEvent(NULL, TRUE, TRUE, NULL)); | 33 test_event.Set(::CreateEvent(NULL, TRUE, TRUE, NULL)); |
| 34 if (!test_event.IsValid()) | 34 if (!test_event.IsValid()) |
| 35 return SBOX_TEST_FIRST_ERROR; | 35 return SBOX_TEST_FIRST_ERROR; |
| 36 | 36 |
| 37 // Get the target process ID. | 37 // Get the target process ID. |
| 38 DWORD target_process_id = ::wcstoul(argv[0], NULL, 10); | 38 DWORD target_process_id = ::wcstoul(argv[0], NULL, 10); |
| 39 | 39 |
| 40 HANDLE handle = NULL; | 40 HANDLE handle = NULL; |
| 41 ResultCode result = SandboxFactory::GetTargetServices()->DuplicateHandle( | 41 ResultCode result = SandboxFactory::GetTargetServices()->DuplicateHandle( |
| 42 test_event, target_process_id, &handle, 0, DUPLICATE_SAME_ACCESS); | 42 test_event.Get(), target_process_id, &handle, 0, DUPLICATE_SAME_ACCESS); |
| 43 | 43 |
| 44 return (result == SBOX_ALL_OK) ? SBOX_TEST_SUCCEEDED : SBOX_TEST_DENIED; | 44 return (result == SBOX_ALL_OK) ? SBOX_TEST_SUCCEEDED : SBOX_TEST_DENIED; |
| 45 } | 45 } |
| 46 | 46 |
| 47 // Tests that duplicating an object works only when the policy allows it. | 47 // Tests that duplicating an object works only when the policy allows it. |
| 48 TEST(HandlePolicyTest, DuplicateHandle) { | 48 TEST(HandlePolicyTest, DuplicateHandle) { |
| 49 TestRunner target; | 49 TestRunner target; |
| 50 TestRunner runner; | 50 TestRunner runner; |
| 51 | 51 |
| 52 // Kick off an asynchronous target process for testing. | 52 // Kick off an asynchronous target process for testing. |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 | 105 |
| 106 // Now successfully open the event after adding a broker handle rule. | 106 // Now successfully open the event after adding a broker handle rule. |
| 107 EXPECT_TRUE(runner.AddRule(TargetPolicy::SUBSYS_HANDLES, | 107 EXPECT_TRUE(runner.AddRule(TargetPolicy::SUBSYS_HANDLES, |
| 108 TargetPolicy::HANDLES_DUP_BROKER, | 108 TargetPolicy::HANDLES_DUP_BROKER, |
| 109 L"Event")); | 109 L"Event")); |
| 110 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(cmd_line.c_str())); | 110 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(cmd_line.c_str())); |
| 111 } | 111 } |
| 112 | 112 |
| 113 } // namespace sandbox | 113 } // namespace sandbox |
| 114 | 114 |
| OLD | NEW |