Skip to content

Commit 0a3781d

Browse files
committed
Fix permission error with wnix sockets.
In the fix for golang/go#35033 Go started creating read-only files on Windows when no read permission bit was requested in the OpenFile call. This was not documented in the release notes (but see https://go-review.googlesource.com/c/go/+/223957/). Deal with the immediate issue by adding owner-read and owner-write permissions in our WriteFile which creates the file. Also add a workaround for the fact that previous version of Fleetspeak have left behind read-only files - simply clear the read-only attribute if the file already exists.
1 parent c2e95c4 commit 0a3781d

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

fleetspeak/src/windows/wnixsocket/wnixsocket_windows.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,17 @@ func Listen(socketPath string, mode os.FileMode) (net.Listener, error) {
9090
return nil, fmt.Errorf("failed to listen on a hashpipe: %v", err)
9191
}
9292

93+
// Previous versions of Fleetspeak had a bug where on go1.14 the above
94+
// WriteFile would create a read-only file. Clear that attribute if
95+
// such a file has been left behind.
96+
if _, err := os.Stat(socketPath); !os.IsNotExist(err) {
97+
if err := windows.Chmod(socketPath, windows.S_IWRITE); err != nil {
98+
return nil, fmt.Errorf("clearing read-only bit on wnix socket: %w", err)
99+
}
100+
}
101+
93102
// The socket file will be truncated if it exists.
94-
if err := ioutil.WriteFile(socketPath, []byte{}, 0); err != nil {
103+
if err := ioutil.WriteFile(socketPath, []byte{}, 0600); err != nil {
95104
return nil, fmt.Errorf("error while truncating a Wnix socket file; ioutil.WriteFile(%q, ...): %v", socketPath, err)
96105
}
97106

0 commit comments

Comments
 (0)