aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-08-29 16:16:48 -0600
committerJason A. Donenfeld <Jason@zx2c4.com>2019-08-30 08:47:21 -0600
commita423506252312b2affff59334d36ad6c5471d013 (patch)
tree18badadf8bdf1b77b93932b947a352e5591ddf2b
parentversion: use ProductName and ProductVersion as strings (diff)
downloadwireguard-windows-a423506252312b2affff59334d36ad6c5471d013.tar.xz
wireguard-windows-a423506252312b2affff59334d36ad6c5471d013.zip
version: hard code name and version at compile time
We really do want the true name and version in logs so that external consumers have a good reference point for helping us debug. We can then do the log file directory explicitly.
-rw-r--r--Makefile2
-rw-r--r--conf/path_windows.go12
-rw-r--r--resources.rc2
-rw-r--r--ringlogger/dump.go5
-rw-r--r--ui/aboutdialog.go3
-rw-r--r--updater/versions.go3
-rw-r--r--version/debugging_linux.go4
-rw-r--r--version/mksyscall.go8
-rw-r--r--version/useragent.go8
-rw-r--r--version/version.h (renamed from version.h)0
-rw-r--r--version/version_windows.go61
-rw-r--r--version/zsyscall_windows.go82
12 files changed, 20 insertions, 170 deletions
diff --git a/Makefile b/Makefile
index 67d85c6c..c85b91e1 100644
--- a/Makefile
+++ b/Makefile
@@ -8,7 +8,7 @@ export GOROOT := $(CURDIR)/.deps/goroot
rwildcard=$(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d))
SOURCE_FILES := $(call rwildcard,,*.go *.c *.h) .deps/prepared
-RESOURCE_FILES := resources.rc version.h manifest.xml $(patsubst %.svg,%.ico,$(wildcard ui/icon/*.svg))
+RESOURCE_FILES := resources.rc version/version.h manifest.xml $(patsubst %.svg,%.ico,$(wildcard ui/icon/*.svg))
REQUIRED_GO_VERSION := go1.13beta1
ifneq ($(shell go version 2>/dev/null | cut -d ' ' -f 3),$(REQUIRED_GO_VERSION))
diff --git a/conf/path_windows.go b/conf/path_windows.go
index 041afe84..2997114e 100644
--- a/conf/path_windows.go
+++ b/conf/path_windows.go
@@ -10,8 +10,6 @@ import (
"path/filepath"
"golang.org/x/sys/windows"
-
- "golang.zx2c4.com/wireguard/windows/version"
)
var cachedConfigFileDir string
@@ -35,6 +33,13 @@ func tunnelConfigurationsDirectory() (string, error) {
return cachedConfigFileDir, nil
}
+// PresetRootDirectory causes RootDirectory() to not try any automatic deduction, and instead
+// uses what's passed to it. This isn't used by wireguard-windows, but is useful for external
+// consumers of our libraries who might want to do strange things.
+func PresetRootDirectory(root string) {
+ cachedRootDir = root
+}
+
func RootDirectory() (string, error) {
if cachedRootDir != "" {
return cachedRootDir, nil
@@ -43,8 +48,7 @@ func RootDirectory() (string, error) {
if err != nil {
return "", err
}
- name, _ := version.RunningNameVersion()
- c := filepath.Join(root, name)
+ c := filepath.Join(root, "WireGuard")
err = os.MkdirAll(c, os.ModeDir|0700)
if err != nil {
return "", err
diff --git a/resources.rc b/resources.rc
index 76f8a773..845e9684 100644
--- a/resources.rc
+++ b/resources.rc
@@ -4,7 +4,7 @@
*/
#include <windows.h>
-#include "version.h"
+#include "version/version.h"
CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST manifest.xml
diff --git a/ringlogger/dump.go b/ringlogger/dump.go
index 53e67eeb..05a9b27f 100644
--- a/ringlogger/dump.go
+++ b/ringlogger/dump.go
@@ -12,8 +12,8 @@ import (
"golang.org/x/sys/windows"
"golang.org/x/sys/windows/registry"
+
"golang.zx2c4.com/wireguard/windows/conf"
- "golang.zx2c4.com/wireguard/windows/version"
)
func DumpTo(out io.Writer, localSystem bool) error {
@@ -39,8 +39,7 @@ func DumpTo(out io.Writer, localSystem bool) error {
if err != nil {
return err
}
- name, _ := version.RunningNameVersion()
- path = filepath.Join(systemprofile, "AppData", "Local", name, "log.bin")
+ path = filepath.Join(systemprofile, "AppData", "Local", "WireGuard", "log.bin")
}
file, err := os.Open(path)
if err != nil {
diff --git a/ui/aboutdialog.go b/ui/aboutdialog.go
index 732531d4..89b55669 100644
--- a/ui/aboutdialog.go
+++ b/ui/aboutdialog.go
@@ -83,8 +83,7 @@ func runAboutDialog(owner walk.Form) error {
return err
}
detailsLbl.SetTextAlignment(walk.AlignHCenterVNear)
- _, appVersion := version.RunningNameVersion()
- detailsLbl.SetText(fmt.Sprintf("App version: %s\nGo backend version: %s\nGo version: %s\nOperating system: %s\nArchitecture: %s", appVersion, device.WireGuardGoVersion, strings.TrimPrefix(runtime.Version(), "go"), version.OsName(), runtime.GOARCH))
+ detailsLbl.SetText(fmt.Sprintf("App version: %s\nGo backend version: %s\nGo version: %s\nOperating system: %s\nArchitecture: %s", version.Number, device.WireGuardGoVersion, strings.TrimPrefix(runtime.Version(), "go"), version.OsName(), runtime.GOARCH))
copyrightLbl, err := walk.NewTextLabel(dlg)
if err != nil {
diff --git a/updater/versions.go b/updater/versions.go
index 7292ce7e..72f90240 100644
--- a/updater/versions.go
+++ b/updater/versions.go
@@ -17,8 +17,7 @@ import (
func versionNewerThanUs(candidate string) (bool, error) {
candidateParts := strings.Split(candidate, ".")
- _, ver := version.RunningNameVersion()
- ourParts := strings.Split(ver, ".")
+ ourParts := strings.Split(version.Number, ".")
if len(candidateParts) == 0 || len(ourParts) == 0 {
return false, errors.New("Empty version")
}
diff --git a/version/debugging_linux.go b/version/debugging_linux.go
index 7c9c09c5..ddea4242 100644
--- a/version/debugging_linux.go
+++ b/version/debugging_linux.go
@@ -30,10 +30,6 @@ func OsName() string {
return fmt.Sprintf("%s %s %s", utsToStr(utsname.Sysname), utsToStr(utsname.Release), utsToStr(utsname.Version))
}
-func RunningNameVersion() (string, string) {
- return "WireGuard", "0.0.0.0"
-}
-
func VerifyAuthenticode(path string) bool {
return true
}
diff --git a/version/mksyscall.go b/version/mksyscall.go
deleted file mode 100644
index 3c993928..00000000
--- a/version/mksyscall.go
+++ /dev/null
@@ -1,8 +0,0 @@
-/* SPDX-License-Identifier: MIT
- *
- * Copyright (C) 2019 WireGuard LLC. All Rights Reserved.
- */
-
-package version
-
-//go:generate go run $GOROOT/src/syscall/mksyscall_windows.go -output zsyscall_windows.go os_windows.go version_windows.go
diff --git a/version/useragent.go b/version/useragent.go
index 52fb5c83..1c1adf55 100644
--- a/version/useragent.go
+++ b/version/useragent.go
@@ -10,7 +10,11 @@ import (
"runtime"
)
+// #include "version.h"
+import "C"
+
+const Number = C.WIREGUARD_WINDOWS_VERSION_STRING
+
func UserAgent() string {
- name, ver := RunningNameVersion()
- return fmt.Sprintf("%s/%s (%s; %s)", name, ver, OsName(), runtime.GOARCH)
+ return fmt.Sprintf("WireGuard/%s (%s; %s)", Number, OsName(), runtime.GOARCH)
}
diff --git a/version.h b/version/version.h
index 61ce5495..61ce5495 100644
--- a/version.h
+++ b/version/version.h
diff --git a/version/version_windows.go b/version/version_windows.go
deleted file mode 100644
index b583d160..00000000
--- a/version/version_windows.go
+++ /dev/null
@@ -1,61 +0,0 @@
-/* SPDX-License-Identifier: MIT
- *
- * Copyright (C) 2019 WireGuard LLC. All Rights Reserved.
- */
-
-package version
-
-import (
- "os"
- "runtime"
- "unsafe"
-
- "golang.org/x/sys/windows"
-)
-
-//sys GetFileVersionInfoSize(filename *uint16, zero *uint32) (size uint32, err error) = version.GetFileVersionInfoSizeW
-//sys GetFileVersionInfo(filename *uint16, zero uint32, size uint32, block *byte) (err error) = version.GetFileVersionInfoW
-//sys VerQueryValue(block *byte, section *uint16, value **byte, size *uint32) (err error) = version.VerQueryValueW
-
-var cachedVersion, cachedName string
-
-func RunningNameVersion() (name, version string) {
- if len(cachedVersion) != 0 || len(cachedName) != 0 {
- return cachedName, cachedVersion
- }
- self, err := os.Executable()
- if err != nil {
- panic(err)
- }
- self16, err := windows.UTF16PtrFromString(self)
- if err != nil {
- panic(err)
- }
- var zero uint32
- size, err := GetFileVersionInfoSize(self16, &zero)
- if err != nil {
- panic(err)
- }
- buffer := make([]byte, size)
- err = GetFileVersionInfo(self16, zero, size, &buffer[0])
- if err != nil {
- panic(err)
- }
-
- var val16 *uint16
- err = VerQueryValue(&buffer[0], windows.StringToUTF16Ptr(`\StringFileInfo\040904b0\ProductName`), (**byte)(unsafe.Pointer(&val16)), &size)
- if err != nil {
- panic(err)
- }
- name = windows.UTF16ToString((*[(1 << 30) - 1]uint16)(unsafe.Pointer(val16))[:size])
- err = VerQueryValue(&buffer[0], windows.StringToUTF16Ptr(`\StringFileInfo\040904b0\ProductVersion`), (**byte)(unsafe.Pointer(&val16)), &size)
- if err != nil {
- panic(err)
- }
- version = windows.UTF16ToString((*[(1 << 30) - 1]uint16)(unsafe.Pointer(val16))[:size])
- runtime.KeepAlive(buffer)
-
- cachedName = name
- cachedVersion = version
- return
-}
diff --git a/version/zsyscall_windows.go b/version/zsyscall_windows.go
deleted file mode 100644
index 21684bb3..00000000
--- a/version/zsyscall_windows.go
+++ /dev/null
@@ -1,82 +0,0 @@
-// Code generated by 'go generate'; DO NOT EDIT.
-
-package version
-
-import (
- "syscall"
- "unsafe"
-
- "golang.org/x/sys/windows"
-)
-
-var _ unsafe.Pointer
-
-// Do the interface allocations only once for common
-// Errno values.
-const (
- errnoERROR_IO_PENDING = 997
-)
-
-var (
- errERROR_IO_PENDING error = syscall.Errno(errnoERROR_IO_PENDING)
-)
-
-// errnoErr returns common boxed Errno values, to prevent
-// allocations at runtime.
-func errnoErr(e syscall.Errno) error {
- switch e {
- case 0:
- return nil
- case errnoERROR_IO_PENDING:
- return errERROR_IO_PENDING
- }
- // TODO: add more here, after collecting data on the common
- // error values see on Windows. (perhaps when running
- // all.bat?)
- return e
-}
-
-var (
- modversion = windows.NewLazySystemDLL("version.dll")
-
- procGetFileVersionInfoSizeW = modversion.NewProc("GetFileVersionInfoSizeW")
- procGetFileVersionInfoW = modversion.NewProc("GetFileVersionInfoW")
- procVerQueryValueW = modversion.NewProc("VerQueryValueW")
-)
-
-func GetFileVersionInfoSize(filename *uint16, zero *uint32) (size uint32, err error) {
- r0, _, e1 := syscall.Syscall(procGetFileVersionInfoSizeW.Addr(), 2, uintptr(unsafe.Pointer(filename)), uintptr(unsafe.Pointer(zero)), 0)
- size = uint32(r0)
- if size == 0 {
- if e1 != 0 {
- err = errnoErr(e1)
- } else {
- err = syscall.EINVAL
- }
- }
- return
-}
-
-func GetFileVersionInfo(filename *uint16, zero uint32, size uint32, block *byte) (err error) {
- r1, _, e1 := syscall.Syscall6(procGetFileVersionInfoW.Addr(), 4, uintptr(unsafe.Pointer(filename)), uintptr(zero), uintptr(size), uintptr(unsafe.Pointer(block)), 0, 0)
- if r1 == 0 {
- if e1 != 0 {
- err = errnoErr(e1)
- } else {
- err = syscall.EINVAL
- }
- }
- return
-}
-
-func VerQueryValue(block *byte, section *uint16, value **byte, size *uint32) (err error) {
- r1, _, e1 := syscall.Syscall6(procVerQueryValueW.Addr(), 4, uintptr(unsafe.Pointer(block)), uintptr(unsafe.Pointer(section)), uintptr(unsafe.Pointer(value)), uintptr(unsafe.Pointer(size)), 0, 0)
- if r1 == 0 {
- if e1 != 0 {
- err = errnoErr(e1)
- } else {
- err = syscall.EINVAL
- }
- }
- return
-}