MCPcopy
hub / github.com/lxc/incus / GetUcred

Function GetUcred

internal/linux/ucred.go:10–30  ·  view source on GitHub ↗

GetUcred returns the credentials from the remote end of a unix socket.

(conn *net.UnixConn)

Source from the content-addressed store, hash-verified

8
9// GetUcred returns the credentials from the remote end of a unix socket.
10func GetUcred(conn *net.UnixConn) (*unix.Ucred, error) {
11 rawConn, err := conn.SyscallConn()
12 if err != nil {
13 return nil, err
14 }
15
16 var ucred *unix.Ucred
17 var ucredErr error
18 err = rawConn.Control(func(fd uintptr) {
19 ucred, ucredErr = unix.GetsockoptUcred(int(fd), unix.SOL_SOCKET, unix.SO_PEERCRED)
20 })
21 if err != nil {
22 return nil, err
23 }
24
25 if ucredErr != nil {
26 return nil, ucredErr
27 }
28
29 return ucred, nil
30}

Callers 5

NewSeccompServerFunction · 0.92
GetCredFromContextFunction · 0.92
proxyConnectionFunction · 0.92
TestCredsSendRecvFunction · 0.92
ConnStateHandlerMethod · 0.92

Calls

no outgoing calls

Tested by 1

TestCredsSendRecvFunction · 0.74

Used in the wild real call sites across dependent graphs

searching dependent graphs…