1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #43189 from thaJeztah/remove_unused_win32k

pkg/system: remove unused HasWin32KSupport() and rewrite IsWindowsClient()
This commit is contained in:
Tianon Gravi 2022-02-03 12:03:18 -08:00 committed by GitHub
commit 21981800a2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 56 deletions

View file

@ -1,65 +1,23 @@
package system // import "github.com/docker/docker/pkg/system" package system // import "github.com/docker/docker/pkg/system"
import ( import "golang.org/x/sys/windows"
"unsafe"
"github.com/sirupsen/logrus"
"golang.org/x/sys/windows"
)
const ( const (
// Deprecated: use github.com/docker/pkg/idtools.SeTakeOwnershipPrivilege // Deprecated: use github.com/docker/pkg/idtools.SeTakeOwnershipPrivilege
SeTakeOwnershipPrivilege = "SeTakeOwnershipPrivilege" SeTakeOwnershipPrivilege = "SeTakeOwnershipPrivilege"
)
const (
// Deprecated: use github.com/docker/pkg/idtools.ContainerAdministratorSidString // Deprecated: use github.com/docker/pkg/idtools.ContainerAdministratorSidString
ContainerAdministratorSidString = "S-1-5-93-2-1" ContainerAdministratorSidString = "S-1-5-93-2-1"
// Deprecated: use github.com/docker/pkg/idtools.ContainerUserSidString // Deprecated: use github.com/docker/pkg/idtools.ContainerUserSidString
ContainerUserSidString = "S-1-5-93-2-2" ContainerUserSidString = "S-1-5-93-2-2"
) )
var ( // VER_NT_WORKSTATION, see https://docs.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-osversioninfoexa
ntuserApiset = windows.NewLazyDLL("ext-ms-win-ntuser-window-l1-1-0") const verNTWorkstation = 0x00000001 // VER_NT_WORKSTATION
procGetVersionExW = modkernel32.NewProc("GetVersionExW")
)
// https://docs.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-osversioninfoexa
// TODO: use golang.org/x/sys/windows.OsVersionInfoEx (needs OSVersionInfoSize to be exported)
type osVersionInfoEx struct {
OSVersionInfoSize uint32
MajorVersion uint32
MinorVersion uint32
BuildNumber uint32
PlatformID uint32
CSDVersion [128]uint16
ServicePackMajor uint16
ServicePackMinor uint16
SuiteMask uint16
ProductType byte
Reserve byte
}
// IsWindowsClient returns true if the SKU is client. It returns false on // IsWindowsClient returns true if the SKU is client. It returns false on
// Windows server, or if an error occurred when making the GetVersionExW // Windows server, or if an error occurred when making the GetVersionExW
// syscall. // syscall.
func IsWindowsClient() bool { func IsWindowsClient() bool {
osviex := &osVersionInfoEx{OSVersionInfoSize: 284} ver := windows.RtlGetVersion()
r1, _, err := procGetVersionExW.Call(uintptr(unsafe.Pointer(osviex))) return ver != nil && ver.ProductType == verNTWorkstation
if r1 == 0 {
logrus.WithError(err).Warn("GetVersionExW failed - assuming server SKU")
return false
}
// VER_NT_WORKSTATION, see https://docs.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-osversioninfoexa
const verNTWorkstation = 0x00000001 // VER_NT_WORKSTATION
return osviex.ProductType == verNTWorkstation
}
// HasWin32KSupport determines whether containers that depend on win32k can
// run on this machine. Win32k is the driver used to implement windowing.
func HasWin32KSupport() bool {
// For now, check for ntuser API support on the host. In the future, a host
// may support win32k in containers even if the host does not support ntuser
// APIs.
return ntuserApiset.Load() == nil
} }

View file

@ -1,9 +0,0 @@
package system // import "github.com/docker/docker/pkg/system"
import "testing"
func TestHasWin32KSupport(t *testing.T) {
s := HasWin32KSupport() // make sure this doesn't panic
t.Logf("win32k: %v", s) // will be different on different platforms -- informative only
}