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

Side by Side Diff: sandbox/linux/syscall_broker/broker_file_permission.h

Issue 721553002: sandbox: Extend BrokerPolicy to support file creation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: lame Created 6 years, 1 month 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
OLDNEW
(Empty)
1 // Copyright 2014 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_SYSCALL_BROKER_BROKER_FILE_PERMISSION_H_
6 #define SANDBOX_LINUX_SYSCALL_BROKER_BROKER_FILE_PERMISSION_H_
7
8 #include <string>
9
10 #include "base/macros.h"
11
12 class Pickle;
13
14 namespace sandbox {
15
16 namespace syscall_broker {
17
18 class BrokerFilePermission {
19 public:
20 ~BrokerFilePermission() {}
21 BrokerFilePermission(const BrokerFilePermission&) = default;
22 BrokerFilePermission& operator=(const BrokerFilePermission&) = default;
23
24 static BrokerFilePermission ReadOnly(std::string path) {
25 return BrokerFilePermission(path, false, false, true, false, false);
26 }
27
28 static BrokerFilePermission ReadOnlyRecursive(std::string path) {
29 return BrokerFilePermission(path, true, false, true, false, false);
30 }
31
32 static BrokerFilePermission WriteOnly(std::string path) {
33 return BrokerFilePermission(path, false, false, false, true, false);
34 }
35
36 static BrokerFilePermission ReadWrite(std::string path) {
37 return BrokerFilePermission(path, false, false, true, true, false);
38 }
39
40 static BrokerFilePermission ReadWriteCreate(std::string path) {
41 return BrokerFilePermission(path, false, false, true, true, true);
42 }
43
44 static BrokerFilePermission ReadWriteCreateUnlink(std::string path) {
45 return BrokerFilePermission(path, false, true, true, true, true);
46 }
47
48 static BrokerFilePermission ReadWriteCreateUnlinkRecursive(std::string path) {
49 return BrokerFilePermission(path, true, true, true, true, true);
50 }
51
52 // Returns true if |requested_filename| is allowed to be opened
53 // by this permission.
54 // If |file_to_open| is not NULL it is set to point to either
55 // the |requested_filename| in the case of a recursive match,
56 // or a pointer the matched path in the whitelist if an absolute
57 // match.
58 // Async signal safe if |file_to_open| is NULL
59 bool CheckOpen(const char* requested_filename,
60 int flags,
61 const char** file_to_open,
62 bool* unlink_after_open) const;
63 // Returns true if |requested_filename| is allowed to be accessed
64 // by this permission.
65 // If |file_to_open| is not NULL it is set to point to either
66 // the |requested_filename| in the case of a recursive match,
67 // or a pointer the matched path in the whitelist if an absolute
68 // match.
69 // Async signal safe if |file_to_open| is NULL
70 bool CheckAccess(const char* requested_filename,
71 int mode,
72 const char** file_to_access) const;
73
74 private:
75 BrokerFilePermission(std::string path,
76 bool recursive,
77 bool unlink,
78 bool allow_read,
79 bool allow_write,
80 bool allow_create);
81 bool MatchPath(const char* requested_filename) const;
82
83 const std::string path_;
jln (very slow on Chromium) 2014/11/24 20:12:17 Why store a std::string? It looks like a scoped_pt
84 const bool
85 recursive_; // Allow everything under this path. |path| must be a dir.
86 const bool unlink_; // unlink after opening.
87 const bool allow_read_;
88 const bool allow_write_;
89 const bool allow_create_;
90 };
91
92 } // namespace syscall_broker
93
94 } // namespace sandbox
95
96 #endif // SANDBOX_LINUX_SYSCALL_BROKER_BROKER_FILE_PERMISSION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698