mirror of
https://github.com/vgough/encfs.git
synced 2024-11-21 23:43:26 +01:00
Ignore .encfs6.xml file in reverse mode (#478)
* Ignore .encfs6.xml file in reverse mode * Update reverse tests * Add test cases
This commit is contained in:
parent
8caea461a7
commit
e963664cae
@ -52,8 +52,8 @@ class DirDeleter {
|
||||
};
|
||||
|
||||
DirTraverse::DirTraverse(std::shared_ptr<DIR> _dirPtr, uint64_t _iv,
|
||||
std::shared_ptr<NameIO> _naming)
|
||||
: dir(std::move(_dirPtr)), iv(_iv), naming(std::move(_naming)) {}
|
||||
std::shared_ptr<NameIO> _naming, bool _root)
|
||||
: dir(std::move(_dirPtr)), iv(_iv), naming(std::move(_naming)), root(_root) {}
|
||||
|
||||
DirTraverse &DirTraverse::operator=(const DirTraverse &src) = default;
|
||||
|
||||
@ -61,6 +61,7 @@ DirTraverse::~DirTraverse() {
|
||||
dir.reset();
|
||||
iv = 0;
|
||||
naming.reset();
|
||||
root = false;
|
||||
}
|
||||
|
||||
static bool _nextName(struct dirent *&de, const std::shared_ptr<DIR> &dir,
|
||||
@ -90,6 +91,10 @@ static bool _nextName(struct dirent *&de, const std::shared_ptr<DIR> &dir,
|
||||
std::string DirTraverse::nextPlaintextName(int *fileType, ino_t *inode) {
|
||||
struct dirent *de = nullptr;
|
||||
while (_nextName(de, dir, fileType, inode)) {
|
||||
if (root && (strcmp(".encfs6.xml", de->d_name) == 0)) {
|
||||
VLOG(1) << "skipping filename: " << de->d_name;
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
uint64_t localIv = iv;
|
||||
return naming->decodePath(de->d_name, &localIv);
|
||||
@ -106,6 +111,10 @@ std::string DirTraverse::nextInvalid() {
|
||||
struct dirent *de = nullptr;
|
||||
// find the first name which produces a decoding error...
|
||||
while (_nextName(de, dir, (int *)nullptr, (ino_t *)nullptr)) {
|
||||
if (root && (strcmp(".encfs6.xml", de->d_name) == 0)) {
|
||||
VLOG(1) << "skipping filename: " << de->d_name;
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
uint64_t localIv = iv;
|
||||
naming->decodePath(de->d_name, &localIv);
|
||||
@ -355,7 +364,7 @@ DirTraverse DirNode::openDir(const char *plaintextPath) {
|
||||
if (dir == nullptr) {
|
||||
int eno = errno;
|
||||
VLOG(1) << "opendir error " << strerror(eno);
|
||||
return DirTraverse(shared_ptr<DIR>(), 0, std::shared_ptr<NameIO>());
|
||||
return DirTraverse(shared_ptr<DIR>(), 0, std::shared_ptr<NameIO>(), false);
|
||||
}
|
||||
std::shared_ptr<DIR> dp(dir, DirDeleter());
|
||||
|
||||
@ -369,7 +378,7 @@ DirTraverse DirNode::openDir(const char *plaintextPath) {
|
||||
} catch (encfs::Error &err) {
|
||||
RLOG(ERROR) << "encode err: " << err.what();
|
||||
}
|
||||
return DirTraverse(dp, iv, naming);
|
||||
return DirTraverse(dp, iv, naming, (strlen(plaintextPath) == 1));
|
||||
}
|
||||
|
||||
bool DirNode::genRenameList(list<RenameEl> &renameList, const char *fromP,
|
||||
|
@ -49,7 +49,7 @@ struct RenameEl;
|
||||
class DirTraverse {
|
||||
public:
|
||||
DirTraverse(std::shared_ptr<DIR> dirPtr, uint64_t iv,
|
||||
std::shared_ptr<NameIO> naming);
|
||||
std::shared_ptr<NameIO> naming, bool root);
|
||||
~DirTraverse();
|
||||
|
||||
DirTraverse &operator=(const DirTraverse &src);
|
||||
@ -74,6 +74,7 @@ class DirTraverse {
|
||||
// more efficient to support filename IV chaining..
|
||||
uint64_t iv;
|
||||
std::shared_ptr<NameIO> naming;
|
||||
bool root;
|
||||
};
|
||||
inline bool DirTraverse::valid() const { return dir.get() != 0; }
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
# Test EncFS normal and paranoid mode
|
||||
|
||||
use Test::More tests => 132;
|
||||
use Test::More tests => 136;
|
||||
use File::Path;
|
||||
use File::Copy;
|
||||
use File::Temp;
|
||||
@ -235,6 +235,11 @@ sub truncate
|
||||
# Test file creation and removal
|
||||
sub fileCreation
|
||||
{
|
||||
# first be sure .encfs6.xml does not show up
|
||||
my $f = encName(".encfs6.xml");
|
||||
cmp_ok( length($f), '>', 8, "encrypted name ok" );
|
||||
ok( ! -f "$raw/$f", "configuration file .encfs6.xml not visible in $raw" );
|
||||
|
||||
# create a file
|
||||
qx(date > "$crypt/df.txt");
|
||||
ok( -f "$crypt/df.txt", "file created" ) || BAIL_OUT("file create failed");
|
||||
|
@ -91,11 +91,11 @@ sub encName
|
||||
return $enc;
|
||||
}
|
||||
|
||||
# Copy a directory tree and verify that the decrypted data is identical
|
||||
# Copy a directory tree and verify that the decrypted data is identical, we also create a foo/.encfs6.xml file, to be sure it correctly shows-up
|
||||
sub copy_test
|
||||
{
|
||||
ok(system("cp -a encfs $plain")==0, "copying files to plain");
|
||||
ok(system("diff -r -q $plain $decrypted")==0, "decrypted files are identical");
|
||||
ok(system("cp -a encfs $plain && mkdir $plain/foo && touch $plain/foo/.encfs6.xml")==0, "copying files to plain");
|
||||
ok(system("diff -r -q --exclude='.encfs6.xml' $plain $decrypted")==0, "decrypted files are identical");
|
||||
ok(-f "$plain/encfs/encfs.cpp", "file exists");
|
||||
unlink("$plain/encfs/encfs.cpp");
|
||||
ok(! -f "$decrypted/encfs.cpp", "file deleted");
|
||||
|
Loading…
Reference in New Issue
Block a user