OLD | NEW |
| (Empty) |
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 SANDBOX_LINUX_SERVICES_BROKER_PROCESS_H_ | |
6 #define SANDBOX_LINUX_SERVICES_BROKER_PROCESS_H_ | |
7 | |
8 #include <string> | |
9 #include <vector> | |
10 | |
11 #include "base/basictypes.h" | |
12 #include "base/pickle.h" | |
13 #include "base/process.h" | |
14 | |
15 namespace sandbox { | |
16 | |
17 // Create a new "broker" process to which we can send requests via an IPC | |
18 // channel. | |
19 // This is a low level IPC mechanism that is suitable to be called from a | |
20 // signal handler. | |
21 // A process would typically create a broker process before entering | |
22 // sandboxing. | |
23 // 1. BrokerProcess open_broker(file_whitelist); | |
24 // 2. CHECK(open_broker.Init(NULL)); | |
25 // 3. Enable sandbox. | |
26 // 4. Use open_broker.Open() to open files. | |
27 class BrokerProcess { | |
28 public: | |
29 // |allowed_file_names| is a white list of files that can be opened later via | |
30 // the Open() API. | |
31 // |fast_check_in_client| and |quiet_failures_for_tests| are reserved for | |
32 // unit tests, don't use it. | |
33 explicit BrokerProcess(const std::vector<std::string>& allowed_r_files_, | |
34 const std::vector<std::string>& allowed_w_files_, | |
35 bool fast_check_in_client = true, | |
36 bool quiet_failures_for_tests = false); | |
37 ~BrokerProcess(); | |
38 // Will initialize the broker process. There should be no threads at this | |
39 // point, since we need to fork(). | |
40 // sandbox_callback should be NULL as this feature is not implemented yet. | |
41 bool Init(void* sandbox_callback); | |
42 | |
43 // Can be used in place of open(). Will be async signal safe. | |
44 // The implementation only supports certain white listed flags and will | |
45 // return -EPERM on other flags. | |
46 // It's similar to the open() system call and will return -errno on errors. | |
47 int Open(const char* pathname, int flags) const; | |
48 | |
49 int broker_pid() const { return broker_pid_; } | |
50 | |
51 private: | |
52 bool HandleRequest() const; | |
53 bool HandleOpenRequest(int reply_ipc, const Pickle& read_pickle, | |
54 PickleIterator iter) const; | |
55 bool GetFileNameIfAllowedAccess(const char*, int, const char**) const; | |
56 bool initialized_; // Whether we've been through Init() yet. | |
57 bool is_child_; // Whether we're the child (broker process). | |
58 bool fast_check_in_client_; // Whether to forward a request that we know | |
59 // will be denied to the broker. | |
60 bool quiet_failures_for_tests_; // Disable certain error message when | |
61 // testing for failures. | |
62 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_w_files_; // Files allowed for write. | |
65 int ipc_socketpair_; // Our communication channel to parent or child. | |
66 DISALLOW_IMPLICIT_CONSTRUCTORS(BrokerProcess); | |
67 }; | |
68 | |
69 } // namespace sandbox | |
70 | |
71 #endif // SANDBOX_LINUX_SERVICES_BROKER_PROCESS_H_ | |
OLD | NEW |