Wed, 31 Dec 2014 06:09:35 +0100
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) 2012 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 | // Sandbox is a sandbox library for windows processes. Use when you want a |
michael@0 | 6 | // 'privileged' process and a 'locked down process' to interact with. |
michael@0 | 7 | // The privileged process is called the broker and it is started by external |
michael@0 | 8 | // means (such as the user starting it). The 'sandboxed' process is called the |
michael@0 | 9 | // target and it is started by the broker. There can be many target processes |
michael@0 | 10 | // started by a single broker process. This library provides facilities |
michael@0 | 11 | // for both the broker and the target. |
michael@0 | 12 | // |
michael@0 | 13 | // The design rationale and relevant documents can be found at http://go/sbox. |
michael@0 | 14 | // |
michael@0 | 15 | // Note: this header does not include the SandboxFactory definitions because |
michael@0 | 16 | // there are cases where the Sandbox library is linked against the main .exe |
michael@0 | 17 | // while its API needs to be used in a DLL. |
michael@0 | 18 | |
michael@0 | 19 | #ifndef SANDBOX_WIN_SRC_SANDBOX_H_ |
michael@0 | 20 | #define SANDBOX_WIN_SRC_SANDBOX_H_ |
michael@0 | 21 | |
michael@0 | 22 | #include <windows.h> |
michael@0 | 23 | |
michael@0 | 24 | #include "base/basictypes.h" |
michael@0 | 25 | #include "sandbox/win/src/sandbox_policy.h" |
michael@0 | 26 | #include "sandbox/win/src/sandbox_types.h" |
michael@0 | 27 | |
michael@0 | 28 | // sandbox: Google User-Land Application Sandbox |
michael@0 | 29 | namespace sandbox { |
michael@0 | 30 | |
michael@0 | 31 | class BrokerServices; |
michael@0 | 32 | class ProcessState; |
michael@0 | 33 | class TargetPolicy; |
michael@0 | 34 | class TargetServices; |
michael@0 | 35 | |
michael@0 | 36 | // BrokerServices exposes all the broker API. |
michael@0 | 37 | // The basic use is to start the target(s) and wait for them to end. |
michael@0 | 38 | // |
michael@0 | 39 | // This API is intended to be called in the following order |
michael@0 | 40 | // (error checking omitted): |
michael@0 | 41 | // BrokerServices* broker = SandboxFactory::GetBrokerServices(); |
michael@0 | 42 | // broker->Init(); |
michael@0 | 43 | // PROCESS_INFORMATION target; |
michael@0 | 44 | // broker->SpawnTarget(target_exe_path, target_args, &target); |
michael@0 | 45 | // ::ResumeThread(target->hThread); |
michael@0 | 46 | // // -- later you can call: |
michael@0 | 47 | // broker->WaitForAllTargets(option); |
michael@0 | 48 | // |
michael@0 | 49 | class BrokerServices { |
michael@0 | 50 | public: |
michael@0 | 51 | // Initializes the broker. Must be called before any other on this class. |
michael@0 | 52 | // returns ALL_OK if successful. All other return values imply failure. |
michael@0 | 53 | // If the return is ERROR_GENERIC, you can call ::GetLastError() to get |
michael@0 | 54 | // more information. |
michael@0 | 55 | virtual ResultCode Init() = 0; |
michael@0 | 56 | |
michael@0 | 57 | // Returns the interface pointer to a new, empty policy object. Use this |
michael@0 | 58 | // interface to specify the sandbox policy for new processes created by |
michael@0 | 59 | // SpawnTarget() |
michael@0 | 60 | virtual TargetPolicy* CreatePolicy() = 0; |
michael@0 | 61 | |
michael@0 | 62 | // Creates a new target (child process) in a suspended state. |
michael@0 | 63 | // Parameters: |
michael@0 | 64 | // exe_path: This is the full path to the target binary. This parameter |
michael@0 | 65 | // can be null and in this case the exe path must be the first argument |
michael@0 | 66 | // of the command_line. |
michael@0 | 67 | // command_line: The arguments to be passed as command line to the new |
michael@0 | 68 | // process. This can be null if the exe_path parameter is not null. |
michael@0 | 69 | // policy: This is the pointer to the policy object for the sandbox to |
michael@0 | 70 | // be created. |
michael@0 | 71 | // target: returns the resulting target process information such as process |
michael@0 | 72 | // handle and PID just as if CreateProcess() had been called. The caller is |
michael@0 | 73 | // responsible for closing the handles returned in this structure. |
michael@0 | 74 | // Returns: |
michael@0 | 75 | // ALL_OK if successful. All other return values imply failure. |
michael@0 | 76 | virtual ResultCode SpawnTarget(const wchar_t* exe_path, |
michael@0 | 77 | const wchar_t* command_line, |
michael@0 | 78 | TargetPolicy* policy, |
michael@0 | 79 | PROCESS_INFORMATION* target) = 0; |
michael@0 | 80 | |
michael@0 | 81 | // This call blocks (waits) for all the targets to terminate. |
michael@0 | 82 | // Returns: |
michael@0 | 83 | // ALL_OK if successful. All other return values imply failure. |
michael@0 | 84 | // If the return is ERROR_GENERIC, you can call ::GetLastError() to get |
michael@0 | 85 | // more information. |
michael@0 | 86 | virtual ResultCode WaitForAllTargets() = 0; |
michael@0 | 87 | |
michael@0 | 88 | // Adds an unsandboxed process as a peer for policy decisions (e.g. |
michael@0 | 89 | // HANDLES_DUP_ANY policy). |
michael@0 | 90 | // Returns: |
michael@0 | 91 | // ALL_OK if successful. All other return values imply failure. |
michael@0 | 92 | // If the return is ERROR_GENERIC, you can call ::GetLastError() to get |
michael@0 | 93 | // more information. |
michael@0 | 94 | virtual ResultCode AddTargetPeer(HANDLE peer_process) = 0; |
michael@0 | 95 | |
michael@0 | 96 | // Install the AppContainer with the specified sid an name. Returns ALL_OK if |
michael@0 | 97 | // successful or an error code if the AppContainer cannot be installed. |
michael@0 | 98 | virtual ResultCode InstallAppContainer(const wchar_t* sid, |
michael@0 | 99 | const wchar_t* name) = 0; |
michael@0 | 100 | |
michael@0 | 101 | // Removes from the system the AppContainer with the specified sid. |
michael@0 | 102 | // Returns ALL_OK if successful or an error code otherwise. |
michael@0 | 103 | virtual ResultCode UninstallAppContainer(const wchar_t* sid) = 0; |
michael@0 | 104 | }; |
michael@0 | 105 | |
michael@0 | 106 | // TargetServices models the current process from the perspective |
michael@0 | 107 | // of a target process. To obtain a pointer to it use |
michael@0 | 108 | // Sandbox::GetTargetServices(). Note that this call returns a non-null |
michael@0 | 109 | // pointer only if this process is in fact a target. A process is a target |
michael@0 | 110 | // only if the process was spawned by a call to BrokerServices::SpawnTarget(). |
michael@0 | 111 | // |
michael@0 | 112 | // This API allows the target to gain access to resources with a high |
michael@0 | 113 | // privilege token and then when it is ready to perform dangerous activities |
michael@0 | 114 | // (such as download content from the web) it can lower its token and |
michael@0 | 115 | // enter into locked-down (sandbox) mode. |
michael@0 | 116 | // The typical usage is as follows: |
michael@0 | 117 | // |
michael@0 | 118 | // TargetServices* target_services = Sandbox::GetTargetServices(); |
michael@0 | 119 | // if (NULL != target_services) { |
michael@0 | 120 | // // We are the target. |
michael@0 | 121 | // target_services->Init(); |
michael@0 | 122 | // // Do work that requires high privileges here. |
michael@0 | 123 | // // .... |
michael@0 | 124 | // // When ready to enter lock-down mode call LowerToken: |
michael@0 | 125 | // target_services->LowerToken(); |
michael@0 | 126 | // } |
michael@0 | 127 | // |
michael@0 | 128 | // For more information see the BrokerServices API documentation. |
michael@0 | 129 | class TargetServices { |
michael@0 | 130 | public: |
michael@0 | 131 | // Initializes the target. Must call this function before any other. |
michael@0 | 132 | // returns ALL_OK if successful. All other return values imply failure. |
michael@0 | 133 | // If the return is ERROR_GENERIC, you can call ::GetLastError() to get |
michael@0 | 134 | // more information. |
michael@0 | 135 | virtual ResultCode Init() = 0; |
michael@0 | 136 | |
michael@0 | 137 | // Discards the impersonation token and uses the lower token, call before |
michael@0 | 138 | // processing any untrusted data or running third-party code. If this call |
michael@0 | 139 | // fails the current process could be terminated immediately. |
michael@0 | 140 | virtual void LowerToken() = 0; |
michael@0 | 141 | |
michael@0 | 142 | // Returns the ProcessState object. Through that object it's possible to have |
michael@0 | 143 | // information about the current state of the process, such as whether |
michael@0 | 144 | // LowerToken has been called or not. |
michael@0 | 145 | virtual ProcessState* GetState() = 0; |
michael@0 | 146 | |
michael@0 | 147 | // Requests the broker to duplicate the supplied handle into the target |
michael@0 | 148 | // process. The target process must be an active sandbox child process |
michael@0 | 149 | // and the source process must have a corresponding policy allowing |
michael@0 | 150 | // handle duplication for this object type. |
michael@0 | 151 | // Returns: |
michael@0 | 152 | // ALL_OK if successful. All other return values imply failure. |
michael@0 | 153 | // If the return is ERROR_GENERIC, you can call ::GetLastError() to get |
michael@0 | 154 | // more information. |
michael@0 | 155 | virtual ResultCode DuplicateHandle(HANDLE source_handle, |
michael@0 | 156 | DWORD target_process_id, |
michael@0 | 157 | HANDLE* target_handle, |
michael@0 | 158 | DWORD desired_access, |
michael@0 | 159 | DWORD options) = 0; |
michael@0 | 160 | }; |
michael@0 | 161 | |
michael@0 | 162 | } // namespace sandbox |
michael@0 | 163 | |
michael@0 | 164 | |
michael@0 | 165 | #endif // SANDBOX_WIN_SRC_SANDBOX_H_ |