diff options
41 files changed, 140 insertions, 125 deletions
diff --git a/conf/config.go b/conf/config.go index e6cc6aac..d8935b44 100644 --- a/conf/config.go +++ b/conf/config.go @@ -27,9 +27,11 @@ type Endpoint struct { Port uint16 } -type Key [KeyLength]byte -type HandshakeTime time.Duration -type Bytes uint64 +type ( + Key [KeyLength]byte + HandshakeTime time.Duration + Bytes uint64 +) type Config struct { Name string diff --git a/conf/migration_windows.go b/conf/migration_windows.go index e81fb5e4..4e106e20 100644 --- a/conf/migration_windows.go +++ b/conf/migration_windows.go @@ -18,8 +18,10 @@ import ( "golang.org/x/sys/windows" ) -var migrating sync.Mutex -var lastMigrationTimer *time.Timer +var ( + migrating sync.Mutex + lastMigrationTimer *time.Timer +) type MigrationCallback func(name, oldPath, newPath string) @@ -53,7 +55,7 @@ func migrateUnencryptedConfigs(sharingBase int, migrated MigrationCallback) { if err != nil { continue } - if info.Mode().Perm()&0444 == 0 { + if info.Mode().Perm()&0o444 == 0 { continue } diff --git a/conf/name.go b/conf/name.go index 2b42c0e9..1ecb3225 100644 --- a/conf/name.go +++ b/conf/name.go @@ -18,9 +18,11 @@ var reservedNames = []string{ "LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9", } -const serviceNameForbidden = "$" -const netshellDllForbidden = "\\/:*?\"<>|\t" -const specialChars = "/\\<>:\"|?*\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x00" +const ( + serviceNameForbidden = "$" + netshellDllForbidden = "\\/:*?\"<>|\t" + specialChars = "/\\<>:\"|?*\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x00" +) var allowedNameFormat = regexp.MustCompile("^[a-zA-Z0-9_=+.-]{1,32}$") @@ -60,6 +62,7 @@ type naturalSortToken struct { maybeString string maybeNumber int } + type naturalSortString struct { originalString string tokens []naturalSortToken diff --git a/conf/parser.go b/conf/parser.go index 477a5205..ff030362 100644 --- a/conf/parser.go +++ b/conf/parser.go @@ -158,7 +158,7 @@ func (c *Config) maybeAddPeer(p *Peer) { } } -func FromWgQuick(s string, name string) (*Config, error) { +func FromWgQuick(s, name string) (*Config, error) { if !TunnelNameIsValid(name) { return nil, &ParseError{l18n.Sprintf("Tunnel name is not valid"), name} } @@ -319,7 +319,7 @@ func FromWgQuick(s string, name string) (*Config, error) { return &conf, nil } -func FromWgQuickWithUnknownEncoding(s string, name string) (*Config, error) { +func FromWgQuickWithUnknownEncoding(s, name string) (*Config, error) { c, firstErr := FromWgQuick(s, name) if firstErr == nil { return c, nil diff --git a/conf/parser_test.go b/conf/parser_test.go index c2f757c7..67a208eb 100644 --- a/conf/parser_test.go +++ b/conf/parser_test.go @@ -54,6 +54,7 @@ func equal(t *testing.T, expected, actual interface{}) bool { t.Errorf("Failed equals at %s:%d\nactual %#v\nexpected %#v", fn, line, actual, expected) return false } + func lenTest(t *testing.T, actualO interface{}, expected int) bool { actual := reflect.ValueOf(actualO).Len() if reflect.DeepEqual(expected, actual) { @@ -63,6 +64,7 @@ func lenTest(t *testing.T, actualO interface{}, expected int) bool { t.Errorf("Wrong length at %s:%d\nactual %#v\nexpected %#v", fn, line, actual, expected) return false } + func contains(t *testing.T, list, element interface{}) bool { listValue := reflect.ValueOf(list) for i := 0; i < listValue.Len(); i++ { diff --git a/conf/path_windows.go b/conf/path_windows.go index e994a1b1..ec93d5ff 100644 --- a/conf/path_windows.go +++ b/conf/path_windows.go @@ -15,8 +15,10 @@ import ( "golang.org/x/sys/windows" ) -var cachedConfigFileDir string -var cachedRootDir string +var ( + cachedConfigFileDir string + cachedRootDir string +) func tunnelConfigurationsDirectory() (string, error) { if cachedConfigFileDir != "" { @@ -27,7 +29,7 @@ func tunnelConfigurationsDirectory() (string, error) { return "", err } c := filepath.Join(root, "Configurations") - err = os.Mkdir(c, os.ModeDir|0700) + err = os.Mkdir(c, os.ModeDir|0o700) if err != nil && !os.IsExist(err) { return "", err } diff --git a/conf/store.go b/conf/store.go index def94836..af253046 100644 --- a/conf/store.go +++ b/conf/store.go @@ -14,8 +14,10 @@ import ( "golang.zx2c4.com/wireguard/windows/conf/dpapi" ) -const configFileSuffix = ".conf.dpapi" -const configFileUnencryptedSuffix = ".conf" +const ( + configFileSuffix = ".conf.dpapi" + configFileUnencryptedSuffix = ".conf" +) func ListConfigNames() ([]string, error) { configFileDir, err := tunnelConfigurationsDirectory() @@ -40,7 +42,7 @@ func ListConfigNames() ([]string, error) { if err != nil { continue } - if info.Mode().Perm()&0444 == 0 { + if info.Mode().Perm()&0o444 == 0 { continue } configs[i] = name diff --git a/driver/driver_windows.go b/driver/driver_windows.go index dcdc0e69..74dd087c 100644 --- a/driver/driver_windows.go +++ b/driver/driver_windows.go @@ -79,7 +79,7 @@ func closeAdapter(wireguard *Adapter) { // the GUID of the created network adapter, which then influences NLA generation // deterministically. If it is set to nil, the GUID is chosen by the system at random, // and hence a new NLA entry is created for each new adapter. -func CreateAdapter(name string, tunnelType string, requestedGUID *windows.GUID) (wireguard *Adapter, err error) { +func CreateAdapter(name, tunnelType string, requestedGUID *windows.GUID) (wireguard *Adapter, err error) { var name16 *uint16 name16, err = windows.UTF16PtrFromString(name) if err != nil { diff --git a/driver/memmod/memmod_windows.go b/driver/memmod/memmod_windows.go index 666adceb..63f066fd 100644 --- a/driver/memmod/memmod_windows.go +++ b/driver/memmod/memmod_windows.go @@ -47,7 +47,7 @@ func (module *Module) headerDirectory(idx int) *IMAGE_DATA_DIRECTORY { return &module.headers.OptionalHeader.DataDirectory[idx] } -func (module *Module) copySections(address uintptr, size uintptr, oldHeaders *IMAGE_NT_HEADERS) error { +func (module *Module) copySections(address, size uintptr, oldHeaders *IMAGE_NT_HEADERS) error { sections := module.headers.Sections() for i := range sections { if sections[i].SizeOfRawData == 0 { @@ -139,7 +139,7 @@ func (module *Module) finalizeSection(sectionData *sectionFinalizeData) error { } // determine protection flags based on characteristics - var ProtectionFlags = [8]uint32{ + ProtectionFlags := [8]uint32{ windows.PAGE_NOACCESS, // not writeable, not readable, not executable windows.PAGE_EXECUTE, // not writeable, not readable, executable windows.PAGE_READONLY, // not writeable, readable, not executable @@ -387,10 +387,12 @@ type addressRange struct { end uintptr } -var loadedAddressRanges []addressRange -var loadedAddressRangesMu sync.RWMutex -var haveHookedRtlPcToFileHeader sync.Once -var hookRtlPcToFileHeaderResult error +var ( + loadedAddressRanges []addressRange + loadedAddressRangesMu sync.RWMutex + haveHookedRtlPcToFileHeader sync.Once + hookRtlPcToFileHeaderResult error +) func hookRtlPcToFileHeader() error { var kernelBase windows.Handle diff --git a/driver/wintunremoval_windows.go b/driver/wintunremoval_windows.go index f98b55a5..7ccfd6ff 100644 --- a/driver/wintunremoval_windows.go +++ b/driver/wintunremoval_windows.go @@ -12,7 +12,7 @@ import ( ) func UninstallLegacyWintun() error { - var deviceClassNetGUID = &windows.GUID{0x4d36e972, 0xe325, 0x11ce, [8]byte{0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18}} + deviceClassNetGUID := &windows.GUID{0x4d36e972, 0xe325, 0x11ce, [8]byte{0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18}} devInfo, err := windows.SetupDiCreateDeviceInfoListEx(deviceClassNetGUID, 0, "") if err != nil { return err diff --git a/elevate/shellexecute.go b/elevate/shellexecute.go index d4daa97b..0c411a66 100644 --- a/elevate/shellexecute.go +++ b/elevate/shellexecute.go @@ -24,7 +24,7 @@ const ( cSEE_MASK_DEFAULT = 0 ) -func ShellExecute(program string, arguments string, directory string, show int32) (err error) { +func ShellExecute(program, arguments, directory string, show int32) (err error) { var ( program16 *uint16 arguments16 *uint16 diff --git a/embeddable-dll-service/main.go b/embeddable-dll-service/main.go index df63034e..7450d72d 100644 --- a/embeddable-dll-service/main.go +++ b/embeddable-dll-service/main.go @@ -7,17 +7,16 @@ package main import ( "C" + "crypto/rand" + "log" + "path/filepath" + "unsafe" "golang.org/x/crypto/curve25519" "golang.org/x/sys/windows" "golang.zx2c4.com/wireguard/windows/conf" "golang.zx2c4.com/wireguard/windows/tunnel" - - "crypto/rand" - "log" - "path/filepath" - "unsafe" ) //export WireGuardTunnelService @@ -33,7 +32,7 @@ func WireGuardTunnelService(confFile16 *uint16) bool { } //export WireGuardGenerateKeypair -func WireGuardGenerateKeypair(publicKey *byte, privateKey *byte) { +func WireGuardGenerateKeypair(publicKey, privateKey *byte) { publicKeyArray := (*[32]byte)(unsafe.Pointer(publicKey)) privateKeyArray := (*[32]byte)(unsafe.Pointer(privateKey)) n, err := rand.Read(privateKeyArray[:]) diff --git a/l18n/l18n.go b/l18n/l18n.go index 0eb72714..4af5cfdb 100644 --- a/l18n/l18n.go +++ b/l18n/l18n.go @@ -13,8 +13,10 @@ import ( "golang.org/x/text/message" ) -var printer *message.Printer -var printerLock sync.Mutex +var ( + printer *message.Printer + printerLock sync.Mutex +) // prn returns the printer for user preferred UI language. func prn() *message.Printer { @@ -54,7 +54,7 @@ func fatalf(format string, v ...interface{}) { fatal(l18n.Sprintf(format, v...)) } -func info(title string, format string, v ...interface{}) { +func info(title, format string, v ...interface{}) { if log.Writer() == io.Discard { windows.MessageBox(0, windows.StringToUTF16Ptr(l18n.Sprintf(format, v...)), windows.StringToUTF16Ptr(title), windows.MB_ICONINFORMATION) } else { @@ -63,7 +63,7 @@ func info(title string, format string, v ...interface{}) { } func usage() { - var flags = [...]string{ + flags := [...]string{ l18n.Sprintf("(no argument): elevate and install manager service"), "/installmanagerservice", "/installtunnelservice CONFIG_PATH", diff --git a/manager/ipc_client.go b/manager/ipc_client.go index 2f78a47e..199156bc 100644 --- a/manager/ipc_client.go +++ b/manager/ipc_client.go @@ -64,7 +64,7 @@ var ( ) type TunnelChangeCallback struct { - cb func(tunnel *Tunnel, state TunnelState, globalState TunnelState, err error) + cb func(tunnel *Tunnel, state, globalState TunnelState, err error) } var tunnelChangeCallbacks = make(map[*TunnelChangeCallback]bool) @@ -93,7 +93,7 @@ type UpdateProgressCallback struct { var updateProgressCallbacks = make(map[*UpdateProgressCallback]bool) -func InitializeIPCClient(reader *os.File, writer *os.File, events *os.File) { +func InitializeIPCClient(reader, writer, events *os.File) { rpcDecoder = gob.NewDecoder(reader) rpcEncoder = gob.NewEncoder(writer) go func() { @@ -431,43 +431,52 @@ func IPCClientUpdate() error { return rpcEncoder.Encode(UpdateMethodType) } -func IPCClientRegisterTunnelChange(cb func(tunnel *Tunnel, state TunnelState, globalState TunnelState, err error)) *TunnelChangeCallback { +func IPCClientRegisterTunnelChange(cb func(tunnel *Tunnel, state, globalState TunnelState, err error)) *TunnelChangeCallback { s := &TunnelChangeCallback{cb} tunnelChangeCallbacks[s] = true return s } + func (cb *TunnelChangeCallback) Unregister() { delete(tunnelChangeCallbacks, cb) } + func IPCClientRegisterTunnelsChange(cb func()) *TunnelsChangeCallback { s := &TunnelsChangeCallback{cb} tunnelsChangeCallbacks[s] = true return s } + func (cb *TunnelsChangeCallback) Unregister() { delete(tunnelsChangeCallbacks, cb) } + func IPCClientRegisterManagerStopping(cb func()) *ManagerStoppingCallback { s := &ManagerStoppingCallback{cb} managerStoppingCallbacks[s] = true return s } + func (cb *ManagerStoppingCallback) Unregister() { delete(managerStoppingCallbacks, cb) } + func IPCClientRegisterUpdateFound(cb func(updateState UpdateState)) *UpdateFoundCallback { s := &UpdateFoundCallback{cb} updateFoundCallbacks[s] = true return s } + func (cb *UpdateFoundCallback) Unregister() { delete(updateFoundCallbacks, cb) } + func IPCClientRegisterUpdateProgress(cb func(dp updater.DownloadProgress)) *UpdateProgressCallback { s := &UpdateProgressCallback{cb} updateProgressCallbacks[s] = true return s } + func (cb *UpdateProgressCallback) Unregister() { delete(updateProgressCallbacks, cb) } diff --git a/manager/ipc_driver.go b/manager/ipc_driver.go index 2155207b..a4f83e61 100644 --- a/manager/ipc_driver.go +++ b/manager/ipc_driver.go @@ -16,8 +16,10 @@ type lockedDriverAdapter struct { sync.Mutex } -var driverAdapters = make(map[string]*lockedDriverAdapter) -var driverAdaptersLock sync.RWMutex +var ( + driverAdapters = make(map[string]*lockedDriverAdapter) + driverAdaptersLock sync.RWMutex +) func findDriverAdapter(tunnelName string) (*lockedDriverAdapter, error) { driverAdaptersLock.RLock() diff --git a/manager/ipc_server.go b/manager/ipc_server.go index dccbce28..bb36c649 100644 --- a/manager/ipc_server.go +++ b/manager/ipc_server.go @@ -23,10 +23,12 @@ import ( "golang.zx2c4.com/wireguard/windows/updater" ) -var managerServices = make(map[*ManagerService]bool) -var managerServicesLock sync.RWMutex -var haveQuit uint32 -var quitManagersChan = make(chan struct{}, 1) +var ( + managerServices = make(map[*ManagerService]bool) + managerServicesLock sync.RWMutex + haveQuit uint32 + quitManagersChan = make(chan struct{}, 1) +) type ManagerService struct { events *os.File @@ -439,7 +441,7 @@ func (s *ManagerService) ServeConn(reader io.Reader, writer io.Writer) { } } -func IPCServerListen(reader *os.File, writer *os.File, events *os.File, elevatedToken windows.Token) { +func IPCServerListen(reader, writer, events *os.File, elevatedToken windows.Token) { service := &ManagerService{ events: events, elevatedToken: elevatedToken, diff --git a/manager/service.go b/manager/service.go index d5c50156..5e243969 100644 --- a/manager/service.go +++ b/manager/service.go @@ -207,7 +207,8 @@ func (service *managerService) Execute(args []string, r <-chan svc.ChangeRequest windows.Handle(theirReader.Fd()), windows.Handle(theirWriter.Fd()), windows.Handle(theirEvents.Fd()), - theirLogMapping}, runToken) + theirLogMapping, + }, runToken) } else { err = errors.New("Session has logged out") } diff --git a/manager/tunneltracker.go b/manager/tunneltracker.go index 96020635..4a6fb5bb 100644 --- a/manager/tunneltracker.go +++ b/manager/tunneltracker.go @@ -24,8 +24,10 @@ import ( "golang.zx2c4.com/wireguard/windows/services" ) -var trackedTunnels = make(map[string]TunnelState) -var trackedTunnelsLock = sync.Mutex{} +var ( + trackedTunnels = make(map[string]TunnelState) + trackedTunnelsLock = sync.Mutex{} +) func trackedTunnelsGlobalState() (state TunnelState) { state = TunnelStopped diff --git a/ringlogger/global.go b/ringlogger/global.go index 0685cbd7..6b614190 100644 --- a/ringlogger/global.go +++ b/ringlogger/global.go @@ -30,8 +30,10 @@ func InitGlobalLogger(file, tag string) error { //go:linkname overrideWrite runtime.overrideWrite var overrideWrite func(fd uintptr, p unsafe.Pointer, n int32) int32 -var globalBuffer [maxLogLineLength - 1 - maxTagLength - 3]byte -var globalBufferLocation int +var ( + globalBuffer [maxLogLineLength - 1 - maxTagLength - 3]byte + globalBufferLocation int +) //go:nosplit func globalWrite(fd uintptr, p unsafe.Pointer, n int32) int32 { diff --git a/ringlogger/ringlogger.go b/ringlogger/ringlogger.go index 8888b64e..e002b2fe 100644 --- a/ringlogger/ringlogger.go +++ b/ringlogger/ringlogger.go @@ -45,11 +45,11 @@ type Ringlogger struct { readOnly bool } -func NewRinglogger(filename string, tag string) (*Ringlogger, error) { +func NewRinglogger(filename, tag string) (*Ringlogger, error) { if len(tag) > maxTagLength { return nil, windows.ERROR_LABEL_TOO_LONG } - file, err := os.OpenFile(filename, os.O_RDWR|os.O_CREATE, 0600) + file, err := os.OpenFile(filename, os.O_RDWR|os.O_CREATE, 0o600) if err != nil { return nil, err } @@ -69,7 +69,7 @@ func NewRinglogger(filename string, tag string) (*Ringlogger, error) { return rl, nil } -func NewRingloggerFromInheritedMappingHandle(handleStr string, tag string) (*Ringlogger, error) { +func NewRingloggerFromInheritedMappingHandle(handleStr, tag string) (*Ringlogger, error) { handle, err := strconv.ParseUint(handleStr, 10, 64) if err != nil { return nil, err diff --git a/tunnel/deterministicguid.go b/tunnel/deterministicguid.go index afdab11e..818902e2 100644 --- a/tunnel/deterministicguid.go +++ b/tunnel/deterministicguid.go @@ -18,8 +18,10 @@ import ( "golang.zx2c4.com/wireguard/windows/conf" ) -const deterministicGUIDLabel = "Deterministic WireGuard Windows GUID v1 jason@zx2c4.com" -const fixedGUIDLabel = "Fixed WireGuard Windows GUID v1 jason@zx2c4.com" +const ( + deterministicGUIDLabel = "Deterministic WireGuard Windows GUID v1 jason@zx2c4.com" + fixedGUIDLabel = "Fixed WireGuard Windows GUID v1 jason@zx2c4.com" +) // Escape hatch for external consumers, not us. var UseFixedGUIDInsteadOfDeterministic = false diff --git a/tunnel/firewall/rules.go b/tunnel/firewall/rules.go index 201a73e3..c5a0c4e6 100644 --- a/tunnel/firewall/rules.go +++ b/tunnel/firewall/rules.go @@ -583,7 +583,6 @@ func permitDHCPIPv6(session uintptr, baseObjects *baseObjects, weight uint8) err } func permitNdp(session uintptr, baseObjects *baseObjects, weight uint8) error { - /* TODO: actually handle the hop limit somehow! The rules should vaguely be: * - icmpv6 133: must be outgoing, dst must be FF02::2/128, hop limit must be 255 * - icmpv6 134: must be incoming, src must be FE80::/10, hop limit must be 255 @@ -986,7 +985,7 @@ func blockAll(session uintptr, baseObjects *baseObjects, weight uint8) error { } // Block all DNS traffic except towards specified DNS servers. -func blockDNS(except []netip.Addr, session uintptr, baseObjects *baseObjects, weightAllow uint8, weightDeny uint8) error { +func blockDNS(except []netip.Addr, session uintptr, baseObjects *baseObjects, weightAllow, weightDeny uint8) error { if weightDeny >= weightAllow { return errors.New("The allow weight must be greater than the deny weight") } diff --git a/tunnel/firewall/types_windows.go b/tunnel/firewall/types_windows.go index 075daae4..991147cb 100644 --- a/tunnel/firewall/types_windows.go +++ b/tunnel/firewall/types_windows.go @@ -148,8 +148,10 @@ var cFWPM_CONDITION_IP_LOCAL_ADDRESS = windows.GUID{ Data4: [8]byte{0xbf, 0xe3, 0xff, 0xd8, 0xf5, 0xa0, 0x89, 0x57}, } -var cFWPM_CONDITION_ICMP_TYPE = cFWPM_CONDITION_IP_LOCAL_PORT -var cFWPM_CONDITION_ICMP_CODE = cFWPM_CONDITION_IP_REMOTE_PORT +var ( + cFWPM_CONDITION_ICMP_TYPE = cFWPM_CONDITION_IP_LOCAL_PORT + cFWPM_CONDITION_ICMP_CODE = cFWPM_CONDITION_IP_REMOTE_PORT +) // 7bc43cbf-37ba-45f1-b74a-82ff518eeb10 var cFWPM_CONDITION_L2_FLAGS = windows.GUID{ diff --git a/tunnel/firewall/types_windows_test.go b/tunnel/firewall/types_windows_test.go index 683e52ea..cbb73b5c 100644 --- a/tunnel/firewall/types_windows_test.go +++ b/tunnel/firewall/types_windows_test.go @@ -11,7 +11,6 @@ import ( ) func TestWtFwpByteBlobSize(t *testing.T) { - const actualWtFwpByteBlobSize = unsafe.Sizeof(wtFwpByteBlob{}) if actualWtFwpByteBlobSize != wtFwpByteBlob_Size { @@ -21,7 +20,6 @@ func TestWtFwpByteBlobSize(t *testing.T) { } func TestWtFwpByteBlobOffsets(t *testing.T) { - s := wtFwpByteBlob{} sp := uintptr(unsafe.Pointer(&s)) @@ -34,7 +32,6 @@ func TestWtFwpByteBlobOffsets(t *testing.T) { } func TestWtFwpmAction0Size(t *testing.T) { - const actualWtFwpmAction0Size = unsafe.Sizeof(wtFwpmAction0{}) if actualWtFwpmAction0Size != wtFwpmAction0_Size { @@ -44,7 +41,6 @@ func TestWtFwpmAction0Size(t *testing.T) { } func TestWtFwpmAction0Offsets(t *testing.T) { - s := wtFwpmAction0{} sp := uintptr(unsafe.Pointer(&s)) @@ -58,7 +54,6 @@ func TestWtFwpmAction0Offsets(t *testing.T) { } func TestWtFwpBitmapArray64Size(t *testing.T) { - const actualWtFwpBitmapArray64Size = unsafe.Sizeof(wtFwpBitmapArray64{}) if actualWtFwpBitmapArray64Size != wtFwpBitmapArray64_Size { @@ -68,7 +63,6 @@ func TestWtFwpBitmapArray64Size(t *testing.T) { } func TestWtFwpByteArray6Size(t *testing.T) { - const actualWtFwpByteArray6Size = unsafe.Sizeof(wtFwpByteArray6{}) if actualWtFwpByteArray6Size != wtFwpByteArray6_Size { @@ -78,7 +72,6 @@ func TestWtFwpByteArray6Size(t *testing.T) { } func TestWtFwpByteArray16Size(t *testing.T) { - const actualWtFwpByteArray16Size = unsafe.Sizeof(wtFwpByteArray16{}) if actualWtFwpByteArray16Size != wtFwpByteArray16_Size { @@ -88,7 +81,6 @@ func TestWtFwpByteArray16Size(t *testing.T) { } func TestWtFwpConditionValue0Size(t *testing.T) { - const actualWtFwpConditionValue0Size = unsafe.Sizeof(wtFwpConditionValue0{}) if actualWtFwpConditionValue0Size != wtFwpConditionValue0_Size { @@ -98,7 +90,6 @@ func TestWtFwpConditionValue0Size(t *testing.T) { } func TestWtFwpConditionValue0Offsets(t *testing.T) { - s := wtFwpConditionValue0{} sp := uintptr(unsafe.Pointer(&s)) @@ -111,7 +102,6 @@ func TestWtFwpConditionValue0Offsets(t *testing.T) { } func TestWtFwpV4AddrAndMaskSize(t *testing.T) { - const actualWtFwpV4AddrAndMaskSize = unsafe.Sizeof(wtFwpV4AddrAndMask{}) if actualWtFwpV4AddrAndMaskSize != wtFwpV4AddrAndMask_Size { @@ -121,7 +111,6 @@ func TestWtFwpV4AddrAndMaskSize(t *testing.T) { } func TestWtFwpV4AddrAndMaskOffsets(t *testing.T) { - s := wtFwpV4AddrAndMask{} sp := uintptr(unsafe.Pointer(&s)) @@ -135,7 +124,6 @@ func TestWtFwpV4AddrAndMaskOffsets(t *testing.T) { } func TestWtFwpV6AddrAndMaskSize(t *testing.T) { - const actualWtFwpV6AddrAndMaskSize = unsafe.Sizeof(wtFwpV6AddrAndMask{}) if actualWtFwpV6AddrAndMaskSize != wtFwpV6AddrAndMask_Size { @@ -145,7 +133,6 @@ func TestWtFwpV6AddrAndMaskSize(t *testing.T) { } func TestWtFwpV6AddrAndMaskOffsets(t *testing.T) { - s := wtFwpV6AddrAndMask{} sp := uintptr(unsafe.Pointer(&s)) @@ -159,7 +146,6 @@ func TestWtFwpV6AddrAndMaskOffsets(t *testing.T) { } func TestWtFwpValue0Size(t *testing.T) { - const actualWtFwpValue0Size = unsafe.Sizeof(wtFwpValue0{}) if actualWtFwpValue0Size != wtFwpValue0_Size { @@ -168,7 +154,6 @@ func TestWtFwpValue0Size(t *testing.T) { } func TestWtFwpValue0Offsets(t *testing.T) { - s := wtFwpValue0{} sp := uintptr(unsafe.Pointer(&s)) @@ -181,7 +166,6 @@ func TestWtFwpValue0Offsets(t *testing.T) { } func TestWtFwpmDisplayData0Size(t *testing.T) { - const actualWtFwpmDisplayData0Size = unsafe.Sizeof(wtFwpmDisplayData0{}) if actualWtFwpmDisplayData0Size != wtFwpmDisplayData0_Size { @@ -191,7 +175,6 @@ func TestWtFwpmDisplayData0Size(t *testing.T) { } func TestWtFwpmDisplayData0Offsets(t *testing.T) { - s := wtFwpmDisplayData0{} sp := uintptr(unsafe.Pointer(&s)) @@ -205,7 +188,6 @@ func TestWtFwpmDisplayData0Offsets(t *testing.T) { } func TestWtFwpmFilterCondition0Size(t *testing.T) { - const actualWtFwpmFilterCondition0Size = unsafe.Sizeof(wtFwpmFilterCondition0{}) if actualWtFwpmFilterCondition0Size != wtFwpmFilterCondition0_Size { @@ -215,7 +197,6 @@ func TestWtFwpmFilterCondition0Size(t *testing.T) { } func TestWtFwpmFilterCondition0Offsets(t *testing.T) { - s := wtFwpmFilterCondition0{} sp := uintptr(unsafe.Pointer(&s)) @@ -237,7 +218,6 @@ func TestWtFwpmFilterCondition0Offsets(t *testing.T) { } func TestWtFwpmFilter0Size(t *testing.T) { - const actualWtFwpmFilter0Size = unsafe.Sizeof(wtFwpmFilter0{}) if actualWtFwpmFilter0Size != wtFwpmFilter0_Size { @@ -247,7 +227,6 @@ func TestWtFwpmFilter0Size(t *testing.T) { } func TestWtFwpmFilter0Offsets(t *testing.T) { - s := wtFwpmFilter0{} sp := uintptr(unsafe.Pointer(&s)) @@ -364,7 +343,6 @@ func TestWtFwpmFilter0Offsets(t *testing.T) { } func TestWtFwpProvider0Size(t *testing.T) { - const actualWtFwpProvider0Size = unsafe.Sizeof(wtFwpProvider0{}) if actualWtFwpProvider0Size != wtFwpProvider0_Size { @@ -374,7 +352,6 @@ func TestWtFwpProvider0Size(t *testing.T) { } func TestWtFwpProvider0Offsets(t *testing.T) { - s := wtFwpProvider0{} sp := uintptr(unsafe.Pointer(&s)) @@ -412,7 +389,6 @@ func TestWtFwpProvider0Offsets(t *testing.T) { } func TestWtFwpmSession0Size(t *testing.T) { - const actualWtFwpmSession0Size = unsafe.Sizeof(wtFwpmSession0{}) if actualWtFwpmSession0Size != wtFwpmSession0_Size { @@ -422,7 +398,6 @@ func TestWtFwpmSession0Size(t *testing.T) { } func TestWtFwpmSession0Offsets(t *testing.T) { - s := wtFwpmSession0{} sp := uintptr(unsafe.Pointer(&s)) @@ -482,7 +457,6 @@ func TestWtFwpmSession0Offsets(t *testing.T) { } func TestWtFwpmSublayer0Size(t *testing.T) { - const actualWtFwpmSublayer0Size = unsafe.Sizeof(wtFwpmSublayer0{}) if actualWtFwpmSublayer0Size != wtFwpmSublayer0_Size { @@ -492,7 +466,6 @@ func TestWtFwpmSublayer0Size(t *testing.T) { } func TestWtFwpmSublayer0Offsets(t *testing.T) { - s := wtFwpmSublayer0{} sp := uintptr(unsafe.Pointer(&s)) diff --git a/tunnel/interfacewatcher.go b/tunnel/interfacewatcher.go index 08e8936a..b26d71de 100644 --- a/tunnel/interfacewatcher.go +++ b/tunnel/interfacewatcher.go @@ -24,10 +24,12 @@ type interfaceWatcherError struct { serviceError services.Error err error } + type interfaceWatcherEvent struct { luid winipcfg.LUID family winipcfg.AddressFamily } + type interfaceWatcher struct { errors chan interfaceWatcherError started chan winipcfg.AddressFamily diff --git a/tunnel/winipcfg/types_test.go b/tunnel/winipcfg/types_test.go index 26268dbe..d749325a 100644 --- a/tunnel/winipcfg/types_test.go +++ b/tunnel/winipcfg/types_test.go @@ -957,7 +957,6 @@ func TestIPAddressPrefix(t *testing.T) { offset := uintptr(unsafe.Pointer(&s.PrefixLength)) - sp if offset != ipAddressPrefixPrefixLengthOffset { t.Errorf("IPAddressPrefix.PrefixLength offset is %d although %d is expected", offset, ipAddressPrefixPrefixLengthOffset) - } } diff --git a/ui/aboutdialog.go b/ui/aboutdialog.go index 4d7cf7f1..feee2efc 100644 --- a/ui/aboutdialog.go +++ b/ui/aboutdialog.go @@ -18,8 +18,10 @@ import ( "golang.zx2c4.com/wireguard/windows/version" ) -var easterEggIndex = -1 -var showingAboutDialog *walk.Dialog +var ( + easterEggIndex = -1 + showingAboutDialog *walk.Dialog +) func onAbout(owner walk.Form) { showError(runAboutDialog(owner), owner) diff --git a/ui/confview.go b/ui/confview.go index 3d16f38f..b2bcb126 100644 --- a/ui/confview.go +++ b/ui/confview.go @@ -605,7 +605,7 @@ func (cv *ConfView) onToggleActiveClicked() { }() } -func (cv *ConfView) onTunnelChanged(tunnel *manager.Tunnel, state manager.TunnelState, globalState manager.TunnelState, err error) { +func (cv *ConfView) onTunnelChanged(tunnel *manager.Tunnel, state, globalState manager.TunnelState, err error) { cv.Synchronize(func() { cv.interfaze.toggleActive.updateGlobal(globalState) if cv.tunnel != nil && cv.tunnel.Name == tunnel.Name { diff --git a/ui/filesave.go b/ui/filesave.go index 8cedec27..63f50dd5 100644 --- a/ui/filesave.go +++ b/ui/filesave.go @@ -24,7 +24,7 @@ func writeFileWithOverwriteHandling(owner walk.Form, filePath string, write func return true } - file, err := os.OpenFile(filePath, os.O_CREATE|os.O_WRONLY|os.O_EXCL, 0600) + file, err := os.OpenFile(filePath, os.O_CREATE|os.O_WRONLY|os.O_EXCL, 0o600) if err != nil { if os.IsExist(err) { if walk.DlgCmdNo == walk.MsgBox(owner, l18n.Sprintf("Writing file failed"), l18n.Sprintf(`File ā%sā already exists. diff --git a/ui/listview.go b/ui/listview.go index 13608b4e..428d8330 100644 --- a/ui/listview.go +++ b/ui/listview.go @@ -181,7 +181,7 @@ func (tv *ListView) StyleCell(style *walk.CellStyle) { } } -func (tv *ListView) onTunnelChange(tunnel *manager.Tunnel, state manager.TunnelState, globalState manager.TunnelState, err error) { +func (tv *ListView) onTunnelChange(tunnel *manager.Tunnel, state, globalState manager.TunnelState, err error) { tv.Synchronize(func() { idx := -1 for i := range tv.model.tunnels { diff --git a/ui/managewindow.go b/ui/managewindow.go index 15e93e9c..d02e223a 100644 --- a/ui/managewindow.go +++ b/ui/managewindow.go @@ -161,7 +161,7 @@ func (mtw *ManageTunnelsWindow) updateProgressIndicator(globalState manager.Tunn } } -func (mtw *ManageTunnelsWindow) onTunnelChange(tunnel *manager.Tunnel, state manager.TunnelState, globalState manager.TunnelState, err error) { +func (mtw *ManageTunnelsWindow) onTunnelChange(tunnel *manager.Tunnel, state, globalState manager.TunnelState, err error) { mtw.Synchronize(func() { mtw.updateProgressIndicator(globalState) diff --git a/ui/raise.go b/ui/raise.go index 2d748a5c..c402bea7 100644 --- a/ui/raise.go +++ b/ui/raise.go @@ -55,7 +55,7 @@ func WaitForRaiseUIThenQuit() { var handle win.HWINEVENTHOOK runtime.LockOSThread() defer runtime.UnlockOSThread() - handle, err := win.SetWinEventHook(win.EVENT_OBJECT_CREATE, win.EVENT_OBJECT_CREATE, 0, func(hWinEventHook win.HWINEVENTHOOK, event uint32, hwnd win.HWND, idObject int32, idChild int32, idEventThread uint32, dwmsEventTime uint32) uintptr { + handle, err := win.SetWinEventHook(win.EVENT_OBJECT_CREATE, win.EVENT_OBJECT_CREATE, 0, func(hWinEventHook win.HWINEVENTHOOK, event uint32, hwnd win.HWND, idObject, idChild int32, idEventThread, dwmsEventTime uint32) uintptr { class := make([]uint16, len(manageWindowWindowClass)+2) /* Plus 2, one for the null terminator, and one to see if this is only a prefix */ n, err := win.GetClassName(hwnd, &class[0], len(class)) if err != nil || n != len(manageWindowWindowClass) || windows.UTF16ToString(class) != manageWindowWindowClass { diff --git a/ui/syntax/highlighter.go b/ui/syntax/highlighter.go index 47946093..d8e6a2a7 100644 --- a/ui/syntax/highlighter.go +++ b/ui/syntax/highlighter.go @@ -222,7 +222,7 @@ func (s stringSpan) isValidIPv6() bool { return true } -func (s stringSpan) isValidUint(supportHex bool, min uint64, max uint64) bool { +func (s stringSpan) isValidUint(supportHex bool, min, max uint64) bool { // Bound this around 32 bits, so that we don't have to write overflow logic. if s.len > 10 || s.len == 0 { return false @@ -444,7 +444,7 @@ func (hsa *highlightSpanArray) append(o *byte, s stringSpan, t highlight) { *hsa = append(*hsa, highlightSpan{t, int((uintptr(unsafe.Pointer(s.s))) - (uintptr(unsafe.Pointer(o)))), s.len}) } -func (hsa *highlightSpanArray) highlightMultivalueValue(parent stringSpan, s stringSpan, section field) { +func (hsa *highlightSpanArray) highlightMultivalueValue(parent, s stringSpan, section field) { switch section { case fieldDNS: if s.isValidIPv4() || s.isValidIPv6() { @@ -477,7 +477,7 @@ func (hsa *highlightSpanArray) highlightMultivalueValue(parent stringSpan, s str } } -func (hsa *highlightSpanArray) highlightMultivalue(parent stringSpan, s stringSpan, section field) { +func (hsa *highlightSpanArray) highlightMultivalue(parent, s stringSpan, section field) { currentSpan := stringSpan{s.s, 0} lenAtLastSpace := 0 for i := 0; i < s.len; i++ { @@ -506,7 +506,7 @@ func (hsa *highlightSpanArray) highlightMultivalue(parent stringSpan, s stringSp } } -func (hsa *highlightSpanArray) highlightValue(parent stringSpan, s stringSpan, section field) { +func (hsa *highlightSpanArray) highlightValue(parent, s stringSpan, section field) { switch section { case fieldPrivateKey: hsa.append(parent.s, s, validateHighlight(s.isValidKey(), highlightPrivateKey)) diff --git a/ui/syntax/syntaxedit.go b/ui/syntax/syntaxedit.go index 42f6e7b7..18b51436 100644 --- a/ui/syntax/syntaxedit.go +++ b/ui/syntax/syntaxedit.go @@ -90,22 +90,22 @@ type spanStyle struct { } var stylemap = map[highlight]spanStyle{ - highlightSection: spanStyle{color: win.RGB(0x32, 0x6D, 0x74), effects: win.CFE_BOLD}, - highlightField: spanStyle{color: win.RGB(0x9B, 0x23, 0x93), effects: win.CFE_BOLD}, - highlightPrivateKey: spanStyle{color: win.RGB(0x64, 0x38, 0x20)}, - highlightPublicKey: spanStyle{color: win.RGB(0x64, 0x38, 0x20)}, - highlightPresharedKey: spanStyle{color: win.RGB(0x64, 0x38, 0x20)}, - highlightIP: spanStyle{color: win.RGB(0x0E, 0x0E, 0xFF)}, - highlightCidr: spanStyle{color: win.RGB(0x81, 0x5F, 0x03)}, - highlightHost: spanStyle{color: win.RGB(0x0E, 0x0E, 0xFF)}, - highlightPort: spanStyle{color: win.RGB(0x81, 0x5F, 0x03)}, - highlightMTU: spanStyle{color: win.RGB(0x1C, 0x00, 0xCF)}, - highlightTable: spanStyle{color: win.RGB(0x1C, 0x00, 0xCF)}, - highlightKeepalive: spanStyle{color: win.RGB(0x1C, 0x00, 0xCF)}, - highlightComment: spanStyle{color: win.RGB(0x53, 0x65, 0x79), effects: win.CFE_ITALIC}, - highlightDelimiter: spanStyle{color: win.RGB(0x00, 0x00, 0x00)}, - highlightCmd: spanStyle{color: win.RGB(0x63, 0x75, 0x89)}, - highlightError: spanStyle{color: win.RGB(0xC4, 0x1A, 0x16), effects: win.CFE_UNDERLINE}, + highlightSection: {color: win.RGB(0x32, 0x6D, 0x74), effects: win.CFE_BOLD}, + highlightField: {color: win.RGB(0x9B, 0x23, 0x93), effects: win.CFE_BOLD}, + highlightPrivateKey: {color: win.RGB(0x64, 0x38, 0x20)}, + highlightPublicKey: {color: win.RGB(0x64, 0x38, 0x20)}, + highlightPresharedKey: {color: win.RGB(0x64, 0x38, 0x20)}, + highlightIP: {color: win.RGB(0x0E, 0x0E, 0xFF)}, + highlightCidr: {color: win.RGB(0x81, 0x5F, 0x03)}, + highlightHost: {color: win.RGB(0x0E, 0x0E, 0xFF)}, + highlightPort: {color: win.RGB(0x81, 0x5F, 0x03)}, + highlightMTU: {color: win.RGB(0x1C, 0x00, 0xCF)}, + highlightTable: {color: win.RGB(0x1C, 0x00, 0xCF)}, + highlightKeepalive: {color: win.RGB(0x1C, 0x00, 0xCF)}, + highlightComment: {color: win.RGB(0x53, 0x65, 0x79), effects: win.CFE_ITALIC}, + highlightDelimiter: {color: win.RGB(0x00, 0x00, 0x00)}, + highlightCmd: {color: win.RGB(0x63, 0x75, 0x89)}, + highlightError: {color: win.RGB(0xC4, 0x1A, 0x16), effects: win.CFE_UNDERLINE}, } func (se *SyntaxEdit) evaluateUntunneledBlocking(cfg string, spans []highlightSpan) { @@ -252,7 +252,7 @@ func (tray *Tray) rebalanceTunnelsMenu() { } } -func (tray *Tray) onTunnelChange(tunnel *manager.Tunnel, state manager.TunnelState, globalState manager.TunnelState, err error) { +func (tray *Tray) onTunnelChange(tunnel *manager.Tunnel, state, globalState manager.TunnelState, err error) { tray.mtw.Synchronize(func() { tray.updateGlobalState(globalState) if err == nil { diff --git a/ui/tunnelspage.go b/ui/tunnelspage.go index a62cb0ce..4c687a39 100644 --- a/ui/tunnelspage.go +++ b/ui/tunnelspage.go @@ -280,7 +280,7 @@ func (tp *TunnelsPage) updateConfView() { func (tp *TunnelsPage) importFiles(paths []string) { go func() { - syncedMsgBox := func(title string, message string, flags walk.MsgBoxStyle) { + syncedMsgBox := func(title, message string, flags walk.MsgBoxStyle) { tp.Synchronize(func() { walk.MsgBox(tp.Form(), title, message, flags) }) @@ -422,7 +422,6 @@ func (tp *TunnelsPage) addTunnel(config *conf.Config) { if err != nil { showErrorCustom(tp.Form(), l18n.Sprintf("Unable to create tunnel"), err.Error()) } - } // Handlers @@ -519,7 +518,6 @@ func (tp *TunnelsPage) onDelete() { tunnelsToDelete := make([]manager.Tunnel, len(indices)) for i, j := range indices { tunnelsToDelete[i] = tp.listView.model.tunnels[j] - } go func() { tp.listView.SetSuspendTunnelsUpdate(true) @@ -20,10 +20,12 @@ import ( "golang.zx2c4.com/wireguard/windows/version" ) -var noTrayAvailable = false -var shouldQuitManagerWhenExiting = false -var startTime = time.Now() -var IsAdmin = false // A global, because this really is global for the process +var ( + noTrayAvailable = false + shouldQuitManagerWhenExiting = false + startTime = time.Now() + IsAdmin = false // A global, because this really is global for the process +) func RunUI() { runtime.LockOSThread() diff --git a/updater/msirunner.go b/updater/msirunner.go index 13495f46..c68fdce7 100644 --- a/updater/msirunner.go +++ b/updater/msirunner.go @@ -38,7 +38,7 @@ func (t *tempFile) Delete() error { if err != nil { return err } - return windows.DeleteFile(name16) //TODO: how does this deal with reparse points? + return windows.DeleteFile(name16) // TODO: how does this deal with reparse points? } disposition := byte(1) err := windows.SetFileInformationByHandle(t.originalHandle, windows.FileDispositionInfo, &disposition, 1) diff --git a/updater/winhttp/winhttp.go b/updater/winhttp/winhttp.go index 41fa5082..44ba44db 100644 --- a/updater/winhttp/winhttp.go +++ b/updater/winhttp/winhttp.go @@ -21,11 +21,13 @@ import ( type Session struct { handle _HINTERNET } + type Connection struct { handle _HINTERNET session *Session https bool } + type Response struct { handle _HINTERNET connection *Connection diff --git a/version/official.go b/version/official.go index a330700f..250df76f 100644 --- a/version/official.go +++ b/version/official.go @@ -101,7 +101,7 @@ func extractCertificateNames(path string) ([]string, error) { return names, nil } -func extractCertificatePolicies(path string, oid string) ([]string, error) { +func extractCertificatePolicies(path, oid string) ([]string, error) { path16, err := windows.UTF16PtrFromString(path) if err != nil { return nil, err |