Skip to content

Commit eb315e3

Browse files
authored
Merge pull request docker#26 from cpuguy83/remove_group_lookup
Remove support for group lookup
2 parents 4ccf312 + 62665b1 commit eb315e3

File tree

1 file changed

+4
-53
lines changed

1 file changed

+4
-53
lines changed

sockets/unix_socket.go

Lines changed: 4 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,26 @@
1-
// +build linux freebsd solaris
1+
// +build !windows
22

33
package sockets
44

55
import (
6-
"fmt"
76
"net"
87
"os"
9-
"strconv"
108
"syscall"
11-
12-
"github.com/Sirupsen/logrus"
13-
"github.com/opencontainers/runc/libcontainer/user"
149
)
1510

1611
// NewUnixSocket creates a unix socket with the specified path and group.
17-
func NewUnixSocket(path, group string) (net.Listener, error) {
12+
func NewUnixSocket(path string, gid int) (net.Listener, error) {
1813
if err := syscall.Unlink(path); err != nil && !os.IsNotExist(err) {
1914
return nil, err
2015
}
2116
mask := syscall.Umask(0777)
2217
defer syscall.Umask(mask)
18+
2319
l, err := net.Listen("unix", path)
2420
if err != nil {
2521
return nil, err
2622
}
27-
if err := setSocketGroup(path, group); err != nil {
28-
l.Close()
23+
if err := os.Chown(path, 0, gid); err != nil {
2924
return nil, err
3025
}
3126
if err := os.Chmod(path, 0660); err != nil {
@@ -34,47 +29,3 @@ func NewUnixSocket(path, group string) (net.Listener, error) {
3429
}
3530
return l, nil
3631
}
37-
38-
func setSocketGroup(path, group string) error {
39-
if group == "" {
40-
return nil
41-
}
42-
if err := changeGroup(path, group); err != nil {
43-
if group != "docker" {
44-
return err
45-
}
46-
logrus.Debugf("Warning: could not change group %s to docker: %v", path, err)
47-
}
48-
return nil
49-
}
50-
51-
func changeGroup(path string, nameOrGid string) error {
52-
gid, err := lookupGidByName(nameOrGid)
53-
if err != nil {
54-
return err
55-
}
56-
logrus.Debugf("%s group found. gid: %d", nameOrGid, gid)
57-
return os.Chown(path, 0, gid)
58-
}
59-
60-
func lookupGidByName(nameOrGid string) (int, error) {
61-
groupFile, err := user.GetGroupPath()
62-
if err != nil {
63-
return -1, err
64-
}
65-
groups, err := user.ParseGroupFileFilter(groupFile, func(g user.Group) bool {
66-
return g.Name == nameOrGid || strconv.Itoa(g.Gid) == nameOrGid
67-
})
68-
if err != nil {
69-
return -1, err
70-
}
71-
if groups != nil && len(groups) > 0 {
72-
return groups[0].Gid, nil
73-
}
74-
gid, err := strconv.Atoi(nameOrGid)
75-
if err == nil {
76-
logrus.Warnf("Could not find GID %d", gid)
77-
return gid, nil
78-
}
79-
return -1, fmt.Errorf("Group %s not found", nameOrGid)
80-
}

0 commit comments

Comments
 (0)