Skip to content

Commit

Permalink
Merge pull request #9 from vanym/passfile
Browse files Browse the repository at this point in the history
Add passfile option
  • Loading branch information
andrew-grechkin committed Aug 14, 2023
2 parents e996095 + a5c8c28 commit 037570b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required (VERSION 3.12 FATAL_ERROR)

project (fuse3-p7zip
VERSION 1.2.0
VERSION 1.2.1
DESCRIPTION "fuse3 file system that uses the p7zip library to mount archives"
LANGUAGES CXX
)
Expand Down
24 changes: 17 additions & 7 deletions src/fuse3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "version.hpp"

#include <cstring>
#include <fstream>
#include <filesystem>
#include <map>
#include <memory>
Expand All @@ -31,10 +32,14 @@ struct Cache {

static struct cmd_params_t {
char* password = nullptr;
char* passfile = nullptr;
std::vector<std::string> cli_args;
} cmd_params;

static const fuse_opt opts_spec[] = {CMD_OPT("--password=%s", password), CMD_OPT("-p %s", password), FUSE_OPT_END};
static const fuse_opt opts_spec[] = {CMD_OPT("--password=%s", password), CMD_OPT("-p %s", password),
CMD_OPT("--passfile=%s", passfile), FUSE_OPT_END};

static std::string cmd_password;

class Fuse::Params: public fuse_cmdline_opts {
public:
Expand Down Expand Up @@ -62,10 +67,17 @@ Fuse::Params::Params(int argc, char** argv)

CheckResult(fuse_parse_cmdline(&args, this) == 0, "fuse_parse_cmdline");

if (!cmd_params.password) {
if (cmd_params.password) {
cmd_password = cmd_params.password;
} else if (cmd_params.passfile) {
std::ifstream passfile(cmd_params.passfile);
std::istreambuf_iterator it(passfile);
std::string pass(it, {});
cmd_password = pass;
} else {
auto password = std::getenv("FUSE3_P7ZIP_PASSWORD");
if (password) {
cmd_params.password = password;
cmd_password = password;
}
}

Expand All @@ -90,6 +102,7 @@ void Fuse::Params::print_usage()
printf("usage: fuse3-7z [options] <archive> <mountpoint>\n\n");
printf("Options:\n");
printf(" -p <password> provide password for protected archives\n");
printf(" --passfile <file> provide file with password for protected archives\n");
fuse_cmdline_help();
fuse_lib_help(&args);
exit(0);
Expand Down Expand Up @@ -232,10 +245,7 @@ const std::string& Fuse::path() const

std::string Fuse::password() const
{
if (cmd_params.password) {
return std::string(cmd_params.password);
}
return std::string();
return cmd_password;
}

ssize_t Fuse::execute(sevenzip::IArchive* arc)
Expand Down

0 comments on commit 037570b

Please sign in to comment.