1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this
4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 
6 #ifndef mozilla_Sandbox_h
7 #define mozilla_Sandbox_h
8 
9 #include <string>
10 
11 enum MacSandboxType {
12   MacSandboxType_Default = 0,
13   MacSandboxType_Content,
14   MacSandboxType_GMP,
15   MacSandboxType_RDD,
16   MacSandboxType_Socket,
17   MacSandboxType_Utility,
18   MacSandboxType_Invalid
19 };
20 
21 typedef struct _MacSandboxInfo {
_MacSandboxInfo_MacSandboxInfo22   _MacSandboxInfo()
23       : type(MacSandboxType_Default),
24         level(0),
25         hasFilePrivileges(false),
26         hasSandboxedProfile(false),
27         hasAudio(false),
28         hasWindowServer(false),
29         shouldLog(false) {}
30   _MacSandboxInfo(const struct _MacSandboxInfo& other) = default;
31 
32   void AppendAsParams(std::vector<std::string>& aParams) const;
33   static void AppendFileAccessParam(std::vector<std::string>& aParams,
34                                     bool aHasFilePrivileges);
35 
36  private:
37   void AppendStartupParam(std::vector<std::string>& aParams) const;
38   void AppendLoggingParam(std::vector<std::string>& aParams) const;
39   void AppendAppPathParam(std::vector<std::string>& aParams) const;
40   void AppendPluginPathParam(std::vector<std::string>& aParams) const;
41   void AppendLevelParam(std::vector<std::string>& aParams) const;
42   void AppendAudioParam(std::vector<std::string>& aParams) const;
43   void AppendWindowServerParam(std::vector<std::string>& aParams) const;
44   void AppendReadPathParams(std::vector<std::string>& aParams) const;
45 #ifdef DEBUG
46   void AppendDebugWriteDirParam(std::vector<std::string>& aParams) const;
47 #endif
48 
49  public:
50   MacSandboxType type;
51   int32_t level;
52   bool hasFilePrivileges;
53   bool hasSandboxedProfile;
54   bool hasAudio;
55   bool hasWindowServer;
56 
57   std::string appPath;
58   std::string appBinaryPath;
59   std::string appDir;
60   std::string profileDir;
61   std::string debugWriteDir;
62 
63   std::string pluginPath;
64   std::string pluginBinaryPath;
65 
66   std::string testingReadPath1;
67   std::string testingReadPath2;
68   std::string testingReadPath3;
69   std::string testingReadPath4;
70 
71   std::string crashServerPort;
72 
73   bool shouldLog;
74 } MacSandboxInfo;
75 
76 namespace mozilla {
77 
78 bool StartMacSandbox(MacSandboxInfo const& aInfo, std::string& aErrorMessage);
79 bool StartMacSandboxIfEnabled(MacSandboxType aSandboxType, int aArgc,
80                               char** aArgv, std::string& aErrorMessage);
81 bool IsMacSandboxStarted();
82 #ifdef DEBUG
83 void AssertMacSandboxEnabled();
84 #endif /* DEBUG */
85 
86 }  // namespace mozilla
87 
88 #endif  // mozilla_Sandbox_h
89