From c3adf9729de82bba52405e9f20f235b6a009308f Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Sun, 11 Nov 2018 18:27:37 +0100 Subject: fusefrontend: make ListXAttr symlink-safe on Linux Uses /proc/self/fd. --- internal/fusefrontend/xattr_linux.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'internal/fusefrontend/xattr_linux.go') diff --git a/internal/fusefrontend/xattr_linux.go b/internal/fusefrontend/xattr_linux.go index a17b12c..915713d 100644 --- a/internal/fusefrontend/xattr_linux.go +++ b/internal/fusefrontend/xattr_linux.go @@ -99,3 +99,27 @@ func (fs *FS) removeXAttr(relPath string, cAttr string, context *fuse.Context) f err := xattr.Remove(procFd(fd), cAttr) return unpackXattrErr(err) } + +// listXAttr - list encrypted xattr names on plaintext path "relPath". +// +// This function is symlink-safe on Linux by using /proc/self/fd. +func (fs *FS) listXAttr(relPath string, context *fuse.Context) ([]string, fuse.Status) { + file, fd, status := fs.getFileFd(relPath, context) + if !status.Ok() { + // If relPath is a symlink, getFileFd fails with ELOOP. As setXattr() + // also fails with ELOOP, there is no way to set xattrs on symlinks, + // and we can assume that the file does not have any. + if status == fuse.Status(syscall.ELOOP) { + return nil, fuse.OK + } + return nil, status + } + defer file.Release() + + cNames, err := xattr.List(procFd(fd)) + if err != nil { + status := unpackXattrErr(err) + return nil, status + } + return cNames, fuse.OK +} -- cgit v1.2.3