michael@0: // Copyright (c) 2006-2008 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_policy.h" michael@0: michael@0: #include michael@0: michael@0: #include "sandbox/win/src/ipc_tags.h" michael@0: #include "sandbox/win/src/policy_engine_opcodes.h" michael@0: #include "sandbox/win/src/policy_params.h" michael@0: #include "sandbox/win/src/sandbox_types.h" michael@0: michael@0: namespace { michael@0: michael@0: // Creates a named pipe and duplicates the handle to 'target_process'. The michael@0: // remaining parameters are the same as CreateNamedPipeW(). michael@0: HANDLE CreateNamedPipeHelper(HANDLE target_process, LPCWSTR pipe_name, michael@0: DWORD open_mode, DWORD pipe_mode, michael@0: DWORD max_instances, DWORD out_buffer_size, michael@0: DWORD in_buffer_size, DWORD default_timeout, michael@0: LPSECURITY_ATTRIBUTES security_attributes) { michael@0: HANDLE pipe = ::CreateNamedPipeW(pipe_name, open_mode, pipe_mode, michael@0: max_instances, out_buffer_size, michael@0: in_buffer_size, default_timeout, michael@0: security_attributes); michael@0: if (INVALID_HANDLE_VALUE == pipe) michael@0: return pipe; michael@0: michael@0: HANDLE new_pipe; michael@0: if (!::DuplicateHandle(::GetCurrentProcess(), pipe, michael@0: target_process, &new_pipe, michael@0: 0, FALSE, michael@0: DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS)) { michael@0: return INVALID_HANDLE_VALUE; michael@0: } michael@0: michael@0: return new_pipe; michael@0: } michael@0: michael@0: } // namespace michael@0: michael@0: namespace sandbox { michael@0: michael@0: bool NamedPipePolicy::GenerateRules(const wchar_t* name, michael@0: TargetPolicy::Semantics semantics, michael@0: LowLevelPolicy* policy) { michael@0: if (TargetPolicy::NAMEDPIPES_ALLOW_ANY != semantics) { michael@0: return false; michael@0: } michael@0: PolicyRule pipe(ASK_BROKER); michael@0: if (!pipe.AddStringMatch(IF, NameBased::NAME, name, CASE_INSENSITIVE)) { michael@0: return false; michael@0: } michael@0: if (!policy->AddRule(IPC_CREATENAMEDPIPEW_TAG, &pipe)) { michael@0: return false; michael@0: } michael@0: return true; michael@0: } michael@0: michael@0: DWORD NamedPipePolicy::CreateNamedPipeAction(EvalResult eval_result, michael@0: const ClientInfo& client_info, michael@0: const std::wstring &name, michael@0: DWORD open_mode, DWORD pipe_mode, michael@0: DWORD max_instances, michael@0: DWORD out_buffer_size, michael@0: DWORD in_buffer_size, michael@0: DWORD default_timeout, michael@0: HANDLE* pipe) { michael@0: // The only action supported is ASK_BROKER which means create the pipe. michael@0: if (ASK_BROKER != eval_result) { michael@0: return ERROR_ACCESS_DENIED; michael@0: } michael@0: michael@0: *pipe = CreateNamedPipeHelper(client_info.process, name.c_str(), michael@0: open_mode, pipe_mode, max_instances, michael@0: out_buffer_size, in_buffer_size, michael@0: default_timeout, NULL); michael@0: michael@0: if (INVALID_HANDLE_VALUE == *pipe) michael@0: return ERROR_ACCESS_DENIED; michael@0: michael@0: return ERROR_SUCCESS; michael@0: } michael@0: michael@0: } // namespace sandbox