1RCMD(3) BSD Library Functions Manual RCMD(3)
2
4 rcmd, rresvport, iruserok, ruserok — routines for returning a stream to a
5 remote command
6
8 #include <netdb.h> /* Or <unistd.h> on some systems */
9
10 int
11 rcmd(char **ahost, int inport, const char *locuser, const char *remuser,
12 const char *cmd, int *fd2p);
13
14 int
15 rresvport(int *port);
16
17 int
18 iruserok(u_int32_t raddr, int superuser, const char *ruser,
19 const char *luser);
20
21 int
22 ruserok(const char *rhost, int superuser, const char *ruser,
23 const char *luser);
24
26 The rcmd() function is used by the superuser to execute a command on a
27 remote machine using an authentication scheme based on reserved port num‐
28 bers. The rresvport() function returns a descriptor to a socket with an
29 address in the privileged port space. The iruserok() and ruserok() func‐
30 tions are used by servers to authenticate clients requesting service with
31 rcmd(). All four functions are present in the same file and are used by
32 the rshd(8) server (among others).
33
34 The rcmd() function looks up the host *ahost using gethostbyname(3),
35 returning -1 if the host does not exist. Otherwise *ahost is set to the
36 standard name of the host and a connection is established to a server
37 residing at the well-known Internet port inport.
38
39 If the connection succeeds, a socket in the Internet domain of type
40 SOCK_STREAM is returned to the caller, and given to the remote command as
41 stdin and stdout. If fd2p is non-zero, then an auxiliary channel to a
42 control process will be set up, and a descriptor for it will be placed in
43 *fd2p. The control process will return diagnostic output from the com‐
44 mand (unit 2) on this channel, and will also accept bytes on this channel
45 as being UNIX signal numbers, to be forwarded to the process group of the
46 command. If fd2p is 0, then the stderr (unit 2 of the remote command)
47 will be made the same as the stdout and no provision is made for sending
48 arbitrary signals to the remote process, although you may be able to get
49 its attention by using out-of-band data.
50
51 The protocol is described in detail in rshd(8).
52
53 The rresvport() function is used to obtain a socket with a privileged
54 address bound to it. This socket is suitable for use by rcmd() and sev‐
55 eral other functions. Privileged Internet ports are those in the range 0
56 to 1023. Only the superuser is allowed to bind an address of this sort
57 to a socket.
58
59 The iruserok() and ruserok() functions take a remote host's IP address or
60 name, respectively, two user names and a flag indicating whether the
61 local user's name is that of the superuser. Then, if the user is NOT the
62 superuser, it checks the /etc/hosts.equiv file. If that lookup is not
63 done, or is unsuccessful, the .rhosts in the local user's home directory
64 is checked to see if the request for service is allowed.
65
66 If this file does not exist, is not a regular file, is owned by anyone
67 other than the user or the superuser, or is writable by anyone other than
68 the owner, the check automatically fails. Zero is returned if the
69 machine name is listed in the “hosts.equiv” file, or the host and remote
70 user name are found in the “.rhosts” file; otherwise iruserok() and
71 ruserok() return -1. If the local domain (as obtained from
72 gethostname(2)) is the same as the remote domain, only the machine name
73 need be specified.
74
75 If the IP address of the remote host is known, iruserok() should be used
76 in preference to ruserok(), as it does not require trusting the DNS
77 server for the remote host's domain.
78
80 The rcmd() function returns a valid socket descriptor on success. It
81 returns -1 on error and prints a diagnostic message on the standard
82 error.
83
84 The rresvport() function returns a valid, bound socket descriptor on suc‐
85 cess. It returns -1 on error with the global value errno set according
86 to the reason for failure. The error code EAGAIN is overloaded to mean
87 ``All network ports in use.''
88
90 Not in POSIX.1-2001. Present on the BSDs, Solaris, and many other sys‐
91 tems. These functions appeared in 4.2BSD.
92
94 rlogin(1), rsh(1), intro(2), rexec(3), rexecd(8), rlogind(8), rshd(8)
95
964.2BSD June 4, 1993 4.2BSD