From b214be5e3f76dd17efc9832131f4a7e0414b4cea Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Wed, 2 Jan 2019 20:48:46 +0100 Subject: fusefrontend: xattr: fix operations on files without read permissions * listxattr is fixed via the /proc/self/fd trick * setxattr,removexattr are fixed by opening the file O_WRONLY Fixes https://github.com/rfjakob/gocryptfs/issues/308 --- internal/fusefrontend/fs.go | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'internal/fusefrontend/fs.go') diff --git a/internal/fusefrontend/fs.go b/internal/fusefrontend/fs.go index e7c3903..5c52a19 100644 --- a/internal/fusefrontend/fs.go +++ b/internal/fusefrontend/fs.go @@ -160,6 +160,17 @@ func (fs *FS) Open(path string, flags uint32, context *fuse.Context) (fuseFile n return NewFile(f, fs) } +// openBackingFile opens the ciphertext file that backs relative plaintext +// path "relPath". Always adds O_NOFOLLOW to the flags. +func (fs *FS) openBackingFile(relPath string, flags int) (fd int, err error) { + dirfd, cName, err := fs.openBackingDir(relPath) + if err != nil { + return -1, err + } + defer syscall.Close(dirfd) + return syscallcompat.Openat(dirfd, cName, flags|syscall.O_NOFOLLOW, 0) +} + // Due to RMW, we always need read permissions on the backing file. This is a // problem if the file permissions do not allow reading (i.e. 0200 permissions). // This function works around that problem by chmod'ing the file, obtaining a fd, -- cgit v1.2.3