Extract handle from pipe connection

This commit is contained in:
2025-04-06 22:44:56 -04:00
parent 081b05659a
commit ffe191394a
3 changed files with 12 additions and 5 deletions
+6 -4
View File
@@ -6,20 +6,22 @@ package peercred
import (
"fmt"
"net"
"github.com/Microsoft/go-winio"
"golang.org/x/sys/windows"
)
// Get returns the peer credentials for c.
func Get(h windows.Handle) *Creds {
creds, _ := get(&h)
func Get(c net.Conn) *Creds {
creds, _ := get(winio.UtilGetPipeHandle(c))
return creds
}
func get(h *windows.Handle) (*Creds, error) {
func get(h windows.Handle) (*Creds, error) {
// get PID
var clientPID uint32
windows.GetNamedPipeClientProcessId(*h, &clientPID)
windows.GetNamedPipeClientProcessId(h, &clientPID)
// get SID (UID)
var access uint32 = windows.PROCESS_QUERY_INFORMATION