Merge branch 'dev_cs_collector' of https://github.com/benridley/windows_exporter into dev_cs_collector

This commit is contained in:
Ben Ridley
2021-03-29 10:14:26 -07:00

View File

@@ -74,17 +74,19 @@ func netApiBufferFree(buffer *wKSTAInfo102) {
// NetWkstaGetInfo returns information about the configuration of a workstation. // NetWkstaGetInfo returns information about the configuration of a workstation.
// https://docs.microsoft.com/en-us/windows/win32/api/lmwksta/nf-lmwksta-netwkstagetinfo // https://docs.microsoft.com/en-us/windows/win32/api/lmwksta/nf-lmwksta-netwkstagetinfo
func netWkstaGetInfo() (*wKSTAInfo102, uint32, error) { func netWkstaGetInfo() (wKSTAInfo102, uint32, error) {
var lpwi *wKSTAInfo102 var lpwi *wKSTAInfo102
pLevel := uintptr(102) pLevel := uintptr(102)
r1, _, _ := procNetWkstaGetInfo.Call(0, pLevel, uintptr(unsafe.Pointer(&lpwi))) r1, _, _ := procNetWkstaGetInfo.Call(0, pLevel, uintptr(unsafe.Pointer(&lpwi)))
defer netApiBufferFree(lpwi)
if ret := *(*uint32)(unsafe.Pointer(&r1)); ret != 0 { if ret := *(*uint32)(unsafe.Pointer(&r1)); ret != 0 {
return nil, ret, errors.New(NetApiStatus[ret]) return wKSTAInfo102{}, ret, errors.New(NetApiStatus[ret])
} }
return lpwi, 0, nil deref := *lpwi
return deref, 0, nil
} }
// GetWorkstationInfo is an idiomatic wrapper for netWkstaGetInfo // GetWorkstationInfo is an idiomatic wrapper for netWkstaGetInfo
@@ -102,7 +104,5 @@ func GetWorkstationInfo() (WorkstationInfo, error) {
LanRoot: windows.UTF16PtrToString(info.wki102_lanroot), LanRoot: windows.UTF16PtrToString(info.wki102_lanroot),
LoggedOnUsers: info.wki102_logged_on_users, LoggedOnUsers: info.wki102_logged_on_users,
} }
// Free the memory allocated by netapi
netApiBufferFree(info)
return workstationInfo, nil return workstationInfo, nil
} }