lib9p

Go 9P library.
Log | Files | Refs

commit 09b7ae82a07a3e2e4e09d810186a2a16db3d301d
parent 74f108c38a6d5f05b5e7e4495e53ccdee20bff09
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Fri,  6 Oct 2023 07:43:38 +0900

add AuthFile

Diffstat:
Aauth.go | 33+++++++++++++++++++++++++++++++++
Mfile.go | 7++++++-
Mserver.go | 7+++++--
3 files changed, 44 insertions(+), 3 deletions(-)

diff --git a/auth.go b/auth.go @@ -0,0 +1,32 @@ +package lib9p + +import ( + "errors" + "io" +) + +type AuthFile struct { + Q Qid // TODO: how to avoid name confliction + Uname string + Aname string + AuthOK bool + W io.Writer + R io.Reader +} + +func (af *AuthFile) Parent() (File, error) { + return nil, errors.New("no parent for auth file") +} + +func (af *AuthFile) Child() ([]File, error) { + return nil, errors.New("no parent for auth file") +} + +func (af *AuthFile) Stat() (*FileInfo, error) { + return nil, errors.New("auth file") +} +func (af *AuthFile) Qid() Qid { return af.Q } +func (af *AuthFile) Open(OpenMode) error { return nil } +func (af *AuthFile) Close() error { return nil } +func (af *AuthFile) Read(p []byte) (int, error) { return af.R.Read(p) } +func (af *AuthFile) Write(p []byte) (int, error) { return af.W.Write(p) } +\ No newline at end of file diff --git a/file.go b/file.go @@ -13,7 +13,12 @@ type File interface { Qid() Qid Open(mode OpenMode) error Close() error - Read(b []byte) (int, error) + io.Reader +} + +type WriterFile interface { + File + io.Writer } type CreaterFile interface { diff --git a/server.go b/server.go @@ -202,13 +202,16 @@ func sAttach(s *Server, r *Req) { return } - // TODO: implement afid if ifcall.AFid() != NOFID { - _, ok := s.fPool.lookup(ifcall.AFid()) + afid, ok := s.fPool.lookup(ifcall.AFid()) if !ok { respond(r, ErrUnknownFid) return } + if !afid.File.(*AuthFile).AuthOK { + respond(r, fmt.Errorf("not authenticated")) + return + } } fid.File = s.fs.Root()