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| and |quiet_failures_for_tests| are reserved for |
| 27 // unit tests, don't use it. |
| 28 explicit BrokerProcess(const std::vector<std::string>& allowed_file_names, |
| 29 bool fast_check_in_client = true, |
| 30 bool quiet_failures_for_tests = false); |
| 31 ~BrokerProcess(); |
| 32 // Will initialize the broker process. There should be no threads at this |
| 33 // point, since we need to fork(). |
| 34 // sandbox_callback should be NULL as this feature is not implemented yet. |
| 35 bool Init(void* sandbox_callback); |
| 36 |
| 37 // Can be used in place of open(). Will be async signal safe. |
| 38 // The implementation only supports O_RDONLY for now. |
| 39 // It's similar to the open() system call and will return -errno. |
| 40 int Open(const char* pathname, int flags) const; |
| 41 |
| 42 int broker_pid() const { return broker_pid_; } |
| 43 |
| 44 private: |
| 45 bool initialized_; // Whether we've been through Init() yet. |
| 46 bool is_child_; // Whether we're the child (broker process). |
| 47 bool fast_check_in_client_; // Whether to forward a request that we know |
| 48 // will be denied to the broker. |
| 49 bool quiet_failures_for_tests_; // Disable certain error message when |
| 50 // testing for failures. |
| 51 pid_t broker_pid_; // The PID of the broker (child). |
| 52 std::vector<std::string> allowed_file_names_; |
| 53 int ipc_socketpair_; // Our communication channel to parent or child. |
| 54 DISALLOW_IMPLICIT_CONSTRUCTORS(BrokerProcess); |
| 55 }; |
| 56 |
| 57 } // namespace sandbox |
| 58 |
| 59 #endif // SANDBOX_LINUX_SERVICES_BROKER_PROCESS_H_ |
OLD | NEW |