diff --git a/src/cryfs-cli/Cli.cpp b/src/cryfs-cli/Cli.cpp index f1df595e..c7fe0bad 100644 --- a/src/cryfs-cli/Cli.cpp +++ b/src/cryfs-cli/Cli.cpp @@ -316,10 +316,17 @@ namespace cryfs { } } - void Cli::_sanityChecks(const ProgramOptions &options) { - _checkDirAccessible(options.baseDir(), "base directory", ErrorCode::InaccessibleBaseDir); - _checkDirAccessible(options.mountDir(), "mount directory", ErrorCode::InaccessibleMountDir); - _checkMountdirDoesntContainBasedir(options); + void Cli::_sanityChecks(const ProgramOptions &options) { + _checkDirAccessible(bf::absolute(options.baseDir()), "base directory", ErrorCode::InaccessibleBaseDir); + + if (!options.mountDirIsDriveLetter()) { + _checkDirAccessible(options.mountDir(), "mount directory", ErrorCode::InaccessibleMountDir); + _checkMountdirDoesntContainBasedir(options); + } else { + if (bf::exists(options.mountDir())) { + throw CryfsException("Drive " + options.mountDir().string() + " already exists.", ErrorCode::InaccessibleMountDir); + } + } } void Cli::_checkDirAccessible(const bf::path &dir, const std::string &name, ErrorCode errorCode) { diff --git a/src/cryfs-cli/program_options/Parser.cpp b/src/cryfs-cli/program_options/Parser.cpp index 89a6042f..54ebf1b4 100644 --- a/src/cryfs-cli/program_options/Parser.cpp +++ b/src/cryfs-cli/program_options/Parser.cpp @@ -49,8 +49,8 @@ ProgramOptions Parser::parse(const vector &supportedCiphers) const { if (!vm.count("mount-dir")) { _showHelpAndExit("Please specify a mount directory.", ErrorCode::InvalidArguments); } - bf::path baseDir = bf::absolute(vm["base-dir"].as()); - bf::path mountDir = bf::absolute(vm["mount-dir"].as()); + bf::path baseDir = vm["base-dir"].as(); + bf::path mountDir = vm["mount-dir"].as(); optional configfile = none; if (vm.count("config")) { configfile = bf::absolute(vm["config"].as()); diff --git a/src/cryfs-cli/program_options/ProgramOptions.cpp b/src/cryfs-cli/program_options/ProgramOptions.cpp index 94ba6fc8..ccf25b87 100644 --- a/src/cryfs-cli/program_options/ProgramOptions.cpp +++ b/src/cryfs-cli/program_options/ProgramOptions.cpp @@ -15,9 +15,19 @@ ProgramOptions::ProgramOptions(bf::path baseDir, bf::path mountDir, optional missingBlockIsIntegrityViolation, vector fuseOptions) - :_baseDir(std::move(baseDir)), _mountDir(std::move(mountDir)), _configFile(std::move(configFile)), _foreground(foreground), _allowFilesystemUpgrade(allowFilesystemUpgrade), _allowReplacedFilesystem(allowReplacedFilesystem), _allowIntegrityViolations(allowIntegrityViolations), - _cipher(std::move(cipher)), _blocksizeBytes(std::move(blocksizeBytes)), _unmountAfterIdleMinutes(std::move(unmountAfterIdleMinutes)), - _missingBlockIsIntegrityViolation(std::move(missingBlockIsIntegrityViolation)), _logFile(std::move(logFile)), _fuseOptions(std::move(fuseOptions)) { + : _configFile(std::move(configFile)), _baseDir(bf::absolute(std::move(baseDir))), _mountDir(std::move(mountDir)), +#if defined(_MSC_VER) + _mountDirIsDriveLetter(_mountDir.has_root_path() && !_mountDir.has_root_directory() && !_mountDir.has_parent_path()), +#else + _mountDirIsDriveLetter(false), +#endif + _foreground(foreground), + _allowFilesystemUpgrade(allowFilesystemUpgrade), _allowReplacedFilesystem(allowReplacedFilesystem), _allowIntegrityViolations(allowIntegrityViolations), + _cipher(std::move(cipher)), _blocksizeBytes(std::move(blocksizeBytes)), _unmountAfterIdleMinutes(std::move(unmountAfterIdleMinutes)), + _missingBlockIsIntegrityViolation(std::move(missingBlockIsIntegrityViolation)), _logFile(std::move(logFile)), _fuseOptions(std::move(fuseOptions)) { + if (!_mountDirIsDriveLetter) { + _mountDir = bf::absolute(std::move(_mountDir)); + } } const bf::path &ProgramOptions::baseDir() const { @@ -28,6 +38,10 @@ const bf::path &ProgramOptions::mountDir() const { return _mountDir; } +bool ProgramOptions::mountDirIsDriveLetter() const { + return _mountDirIsDriveLetter; +} + const optional &ProgramOptions::configFile() const { return _configFile; } diff --git a/src/cryfs-cli/program_options/ProgramOptions.h b/src/cryfs-cli/program_options/ProgramOptions.h index f592db63..545fea0c 100644 --- a/src/cryfs-cli/program_options/ProgramOptions.h +++ b/src/cryfs-cli/program_options/ProgramOptions.h @@ -25,6 +25,7 @@ namespace cryfs { const boost::filesystem::path &baseDir() const; const boost::filesystem::path &mountDir() const; + bool mountDirIsDriveLetter() const; const boost::optional &configFile() const; bool foreground() const; bool allowFilesystemUpgrade() const; @@ -38,9 +39,10 @@ namespace cryfs { const std::vector &fuseOptions() const; private: - boost::filesystem::path _baseDir; - boost::filesystem::path _mountDir; - boost::optional _configFile; + boost::optional _configFile; + boost::filesystem::path _baseDir; // this is always absolute + boost::filesystem::path _mountDir; // this is absolute iff !_mountDirIsDriveLetter + bool _mountDirIsDriveLetter; bool _foreground; bool _allowFilesystemUpgrade; bool _allowReplacedFilesystem;