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 "base/strings/stringprintf.h" |
11 #include "sandbox/win/src/ipc_tags.h" | 11 #include "sandbox/win/src/ipc_tags.h" |
12 #include "sandbox/win/src/nt_internals.h" | 12 #include "sandbox/win/src/nt_internals.h" |
13 #include "sandbox/win/src/policy_engine_opcodes.h" | 13 #include "sandbox/win/src/policy_engine_opcodes.h" |
14 #include "sandbox/win/src/policy_params.h" | 14 #include "sandbox/win/src/policy_params.h" |
15 #include "sandbox/win/src/sandbox_types.h" | 15 #include "sandbox/win/src/sandbox_types.h" |
16 #include "sandbox/win/src/sandbox_utils.h" | 16 #include "sandbox/win/src/sandbox_utils.h" |
17 #include "sandbox/win/src/sync_interception.h" | 17 #include "sandbox/win/src/sync_interception.h" |
18 #include "sandbox/win/src/win_utils.h" | 18 #include "sandbox/win/src/win_utils.h" |
19 | 19 |
20 namespace sandbox { | 20 namespace sandbox { |
21 | 21 |
22 // Provides functionality to resolve a symbolic link within the object | 22 // Provides functionality to resolve a symbolic link within the object |
23 // directory passed in. | 23 // directory passed in. |
24 NTSTATUS ResolveSymbolicLink(const std::wstring& directory_name, | 24 NTSTATUS ResolveSymbolicLink(const base::string16& directory_name, |
25 const std::wstring& name, | 25 const base::string16& name, |
26 std::wstring* target) { | 26 base::string16* target) { |
27 NtOpenDirectoryObjectFunction NtOpenDirectoryObject = NULL; | 27 NtOpenDirectoryObjectFunction NtOpenDirectoryObject = NULL; |
28 ResolveNTFunctionPtr("NtOpenDirectoryObject", &NtOpenDirectoryObject); | 28 ResolveNTFunctionPtr("NtOpenDirectoryObject", &NtOpenDirectoryObject); |
29 | 29 |
30 NtQuerySymbolicLinkObjectFunction NtQuerySymbolicLinkObject = NULL; | 30 NtQuerySymbolicLinkObjectFunction NtQuerySymbolicLinkObject = NULL; |
31 ResolveNTFunctionPtr("NtQuerySymbolicLinkObject", | 31 ResolveNTFunctionPtr("NtQuerySymbolicLinkObject", |
32 &NtQuerySymbolicLinkObject); | 32 &NtQuerySymbolicLinkObject); |
33 | 33 |
34 NtOpenSymbolicLinkObjectFunction NtOpenSymbolicLinkObject = NULL; | 34 NtOpenSymbolicLinkObjectFunction NtOpenSymbolicLinkObject = NULL; |
35 ResolveNTFunctionPtr("NtOpenSymbolicLinkObject", &NtOpenSymbolicLinkObject); | 35 ResolveNTFunctionPtr("NtOpenSymbolicLinkObject", &NtOpenSymbolicLinkObject); |
36 | 36 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 *directory = base_named_objects_handle; | 100 *directory = base_named_objects_handle; |
101 return STATUS_SUCCESS; | 101 return STATUS_SUCCESS; |
102 } | 102 } |
103 | 103 |
104 NtOpenDirectoryObjectFunction NtOpenDirectoryObject = NULL; | 104 NtOpenDirectoryObjectFunction NtOpenDirectoryObject = NULL; |
105 ResolveNTFunctionPtr("NtOpenDirectoryObject", &NtOpenDirectoryObject); | 105 ResolveNTFunctionPtr("NtOpenDirectoryObject", &NtOpenDirectoryObject); |
106 | 106 |
107 DWORD session_id = 0; | 107 DWORD session_id = 0; |
108 ProcessIdToSessionId(::GetCurrentProcessId(), &session_id); | 108 ProcessIdToSessionId(::GetCurrentProcessId(), &session_id); |
109 | 109 |
110 std::wstring base_named_objects_path; | 110 base::string16 base_named_objects_path; |
111 | 111 |
112 NTSTATUS status = ResolveSymbolicLink(L"\\Sessions\\BNOLINKS", | 112 NTSTATUS status = ResolveSymbolicLink(L"\\Sessions\\BNOLINKS", |
113 base::StringPrintf(L"%d", session_id), | 113 base::StringPrintf(L"%d", session_id), |
114 &base_named_objects_path); | 114 &base_named_objects_path); |
115 if (status != STATUS_SUCCESS) { | 115 if (status != STATUS_SUCCESS) { |
116 DLOG(ERROR) << "Failed to resolve BaseNamedObjects path. Error: " | 116 DLOG(ERROR) << "Failed to resolve BaseNamedObjects path. Error: " |
117 << status; | 117 << status; |
118 return status; | 118 return status; |
119 } | 119 } |
120 | 120 |
121 UNICODE_STRING directory_name = {}; | 121 UNICODE_STRING directory_name = {}; |
122 OBJECT_ATTRIBUTES object_attributes = {}; | 122 OBJECT_ATTRIBUTES object_attributes = {}; |
123 InitObjectAttribs(base_named_objects_path, OBJ_CASE_INSENSITIVE, NULL, | 123 InitObjectAttribs(base_named_objects_path, OBJ_CASE_INSENSITIVE, NULL, |
124 &object_attributes, &directory_name); | 124 &object_attributes, &directory_name); |
125 status = NtOpenDirectoryObject(&base_named_objects_handle, | 125 status = NtOpenDirectoryObject(&base_named_objects_handle, |
126 DIRECTORY_ALL_ACCESS, | 126 DIRECTORY_ALL_ACCESS, |
127 &object_attributes); | 127 &object_attributes); |
128 if (status == STATUS_SUCCESS) | 128 if (status == STATUS_SUCCESS) |
129 *directory = base_named_objects_handle; | 129 *directory = base_named_objects_handle; |
130 return status; | 130 return status; |
131 } | 131 } |
132 | 132 |
133 bool SyncPolicy::GenerateRules(const wchar_t* name, | 133 bool SyncPolicy::GenerateRules(const wchar_t* name, |
134 TargetPolicy::Semantics semantics, | 134 TargetPolicy::Semantics semantics, |
135 LowLevelPolicy* policy) { | 135 LowLevelPolicy* policy) { |
136 std::wstring mod_name(name); | 136 base::string16 mod_name(name); |
137 if (mod_name.empty()) { | 137 if (mod_name.empty()) { |
138 return false; | 138 return false; |
139 } | 139 } |
140 | 140 |
141 if (TargetPolicy::EVENTS_ALLOW_ANY != semantics && | 141 if (TargetPolicy::EVENTS_ALLOW_ANY != semantics && |
142 TargetPolicy::EVENTS_ALLOW_READONLY != semantics) { | 142 TargetPolicy::EVENTS_ALLOW_READONLY != semantics) { |
143 // Other flags are not valid for sync policy yet. | 143 // Other flags are not valid for sync policy yet. |
144 NOTREACHED(); | 144 NOTREACHED(); |
145 return false; | 145 return false; |
146 } | 146 } |
(...skipping 24 matching lines...) Expand all Loading... |
171 | 171 |
172 if (!policy->AddRule(IPC_CREATEEVENT_TAG, &create)) | 172 if (!policy->AddRule(IPC_CREATEEVENT_TAG, &create)) |
173 return false; | 173 return false; |
174 } | 174 } |
175 | 175 |
176 return true; | 176 return true; |
177 } | 177 } |
178 | 178 |
179 DWORD SyncPolicy::CreateEventAction(EvalResult eval_result, | 179 DWORD SyncPolicy::CreateEventAction(EvalResult eval_result, |
180 const ClientInfo& client_info, | 180 const ClientInfo& client_info, |
181 const std::wstring &event_name, | 181 const base::string16 &event_name, |
182 uint32 event_type, | 182 uint32 event_type, |
183 uint32 initial_state, | 183 uint32 initial_state, |
184 HANDLE *handle) { | 184 HANDLE *handle) { |
185 NtCreateEventFunction NtCreateEvent = NULL; | 185 NtCreateEventFunction NtCreateEvent = NULL; |
186 ResolveNTFunctionPtr("NtCreateEvent", &NtCreateEvent); | 186 ResolveNTFunctionPtr("NtCreateEvent", &NtCreateEvent); |
187 | 187 |
188 // The only action supported is ASK_BROKER which means create the requested | 188 // The only action supported is ASK_BROKER which means create the requested |
189 // file as specified. | 189 // file as specified. |
190 if (ASK_BROKER != eval_result) | 190 if (ASK_BROKER != eval_result) |
191 return false; | 191 return false; |
(...skipping 17 matching lines...) Expand all Loading... |
209 if (!::DuplicateHandle(::GetCurrentProcess(), local_handle, | 209 if (!::DuplicateHandle(::GetCurrentProcess(), local_handle, |
210 client_info.process, handle, 0, FALSE, | 210 client_info.process, handle, 0, FALSE, |
211 DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS)) { | 211 DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS)) { |
212 return STATUS_ACCESS_DENIED; | 212 return STATUS_ACCESS_DENIED; |
213 } | 213 } |
214 return status; | 214 return status; |
215 } | 215 } |
216 | 216 |
217 DWORD SyncPolicy::OpenEventAction(EvalResult eval_result, | 217 DWORD SyncPolicy::OpenEventAction(EvalResult eval_result, |
218 const ClientInfo& client_info, | 218 const ClientInfo& client_info, |
219 const std::wstring &event_name, | 219 const base::string16 &event_name, |
220 uint32 desired_access, | 220 uint32 desired_access, |
221 HANDLE *handle) { | 221 HANDLE *handle) { |
222 NtOpenEventFunction NtOpenEvent = NULL; | 222 NtOpenEventFunction NtOpenEvent = NULL; |
223 ResolveNTFunctionPtr("NtOpenEvent", &NtOpenEvent); | 223 ResolveNTFunctionPtr("NtOpenEvent", &NtOpenEvent); |
224 | 224 |
225 // The only action supported is ASK_BROKER which means create the requested | 225 // The only action supported is ASK_BROKER which means create the requested |
226 // event as specified. | 226 // event as specified. |
227 if (ASK_BROKER != eval_result) | 227 if (ASK_BROKER != eval_result) |
228 return false; | 228 return false; |
229 | 229 |
(...skipping 14 matching lines...) Expand all Loading... |
244 | 244 |
245 if (!::DuplicateHandle(::GetCurrentProcess(), local_handle, | 245 if (!::DuplicateHandle(::GetCurrentProcess(), local_handle, |
246 client_info.process, handle, 0, FALSE, | 246 client_info.process, handle, 0, FALSE, |
247 DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS)) { | 247 DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS)) { |
248 return STATUS_ACCESS_DENIED; | 248 return STATUS_ACCESS_DENIED; |
249 } | 249 } |
250 return status; | 250 return status; |
251 } | 251 } |
252 | 252 |
253 } // namespace sandbox | 253 } // namespace sandbox |
OLD | NEW |