From 5d102497e80f17056ce97bcc58a4906cf8a05c28 Mon Sep 17 00:00:00 2001 From: kali Date: Fri, 25 Sep 2020 17:46:50 +0200 Subject: [bug] workaround for helper path in windows --- pkg/helper/helper.go | 4 ++-- pkg/helper/windows.go | 18 +++++++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) (limited to 'pkg/helper') diff --git a/pkg/helper/helper.go b/pkg/helper/helper.go index 9d0b330..691fc6e 100644 --- a/pkg/helper/helper.go +++ b/pkg/helper/helper.go @@ -29,9 +29,9 @@ import ( ) var ( - AppName = "DemoLibVPN" + AppName = "DemoLibVPN" BinaryName = "bitmask" - Version = "git" + Version = "git" ) type openvpnT struct { diff --git a/pkg/helper/windows.go b/pkg/helper/windows.go index ef4f271..44ac6f5 100644 --- a/pkg/helper/windows.go +++ b/pkg/helper/windows.go @@ -33,8 +33,10 @@ import ( var ( svcName = BinaryName + `-helper-v2` + + // XXX this is set to c:\WINDOWS\system32 on initialization. Do not use it, use a function call instead. appPath = getExecDir() - LogFolder = appPath + LogFolder = getExecDir() openvpnPath = path.Join(appPath, "openvpn.exe") chocoOpenvpnPath = `C:\Program Files\OpenVPN\bin\openvpn.exe` platformOpenvpnFlags = []string{ @@ -47,9 +49,11 @@ var ( func getExecDir() string { ex, err := os.Executable() if err != nil { - log.Fatal("Cannot find executable path") + log.Println("Cannot find executable path") + return "" } - return path.Dir(ex) + /* XXX filepath.Abs is buggy, maybe because of spaces in the path. fuck it, this is good enough for now */ + return strings.Replace(ex, "\\helper.exe", "", 1) } type httpConf struct { @@ -131,11 +135,15 @@ func daemonize() {} func runServer(port int) {} func getOpenvpnPath() string { - if _, err := os.Stat(openvpnPath); !os.IsNotExist(err) { - return openvpnPath + openvpn := path.Join(getExecDir(), "openvpn.exe") + if _, err := os.Stat(openvpn); !os.IsNotExist(err) { + log.Println("DEBUG: openvpnpath found,", openvpnPath) + return openvpn } else if _, err := os.Stat(chocoOpenvpnPath); !os.IsNotExist(err) { + log.Println("DEBUG: choco openvpn found,", chocoOpenvpnPath) return chocoOpenvpnPath } + log.Println("DEBUG: did not find system-wide openvpn...") return "openvpn.exe" } -- cgit v1.2.3