ConfigHelpers.h (1890B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef SECURITY_SANDBOX_WIN_SRC_SANDBOXBROKER_CONFIGHELPERS_H_ 8 #define SECURITY_SANDBOX_WIN_SRC_SANDBOXBROKER_CONFIGHELPERS_H_ 9 10 #include <minwindef.h> 11 12 #include "mozilla/Attributes.h" 13 #include "nsStringFwd.h" 14 #include "sandbox/win/src/sandbox_policy.h" 15 16 namespace sandbox { 17 class TargetPolicy; 18 } // namespace sandbox 19 20 namespace mozilla::sandboxing { 21 22 // Used to track size of config and fail if rule will breach the maximum set. 23 class SizeTrackingConfig { 24 public: 25 explicit SizeTrackingConfig(sandbox::TargetConfig* aConfig, 26 int32_t aStoragePages); 27 28 virtual sandbox::ResultCode AllowFileAccess(sandbox::FileSemantics aSemantics, 29 const wchar_t* aPattern); 30 31 private: 32 sandbox::TargetConfig* mConfig; 33 int32_t mRemainingSize; 34 }; 35 36 MOZ_RAII class UserFontConfigHelper final { 37 public: 38 UserFontConfigHelper(const wchar_t* aUserFontKeyPath, 39 const nsString& aWinUserProfile, 40 const nsString& aLocalAppData, 41 const nsString& aRoamingAppData); 42 ~UserFontConfigHelper(); 43 44 void AddRules(sandboxing::SizeTrackingConfig& aConfig) const; 45 46 UserFontConfigHelper(const UserFontConfigHelper&) = delete; 47 UserFontConfigHelper& operator=(const UserFontConfigHelper&) = delete; 48 49 private: 50 const nsString& mWinUserProfile; 51 const nsString& mLocalAppData; 52 const nsString& mRoamingAppData; 53 HKEY mUserFontKey = nullptr; 54 }; 55 56 } // namespace mozilla::sandboxing 57 58 #endif // SECURITY_SANDBOX_WIN_SRC_SANDBOXBROKER_CONFIGHELPERS_H_