mirror of
https://github.com/containers/podman.git
synced 2025-11-02 23:39:52 +08:00
Fix Lint on Windows and enable the job
[NO NEW TESTS NEEDED] Purely refactoring Signed-off-by: Matt Heon <mheon@redhat.com>
This commit is contained in:
@ -19,6 +19,7 @@ const registriesConf = `unqualified-search-registries=["docker.io"]
|
||||
|
||||
const appendPort = `grep -q Port\ %d /etc/ssh/sshd_config || echo Port %d >> /etc/ssh/sshd_config`
|
||||
|
||||
//nolint:unused
|
||||
const changePort = `sed -E -i 's/^Port[[:space:]]+[0-9]+/Port %d/' /etc/ssh/sshd_config`
|
||||
|
||||
const configServices = `ln -fs /usr/lib/systemd/system/sshd.service /etc/systemd/system/multi-user.target.wants/sshd.service
|
||||
@ -240,7 +241,7 @@ http://docs.microsoft.com/en-us/windows/wsl/install\
|
||||
|
||||
const (
|
||||
gvProxy = "gvproxy.exe"
|
||||
winSShProxy = "win-sshproxy.exe"
|
||||
winSSHProxy = "win-sshproxy.exe"
|
||||
pipePrefix = "npipe:////./pipe/"
|
||||
globalPipe = "docker_engine"
|
||||
userModeDist = "podman-net-usermode"
|
||||
|
||||
@ -40,10 +40,12 @@ func (e *ExitCodeError) Error() string {
|
||||
return fmt.Sprintf("Process failed with exit code: %d", e.code)
|
||||
}
|
||||
|
||||
//nolint:unused
|
||||
func getConfigPath(name string) (string, error) {
|
||||
return getConfigPathExt(name, "json")
|
||||
}
|
||||
|
||||
//nolint:unused
|
||||
func getConfigPathExt(name string, extension string) (string, error) {
|
||||
vmConfigDir, err := machine.GetConfDir(vmtype)
|
||||
if err != nil {
|
||||
@ -396,7 +398,9 @@ func attemptFeatureInstall(reExec, admin bool) error {
|
||||
}
|
||||
|
||||
func launchElevate(operation string) error {
|
||||
truncateElevatedOutputFile()
|
||||
if err := truncateElevatedOutputFile(); err != nil {
|
||||
return err
|
||||
}
|
||||
err := relaunchElevatedWait()
|
||||
if err != nil {
|
||||
if eerr, ok := err.(*ExitCodeError); ok {
|
||||
@ -565,6 +569,7 @@ func wslPipe(input string, dist string, arg ...string) error {
|
||||
return pipeCmdPassThrough(wutil.FindWSL(), input, newArgs...)
|
||||
}
|
||||
|
||||
//nolint:unused
|
||||
func wslCreateKeys(identityPath string, dist string) (string, error) {
|
||||
return machine.CreateSSHKeysPrefix(identityPath, true, true, wutil.FindWSL(), "-u", "root", "-d", dist)
|
||||
}
|
||||
@ -619,6 +624,7 @@ func setupWslProxyEnv() (hasProxy bool) {
|
||||
return
|
||||
}
|
||||
|
||||
//nolint:unused
|
||||
func obtainGlobalConfigLock() (*fileLock, error) {
|
||||
lockDir, err := machine.GetGlobalDataDir()
|
||||
if err != nil {
|
||||
@ -734,6 +740,7 @@ func isRunning(name string) (bool, error) {
|
||||
return sysd, err
|
||||
}
|
||||
|
||||
//nolint:unused
|
||||
func getDiskSize(name string) uint64 {
|
||||
vmDataDir, err := machine.GetDataDir(vmtype)
|
||||
if err != nil {
|
||||
@ -748,6 +755,7 @@ func getDiskSize(name string) uint64 {
|
||||
return uint64(info.Size())
|
||||
}
|
||||
|
||||
//nolint:unused
|
||||
func getCPUs(name string) (uint64, error) {
|
||||
dist := machine.ToDist(name)
|
||||
if run, _ := isWSLRunning(dist); !run {
|
||||
@ -772,6 +780,7 @@ func getCPUs(name string) (uint64, error) {
|
||||
return uint64(ret), err
|
||||
}
|
||||
|
||||
//nolint:unused
|
||||
func getMem(name string) (uint64, error) {
|
||||
dist := machine.ToDist(name)
|
||||
if run, _ := isWSLRunning(dist); !run {
|
||||
@ -808,6 +817,7 @@ func getMem(name string) (uint64, error) {
|
||||
return total - available, err
|
||||
}
|
||||
|
||||
//nolint:unused
|
||||
func getResources(mc *vmconfigs.MachineConfig) (resources vmconfigs.ResourceConfig) {
|
||||
resources.CPUs, _ = getCPUs(mc.Name)
|
||||
resources.Memory, _ = getMem(mc.Name)
|
||||
|
||||
@ -160,7 +160,7 @@ func (w WSLStubber) SetProviderAttrs(mc *vmconfigs.MachineConfig, opts define.Se
|
||||
|
||||
dist := machine.ToDist(mc.Name)
|
||||
if err := changeDistUserModeNetworking(dist, mc.SSH.RemoteUsername, mc.ImagePath.GetPath(), *opts.UserModeNetworking); err != nil {
|
||||
return fmt.Errorf("failure changing state of user-mode networking setting", err)
|
||||
return fmt.Errorf("failure changing state of user-mode networking setting: %w", err)
|
||||
}
|
||||
|
||||
mc.WSLHypervisor.UserModeNetworking = *opts.UserModeNetworking
|
||||
|
||||
@ -5,12 +5,12 @@ package wsl
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/containers/podman/v5/pkg/machine/vmconfigs"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/containers/podman/v5/pkg/machine"
|
||||
"github.com/containers/podman/v5/pkg/machine/vmconfigs"
|
||||
"github.com/containers/podman/v5/pkg/machine/wsl/wutil"
|
||||
"github.com/containers/podman/v5/pkg/specgen"
|
||||
"github.com/sirupsen/logrus"
|
||||
@ -84,7 +84,9 @@ func startUserModeNetworking(mc *vmconfigs.MachineConfig) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer flock.unlock()
|
||||
defer func() {
|
||||
_ = flock.unlock()
|
||||
}()
|
||||
|
||||
running, err := isWSLRunning(userModeDist)
|
||||
if err != nil {
|
||||
@ -121,7 +123,9 @@ func stopUserModeNetworking(mc *vmconfigs.MachineConfig) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer flock.unlock()
|
||||
defer func() {
|
||||
_ = flock.unlock()
|
||||
}()
|
||||
|
||||
err = removeUserModeNetEntry(mc.Name)
|
||||
if err != nil {
|
||||
@ -322,7 +326,7 @@ func obtainUserModeNetLock() (*fileLock, error) {
|
||||
func changeDistUserModeNetworking(dist string, user string, image string, enable bool) error {
|
||||
// Only install if user-mode is being enabled and there was an image path passed
|
||||
if enable {
|
||||
if len(image) <= 0 {
|
||||
if len(image) == 0 {
|
||||
return errors.New("existing machine configuration is corrupt, no image is defined")
|
||||
}
|
||||
if err := installUserModeDist(dist, image); err != nil {
|
||||
|
||||
@ -19,7 +19,6 @@ import (
|
||||
"golang.org/x/sys/windows/registry"
|
||||
)
|
||||
|
||||
// nolint
|
||||
type SHELLEXECUTEINFO struct {
|
||||
cbSize uint32
|
||||
fMask uint32
|
||||
@ -38,7 +37,6 @@ type SHELLEXECUTEINFO struct {
|
||||
hProcess syscall.Handle
|
||||
}
|
||||
|
||||
// nolint
|
||||
type Luid struct {
|
||||
lowPart uint32
|
||||
highPart int32
|
||||
@ -54,19 +52,30 @@ type TokenPrivileges struct {
|
||||
privileges [1]LuidAndAttributes
|
||||
}
|
||||
|
||||
// nolint // Cleaner to refer to the official OS constant names, and consistent with syscall
|
||||
// Cleaner to refer to the official OS constant names, and consistent with syscall
|
||||
const (
|
||||
SEE_MASK_NOCLOSEPROCESS = 0x40
|
||||
EWX_FORCEIFHUNG = 0x10
|
||||
EWX_REBOOT = 0x02
|
||||
EWX_RESTARTAPPS = 0x40
|
||||
SHTDN_REASON_MAJOR_APPLICATION = 0x00040000
|
||||
//nolint:stylecheck
|
||||
SEE_MASK_NOCLOSEPROCESS = 0x40
|
||||
//nolint:stylecheck
|
||||
EWX_FORCEIFHUNG = 0x10
|
||||
//nolint:stylecheck
|
||||
EWX_REBOOT = 0x02
|
||||
//nolint:stylecheck
|
||||
EWX_RESTARTAPPS = 0x40
|
||||
//nolint:stylecheck
|
||||
SHTDN_REASON_MAJOR_APPLICATION = 0x00040000
|
||||
//nolint:stylecheck
|
||||
SHTDN_REASON_MINOR_INSTALLATION = 0x00000002
|
||||
SHTDN_REASON_FLAG_PLANNED = 0x80000000
|
||||
TOKEN_ADJUST_PRIVILEGES = 0x0020
|
||||
TOKEN_QUERY = 0x0008
|
||||
SE_PRIVILEGE_ENABLED = 0x00000002
|
||||
SE_ERR_ACCESSDENIED = 0x05
|
||||
//nolint:stylecheck
|
||||
SHTDN_REASON_FLAG_PLANNED = 0x80000000
|
||||
//nolint:stylecheck
|
||||
TOKEN_ADJUST_PRIVILEGES = 0x0020
|
||||
//nolint:stylecheck
|
||||
TOKEN_QUERY = 0x0008
|
||||
//nolint:stylecheck
|
||||
SE_PRIVILEGE_ENABLED = 0x00000002
|
||||
//nolint:stylecheck
|
||||
SE_ERR_ACCESSDENIED = 0x05
|
||||
)
|
||||
|
||||
func winVersionAtLeast(major uint, minor uint, build uint) bool {
|
||||
@ -101,7 +110,9 @@ func hasAdminRights() bool {
|
||||
logrus.Warnf("SID allocation error: %s", err)
|
||||
return false
|
||||
}
|
||||
defer windows.FreeSid(sid)
|
||||
defer func() {
|
||||
_ = windows.FreeSid(sid)
|
||||
}()
|
||||
|
||||
// From MS docs:
|
||||
// "If TokenHandle is NULL, CheckTokenMembership uses the impersonation
|
||||
@ -148,8 +159,10 @@ func relaunchElevatedWait() error {
|
||||
return wrapMaybef(err, "could not launch process, ShellEX Error = %d", info.hInstApp)
|
||||
}
|
||||
|
||||
handle := syscall.Handle(info.hProcess)
|
||||
defer syscall.CloseHandle(handle)
|
||||
handle := info.hProcess
|
||||
defer func() {
|
||||
_ = syscall.CloseHandle(handle)
|
||||
}()
|
||||
|
||||
w, err := syscall.WaitForSingleObject(handle, syscall.INFINITE)
|
||||
switch w {
|
||||
@ -265,6 +278,7 @@ func obtainShutdownPrivilege() error {
|
||||
}
|
||||
|
||||
var privs TokenPrivileges
|
||||
//nolint:staticcheck
|
||||
if ret, _, err := LookupPrivilegeValue.Call(uintptr(0), uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(SeShutdownName))), uintptr(unsafe.Pointer(&(privs.privileges[0].luid)))); ret != 1 {
|
||||
return fmt.Errorf("looking up shutdown privilege: %w", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user