From df69371620ef8fdf0fc4693274f9b524c8250d0e Mon Sep 17 00:00:00 2001 From: Wade Simmons Date: Fri, 21 Feb 2020 15:25:33 -0500 Subject: [PATCH] use absolute paths on darwin and windows (#191) We want to make sure to use the system binaries, and not whatever is in the PATH. --- tun_darwin.go | 8 ++++---- tun_windows.go | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tun_darwin.go b/tun_darwin.go index 0cc9339..0562559 100644 --- a/tun_darwin.go +++ b/tun_darwin.go @@ -42,18 +42,18 @@ func (c *Tun) Activate() error { c.Device = c.Interface.Name() // TODO use syscalls instead of exec.Command - if err = exec.Command("ifconfig", c.Device, c.Cidr.String(), c.Cidr.IP.String()).Run(); err != nil { + if err = exec.Command("/sbin/ifconfig", c.Device, c.Cidr.String(), c.Cidr.IP.String()).Run(); err != nil { return fmt.Errorf("failed to run 'ifconfig': %s", err) } - if err = exec.Command("route", "-n", "add", "-net", c.Cidr.String(), "-interface", c.Device).Run(); err != nil { + if err = exec.Command("/sbin/route", "-n", "add", "-net", c.Cidr.String(), "-interface", c.Device).Run(); err != nil { return fmt.Errorf("failed to run 'route add': %s", err) } - if err = exec.Command("ifconfig", c.Device, "mtu", strconv.Itoa(c.MTU)).Run(); err != nil { + if err = exec.Command("/sbin/ifconfig", c.Device, "mtu", strconv.Itoa(c.MTU)).Run(); err != nil { return fmt.Errorf("failed to run 'ifconfig': %s", err) } // Unsafe path routes for _, r := range c.UnsafeRoutes { - if err = exec.Command("route", "-n", "add", "-net", r.route.String(), "-interface", c.Device).Run(); err != nil { + if err = exec.Command("/sbin/route", "-n", "add", "-net", r.route.String(), "-interface", c.Device).Run(); err != nil { return fmt.Errorf("failed to run 'route add' for unsafe_route %s: %s", r.route.String(), err) } } diff --git a/tun_windows.go b/tun_windows.go index 301a3f2..ada043a 100644 --- a/tun_windows.go +++ b/tun_windows.go @@ -47,7 +47,7 @@ func (c *Tun) Activate() error { // TODO use syscalls instead of exec.Command err = exec.Command( - "netsh", "interface", "ipv4", "set", "address", + `C:\Windows\System32\netsh.exe`, "interface", "ipv4", "set", "address", fmt.Sprintf("name=%s", c.Device), "source=static", fmt.Sprintf("addr=%s", c.Cidr.IP), @@ -58,7 +58,7 @@ func (c *Tun) Activate() error { return fmt.Errorf("failed to run 'netsh' to set address: %s", err) } err = exec.Command( - "netsh", "interface", "ipv4", "set", "interface", + `C:\Windows\System32\netsh.exe`, "interface", "ipv4", "set", "interface", c.Device, fmt.Sprintf("mtu=%d", c.MTU), ).Run()