mirror of
https://github.com/rwinkhart/sys.git
synced 2026-09-05 16:47:27 -04:00
windows: add basic WTS functions for windows/svc usage
The svc package exposes svc.SessionChange, but it's impossible to do anything with them without these structures, and without being able to enumerate them prior to events, the events themselves aren't useful, so we add the enumeration functions as well. Change-Id: I14c932dfe97c6712fd4868c1b3a0e3a61a6a562c Reviewed-on: https://go-review.googlesource.com/c/sys/+/176623 Run-TryBot: Jason Donenfeld <Jason@zx2c4.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
This commit is contained in:
committed by
Alex Brainman
parent
24a5b2278f
commit
f91f9b37d0
@@ -46,6 +46,7 @@ var (
|
||||
modsecur32 = NewLazySystemDLL("secur32.dll")
|
||||
modnetapi32 = NewLazySystemDLL("netapi32.dll")
|
||||
moduserenv = NewLazySystemDLL("userenv.dll")
|
||||
modwtsapi32 = NewLazySystemDLL("wtsapi32.dll")
|
||||
|
||||
procRegisterEventSourceW = modadvapi32.NewProc("RegisterEventSourceW")
|
||||
procDeregisterEventSource = modadvapi32.NewProc("DeregisterEventSource")
|
||||
@@ -269,6 +270,9 @@ var (
|
||||
procDuplicateTokenEx = modadvapi32.NewProc("DuplicateTokenEx")
|
||||
procGetUserProfileDirectoryW = moduserenv.NewProc("GetUserProfileDirectoryW")
|
||||
procGetSystemDirectoryW = modkernel32.NewProc("GetSystemDirectoryW")
|
||||
procWTSQueryUserToken = modwtsapi32.NewProc("WTSQueryUserToken")
|
||||
procWTSEnumerateSessionsW = modwtsapi32.NewProc("WTSEnumerateSessionsW")
|
||||
procWTSFreeMemory = modwtsapi32.NewProc("WTSFreeMemory")
|
||||
)
|
||||
|
||||
func RegisterEventSource(uncServerName *uint16, sourceName *uint16) (handle Handle, err error) {
|
||||
@@ -2943,3 +2947,32 @@ func getSystemDirectory(dir *uint16, dirLen uint32) (len uint32, err error) {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func WTSQueryUserToken(session uint32, token *Token) (err error) {
|
||||
r1, _, e1 := syscall.Syscall(procWTSQueryUserToken.Addr(), 2, uintptr(session), uintptr(unsafe.Pointer(token)), 0)
|
||||
if r1 == 0 {
|
||||
if e1 != 0 {
|
||||
err = errnoErr(e1)
|
||||
} else {
|
||||
err = syscall.EINVAL
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func WTSEnumerateSessions(handle Handle, reserved uint32, version uint32, sessions **WTS_SESSION_INFO, count *uint32) (err error) {
|
||||
r1, _, e1 := syscall.Syscall6(procWTSEnumerateSessionsW.Addr(), 5, uintptr(handle), uintptr(reserved), uintptr(version), uintptr(unsafe.Pointer(sessions)), uintptr(unsafe.Pointer(count)), 0)
|
||||
if r1 == 0 {
|
||||
if e1 != 0 {
|
||||
err = errnoErr(e1)
|
||||
} else {
|
||||
err = syscall.EINVAL
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func WTSFreeMemory(ptr uintptr) {
|
||||
syscall.Syscall(procWTSFreeMemory.Addr(), 1, uintptr(ptr), 0, 0)
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user