fusefrontend: make ListXAttr symlink-safe on Linux
Uses /proc/self/fd.
This commit is contained in:
parent
d3ae87fa2b
commit
c3adf9729d
|
@ -82,21 +82,18 @@ func (fs *FS) RemoveXAttr(relPath string, attr string, context *fuse.Context) fu
|
||||||
return fs.removeXAttr(relPath, cAttr, context)
|
return fs.removeXAttr(relPath, cAttr, context)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListXAttr - FUSE call. Lists extended attributes on the file at "path".
|
// ListXAttr - FUSE call. Lists extended attributes on the file at "relPath".
|
||||||
//
|
//
|
||||||
// TODO: Make symlink-safe. Blocker: package xattr does not provide
|
// This function is symlink-safe on Linux.
|
||||||
// flistxattr(2).
|
// Darwin does not have flistxattr(2) nor /proc/self/fd. How to implement this
|
||||||
func (fs *FS) ListXAttr(path string, context *fuse.Context) ([]string, fuse.Status) {
|
// on Darwin in a symlink-safe way?
|
||||||
if fs.isFiltered(path) {
|
func (fs *FS) ListXAttr(relPath string, context *fuse.Context) ([]string, fuse.Status) {
|
||||||
|
if fs.isFiltered(relPath) {
|
||||||
return nil, fuse.EPERM
|
return nil, fuse.EPERM
|
||||||
}
|
}
|
||||||
cPath, err := fs.getBackingPath(path)
|
cNames, status := fs.listXAttr(relPath, context)
|
||||||
if err != nil {
|
if !status.Ok() {
|
||||||
return nil, fuse.ToStatus(err)
|
return nil, status
|
||||||
}
|
|
||||||
cNames, err := xattr.LList(cPath)
|
|
||||||
if err != nil {
|
|
||||||
return nil, unpackXattrErr(err)
|
|
||||||
}
|
}
|
||||||
names := make([]string, 0, len(cNames))
|
names := make([]string, 0, len(cNames))
|
||||||
for _, curName := range cNames {
|
for _, curName := range cNames {
|
||||||
|
|
|
@ -53,3 +53,17 @@ func (fs *FS) removeXAttr(relPath string, cAttr string, context *fuse.Context) f
|
||||||
err = xattr.LRemove(cPath, cAttr)
|
err = xattr.LRemove(cPath, cAttr)
|
||||||
return unpackXattrErr(err)
|
return unpackXattrErr(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This function is NOT symlink-safe because Darwin lacks
|
||||||
|
// both flistxattr() and /proc/self/fd.
|
||||||
|
func (fs *FS) listXAttr(relPath string, context *fuse.Context) ([]string, fuse.Status) {
|
||||||
|
cPath, err := fs.getBackingPath(relPath)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fuse.ToStatus(err)
|
||||||
|
}
|
||||||
|
cNames, err := xattr.LList(cPath)
|
||||||
|
if err != nil {
|
||||||
|
return nil, unpackXattrErr(err)
|
||||||
|
}
|
||||||
|
return cNames, fuse.OK
|
||||||
|
}
|
||||||
|
|
|
@ -99,3 +99,27 @@ func (fs *FS) removeXAttr(relPath string, cAttr string, context *fuse.Context) f
|
||||||
err := xattr.Remove(procFd(fd), cAttr)
|
err := xattr.Remove(procFd(fd), cAttr)
|
||||||
return unpackXattrErr(err)
|
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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue