security/sandbox/win/src/named_pipe_policy.cc

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/security/sandbox/win/src/named_pipe_policy.cc	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,86 @@
     1.4 +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
     1.5 +// Use of this source code is governed by a BSD-style license that can be
     1.6 +// found in the LICENSE file.
     1.7 +
     1.8 +#include "sandbox/win/src/named_pipe_policy.h"
     1.9 +
    1.10 +#include <string>
    1.11 +
    1.12 +#include "sandbox/win/src/ipc_tags.h"
    1.13 +#include "sandbox/win/src/policy_engine_opcodes.h"
    1.14 +#include "sandbox/win/src/policy_params.h"
    1.15 +#include "sandbox/win/src/sandbox_types.h"
    1.16 +
    1.17 +namespace {
    1.18 +
    1.19 +// Creates a named pipe and duplicates the handle to 'target_process'. The
    1.20 +// remaining parameters are the same as CreateNamedPipeW().
    1.21 +HANDLE CreateNamedPipeHelper(HANDLE target_process, LPCWSTR pipe_name,
    1.22 +                              DWORD open_mode, DWORD pipe_mode,
    1.23 +                              DWORD max_instances, DWORD out_buffer_size,
    1.24 +                              DWORD in_buffer_size, DWORD default_timeout,
    1.25 +                              LPSECURITY_ATTRIBUTES security_attributes) {
    1.26 +  HANDLE pipe = ::CreateNamedPipeW(pipe_name, open_mode, pipe_mode,
    1.27 +                                   max_instances, out_buffer_size,
    1.28 +                                   in_buffer_size, default_timeout,
    1.29 +                                   security_attributes);
    1.30 +  if (INVALID_HANDLE_VALUE == pipe)
    1.31 +    return pipe;
    1.32 +
    1.33 +  HANDLE new_pipe;
    1.34 +  if (!::DuplicateHandle(::GetCurrentProcess(), pipe,
    1.35 +                         target_process, &new_pipe,
    1.36 +                         0, FALSE,
    1.37 +                         DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS)) {
    1.38 +    return INVALID_HANDLE_VALUE;
    1.39 +  }
    1.40 +
    1.41 +  return new_pipe;
    1.42 +}
    1.43 +
    1.44 +}  // namespace
    1.45 +
    1.46 +namespace sandbox {
    1.47 +
    1.48 +bool NamedPipePolicy::GenerateRules(const wchar_t* name,
    1.49 +                                    TargetPolicy::Semantics semantics,
    1.50 +                                    LowLevelPolicy* policy) {
    1.51 +  if (TargetPolicy::NAMEDPIPES_ALLOW_ANY != semantics) {
    1.52 +    return false;
    1.53 +  }
    1.54 +  PolicyRule pipe(ASK_BROKER);
    1.55 +  if (!pipe.AddStringMatch(IF, NameBased::NAME, name, CASE_INSENSITIVE)) {
    1.56 +    return false;
    1.57 +  }
    1.58 +  if (!policy->AddRule(IPC_CREATENAMEDPIPEW_TAG, &pipe)) {
    1.59 +    return false;
    1.60 +  }
    1.61 +  return true;
    1.62 +}
    1.63 +
    1.64 +DWORD NamedPipePolicy::CreateNamedPipeAction(EvalResult eval_result,
    1.65 +                                             const ClientInfo& client_info,
    1.66 +                                             const std::wstring &name,
    1.67 +                                             DWORD open_mode, DWORD pipe_mode,
    1.68 +                                             DWORD max_instances,
    1.69 +                                             DWORD out_buffer_size,
    1.70 +                                             DWORD in_buffer_size,
    1.71 +                                             DWORD default_timeout,
    1.72 +                                             HANDLE* pipe) {
    1.73 +  // The only action supported is ASK_BROKER which means create the pipe.
    1.74 +  if (ASK_BROKER != eval_result) {
    1.75 +    return ERROR_ACCESS_DENIED;
    1.76 +  }
    1.77 +
    1.78 +  *pipe = CreateNamedPipeHelper(client_info.process, name.c_str(),
    1.79 +                                open_mode, pipe_mode, max_instances,
    1.80 +                                out_buffer_size, in_buffer_size,
    1.81 +                                default_timeout, NULL);
    1.82 +
    1.83 +  if (INVALID_HANDLE_VALUE == *pipe)
    1.84 +    return ERROR_ACCESS_DENIED;
    1.85 +
    1.86 +  return ERROR_SUCCESS;
    1.87 +}
    1.88 +
    1.89 +}  // namespace sandbox

mercurial