mirror of
https://github.com/containers/podman.git
synced 2025-11-02 14:55:28 +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,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