Added a header with credentials to each request.

geesefs-0-30-9
Aaron Jacobs 2015-03-03 10:58:01 +11:00
parent 8d99b454a8
commit 44901edc6b
3 changed files with 50 additions and 12 deletions

View File

@ -198,6 +198,13 @@ type HandleID uint64
// ReadDirRequest.Offset for details.
type DirOffset uint64
// A header that is included with every request.
type RequestHeader struct {
// Credentials information for the process making the request.
Uid uint32
Gid uint32
}
// Information about a child inode within its parent directory. Shared by the
// responses for LookUpInode, MkDir, etc. Consumed by the kernel in order to
// set up a dcache entry.
@ -274,15 +281,15 @@ type ChildInodeEntry struct {
////////////////////////////////////////////////////////////////////////
type InitRequest struct {
// User and group IDs for the process that is mounting the file system.
Uid uint32
Gid uint32
Header RequestHeader
}
type InitResponse struct {
}
type LookUpInodeRequest struct {
Header RequestHeader
// The ID of the directory inode to which the child belongs.
Parent InodeID
@ -303,6 +310,8 @@ type LookUpInodeResponse struct {
}
type GetInodeAttributesRequest struct {
Header RequestHeader
// The inode of interest.
Inode InodeID
}
@ -315,6 +324,8 @@ type GetInodeAttributesResponse struct {
}
type ForgetInodeRequest struct {
Header RequestHeader
// The inode to be forgotten. The kernel guarantees that the node ID will not
// be used in further calls to the file system (unless it is reissued by the
// file system).
@ -325,6 +336,8 @@ type ForgetInodeResponse struct {
}
type MkDirRequest struct {
Header RequestHeader
// The ID of parent directory inode within which to create the child.
Parent InodeID
@ -348,6 +361,8 @@ type MkDirResponse struct {
}
type OpenDirRequest struct {
Header RequestHeader
// The ID of the inode to be opened.
Inode InodeID
@ -371,6 +386,8 @@ type OpenDirResponse struct {
}
type ReadDirRequest struct {
Header RequestHeader
// The directory inode that we are reading, and the handle previously
// returned by OpenDir when opening that inode.
Inode InodeID
@ -460,6 +477,8 @@ type ReadDirResponse struct {
}
type ReleaseDirHandleRequest struct {
Header RequestHeader
// The handle ID to be released. The kernel guarantees that this ID will not
// be used in further calls to the file system (unless it is reissued by the
// file system).
@ -470,6 +489,8 @@ type ReleaseDirHandleResponse struct {
}
type OpenFileRequest struct {
Header RequestHeader
// The ID of the inode to be opened.
Inode InodeID
@ -493,6 +514,8 @@ type OpenFileResponse struct {
}
type ReadFileRequest struct {
Header RequestHeader
// The file inode that we are reading, and the handle previously returned by
// OpenFile when opening that inode.
Inode InodeID
@ -516,6 +539,8 @@ type ReadFileResponse struct {
}
type ReleaseFileHandleRequest struct {
Header RequestHeader
// The handle ID to be released. The kernel guarantees that this ID will not
// be used in further calls to the file system (unless it is reissued by the
// file system).

View File

@ -135,8 +135,8 @@ func (fs *HelloFS) Init(
req *fuse.InitRequest) (
resp *fuse.InitResponse, err error) {
resp = &fuse.InitResponse{}
fs.Uid = req.Uid
fs.Gid = req.Gid
fs.Uid = req.Header.Uid
fs.Gid = req.Header.Gid
return
}

View File

@ -43,6 +43,13 @@ func convertChildInodeEntry(
out.EntryValid = in.EntryExpiration.Sub(clock.Now())
}
func convertHeader(
in bazilfuse.Header) (out RequestHeader) {
out.Uid = in.Uid
out.Gid = in.Gid
return
}
// Serve the fuse connection by repeatedly reading requests from the supplied
// FUSE connection, responding as dictated by the file system. Return when the
// connection is closed or an unexpected error occurs.
@ -82,8 +89,7 @@ func (s *server) handleFuseRequest(fuseReq bazilfuse.Request) {
case *bazilfuse.InitRequest:
// Convert the request.
req := &InitRequest{
Uid: typed.Header.Uid,
Gid: typed.Header.Gid,
Header: convertHeader(typed.Header),
}
// Call the file system.
@ -110,6 +116,7 @@ func (s *server) handleFuseRequest(fuseReq bazilfuse.Request) {
case *bazilfuse.LookupRequest:
// Convert the request.
req := &LookUpInodeRequest{
Header: convertHeader(typed.Header),
Parent: InodeID(typed.Header.Node),
Name: typed.Name,
}
@ -132,7 +139,8 @@ func (s *server) handleFuseRequest(fuseReq bazilfuse.Request) {
case *bazilfuse.GetattrRequest:
// Convert the request.
req := &GetInodeAttributesRequest{
Inode: InodeID(typed.Header.Node),
Header: convertHeader(typed.Header),
Inode: InodeID(typed.Header.Node),
}
// Call the file system.
@ -155,6 +163,7 @@ func (s *server) handleFuseRequest(fuseReq bazilfuse.Request) {
case *bazilfuse.MkdirRequest:
// Convert the request.
req := &MkDirRequest{
Header: convertHeader(typed.Header),
Parent: InodeID(typed.Header.Node),
Name: typed.Name,
Mode: typed.Mode,
@ -180,8 +189,9 @@ func (s *server) handleFuseRequest(fuseReq bazilfuse.Request) {
if typed.Dir {
// Convert the request.
req := &OpenDirRequest{
Inode: InodeID(typed.Header.Node),
Flags: typed.Flags,
Header: convertHeader(typed.Header),
Inode: InodeID(typed.Header.Node),
Flags: typed.Flags,
}
// Call the file system.
@ -202,8 +212,9 @@ func (s *server) handleFuseRequest(fuseReq bazilfuse.Request) {
} else {
// Convert the request.
req := &OpenFileRequest{
Inode: InodeID(typed.Header.Node),
Flags: typed.Flags,
Header: convertHeader(typed.Header),
Inode: InodeID(typed.Header.Node),
Flags: typed.Flags,
}
// Call the file system.
@ -228,6 +239,7 @@ func (s *server) handleFuseRequest(fuseReq bazilfuse.Request) {
if typed.Dir {
// Convert the request.
req := &ReadDirRequest{
Header: convertHeader(typed.Header),
Inode: InodeID(typed.Header.Node),
Handle: HandleID(typed.Handle),
Offset: DirOffset(typed.Offset),
@ -252,6 +264,7 @@ func (s *server) handleFuseRequest(fuseReq bazilfuse.Request) {
} else {
// Convert the request.
req := &ReadFileRequest{
Header: convertHeader(typed.Header),
Inode: InodeID(typed.Header.Node),
Handle: HandleID(typed.Handle),
Offset: typed.Offset,