From b70b012bc692477fdf51b09627c6a7333265ee31 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Thu, 29 Aug 2019 16:16:48 -0600 Subject: 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. Signed-off-by: Jason A. Donenfeld --- Makefile | 2 +- conf/path_windows.go | 12 ++++--- resources.rc | 2 +- ringlogger/dump.go | 5 ++- ui/aboutdialog.go | 3 +- updater/versions.go | 3 +- version.h | 2 -- version/debugging_linux.go | 4 --- version/mksyscall.go | 8 ----- version/useragent.go | 8 +++-- version/version.h | 2 ++ version/version_windows.go | 61 --------------------------------- version/zsyscall_windows.go | 82 --------------------------------------------- 13 files changed, 22 insertions(+), 172 deletions(-) delete mode 100644 version.h delete mode 100644 version/mksyscall.go create mode 100644 version/version.h delete mode 100644 version/version_windows.go delete mode 100644 version/zsyscall_windows.go 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 -#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.h b/version.h deleted file mode 100644 index 61ce5495..00000000 --- a/version.h +++ /dev/null @@ -1,2 +0,0 @@ -#define WIREGUARD_WINDOWS_VERSION_ARRAY 0,0,23 -#define WIREGUARD_WINDOWS_VERSION_STRING "0.0.23" 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/version.h b/version/version.h new file mode 100644 index 00000000..61ce5495 --- /dev/null +++ b/version/version.h @@ -0,0 +1,2 @@ +#define WIREGUARD_WINDOWS_VERSION_ARRAY 0,0,23 +#define WIREGUARD_WINDOWS_VERSION_STRING "0.0.23" 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 -} -- cgit v1.2.3-59-g8ed1b