mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
pkg/system: rewrite IsWindowsClient() using golang.org/x/sys/windows
Looks like we should be able to use the implementation from x/sys/windows. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
be463cbd6c
commit
ab9796b0e9
1 changed files with 5 additions and 31 deletions
|
@ -1,10 +1,6 @@
|
|||
package system // import "github.com/docker/docker/pkg/system"
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
import "golang.org/x/sys/windows"
|
||||
|
||||
const (
|
||||
// Deprecated: use github.com/docker/pkg/idtools.SeTakeOwnershipPrivilege
|
||||
|
@ -15,35 +11,13 @@ const (
|
|||
ContainerUserSidString = "S-1-5-93-2-2"
|
||||
)
|
||||
|
||||
var 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
|
||||
}
|
||||
// VER_NT_WORKSTATION, see https://docs.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-osversioninfoexa
|
||||
const verNTWorkstation = 0x00000001 // VER_NT_WORKSTATION
|
||||
|
||||
// IsWindowsClient returns true if the SKU is client. It returns false on
|
||||
// Windows server, or if an error occurred when making the GetVersionExW
|
||||
// syscall.
|
||||
func IsWindowsClient() bool {
|
||||
osviex := &osVersionInfoEx{OSVersionInfoSize: 284}
|
||||
r1, _, err := procGetVersionExW.Call(uintptr(unsafe.Pointer(osviex)))
|
||||
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
|
||||
ver := windows.RtlGetVersion()
|
||||
return ver != nil && ver.ProductType == verNTWorkstation
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue