1RCMD(3) Linux Programmer's Manual RCMD(3)
2
3
4
6 rcmd, rresvport, iruserok, ruserok, rcmd_af, rresvport_af, iruserok_af,
7 ruserok_af - routines for returning a stream to a remote command
8
10 #include <netdb.h> /* Or <unistd.h> on some systems */
11
12 int rcmd(char **ahost, unsigned short inport, const char *locuser,
13 const char *remuser, const char *cmd, int *fd2p);
14
15 int rresvport(int *port);
16
17 int iruserok(uint32_t raddr, int superuser,
18 const char *ruser, const char *luser);
19
20 int ruserok(const char *rhost, int superuser,
21 const char *ruser, const char *luser);
22
23 int rcmd_af(char **ahost, unsigned short inport, const char *locuser,
24 const char *remuser, const char *cmd, int *fd2p,
25 sa_family_t af);
26
27 int rresvport_af(int *port, sa_family_t af);
28
29 int iruserok_af(const void *raddr, int superuser,
30 const char *ruser, const char *luser, sa_family_t af);
31
32 int ruserok_af(const char *rhost, int superuser,
33 const char *ruser, const char *luser, sa_family_t af);
34
35 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
36
37 rcmd(), rcmd_af(), rresvport(), rresvport_af(), iruserok(),
38 iruserok_af(), ruserok(), ruserok_af():
39 Since glibc 2.19:
40 _DEFAULT_SOURCE
41 Glibc 2.19 and earlier:
42 _BSD_SOURCE
43
45 The rcmd() function is used by the superuser to execute a command on a
46 remote machine using an authentication scheme based on privileged port
47 numbers. The rresvport() function returns a file descriptor to a
48 socket with an address in the privileged port space. The iruserok()
49 and ruserok() functions are used by servers to authenticate clients re‐
50 questing service with rcmd(). All four functions are used by the
51 rshd(8) server (among others).
52
53 rcmd()
54 The rcmd() function looks up the host *ahost using gethostbyname(3),
55 returning -1 if the host does not exist. Otherwise, *ahost is set to
56 the standard name of the host and a connection is established to a
57 server residing at the well-known Internet port inport.
58
59 If the connection succeeds, a socket in the Internet domain of type
60 SOCK_STREAM is returned to the caller, and given to the remote command
61 as stdin and stdout. If fd2p is nonzero, then an auxiliary channel to
62 a control process will be set up, and a file descriptor for it will be
63 placed in *fd2p. The control process will return diagnostic output
64 from the command (unit 2) on this channel, and will also accept bytes
65 on this channel as being UNIX signal numbers, to be forwarded to the
66 process group of the command. If fd2p is 0, then the stderr (unit 2 of
67 the remote command) will be made the same as the stdout and no provi‐
68 sion is made for sending arbitrary signals to the remote process, al‐
69 though you may be able to get its attention by using out-of-band data.
70
71 The protocol is described in detail in rshd(8).
72
73 rresvport()
74 The rresvport() function is used to obtain a socket with a privileged
75 port bound to it. This socket is suitable for use by rcmd() and sev‐
76 eral other functions. Privileged ports are those in the range 0 to
77 1023. Only a privileged process (on Linux: a process that has the
78 CAP_NET_BIND_SERVICE capability in the user namespace governing its
79 network namespace). is allowed to bind to a privileged port. In the
80 glibc implementation, this function restricts its search to the ports
81 from 512 to 1023. The port argument is value-result: the value it sup‐
82 plies to the call is used as the starting point for a circular search
83 of the port range; on (successful) return, it contains the port number
84 that was bound to.
85
86 iruserok() and ruserok()
87 The iruserok() and ruserok() functions take a remote host's IP address
88 or name, respectively, two usernames and a flag indicating whether the
89 local user's name is that of the superuser. Then, if the user is not
90 the superuser, it checks the /etc/hosts.equiv file. If that lookup is
91 not done, or is unsuccessful, the .rhosts in the local user's home di‐
92 rectory is checked to see if the request for service is allowed.
93
94 If this file does not exist, is not a regular file, is owned by anyone
95 other than the user or the superuser, is writable by anyone other than
96 the owner, or is hardlinked anywhere, the check automatically fails.
97 Zero is returned if the machine name is listed in the hosts.equiv file,
98 or the host and remote username are found in the .rhosts file; other‐
99 wise iruserok() and ruserok() return -1. If the local domain (as ob‐
100 tained from gethostname(2)) is the same as the remote domain, only the
101 machine name need be specified.
102
103 If the IP address of the remote host is known, iruserok() should be
104 used in preference to ruserok(), as it does not require trusting the
105 DNS server for the remote host's domain.
106
107 *_af() variants
108 All of the functions described above work with IPv4 (AF_INET) sockets.
109 The "_af" variants take an extra argument that allows the socket ad‐
110 dress family to be specified. For these functions, the af argument can
111 be specified as AF_INET or AF_INET6. In addition, rcmd_af() supports
112 the use of AF_UNSPEC.
113
115 The rcmd() function returns a valid socket descriptor on success. It
116 returns -1 on error and prints a diagnostic message on the standard er‐
117 ror.
118
119 The rresvport() function returns a valid, bound socket descriptor on
120 success. It returns -1 on error with the global value errno set ac‐
121 cording to the reason for failure. The error code EAGAIN is overloaded
122 to mean "All network ports in use."
123
124 For information on the return from ruserok() and iruserok(), see above.
125
127 The functions iruserok_af(), rcmd_af(), rresvport_af(), and
128 ruserok_af() functions are provide in glibc since version 2.2.
129
131 For an explanation of the terms used in this section, see at‐
132 tributes(7).
133
134 ┌────────────────────────────┬───────────────┬────────────────┐
135 │Interface │ Attribute │ Value │
136 ├────────────────────────────┼───────────────┼────────────────┤
137 │rcmd(), rcmd_af() │ Thread safety │ MT-Unsafe │
138 ├────────────────────────────┼───────────────┼────────────────┤
139 │rresvport(), rresvport_af() │ Thread safety │ MT-Safe │
140 ├────────────────────────────┼───────────────┼────────────────┤
141 │iruserok(), ruserok(), │ Thread safety │ MT-Safe locale │
142 │iruserok_af(), ruserok_af() │ │ │
143 └────────────────────────────┴───────────────┴────────────────┘
144
146 Not in POSIX.1. Present on the BSDs, Solaris, and many other systems.
147 These functions appeared in 4.2BSD. The "_af" variants are more recent
148 additions, and are not present on as wide a range of systems.
149
151 iruserok() and iruserok_af() are declared in glibc headers only since
152 version 2.12.
153
155 rlogin(1), rsh(1), rexec(3), rexecd(8), rlogind(8), rshd(8)
156
158 This page is part of release 5.10 of the Linux man-pages project. A
159 description of the project, information about reporting bugs, and the
160 latest version of this page, can be found at
161 https://www.kernel.org/doc/man-pages/.
162
163
164
165Linux 2020-12-21 RCMD(3)