From 5e958a41f6a603ac2d97ec768a4538f5f877dd54 Mon Sep 17 00:00:00 2001 From: Eric Gouyer Date: Sat, 3 Aug 2019 04:58:46 +0200 Subject: [PATCH] add support for retrieving UID GID PID for each fuseops, ala FUSE-C fuse_get_context() --- mounted_file_system.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/mounted_file_system.go b/mounted_file_system.go index bb9bb35..fe272cf 100644 --- a/mounted_file_system.go +++ b/mounted_file_system.go @@ -14,7 +14,10 @@ package fuse -import "context" +import ( + "context" + "fmt" +) // MountedFileSystem represents the status of a mount operation, with a method // that waits for unmounting. @@ -47,3 +50,17 @@ func (mfs *MountedFileSystem) Join(ctx context.Context) error { return ctx.Err() } } + +// GetFuseContext implements the equiv. of FUSE-C fuse_get_context() and thus +// returns the UID / GID / PID associated with all FUSE requests send by the kernel. +// ctx parameter must be one of the context from the fuseops handlers (e.g.: CreateFile) +func (mfs *MountedFileSystem) GetFuseContext(ctx context.Context) (uid, gid, pid uint32, err error) { + foo := ctx.Value(contextKey) + state, ok := foo.(opState) + if !ok { + return 0, 0, 0, fmt.Errorf("GetFuseContext called with invalid context: %#v", ctx) + } + inMsg := state.inMsg + header := inMsg.Header() + return header.Uid, header.Gid, header.Pid, nil +}