OLD | NEW |
---|---|
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <string> | 5 #include <string> |
6 | 6 |
7 #include "sandbox/win/src/sync_policy.h" | 7 #include "sandbox/win/src/sync_policy.h" |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/strings/stringprintf.h" | |
10 #include "sandbox/win/src/ipc_tags.h" | 11 #include "sandbox/win/src/ipc_tags.h" |
12 #include "sandbox/win/src/nt_internals.h" | |
11 #include "sandbox/win/src/policy_engine_opcodes.h" | 13 #include "sandbox/win/src/policy_engine_opcodes.h" |
12 #include "sandbox/win/src/policy_params.h" | 14 #include "sandbox/win/src/policy_params.h" |
13 #include "sandbox/win/src/sandbox_types.h" | 15 #include "sandbox/win/src/sandbox_types.h" |
14 #include "sandbox/win/src/sandbox_utils.h" | 16 #include "sandbox/win/src/sandbox_utils.h" |
17 #include "sandbox/win/src/sync_interception.h" | |
18 #include "sandbox/win/src/win_utils.h" | |
15 | 19 |
16 namespace sandbox { | 20 namespace sandbox { |
17 | 21 |
22 NTSTATUS GetBaseNamedObjectsDirectory(HANDLE* directory) { | |
23 static HANDLE base_named_objects_handle = NULL; | |
24 if (base_named_objects_handle) { | |
25 *directory = base_named_objects_handle; | |
26 return STATUS_SUCCESS; | |
27 } | |
28 | |
29 NtOpenDirectoryObjectFunction NtOpenDirectoryObject = NULL; | |
30 ResolveNTFunctionPtr("NtOpenDirectoryObject", &NtOpenDirectoryObject); | |
31 | |
32 DWORD session_id = 0; | |
33 ProcessIdToSessionId(::GetCurrentProcessId(), &session_id); | |
34 | |
35 std::wstring base_named_objects_path = | |
36 base::StringPrintf(L"\\Sessions\\%d\\BaseNamedObjects", session_id); | |
37 | |
38 UNICODE_STRING directory_name = {0}; | |
39 OBJECT_ATTRIBUTES object_attributes = {0}; | |
40 InitObjectAttribs(base_named_objects_path, OBJ_CASE_INSENSITIVE, NULL, | |
41 &object_attributes, &directory_name); | |
42 NTSTATUS status = NtOpenDirectoryObject(&base_named_objects_handle, | |
43 DIRECTORY_ALL_ACCESS, | |
44 &object_attributes); | |
45 if (status == STATUS_SUCCESS) | |
46 *directory = base_named_objects_handle; | |
47 return status; | |
48 } | |
49 | |
18 bool SyncPolicy::GenerateRules(const wchar_t* name, | 50 bool SyncPolicy::GenerateRules(const wchar_t* name, |
19 TargetPolicy::Semantics semantics, | 51 TargetPolicy::Semantics semantics, |
20 LowLevelPolicy* policy) { | 52 LowLevelPolicy* policy) { |
21 std::wstring mod_name(name); | 53 std::wstring mod_name(name); |
22 if (mod_name.empty()) { | 54 if (mod_name.empty()) { |
23 return false; | 55 return false; |
24 } | 56 } |
25 | 57 |
26 if (TargetPolicy::EVENTS_ALLOW_ANY != semantics && | 58 if (TargetPolicy::EVENTS_ALLOW_ANY != semantics && |
27 TargetPolicy::EVENTS_ALLOW_READONLY != semantics) { | 59 TargetPolicy::EVENTS_ALLOW_READONLY != semantics) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
60 | 92 |
61 return true; | 93 return true; |
62 } | 94 } |
63 | 95 |
64 DWORD SyncPolicy::CreateEventAction(EvalResult eval_result, | 96 DWORD SyncPolicy::CreateEventAction(EvalResult eval_result, |
65 const ClientInfo& client_info, | 97 const ClientInfo& client_info, |
66 const std::wstring &event_name, | 98 const std::wstring &event_name, |
67 uint32 manual_reset, | 99 uint32 manual_reset, |
68 uint32 initial_state, | 100 uint32 initial_state, |
69 HANDLE *handle) { | 101 HANDLE *handle) { |
102 NtCreateEventFunction NtCreateEvent = NULL; | |
103 ResolveNTFunctionPtr("NtCreateEvent", &NtCreateEvent); | |
104 | |
105 NtCloseFunction NtClose = NULL; | |
106 ResolveNTFunctionPtr("NtClose", &NtClose); | |
107 | |
70 // The only action supported is ASK_BROKER which means create the requested | 108 // The only action supported is ASK_BROKER which means create the requested |
71 // file as specified. | 109 // file as specified. |
72 if (ASK_BROKER != eval_result) | 110 if (ASK_BROKER != eval_result) |
73 return false; | 111 return false; |
74 | 112 |
75 HANDLE local_handle = ::CreateEvent(NULL, manual_reset, initial_state, | 113 HANDLE object_directory = NULL; |
76 event_name.c_str()); | 114 NTSTATUS status = GetBaseNamedObjectsDirectory(&object_directory); |
115 if (status != STATUS_SUCCESS) | |
116 return status; | |
117 | |
118 UNICODE_STRING unicode_event_name = {0}; | |
rvargas (doing something else)
2013/10/23 01:36:57
nit: = {};
ananta
2013/10/23 06:20:18
Done.
| |
119 OBJECT_ATTRIBUTES object_attributes = {0}; | |
120 InitObjectAttribs(event_name, OBJ_CASE_INSENSITIVE, object_directory, | |
121 &object_attributes, &unicode_event_name); | |
122 | |
123 HANDLE local_handle = NULL; | |
124 status = NtCreateEvent( | |
125 &local_handle, EVENT_ALL_ACCESS, &object_attributes, | |
126 manual_reset ? NotificationEvent : SynchronizationEvent, | |
127 initial_state); | |
77 if (NULL == local_handle) | 128 if (NULL == local_handle) |
78 return ::GetLastError(); | 129 return status; |
79 | 130 |
80 if (!::DuplicateHandle(::GetCurrentProcess(), local_handle, | 131 if (!::DuplicateHandle(::GetCurrentProcess(), local_handle, |
81 client_info.process, handle, 0, FALSE, | 132 client_info.process, handle, 0, FALSE, |
82 DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS)) { | 133 DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS)) { |
83 return ERROR_ACCESS_DENIED; | 134 return STATUS_ACCESS_DENIED; |
84 } | 135 } |
85 return ERROR_SUCCESS; | 136 return status; |
86 } | 137 } |
87 | 138 |
88 DWORD SyncPolicy::OpenEventAction(EvalResult eval_result, | 139 DWORD SyncPolicy::OpenEventAction(EvalResult eval_result, |
89 const ClientInfo& client_info, | 140 const ClientInfo& client_info, |
90 const std::wstring &event_name, | 141 const std::wstring &event_name, |
91 uint32 desired_access, | 142 uint32 desired_access, |
92 uint32 inherit_handle, | 143 uint32 inherit_handle, |
93 HANDLE *handle) { | 144 HANDLE *handle) { |
145 NtOpenEventFunction NtOpenEvent = NULL; | |
146 ResolveNTFunctionPtr("NtOpenEvent", &NtOpenEvent); | |
147 | |
94 // The only action supported is ASK_BROKER which means create the requested | 148 // The only action supported is ASK_BROKER which means create the requested |
95 // file as specified. | 149 // event as specified. |
96 if (ASK_BROKER != eval_result) | 150 if (ASK_BROKER != eval_result) |
97 return false; | 151 return false; |
98 | 152 |
99 HANDLE local_handle = ::OpenEvent(desired_access, FALSE, | 153 HANDLE object_directory = NULL; |
100 event_name.c_str()); | 154 NTSTATUS status = GetBaseNamedObjectsDirectory(&object_directory); |
155 if (status != STATUS_SUCCESS) | |
156 return status; | |
157 | |
158 UNICODE_STRING unicode_event_name = {0}; | |
159 OBJECT_ATTRIBUTES object_attributes = {0}; | |
160 InitObjectAttribs(event_name, OBJ_CASE_INSENSITIVE, object_directory, | |
161 &object_attributes, &unicode_event_name); | |
162 | |
163 HANDLE local_handle = NULL; | |
164 status = NtOpenEvent(&local_handle, desired_access, &object_attributes); | |
101 if (NULL == local_handle) | 165 if (NULL == local_handle) |
102 return ::GetLastError(); | 166 return status; |
103 | 167 |
104 if (!::DuplicateHandle(::GetCurrentProcess(), local_handle, | 168 if (!::DuplicateHandle(::GetCurrentProcess(), local_handle, |
105 client_info.process, handle, 0, inherit_handle, | 169 client_info.process, handle, 0, inherit_handle, |
106 DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS)) { | 170 DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS)) { |
107 return ERROR_ACCESS_DENIED; | 171 return STATUS_ACCESS_DENIED; |
108 } | 172 } |
109 return ERROR_SUCCESS; | 173 return status; |
110 } | 174 } |
111 | 175 |
112 } // namespace sandbox | 176 } // namespace sandbox |
OLD | NEW |