mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-25 11:05:45 +00:00
util/groupmember: fail earlier if group doesn't exist, use slices.Contains
Noticed both while re-reading this code. Updates #cleanup Change-Id: I3b70f1d5dc372853fa292ae1adbdee8cfc6a9a7b Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
parent
228a82f178
commit
673ff2cb0b
@ -7,6 +7,7 @@
|
||||
|
||||
import (
|
||||
"os/user"
|
||||
"slices"
|
||||
)
|
||||
|
||||
// IsMemberOfGroup reports whether the provided user is a member of
|
||||
@ -16,18 +17,13 @@ func IsMemberOfGroup(group, userName string) (bool, error) {
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
ugids, err := u.GroupIds()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
g, err := user.LookupGroup(group)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
for _, ugid := range ugids {
|
||||
if g.Gid == ugid {
|
||||
return true, nil
|
||||
ugids, err := u.GroupIds()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
}
|
||||
return false, nil
|
||||
return slices.Contains(ugids, g.Gid), nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user