Exemple #1
0
/*
https://msdn.microsoft.com/en-us/library/ms724832(VS.85).aspx
Windows 10					10.0*
Windows Server 2016			10.0*
Windows 8.1					6.3*
Windows Server 2012 R2		6.3*
Windows 8					6.2
Windows Server 2012			6.2
Windows 7					6.1
Windows Server 2008 R2		6.1
Windows Server 2008			6.0
Windows Vista				6.0
Windows Server 2003 R2		5.2
Windows Server 2003			5.2
Windows XP 64-Bit Edition	5.2
Windows XP					5.1
Windows 2000				5.0
*/
func GetVersion() (int, int, int) {
	v, err := syscall.GetVersion()
	if err != nil {
		panic(err)
	}
	return int(uint8(v)), int(uint8(v >> 8)), int(uint16(v >> 16))
}
Exemple #2
0
func StartMonitor() {

	var apiVersion uint32

	// xp (5.1) uses version 1 of the api, Vista (6.0) uses version 2
	switch v, _ := syscall.GetVersion(); {
	case v&0xff == 5:
		if (v>>8)&0xFF > 0 {
			apiVersion = 1
		} else {
			// Windows 2000
			fmt.Fprintln(os.Stderr, "Requires Windows XP or later")
			os.Exit(10)
		}
	case v&0xff > 5:
		apiVersion = 2
	default:
		// Earlier than Windows 2000. Its probably crashed before reaching here!
		fmt.Fprintln(os.Stderr, "Requires Windows XP or later")
		os.Exit(10)
	}

	e := WlanOpenHandle(apiVersion, 0, &apiVersion, &handle)

	if e != ERROR_SUCCESS {
		fmt.Fprintln(os.Stderr, "WlanOpenHandle: ", e.Error())
		os.Exit(int(e))
	}
}
Exemple #3
0
func isWindowsXP(t *testing.T) bool {
	v, err := syscall.GetVersion()
	if err != nil {
		t.Fatalf("GetVersion failed: %v", err)
	}
	major := byte(v)
	return major < 6
}
Exemple #4
0
// osVersion returns the OS version.
func osVersion() string {
	v, err := syscall.GetVersion()
	if err != nil {
		return "0.0"
	}
	major := uint8(v)
	minor := uint8(v >> 8)
	return fmt.Sprintf("%d.%d", major, minor)
}
Exemple #5
0
func probeWindowsIPStack() (supportsVistaIP bool) {
	v, err := syscall.GetVersion()
	if err != nil {
		return true // Windows 10 and above will deprecate this API
	}
	if byte(v) < 6 { // major version of Windows Vista is 6
		return false
	}
	return true
}
Exemple #6
0
func init() {
	v, err := syscall.GetVersion()
	if err != nil {
		return
	}
	if major := byte(v); major < 6 {
		// Windows XP SP2 and Windows 2003 do not support SHA2.
		// http://blogs.technet.com/b/pki/archive/2010/09/30/sha2-and-windows.aspx
		supportSHA2 = false
	}
}
// GetOSVersion gets the operating system version on Windows. Note that
// docker.exe must be manifested to get the correct version information.
func GetOSVersion() (OSVersion, error) {
	var err error
	osv := OSVersion{}
	osv.Version, err = syscall.GetVersion()
	if err != nil {
		return osv, fmt.Errorf("Failed to call GetVersion()")
	}
	osv.MajorVersion = uint8(osv.Version & 0xFF)
	osv.MinorVersion = uint8(osv.Version >> 8 & 0xFF)
	osv.Build = uint16(osv.Version >> 16)
	return osv, nil
}
Exemple #8
0
// GetOSVersion gets the operating system version on Windows. Note that
// docker.exe must be manifested to get the correct version information.
func GetOSVersion() OSVersion {
	var err error
	osv := OSVersion{}
	osv.Version, err = syscall.GetVersion()
	if err != nil {
		// GetVersion never fails.
		panic(err)
	}
	osv.MajorVersion = uint8(osv.Version & 0xFF)
	osv.MinorVersion = uint8(osv.Version >> 8 & 0xFF)
	osv.Build = uint16(osv.Version >> 16)
	return osv
}
Exemple #9
0
// GetWindowsVersion returns the Windows version information. Applications not
// manifested for Windows 8.1 or Windows 10 will return the Windows 8 OS version
// value (6.2).
//
// For a table of version numbers see:
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms724833(v=vs.85).aspx
func GetWindowsVersion() (major, minor, build int) {
	// https://msdn.microsoft.com/en-us/library/windows/desktop/ms724439(v=vs.85).aspx
	ver, err := syscall.GetVersion()
	if err != nil {
		// GetVersion should never return an error.
		panic(fmt.Errorf("GetVersion failed: %v", err))
	}

	major = int(ver & 0xFF)
	minor = int(ver >> 8 & 0xFF)
	build = int(ver >> 16)
	return major, minor, build
}
Exemple #10
0
// GetWindowsVersion returns the Windows version information. Applications not
// manifested for Windows 8.1 or Windows 10 will return the Windows 8 OS version
// value (6.2).
//
// For a table of version numbers see:
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms724833(v=vs.85).aspx
func GetWindowsVersion() Version {
	// https://msdn.microsoft.com/en-us/library/windows/desktop/ms724439(v=vs.85).aspx
	ver, err := syscall.GetVersion()
	if err != nil {
		// GetVersion should never return an error.
		panic(fmt.Errorf("GetVersion failed: %v", err))
	}

	return Version{
		Major: int(ver & 0xFF),
		Minor: int(ver >> 8 & 0xFF),
		Build: int(ver >> 16),
	}
}
Exemple #11
0
func GetKernelVersion() (*KernelVersionInfo, error) {

	var (
		h         syscall.Handle
		dwVersion uint32
		err       error
	)

	KVI := &KernelVersionInfo{"Unknown", 0, 0, 0}

	if err = syscall.RegOpenKeyEx(syscall.HKEY_LOCAL_MACHINE,
		syscall.StringToUTF16Ptr(`SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\`),
		0,
		syscall.KEY_READ,
		&h); err != nil {
		return KVI, err
	}
	defer syscall.RegCloseKey(h)

	var buf [1 << 10]uint16
	var typ uint32
	n := uint32(len(buf) * 2) // api expects array of bytes, not uint16

	if err = syscall.RegQueryValueEx(h,
		syscall.StringToUTF16Ptr("BuildLabEx"),
		nil,
		&typ,
		(*byte)(unsafe.Pointer(&buf[0])),
		&n); err != nil {
		return KVI, err
	}

	KVI.kvi = syscall.UTF16ToString(buf[:])

	// Important - docker.exe MUST be manifested for this API to return
	// the correct information.
	if dwVersion, err = syscall.GetVersion(); err != nil {
		return KVI, err
	}

	KVI.major = int(dwVersion & 0xFF)
	KVI.minor = int((dwVersion & 0XFF00) >> 8)
	KVI.build = int((dwVersion & 0xFFFF0000) >> 16)

	return KVI, nil
}
Exemple #12
0
// checkSystem validates platform-specific requirements
func checkSystem() error {
	var dwVersion uint32

	// TODO Windows. May need at some point to ensure have elevation and
	// possibly LocalSystem.

	// Validate the OS version. Note that docker.exe must be manifested for this
	// call to return the correct version.
	dwVersion, err := syscall.GetVersion()
	if err != nil {
		return fmt.Errorf("Failed to call GetVersion()")
	}
	if int(dwVersion&0xFF) < 10 {
		return fmt.Errorf("This version of Windows does not support the docker daemon")
	}

	return nil
}
Exemple #13
0
// Version returns bot version, os and Go runtime info on Windows.
func Version() (os string, rt string) {
	os = runtime.GOOS
	var flavor string
	if ver, err := syscall.GetVersion(); err == nil {
		var major, minor, build = byte(ver), uint8(ver >> 8), uint16(ver >> 16)
		switch {
		case major == 4:
			switch minor {
			case 0:
				flavor = "NT"
			case 10:
				flavor = "98"
			case 90:
				flavor = "Me"
			}
		case major == 5:
			switch {
			case minor == 2:
				flavor = "2003"
			case minor == 1 && build == 2600:
				flavor = "XP"
			case minor == 0:
				flavor = "2000"
			}
		case major == 6:
			switch minor {
			case 3:
				flavor = "8.1"
			case 2:
				flavor = "8"
			case 1:
				flavor = "7"
			case 0:
				flavor = "Vista"
			}
		}
		os = fmt.Sprintf("%s %s: [Version %d.%d.%d]",
			strings.Title(runtime.GOOS), flavor,
			major, minor, build)
	}
	rt = fmt.Sprintf("%s %s/%s", runtime.Version(), runtime.GOOS, runtime.GOARCH)
	return os, BOTVERSION + " (" + rt + ")"
}
// checkSystem validates the system is supported and we have sufficient privileges
func checkSystem() error {
	var dwVersion uint32

	// TODO Windows. Once daemon is running on Windows, move this code back to
	// NewDaemon() in daemon.go, and extend the check to support Windows.
	if runtime.GOOS != "linux" && runtime.GOOS != "windows" {
		return ErrSystemNotSupported
	}

	// TODO Windows. May need at some point to ensure have elevation and
	// possibly LocalSystem.

	// Validate the OS version. Note that docker.exe must be manifested for this
	// call to return the correct version.
	dwVersion, err := syscall.GetVersion()
	if err != nil {
		return fmt.Errorf("Failed to call GetVersion()")
	}
	if int(dwVersion&0xFF) < 10 {
		return fmt.Errorf("This version of Windows does not support the docker daemon")
	}

	return nil
}