Skip to content

Commit

Permalink
Merge pull request #7 from andrew-grechkin/agrechkin/add-password-sup…
Browse files Browse the repository at this point in the history
…port

feat: add support for password protected archives
  • Loading branch information
andrew-grechkin committed Apr 13, 2023
2 parents 3b44312 + 14139d0 commit 1c7b2b4
Show file tree
Hide file tree
Showing 20 changed files with 139 additions and 100 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.1.0
VERSION 1.2.0
DESCRIPTION "fuse3 file system that uses the p7zip library to mount archives"
LANGUAGES CXX
)
Expand Down
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
BUILD_TYPE ?= "Debug"
DIR = ".build-$(BUILD_TYPE)"

.PHONY: \
build

$(DIR):
mkdir -p "$(DIR)"

build:
@cmake -DCMAKE_BUILD_TYPE="$(BUILD_TYPE)" -S . -B "$(DIR)"
@make -j -C "$(DIR)" install

tidy:
@cp -f "$(shell git rev-parse --show-toplevel)/.clang-format" /tmp
@tidyall -a -j 4
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,22 @@ encoding `cp866` will be enforced for listing archived files/directories.

## Configuration

### Command line options

* -p <PASSWORD>

Provide a password which will be used if archive is protected with a password.

### Environment variables

* FUSE3_P7ZIP_LIBRARY

Change where application searches for 7z.so library. By default this is `/usr/lib/p7zip/7z.so`

* FUSE3_P7ZIP_PASSWORD

Provide a password which will be used if archive is protected with a password.

* FUSE3_P7ZIP_FORCE_ENCODING

Some archives (especially those ones created on windows) have file names encoded in non Unicode encoding. This
Expand Down Expand Up @@ -68,22 +78,22 @@ encoding `cp866` will be enforced for listing archived files/directories.

* FUSE3_P7ZIP_FORMATS

When opening a file application tries formats in alphabetical order. Sometimes it's desired to open a file with
format later in the list. This environment variable allows to override formats order.
When opening a file application tries all formats in the alphabetical order. Sometimes it's desired to open a file
with a format later in the list. This environment variable allows to override formats order.

for example (try open .iso file with Iso or Udf formats first and only fallback on APM and GPT formats)
```
FUSE3_P7ZIP_FORMATS="Iso:Udf:*:APM:GPT" fuse3-p7zip ubuntu-20.04-desktop-amd64.iso /tmp/mnt
```

To check list of available formats run `7z i` command
To check the list of all available formats run `7z i` command

## Examples

### vifm config snippet (mount 7zip supported archive with fuse3-p7zip in vifm)

