1e6063dd1SDima Dorfman.\" 2e6063dd1SDima Dorfman.\" Copyright (c) 2001 Dima Dorfman. 3e6063dd1SDima Dorfman.\" All rights reserved. 4e6063dd1SDima Dorfman.\" 5e6063dd1SDima Dorfman.\" Redistribution and use in source and binary forms, with or without 6e6063dd1SDima Dorfman.\" modification, are permitted provided that the following conditions 7e6063dd1SDima Dorfman.\" are met: 8e6063dd1SDima Dorfman.\" 1. Redistributions of source code must retain the above copyright 9e6063dd1SDima Dorfman.\" notice, this list of conditions and the following disclaimer. 10e6063dd1SDima Dorfman.\" 2. Redistributions in binary form must reproduce the above copyright 11e6063dd1SDima Dorfman.\" notice, this list of conditions and the following disclaimer in the 12e6063dd1SDima Dorfman.\" documentation and/or other materials provided with the distribution. 13e6063dd1SDima Dorfman.\" 14e6063dd1SDima Dorfman.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15e6063dd1SDima Dorfman.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16e6063dd1SDima Dorfman.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17e6063dd1SDima Dorfman.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18e6063dd1SDima Dorfman.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19e6063dd1SDima Dorfman.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20e6063dd1SDima Dorfman.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21e6063dd1SDima Dorfman.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22e6063dd1SDima Dorfman.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23e6063dd1SDima Dorfman.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24e6063dd1SDima Dorfman.\" SUCH DAMAGE. 25e6063dd1SDima Dorfman.\" 26*fa9f7422SGordon Bergling.Dd November 16, 2023 27e6063dd1SDima Dorfman.Dt GETPEEREID 3 28e6063dd1SDima Dorfman.Os 29e6063dd1SDima Dorfman.Sh NAME 30e6063dd1SDima Dorfman.Nm getpeereid 31e6063dd1SDima Dorfman.Nd get the effective credentials of a UNIX-domain peer 32e6063dd1SDima Dorfman.Sh LIBRARY 33e6063dd1SDima Dorfman.Lb libc 34e6063dd1SDima Dorfman.Sh SYNOPSIS 352c0dd4d1SDima Dorfman.In unistd.h 36e6063dd1SDima Dorfman.Ft int 37e6063dd1SDima Dorfman.Fn getpeereid "int s" "uid_t *euid" "gid_t *egid" 38e6063dd1SDima Dorfman.Sh DESCRIPTION 39e6063dd1SDima DorfmanThe 40e6063dd1SDima Dorfman.Fn getpeereid 412c0dd4d1SDima Dorfmanfunction returns the effective user and group IDs of the 422c0dd4d1SDima Dorfmanpeer connected to a 432c0dd4d1SDima Dorfman.Ux Ns -domain 442c0dd4d1SDima Dorfmansocket. 45e6063dd1SDima DorfmanThe argument 46e6063dd1SDima Dorfman.Fa s 47*fa9f7422SGordon Berglingmust be a connected 482c0dd4d1SDima Dorfman.Ux Ns -domain 492c0dd4d1SDima Dorfmansocket 50e6063dd1SDima Dorfman.Pq Xr unix 4 51e6063dd1SDima Dorfmanof type 52e6063dd1SDima Dorfman.Dv SOCK_STREAM 53e6063dd1SDima Dorfmanon which either 54e6063dd1SDima Dorfman.Xr connect 2 55e6063dd1SDima Dorfmanor 56e6063dd1SDima Dorfman.Xr listen 2 57f02396d5SEric van Gyzenhas been called. 58f02396d5SEric van GyzenThe effective user ID is placed in 59e6063dd1SDima Dorfman.Fa euid , 60e6063dd1SDima Dorfmanand the effective group ID in 61e6063dd1SDima Dorfman.Fa egid . 62e6063dd1SDima Dorfman.Pp 63e6063dd1SDima DorfmanThe credentials returned to the 64e6063dd1SDima Dorfman.Xr listen 2 65e6063dd1SDima Dorfmancaller are those of its peer at the time it called 66e6063dd1SDima Dorfman.Xr connect 2 ; 67e6063dd1SDima Dorfmanthe credentials returned to the 68e6063dd1SDima Dorfman.Xr connect 2 69e6063dd1SDima Dorfmancaller are those of its peer at the time it called 70e6063dd1SDima Dorfman.Xr listen 2 . 71e6063dd1SDima DorfmanThis mechanism is reliable; there is no way for either side to influence 72e6063dd1SDima Dorfmanthe credentials returned to its peer except by calling the appropriate 73e6063dd1SDima Dorfmansystem call (i.e., either 74e6063dd1SDima Dorfman.Xr connect 2 75e6063dd1SDima Dorfmanor 76e6063dd1SDima Dorfman.Xr listen 2 ) 77e6063dd1SDima Dorfmanunder different effective credentials. 78e6063dd1SDima Dorfman.Pp 792c0dd4d1SDima DorfmanOne common use of this routine is for a 802c0dd4d1SDima Dorfman.Ux Ns -domain 812c0dd4d1SDima Dorfmanserver 82e6063dd1SDima Dorfmanto verify the credentials of its client. 83e6063dd1SDima DorfmanLikewise, the client can verify the credentials of the server. 84e6063dd1SDima Dorfman.Sh IMPLEMENTATION NOTES 85e6063dd1SDima DorfmanOn 86e6063dd1SDima Dorfman.Fx , 87e6063dd1SDima Dorfman.Fn getpeereid 88e6063dd1SDima Dorfmanis implemented in terms of the 89e6063dd1SDima Dorfman.Dv LOCAL_PEERCRED 90e6063dd1SDima Dorfman.Xr unix 4 91e6063dd1SDima Dorfmansocket option. 92e6063dd1SDima Dorfman.Sh RETURN VALUES 93b9449db1SAnton Berezin.Rv -std getpeereid 94e6063dd1SDima Dorfman.Sh ERRORS 9595f4226bSRuslan ErmilovThe 96b9449db1SAnton Berezin.Fn getpeereid 9795f4226bSRuslan Ermilovfunction 982c0dd4d1SDima Dorfmanfails if: 99e6063dd1SDima Dorfman.Bl -tag -width Er 100e6063dd1SDima Dorfman.It Bq Er EBADF 101e6063dd1SDima DorfmanThe argument 102e6063dd1SDima Dorfman.Fa s 103e6063dd1SDima Dorfmanis not a valid descriptor. 104e6063dd1SDima Dorfman.It Bq Er ENOTSOCK 105e6063dd1SDima DorfmanThe argument 106e6063dd1SDima Dorfman.Fa s 107e6063dd1SDima Dorfmanis a file, not a socket. 108e6063dd1SDima Dorfman.It Bq Er ENOTCONN 109e6063dd1SDima DorfmanThe argument 110e6063dd1SDima Dorfman.Fa s 111e6063dd1SDima Dorfmandoes not refer to a socket on which 112e6063dd1SDima Dorfman.Xr connect 2 113e6063dd1SDima Dorfmanor 114e6063dd1SDima Dorfman.Xr listen 2 115e6063dd1SDima Dorfmanhave been called. 116e6063dd1SDima Dorfman.It Bq Er EINVAL 117e6063dd1SDima DorfmanThe argument 118e6063dd1SDima Dorfman.Fa s 119e6063dd1SDima Dorfmandoes not refer to a socket of type 12076183f34SDima Dorfman.Dv SOCK_STREAM , 12176183f34SDima Dorfmanor the kernel returned invalid data. 122e6063dd1SDima Dorfman.El 123e6063dd1SDima Dorfman.Sh SEE ALSO 124e6063dd1SDima Dorfman.Xr connect 2 , 125e6063dd1SDima Dorfman.Xr getpeername 2 , 126e6063dd1SDima Dorfman.Xr getsockname 2 , 127e6063dd1SDima Dorfman.Xr getsockopt 2 , 128e6063dd1SDima Dorfman.Xr listen 2 , 129e6063dd1SDima Dorfman.Xr unix 4 130e6063dd1SDima Dorfman.Sh HISTORY 131e6063dd1SDima DorfmanThe 132e6063dd1SDima Dorfman.Fn getpeereid 1332c0dd4d1SDima Dorfmanfunction appeared in 134ca4b6b39SDima Dorfman.Fx 4.6 . 135