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