GetUcred returns the credentials from the remote end of a unix socket.
(conn *net.UnixConn)
| 8 | |
| 9 | // GetUcred returns the credentials from the remote end of a unix socket. |
| 10 | func 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 | } |
no outgoing calls
searching dependent graphs…