Skip to content

Commit

Permalink
Upstream patch: Ignore .encfs6.xml file in reverse mode (vgough#478)
Browse files Browse the repository at this point in the history
* Ignore .encfs6.xml file in reverse mode

# Conflicts:
#	encfs/DirNode.cpp
#	encfs/DirNode.h
#	integration/normal.t.pl
#	integration/reverse.t.pl
  • Loading branch information
jetwhiz committed Jan 26, 2019
1 parent 7154b00 commit 9d98326
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
22 changes: 16 additions & 6 deletions encfs/DirNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ class DirDeleter {
};

DirTraverse::DirTraverse(const std::shared_ptr<unix::DIR> &_dirPtr, uint64_t _iv,
const std::shared_ptr<NameIO> &_naming)
: dir(_dirPtr), iv(_iv), naming(_naming) {}
const std::shared_ptr<NameIO> &_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) {}
Expand All @@ -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<unix::DIR> &dir,
Expand Down Expand Up @@ -98,6 +99,10 @@ static bool _nextName(struct unix::dirent *&de, const std::shared_ptr<unix::DIR>
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);
Expand All @@ -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);
Expand Down Expand Up @@ -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<unix::DIR>(), 0, std::shared_ptr<NameIO>());
int eno = errno;
VLOG(1) << "opendir error " << strerror(eno);
return DirTraverse(shared_ptr<unix::DIR>(), 0, std::shared_ptr<NameIO>(), false);
} else {
std::shared_ptr<unix::DIR> dp(dir, DirDeleter());

Expand All @@ -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));
}
}

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(const std::shared_ptr<unix::DIR> &dirPtr, uint64_t iv,
const std::shared_ptr<NameIO> &naming);
const std::shared_ptr<NameIO> &naming, bool root);
DirTraverse(const DirTraverse &src);
~DirTraverse();

Expand All @@ -75,6 +75,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

0 comments on commit 9d98326

Please sign in to comment.