From 7123e6d1f4e3b505c59e626eeaed1212413e8bea Mon Sep 17 00:00:00 2001 From: Viktor Liu Date: Sat, 16 May 2026 17:23:36 +0200 Subject: [PATCH] Fix Windows lint errcheck/unused and Linux nilerr in console VNC fallback --- client/internal/engine_vnc_console_linux.go | 3 +++ client/vnc/server/agent_windows.go | 12 +++--------- client/vnc/server/input_windows.go | 8 +------- client/vnc/server/keysym_typetext.go | 2 ++ client/vnc/server/server_windows.go | 2 +- 5 files changed, 10 insertions(+), 17 deletions(-) diff --git a/client/internal/engine_vnc_console_linux.go b/client/internal/engine_vnc_console_linux.go index e04476e71..68ea3616c 100644 --- a/client/internal/engine_vnc_console_linux.go +++ b/client/internal/engine_vnc_console_linux.go @@ -5,6 +5,8 @@ package internal import ( "fmt" + log "github.com/sirupsen/logrus" + vncserver "github.com/netbirdio/netbird/client/vnc/server" ) @@ -21,6 +23,7 @@ func newConsoleVNC() (vncserver.ScreenCapturer, vncserver.InputInjector, error) } inj, err := vncserver.NewUInputInjector(w, h) if err != nil { + log.Debugf("uinput unavailable, falling back to view-only VNC: %v", err) return poller, &vncserver.StubInputInjector{}, nil } return poller, inj, nil diff --git a/client/vnc/server/agent_windows.go b/client/vnc/server/agent_windows.go index a0d279080..6a777b442 100644 --- a/client/vnc/server/agent_windows.go +++ b/client/vnc/server/agent_windows.go @@ -91,12 +91,6 @@ const ( wtsDisconnected = 4 ) -type wtsSessionInfo struct { - SessionID uint32 - WinStationName [66]byte // actually *uint16, but we just need the struct size - State uint32 -} - // getActiveSessionID returns the session ID of the best session to attach to. // On a Windows Server with no console display attached, session 1 still // reports WTSActive (login screen "owns" the console), so a naive @@ -176,7 +170,7 @@ func reapOrphanOnPort(portStr string) { log.Warnf("reap on port %d: open PID=%d: %v", port, pid, err) return } - defer windows.CloseHandle(h) + defer func() { _ = windows.CloseHandle(h) }() if !isOurAgentProcess(h) { log.Warnf("reap on port %d: PID=%d is not a netbird vnc-agent, leaving it alone", port, pid) return @@ -307,7 +301,7 @@ func getSystemTokenForSession(sessionID uint32) (windows.Token, error) { return dup, nil } -const agentTokenEnvVar = "NB_VNC_AGENT_TOKEN" +const agentTokenEnvVar = "NB_VNC_AGENT_TOKEN" // #nosec G101 -- env var name, not a credential // injectEnvVar appends a KEY=VALUE entry to a Unicode environment block. // The block is a sequence of null-terminated UTF-16 strings, terminated by @@ -698,7 +692,7 @@ func (m *sessionManager) killAgent() { // error output, panic stack traces) are forwarded verbatim so failures // during early agent startup remain visible. func relogAgentOutput(pipe windows.Handle) { - defer windows.CloseHandle(pipe) + defer func() { _ = windows.CloseHandle(pipe) }() f := os.NewFile(uintptr(pipe), "vnc-agent-stderr") defer f.Close() diff --git a/client/vnc/server/input_windows.go b/client/vnc/server/input_windows.go index 1a0ea22d2..0dea1f343 100644 --- a/client/vnc/server/input_windows.go +++ b/client/vnc/server/input_windows.go @@ -41,12 +41,6 @@ const ( keyeventfScanCode = 0x0008 ) -// winlogonDesktopName is the name of the Windows secure desktop that hosts the -// logon UI, Ctrl+Alt+Del screen, UAC prompts, and credential dialogs. Its -// clipboard is isolated from the interactive Default desktop, so pasting via -// the clipboard API does not work there. We fall back to synthesizing the -// text as Unicode keystrokes. -const winlogonDesktopName = "Winlogon" // maxTypedClipboardChars caps the number of characters we will synthesize as // keystrokes when falling back on the Winlogon desktop. Passwords are short; @@ -258,7 +252,7 @@ func signalSAS() { return } ev := windows.Handle(h) - defer windows.CloseHandle(ev) + defer func() { _ = windows.CloseHandle(ev) }() if err := windows.SetEvent(ev); err != nil { log.Warnf("SetEvent SAS: %v", err) } else { diff --git a/client/vnc/server/keysym_typetext.go b/client/vnc/server/keysym_typetext.go index e74c23967..788d65eb4 100644 --- a/client/vnc/server/keysym_typetext.go +++ b/client/vnc/server/keysym_typetext.go @@ -1,3 +1,5 @@ +//go:build !windows + package server // keysymForASCIIRune maps an ASCII rune to (X11 keysym for the unshifted diff --git a/client/vnc/server/server_windows.go b/client/vnc/server/server_windows.go index 97d6b5393..6caec5cdd 100644 --- a/client/vnc/server/server_windows.go +++ b/client/vnc/server/server_windows.go @@ -166,7 +166,7 @@ func createSASEvent() (windows.Handle, bool) { // signalled, until ctx is cancelled. Recovers from panics inside SendSAS so // a future ABI surprise doesn't tear down the service. func runSASListenerLoop(ctx context.Context, ev windows.Handle) { - defer windows.CloseHandle(ev) + defer func() { _ = windows.CloseHandle(ev) }() defer func() { if r := recover(); r != nil { log.Warnf("SAS listener recovered from panic: %v", r)