Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore .encfs6.xml file in reverse mode #478

Merged
merged 5 commits into from
Mar 17, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions encfs/DirNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,16 @@ 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;

DirTraverse::~DirTraverse() {
dir.reset();
iv = 0;
naming.reset();
root = false;
}

static bool _nextName(struct dirent *&de, const std::shared_ptr<DIR> &dir,
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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());

Expand All @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion encfs/DirNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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; }

Expand Down
2 changes: 1 addition & 1 deletion integration/reverse.t.pl
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ sub encName
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("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");
Expand Down