1GETPEEREID(3bsd)                     LOCAL                    GETPEEREID(3bsd)
2

NAME

4     getpeereid — get the effective credentials of a UNIX-domain peer
5

LIBRARY

7     Utility functions from BSD systems (libbsd, -lbsd)
8

SYNOPSIS

10     #include <sys/types.h>
11     #include <unistd.h>
12     (See libbsd(7) for include usage.)
13
14     int
15     getpeereid(int s, uid_t *euid, gid_t *egid);
16

DESCRIPTION

18     The getpeereid() function returns the effective user and group IDs of the
19     peer connected to a UNIX-domain socket.  The argument s must be a
20     UNIX-domain socket (unix(4)) of type SOCK_STREAM on which either
21     connect(2) or listen(2) have been called.  The effective used ID is
22     placed in euid, and the effective group ID in egid.
23
24     The credentials returned to the listen(2) caller are those of its peer at
25     the time it called connect(2); the credentials returned to the connect(2)
26     caller are those of its peer at the time it called listen(2).  This mech‐
27     anism is reliable; there is no way for either side to influence the cre‐
28     dentials returned to its peer except by calling the appropriate system
29     call (i.e., either connect(2) or listen(2)) under different effective
30     credentials.
31
32     One common use of this routine is for a UNIX-domain server to verify the
33     credentials of its client.  Likewise, the client can verify the creden‐
34     tials of the server.
35

IMPLEMENTATION NOTES

37     On FreeBSD, getpeereid() is implemented in terms of the LOCAL_PEERCRED
38     unix(4) socket option.
39

RETURN VALUES

41     The getpeereid() function returns the value 0 if successful; otherwise
42     the value -1 is returned and the global variable errno is set to indicate
43     the error.
44

ERRORS

46     The getpeereid() function fails if:
47
48     [EBADF]            The argument s is not a valid descriptor.
49
50     [ENOTSOCK]         The argument s is a file, not a socket.
51
52     [ENOTCONN]         The argument s does not refer to a socket on which
53                        connect(2) or listen(2) have been called.
54
55     [EINVAL]           The argument s does not refer to a socket of type
56                        SOCK_STREAM, or the kernel returned invalid data.
57

SEE ALSO

59     connect(2), getpeername(2), getsockname(2), getsockopt(2), listen(2),
60     unix(4)
61

HISTORY

63     The getpeereid() function appeared in FreeBSD 4.6.
64
65BSD                              July 15, 2001                             BSD
Impressum