getpeereid (3)
Leading comments
Copyright (c) 2001 Dima Dorfman. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or othe...
NAME
getpeereid - get the effective credentials of a UNIX-domain peerLIBRARY
Lb libbsdSYNOPSIS
In sys/types.h In unistd.h (See libbsd(7) for include usage.) Ft int Fn getpeereid int s uid_t *euid gid_t *egidDESCRIPTION
The Fn getpeereid function returns the effective user and group IDs of the peer connected to a UNIX socket. The argument Fa s must be a UNIX socket (unix(4) ) of type SOCK_STREAM on which either connect(2) or listen(2) have been called. The effective used ID is placed in Fa euid , and the effective group ID in Fa egid .The credentials returned to the listen(2) caller are those of its peer at the time it called connect(2); the credentials returned to the connect(2) caller are those of its peer at the time it called listen(2). This mechanism is reliable; there is no way for either side to influence the credentials returned to its peer except by calling the appropriate system call (i.e., either connect(2) or listen(2)) under different effective credentials.
One common use of this routine is for a UNIX server to verify the credentials of its client. Likewise, the client can verify the credentials of the server.
IMPLEMENTATION NOTES
On Fx , Fn getpeereid is implemented in terms of the LOCAL_PEERCRED unix(4) socket option.RETURN VALUES
Rv -std getpeereidERRORS
The Fn getpeereid function fails if:- Bq Er EBADF
- The argument Fa s is not a valid descriptor.
- Bq Er ENOTSOCK
- The argument Fa s is a file, not a socket.
- Bq Er ENOTCONN
- The argument Fa s does not refer to a socket on which connect(2) or listen(2) have been called.
- Bq Er EINVAL
- The argument Fa s does not refer to a socket of type SOCK_STREAM or the kernel returned invalid data.