add support for retrieving UID GID PID for each fuseops, ala FUSE-C fuse_get_context()

notifications
Eric Gouyer 2019-08-03 04:58:46 +02:00 committed by Michael Stapelberg
parent 2681cd5156
commit 5e958a41f6
1 changed files with 18 additions and 1 deletions

View File

@ -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
}