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