lib9p

Go 9P library.
Log | Files | Refs

commit 176cca869c6bed56075961cdef68e62591668375
parent 09b7ae82a07a3e2e4e09d810186a2a16db3d301d
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Fri,  6 Oct 2023 07:57:36 +0900

confirm authentication

Diffstat:
Mserver.go | 26++++++++++++++++++++------
1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/server.go b/server.go @@ -38,7 +38,7 @@ type Server struct { speakChan chan<- *Req speakErrChan <-chan error - auth func(*Req, *Fid) + Auth func(*Req) } func NewServer(fsys FS, mSize uint32, r io.Reader, w io.Writer) *Server { @@ -174,13 +174,14 @@ func rVersion(r *Req, err error) { func sAuth(s *Server, r *Req) { ifcall := r.ifcall.(*TAuth) - afid, err := s.fPool.add(ifcall.AFid()) + var err error + r.afid, err = s.fPool.add(ifcall.AFid()) if err != nil { respond(r, ErrDupFid) } - if s.auth != nil { - s.auth(r, afid) + if s.Auth != nil { + s.Auth(r) } else { respond(r, fmt.Errorf("authentication not required")) return @@ -202,13 +203,26 @@ func sAttach(s *Server, r *Req) { return } - if ifcall.AFid() != NOFID { + if s.Auth == nil && ifcall.AFid() != NOFID { + respond(r, ErrBotch) + return + } + if s.Auth != nil && ifcall.AFid() == NOFID { + respond(r, fmt.Errorf("authentication required")) + return + } + if s.Auth != nil && ifcall.AFid() != NOFID { afid, ok := s.fPool.lookup(ifcall.AFid()) if !ok { respond(r, ErrUnknownFid) return } - if !afid.File.(*AuthFile).AuthOK { + af, ok := afid.File.(*AuthFile) + if !ok { + respond(r, fmt.Errorf("not auth file")) + return + } + if !af.AuthOK { respond(r, fmt.Errorf("not authenticated")) return }