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/named_pipe_dispatcher.h" michael@0: michael@0: #include "base/basictypes.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/named_pipe_interception.h" michael@0: #include "sandbox/win/src/named_pipe_policy.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: michael@0: michael@0: namespace sandbox { michael@0: michael@0: NamedPipeDispatcher::NamedPipeDispatcher(PolicyBase* policy_base) michael@0: : policy_base_(policy_base) { michael@0: static const IPCCall create_params = { michael@0: {IPC_CREATENAMEDPIPEW_TAG, WCHAR_TYPE, ULONG_TYPE, ULONG_TYPE, ULONG_TYPE, michael@0: ULONG_TYPE, ULONG_TYPE, ULONG_TYPE}, michael@0: reinterpret_cast(&NamedPipeDispatcher::CreateNamedPipe) michael@0: }; michael@0: michael@0: ipc_calls_.push_back(create_params); michael@0: } michael@0: michael@0: bool NamedPipeDispatcher::SetupService(InterceptionManager* manager, michael@0: int service) { michael@0: if (IPC_CREATENAMEDPIPEW_TAG == service) michael@0: return INTERCEPT_EAT(manager, L"kernel32.dll", CreateNamedPipeW, michael@0: CREATE_NAMED_PIPE_ID, 36); michael@0: michael@0: return false; michael@0: } michael@0: michael@0: bool NamedPipeDispatcher::CreateNamedPipe( michael@0: IPCInfo* ipc, std::wstring* name, DWORD open_mode, DWORD pipe_mode, michael@0: DWORD max_instances, DWORD out_buffer_size, DWORD in_buffer_size, michael@0: DWORD default_timeout) { michael@0: const wchar_t* pipe_name = name->c_str(); michael@0: CountedParameterSet params; michael@0: params[NameBased::NAME] = ParamPickerMake(pipe_name); michael@0: michael@0: EvalResult eval = policy_base_->EvalPolicy(IPC_CREATENAMEDPIPEW_TAG, michael@0: params.GetBase()); michael@0: michael@0: HANDLE pipe; michael@0: DWORD ret = NamedPipePolicy::CreateNamedPipeAction(eval, *ipc->client_info, michael@0: *name, open_mode, michael@0: pipe_mode, max_instances, michael@0: out_buffer_size, michael@0: in_buffer_size, michael@0: default_timeout, &pipe); michael@0: michael@0: ipc->return_info.win32_result = ret; michael@0: ipc->return_info.handle = pipe; michael@0: return true; michael@0: } michael@0: michael@0: } // namespace sandbox