mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-29 04:55:31 +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 (
|
import (
|
||||||
"os/user"
|
"os/user"
|
||||||
|
"slices"
|
||||||
)
|
)
|
||||||
|
|
||||||
// IsMemberOfGroup reports whether the provided user is a member of
|
// IsMemberOfGroup reports whether the provided user is a member of
|
||||||
@ -16,18 +17,13 @@ func IsMemberOfGroup(group, userName string) (bool, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
ugids, err := u.GroupIds()
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
g, err := user.LookupGroup(group)
|
g, err := user.LookupGroup(group)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
for _, ugid := range ugids {
|
ugids, err := u.GroupIds()
|
||||||
if g.Gid == ugid {
|
if err != nil {
|
||||||
return true, nil
|
return false, err
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false, nil
|
return slices.Contains(ugids, g.Gid), nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user