security/sandbox/win/src/named_pipe_policy.cc

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
michael@0 2 // Use of this source code is governed by a BSD-style license that can be
michael@0 3 // found in the LICENSE file.
michael@0 4
michael@0 5 #include "sandbox/win/src/named_pipe_policy.h"
michael@0 6
michael@0 7 #include <string>
michael@0 8
michael@0 9 #include "sandbox/win/src/ipc_tags.h"
michael@0 10 #include "sandbox/win/src/policy_engine_opcodes.h"
michael@0 11 #include "sandbox/win/src/policy_params.h"
michael@0 12 #include "sandbox/win/src/sandbox_types.h"
michael@0 13
michael@0 14 namespace {
michael@0 15
michael@0 16 // Creates a named pipe and duplicates the handle to 'target_process'. The
michael@0 17 // remaining parameters are the same as CreateNamedPipeW().
michael@0 18 HANDLE CreateNamedPipeHelper(HANDLE target_process, LPCWSTR pipe_name,
michael@0 19 DWORD open_mode, DWORD pipe_mode,
michael@0 20 DWORD max_instances, DWORD out_buffer_size,
michael@0 21 DWORD in_buffer_size, DWORD default_timeout,
michael@0 22 LPSECURITY_ATTRIBUTES security_attributes) {
michael@0 23 HANDLE pipe = ::CreateNamedPipeW(pipe_name, open_mode, pipe_mode,
michael@0 24 max_instances, out_buffer_size,
michael@0 25 in_buffer_size, default_timeout,
michael@0 26 security_attributes);
michael@0 27 if (INVALID_HANDLE_VALUE == pipe)
michael@0 28 return pipe;
michael@0 29
michael@0 30 HANDLE new_pipe;
michael@0 31 if (!::DuplicateHandle(::GetCurrentProcess(), pipe,
michael@0 32 target_process, &new_pipe,
michael@0 33 0, FALSE,
michael@0 34 DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS)) {
michael@0 35 return INVALID_HANDLE_VALUE;
michael@0 36 }
michael@0 37
michael@0 38 return new_pipe;
michael@0 39 }
michael@0 40
michael@0 41 } // namespace
michael@0 42
michael@0 43 namespace sandbox {
michael@0 44
michael@0 45 bool NamedPipePolicy::GenerateRules(const wchar_t* name,
michael@0 46 TargetPolicy::Semantics semantics,
michael@0 47 LowLevelPolicy* policy) {
michael@0 48 if (TargetPolicy::NAMEDPIPES_ALLOW_ANY != semantics) {
michael@0 49 return false;
michael@0 50 }
michael@0 51 PolicyRule pipe(ASK_BROKER);
michael@0 52 if (!pipe.AddStringMatch(IF, NameBased::NAME, name, CASE_INSENSITIVE)) {
michael@0 53 return false;
michael@0 54 }
michael@0 55 if (!policy->AddRule(IPC_CREATENAMEDPIPEW_TAG, &pipe)) {
michael@0 56 return false;
michael@0 57 }
michael@0 58 return true;
michael@0 59 }
michael@0 60
michael@0 61 DWORD NamedPipePolicy::CreateNamedPipeAction(EvalResult eval_result,
michael@0 62 const ClientInfo& client_info,
michael@0 63 const std::wstring &name,
michael@0 64 DWORD open_mode, DWORD pipe_mode,
michael@0 65 DWORD max_instances,
michael@0 66 DWORD out_buffer_size,
michael@0 67 DWORD in_buffer_size,
michael@0 68 DWORD default_timeout,
michael@0 69 HANDLE* pipe) {
michael@0 70 // The only action supported is ASK_BROKER which means create the pipe.
michael@0 71 if (ASK_BROKER != eval_result) {
michael@0 72 return ERROR_ACCESS_DENIED;
michael@0 73 }
michael@0 74
michael@0 75 *pipe = CreateNamedPipeHelper(client_info.process, name.c_str(),
michael@0 76 open_mode, pipe_mode, max_instances,
michael@0 77 out_buffer_size, in_buffer_size,
michael@0 78 default_timeout, NULL);
michael@0 79
michael@0 80 if (INVALID_HANDLE_VALUE == *pipe)
michael@0 81 return ERROR_ACCESS_DENIED;
michael@0 82
michael@0 83 return ERROR_SUCCESS;
michael@0 84 }
michael@0 85
michael@0 86 } // namespace sandbox

mercurial