summaryrefslogtreecommitdiff
path: root/internal/fusefrontend/fs_dir.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2016-11-28 22:46:04 +0100
committerJakob Unterwurzacher2016-11-28 22:46:04 +0100
commita66440c66816c919acfaa4cd079fe2fae7043294 (patch)
treea59e9fbb412fecc5548e546548ea72035847adbb /internal/fusefrontend/fs_dir.go
parent7fc93ec0937d925941107a0d05341b6da8540d05 (diff)
fusefrontend: use Lchown when preserving owner
This prevents (unlikely) symlink race attacks
Diffstat (limited to 'internal/fusefrontend/fs_dir.go')
-rw-r--r--internal/fusefrontend/fs_dir.go13
1 files changed, 6 insertions, 7 deletions
diff --git a/internal/fusefrontend/fs_dir.go b/internal/fusefrontend/fs_dir.go
index 6b581b1..05cea75 100644
--- a/internal/fusefrontend/fs_dir.go
+++ b/internal/fusefrontend/fs_dir.go
@@ -54,9 +54,9 @@ func (fs *FS) Mkdir(newPath string, mode uint32, context *fuse.Context) (code fu
err = os.Mkdir(cPath, os.FileMode(mode))
// Set owner
if fs.args.PreserveOwner {
- err = os.Chown(cPath, int(context.Owner.Uid), int(context.Owner.Gid))
+ err = os.Lchown(cPath, int(context.Owner.Uid), int(context.Owner.Gid))
if err != nil {
- tlog.Warn.Printf("Mkdir: Chown failed: %v", err)
+ tlog.Warn.Printf("Mkdir: Lchown failed: %v", err)
}
}
return fuse.ToStatus(err)
@@ -94,7 +94,6 @@ func (fs *FS) Mkdir(newPath string, mode uint32, context *fuse.Context) (code fu
return fuse.ToStatus(err)
}
}
-
// Set permissions back to what the user wanted
if origMode != mode {
err = os.Chmod(cPath, os.FileMode(origMode))
@@ -104,13 +103,13 @@ func (fs *FS) Mkdir(newPath string, mode uint32, context *fuse.Context) (code fu
}
// Set owner
if fs.args.PreserveOwner {
- err = os.Chown(cPath, int(context.Owner.Uid), int(context.Owner.Gid))
+ err = os.Lchown(cPath, int(context.Owner.Uid), int(context.Owner.Gid))
if err != nil {
- tlog.Warn.Printf("Mkdir: Chown failed: %v", err)
+ tlog.Warn.Printf("Mkdir: Lchown 1 failed: %v", err)
}
- err = os.Chown(filepath.Join(cPath, nametransform.DirIVFilename), int(context.Owner.Uid), int(context.Owner.Gid))
+ err = os.Lchown(filepath.Join(cPath, nametransform.DirIVFilename), int(context.Owner.Uid), int(context.Owner.Gid))
if err != nil {
- tlog.Warn.Printf("Mkdir: Chown failed: %v", err)
+ tlog.Warn.Printf("Mkdir: Lchown 2 failed: %v", err)
}
}
return fuse.OK