mirror of
https://github.com/vgough/encfs.git
synced 2024-11-25 01:13:12 +01:00
Revert "Remove open_readonly_workaround"
Caused a regression: https://github.com/vgough/encfs/issues/181
Without this, "umask 0777 ; echo foo > bar" fails.
This reverts commit c2e046b694
.
This commit is contained in:
parent
2b3e6031eb
commit
4a691dc0bb
@ -75,6 +75,32 @@ RawFileIO::~RawFileIO() {
|
||||
|
||||
Interface RawFileIO::interface() const { return RawFileIO_iface; }
|
||||
|
||||
/*
|
||||
Workaround for opening a file for write when permissions don't allow.
|
||||
Since the kernel has already checked permissions, we can assume it is ok to
|
||||
provide access. So force it by changing permissions temporarily. Should
|
||||
be called with a lock around it so that there won't be a race condition
|
||||
with calls to lstat picking up the wrong permissions.
|
||||
|
||||
This works around the problem described in https://github.com/vgough/encfs/issues/181
|
||||
Without this, "umask 0777 ; echo foo > bar" fails.
|
||||
*/
|
||||
static int open_readonly_workaround(const char *path, int flags) {
|
||||
int fd = -1;
|
||||
struct stat stbuf;
|
||||
memset(&stbuf, 0, sizeof(struct stat));
|
||||
if (lstat(path, &stbuf) != -1) {
|
||||
// make sure user has read/write permission..
|
||||
chmod(path, stbuf.st_mode | 0600);
|
||||
fd = ::open(path, flags);
|
||||
chmod(path, stbuf.st_mode);
|
||||
} else {
|
||||
RLOG(INFO) << "can't stat file " << path;
|
||||
}
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
/*
|
||||
We shouldn't have to support all possible open flags, so untaint the flags
|
||||
argument by only taking ones we understand and accept.
|
||||
@ -107,6 +133,11 @@ int RawFileIO::open(int flags) {
|
||||
|
||||
VLOG(1) << "open file with flags " << finalFlags << ", result = " << newFd;
|
||||
|
||||
if ((newFd == -1) && (errno == EACCES)) {
|
||||
VLOG(1) << "using readonly workaround for open";
|
||||
newFd = open_readonly_workaround(name.c_str(), finalFlags);
|
||||
}
|
||||
|
||||
if (newFd >= 0) {
|
||||
if (oldfd >= 0) {
|
||||
RLOG(ERROR) << "leaking FD?: oldfd = " << oldfd << ", fd = " << fd
|
||||
|
Loading…
Reference in New Issue
Block a user