]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libc/gen/getpeereid.3
Fix "version introduced" in numerous manual pages
[FreeBSD/FreeBSD.git] / lib / libc / gen / getpeereid.3
1 .\"
2 .\" Copyright (c) 2001 Dima Dorfman.
3 .\" All rights reserved.
4 .\"
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
7 .\" are met:
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\"    notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\"    notice, this list of conditions and the following disclaimer in the
12 .\"    documentation and/or other materials provided with the distribution.
13 .\"
14 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 .\" SUCH DAMAGE.
25 .\"
26 .Dd November 16, 2023
27 .Dt GETPEEREID 3
28 .Os
29 .Sh NAME
30 .Nm getpeereid
31 .Nd get the effective credentials of a UNIX-domain peer
32 .Sh LIBRARY
33 .Lb libc
34 .Sh SYNOPSIS
35 .In unistd.h
36 .Ft int
37 .Fn getpeereid "int s" "uid_t *euid" "gid_t *egid"
38 .Sh DESCRIPTION
39 The
40 .Fn getpeereid
41 function returns the effective user and group IDs of the
42 peer connected to a
43 .Ux Ns -domain
44 socket.
45 The argument
46 .Fa s
47 must be a connected
48 .Ux Ns -domain
49 socket
50 .Pq Xr unix 4
51 of type
52 .Dv SOCK_STREAM
53 on which either
54 .Xr connect 2
55 or
56 .Xr listen 2
57 has been called.
58 The effective user ID is placed in
59 .Fa euid ,
60 and the effective group ID in
61 .Fa egid .
62 .Pp
63 The credentials returned to the
64 .Xr listen 2
65 caller are those of its peer at the time it called
66 .Xr connect 2 ;
67 the credentials returned to the
68 .Xr connect 2
69 caller are those of its peer at the time it called
70 .Xr listen 2 .
71 This mechanism is reliable; there is no way for either side to influence
72 the credentials returned to its peer except by calling the appropriate
73 system call (i.e., either
74 .Xr connect 2
75 or
76 .Xr listen 2 )
77 under different effective credentials.
78 .Pp
79 One common use of this routine is for a
80 .Ux Ns -domain
81 server
82 to verify the credentials of its client.
83 Likewise, the client can verify the credentials of the server.
84 .Sh IMPLEMENTATION NOTES
85 On
86 .Fx ,
87 .Fn getpeereid
88 is implemented in terms of the
89 .Dv LOCAL_PEERCRED
90 .Xr unix 4
91 socket option.
92 .Sh RETURN VALUES
93 .Rv -std getpeereid
94 .Sh ERRORS
95 The
96 .Fn getpeereid
97 function
98 fails if:
99 .Bl -tag -width Er
100 .It Bq Er EBADF
101 The argument
102 .Fa s
103 is not a valid descriptor.
104 .It Bq Er ENOTSOCK
105 The argument
106 .Fa s
107 is a file, not a socket.
108 .It Bq Er ENOTCONN
109 The argument
110 .Fa s
111 does not refer to a socket on which
112 .Xr connect 2
113 or
114 .Xr listen 2
115 have been called.
116 .It Bq Er EINVAL
117 The argument
118 .Fa s
119 does not refer to a socket of type
120 .Dv SOCK_STREAM ,
121 or the kernel returned invalid data.
122 .El
123 .Sh SEE ALSO
124 .Xr connect 2 ,
125 .Xr getpeername 2 ,
126 .Xr getsockname 2 ,
127 .Xr getsockopt 2 ,
128 .Xr listen 2 ,
129 .Xr unix 4
130 .Sh HISTORY
131 The
132 .Fn getpeereid
133 function appeared in
134 .Fx 4.6 .