summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/rs/xid/hostid_windows.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2018-05-27 21:48:57 +0200
committerWim <wim@42.be>2018-05-27 21:48:57 +0200
commitfc6074ea9fba9684aaad1ab6d43a0ec23db8c5d3 (patch)
tree28a92899258e0f1e546fdba72ff09a4b1b759a83 /vendor/github.com/rs/xid/hostid_windows.go
parentab1670e2cec92d4ff1058f854198ea6c9c0750d0 (diff)
downloadmatterbridge-msglm-fc6074ea9fba9684aaad1ab6d43a0ec23db8c5d3.tar.gz
matterbridge-msglm-fc6074ea9fba9684aaad1ab6d43a0ec23db8c5d3.tar.bz2
matterbridge-msglm-fc6074ea9fba9684aaad1ab6d43a0ec23db8c5d3.zip
Add vendor github.com/rs/xid
Diffstat (limited to 'vendor/github.com/rs/xid/hostid_windows.go')
-rw-r--r--vendor/github.com/rs/xid/hostid_windows.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/vendor/github.com/rs/xid/hostid_windows.go b/vendor/github.com/rs/xid/hostid_windows.go
new file mode 100644
index 00000000..b8e1c2cb
--- /dev/null
+++ b/vendor/github.com/rs/xid/hostid_windows.go
@@ -0,0 +1,39 @@
+// +build windows
+
+package xid
+
+import (
+ "fmt"
+ "unsafe"
+
+ "golang.org/x/sys/windows"
+)
+
+func readPlatformMachineID() (string, error) {
+ // source: https://github.com/shirou/gopsutil/blob/master/host/host_windows.go
+ var h windows.Handle
+ err := windows.RegOpenKeyEx(windows.HKEY_LOCAL_MACHINE, windows.StringToUTF16Ptr(`SOFTWARE\Microsoft\Cryptography`), 0, windows.KEY_READ|windows.KEY_WOW64_64KEY, &h)
+ if err != nil {
+ return "", err
+ }
+ defer windows.RegCloseKey(h)
+
+ const windowsRegBufLen = 74 // len(`{`) + len(`abcdefgh-1234-456789012-123345456671` * 2) + len(`}`) // 2 == bytes/UTF16
+ const uuidLen = 36
+
+ var regBuf [windowsRegBufLen]uint16
+ bufLen := uint32(windowsRegBufLen)
+ var valType uint32
+ err = windows.RegQueryValueEx(h, windows.StringToUTF16Ptr(`MachineGuid`), nil, &valType, (*byte)(unsafe.Pointer(&regBuf[0])), &bufLen)
+ if err != nil {
+ return "", err
+ }
+
+ hostID := windows.UTF16ToString(regBuf[:])
+ hostIDLen := len(hostID)
+ if hostIDLen != uuidLen {
+ return "", fmt.Errorf("HostID incorrect: %q\n", hostID)
+ }
+
+ return hostID, nil
+}