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/pickle.h" | 12 #include "base/pickle.h" |
13 #include "base/process.h" | 13 #include "base/process.h" |
14 | 14 |
15 namespace sandbox { | 15 namespace sandbox { |
16 | 16 |
17 // Create a new "broker" process to which we can send requests via an IPC | 17 // Create a new "broker" process to which we can send requests via an IPC |
18 // channel. | 18 // channel. |
19 // This is a low level IPC mechanism that is suitable to be called from a | 19 // This is a low level IPC mechanism that is suitable to be called from a |
20 // signal handler. | 20 // signal handler. |
21 // A process would typically create a broker process before entering | 21 // A process would typically create a broker process before entering |
22 // sandboxing. | 22 // sandboxing. |
23 // 1. BrokerProcess open_broker(file_whitelist); | 23 // 1. BrokerProcess open_broker(read_whitelist, write_whitelist); |
24 // 2. CHECK(open_broker.Init(NULL)); | 24 // 2. CHECK(open_broker.Init(NULL)); |
25 // 3. Enable sandbox. | 25 // 3. Enable sandbox. |
26 // 4. Use open_broker.Open() to open files. | 26 // 4. Use open_broker.Open() to open files. |
27 class BrokerProcess { | 27 class BrokerProcess { |
28 public: | 28 public: |
29 // |allowed_file_names| is a white list of files that can be opened later via | 29 // |allowed_file_names| is a white list of files that can be opened later via |
30 // the Open() API. | 30 // the Open() API. |
31 // |fast_check_in_client| and |quiet_failures_for_tests| are reserved for | 31 // |fast_check_in_client| and |quiet_failures_for_tests| are reserved for |
32 // unit tests, don't use it. | 32 // unit tests, don't use it. |
33 explicit BrokerProcess(const std::vector<std::string>& allowed_r_files_, | 33 explicit BrokerProcess(const std::vector<std::string>& allowed_r_files_, |
34 const std::vector<std::string>& allowed_w_files_, | 34 const std::vector<std::string>& allowed_w_files_, |
35 bool fast_check_in_client = true, | 35 bool fast_check_in_client = true, |
36 bool quiet_failures_for_tests = false); | 36 bool quiet_failures_for_tests = false); |
37 ~BrokerProcess(); | 37 ~BrokerProcess(); |
38 // Will initialize the broker process. There should be no threads at this | 38 // Will initialize the broker process. There should be no threads at this |
39 // point, since we need to fork(). | 39 // point, since we need to fork(). |
40 // sandbox_callback should be NULL as this feature is not implemented yet. | 40 // sandbox_callback is a function that should be called to enable the |
41 bool Init(void* sandbox_callback); | 41 // sandbox in the broker. |
| 42 bool Init(bool (*sandbox_callback)(void)); |
42 | 43 |
43 // Can be used in place of open(). Will be async signal safe. | 44 // Can be used in place of open(). Will be async signal safe. |
44 // The implementation only supports certain white listed flags and will | 45 // The implementation only supports certain white listed flags and will |
45 // return -EPERM on other flags. | 46 // return -EPERM on other flags. |
46 // It's similar to the open() system call and will return -errno on errors. | 47 // It's similar to the open() system call and will return -errno on errors. |
47 int Open(const char* pathname, int flags) const; | 48 int Open(const char* pathname, int flags) const; |
48 | 49 |
49 int broker_pid() const { return broker_pid_; } | 50 int broker_pid() const { return broker_pid_; } |
50 | 51 |
51 private: | 52 private: |
(...skipping 10 matching lines...) Expand all Loading... |
62 pid_t broker_pid_; // The PID of the broker (child). | 63 pid_t broker_pid_; // The PID of the broker (child). |
63 const std::vector<std::string> allowed_r_files_; // Files allowed for read. | 64 const std::vector<std::string> allowed_r_files_; // Files allowed for read. |
64 const std::vector<std::string> allowed_w_files_; // Files allowed for write. | 65 const std::vector<std::string> allowed_w_files_; // Files allowed for write. |
65 int ipc_socketpair_; // Our communication channel to parent or child. | 66 int ipc_socketpair_; // Our communication channel to parent or child. |
66 DISALLOW_IMPLICIT_CONSTRUCTORS(BrokerProcess); | 67 DISALLOW_IMPLICIT_CONSTRUCTORS(BrokerProcess); |
67 }; | 68 }; |
68 | 69 |
69 } // namespace sandbox | 70 } // namespace sandbox |
70 | 71 |
71 #endif // SANDBOX_LINUX_SERVICES_BROKER_PROCESS_H_ | 72 #endif // SANDBOX_LINUX_SERVICES_BROKER_PROCESS_H_ |
OLD | NEW |