#include "c.h"
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
Go to the source code of this file.
◆ getpeereid()
int getpeereid |
( |
int |
sock, |
|
|
uid_t * |
uid, |
|
|
gid_t * |
gid |
|
) |
| |
Definition at line 33 of file getpeereid.c.
35 #if defined(SO_PEERCRED)
37 struct ucred peercred;
40 if (getsockopt(sock, SOL_SOCKET, SO_PEERCRED, &peercred, &so_len) != 0 ||
41 so_len !=
sizeof(peercred))
46 #elif defined(LOCAL_PEERCRED)
48 struct xucred peercred;
51 if (getsockopt(sock, 0, LOCAL_PEERCRED, &peercred, &so_len) != 0 ||
52 so_len !=
sizeof(peercred) ||
53 peercred.cr_version != XUCRED_VERSION)
55 *uid = peercred.cr_uid;
56 *gid = peercred.cr_gid;
58 #elif defined(HAVE_GETPEERUCRED)
63 if (getpeerucred(sock, &ucred) == -1)
66 *uid = ucred_geteuid(ucred);
67 *gid = ucred_getegid(ucred);
70 if (*uid == (
uid_t) (-1) || *gid == (
gid_t) (-1))
Referenced by auth_peer(), and PQconnectPoll().