mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Use idtools.LookupGroup instead of parsing /etc/group file for docker.sock ownership
Signed-off-by: James Watkins-Harvey <jwatkins@progi-media.com>
This commit is contained in:
parent
46652b00ad
commit
a2e384682b
1 changed files with 4 additions and 14 deletions
|
@ -6,25 +6,15 @@ import (
|
|||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/opencontainers/runc/libcontainer/user"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/docker/docker/pkg/idtools"
|
||||
)
|
||||
|
||||
const defaultSocketGroup = "docker"
|
||||
|
||||
func lookupGID(name string) (int, error) {
|
||||
groupFile, err := user.GetGroupPath()
|
||||
if err != nil {
|
||||
return -1, errors.Wrap(err, "error looking up groups")
|
||||
}
|
||||
groups, err := user.ParseGroupFileFilter(groupFile, func(g user.Group) bool {
|
||||
return g.Name == name || strconv.Itoa(g.Gid) == name
|
||||
})
|
||||
if err != nil {
|
||||
return -1, errors.Wrapf(err, "error parsing groups for %s", name)
|
||||
}
|
||||
if len(groups) > 0 {
|
||||
return groups[0].Gid, nil
|
||||
group, err := idtools.LookupGroup(name)
|
||||
if err == nil {
|
||||
return group.Gid, nil
|
||||
}
|
||||
gid, err := strconv.Atoi(name)
|
||||
if err == nil {
|
||||
|
|
Loading…
Reference in a new issue