File: npipe_windows.go

package info (click to toggle)
golang-github-containers-gvisor-tap-vsocks 0.8.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 800 kB
  • sloc: sh: 95; makefile: 59
file content (43 lines) | stat: -rw-r--r-- 1,029 bytes parent folder | download
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
package sshclient

import (
	"fmt"
	"net"
	"net/url"
	"os/user"
	"strings"

	winio "github.com/Microsoft/go-winio"
	"github.com/pkg/errors"
	"github.com/sirupsen/logrus"
)

// https://docs.microsoft.com/en-us/windows-hardware/drivers/kernel/sddl-for-device-objects
// Allow built-in admins and system/kernel components
const SddlDevObjSysAllAdmAll = "D:P(A;;GA;;;SY)(A;;GA;;;BA)"

func ListenNpipe(socketURI *url.URL) (net.Listener, error) {
	user, err := user.Current()
	if err != nil {
		return nil, err
	}

	// Also allow current user
	sddl := fmt.Sprintf("%s(A;;GA;;;%s)", SddlDevObjSysAllAdmAll, user.Uid)
	config := winio.PipeConfig{
		SecurityDescriptor: sddl,
		MessageMode:        true,
		InputBufferSize:    65536,
		OutputBufferSize:   65536,
	}
	path := strings.Replace(socketURI.Path, "/", "\\", -1)

	listener, err := winio.ListenPipe(path, &config)
	if err != nil {
		return listener, errors.Wrapf(err, "Error listening on socket: %s", socketURI)
	}

	logrus.Info("Listening on: " + path)

	return listener, nil
}