RCMD(3)
๐ RCMD(3) โ a little group chat about remote-command sockets
okay so this one lives in the Library Functions Manual, and it's part of the Standard C Library (libc, -lc) ๐ซถ. The whole page is about routines for returning a stream to a remote command โ extremely old-school network glamour, no cap.
โจ SYNOPSIS โจ
#include <unistd.h>
int
rcmd(char **ahost, int inport, const char *locuser, const char *remuser,
const char *cmd, int *fd2p);
int
rresvport(int *port);
int
iruserok(u_long raddr, int superuser, const char *ruser,
const char *luser);
int
ruserok(const char *rhost, int superuser, const char *ruser,
const char *luser);
int
rcmd_af(char **ahost, int inport, const char *locuser,
const char *remuser, const char *cmd, int *fd2p, int af);
int
rresvport_af(int *port, int af);
int
iruserok_sa(const void *addr, int addrlen, int superuser,
const char *ruser, const char *luser);
๐ธ DESCRIPTION ๐ธ
So bestie, here's the vibe: rcmd() is the function the super-user uses to execute a command on a remote machine, and it does the authentication with an old-school scheme based on reserved port numbers ๐. Then rresvport() hands you a descriptor to a socket whose address sits in the privileged port space. And ruserok() is what servers use to authenticate clients that come asking for service via rcmd() ๐
.
All three of these functions live in the same file, and they're used by the rshd(8) server (among others) โ iykyk.
๐ฆ the rcmd() moment
rcmd() looks up the host *ahost using gethostbyname(3), and returns -1 if the host does not exist. But if it does exist? Then *ahost gets set to the standard name of the host, and a connection gets established to a server residing at the well-known Internet port inport โญ.
If the connection succeeds, you get a socket back in the Internet domain of type SOCK_STREAM, and that socket is given to the remote command as stdin and stdout ๐.
Now โ if fd2p is non-zero, an auxiliary channel to a control process gets set up, and a descriptor for it gets placed in *fd2p. That control process returns diagnostic output from the command (unit 2) on this channel, and it will also accept bytes on this channel as being Unix signal numbers, to be forwarded to the process group of the command ๐.
If fd2p is 0, then the stderr (unit 2 of the remote command) is made the same as the stdout, and no provision is made for sending arbitrary signals to the remote process โ although you may be able to get its attention by using out-of-band data ๐.
The protocol is described in detail in rshd(8). fr fr, go read it.
๐ง the rresvport() moment
rresvport() is how you obtain a socket to which an address with a Privileged Internet port is bound. This socket is suitable for use by rcmd() and several other functions โจ.
Privileged Internet ports are those in the range 0 to 1023 ๐ฅ. And only the super-user is allowed to bind an address of this sort to a socket โ that's the whole point, bestie.
๐ the iruserok() / ruserok() moment
iruserok() and ruserok() take a remote host's IP address or name, as returned by the gethostbyname(3) routines, plus two user names and a flag indicating whether the local user's name is that of the super-user.
Then, if the user is NOT the super-user, it checks the /etc/hosts.equiv file ๐. If that lookup is not done, or is unsuccessful, the .rhosts file in the local user's home directory is checked to see if the request for service is allowed.
โ ๏ธ Okay this part matters: if this file does not exist, is not a regular file, is owned by anyone other than the user or the super-user, or is writable by anyone other than the owner, the check automatically fails. Like, no discussion, it's over ๐.
Zero is returned if the machine name is listed in the โhosts.equivโ file, or the host and remote user name are found in the โ.rhostsโ file; otherwise iruserok() and ruserok() return -1.
Also cute detail: if the local domain (as obtained from gethostname(3)) is the same as the remote domain, only the machine name need be specified ๐.
Security tea:iruserok()is strongly preferred for security reasons. It requires trusting the local DNS at most, whileruserok()requires trusting the entire DNS, which can be spoofed. So likeโฆ choose wisely, bestie ๐ญ
๐ the _af and _sa girlies
The functions with an โ_afโ or โ_saโ suffix โ that's rcmd_af(), rresvport_af() and iruserok_sa() โ work the same as the corresponding functions without a suffix, except that they are capable of handling both IPv6 and IPv4 ports ๐.
The โ_afโ suffix means the function has an additional af argument, which is used to specify the address family (see below). The af argument extension is implemented for functions that have no binary address argument โ instead, the af argument specifies which address family is desired ๐
.
The โ_saโ suffix means the function has general socket address and length arguments. Since the socket address is a protocol independent data structure, IPv4 and IPv6 socket addresses can be passed as desired. The sa argument extension is implemented for functions that pass a protocol dependent binary address argument โ that argument needs to be replaced with a more general address structure to support multiple address families in a general way ๐ฆ.
And the functions with neither an โ_afโ suffix nor an โ_saโ suffix work for IPv4 only โ except for ruserok(), which can handle both IPv6 and IPv4 โญ.
To switch the address family, the af argument must be filled with AF_INET, or AF_INET6. For rcmd_af(), PF_UNSPEC is also allowed โจ.
๐ ENVIRONMENT ๐
RSHโ when using thercmd()function, this variable is used as the program to run instead ofrsh(1)๐
๐ DIAGNOSTICS ๐
rcmd()returns a valid socket descriptor on success. It returns-1on error and prints a diagnostic message on the standard error ๐ญrresvport()returns a valid, bound socket descriptor on success. It returns-1on error with the global valueerrnoset according to the reason for failure. The error codeEAGAINis overloaded to mean ``All network ports in use.'' ๐
๐ SEE ALSO ๐
rlogin(1),rsh(1),intro(2),rlogind(8),rshd(8)- W. Stevens and M. Thomas, Advanced Socket API for IPv6,
RFC2292. - W. Stevens, M. Thomas, and E. Nordmark, Advanced Socket API for IPv6,
RFC3542.
๐ฆ HISTORY ๐ฆ
Most of these functions appeared in 4.2BSD ๐
rresvport_af()appeared inRFC2292, and was implemented by the WIDE project for the Hydrangea IPv6 protocol stack kit ๐ธrcmd_af()appeared indraft-ietf-ipngwg-rfc2292bis-01.txt, and was implemented in the WIDE/KAME IPv6 protocol stack kit ๐ฅiruserok_sa()appeared in discussion on the IETF ipngwg mailing list, and was implemented in FreeBSD 4.0 โจ
that's the whole page, bestie โ mwah ๐
Debian ๐ March 3, 2000 โ yeah she's an elder icon but she still ate, periodt ๐ ๐ซถ
๐ฆ where this page comes from
- freebsd 15.1: base 15.1
- Copyright (c) 1983, 1991, 1993 The Regents of the University of California. All rights reserved
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms