michael@0: // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: michael@0: #ifndef SANDBOX_SRC_FILESYSTEM_POLICY_H__ michael@0: #define SANDBOX_SRC_FILESYSTEM_POLICY_H__ michael@0: michael@0: #include michael@0: michael@0: #include "base/basictypes.h" michael@0: #include "sandbox/win/src/crosscall_server.h" michael@0: #include "sandbox/win/src/nt_internals.h" michael@0: #include "sandbox/win/src/policy_low_level.h" michael@0: #include "sandbox/win/src/sandbox_policy.h" michael@0: michael@0: namespace sandbox { michael@0: michael@0: enum EvalResult; michael@0: michael@0: // This class centralizes most of the knowledge related to file system policy michael@0: class FileSystemPolicy { michael@0: public: michael@0: // Creates the required low-level policy rules to evaluate a high-level michael@0: // policy rule for File IO, in particular open or create actions. michael@0: // 'name' is the file or directory name. michael@0: // 'semantics' is the desired semantics for the open or create. michael@0: // 'policy' is the policy generator to which the rules are going to be added. michael@0: static bool GenerateRules(const wchar_t* name, michael@0: TargetPolicy::Semantics semantics, michael@0: LowLevelPolicy* policy); michael@0: michael@0: // Add basic file system rules. michael@0: static bool SetInitialRules(LowLevelPolicy* policy); michael@0: michael@0: // Performs the desired policy action on a create request with an michael@0: // API that is compatible with the IPC-received parameters. michael@0: // 'client_info' : the target process that is making the request. michael@0: // 'eval_result' : The desired policy action to accomplish. michael@0: // 'file' : The target file or directory. michael@0: static bool CreateFileAction(EvalResult eval_result, michael@0: const ClientInfo& client_info, michael@0: const std::wstring &file, michael@0: uint32 attributes, michael@0: uint32 desired_access, michael@0: uint32 file_attributes, michael@0: uint32 share_access, michael@0: uint32 create_disposition, michael@0: uint32 create_options, michael@0: HANDLE* handle, michael@0: NTSTATUS* nt_status, michael@0: ULONG_PTR* io_information); michael@0: michael@0: // Performs the desired policy action on an open request with an michael@0: // API that is compatible with the IPC-received parameters. michael@0: // 'client_info' : the target process that is making the request. michael@0: // 'eval_result' : The desired policy action to accomplish. michael@0: // 'file' : The target file or directory. michael@0: static bool OpenFileAction(EvalResult eval_result, michael@0: const ClientInfo& client_info, michael@0: const std::wstring &file, michael@0: uint32 attributes, michael@0: uint32 desired_access, michael@0: uint32 share_access, michael@0: uint32 open_options, michael@0: HANDLE* handle, michael@0: NTSTATUS* nt_status, michael@0: ULONG_PTR* io_information); michael@0: michael@0: // Performs the desired policy action on a query request with an michael@0: // API that is compatible with the IPC-received parameters. michael@0: static bool QueryAttributesFileAction(EvalResult eval_result, michael@0: const ClientInfo& client_info, michael@0: const std::wstring &file, michael@0: uint32 attributes, michael@0: FILE_BASIC_INFORMATION* file_info, michael@0: NTSTATUS* nt_status); michael@0: michael@0: // Performs the desired policy action on a query request with an michael@0: // API that is compatible with the IPC-received parameters. michael@0: static bool QueryFullAttributesFileAction( michael@0: EvalResult eval_result, michael@0: const ClientInfo& client_info, michael@0: const std::wstring &file, michael@0: uint32 attributes, michael@0: FILE_NETWORK_OPEN_INFORMATION* file_info, michael@0: NTSTATUS* nt_status); michael@0: michael@0: // Performs the desired policy action on a set_info request with an michael@0: // API that is compatible with the IPC-received parameters. michael@0: static bool SetInformationFileAction(EvalResult eval_result, michael@0: const ClientInfo& client_info, michael@0: HANDLE target_file_handle, michael@0: void* file_info, michael@0: uint32 length, michael@0: uint32 info_class, michael@0: IO_STATUS_BLOCK* io_block, michael@0: NTSTATUS* nt_status); michael@0: }; michael@0: michael@0: // Expands the path and check if it's a reparse point. Returns false if michael@0: // we cannot determine or if there is an unexpected error. In that case michael@0: // the path cannot be trusted. michael@0: bool PreProcessName(const std::wstring& path, std::wstring* new_path); michael@0: michael@0: } // namespace sandbox michael@0: michael@0: #endif // SANDBOX_SRC_FILESYSTEM_POLICY_H__