From ab519c54dc18ca47d6838bdad4e5fabdbf16ede0 Mon Sep 17 00:00:00 2001 From: AlexSSD7 Date: Fri, 1 Sep 2023 16:29:01 +0100 Subject: [PATCH] Minor touchups --- cmd/root.go | 2 +- cmd/run.go | 1 + cmd/shell.go | 6 +++--- cmd/utils.go | 4 ++++ osspecifics/osspecifics_windows.go | 4 ---- share/ftp.go | 3 +-- share/ports.go | 3 ++- utils/errors.go | 2 +- vm/filemanager.go | 2 +- vm/types.go | 2 +- 10 files changed, 15 insertions(+), 14 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index f5f9f74..b3cb0e1 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -53,7 +53,7 @@ func init() { rootCmd.PersistentFlags().BoolVar(&vmDebugFlag, "vm-debug", false, "Enables the VM debug mode. This will open an accessible VM monitor. You can log in with root user and no password.") rootCmd.PersistentFlags().BoolVar(&unrestrictedNetworkingFlag, "vm-unrestricted-networking", false, "Enables unrestricted networking. This will allow the VM to connect to the internet.") - rootCmd.PersistentFlags().Uint32Var(&vmMemAllocFlag, "vm-mem-alloc", defaultMemAlloc, fmt.Sprintf("Specifies the VM memory allocation in KiB (the default is %v in LUKS mode)", defaultMemAllocLUKS)) + rootCmd.PersistentFlags().Uint32Var(&vmMemAllocFlag, "vm-mem-alloc", defaultMemAlloc, fmt.Sprintf("Specifies the VM memory allocation in KiB. (the default is %v in LUKS mode)", defaultMemAllocLUKS)) rootCmd.PersistentFlags().Uint32Var(&vmOSUpTimeoutFlag, "vm-os-up-timeout", 30, "Specifies the VM OS-up timeout in seconds.") rootCmd.PersistentFlags().Uint32Var(&vmSSHSetupTimeoutFlag, "vm-ssh-setup-timeout", 60, "Specifies the VM SSH server setup timeout in seconds. This cannot be lower than the OS-up timeout.") diff --git a/cmd/run.go b/cmd/run.go index 915ecbd..82b467e 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -50,6 +50,7 @@ var runCmd = &cobra.Command{ if vmMemAllocFlag != defaultMemAlloc { slog.Warn("Enforcing minimum LUKS memory allocation. Please add --allow-luks-low-memory to disable this.", "min", vmMemAllocFlag, "specified", vmMemAllocFlag) } + vmMemAllocFlag = defaultMemAllocLUKS } } diff --git a/cmd/shell.go b/cmd/shell.go index 8934786..a510418 100644 --- a/cmd/shell.go +++ b/cmd/shell.go @@ -32,9 +32,9 @@ var shellCmd = &cobra.Command{ continue } - fpr, err := vm.ParsePortForwardString(fp) + fpr, err := vm.ParsePortForwardingRuleString(fp) if err != nil { - slog.Error("Failed to parse port forward string", "index", i, "value", fp, "error", err.Error()) + slog.Error("Failed to parse port forwarding rule string", "index", i, "value", fp, "error", err.Error()) os.Exit(1) } @@ -43,7 +43,7 @@ var shellCmd = &cobra.Command{ os.Exit(runVM(passthroughArg, func(ctx context.Context, i *vm.VM, fm *vm.FileManager, trc *share.NetTapRuntimeContext) int { if trc != nil { - slog.Info("Tap networking is active", "host-ip", trc.Net.HostIP, "vm-ip", trc.Net.GuestIP) + slog.Info("Tap host-VM networking is active", "host-ip", trc.Net.HostIP, "vm-ip", trc.Net.GuestIP) } err := runVMShell(ctx, i) diff --git a/cmd/utils.go b/cmd/utils.go index 4aca1c1..a23cc21 100644 --- a/cmd/utils.go +++ b/cmd/utils.go @@ -68,6 +68,10 @@ func runVM(passthroughArg string, fn func(context.Context, *vm.VM, *vm.FileManag if len(passthroughConfig.USB) != 0 { // Log USB-related warnings. + // Unfortunately USB passthrough is unstable in macOS and Windows. On Windows, you also need to install external + // libusbK driver, which nullifies the UX. This is a problem with how QEMU works, and unfortunately there isn't + // much we can do about it from our side. + switch runtime.GOOS { case "windows": // TODO: To document: installation of libusbK driver with Zadig utility. diff --git a/osspecifics/osspecifics_windows.go b/osspecifics/osspecifics_windows.go index a78977c..8387085 100644 --- a/osspecifics/osspecifics_windows.go +++ b/osspecifics/osspecifics_windows.go @@ -76,10 +76,6 @@ func CheckRunAsRoot() (bool, error) { defer func() { _ = windows.FreeSid(sid) }() - // This appears to cast a null pointer so I'm not sure why this - // works, but this guy says it does and it Works for Me™: - // https://github.com/golang/go/issues/28804#issuecomment-438838144 - member, err := windows.Token(0).IsMember(sid) if err != nil { return false, errors.Wrap(err, "check win sid membership") diff --git a/share/ftp.go b/share/ftp.go index cde2d1f..1440a11 100644 --- a/share/ftp.go +++ b/share/ftp.go @@ -44,8 +44,7 @@ func NewFTPBackend(uc *UserConfiguration) (Backend, *VMShareOptions, error) { passivePortCount: passivePortCount, extIP: uc.ftpExtIP, }, &VMShareOptions{ - Ports: ports, - EnableTap: false, + Ports: ports, }, nil } diff --git a/share/ports.go b/share/ports.go index 12feb97..b11e9d2 100644 --- a/share/ports.go +++ b/share/ports.go @@ -14,7 +14,7 @@ func getNetworkSharePort(subsequent uint16) (uint16, error) { } func getClosestAvailPortWithSubsequent(port uint16, subsequent uint16) (uint16, error) { - // We use 10 as port range + // We use 10 as port range. for i := port; i < 65535; i += subsequent { ok, err := checkPortAvailable(i, subsequent) if err != nil { @@ -31,6 +31,7 @@ func getClosestAvailPortWithSubsequent(port uint16, subsequent uint16) (uint16, func checkPortAvailable(port uint16, subsequent uint16) (bool, error) { if port+subsequent < port { + // We check for uint16 overflow here. return false, fmt.Errorf("subsequent ports exceed allowed port range") } diff --git a/utils/errors.go b/utils/errors.go index 9401657..a495ca6 100644 --- a/utils/errors.go +++ b/utils/errors.go @@ -19,7 +19,7 @@ func GetLogErrMsg(s string, logLabel string) string { origLogLen := len(logToInclude) const maxLogLen = 256 if origLogLen > maxLogLen { - logToInclude = fmt.Sprintf("[%v chars trimmed]", origLogLen) + logToInclude[len(logToInclude)-maxLogLen:] + logToInclude = fmt.Sprintf("[%v chars trimmed]", origLogLen-maxLogLen) + logToInclude[len(logToInclude)-maxLogLen:] } return fmt.Sprintf("(%v: '%v')", logLabel, logToInclude) diff --git a/vm/filemanager.go b/vm/filemanager.go index fd8fc51..16f53c2 100644 --- a/vm/filemanager.go +++ b/vm/filemanager.go @@ -158,7 +158,7 @@ func (fm *FileManager) Mount(devName string, mo MountOptions) error { return fmt.Errorf("device name is empty") } - // It does allow mapper/ prefix for mapped devices. + // It does allow "mapper/" prefix for mapped devices. // This is to enable the support for LVM and LUKS. if !utils.ValidateDevName(devName) { return fmt.Errorf("bad device name") diff --git a/vm/types.go b/vm/types.go index 428c66b..c3baa0c 100644 --- a/vm/types.go +++ b/vm/types.go @@ -15,7 +15,7 @@ type PortForwardingRule struct { VMPort uint16 } -func ParsePortForwardString(s string) (PortForwardingRule, error) { +func ParsePortForwardingRuleString(s string) (PortForwardingRule, error) { split := strings.Split(s, ":") switch len(split) { case 2: