From 325ad224bebf4d5b66d03309ffb107e787cdb195 Mon Sep 17 00:00:00 2001 From: Ollie Agent Date: Sun, 2 Aug 2026 15:50:31 +0200 Subject: [PATCH] Extract checkPerm to package-level function, resolve perms in open MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - checkPerm no longer needs *Server: it takes uid, perm, and inGroup directly. The caller (open) resolves uid/gid via fileOwnerGroup, perm via makeStat, and group membership via InGroup. - checkPerm is now a pure function: (uname, mode, uid, perm, inGroup) → returns only on permissions, needs nothing from Server state. - open is the remaining method that resolves these values. server.go: 10 remaining Server methods. --- cmd/olliesrv/server.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) 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