Allow specifying base and mount directory parameters as relative paths

This commit is contained in:
Sebastian Messmer 2015-11-17 01:49:35 -08:00
parent 142881a70f
commit 49b4a9b1c0
5 changed files with 41 additions and 27 deletions

View File

@ -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.

View File

@ -14,6 +14,7 @@
#include "../filesystem/CryDevice.h"
#include "../config/CryConfigLoader.h"
#include "program_options/Parser.h"
#include <boost/filesystem.hpp>
#include <gitversion/version.h>
@ -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<OnDiskBlockStore>(bf::path(options.baseDir()));
auto blockStore = make_unique_ref<OnDiskBlockStore>(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<spdlog::sinks::simple_file_sink<std::mutex>>("cryfs", *options.logFile()));
spdlog::create<spdlog::sinks::simple_file_sink<std::mutex>>("cryfs", options.logFile()->native()));
} else if (options.foreground()) {
cpputils::logging::setLogger(spdlog::stderr_logger_mt("cryfs"));
} else {

View File

@ -4,6 +4,7 @@
#include <boost/optional.hpp>
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<string> &supportedCiphers) const {
pair<vector<char*>, vector<char*>> options = splitAtDoubleDash(_options);
po::variables_map vm = _parseOptionsOrShowHelp(options.first, supportedCiphers);
string baseDir = vm["base-dir"].as<string>();
string mountDir = vm["mount-dir"].as<string>();
optional<string> configfile = none;
bf::path baseDir = bf::canonical(vm["base-dir"].as<string>());
bf::path mountDir = bf::canonical(vm["mount-dir"].as<string>());
optional<bf::path> configfile = none;
if (vm.count("config")) {
configfile = vm["config"].as<string>();
configfile = bf::canonical(vm["config"].as<string>());
}
bool foreground = vm.count("foreground");
if (foreground) {
@ -43,9 +44,9 @@ ProgramOptions Parser::parse(const vector<string> &supportedCiphers) const {
if (vm.count("unmount-idle")) {
unmountAfterIdleMinutes = vm["unmount-idle"].as<double>();
}
optional<string> logfile = none;
optional<bf::path> logfile = none;
if (vm.count("logfile")) {
logfile = vm["logfile"].as<string>();
logfile = bf::canonical(vm["logfile"].as<string>());
}
optional<string> cipher = none;
if (vm.count("cipher")) {

View File

@ -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<string> &configFile,
ProgramOptions::ProgramOptions(const bf::path &baseDir, const bf::path &mountDir, const optional<bf::path> &configFile,
bool foreground, const optional<double> &unmountAfterIdleMinutes,
const optional<string> &logFile, const optional<string> &cipher,
const optional<bf::path> &logFile, const optional<string> &cipher,
const optional<string> &extPass, const vector<char*> &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<string> &ProgramOptions::configFile() const {
const optional<bf::path> &ProgramOptions::configFile() const {
return _configFile;
}
@ -54,7 +58,7 @@ const optional<double> &ProgramOptions::unmountAfterIdleMinutes() const {
return _unmountAfterIdleMinutes;
}
const optional<string> &ProgramOptions::logFile() const {
const optional<bf::path> &ProgramOptions::logFile() const {
return _logFile;
}

View File

@ -6,36 +6,39 @@
#include <string>
#include <boost/optional.hpp>
#include <messmer/cpp-utils/macros.h>
#include <boost/filesystem.hpp>
namespace cryfs {
namespace program_options {
class ProgramOptions final {
public:
ProgramOptions(const std::string &baseDir, const std::string &mountDir, const boost::optional<std::string> &configFile,
ProgramOptions(const boost::filesystem::path &baseDir, const boost::filesystem::path &mountDir,
const boost::optional<boost::filesystem::path> &configFile,
bool foreground, const boost::optional<double> &unmountAfterIdleMinutes,
const boost::optional<std::string> &logFile, const boost::optional<std::string> &cipher,
const boost::optional<std::string> &extPass, const std::vector<char *> &fuseOptions);
const boost::optional<boost::filesystem::path> &logFile,
const boost::optional<std::string> &cipher, const boost::optional<std::string> &extPass,
const std::vector<char *> &fuseOptions);
ProgramOptions(ProgramOptions &&rhs);
~ProgramOptions();
const std::string &baseDir() const;
std::string mountDir() const;
const boost::optional<std::string> &configFile() const;
const boost::filesystem::path &baseDir() const;
boost::filesystem::path mountDir() const;
const boost::optional<boost::filesystem::path> &configFile() const;
bool foreground() const;
const boost::optional<std::string> &cipher() const;
const boost::optional<double> &unmountAfterIdleMinutes() const;
const boost::optional<std::string> &logFile() const;
const boost::optional<boost::filesystem::path> &logFile() const;
const boost::optional<std::string> &extPass() const;
const std::vector<char *> &fuseOptions() const;
private:
std::string _baseDir;
boost::filesystem::path _baseDir;
char *_mountDir;
boost::optional<std::string> _configFile;
boost::optional<boost::filesystem::path> _configFile;
bool _foreground;
boost::optional<std::string> _cipher;
boost::optional<double> _unmountAfterIdleMinutes;
boost::optional<std::string> _logFile;
boost::optional<boost::filesystem::path> _logFile;
boost::optional<std::string> _extPass;
std::vector<char *> _fuseOptions;