From 55df8acac30c382390ca59474f1732b0f1b230b8 Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Mon, 28 Nov 2016 23:15:24 +0100 Subject: fusefrontend: preserve owner for symlinks https://github.com/rfjakob/gocryptfs/issues/64 --- internal/fusefrontend/fs.go | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/internal/fusefrontend/fs.go b/internal/fusefrontend/fs.go index 8e12997..6165d86 100644 --- a/internal/fusefrontend/fs.go +++ b/internal/fusefrontend/fs.go @@ -351,7 +351,6 @@ func (fs *FS) Symlink(target string, linkName string, context *fuse.Context) (co // Symlinks are encrypted like file contents (GCM) and base64-encoded cBinTarget := fs.contentEnc.EncryptBlock([]byte(target), 0, nil) cTarget := base64.URLEncoding.EncodeToString(cBinTarget) - // Handle long file name cName := filepath.Base(cPath) if nametransform.IsLongContent(cName) { @@ -361,25 +360,32 @@ func (fs *FS) Symlink(target string, linkName string, context *fuse.Context) (co return fuse.ToStatus(err) } defer dirfd.Close() - - // Create ".name" + // Create ".name" file err = fs.nameTransform.WriteLongName(dirfd, cName, linkName) if err != nil { return fuse.ToStatus(err) } - - // Create symlink + // Create "gocryptfs.longfile." symlink // TODO use syscall.Symlinkat once it is available in Go err = syscall.Symlink(cTarget, cPath) if err != nil { nametransform.DeleteLongName(dirfd, cName) } - + } else { + // Create symlink + err = os.Symlink(cTarget, cPath) + } + if err != nil { return fuse.ToStatus(err) } - - err = os.Symlink(cTarget, cPath) - return fuse.ToStatus(err) + // Set owner + if fs.args.PreserveOwner { + err = os.Lchown(cPath, int(context.Owner.Uid), int(context.Owner.Gid)) + if err != nil { + tlog.Warn.Printf("Mknod: Lchown failed: %v", err) + } + } + return fuse.OK } // Rename implements pathfs.Filesystem. -- cgit v1.2.3