Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Side by Side Diff: sandbox/linux/services/broker_process.h

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

Powered by Google App Engine
This is Rietveld 408576698