diff --git a/cmd/olliesrv/server.go b/cmd/olliesrv/server.go index 5c4d0f8..72c14ba 100644 --- a/cmd/olliesrv/server.go +++ b/cmd/olliesrv/server.go @@ -144,14 +144,11 @@ func fileOwnerGroup(root *fs.Tree, path string) (uid, gid string) { return "ollie", "agent" } -func (s *Server) checkPerm(uname, path string, mode uint8) error { - uid, gid := fileOwnerGroup(s.rootTree, path) - dir := makeStat(s.rootTree, path) - perm := uint32(dir.Mode) & 0777 +func checkPerm(uname string, mode uint8, uid string, perm uint32, inGroup bool) error { var bits uint32 if uname == uid { bits = (perm >> 6) & 7 - } else if s.InGroup(gid, uname) { + } else if inGroup { bits = (perm >> 3) & 7 } else { bits = perm & 7 @@ -415,7 +412,8 @@ func (s *Server) open(cs *connState, fc *plan9.Fcall) *plan9.Fcall { if !ok { return errFcall(fc, "bad fid") } - if err := s.checkPerm(cs.uname, f.path, fc.Mode); err != nil { + uid, gid := fileOwnerGroup(s.rootTree, f.path) + if err := checkPerm(cs.uname, fc.Mode, uid, uint32(makeStat(s.rootTree, f.path).Mode)&0777, s.InGroup(gid, cs.uname)); err != nil { return errFcall(fc, err.Error()) } f.mode = fc.Mode