-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement AF_UNIX sockets on Windows
See moby/moby#36442 Signed-off-by: Marat Radchenko <[email protected]>
- Loading branch information
1 parent
5df8d2b
commit d29df4a
Showing
9 changed files
with
112 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
//go:build !windows | ||
|
||
package sockets | ||
|
||
import ( | ||
"net" | ||
"os" | ||
"syscall" | ||
"testing" | ||
) | ||
|
||
func createTestUnixSocket(t *testing.T, path string) (listener net.Listener) { | ||
uid, gid := os.Getuid(), os.Getgid() | ||
perms := os.FileMode(0660) | ||
l, err := NewUnixSocketWithOpts(path, WithChown(uid, gid), WithChmod(perms)) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
p, err := os.Stat(path) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if p.Mode().Perm() != perms { | ||
t.Fatalf("unexpected file permissions: expected: %#o, got: %#o", perms, p.Mode().Perm()) | ||
} | ||
if stat, ok := p.Sys().(*syscall.Stat_t); ok { | ||
if stat.Uid != uint32(uid) || stat.Gid != uint32(gid) { | ||
t.Fatalf("unexpected file ownership: expected: %d:%d, got: %d:%d", uid, gid, stat.Uid, stat.Gid) | ||
} | ||
} | ||
return l | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package sockets | ||
|
||
import ( | ||
"net" | ||
"testing" | ||
) | ||
|
||
func createTestUnixSocket(t *testing.T, path string) (listener net.Listener) { | ||
l, err := NewUnixSocketWithOpts(path) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
return l | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
//go:build !windows | ||
|
||
package sockets | ||
|
||
import ( | ||
"net" | ||
"syscall" | ||
) | ||
|
||
func listenUnix(path string) (net.Listener, error) { | ||
// net.Listen does not allow for permissions to be set. As a result, when | ||
// specifying custom permissions ("WithChmod()"), there is a short time | ||
// between creating the socket and applying the permissions, during which | ||
// the socket permissions are Less restrictive than desired. | ||
// | ||
// To work around this limitation of net.Listen(), we temporarily set the | ||
// umask to 0777, which forces the socket to be created with 000 permissions | ||
// (i.e.: no access for anyone). After that, WithChmod() must be used to set | ||
// the desired permissions. | ||
// | ||
// We don't use "defer" here, to reset the umask to its original value as soon | ||
// as possible. Ideally we'd be able to detect if WithChmod() was passed as | ||
// an option, and skip changing umask if default permissions are used. | ||
origUmask := syscall.Umask(0o777) | ||
l, err := net.Listen("unix", path) | ||
syscall.Umask(origUmask) | ||
return l, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package sockets | ||
|
||
import "net" | ||
|
||
func listenUnix(path string) (net.Listener, error) { | ||
return net.Listen("unix", path) | ||
} |