From 9d98326cde3bacb41e5af43f38727cd64322f9cd Mon Sep 17 00:00:00 2001 From: Charles Munson Date: Sat, 26 Jan 2019 18:43:21 -0500 Subject: [PATCH] Upstream patch: Ignore .encfs6.xml file in reverse mode (#478) * Ignore .encfs6.xml file in reverse mode # Conflicts: # encfs/DirNode.cpp # encfs/DirNode.h # integration/normal.t.pl # integration/reverse.t.pl --- encfs/DirNode.cpp | 22 ++++++++++++++++------ encfs/DirNode.h | 3 ++- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/encfs/DirNode.cpp b/encfs/DirNode.cpp index 7a004a45..2adafb81 100644 --- a/encfs/DirNode.cpp +++ b/encfs/DirNode.cpp @@ -52,8 +52,8 @@ class DirDeleter { }; DirTraverse::DirTraverse(const std::shared_ptr &_dirPtr, uint64_t _iv, - const std::shared_ptr &_naming) - : dir(_dirPtr), iv(_iv), naming(_naming) {} + const std::shared_ptr &_naming, bool _root) + : dir(_dirPtr), iv(_iv), naming(_naming), root(_root) {} DirTraverse::DirTraverse(const DirTraverse &src) : dir(src.dir), iv(src.iv), naming(src.naming) {} @@ -70,6 +70,7 @@ DirTraverse::~DirTraverse() { dir.reset(); iv = 0; naming.reset(); + root = false; } static bool _nextName(struct unix::dirent *&de, const std::shared_ptr &dir, @@ -98,6 +99,10 @@ static bool _nextName(struct unix::dirent *&de, const std::shared_ptr std::string DirTraverse::nextPlaintextName(int *fileType, ino_t *inode) { struct unix::dirent *de = 0; 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); @@ -113,7 +118,11 @@ std::string DirTraverse::nextPlaintextName(int *fileType, ino_t *inode) { std::string DirTraverse::nextInvalid() { struct unix::dirent *de = 0; // find the first name which produces a decoding error... - while (_nextName(de, dir, (int *)0, (ino_t *)0)) { + 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); @@ -364,8 +373,9 @@ DirTraverse DirNode::openDir(const char *plaintextPath) { unix::DIR *dir = unix::opendir(cyName.c_str()); if (dir == NULL) { - VLOG(1) << "opendir error " << strerror(errno); - return DirTraverse(shared_ptr(), 0, std::shared_ptr()); + int eno = errno; + VLOG(1) << "opendir error " << strerror(eno); + return DirTraverse(shared_ptr(), 0, std::shared_ptr(), false); } else { std::shared_ptr dp(dir, DirDeleter()); @@ -377,7 +387,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)); } } diff --git a/encfs/DirNode.h b/encfs/DirNode.h index 2f6e87fd..5e8717f8 100644 --- a/encfs/DirNode.h +++ b/encfs/DirNode.h @@ -49,7 +49,7 @@ struct RenameEl; class DirTraverse { public: DirTraverse(const std::shared_ptr &dirPtr, uint64_t iv, - const std::shared_ptr &naming); + const std::shared_ptr &naming, bool root); DirTraverse(const DirTraverse &src); ~DirTraverse(); @@ -75,6 +75,7 @@ class DirTraverse { // more efficient to support filename IV chaining.. uint64_t iv; std::shared_ptr naming; + bool root; }; inline bool DirTraverse::valid() const { return dir.get() != 0; }