security/sandbox/win/src/sync_dispatcher.cc

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/security/sandbox/win/src/sync_dispatcher.cc	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,86 @@
     1.4 +// Copyright (c) 2006-2010 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/sync_dispatcher.h"
     1.9 +
    1.10 +#include "sandbox/win/src/crosscall_client.h"
    1.11 +#include "sandbox/win/src/interception.h"
    1.12 +#include "sandbox/win/src/interceptors.h"
    1.13 +#include "sandbox/win/src/ipc_tags.h"
    1.14 +#include "sandbox/win/src/policy_broker.h"
    1.15 +#include "sandbox/win/src/policy_params.h"
    1.16 +#include "sandbox/win/src/sandbox.h"
    1.17 +#include "sandbox/win/src/sync_interception.h"
    1.18 +#include "sandbox/win/src/sync_policy.h"
    1.19 +
    1.20 +namespace sandbox {
    1.21 +
    1.22 +SyncDispatcher::SyncDispatcher(PolicyBase* policy_base)
    1.23 +    : policy_base_(policy_base) {
    1.24 +  static const IPCCall create_params = {
    1.25 +    {IPC_CREATEEVENT_TAG, WCHAR_TYPE, ULONG_TYPE, ULONG_TYPE},
    1.26 +    reinterpret_cast<CallbackGeneric>(&SyncDispatcher::CreateEvent)
    1.27 +  };
    1.28 +
    1.29 +  static const IPCCall open_params = {
    1.30 +    {IPC_OPENEVENT_TAG, WCHAR_TYPE, ULONG_TYPE, ULONG_TYPE},
    1.31 +    reinterpret_cast<CallbackGeneric>(&SyncDispatcher::OpenEvent)
    1.32 +  };
    1.33 +
    1.34 +  ipc_calls_.push_back(create_params);
    1.35 +  ipc_calls_.push_back(open_params);
    1.36 +}
    1.37 +
    1.38 +bool SyncDispatcher::SetupService(InterceptionManager* manager,
    1.39 +                                  int service) {
    1.40 +  if (IPC_CREATEEVENT_TAG == service)
    1.41 +      return INTERCEPT_EAT(manager, L"kernel32.dll", CreateEventW,
    1.42 +                           CREATE_EVENT_ID, 20);
    1.43 +
    1.44 +  if (IPC_OPENEVENT_TAG == service)
    1.45 +    return INTERCEPT_EAT(manager, L"kernel32.dll", OpenEventW,
    1.46 +                         OPEN_EVENT_ID, 16);
    1.47 +
    1.48 +  return false;
    1.49 +}
    1.50 +
    1.51 +bool SyncDispatcher::CreateEvent(IPCInfo* ipc, std::wstring* name,
    1.52 +                                 DWORD manual_reset, DWORD initial_state) {
    1.53 +  const wchar_t* event_name = name->c_str();
    1.54 +  CountedParameterSet<NameBased> params;
    1.55 +  params[NameBased::NAME] = ParamPickerMake(event_name);
    1.56 +
    1.57 +  EvalResult result = policy_base_->EvalPolicy(IPC_CREATEEVENT_TAG,
    1.58 +                                               params.GetBase());
    1.59 +  HANDLE handle = NULL;
    1.60 +  DWORD ret = SyncPolicy::CreateEventAction(result, *ipc->client_info, *name,
    1.61 +                                            manual_reset, initial_state,
    1.62 +                                            &handle);
    1.63 +  // Return operation status on the IPC.
    1.64 +  ipc->return_info.win32_result = ret;
    1.65 +  ipc->return_info.handle = handle;
    1.66 +  return true;
    1.67 +}
    1.68 +
    1.69 +bool SyncDispatcher::OpenEvent(IPCInfo* ipc, std::wstring* name,
    1.70 +                               DWORD desired_access, DWORD inherit_handle) {
    1.71 +  const wchar_t* event_name = name->c_str();
    1.72 +
    1.73 +  CountedParameterSet<OpenEventParams> params;
    1.74 +  params[OpenEventParams::NAME] = ParamPickerMake(event_name);
    1.75 +  params[OpenEventParams::ACCESS] = ParamPickerMake(desired_access);
    1.76 +
    1.77 +  EvalResult result = policy_base_->EvalPolicy(IPC_OPENEVENT_TAG,
    1.78 +                                               params.GetBase());
    1.79 +  HANDLE handle = NULL;
    1.80 +  DWORD ret = SyncPolicy::OpenEventAction(result, *ipc->client_info, *name,
    1.81 +                                          desired_access, inherit_handle,
    1.82 +                                          &handle);
    1.83 +  // Return operation status on the IPC.
    1.84 +  ipc->return_info.win32_result = ret;
    1.85 +  ipc->return_info.handle = handle;
    1.86 +  return true;
    1.87 +}
    1.88 +
    1.89 +}  // namespace sandbox

mercurial