Windows fixes

This commit is contained in:
AlexSSD7 2023-09-03 14:08:24 +01:00
commit 1b69e6294d
7 changed files with 30 additions and 20 deletions

View file

@ -28,11 +28,12 @@ import (
"strings"
"time"
"log/slog"
"github.com/AlexSSD7/linsk/utils"
"github.com/alessio/shellescape"
"github.com/google/uuid"
"github.com/pkg/errors"
"golang.org/x/exp/slog"
)
func Available() bool {
@ -66,7 +67,8 @@ func NewTapManager(logger *slog.Logger) (*TapManager, error) {
var tapNameRegexp = regexp.MustCompile(`^LinskTap-\d+$`)
func NewUniqueTapName() (string, error) {
return fmt.Sprintf("LinskTap-%v", time.Now().UnixNano())
time.Sleep(time.Millisecond)
return fmt.Sprintf("LinskTap-%v", time.Now().UnixNano()), nil
}
func (tm *TapManager) CreateNewTap(tapName string) error {

View file

@ -40,8 +40,8 @@ func TerminateProcess(pid int) error {
return exec.Command("TASKKILL", "/T", "/F", "/PID", fmt.Sprint(pid)).Run()
}
var physicalDriveCheckRegexp = regexp.MustCompile(`^\\\\.\\PhysicalDrive(\d+)$`)
var physicalDriveFindRegexp = regexp.MustCompile(`PhysicalDrive(\d+)`)
var physicalDriveCheckRegexp = regexp.MustCompile(`(?i)^\\\\.\\PhysicalDrive(\d+)$`)
var physicalDriveFindRegexp = regexp.MustCompile(`(?i)PhysicalDrive(\d+)`)
// This is never used except for a band-aid that would check
// that there are no double-mounts.

View file

@ -34,7 +34,7 @@ const (
)
var safeArgs = map[string]ArgAcceptedValue{
"accel": ArgAcceptedValueString,
"accel": ArgAcceptedValueKeyValue,
"boot": ArgAcceptedValueString,
"m": ArgAcceptedValueUint,
"smp": ArgAcceptedValueUint,

View file

@ -69,11 +69,6 @@ func NewKeyValueArg(key string, items []KeyValueArgItem) (*KeyValueArg, error) {
return nil, fmt.Errorf("empty key not allowed")
}
if len(item.Value) == 0 {
// Values *can* be empty, though. We do not allow them for consistency.
return nil, fmt.Errorf("empty value for key '%v' is not allowed", item.Key)
}
err := validateArgStrValue(item.Key)
if err != nil {
return nil, errors.Wrapf(err, "validate key '%v'", item.Key)

View file

@ -45,5 +45,9 @@ func validateArgStrValue(s string) error {
return fmt.Errorf("backslashes are not allowed")
}
if strings.Contains(s, "=") {
return fmt.Errorf("equals sign is not allowed")
}
return nil
}

View file

@ -35,10 +35,12 @@ import (
)
func getUniqueQEMUNetID() string {
time.Sleep(time.Millisecond)
return "net" + utils.IntToStr(time.Now().UnixNano())
}
func getUniqueQEMUDriveID() string {
time.Sleep(time.Millisecond)
return "drive" + utils.IntToStr(time.Now().UnixNano())
}
@ -56,28 +58,31 @@ func cleanQEMUPath(s string) string {
func configureBaseVMCmd(logger *slog.Logger, cfg Config) (string, []qemucli.Arg, error) {
baseCmd := "qemu-system"
if osspecifics.IsWindows() {
baseCmd += ".exe"
}
args := []qemucli.Arg{
qemucli.MustNewStringArg("serial", "stdio"),
qemucli.MustNewUintArg("m", cfg.MemoryAlloc),
qemucli.MustNewUintArg("smp", runtime.NumCPU()),
}
var accel string
var accel []qemucli.KeyValueArgItem
switch {
case osspecifics.IsWindows():
// TODO: To document: For Windows, we need to install QEMU using an installer and add it to PATH.
// Then, we should enable Windows Hypervisor Platform in "Turn Windows features on or off".
// IMPORTANT: We should also install libusbK drivers for USB devices we want to pass through.
// This can be easily done with a program called Zadiag by Akeo.
accel = "whpx,kernel-irqchip=off"
accel = []qemucli.KeyValueArgItem{
{Key: "whpx"},
{Key: "kernel-irqchip", Value: "off"},
}
case osspecifics.IsMacOS():
accel = "hvf"
accel = []qemucli.KeyValueArgItem{{
Key: "hvf",
}}
default:
accel = "kvm"
accel = []qemucli.KeyValueArgItem{{
Key: "kvm",
}}
}
switch runtime.GOARCH {
@ -102,7 +107,7 @@ func configureBaseVMCmd(logger *slog.Logger, cfg Config) (string, []qemucli.Arg,
return "", nil, fmt.Errorf("arch '%v' is not supported", runtime.GOARCH)
}
args = append(args, qemucli.MustNewStringArg("accel", accel))
args = append(args, qemucli.MustNewKeyValueArg("accel", accel))
if cfg.BIOSPath != "" {
biosPath := cleanQEMUPath(cfg.BIOSPath)
@ -130,6 +135,10 @@ func configureBaseVMCmd(logger *slog.Logger, cfg Config) (string, []qemucli.Arg,
args = append(args, cdromArg, qemucli.MustNewStringArg("boot", "d"))
}
if osspecifics.IsWindows() {
baseCmd += ".exe"
}
return baseCmd, args, nil
}

View file

@ -113,7 +113,7 @@ func (fm *FileManager) luksOpen(sc *ssh.Client, fullDevPath string) error {
return errors.Wrap(err, "write prompt to stderr")
}
pwd, err := term.ReadPassword(syscall.Stdin)
pwd, err := term.ReadPassword(int(syscall.Stdin))
if err != nil {
return errors.Wrap(err, "read luks password")
}