From 49b4a9b1c058d702aaddf2f6fdaa8f7c2e3da6d1 Mon Sep 17 00:00:00 2001 From: Sebastian Messmer Date: Tue, 17 Nov 2015 01:49:35 -0800 Subject: [PATCH] Allow specifying base and mount directory parameters as relative paths --- ChangeLog.txt | 4 ++++ src/cli/Cli.cpp | 6 ++++-- src/cli/program_options/Parser.cpp | 13 ++++++------ src/cli/program_options/ProgramOptions.cpp | 22 ++++++++++++--------- src/cli/program_options/ProgramOptions.h | 23 ++++++++++++---------- 5 files changed, 41 insertions(+), 27 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 2916081b..40c31cfd 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,3 +1,7 @@ +Version 0.8.2 +--------------- +* Mount directory and base directory can be specified as relative paths. + Version 0.8.1 --------------- * Config File Encryption: Configuration files are encrypted with two ciphers. The user specifies a password, which is then used with the scrypt KDF to generate the two encryption keys. diff --git a/src/cli/Cli.cpp b/src/cli/Cli.cpp index aacb5e15..2f048ee7 100644 --- a/src/cli/Cli.cpp +++ b/src/cli/Cli.cpp @@ -14,6 +14,7 @@ #include "../filesystem/CryDevice.h" #include "../config/CryConfigLoader.h" #include "program_options/Parser.h" +#include #include @@ -62,6 +63,7 @@ using boost::chrono::milliseconds; //TODO Improve parallelity. //TODO Did deadlock in bonnie++ second run (in the create files sequentially) - maybe also in a later run or different step? //TODO Replace ASSERTs with other error handling when it is not a programming error but an environment influence (e.g. a block is missing) +//TODO Biicode warning: Depend on cryptopp dev version? Should use release version! namespace cryfs { @@ -147,7 +149,7 @@ namespace cryfs { void Cli::_runFilesystem(const ProgramOptions &options) { try { - auto blockStore = make_unique_ref(bf::path(options.baseDir())); + auto blockStore = make_unique_ref(options.baseDir()); auto config = _loadOrCreateConfig(options); CryDevice device(std::move(config), std::move(blockStore)); fspp::FilesystemImpl fsimpl(&device); @@ -186,7 +188,7 @@ namespace cryfs { //TODO Test that --logfile parameter works. Should be: file if specified, otherwise stderr if foreground, else syslog. if (options.logFile() != none) { cpputils::logging::setLogger( - spdlog::create>("cryfs", *options.logFile())); + spdlog::create>("cryfs", options.logFile()->native())); } else if (options.foreground()) { cpputils::logging::setLogger(spdlog::stderr_logger_mt("cryfs")); } else { diff --git a/src/cli/program_options/Parser.cpp b/src/cli/program_options/Parser.cpp index 36775c96..7fe76d29 100644 --- a/src/cli/program_options/Parser.cpp +++ b/src/cli/program_options/Parser.cpp @@ -4,6 +4,7 @@ #include namespace po = boost::program_options; +namespace bf = boost::filesystem; using namespace cryfs::program_options; using std::pair; using std::vector; @@ -29,11 +30,11 @@ ProgramOptions Parser::parse(const vector &supportedCiphers) const { pair, vector> options = splitAtDoubleDash(_options); po::variables_map vm = _parseOptionsOrShowHelp(options.first, supportedCiphers); - string baseDir = vm["base-dir"].as(); - string mountDir = vm["mount-dir"].as(); - optional configfile = none; + bf::path baseDir = bf::canonical(vm["base-dir"].as()); + bf::path mountDir = bf::canonical(vm["mount-dir"].as()); + optional configfile = none; if (vm.count("config")) { - configfile = vm["config"].as(); + configfile = bf::canonical(vm["config"].as()); } bool foreground = vm.count("foreground"); if (foreground) { @@ -43,9 +44,9 @@ ProgramOptions Parser::parse(const vector &supportedCiphers) const { if (vm.count("unmount-idle")) { unmountAfterIdleMinutes = vm["unmount-idle"].as(); } - optional logfile = none; + optional logfile = none; if (vm.count("logfile")) { - logfile = vm["logfile"].as(); + logfile = bf::canonical(vm["logfile"].as()); } optional cipher = none; if (vm.count("cipher")) { diff --git a/src/cli/program_options/ProgramOptions.cpp b/src/cli/program_options/ProgramOptions.cpp index e77372fd..ec145aae 100644 --- a/src/cli/program_options/ProgramOptions.cpp +++ b/src/cli/program_options/ProgramOptions.cpp @@ -6,15 +6,19 @@ using namespace cryfs::program_options; using std::string; using std::vector; using boost::optional; +namespace bf = boost::filesystem; -ProgramOptions::ProgramOptions(const string &baseDir, const string &mountDir, const optional &configFile, +ProgramOptions::ProgramOptions(const bf::path &baseDir, const bf::path &mountDir, const optional &configFile, bool foreground, const optional &unmountAfterIdleMinutes, - const optional &logFile, const optional &cipher, + const optional &logFile, const optional &cipher, const optional &extPass, const vector &fuseOptions) - :_baseDir(baseDir), _mountDir(new char[mountDir.size()+1]), _configFile(configFile), _foreground(foreground), + :_baseDir(baseDir), _mountDir(nullptr), _configFile(configFile), _foreground(foreground), _cipher(cipher), _unmountAfterIdleMinutes(unmountAfterIdleMinutes), _logFile(logFile), _extPass(extPass), _fuseOptions(fuseOptions) { - std::memcpy(_mountDir, mountDir.c_str(), mountDir.size()+1); + + string mountDirStr = mountDir.native(); + _mountDir = new char[mountDirStr.size()+1]; + std::memcpy(_mountDir, mountDirStr.c_str(), mountDirStr.size()+1); // Fuse needs the mountDir passed as first option (first option = position 1, since 0 is the executable name) ASSERT(_fuseOptions.size() >= 1, "There has to be one parameter at least for the executable name"); _fuseOptions.insert(_fuseOptions.begin()+1, _mountDir); @@ -34,15 +38,15 @@ ProgramOptions::~ProgramOptions() { } } -const string &ProgramOptions::baseDir() const { +const bf::path &ProgramOptions::baseDir() const { return _baseDir; } -string ProgramOptions::mountDir() const { - return string(_mountDir); +bf::path ProgramOptions::mountDir() const { + return bf::path(_mountDir); } -const optional &ProgramOptions::configFile() const { +const optional &ProgramOptions::configFile() const { return _configFile; } @@ -54,7 +58,7 @@ const optional &ProgramOptions::unmountAfterIdleMinutes() const { return _unmountAfterIdleMinutes; } -const optional &ProgramOptions::logFile() const { +const optional &ProgramOptions::logFile() const { return _logFile; } diff --git a/src/cli/program_options/ProgramOptions.h b/src/cli/program_options/ProgramOptions.h index 1bca5756..32a86fe7 100644 --- a/src/cli/program_options/ProgramOptions.h +++ b/src/cli/program_options/ProgramOptions.h @@ -6,36 +6,39 @@ #include #include #include +#include namespace cryfs { namespace program_options { class ProgramOptions final { public: - ProgramOptions(const std::string &baseDir, const std::string &mountDir, const boost::optional &configFile, + ProgramOptions(const boost::filesystem::path &baseDir, const boost::filesystem::path &mountDir, + const boost::optional &configFile, bool foreground, const boost::optional &unmountAfterIdleMinutes, - const boost::optional &logFile, const boost::optional &cipher, - const boost::optional &extPass, const std::vector &fuseOptions); + const boost::optional &logFile, + const boost::optional &cipher, const boost::optional &extPass, + const std::vector &fuseOptions); ProgramOptions(ProgramOptions &&rhs); ~ProgramOptions(); - const std::string &baseDir() const; - std::string mountDir() const; - const boost::optional &configFile() const; + const boost::filesystem::path &baseDir() const; + boost::filesystem::path mountDir() const; + const boost::optional &configFile() const; bool foreground() const; const boost::optional &cipher() const; const boost::optional &unmountAfterIdleMinutes() const; - const boost::optional &logFile() const; + const boost::optional &logFile() const; const boost::optional &extPass() const; const std::vector &fuseOptions() const; private: - std::string _baseDir; + boost::filesystem::path _baseDir; char *_mountDir; - boost::optional _configFile; + boost::optional _configFile; bool _foreground; boost::optional _cipher; boost::optional _unmountAfterIdleMinutes; - boost::optional _logFile; + boost::optional _logFile; boost::optional _extPass; std::vector _fuseOptions;