Chromium Code Reviews| Index: sandbox/linux/syscall_broker/broker_file_permission.h |
| diff --git a/sandbox/linux/syscall_broker/broker_file_permission.h b/sandbox/linux/syscall_broker/broker_file_permission.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a0c59f16e97edc498afb4a17d70f3559fcb419dc |
| --- /dev/null |
| +++ b/sandbox/linux/syscall_broker/broker_file_permission.h |
| @@ -0,0 +1,96 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef SANDBOX_LINUX_SYSCALL_BROKER_BROKER_FILE_PERMISSION_H_ |
| +#define SANDBOX_LINUX_SYSCALL_BROKER_BROKER_FILE_PERMISSION_H_ |
| + |
| +#include <string> |
| + |
| +#include "base/macros.h" |
| + |
| +class Pickle; |
| + |
| +namespace sandbox { |
| + |
| +namespace syscall_broker { |
| + |
| +class BrokerFilePermission { |
| + public: |
| + ~BrokerFilePermission() {} |
| + BrokerFilePermission(const BrokerFilePermission&) = default; |
| + BrokerFilePermission& operator=(const BrokerFilePermission&) = default; |
| + |
| + static BrokerFilePermission ReadOnly(std::string path) { |
| + return BrokerFilePermission(path, false, false, true, false, false); |
| + } |
| + |
| + static BrokerFilePermission ReadOnlyRecursive(std::string path) { |
| + return BrokerFilePermission(path, true, false, true, false, false); |
| + } |
| + |
| + static BrokerFilePermission WriteOnly(std::string path) { |
| + return BrokerFilePermission(path, false, false, false, true, false); |
| + } |
| + |
| + static BrokerFilePermission ReadWrite(std::string path) { |
| + return BrokerFilePermission(path, false, false, true, true, false); |
| + } |
| + |
| + static BrokerFilePermission ReadWriteCreate(std::string path) { |
| + return BrokerFilePermission(path, false, false, true, true, true); |
| + } |
| + |
| + static BrokerFilePermission ReadWriteCreateUnlink(std::string path) { |
| + return BrokerFilePermission(path, false, true, true, true, true); |
| + } |
| + |
| + static BrokerFilePermission ReadWriteCreateUnlinkRecursive(std::string path) { |
| + return BrokerFilePermission(path, true, true, true, true, true); |
| + } |
| + |
| + // Returns true if |requested_filename| is allowed to be opened |
| + // by this permission. |
| + // If |file_to_open| is not NULL it is set to point to either |
| + // the |requested_filename| in the case of a recursive match, |
| + // or a pointer the matched path in the whitelist if an absolute |
| + // match. |
| + // Async signal safe if |file_to_open| is NULL |
| + bool CheckOpen(const char* requested_filename, |
| + int flags, |
| + const char** file_to_open, |
| + bool* unlink_after_open) const; |
| + // Returns true if |requested_filename| is allowed to be accessed |
| + // by this permission. |
| + // If |file_to_open| is not NULL it is set to point to either |
| + // the |requested_filename| in the case of a recursive match, |
| + // or a pointer the matched path in the whitelist if an absolute |
| + // match. |
| + // Async signal safe if |file_to_open| is NULL |
| + bool CheckAccess(const char* requested_filename, |
| + int mode, |
| + const char** file_to_access) const; |
| + |
| + private: |
| + BrokerFilePermission(std::string path, |
| + bool recursive, |
| + bool unlink, |
| + bool allow_read, |
| + bool allow_write, |
| + bool allow_create); |
| + bool MatchPath(const char* requested_filename) const; |
| + |
| + 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
|
| + const bool |
| + recursive_; // Allow everything under this path. |path| must be a dir. |
| + const bool unlink_; // unlink after opening. |
| + const bool allow_read_; |
| + const bool allow_write_; |
| + const bool allow_create_; |
| +}; |
| + |
| +} // namespace syscall_broker |
| + |
| +} // namespace sandbox |
| + |
| +#endif // SANDBOX_LINUX_SYSCALL_BROKER_BROKER_FILE_PERMISSION_H_ |