Get the effective credentials of a UNIX-domain peer
#include <sys/types.h> #include <unistd.h> int getpeereid( int s, uid_t *euid, gid_t *egid );
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The getpeereid() function gets the effective user and group IDs of the peer connected to a UNIX-domain socket. If euid and egid are non-NULL, the function stores the IDs in the locations they point to.
If you got the socket by calling connect(), the credentials are those of your peer when you called bind(). If the socket was one returned from accept(), the credentials are those of your peer when you called connect(). 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() or bind()) under different effective credentials.
UNIX-domain servers and clients commonly use this function to verify each other's credentials.
accept(), bind(), connect(), listen(), UNIX protocol