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:
Ben RUBSON 2018-03-17 17:58:04 +01:00 committed by rfjakob
parent 8caea461a7
commit e963664cae
4 changed files with 24 additions and 9 deletions

View File

@ -52,8 +52,8 @@ class DirDeleter {
}; };
DirTraverse::DirTraverse(std::shared_ptr<DIR> _dirPtr, uint64_t _iv, DirTraverse::DirTraverse(std::shared_ptr<DIR> _dirPtr, uint64_t _iv,
std::shared_ptr<NameIO> _naming) std::shared_ptr<NameIO> _naming, bool _root)
: dir(std::move(_dirPtr)), iv(_iv), naming(std::move(_naming)) {} : dir(std::move(_dirPtr)), iv(_iv), naming(std::move(_naming)), root(_root) {}
DirTraverse &DirTraverse::operator=(const DirTraverse &src) = default; DirTraverse &DirTraverse::operator=(const DirTraverse &src) = default;
@ -61,6 +61,7 @@ DirTraverse::~DirTraverse() {
dir.reset(); dir.reset();
iv = 0; iv = 0;
naming.reset(); naming.reset();
root = false;
} }
static bool _nextName(struct dirent *&de, const std::shared_ptr<DIR> &dir, 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) { std::string DirTraverse::nextPlaintextName(int *fileType, ino_t *inode) {
struct dirent *de = nullptr; struct dirent *de = nullptr;
while (_nextName(de, dir, fileType, inode)) { while (_nextName(de, dir, fileType, inode)) {
if (root && (strcmp(".encfs6.xml", de->d_name) == 0)) {
VLOG(1) << "skipping filename: " << de->d_name;
continue;
}
try { try {
uint64_t localIv = iv; uint64_t localIv = iv;
return naming->decodePath(de->d_name, &localIv); return naming->decodePath(de->d_name, &localIv);
@ -106,6 +111,10 @@ std::string DirTraverse::nextInvalid() {
struct dirent *de = nullptr; struct dirent *de = nullptr;
// find the first name which produces a decoding error... // find the first name which produces a decoding error...
while (_nextName(de, dir, (int *)nullptr, (ino_t *)nullptr)) { 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 { try {
uint64_t localIv = iv; uint64_t localIv = iv;
naming->decodePath(de->d_name, &localIv); naming->decodePath(de->d_name, &localIv);
@ -355,7 +364,7 @@ DirTraverse DirNode::openDir(const char *plaintextPath) {
if (dir == nullptr) { if (dir == nullptr) {
int eno = errno; int eno = errno;
VLOG(1) << "opendir error " << strerror(eno); 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()); std::shared_ptr<DIR> dp(dir, DirDeleter());
@ -369,7 +378,7 @@ DirTraverse DirNode::openDir(const char *plaintextPath) {
} catch (encfs::Error &err) { } catch (encfs::Error &err) {
RLOG(ERROR) << "encode err: " << err.what(); 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, bool DirNode::genRenameList(list<RenameEl> &renameList, const char *fromP,

View File

@ -49,7 +49,7 @@ struct RenameEl;
class DirTraverse { class DirTraverse {
public: public:
DirTraverse(std::shared_ptr<DIR> dirPtr, uint64_t iv, DirTraverse(std::shared_ptr<DIR> dirPtr, uint64_t iv,
std::shared_ptr<NameIO> naming); std::shared_ptr<NameIO> naming, bool root);
~DirTraverse(); ~DirTraverse();
DirTraverse &operator=(const DirTraverse &src); DirTraverse &operator=(const DirTraverse &src);
@ -74,6 +74,7 @@ class DirTraverse {
// more efficient to support filename IV chaining.. // more efficient to support filename IV chaining..
uint64_t iv; uint64_t iv;
std::shared_ptr<NameIO> naming; std::shared_ptr<NameIO> naming;
bool root;
}; };
inline bool DirTraverse::valid() const { return dir.get() != 0; } inline bool DirTraverse::valid() const { return dir.get() != 0; }

View File

@ -2,7 +2,7 @@
# Test EncFS normal and paranoid mode # Test EncFS normal and paranoid mode
use Test::More tests => 132; use Test::More tests => 136;
use File::Path; use File::Path;
use File::Copy; use File::Copy;
use File::Temp; use File::Temp;
@ -235,6 +235,11 @@ sub truncate
# Test file creation and removal # Test file creation and removal
sub fileCreation 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 # create a file
qx(date > "$crypt/df.txt"); qx(date > "$crypt/df.txt");
ok( -f "$crypt/df.txt", "file created" ) || BAIL_OUT("file create failed"); ok( -f "$crypt/df.txt", "file created" ) || BAIL_OUT("file create failed");

View File

@ -91,11 +91,11 @@ sub encName
return $enc; 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 sub copy_test
{ {
ok(system("cp -a encfs $plain")==0, "copying files to plain"); ok(system("cp -a encfs $plain && mkdir $plain/foo && touch $plain/foo/.encfs6.xml")==0, "copying files to plain");
ok(system("diff -r -q $plain $decrypted")==0, "decrypted files are identical"); ok(system("diff -r -q --exclude='.encfs6.xml' $plain $decrypted")==0, "decrypted files are identical");
ok(-f "$plain/encfs/encfs.cpp", "file exists"); ok(-f "$plain/encfs/encfs.cpp", "file exists");
unlink("$plain/encfs/encfs.cpp"); unlink("$plain/encfs/encfs.cpp");
ok(! -f "$decrypted/encfs.cpp", "file deleted"); ok(! -f "$decrypted/encfs.cpp", "file deleted");