Debian Codegraph @

upstream/debian-unstable/man3/rcmd.3

raw
1 '\" t
2 .\" Copyright 1983-1993, The Regents of the University of California.
3 .\" Copyright, the authors of the Linux man-pages project
4 .\"
5 .\" SPDX-License-Identifier: BSD-4-Clause-UC
6 .\"
7 .TH rcmd 3 2025-09-21 "Linux man-pages 6.18"
8 .SH NAME
9 rcmd, rresvport, iruserok, ruserok, rcmd_af,
10 rresvport_af, iruserok_af, ruserok_af \- routines for returning a
11 stream to a remote command
12 .SH LIBRARY
13 Standard C library
14 .RI ( libc ,\~ \-lc )
15 .SH SYNOPSIS
16 .nf
17 .BR "#include <netdb.h> " "/* Or <unistd.h> on some systems */"
18 .P
19 .BI "int rcmd(char **restrict " ahost ", unsigned short " inport ,
20 .BI " const char *restrict " locuser ,
21 .BI " const char *restrict " remuser ,
22 .BI " const char *restrict " cmd ", int *restrict " fd2p );
23 .P
24 .BI "int rresvport(int *" port );
25 .P
26 .BI "int iruserok(uint32_t " raddr ", int " superuser ,
27 .BI " const char *" ruser ", const char *" luser );
28 .BI "int ruserok(const char *" rhost ", int " superuser ,
29 .BI " const char *" ruser ", const char *" luser );
30 .P
31 .BI "int rcmd_af(char **restrict " ahost ", unsigned short " inport ,
32 .BI " const char *restrict " locuser ,
33 .BI " const char *restrict " remuser ,
34 .BI " const char *restrict " cmd ", int *restrict " fd2p ,
35 .BI " sa_family_t " af );
36 .P
37 .BI "int rresvport_af(int *" port ", sa_family_t " af );
38 .P
39 .BI "int iruserok_af(const void *restrict " raddr ", int " superuser ,
40 .BI " const char *restrict " ruser ", const char *restrict " luser ,
41 .BI " sa_family_t " af );
42 .BI "int ruserok_af(const char *" rhost ", int " superuser ,
43 .BI " const char *" ruser ", const char *" luser ,
44 .BI " sa_family_t " af );
45 .fi
46 .P
47 .RS -4
48 Feature Test Macro Requirements for glibc (see
49 .BR feature_test_macros (7)):
50 .RE
51 .ad l
52 .P
53 .BR rcmd (),
54 .BR rcmd_af (),
55 .BR rresvport (),
56 .BR rresvport_af (),
57 .BR iruserok (),
58 .BR iruserok_af (),
59 .BR ruserok (),
60 .BR ruserok_af ():
61 .nf
62 Since glibc 2.19:
63 _DEFAULT_SOURCE
64 glibc 2.19 and earlier:
65 _BSD_SOURCE
66 .fi
67 .ad
68 .SH DESCRIPTION
69 The
70 .BR rcmd ()
71 function is used by the superuser to execute a command on
72 a remote machine using an authentication scheme based
73 on privileged port numbers.
74 The
75 .BR rresvport ()
76 function
77 returns a file descriptor to a socket
78 with an address in the privileged port space.
79 The
80 .BR iruserok ()
81 and
82 .BR ruserok ()
83 functions are used by servers
84 to authenticate clients requesting service with
85 .BR rcmd ().
86 All four functions are used by the
87 .BR rshd (8)
88 server (among others).
89 .SS rcmd()
90 The
91 .BR rcmd ()
92 function
93 looks up the host
94 .I *ahost
95 using
96 .BR gethostbyname (3),
97 returning \-1 if the host does not exist.
98 Otherwise,
99 .I *ahost
100 is set to the standard name of the host
101 and a connection is established to a server
102 residing at the well-known Internet port
103 .IR inport .
104 .P
105 If the connection succeeds,
106 a socket in the Internet domain of type
107 .B SOCK_STREAM
108 is returned to the caller, and given to the remote
109 command as
110 .I stdin
111 and
112 .IR stdout .
113 If
114 .I fd2p
115 is nonzero, then an auxiliary channel to a control
116 process will be set up, and a file descriptor for it will be placed
117 in
118 .IR *fd2p .
119 The control process will return diagnostic
120 output from the command (unit 2) on this channel, and will also
121 accept bytes on this channel as being UNIX signal numbers, to be
122 forwarded to the process group of the command.
123 If
124 .I fd2p
125 is 0, then the
126 .I stderr
127 (unit 2 of the remote
128 command) will be made the same as the
129 .I stdout
130 and no
131 provision is made for sending arbitrary signals to the remote process,
132 although you may be able to get its attention by using out-of-band data.
133 .P
134 The protocol is described in detail in
135 .BR rshd (8).
136 .SS rresvport()
137 The
138 .BR rresvport ()
139 function is used to obtain a socket with a privileged
140 port bound to it.
141 This socket is suitable for use by
142 .BR rcmd ()
143 and several other functions.
144 Privileged ports are those in the range 0 to 1023.
145 Only a privileged process
146 (on Linux, a process that has the
147 .B CAP_NET_BIND_SERVICE
148 capability in the user namespace governing its network namespace)
149 is allowed to bind to a privileged port.
150 In the glibc implementation,
151 this function restricts its search to the ports from 512 to 1023.
152 The
153 .I port
154 argument is value-result:
155 the value it supplies to the call is used as the starting point
156 for a circular search of the port range;
157 on (successful) return, it contains the port number that was bound to.
158 .\"
159 .SS iruserok() and ruserok()
160 The
161 .BR iruserok ()
162 and
163 .BR ruserok ()
164 functions take a remote host's IP address or name, respectively,
165 two usernames and a flag indicating whether the local user's
166 name is that of the superuser.
167 Then, if the user is
168 .I not
169 the superuser, it checks the
170 .I /etc/hosts.equiv
171 file.
172 If that lookup is not done, or is unsuccessful, the
173 .I .rhosts
174 in the local user's home directory is checked to see if the request for
175 service is allowed.
176 .P
177 If this file does not exist, is not a regular file, is owned by anyone
178 other than the user or the superuser, is writable by anyone other
179 than the owner, or is hardlinked anywhere, the check automatically fails.
180 Zero is returned if the machine name is listed in the
181 .I hosts.equiv
182 file,
183 or the host and remote username are found in the
184 .I .rhosts
185 file;
186 otherwise,
187 .BR iruserok ()
188 and
189 .BR ruserok ()
190 return \-1.
191 If the local domain
192 (as obtained from
193 .BR gethostname (2))
194 is the same as the remote domain,
195 only the machine name need be specified.
196 .P
197 If the IP address of the remote host is known,
198 .BR iruserok ()
199 should be used in preference to
200 .BR ruserok (),
201 as it does not require trusting the DNS server for the remote host's domain.
202 .SS *_af() variants
203 All of the functions described above work with IPv4
204 .RB ( AF_INET )
205 sockets.
206 The "_af" variants take an extra argument that allows the
207 socket address family to be specified.
208 For these functions, the
209 .I af
210 argument can be specified as
211 .B AF_INET
212 or
213 .BR AF_INET6 .
214 In addition,
215 .BR rcmd_af ()
216 supports the use of
217 .BR AF_UNSPEC .
218 .SH RETURN VALUE
219 The
220 .BR rcmd ()
221 function
222 returns a valid socket descriptor on success.
223 It returns \-1 on error and prints a diagnostic message on the standard error.
224 .P
225 The
226 .BR rresvport ()
227 function
228 returns a valid, bound socket descriptor on success.
229 On failure, it returns \-1 and sets
230 .I errno
231 to indicate the error.
232 The error code
233 .B EAGAIN
234 is overloaded to mean: "All network ports in use".
235 .P
236 For information on the return from
237 .BR ruserok ()
238 and
239 .BR iruserok (),
240 see above.
241 .SH ATTRIBUTES
242 For an explanation of the terms used in this section, see
243 .BR attributes (7).
244 .TS
245 allbox;
246 lbx lb lb
247 l l l.
248 Interface Attribute Value
249 T{
250 .na
251 .nh
252 .BR rcmd (),
253 .BR rcmd_af ()
254 T} Thread safety MT-Unsafe
255 T{
256 .na
257 .nh
258 .BR rresvport (),
259 .BR rresvport_af ()
260 T} Thread safety MT-Safe
261 T{
262 .na
263 .nh
264 .BR iruserok (),
265 .BR ruserok (),
266 .BR iruserok_af (),
267 .BR ruserok_af ()
268 T} Thread safety MT-Safe locale
269 .TE
270 .SH STANDARDS
271 BSD.
272 .SH HISTORY
273 .TP
274 .BR iruserok_af ()
275 .TQ
276 .BR rcmd_af ()
277 .TQ
278 .BR rresvport_af ()
279 .TQ
280 .BR ruserok_af ()
281 glibc 2.2.
282 .P
283 Solaris, 4.2BSD.
284 The "_af" variants are more recent additions,
285 and are not present on as wide a range of systems.
286 .SH BUGS
287 .BR iruserok ()
288 and
289 .BR iruserok_af ()
290 are declared in glibc headers only since glibc 2.12.
291 .\" Bug filed 25 Nov 2007:
292 .\" https://www.sourceware.org/bugzilla/show_bug.cgi?id=5399
293 .SH SEE ALSO
294 .BR rlogin (1),
295 .BR rsh (1),
296 .BR rexec (3),
297 .BR rexecd (8),
298 .BR rlogind (8),
299 .BR rshd (8)