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