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

Side by Side Diff: sandbox/mac/seatbelt_exec.h

Issue 2869203003: Add the SeatbeltExec classes to facilitate the V2 sandbox. (Closed)
Patch Set: Cleanup per review Created 3 years, 7 months 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
« no previous file with comments | « sandbox/mac/seatbelt.proto ('k') | sandbox/mac/seatbelt_exec.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
Robert Sesek 2017/05/17 18:35:26 2017
Greg K 2017/05/17 21:40:07 Done.
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_MAC_SEATBELT_EXEC_H_
6 #define SANDBOX_MAC_SEATBELT_EXEC_H_
7
8 #include <string>
9 #include <unordered_map>
Robert Sesek 2017/05/17 18:35:26 unused
Greg K 2017/05/17 21:40:07 Done.
10
11 #include "base/compiler_specific.h"
12 #include "base/files/scoped_file.h"
13 #include "base/strings/string_piece.h"
14 #include "sandbox/mac/seatbelt.pb.h"
15 #include "sandbox/mac/seatbelt_export.h"
16
17 namespace sandbox {
18
19 // SeatbeltExecClient is used by the process that is launching another sandboxed
20 // process. The API allows the launcher process to supply a sandbox profile and
21 // parameters, which will be communicated to the sandboxed process over IPC.
22 class SEATBELT_EXPORT SeatbeltExecClient {
23 public:
24 SeatbeltExecClient();
25 ~SeatbeltExecClient();
26
27 // The Set*Parameter functions return true if the parameter was successfully
28 // inserted. Check the return value, which indicates if the parameter was
29 // added successfully.
30
31 // Set a boolean parameter in the sandbox profile.
32 bool SetBooleanParameter(const base::StringPiece key,
33 bool value) WARN_UNUSED_RESULT;
34
35 // Set a string parameter in the sandbox profile.
36 bool SetParameter(const base::StringPiece key,
37 const base::StringPiece value) WARN_UNUSED_RESULT;
38
39 // Set the actual sandbox profile, using the scheme-like SBPL.
40 void SetProfile(const base::StringPiece policy);
41
42 // Sends the policy to the SeatbeltExecServer and returns the communication
43 // FD. The FD should be mapped into the sandboxed child process.
44 int SendProfileAndGetFD();
45
46 // Returns the underlying protobuf for testing purposes.
47 const mac::SandboxPolicy& GetPolicyForTesting() { return policy_; }
48
49 private:
50 // This writes a string (the serialized protobuf) to the |pipe_|.
51 bool WriteString(std::string* str);
52
53 // This is the protobuf which contains the sandbox profile and parameters,
54 // and is serialized and sent to the other process.
55 mac::SandboxPolicy policy_;
56
57 // A file descriptor pair used for interprocess communication.
58 int pipe_[2];
59 };
60
61 // SeatbeltExecServer is used by the process that will be sandboxed to receive
62 // the profile and parameters from the launcher process. It can then initialize
63 // the profile, sandboxing the process.
64 class SEATBELT_EXPORT SeatbeltExecServer {
65 public:
66 explicit SeatbeltExecServer(int sandbox_fd);
Robert Sesek 2017/05/17 18:35:26 Comment that |sandbox_fd| should the result of Sen
Greg K 2017/05/17 21:40:07 Done.
67 ~SeatbeltExecServer();
68
69 // Reads the policy from the client, applies the profile, and returns whether
70 // or not the operation succeeds.
71 bool InitializeSandbox();
72
73 // Applies the given sandbox policy, and returns whether or not the operation
74 // succeeds.
75 bool ApplySandboxProfile(const mac::SandboxPolicy& sandbox_policy);
76
77 private:
78 // Reads from the |fd_| and stores the data into a string. This does
79 // not append a NUL terminator as protobuf does not expect one.
80 bool ReadString(std::string* string);
81
82 // The file descriptor used to communicate with the launcher process.
83 base::ScopedFD fd_;
84 };
85
86 } // namespace sandbox
87
88 #endif // SANDBOX_MAC_SEATBELT_EXEC_H_
OLDNEW
« no previous file with comments | « sandbox/mac/seatbelt.proto ('k') | sandbox/mac/seatbelt_exec.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698