michael@0: // Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: michael@0: #include "sandbox/win/src/sync_dispatcher.h" michael@0: michael@0: #include "sandbox/win/src/crosscall_client.h" michael@0: #include "sandbox/win/src/interception.h" michael@0: #include "sandbox/win/src/interceptors.h" michael@0: #include "sandbox/win/src/ipc_tags.h" michael@0: #include "sandbox/win/src/policy_broker.h" michael@0: #include "sandbox/win/src/policy_params.h" michael@0: #include "sandbox/win/src/sandbox.h" michael@0: #include "sandbox/win/src/sync_interception.h" michael@0: #include "sandbox/win/src/sync_policy.h" michael@0: michael@0: namespace sandbox { michael@0: michael@0: SyncDispatcher::SyncDispatcher(PolicyBase* policy_base) michael@0: : policy_base_(policy_base) { michael@0: static const IPCCall create_params = { michael@0: {IPC_CREATEEVENT_TAG, WCHAR_TYPE, ULONG_TYPE, ULONG_TYPE}, michael@0: reinterpret_cast(&SyncDispatcher::CreateEvent) michael@0: }; michael@0: michael@0: static const IPCCall open_params = { michael@0: {IPC_OPENEVENT_TAG, WCHAR_TYPE, ULONG_TYPE, ULONG_TYPE}, michael@0: reinterpret_cast(&SyncDispatcher::OpenEvent) michael@0: }; michael@0: michael@0: ipc_calls_.push_back(create_params); michael@0: ipc_calls_.push_back(open_params); michael@0: } michael@0: michael@0: bool SyncDispatcher::SetupService(InterceptionManager* manager, michael@0: int service) { michael@0: if (IPC_CREATEEVENT_TAG == service) michael@0: return INTERCEPT_EAT(manager, L"kernel32.dll", CreateEventW, michael@0: CREATE_EVENT_ID, 20); michael@0: michael@0: if (IPC_OPENEVENT_TAG == service) michael@0: return INTERCEPT_EAT(manager, L"kernel32.dll", OpenEventW, michael@0: OPEN_EVENT_ID, 16); michael@0: michael@0: return false; michael@0: } michael@0: michael@0: bool SyncDispatcher::CreateEvent(IPCInfo* ipc, std::wstring* name, michael@0: DWORD manual_reset, DWORD initial_state) { michael@0: const wchar_t* event_name = name->c_str(); michael@0: CountedParameterSet params; michael@0: params[NameBased::NAME] = ParamPickerMake(event_name); michael@0: michael@0: EvalResult result = policy_base_->EvalPolicy(IPC_CREATEEVENT_TAG, michael@0: params.GetBase()); michael@0: HANDLE handle = NULL; michael@0: DWORD ret = SyncPolicy::CreateEventAction(result, *ipc->client_info, *name, michael@0: manual_reset, initial_state, michael@0: &handle); michael@0: // Return operation status on the IPC. michael@0: ipc->return_info.win32_result = ret; michael@0: ipc->return_info.handle = handle; michael@0: return true; michael@0: } michael@0: michael@0: bool SyncDispatcher::OpenEvent(IPCInfo* ipc, std::wstring* name, michael@0: DWORD desired_access, DWORD inherit_handle) { michael@0: const wchar_t* event_name = name->c_str(); michael@0: michael@0: CountedParameterSet params; michael@0: params[OpenEventParams::NAME] = ParamPickerMake(event_name); michael@0: params[OpenEventParams::ACCESS] = ParamPickerMake(desired_access); michael@0: michael@0: EvalResult result = policy_base_->EvalPolicy(IPC_OPENEVENT_TAG, michael@0: params.GetBase()); michael@0: HANDLE handle = NULL; michael@0: DWORD ret = SyncPolicy::OpenEventAction(result, *ipc->client_info, *name, michael@0: desired_access, inherit_handle, michael@0: &handle); michael@0: // Return operation status on the IPC. michael@0: ipc->return_info.win32_result = ret; michael@0: ipc->return_info.handle = handle; michael@0: return true; michael@0: } michael@0: michael@0: } // namespace sandbox