int
getpeereid(
int s
, uid_t *euid
, gid_t *egid
)
)
function returns the effective user and group IDs of the
peer connected to a
UNIX-domain
socket.
The argument
s
must be a
UNIX-domain
socket
(unix(4))
of type
SOCK_STREAM
on which either
connect(2)
has been called, or one returned from
accept(2)
after
bind(2)
and
listen(2)
have been called.
If non-NULL, the effective used ID is placed in
euid
,
and the effective group ID in
egid
.
The credentials returned to the accept(2) caller are those of its peer at the time it called connect(2); the credentials returned to the connect(2) caller are those of its peer at the time it called bind(2). This mechanism is reliable; there is no way for either side to influence the credentials returned to its peer except by calling the appropriate system call (i.e., either connect(2) or bind(2)) under different effective credentials.
One common use of this routine is for a UNIX-domain server to verify the credentials of its client. Likewise, the client can verify the credentials of the server.
)
is implemented in terms of the
LOCAL_PEEREID
unix(4)
socket option.
)
function
fails if:
EBADF
]
s
is not a valid descriptor.
ENOTSOCK
]
s
is a file, not a socket.
ENOTCONN
]
s
does not refer to a socket on which
connect(2)
have been called nor one returned from
listen(2).
EINVAL
]
s
does not refer to a socket of type
SOCK_STREAM
,
or the kernel returned invalid data.
)
function appeared in
NetBSD5.0.