mirror of
https://github.com/vgough/encfs.git
synced 2024-11-22 16:03:34 +01:00
Merge pull request #130 from rfjakob/issue112
Remove open_readonly_workaround
This commit is contained in:
commit
f0fdbd8fb0
@ -72,29 +72,6 @@ RawFileIO::~RawFileIO() {
|
||||
|
||||
rel::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.
|
||||
*/
|
||||
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 {
|
||||
rInfo("can't stat file %s", 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.
|
||||
@ -128,11 +105,6 @@ int RawFileIO::open(int flags) {
|
||||
|
||||
rDebug("open file with flags %i, result = %i", finalFlags, newFd);
|
||||
|
||||
if ((newFd == -1) && (errno == EACCES)) {
|
||||
rDebug("using readonly workaround for open");
|
||||
newFd = open_readonly_workaround(name.c_str(), finalFlags);
|
||||
}
|
||||
|
||||
if (newFd >= 0) {
|
||||
if (oldfd >= 0) {
|
||||
rError("leaking FD?: oldfd = %i, fd = %i, newfd = %i", oldfd, fd,
|
||||
|
Loading…
Reference in New Issue
Block a user