From 45addca8cc3e1faf2bf67fad97e3fa142b1f947c Mon Sep 17 00:00:00 2001 From: Jan Noha Date: Thu, 7 Sep 2023 21:06:00 +0200 Subject: [PATCH] macOS sandboxed app support Signed-off-by: Jan Noha --- internal/wguser/conn_unix.go | 11 +++++++++-- internal/wguser/sockpath_darwin.go | 19 +++++++++++++++++++ internal/wguser/sockpath_unix.go | 7 +++++++ 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 internal/wguser/sockpath_darwin.go create mode 100644 internal/wguser/sockpath_unix.go diff --git a/internal/wguser/conn_unix.go b/internal/wguser/conn_unix.go index c85d8dd..84464e7 100644 --- a/internal/wguser/conn_unix.go +++ b/internal/wguser/conn_unix.go @@ -18,11 +18,18 @@ func dial(device string) (net.Conn, error) { // find is the default implementation of Client.find. func find() ([]string, error) { - return findUNIXSockets([]string{ + paths := []string{ // It seems that /var/run is a common location between Linux and the // BSDs, even though it's a symlink on Linux. "/var/run/wireguard", - }) + } + altPaths, err := altSockPaths() + if err != nil { + return nil, err + } + paths = append(paths, altPaths...) + + return findUNIXSockets(paths) } // findUNIXSockets looks for UNIX socket files in the specified directories. diff --git a/internal/wguser/sockpath_darwin.go b/internal/wguser/sockpath_darwin.go new file mode 100644 index 0000000..a8623de --- /dev/null +++ b/internal/wguser/sockpath_darwin.go @@ -0,0 +1,19 @@ +//go:build darwin + +package wguser + +import ( + "os" + "path/filepath" +) + +const NET_EXT_APP_ID = "com.wireguard.macos.network-extension" + +func altSockPaths() ([]string, error) { + homeDir, err := os.UserHomeDir() + if err != nil { + return nil, err + } + path := filepath.Join(homeDir, "Library", "Containers", NET_EXT_APP_ID, "Data") + return []string{path}, nil +} diff --git a/internal/wguser/sockpath_unix.go b/internal/wguser/sockpath_unix.go new file mode 100644 index 0000000..5f9eb99 --- /dev/null +++ b/internal/wguser/sockpath_unix.go @@ -0,0 +1,7 @@ +//go:build !darwin && !windows + +package wguser + +func altSockPaths() ([]string, error) { + return nil, nil +}