OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef SANDBOX_LINUX_SERVICES_BROKER_PROCESS_H_ | 5 #ifndef SANDBOX_LINUX_SERVICES_BROKER_PROCESS_H_ |
6 #define SANDBOX_LINUX_SERVICES_BROKER_PROCESS_H_ | 6 #define SANDBOX_LINUX_SERVICES_BROKER_PROCESS_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/callback_forward.h" | 12 #include "base/callback_forward.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/pickle.h" | 14 #include "base/pickle.h" |
15 #include "base/process/process.h" | 15 #include "base/process/process.h" |
16 #include "sandbox/linux/syscall_broker/broker_policy.h" | 16 #include "sandbox/linux/syscall_broker/broker_policy.h" |
17 #include "sandbox/sandbox_export.h" | 17 #include "sandbox/sandbox_export.h" |
18 | 18 |
19 namespace sandbox { | 19 namespace sandbox { |
20 | 20 |
21 namespace syscall_broker { | 21 namespace syscall_broker { |
22 | 22 |
23 class BrokerClient; | 23 class BrokerClient; |
| 24 class BrokerFilePermission; |
24 | 25 |
25 // Create a new "broker" process to which we can send requests via an IPC | 26 // Create a new "broker" process to which we can send requests via an IPC |
26 // channel by forking the current process. | 27 // channel by forking the current process. |
27 // This is a low level IPC mechanism that is suitable to be called from a | 28 // This is a low level IPC mechanism that is suitable to be called from a |
28 // signal handler. | 29 // signal handler. |
29 // A process would typically create a broker process before entering | 30 // A process would typically create a broker process before entering |
30 // sandboxing. | 31 // sandboxing. |
31 // 1. BrokerProcess open_broker(read_whitelist, write_whitelist); | 32 // 1. BrokerProcess open_broker(read_whitelist, write_whitelist); |
32 // 2. CHECK(open_broker.Init(NULL)); | 33 // 2. CHECK(open_broker.Init(NULL)); |
33 // 3. Enable sandbox. | 34 // 3. Enable sandbox. |
34 // 4. Use open_broker.Open() to open files. | 35 // 4. Use open_broker.Open() to open files. |
35 class SANDBOX_EXPORT BrokerProcess { | 36 class SANDBOX_EXPORT BrokerProcess { |
36 public: | 37 public: |
37 // |denied_errno| is the error code returned when methods such as Open() | 38 // |denied_errno| is the error code returned when methods such as Open() |
38 // or Access() are invoked on a file which is not in the whitelist. EACCESS | 39 // or Access() are invoked on a file which is not in the whitelist. EACCESS |
39 // would be a typical value. | 40 // would be a typical value. |
40 // |allowed_r_files| and |allowed_w_files| are white lists of files that can | 41 // |allowed_r_files| and |allowed_w_files| are white lists of files that can |
41 // be opened later via the Open() API, respectively for reading and writing. | 42 // be opened later via the Open() API, respectively for reading and writing. |
42 // A file available read-write should be listed in both. | 43 // A file available read-write should be listed in both. |
43 // |fast_check_in_client| and |quiet_failures_for_tests| are reserved for | 44 // |fast_check_in_client| and |quiet_failures_for_tests| are reserved for |
44 // unit tests, don't use it. | 45 // unit tests, don't use it. |
45 BrokerProcess(int denied_errno, | 46 |
46 const std::vector<std::string>& allowed_r_files, | 47 BrokerProcess( |
47 const std::vector<std::string>& allowed_w_files, | 48 int denied_errno, |
48 bool fast_check_in_client = true, | 49 const std::vector<syscall_broker::BrokerFilePermission>& permissions, |
49 bool quiet_failures_for_tests = false); | 50 bool fast_check_in_client = true, |
| 51 bool quiet_failures_for_tests = false); |
| 52 |
50 ~BrokerProcess(); | 53 ~BrokerProcess(); |
51 // Will initialize the broker process. There should be no threads at this | 54 // Will initialize the broker process. There should be no threads at this |
52 // point, since we need to fork(). | 55 // point, since we need to fork(). |
53 // broker_process_init_callback will be called in the new broker process, | 56 // broker_process_init_callback will be called in the new broker process, |
54 // after fork() returns. | 57 // after fork() returns. |
55 bool Init(const base::Callback<bool(void)>& broker_process_init_callback); | 58 bool Init(const base::Callback<bool(void)>& broker_process_init_callback); |
56 | 59 |
57 // Can be used in place of access(). Will be async signal safe. | 60 // Can be used in place of access(). Will be async signal safe. |
58 // X_OK will always return an error in practice since the broker process | 61 // X_OK will always return an error in practice since the broker process |
59 // doesn't support execute permissions. | 62 // doesn't support execute permissions. |
(...skipping 22 matching lines...) Expand all Loading... |
82 scoped_ptr<syscall_broker::BrokerClient> broker_client_; | 85 scoped_ptr<syscall_broker::BrokerClient> broker_client_; |
83 | 86 |
84 DISALLOW_COPY_AND_ASSIGN(BrokerProcess); | 87 DISALLOW_COPY_AND_ASSIGN(BrokerProcess); |
85 }; | 88 }; |
86 | 89 |
87 } // namespace syscall_broker | 90 } // namespace syscall_broker |
88 | 91 |
89 } // namespace sandbox | 92 } // namespace sandbox |
90 | 93 |
91 #endif // SANDBOX_LINUX_SERVICES_BROKER_PROCESS_H_ | 94 #endif // SANDBOX_LINUX_SERVICES_BROKER_PROCESS_H_ |
OLD | NEW |