filesystem_policy.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // Copyright (c) 2006-2008 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. #ifndef SANDBOX_WIN_SRC_FILESYSTEM_POLICY_H_
  5. #define SANDBOX_WIN_SRC_FILESYSTEM_POLICY_H_
  6. #include <stdint.h>
  7. #include <string>
  8. #include "sandbox/win/src/crosscall_server.h"
  9. #include "sandbox/win/src/nt_internals.h"
  10. #include "sandbox/win/src/policy_low_level.h"
  11. #include "sandbox/win/src/sandbox_policy.h"
  12. namespace sandbox {
  13. // This class centralizes most of the knowledge related to file system policy
  14. class FileSystemPolicy {
  15. public:
  16. // Creates the required low-level policy rules to evaluate a high-level
  17. // policy rule for File IO, in particular open or create actions.
  18. // 'name' is the file or directory name.
  19. // 'semantics' is the desired semantics for the open or create.
  20. // 'policy' is the policy generator to which the rules are going to be added.
  21. static bool GenerateRules(const wchar_t* name,
  22. Semantics semantics,
  23. LowLevelPolicy* policy);
  24. // Performs the desired policy action on a create request with an
  25. // API that is compatible with the IPC-received parameters.
  26. // 'client_info' : the target process that is making the request.
  27. // 'eval_result' : The desired policy action to accomplish.
  28. // 'file' : The target file or directory.
  29. static bool CreateFileAction(EvalResult eval_result,
  30. const ClientInfo& client_info,
  31. const std::wstring& file,
  32. uint32_t attributes,
  33. uint32_t desired_access,
  34. uint32_t file_attributes,
  35. uint32_t share_access,
  36. uint32_t create_disposition,
  37. uint32_t create_options,
  38. HANDLE* handle,
  39. NTSTATUS* nt_status,
  40. ULONG_PTR* io_information);
  41. // Performs the desired policy action on an open request with an
  42. // API that is compatible with the IPC-received parameters.
  43. // 'client_info' : the target process that is making the request.
  44. // 'eval_result' : The desired policy action to accomplish.
  45. // 'file' : The target file or directory.
  46. static bool OpenFileAction(EvalResult eval_result,
  47. const ClientInfo& client_info,
  48. const std::wstring& file,
  49. uint32_t attributes,
  50. uint32_t desired_access,
  51. uint32_t share_access,
  52. uint32_t open_options,
  53. HANDLE* handle,
  54. NTSTATUS* nt_status,
  55. ULONG_PTR* io_information);
  56. // Performs the desired policy action on a query request with an
  57. // API that is compatible with the IPC-received parameters.
  58. static bool QueryAttributesFileAction(EvalResult eval_result,
  59. const ClientInfo& client_info,
  60. const std::wstring& file,
  61. uint32_t attributes,
  62. FILE_BASIC_INFORMATION* file_info,
  63. NTSTATUS* nt_status);
  64. // Performs the desired policy action on a query request with an
  65. // API that is compatible with the IPC-received parameters.
  66. static bool QueryFullAttributesFileAction(
  67. EvalResult eval_result,
  68. const ClientInfo& client_info,
  69. const std::wstring& file,
  70. uint32_t attributes,
  71. FILE_NETWORK_OPEN_INFORMATION* file_info,
  72. NTSTATUS* nt_status);
  73. // Performs the desired policy action on a set_info request with an
  74. // API that is compatible with the IPC-received parameters.
  75. static bool SetInformationFileAction(EvalResult eval_result,
  76. const ClientInfo& client_info,
  77. HANDLE target_file_handle,
  78. void* file_info,
  79. uint32_t length,
  80. uint32_t info_class,
  81. IO_STATUS_BLOCK* io_block,
  82. NTSTATUS* nt_status);
  83. };
  84. // Expands the path and check if it's a reparse point. Returns false if the path
  85. // cannot be trusted.
  86. bool PreProcessName(std::wstring* path);
  87. // Corrects global paths to have a correctly escaped NT prefix at the
  88. // beginning. If the name has no NT prefix (either normal or escaped)
  89. // add the escaped form to the string
  90. std::wstring FixNTPrefixForMatch(const std::wstring& name);
  91. } // namespace sandbox
  92. #endif // SANDBOX_WIN_SRC_FILESYSTEM_POLICY_H_