bastion 0.60.0
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
//go:build linux
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"net"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
func askPeerPID(c net.Conn) int {
|
||||
uc, ok := c.(*net.UnixConn)
|
||||
if !ok {
|
||||
return 0
|
||||
}
|
||||
raw, err := uc.SyscallConn()
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
pid := 0
|
||||
_ = raw.Control(func(fd uintptr) {
|
||||
if cred, err := unix.GetsockoptUcred(int(fd), unix.SOL_SOCKET, unix.SO_PEERCRED); err == nil {
|
||||
pid = int(cred.Pid)
|
||||
}
|
||||
})
|
||||
return pid
|
||||
}
|
||||
Reference in New Issue
Block a user