OLD | NEW |
---|---|
(Empty) | |
1 #ifndef SANDBOX_LINUX_SERVICES_BROKER_PROCESS_H_ | |
2 #define SANDBOX_LINUX_SERVICES_BROKER_PROCESS_H_ | |
3 | |
4 #include <string> | |
5 #include <vector> | |
6 | |
7 #include "base/basictypes.h" | |
8 #include "base/process.h" | |
9 | |
10 namespace sandbox { | |
11 | |
12 // Create a new "broker" process to which we can send requests via an IPC | |
13 // channel. | |
14 // This is a low level IPC mechanism that is suitable to be called from a | |
15 // signal handler. | |
16 // A process would typically create a broker process before entering | |
17 // sandboxing. | |
18 // 1. BrokerProcess open_broker(file_whitelist); | |
19 // 2. CHECK(open_broker.Init(NULL)); | |
20 // 3. Enable sandbox. | |
21 // 4. Use open_broker.Open() to open files. | |
22 class BrokerProcess { | |
23 public: | |
24 // |allowed_file_names| is a white list of files that can be opened later via | |
25 // the Open() API. | |
26 // |fast_check_in_client| is reserved for unit tests, don't use it. | |
27 explicit BrokerProcess(const std::vector<std::string>& allowed_file_names, | |
28 bool fast_check_in_client = true); | |
29 ~BrokerProcess(); | |
30 // Will initialize the broker process. There should be no threads at this | |
31 // point, since we need to fork(). | |
32 // sandbox_callback should be NULL as this feature is not implemented yet. | |
33 bool Init(void* sandbox_callback); | |
34 | |
35 // Can be used in lieu of open(). Will be async signal safe. | |
Jorge Lucangeli Obes
2012/12/13 04:46:33
Nit: In place?
| |
36 // The implementation only supports O_RDONLY for now. | |
37 // It's similar to the open() system call and will return -errno. | |
38 int Open(const char* pathname, int flags) const; | |
39 | |
40 int broker_pid() const { return broker_pid_; } | |
41 | |
42 private: | |
43 bool initialized_; // Whether we've been through Init() yet. | |
44 bool is_child_; // Whether we're the child (broker process). | |
45 bool fast_check_in_client_; // Whether to forward a request that we know | |
46 // will be denied to the broker. | |
47 pid_t broker_pid_; // The PID of the broker (child). | |
48 std::vector<std::string> allowed_file_names_; | |
49 int ipc_socketpair_; // Our communication channel to parent or child. | |
50 DISALLOW_IMPLICIT_CONSTRUCTORS(BrokerProcess); | |
51 }; | |
52 | |
53 } // namespace sandbox | |
54 | |
55 #endif // SANDBOX_LINUX_SERVICES_BROKER_PROCESS_H_ | |
OLD | NEW |