mirror of
https://github.com/lukaszraczylo/lolcathost.git
synced 2026-06-10 00:00:40 +00:00
Initial commit.
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
//go:build linux
|
||||
|
||||
package daemon
|
||||
|
||||
import (
|
||||
"net"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
// getPeerCredentials extracts peer credentials from a Unix socket connection on Linux.
|
||||
func (s *Server) getPeerCredentials(conn net.Conn) *PeerCredentials {
|
||||
unixConn, ok := conn.(*net.UnixConn)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
rawConn, err := unixConn.SyscallConn()
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
var creds *PeerCredentials
|
||||
rawConn.Control(func(fd uintptr) {
|
||||
ucred, err := unix.GetsockoptUcred(int(fd), unix.SOL_SOCKET, unix.SO_PEERCRED)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
creds = &PeerCredentials{
|
||||
UID: ucred.Uid,
|
||||
GID: ucred.Gid,
|
||||
PID: ucred.Pid,
|
||||
}
|
||||
})
|
||||
|
||||
return creds
|
||||
}
|
||||
Reference in New Issue
Block a user