Ben Chan | cb51773 | 2012-04-11 17:00:00 -0700 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 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 CROS_DISKS_ARCHIVE_MANAGER_H_ |
| 6 | #define CROS_DISKS_ARCHIVE_MANAGER_H_ |
| 7 | |
Ben Chan | cb51773 | 2012-04-11 17:00:00 -0700 | [diff] [blame] | 8 | #include <map> |
Anand K Mistry | 29fee84 | 2020-01-15 15:49:48 +1100 | [diff] [blame] | 9 | #include <memory> |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 10 | #include <string> |
| 11 | #include <vector> |
| 12 | |
François Degros | f76886e | 2020-07-24 18:13:40 +1000 | [diff] [blame] | 13 | #include <brillo/scoped_mount_namespace.h> |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 14 | #include <gtest/gtest_prod.h> |
| 15 | |
Sergei Datsenko | 87c49bb | 2021-01-13 15:08:07 +1100 | [diff] [blame] | 16 | #include "cros-disks/fuse_mounter.h" |
Ben Chan | 5ccd9fe | 2013-11-13 18:28:27 -0800 | [diff] [blame] | 17 | #include "cros-disks/mount_manager.h" |
François Degros | f76886e | 2020-07-24 18:13:40 +1000 | [diff] [blame] | 18 | #include "cros-disks/mount_options.h" |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 19 | |
| 20 | namespace cros_disks { |
| 21 | |
Sergei Datsenko | c9904bb | 2020-12-11 12:46:02 +1100 | [diff] [blame] | 22 | class ArchiveMounter; |
| 23 | |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 24 | // A derived class of MountManager for mounting archive files as a virtual |
| 25 | // filesystem. |
| 26 | class ArchiveManager : public MountManager { |
| 27 | public: |
Sergei Datsenko | c9904bb | 2020-12-11 12:46:02 +1100 | [diff] [blame] | 28 | ArchiveManager(const std::string& mount_root, |
| 29 | Platform* platform, |
| 30 | Metrics* metrics, |
| 31 | brillo::ProcessReaper* process_reaper); |
| 32 | ArchiveManager(const ArchiveManager&) = delete; |
| 33 | ArchiveManager& operator=(const ArchiveManager&) = delete; |
| 34 | |
| 35 | ~ArchiveManager() override; |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 36 | |
François Degros | 7f7a416 | 2020-06-13 00:13:00 +1000 | [diff] [blame] | 37 | // MountManager overrides |
Sergei Datsenko | c9904bb | 2020-12-11 12:46:02 +1100 | [diff] [blame] | 38 | bool Initialize() override; |
| 39 | |
François Degros | 7f7a416 | 2020-06-13 00:13:00 +1000 | [diff] [blame] | 40 | MountSourceType GetMountSourceType() const final { |
Ben Chan | 6d0b272 | 2011-11-18 08:24:14 -0800 | [diff] [blame] | 41 | return MOUNT_SOURCE_ARCHIVE; |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 42 | } |
| 43 | |
François Degros | f76886e | 2020-07-24 18:13:40 +1000 | [diff] [blame] | 44 | bool ResolvePath(const std::string& path, std::string* real_path) final; |
| 45 | |
| 46 | std::string SuggestMountPath(const std::string& source_path) const final; |
| 47 | |
François Degros | 7f7a416 | 2020-06-13 00:13:00 +1000 | [diff] [blame] | 48 | // Checks if the given file path is in an allowed location to be mounted as an |
| 49 | // archive. The following paths can be mounted: |
| 50 | // |
| 51 | // /home/chronos/u-<user-id>/MyFiles/...<file> |
| 52 | // /media/archive/<dir>/...<file> |
| 53 | // /media/fuse/<dir>/...<file> |
| 54 | // /media/removable/<dir>/...<file> |
| 55 | // /run/arc/sdcard/write/emulated/0/<dir>/...<file> |
| 56 | static bool IsInAllowedFolder(const std::string& source_path); |
François Degros | 853c7d9 | 2020-02-17 10:32:21 +1100 | [diff] [blame] | 57 | |
François Degros | f76886e | 2020-07-24 18:13:40 +1000 | [diff] [blame] | 58 | // Gets a list of supplementary group IDs the FUSE mounter program should run |
| 59 | // with in order to access files in all the required locations. |
| 60 | std::vector<gid_t> GetSupplementaryGroups() const; |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 61 | |
Sergei Datsenko | c9904bb | 2020-12-11 12:46:02 +1100 | [diff] [blame] | 62 | bool CanMount(const std::string& source_path) const override; |
François Degros | f76886e | 2020-07-24 18:13:40 +1000 | [diff] [blame] | 63 | |
Sergei Datsenko | c9904bb | 2020-12-11 12:46:02 +1100 | [diff] [blame] | 64 | protected: |
| 65 | std::unique_ptr<MountPoint> DoMount(const std::string& source_path, |
| 66 | const std::string& filesystem_type, |
| 67 | const std::vector<std::string>& options, |
| 68 | const base::FilePath& mount_path, |
Sergei Datsenko | c9904bb | 2020-12-11 12:46:02 +1100 | [diff] [blame] | 69 | MountErrorType* error) override; |
| 70 | |
| 71 | private: |
Sergei Datsenko | 87c49bb | 2021-01-13 15:08:07 +1100 | [diff] [blame] | 72 | friend class ArchiveManagerUnderTest; |
| 73 | |
| 74 | std::unique_ptr<FUSESandboxedProcessFactory> CreateSandboxFactory( |
| 75 | SandboxedExecutable executable, const std::string& user_name) const; |
| 76 | |
Sergei Datsenko | c9904bb | 2020-12-11 12:46:02 +1100 | [diff] [blame] | 77 | std::vector<std::unique_ptr<ArchiveMounter>> mounters_; |
Ben Chan | 8dcede8 | 2011-07-25 20:56:13 -0700 | [diff] [blame] | 78 | }; |
| 79 | |
| 80 | } // namespace cros_disks |
| 81 | |
| 82 | #endif // CROS_DISKS_ARCHIVE_MANAGER_H_ |