blob: 96cbec1e27fc40b420bd2538f0e8a5938f5b6313 [file] [log] [blame]
Ben Chancb517732012-04-11 17:00:00 -07001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Ben Chan8dcede82011-07-25 20:56:13 -07002// 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 Chancb517732012-04-11 17:00:00 -07008#include <map>
Anand K Mistry29fee842020-01-15 15:49:48 +11009#include <memory>
Ben Chan8dcede82011-07-25 20:56:13 -070010#include <string>
11#include <vector>
12
François Degrosf76886e2020-07-24 18:13:40 +100013#include <brillo/scoped_mount_namespace.h>
Ben Chan8dcede82011-07-25 20:56:13 -070014#include <gtest/gtest_prod.h>
15
Sergei Datsenko87c49bb2021-01-13 15:08:07 +110016#include "cros-disks/fuse_mounter.h"
Ben Chan5ccd9fe2013-11-13 18:28:27 -080017#include "cros-disks/mount_manager.h"
François Degrosf76886e2020-07-24 18:13:40 +100018#include "cros-disks/mount_options.h"
Ben Chan8dcede82011-07-25 20:56:13 -070019
20namespace cros_disks {
21
Sergei Datsenkoc9904bb2020-12-11 12:46:02 +110022class ArchiveMounter;
23
Ben Chan8dcede82011-07-25 20:56:13 -070024// A derived class of MountManager for mounting archive files as a virtual
25// filesystem.
26class ArchiveManager : public MountManager {
27 public:
Sergei Datsenkoc9904bb2020-12-11 12:46:02 +110028 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 Chan8dcede82011-07-25 20:56:13 -070036
François Degros7f7a4162020-06-13 00:13:00 +100037 // MountManager overrides
Sergei Datsenkoc9904bb2020-12-11 12:46:02 +110038 bool Initialize() override;
39
François Degros7f7a4162020-06-13 00:13:00 +100040 MountSourceType GetMountSourceType() const final {
Ben Chan6d0b2722011-11-18 08:24:14 -080041 return MOUNT_SOURCE_ARCHIVE;
Ben Chan8dcede82011-07-25 20:56:13 -070042 }
43
François Degrosf76886e2020-07-24 18:13:40 +100044 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 Degros7f7a4162020-06-13 00:13:00 +100048 // 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 Degros853c7d92020-02-17 10:32:21 +110057
François Degrosf76886e2020-07-24 18:13:40 +100058 // 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 Chan8dcede82011-07-25 20:56:13 -070061
Sergei Datsenkoc9904bb2020-12-11 12:46:02 +110062 bool CanMount(const std::string& source_path) const override;
François Degrosf76886e2020-07-24 18:13:40 +100063
Sergei Datsenkoc9904bb2020-12-11 12:46:02 +110064 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 Datsenkoc9904bb2020-12-11 12:46:02 +110069 MountErrorType* error) override;
70
71 private:
Sergei Datsenko87c49bb2021-01-13 15:08:07 +110072 friend class ArchiveManagerUnderTest;
73
74 std::unique_ptr<FUSESandboxedProcessFactory> CreateSandboxFactory(
75 SandboxedExecutable executable, const std::string& user_name) const;
76
Sergei Datsenkoc9904bb2020-12-11 12:46:02 +110077 std::vector<std::unique_ptr<ArchiveMounter>> mounters_;
Ben Chan8dcede82011-07-25 20:56:13 -070078};
79
80} // namespace cros_disks
81
82#endif // CROS_DISKS_ARCHIVE_MANAGER_H_