OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "sandbox/src/handle_policy.h" |
| 6 |
| 7 #include <string> |
| 8 |
| 9 #include "base/win/scoped_handle.h" |
| 10 #include "sandbox/src/ipc_tags.h" |
| 11 #include "sandbox/src/policy_engine_opcodes.h" |
| 12 #include "sandbox/src/policy_params.h" |
| 13 #include "sandbox/src/sandbox.h" |
| 14 #include "sandbox/src/sandbox_factory.h" |
| 15 #include "sandbox/src/sandbox_types.h" |
| 16 #include "sandbox/src/sandbox_utils.h" |
| 17 #include "sandbox/src/win_utils.h" |
| 18 |
| 19 namespace sandbox { |
| 20 |
| 21 bool HandlePolicy::GenerateRules(const wchar_t* type_name, |
| 22 TargetPolicy::Semantics semantics, |
| 23 LowLevelPolicy* policy) { |
| 24 // We don't support any other semantics for handles yet. |
| 25 if (TargetPolicy::HANDLES_DUP_ANY != semantics) { |
| 26 return false; |
| 27 } |
| 28 PolicyRule duplicate_rule(ASK_BROKER); |
| 29 if (!duplicate_rule.AddStringMatch(IF, NameBased::NAME, type_name, |
| 30 CASE_INSENSITIVE)) { |
| 31 return false; |
| 32 } |
| 33 if (!policy->AddRule(IPC_DUPLICATEHANDLEPROXY_TAG, &duplicate_rule)) { |
| 34 return false; |
| 35 } |
| 36 return true; |
| 37 } |
| 38 |
| 39 DWORD HandlePolicy::DuplicateHandleProxyAction(EvalResult eval_result, |
| 40 const ClientInfo& client_info, |
| 41 HANDLE source_handle, |
| 42 DWORD target_process_id, |
| 43 HANDLE* target_handle, |
| 44 DWORD desired_access, |
| 45 BOOL inherit_handle, |
| 46 DWORD options) { |
| 47 // The only action supported is ASK_BROKER which means duplicate the handle. |
| 48 if (ASK_BROKER != eval_result) { |
| 49 return ERROR_ACCESS_DENIED; |
| 50 } |
| 51 |
| 52 // Make sure the target is one of our sandboxed children. |
| 53 if (!SandboxFactory::GetBrokerServices()->IsActiveTarget(target_process_id)) { |
| 54 return ERROR_ACCESS_DENIED; |
| 55 } |
| 56 |
| 57 base::win::ScopedHandle target_process(::OpenProcess(PROCESS_DUP_HANDLE, |
| 58 FALSE, |
| 59 target_process_id)); |
| 60 if (NULL == target_process) |
| 61 return ::GetLastError(); |
| 62 |
| 63 DWORD result = ERROR_SUCCESS; |
| 64 if (!::DuplicateHandle(client_info.process, source_handle, target_process, |
| 65 target_handle, desired_access, inherit_handle, |
| 66 options)) { |
| 67 return ::GetLastError(); |
| 68 } |
| 69 |
| 70 return ERROR_SUCCESS; |
| 71 } |
| 72 |
| 73 } // namespace sandbox |
| 74 |
OLD | NEW |