Skip to content

Commit 45addca

Browse files
committed
macOS sandboxed app support
Signed-off-by: Jan Noha <[email protected]>
1 parent 925a1e7 commit 45addca

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

internal/wguser/conn_unix.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,18 @@ func dial(device string) (net.Conn, error) {
1818

1919
// find is the default implementation of Client.find.
2020
func find() ([]string, error) {
21-
return findUNIXSockets([]string{
21+
paths := []string{
2222
// It seems that /var/run is a common location between Linux and the
2323
// BSDs, even though it's a symlink on Linux.
2424
"/var/run/wireguard",
25-
})
25+
}
26+
altPaths, err := altSockPaths()
27+
if err != nil {
28+
return nil, err
29+
}
30+
paths = append(paths, altPaths...)
31+
32+
return findUNIXSockets(paths)
2633
}
2734

2835
// findUNIXSockets looks for UNIX socket files in the specified directories.

internal/wguser/sockpath_darwin.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//go:build darwin
2+
3+
package wguser
4+
5+
import (
6+
"os"
7+
"path/filepath"
8+
)
9+
10+
const NET_EXT_APP_ID = "com.wireguard.macos.network-extension"
11+
12+
func altSockPaths() ([]string, error) {
13+
homeDir, err := os.UserHomeDir()
14+
if err != nil {
15+
return nil, err
16+
}
17+
path := filepath.Join(homeDir, "Library", "Containers", NET_EXT_APP_ID, "Data")
18+
return []string{path}, nil
19+
}

internal/wguser/sockpath_unix.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//go:build !darwin && !windows
2+
3+
package wguser
4+
5+
func altSockPaths() ([]string, error) {
6+
return nil, nil
7+
}

0 commit comments

Comments
 (0)