forked from superfly/flyctl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server_windows.go
55 lines (46 loc) · 1.08 KB
/
server_windows.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//go:build windows
package server
import (
"errors"
"fmt"
"io/fs"
"net"
"os"
"github.com/Microsoft/go-winio"
"github.com/superfly/flyctl/agent"
)
func removeSocket(path string) (err error) {
if !agent.UseUnixSockets() {
return nil
}
switch _, err = os.Lstat(path); {
case errors.Is(err, fs.ErrNotExist):
err = nil
case err != nil:
break
default:
if err = os.Remove(path); errors.Is(err, fs.ErrNotExist) {
err = nil
}
}
return
}
func bindSocket(socket string) (net.Listener, error) {
if agent.UseUnixSockets() {
return bindUnixSocket(socket)
}
pipe, err := agent.PipeName()
if err != nil {
return nil, err
}
// Default Named Pipe security policy grants full control to the LocalSystem
// account, administrators, and the creator owner. It also grants read
// access to members of the Everyone group and the anonymous account.
// Read allowed to everyone is Ok, because we need to write to pipe to actually
// establish a connection.
l, err := winio.ListenPipe(pipe, nil)
if err != nil {
err = fmt.Errorf("failed binding: %w", err)
}
return l, nil
}