diff options
author | Sebastian Lackner | 2017-11-29 13:05:46 +0100 |
---|---|---|
committer | Sebastian Lackner | 2017-11-29 13:05:46 +0100 |
commit | 67bcbe81e80da29fb340c5a4712831f70442d8c9 (patch) | |
tree | bded6eb0a2536c943f5840cf79883c814a77e21d /internal/fusefrontend/fs.go | |
parent | 0162392a28b75ccb6c3b26c26f2a83b5973a2d92 (diff) |
fusefrontend: Use Fchownat to implement Chown
Diffstat (limited to 'internal/fusefrontend/fs.go')
-rw-r--r-- | internal/fusefrontend/fs.go | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/internal/fusefrontend/fs.go b/internal/fusefrontend/fs.go index c4035fa..d6467f9 100644 --- a/internal/fusefrontend/fs.go +++ b/internal/fusefrontend/fs.go @@ -255,21 +255,22 @@ func (fs *FS) Chown(path string, uid uint32, gid uint32, context *fuse.Context) if fs.isFiltered(path) { return fuse.EPERM } - cPath, err := fs.getBackingPath(path) + dirfd, cName, err := fs.openBackingPath(path) if err != nil { return fuse.ToStatus(err) } - code = fuse.ToStatus(os.Lchown(cPath, int(uid), int(gid))) + defer dirfd.Close() + code = fuse.ToStatus(syscallcompat.Fchownat(int(dirfd.Fd()), cName, int(uid), int(gid), unix.AT_SYMLINK_NOFOLLOW)) if !code.Ok() { return code } if !fs.args.PlaintextNames { // When filename encryption is active, every directory contains // a "gocryptfs.diriv" file. This file should also change the owner. - // Instead of checking if "cPath" is a directory, we just blindly - // execute the Lchown on "cPath/gocryptfs.diriv" and ignore errors. - dirIVPath := filepath.Join(cPath, nametransform.DirIVFilename) - os.Lchown(dirIVPath, int(uid), int(gid)) + // Instead of checking if "cName" is a directory, we just blindly + // execute the chown on "cName/gocryptfs.diriv" and ignore errors. + dirIVPath := filepath.Join(cName, nametransform.DirIVFilename) + syscallcompat.Fchownat(int(dirfd.Fd()), dirIVPath, int(uid), int(gid), unix.AT_SYMLINK_NOFOLLOW) } return fuse.OK } |