Extract checkPerm to package-level function, resolve perms in open
- 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.
This commit is contained in:
parent
8a13174b4f
commit
325ad224be
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue