Home | History | Annotate | Download | only in common
      1 // Copyright (c) 2012 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 #ifndef CONTENT_PUBLIC_COMMON_SANDBOX_INIT_H_
      6 #define CONTENT_PUBLIC_COMMON_SANDBOX_INIT_H_
      7 
      8 #include "base/memory/scoped_ptr.h"
      9 #include "base/process/process.h"
     10 #include "build/build_config.h"
     11 #include "content/common/content_export.h"
     12 
     13 class CommandLine;
     14 
     15 namespace base {
     16 class FilePath;
     17 }
     18 
     19 namespace sandbox {
     20 class SandboxBPFPolicy;
     21 struct SandboxInterfaceInfo;
     22 }
     23 
     24 namespace content {
     25 class SandboxedProcessLauncherDelegate;
     26 
     27 #if defined(OS_WIN)
     28 
     29 // Initialize the sandbox for renderer, gpu, utility, worker, nacl, and plug-in
     30 // processes, depending on the command line flags. Although The browser process
     31 // is not sandboxed, this also needs to be called because it will initialize
     32 // the broker code.
     33 // Returns true if the sandbox was initialized succesfully, false if an error
     34 // occurred.  If process_type isn't one that needs sandboxing true is always
     35 // returned.
     36 CONTENT_EXPORT bool InitializeSandbox(
     37     sandbox::SandboxInterfaceInfo* sandbox_info);
     38 
     39 // This is a restricted version of Windows' DuplicateHandle() function
     40 // that works inside the sandbox and can send handles but not retrieve
     41 // them.  Unlike DuplicateHandle(), it takes a process ID rather than
     42 // a process handle.  It returns true on success, false otherwise.
     43 CONTENT_EXPORT bool BrokerDuplicateHandle(HANDLE source_handle,
     44                                           DWORD target_process_id,
     45                                           HANDLE* target_handle,
     46                                           DWORD desired_access,
     47                                           DWORD options);
     48 
     49 // Inform the current process's sandbox broker (e.g. the broker for
     50 // 32-bit processes) about a process created under a different sandbox
     51 // broker (e.g. the broker for 64-bit processes).  This allows
     52 // BrokerDuplicateHandle() to send handles to a process managed by
     53 // another broker.  For example, it allows the 32-bit renderer to send
     54 // handles to 64-bit NaCl processes.  This returns true on success,
     55 // false otherwise.
     56 CONTENT_EXPORT bool BrokerAddTargetPeer(HANDLE peer_process);
     57 
     58 // Launch a sandboxed process. |delegate| may be NULL. If |delegate| is non-NULL
     59 // then it just has to outlive this method call.
     60 CONTENT_EXPORT base::ProcessHandle StartSandboxedProcess(
     61     SandboxedProcessLauncherDelegate* delegate,
     62     CommandLine* cmd_line);
     63 
     64 #elif defined(OS_MACOSX)
     65 
     66 // Initialize the sandbox of the given |sandbox_type|, optionally specifying a
     67 // directory to allow access to. Note specifying a directory needs to be
     68 // supported by the sandbox profile associated with the given |sandbox_type|.
     69 // Valid values for |sandbox_type| are defined either by the enum SandboxType,
     70 // or by ContentClient::GetSandboxProfileForSandboxType().
     71 //
     72 // If the |sandbox_type| isn't one of the ones defined by content then the
     73 // embedder is queried using ContentClient::GetSandboxPolicyForSandboxType().
     74 // The embedder can use values for |sandbox_type| starting from
     75 // sandbox::SANDBOX_PROCESS_TYPE_AFTER_LAST_TYPE.
     76 //
     77 // Returns true if the sandbox was initialized succesfully, false if an error
     78 // occurred.  If process_type isn't one that needs sandboxing, no action is
     79 // taken and true is always returned.
     80 CONTENT_EXPORT bool InitializeSandbox(int sandbox_type,
     81                                       const base::FilePath& allowed_path);
     82 
     83 #elif defined(OS_LINUX)
     84 
     85 class SandboxInitializerDelegate;
     86 
     87 // Initialize a seccomp-bpf sandbox. |policy| may not be NULL.
     88 // Returns true if the sandbox has been properly engaged.
     89 CONTENT_EXPORT bool InitializeSandbox(
     90     scoped_ptr<sandbox::SandboxBPFPolicy> policy);
     91 
     92 // Return a "baseline" policy. This is used by a SandboxInitializerDelegate to
     93 // implement a policy that is derived from the baseline.
     94 CONTENT_EXPORT scoped_ptr<sandbox::SandboxBPFPolicy>
     95 GetBPFSandboxBaselinePolicy();
     96 #endif  // defined(OS_LINUX)
     97 
     98 }  // namespace content
     99 
    100 #endif  // CONTENT_PUBLIC_COMMON_SANDBOX_INIT_H_
    101