GETPEEREID(3)
π«Ά getpeereid(3) β bestie, whose creds are these? π«Ά
okay so this is the GETPEEREID(3) page from the Library Functions Manual, and it lives in the Standard C Library (libc, -lc). no cap. π
β¨ NAME β¨
getpeereid β get the effective credentials of a UNIX-domain peer
π LIBRARY π
Standard C Library (libc, -lc)
πΈ SYNOPSIS πΈ
#include <unistd.h>
int
getpeereid(int s, uid_t *euid, gid_t *egid);
π DESCRIPTION π
okay bestie, here's the tea: getpeereid() hands you the effective user and group IDs of the peer connected to a Unix-domain socket. the argument s has to be a connected Unix-domain socket (unix(4)) of type SOCK_STREAM on which either connect(2) or listen(2) has been called. the effective user ID goes into euid, and the effective group ID goes into egid. π
now the important part: the credentials returned to the listen(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 listen(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 listen(2)) under different effective credentials. periodt. π₯
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. mutual vibe check, but with uids and gids. β¨
π§ IMPLEMENTATION NOTES π§
on FreeBSD, getpeereid() is implemented in terms of the LOCAL_PEERCRED unix(4) socket option. iykyk. π
π«‘ RETURN VALUES π«‘
the getpeereid() function returns the value 0 if successful; otherwise the value -1 is returned and the global variable errno is set to indicate the error. classic. π
π ERRORS π
the getpeereid() function fails if:
[EBADF]β the argumentsis not a valid descriptor.[ENOTSOCK]β the argumentsis a file, not a socket.[ENOTCONN]β the argumentsdoes not refer to a socket on whichconnect(2)orlisten(2)have been called.[EINVAL]β the argumentsdoes not refer to a socket of typeSOCK_STREAM, or the kernel returned invalid data.
bestie, if you see EINVAL because the kernel returned invalid data, that's not a vibe. π
π SEE ALSO π
π¦ HISTORY π¦
the getpeereid() function appeared in FreeBSD 4.6. iconic behavior from the 4.6 era. π
and that's the whole page, bestie: this version is from Debian, dated November 16, 2023, and the manual page is GETPEEREID(3). mwah, go check those peer creds πβ¨
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- Copyright (c) 2001 Dima Dorfman
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms