Home | History | Annotate | Download | only in src
      1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "sandbox/win/src/sync_dispatcher.h"
      6 
      7 #include "base/win/windows_version.h"
      8 #include "sandbox/win/src/crosscall_client.h"
      9 #include "sandbox/win/src/interception.h"
     10 #include "sandbox/win/src/interceptors.h"
     11 #include "sandbox/win/src/ipc_tags.h"
     12 #include "sandbox/win/src/policy_broker.h"
     13 #include "sandbox/win/src/policy_params.h"
     14 #include "sandbox/win/src/sandbox.h"
     15 #include "sandbox/win/src/sync_interception.h"
     16 #include "sandbox/win/src/sync_policy.h"
     17 
     18 namespace sandbox {
     19 
     20 SyncDispatcher::SyncDispatcher(PolicyBase* policy_base)
     21     : policy_base_(policy_base) {
     22   static const IPCCall create_params = {
     23     {IPC_CREATEEVENT_TAG, WCHAR_TYPE, ULONG_TYPE, ULONG_TYPE},
     24     reinterpret_cast<CallbackGeneric>(&SyncDispatcher::CreateEvent)
     25   };
     26 
     27   static const IPCCall open_params = {
     28     {IPC_OPENEVENT_TAG, WCHAR_TYPE, ULONG_TYPE},
     29     reinterpret_cast<CallbackGeneric>(&SyncDispatcher::OpenEvent)
     30   };
     31 
     32   ipc_calls_.push_back(create_params);
     33   ipc_calls_.push_back(open_params);
     34 }
     35 
     36 bool SyncDispatcher::SetupService(InterceptionManager* manager,
     37                                   int service) {
     38   if (service == IPC_CREATEEVENT_TAG) {
     39     return INTERCEPT_NT(manager, NtCreateEvent, CREATE_EVENT_ID, 24);
     40   }
     41   return (service == IPC_OPENEVENT_TAG) &&
     42       INTERCEPT_NT(manager, NtOpenEvent, OPEN_EVENT_ID, 16);
     43 }
     44 
     45 bool SyncDispatcher::CreateEvent(IPCInfo* ipc, base::string16* name,
     46                                  DWORD event_type, DWORD initial_state) {
     47   const wchar_t* event_name = name->c_str();
     48   CountedParameterSet<NameBased> params;
     49   params[NameBased::NAME] = ParamPickerMake(event_name);
     50 
     51   EvalResult result = policy_base_->EvalPolicy(IPC_CREATEEVENT_TAG,
     52                                                params.GetBase());
     53   HANDLE handle = NULL;
     54   // Return operation status on the IPC.
     55   ipc->return_info.nt_status = SyncPolicy::CreateEventAction(
     56       result, *ipc->client_info, *name, event_type, initial_state, &handle);
     57   ipc->return_info.handle = handle;
     58   return true;
     59 }
     60 
     61 bool SyncDispatcher::OpenEvent(IPCInfo* ipc, base::string16* name,
     62                                DWORD desired_access) {
     63   const wchar_t* event_name = name->c_str();
     64 
     65   CountedParameterSet<OpenEventParams> params;
     66   params[OpenEventParams::NAME] = ParamPickerMake(event_name);
     67   params[OpenEventParams::ACCESS] = ParamPickerMake(desired_access);
     68 
     69   EvalResult result = policy_base_->EvalPolicy(IPC_OPENEVENT_TAG,
     70                                                params.GetBase());
     71   HANDLE handle = NULL;
     72   // Return operation status on the IPC.
     73   ipc->return_info.nt_status = SyncPolicy::OpenEventAction(
     74       result, *ipc->client_info, *name, desired_access, &handle);
     75   ipc->return_info.handle = handle;
     76   return true;
     77 }
     78 
     79 }  // namespace sandbox
     80