mirror of
https://github.com/k3s-io/k3s.git
synced 2024-06-07 19:41:36 +00:00
8b857eef9c
* Ship Stargz Snapshotter Signed-off-by: ktock <ktokunaga.mail@gmail.com> * Bump github.com/containerd/stargz-snapshotter to v0.8.0 Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
61 lines
1.1 KiB
Go
61 lines
1.1 KiB
Go
// Copyright 2019 the Go-FUSE Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package internal
|
|
|
|
import (
|
|
"os/user"
|
|
"strconv"
|
|
)
|
|
|
|
// HasAccess tests if a caller can access a file with permissions
|
|
// `perm` in mode `mask`
|
|
func HasAccess(callerUid, callerGid, fileUid, fileGid uint32, perm uint32, mask uint32) bool {
|
|
if callerUid == 0 {
|
|
// root can do anything.
|
|
return true
|
|
}
|
|
mask = mask & 7
|
|
if mask == 0 {
|
|
return true
|
|
}
|
|
|
|
if callerUid == fileUid {
|
|
if perm&(mask<<6) != 0 {
|
|
return true
|
|
}
|
|
}
|
|
if callerGid == fileGid {
|
|
if perm&(mask<<3) != 0 {
|
|
return true
|
|
}
|
|
}
|
|
if perm&mask != 0 {
|
|
return true
|
|
}
|
|
|
|
// Check other groups.
|
|
if perm&(mask<<3) == 0 {
|
|
// avoid expensive lookup if it's not allowed anyway
|
|
return false
|
|
}
|
|
|
|
u, err := user.LookupId(strconv.Itoa(int(callerUid)))
|
|
if err != nil {
|
|
return false
|
|
}
|
|
gs, err := u.GroupIds()
|
|
if err != nil {
|
|
return false
|
|
}
|
|
|
|
fileGidStr := strconv.Itoa(int(fileGid))
|
|
for _, gidStr := range gs {
|
|
if gidStr == fileGidStr {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|