| 1 | package sshclient |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "net" |
| 6 | "net/url" |
| 7 | "os/user" |
| 8 | "strings" |
| 9 | |
| 10 | winio "github.com/Microsoft/go-winio" |
| 11 | "github.com/sirupsen/logrus" |
| 12 | ) |
| 13 | |
| 14 | |
| 15 | |
| 16 | const SddlDevObjSysAllAdmAll = "D:P(A;;GA;;;SY)(A;;GA;;;BA)" |
| 17 | |
| 18 | func ListenNpipe(socketURI *url.URL) (net.Listener, error) { |
| 19 | user, err := user.Current() |
| 20 | if err != nil { |
| 21 | return nil, err |
| 22 | } |
| 23 | |
| 24 | |
| 25 | sddl := fmt.Sprintf("%s(A;;GA;;;%s)", SddlDevObjSysAllAdmAll, user.Uid) |
| 26 | config := winio.PipeConfig{ |
| 27 | SecurityDescriptor: sddl, |
| 28 | MessageMode: true, |
| 29 | InputBufferSize: 65536, |
| 30 | OutputBufferSize: 65536, |
| 31 | } |
| 32 | path := strings.ReplaceAll(socketURI.Path, "/", "\\") |
| 33 | |
| 34 | listener, err := winio.ListenPipe(path, &config) |
| 35 | if err != nil { |
| 36 | return listener, fmt.Errorf("error listening on socket: %s: %w", socketURI, err) |
| 37 | } |
| 38 | |
| 39 | logrus.Info("Listening on: " + path) |
| 40 | |
| 41 | return listener, nil |
| 42 | } |