Commit 155877e9 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

nodefs: move Access to DefaultOperations

parent 7059718c
......@@ -10,6 +10,7 @@ import (
"unsafe"
"github.com/hanwen/go-fuse/fuse"
"github.com/hanwen/go-fuse/internal"
)
// DefaultOperations provides no-operation default implementations for
......@@ -76,8 +77,23 @@ func (n *DefaultOperations) SetAttr(ctx context.Context, in *fuse.SetAttrIn, out
return fuse.EROFS
}
// The Access default implementation checks traditional unix
// permissions of the GetAttr result agains the caller.
func (n *DefaultOperations) Access(ctx context.Context, mask uint32) fuse.Status {
return fuse.ENOENT
caller, ok := fuse.FromContext(ctx)
if !ok {
return fuse.EINVAL
}
var out fuse.AttrOut
if s := InodeOf(n).Operations().GetAttr(ctx, &out); !s.Ok() {
return s
}
if !internal.HasAccess(caller.Uid, caller.Gid, out.Uid, out.Gid, out.Mode, mask) {
return fuse.EACCES
}
return fuse.OK
}
// FSetAttr delegates to the FileHandle's if f is not nil, or else to the
......
......@@ -11,7 +11,6 @@ import (
"syscall"
"github.com/hanwen/go-fuse/fuse"
"github.com/hanwen/go-fuse/internal"
"golang.org/x/sys/unix"
)
......@@ -296,20 +295,3 @@ func NewLoopbackRoot(root string) (DirOperations, error) {
n.rootNode = n
return n, nil
}
func (n *loopbackNode) Access(ctx context.Context, mask uint32) fuse.Status {
caller, ok := fuse.FromContext(ctx)
if !ok {
return fuse.EACCES
}
var st syscall.Stat_t
if err := syscall.Stat(n.path(), &st); err != nil {
return fuse.ToStatus(err)
}
if !internal.HasAccess(caller.Uid, caller.Gid, st.Uid, st.Gid, uint32(st.Mode), mask) {
return fuse.EACCES
}
return fuse.OK
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment