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