```vim
filetype *.7z,*.zip,
filetype *.7z,
\*.dsl.dz,*.tar,*.a,*.so,lib*.so.*,*.zip,*.ova,*.sfs,
\*.apk,*.apm,*.ar,*.arj,*.cab,*.chm,*.cpio,*.cramfs,*.deb,*.dll,*.dmg,*.doc,*.esd,*.exe,
\*.flv,*.hxs,*.img,*.iso,*.iso,*.jar,*.lib,*.macho,*.msi,*.msp,*.nsis,*.pkg,*.pmd,*.ppt,
Expand Down
10 changes: 0 additions & 10 deletions build

This file was deleted.

37 changes: 0 additions & 37 deletions cmake/FindFUSE.cmake

This file was deleted.

29 changes: 23 additions & 6 deletions include/7zip.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifndef __FUSE3_7Z__7ZIP_HPP_
#ifndef __FUSE3_7Z__7ZIP_HPP_
#define __FUSE3_7Z__7ZIP_HPP_

#include <filesystem>
Expand Down Expand Up @@ -90,22 +90,39 @@ namespace sevenzip {
virtual bool notify_progress(uint64_t current, uint64_t of) const = 0;
};

class EmptyOpenCallback: public IOpenCallback {
class OpenCallback: public IOpenCallback {
public:
OpenCallback(std::string password = std::string())
: _password(password)
{}

std::string request_password() const override
{
return std::string();
return _password;
}

private:
std::string _password;
};

class EmptyExtractCallback: public IExtractCallback {
class ExtractCallback: public IExtractCallback {
public:
ExtractCallback(std::string password = std::string())
: _password(password)
{}

std::string request_password() const override
{
return std::string();
return _password;
}

bool notify_progress(uint64_t, uint64_t) const override
{
return true;
}

private:
std::string _password;
};

class IFile {
Expand Down Expand Up @@ -167,7 +184,7 @@ namespace sevenzip {
bool is_file() const;
bool is_dir() const;

File extract(const IExtractCallback& callback = EmptyExtractCallback()) const;
File extract(const IExtractCallback& callback) const;

size_t get_props_count() const;

Expand Down
2 changes: 1 addition & 1 deletion include/pattern.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace pattern {

class Uncopyable {
public:
Uncopyable(const Uncopyable&) = delete;
Uncopyable(const Uncopyable&) = delete;
Uncopyable& operator=(const Uncopyable&) = delete;

protected:
Expand Down
4 changes: 3 additions & 1 deletion include/string.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifndef __FUSE3_7Z__STRING_HPP_
#ifndef __FUSE3_7Z__STRING_HPP_
#define __FUSE3_7Z__STRING_HPP_

#include <string>
Expand All @@ -10,6 +10,8 @@ std::string utf8(const wchar_t* str);

std::string utf8(const char* str, const char* encoding);

std::wstring wide_str(const char* str);

std::vector<std::string> split(const std::string& d, std::string str);

#endif
8 changes: 4 additions & 4 deletions src/7zip/Archive.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "7zip-impl.hpp"
#include "7zip-impl.hpp"
#include "exception.hpp"
#include "string.hpp"
#include "logger.hpp"
Expand Down Expand Up @@ -103,10 +103,10 @@ namespace sevenzip {
return ret;
}

HRESULT WINAPI ImplArchive::CryptoGetTextPassword(BSTR* password)
HRESULT WINAPI ImplArchive::CryptoGetTextPassword(BSTR* pass)
{
// std::string ret = callback.request_password();
// com::BStr(ret).detach(*password);
LogDebug("%s %p", __PRETTY_FUNCTION__, pass);
*pass = SysAllocString(wide_str(callback.request_password().c_str()).c_str());
return S_OK;
}

Expand Down
10 changes: 5 additions & 5 deletions src/7zip/ArchiveExtractor.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "7zip-impl.hpp"
#include "7zip-impl.hpp"
#include "exception.hpp"
#include "logger.hpp"
#include "string.hpp"

namespace sevenzip {
ULONG WINAPI ImplArchiveExtractor::AddRef()
Expand Down Expand Up @@ -52,7 +53,7 @@ namespace sevenzip {

HRESULT WINAPI ImplArchiveExtractor::SetCompleted(const UInt64* completeValue)
{
LogDebug("%s: %p", __PRETTY_FUNCTION__, completeValue);
LogDebug("%s: %p %llu", __PRETTY_FUNCTION__, completeValue, *completeValue);
HRESULT ret = S_OK;

if (completeValue) ret = callback.notify_progress(*completeValue, total) == true ? S_OK : S_FALSE;
Expand Down Expand Up @@ -128,9 +129,8 @@ namespace sevenzip {

HRESULT WINAPI ImplArchiveExtractor::CryptoGetTextPassword(BSTR* pass)
{
LogDebug("%s: %p", __PRETTY_FUNCTION__, pass);
//ustring ret = callback.request_password();
//com::BStr(ret).detach(*pass);
LogDebug("%s %p", __PRETTY_FUNCTION__, pass);
*pass = SysAllocString(wide_str(callback.request_password().c_str()).c_str());
return S_OK;
}

Expand Down
3 changes: 1 addition & 2 deletions src/7zip/Format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
#include <cstring>

namespace sevenzip {
struct Guid: public GUID {
};
struct Guid: public GUID {};

class ImplFormat: public IFormat {
public:
Expand Down
3 changes: 1 addition & 2 deletions src/7zip/ReadStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
#include "exception.hpp"

namespace sevenzip {
class FileReadStream::FileHandle: public std::FILE {
};
class FileReadStream::FileHandle: public std::FILE {};

HRESULT check_error(FileReadStream::FileHandle* file)
{
Expand Down
3 changes: 1 addition & 2 deletions src/7zip/WriteStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
#include "logger.hpp"

namespace sevenzip {
class FileWriteStream::FileHandle: public std::FILE {
};
class FileWriteStream::FileHandle: public std::FILE {};

HRESULT check_error(FileWriteStream::FileHandle* file)
{
Expand Down
Loading

0 comments on commit 1c7b2b4

Please sign in to comment.