fusefrontend: Use Fchownat to implement Chown

This commit is contained in:
Sebastian Lackner 2017-11-29 13:05:46 +01:00
parent 0162392a28
commit 67bcbe81e8
1 changed files with 7 additions and 6 deletions

View File

@ -255,21 +255,22 @@ func (fs *FS) Chown(path string, uid uint32, gid uint32, context *fuse.Context)
if fs.isFiltered(path) { if fs.isFiltered(path) {
return fuse.EPERM return fuse.EPERM
} }
cPath, err := fs.getBackingPath(path) dirfd, cName, err := fs.openBackingPath(path)
if err != nil { if err != nil {
return fuse.ToStatus(err) 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() { if !code.Ok() {
return code return code
} }
if !fs.args.PlaintextNames { if !fs.args.PlaintextNames {
// When filename encryption is active, every directory contains // When filename encryption is active, every directory contains
// a "gocryptfs.diriv" file. This file should also change the owner. // a "gocryptfs.diriv" file. This file should also change the owner.
// Instead of checking if "cPath" is a directory, we just blindly // Instead of checking if "cName" is a directory, we just blindly
// execute the Lchown on "cPath/gocryptfs.diriv" and ignore errors. // execute the chown on "cName/gocryptfs.diriv" and ignore errors.
dirIVPath := filepath.Join(cPath, nametransform.DirIVFilename) dirIVPath := filepath.Join(cName, nametransform.DirIVFilename)
os.Lchown(dirIVPath, int(uid), int(gid)) syscallcompat.Fchownat(int(dirfd.Fd()), dirIVPath, int(uid), int(gid), unix.AT_SYMLINK_NOFOLLOW)
} }
return fuse.OK return fuse.OK
} }