github.com/ssdev-go/moby@v17.12.1-ce-rc2+incompatible/daemon/listeners/listeners_windows.go (about)

     1  package listeners
     2  
     3  import (
     4  	"crypto/tls"
     5  	"fmt"
     6  	"net"
     7  	"strings"
     8  
     9  	"github.com/Microsoft/go-winio"
    10  	"github.com/docker/go-connections/sockets"
    11  )
    12  
    13  // Init creates new listeners for the server.
    14  func Init(proto, addr, socketGroup string, tlsConfig *tls.Config) ([]net.Listener, error) {
    15  	ls := []net.Listener{}
    16  
    17  	switch proto {
    18  	case "tcp":
    19  		l, err := sockets.NewTCPSocket(addr, tlsConfig)
    20  		if err != nil {
    21  			return nil, err
    22  		}
    23  		ls = append(ls, l)
    24  
    25  	case "npipe":
    26  		// allow Administrators and SYSTEM, plus whatever additional users or groups were specified
    27  		sddl := "D:P(A;;GA;;;BA)(A;;GA;;;SY)"
    28  		if socketGroup != "" {
    29  			for _, g := range strings.Split(socketGroup, ",") {
    30  				sid, err := winio.LookupSidByName(g)
    31  				if err != nil {
    32  					return nil, err
    33  				}
    34  				sddl += fmt.Sprintf("(A;;GRGW;;;%s)", sid)
    35  			}
    36  		}
    37  		c := winio.PipeConfig{
    38  			SecurityDescriptor: sddl,
    39  			MessageMode:        true,  // Use message mode so that CloseWrite() is supported
    40  			InputBufferSize:    65536, // Use 64KB buffers to improve performance
    41  			OutputBufferSize:   65536,
    42  		}
    43  		l, err := winio.ListenPipe(addr, &c)
    44  		if err != nil {
    45  			return nil, err
    46  		}
    47  		ls = append(ls, l)
    48  
    49  	default:
    50  		return nil, fmt.Errorf("invalid protocol format: windows only supports tcp and npipe")
    51  	}
    52  
    53  	return ls, nil
    54  }