feat: add external-controller-pipe for windows

maybe useful for electron and tauri client, node.js and rust still not support AF_UNIX on windows
This commit is contained in:
wwqgtxx
2024-09-27 09:57:09 +08:00
parent 43cb48231a
commit 88bfe7cffe
7 changed files with 96 additions and 11 deletions

View File

@@ -0,0 +1,14 @@
//go:build !windows
package inbound
import (
"net"
"os"
)
const SupportNamedPipe = false
func ListenNamedPipe(path string) (net.Listener, error) {
return nil, os.ErrInvalid
}

View File

@@ -0,0 +1,27 @@
package inbound
import (
"net"
"github.com/metacubex/wireguard-go/ipc/namedpipe"
"golang.org/x/sys/windows"
)
const SupportNamedPipe = true
// windowsSDDL is the Security Descriptor set on the namedpipe.
// It provides read/write access to all users and the local system.
const windowsSDDL = "D:PAI(A;OICI;GWGR;;;BU)(A;OICI;GWGR;;;SY)"
func ListenNamedPipe(path string) (net.Listener, error) {
securityDescriptor, err := windows.SecurityDescriptorFromString(windowsSDDL)
if err != nil {
return nil, err
}
namedpipeLC := namedpipe.ListenConfig{
SecurityDescriptor: securityDescriptor,
InputBufferSize: 256 * 1024,
OutputBufferSize: 256 * 1024,
}
return namedpipeLC.Listen(path)
}