fusefrontend: fix chown on dangling symlinks

We (actually, go-fuse) used to call Chown() instead of Lchown()
which meant that the operation would fail on dangling symlinks.

Fix this by calling os.Lchown() ourself. Also add a test case
for this.
This commit is contained in:
Jakob Unterwurzacher 2016-06-08 00:17:18 +02:00
parent f58a8d8740
commit 5da292828c
2 changed files with 18 additions and 2 deletions

View File

@ -165,11 +165,11 @@ func (fs *FS) Chown(path string, uid uint32, gid uint32, context *fuse.Context)
if fs.isFiltered(path) {
return fuse.EPERM
}
cPath, err := fs.encryptPath(path)
cPath, err := fs.getBackingPath(path)
if err != nil {
return fuse.ToStatus(err)
}
return fs.FileSystem.Chown(cPath, uid, gid, context)
return fuse.ToStatus(os.Lchown(cPath, int(uid), int(gid)))
}
func (fs *FS) Mknod(path string, mode uint32, dev uint32, context *fuse.Context) (code fuse.Status) {

View File

@ -437,3 +437,19 @@ func TestLongNames(t *testing.T) {
t.Errorf("Leftover files, cnt1=%d cnt2=%d", cnt1, cnt2)
}
}
func TestLchown(t *testing.T) {
name := test_helpers.DefaultPlainDir + "symlink"
err := os.Symlink("/target/does/not/exist", name)
if err != nil {
t.Fatal(err)
}
err = os.Chown(name, os.Getuid(), os.Getgid())
if err == nil {
t.Error("Chown on dangling symlink should fail")
}
err = os.Lchown(name, os.Getuid(), os.Getgid())
if err != nil {
t.Error(err)
}
}