xref: /minix3/lib/libc/net/rcmd.3 (revision 2fe8fb192fe7e8720e3e7a77f928da545e872a6a)
1*2fe8fb19SBen Gras.\"	$NetBSD: rcmd.3,v 1.28 2010/03/22 19:30:54 joerg Exp $
2*2fe8fb19SBen Gras.\"
3*2fe8fb19SBen Gras.\" Copyright (c) 1983, 1991, 1993
4*2fe8fb19SBen Gras.\"	The Regents of the University of California.  All rights reserved.
5*2fe8fb19SBen Gras.\"
6*2fe8fb19SBen Gras.\" Redistribution and use in source and binary forms, with or without
7*2fe8fb19SBen Gras.\" modification, are permitted provided that the following conditions
8*2fe8fb19SBen Gras.\" are met:
9*2fe8fb19SBen Gras.\" 1. Redistributions of source code must retain the above copyright
10*2fe8fb19SBen Gras.\"    notice, this list of conditions and the following disclaimer.
11*2fe8fb19SBen Gras.\" 2. Redistributions in binary form must reproduce the above copyright
12*2fe8fb19SBen Gras.\"    notice, this list of conditions and the following disclaimer in the
13*2fe8fb19SBen Gras.\"    documentation and/or other materials provided with the distribution.
14*2fe8fb19SBen Gras.\" 3. Neither the name of the University nor the names of its contributors
15*2fe8fb19SBen Gras.\"    may be used to endorse or promote products derived from this software
16*2fe8fb19SBen Gras.\"    without specific prior written permission.
17*2fe8fb19SBen Gras.\"
18*2fe8fb19SBen Gras.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19*2fe8fb19SBen Gras.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20*2fe8fb19SBen Gras.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21*2fe8fb19SBen Gras.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22*2fe8fb19SBen Gras.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23*2fe8fb19SBen Gras.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24*2fe8fb19SBen Gras.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25*2fe8fb19SBen Gras.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26*2fe8fb19SBen Gras.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27*2fe8fb19SBen Gras.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28*2fe8fb19SBen Gras.\" SUCH DAMAGE.
29*2fe8fb19SBen Gras.\"
30*2fe8fb19SBen Gras.\"     @(#)rcmd.3	8.1 (Berkeley) 6/4/93
31*2fe8fb19SBen Gras.\"
32*2fe8fb19SBen Gras.Dd March 30, 2005
33*2fe8fb19SBen Gras.Dt RCMD 3
34*2fe8fb19SBen Gras.Os
35*2fe8fb19SBen Gras.Sh NAME
36*2fe8fb19SBen Gras.Nm rcmd ,
37*2fe8fb19SBen Gras.Nm orcmd ,
38*2fe8fb19SBen Gras.Nm rcmd_af ,
39*2fe8fb19SBen Gras.Nm orcmd_af ,
40*2fe8fb19SBen Gras.Nm rresvport ,
41*2fe8fb19SBen Gras.Nm rresvport_af ,
42*2fe8fb19SBen Gras.Nm iruserok ,
43*2fe8fb19SBen Gras.Nm ruserok ,
44*2fe8fb19SBen Gras.Nm iruserok_sa
45*2fe8fb19SBen Gras.Nd routines for returning a stream to a remote command
46*2fe8fb19SBen Gras.Sh LIBRARY
47*2fe8fb19SBen Gras.Lb libc
48*2fe8fb19SBen Gras.Sh SYNOPSIS
49*2fe8fb19SBen Gras.In unistd.h
50*2fe8fb19SBen Gras.Ft int
51*2fe8fb19SBen Gras.Fn rcmd "char **ahost" "int inport" "const char *locuser" "const char *remuser" "const char *cmd" "int *fd2p"
52*2fe8fb19SBen Gras.Ft int
53*2fe8fb19SBen Gras.Fn orcmd "char **ahost" "int inport" "const char *locuser" "const char *remuser" "const char *cmd" "int *fd2p"
54*2fe8fb19SBen Gras.Ft int
55*2fe8fb19SBen Gras.Fn rcmd_af "char **ahost" "int inport" "const char *locuser" "const char *remuser" "const char *cmd" "int *fd2p" "int af"
56*2fe8fb19SBen Gras.Ft int
57*2fe8fb19SBen Gras.Fn orcmd_af "char **ahost" "int inport" "const char *locuser" "const char *remuser" "const char *cmd" "int *fd2p" "int af"
58*2fe8fb19SBen Gras.Ft int
59*2fe8fb19SBen Gras.Fn rresvport "int *port"
60*2fe8fb19SBen Gras.Ft int
61*2fe8fb19SBen Gras.Fn rresvport_af "int *port" "int family"
62*2fe8fb19SBen Gras.Ft int
63*2fe8fb19SBen Gras.Fn iruserok "uint32_t raddr" "int superuser" "const char *ruser" "const char *luser"
64*2fe8fb19SBen Gras.Ft int
65*2fe8fb19SBen Gras.Fn ruserok "const char *rhost" "int superuser" "const char *ruser" "const char *luser"
66*2fe8fb19SBen Gras.Ft int
67*2fe8fb19SBen Gras.Fn iruserok_sa "const void *raddr" "int rlen" "int superuser" "const char *ruser" "const char *luser"
68*2fe8fb19SBen Gras.Sh DESCRIPTION
69*2fe8fb19SBen GrasThe
70*2fe8fb19SBen Gras.Fn rcmd
71*2fe8fb19SBen Grasfunction is available for use by anyone to run commands on a
72*2fe8fb19SBen Grasremote system.  It acts like the
73*2fe8fb19SBen Gras.Fn orcmd
74*2fe8fb19SBen Grascommand, with the exception that it makes a call out to the
75*2fe8fb19SBen Gras.Xr rcmd 1
76*2fe8fb19SBen Grascommand, or any other user-specified command, to perform the
77*2fe8fb19SBen Grasactual connection (thus not requiring
78*2fe8fb19SBen Grasthat the caller be running as the super-user), and is only
79*2fe8fb19SBen Grasavailable for the
80*2fe8fb19SBen Gras.Dq shell/tcp
81*2fe8fb19SBen Grasport.
82*2fe8fb19SBen GrasThe
83*2fe8fb19SBen Gras.Fn orcmd
84*2fe8fb19SBen Grasfunction
85*2fe8fb19SBen Grasis used by the super-user to execute a command on
86*2fe8fb19SBen Grasa remote machine using an authentication scheme based
87*2fe8fb19SBen Grason reserved port numbers.
88*2fe8fb19SBen GrasWhile
89*2fe8fb19SBen Gras.Fn rcmd
90*2fe8fb19SBen Grasand
91*2fe8fb19SBen Gras.Fn orcmd
92*2fe8fb19SBen Grascan only handle IPv4 address in the first argument,
93*2fe8fb19SBen Gras.Fn rcmd_af
94*2fe8fb19SBen Grasand
95*2fe8fb19SBen Gras.Fn orcmd_af
96*2fe8fb19SBen Grascan handle other cases as well.
97*2fe8fb19SBen GrasThe
98*2fe8fb19SBen Gras.Fn rresvport
99*2fe8fb19SBen Grasfunction
100*2fe8fb19SBen Grasreturns a descriptor to a socket
101*2fe8fb19SBen Graswith an address in the privileged port space.
102*2fe8fb19SBen GrasThe
103*2fe8fb19SBen Gras.Fn rresvport_af
104*2fe8fb19SBen Grasfunction is similar to
105*2fe8fb19SBen Gras.Fn rresvport ,
106*2fe8fb19SBen Grasbut you can explicitly specify the address family to use.
107*2fe8fb19SBen GrasCalling
108*2fe8fb19SBen Gras.Fn rresvport_af
109*2fe8fb19SBen Graswith
110*2fe8fb19SBen Gras.Dv AF_INET
111*2fe8fb19SBen Grashas the same effect as
112*2fe8fb19SBen Gras.Fn rresvport .
113*2fe8fb19SBen GrasThe
114*2fe8fb19SBen Gras.Fn iruserok
115*2fe8fb19SBen Grasand
116*2fe8fb19SBen Gras.Fn ruserok
117*2fe8fb19SBen Grasfunctions are used by servers
118*2fe8fb19SBen Grasto authenticate clients requesting service with
119*2fe8fb19SBen Gras.Fn rcmd .
120*2fe8fb19SBen GrasAll six functions are present in the same file and are used
121*2fe8fb19SBen Grasby the
122*2fe8fb19SBen Gras.Xr rshd 8
123*2fe8fb19SBen Grasserver (among others).
124*2fe8fb19SBen Gras.Fn iruserok_sa
125*2fe8fb19SBen Grasis an address family independent variant of
126*2fe8fb19SBen Gras.Fn iruserok .
127*2fe8fb19SBen Gras.Pp
128*2fe8fb19SBen GrasThe
129*2fe8fb19SBen Gras.Fn rcmd
130*2fe8fb19SBen Grasfunction
131*2fe8fb19SBen Graslooks up the host
132*2fe8fb19SBen Gras.Fa *ahost
133*2fe8fb19SBen Grasusing
134*2fe8fb19SBen Gras.Xr gethostbyname 3 ,
135*2fe8fb19SBen Grasreturning \-1 if the host does not exist.
136*2fe8fb19SBen GrasOtherwise
137*2fe8fb19SBen Gras.Fa *ahost
138*2fe8fb19SBen Grasis set to the standard name of the host
139*2fe8fb19SBen Grasand a connection is established to a server
140*2fe8fb19SBen Grasresiding at the well-known Internet port
141*2fe8fb19SBen Gras.Fa inport .
142*2fe8fb19SBen Gras.Pp
143*2fe8fb19SBen GrasIf the connection succeeds,
144*2fe8fb19SBen Grasa socket in the Internet domain of type
145*2fe8fb19SBen Gras.Dv SOCK_STREAM
146*2fe8fb19SBen Grasis returned to the caller, and given to the remote
147*2fe8fb19SBen Grascommand as
148*2fe8fb19SBen Gras.Em stdin
149*2fe8fb19SBen Grasand
150*2fe8fb19SBen Gras.Em stdout .
151*2fe8fb19SBen GrasIf
152*2fe8fb19SBen Gras.Fa fd2p
153*2fe8fb19SBen Grasis non-zero, then an auxiliary channel to a control
154*2fe8fb19SBen Grasprocess will be set up, and a descriptor for it will be placed
155*2fe8fb19SBen Grasin
156*2fe8fb19SBen Gras.Fa *fd2p .
157*2fe8fb19SBen GrasThe control process will return diagnostic
158*2fe8fb19SBen Grasoutput from the command (unit 2) on this channel, and will also
159*2fe8fb19SBen Grasaccept bytes on this channel as being
160*2fe8fb19SBen Gras.Ux
161*2fe8fb19SBen Grassignal numbers, to be
162*2fe8fb19SBen Grasforwarded to the process group of the command.
163*2fe8fb19SBen GrasIf
164*2fe8fb19SBen Gras.Fa fd2p
165*2fe8fb19SBen Grasis 0, then the
166*2fe8fb19SBen Gras.Em stderr
167*2fe8fb19SBen Gras(unit 2 of the remote
168*2fe8fb19SBen Grascommand) will be made the same as the
169*2fe8fb19SBen Gras.Em stdout
170*2fe8fb19SBen Grasand no
171*2fe8fb19SBen Grasprovision is made for sending arbitrary signals to the remote process,
172*2fe8fb19SBen Grasalthough you may be able to get its attention by using out-of-band data.
173*2fe8fb19SBen Gras.Pp
174*2fe8fb19SBen Gras.Fn rcmd_af
175*2fe8fb19SBen Grasand
176*2fe8fb19SBen Gras.Fn orcmd_af
177*2fe8fb19SBen Grastake address family in the last argument.
178*2fe8fb19SBen GrasIf the last argument is
179*2fe8fb19SBen Gras.Dv PF_UNSPEC ,
180*2fe8fb19SBen Grasinterpretation of
181*2fe8fb19SBen Gras.Fa *ahost
182*2fe8fb19SBen Graswill obey the underlying address resolution like DNS.
183*2fe8fb19SBen Gras.Pp
184*2fe8fb19SBen GrasThe protocol is described in detail in
185*2fe8fb19SBen Gras.Xr rshd 8 .
186*2fe8fb19SBen Gras.Pp
187*2fe8fb19SBen GrasThe
188*2fe8fb19SBen Gras.Fn rresvport
189*2fe8fb19SBen Grasand
190*2fe8fb19SBen Gras.Fn rresvport_af
191*2fe8fb19SBen Grasfunctions are used to obtain a socket with a privileged
192*2fe8fb19SBen Grasaddress bound to it.  This socket is suitable for use
193*2fe8fb19SBen Grasby
194*2fe8fb19SBen Gras.Fn rcmd
195*2fe8fb19SBen Grasand several other functions.  Privileged Internet ports are those
196*2fe8fb19SBen Grasin the range 0 to 1023.  Only the super-user
197*2fe8fb19SBen Grasis allowed to bind an address of this sort to a socket.
198*2fe8fb19SBen Gras.Pp
199*2fe8fb19SBen GrasThe
200*2fe8fb19SBen Gras.Fn iruserok
201*2fe8fb19SBen Grasand
202*2fe8fb19SBen Gras.Fn ruserok
203*2fe8fb19SBen Grasfunctions take a remote host's IP address or name, respectively,
204*2fe8fb19SBen Grastwo user names and a flag indicating whether the local user's
205*2fe8fb19SBen Grasname is that of the super-user.
206*2fe8fb19SBen GrasThen, if the user is
207*2fe8fb19SBen Gras.Em NOT
208*2fe8fb19SBen Grasthe super-user, it checks the
209*2fe8fb19SBen Gras.Pa /etc/hosts.equiv
210*2fe8fb19SBen Grasfile.
211*2fe8fb19SBen GrasIf that lookup is not done, or is unsuccessful, the
212*2fe8fb19SBen Gras.Pa .rhosts
213*2fe8fb19SBen Grasin the local user's home directory is checked to see if the request for
214*2fe8fb19SBen Grasservice is allowed.
215*2fe8fb19SBen Gras.Pp
216*2fe8fb19SBen GrasIf this file does not exist, is not a regular file, is owned by anyone
217*2fe8fb19SBen Grasother than the user or the super-user, or is writable by anyone other
218*2fe8fb19SBen Grasthan the owner, the check automatically fails.
219*2fe8fb19SBen GrasZero is returned if the machine name is listed in the
220*2fe8fb19SBen Gras.Dq Pa hosts.equiv
221*2fe8fb19SBen Grasfile, or the host and remote user name are found in the
222*2fe8fb19SBen Gras.Dq Pa .rhosts
223*2fe8fb19SBen Grasfile; otherwise
224*2fe8fb19SBen Gras.Fn iruserok
225*2fe8fb19SBen Grasand
226*2fe8fb19SBen Gras.Fn ruserok
227*2fe8fb19SBen Grasreturn \-1.
228*2fe8fb19SBen GrasIf the local domain (as obtained from
229*2fe8fb19SBen Gras.Xr gethostname 3 )
230*2fe8fb19SBen Grasis the same as the remote domain, only the machine name need be specified.
231*2fe8fb19SBen Gras.Pp
232*2fe8fb19SBen GrasIf the IP address of the remote host is known,
233*2fe8fb19SBen Gras.Fn iruserok
234*2fe8fb19SBen Grasshould be used in preference to
235*2fe8fb19SBen Gras.Fn ruserok ,
236*2fe8fb19SBen Grasas it does not require trusting the DNS server for the remote host's domain.
237*2fe8fb19SBen Gras.Pp
238*2fe8fb19SBen GrasWhile
239*2fe8fb19SBen Gras.Fn iruserok
240*2fe8fb19SBen Grascan handle IPv4 addresses only,
241*2fe8fb19SBen Gras.Fn iruserok_sa
242*2fe8fb19SBen Grasand
243*2fe8fb19SBen Gras.Fn ruserok
244*2fe8fb19SBen Grascan handle other address families as well, like IPv6.
245*2fe8fb19SBen GrasThe first argument of
246*2fe8fb19SBen Gras.Fn iruserok_sa
247*2fe8fb19SBen Grasis typed as
248*2fe8fb19SBen Gras.Fa "void *"
249*2fe8fb19SBen Grasto avoid dependency between
250*2fe8fb19SBen Gras.In unistd.h
251*2fe8fb19SBen Grasand
252*2fe8fb19SBen Gras.In sys/socket.h .
253*2fe8fb19SBen Gras.Sh ENVIRONMENT
254*2fe8fb19SBen Gras.Bl -tag -width RCMD_CMDxx -compact
255*2fe8fb19SBen Gras.It Ev RCMD_CMD
256*2fe8fb19SBen GrasWhen using the
257*2fe8fb19SBen Gras.Fn rcmd
258*2fe8fb19SBen Grasfunction, this variable is used as the program to run instead of
259*2fe8fb19SBen Gras.Xr rcmd 1 .
260*2fe8fb19SBen Gras.El
261*2fe8fb19SBen Gras.Sh DIAGNOSTICS
262*2fe8fb19SBen GrasThe
263*2fe8fb19SBen Gras.Fn rcmd
264*2fe8fb19SBen Grasfunction
265*2fe8fb19SBen Grasreturns a valid socket descriptor on success.
266*2fe8fb19SBen GrasIt returns \-1 on error and prints a diagnostic message on the standard error.
267*2fe8fb19SBen Gras.Pp
268*2fe8fb19SBen GrasThe
269*2fe8fb19SBen Gras.Fn rresvport
270*2fe8fb19SBen Grasand
271*2fe8fb19SBen Gras.Fn rresvport_af
272*2fe8fb19SBen Grasfunction
273*2fe8fb19SBen Grasreturn a valid, bound socket descriptor on success.
274*2fe8fb19SBen GrasThey return \-1 on error with the global value
275*2fe8fb19SBen Gras.Va errno
276*2fe8fb19SBen Grasset according to the reason for failure.
277*2fe8fb19SBen GrasThe error code
278*2fe8fb19SBen Gras.Dv EAGAIN
279*2fe8fb19SBen Grasis overloaded to mean ``All network ports in use.''
280*2fe8fb19SBen Gras.Sh SEE ALSO
281*2fe8fb19SBen Gras.Xr rcmd 1 ,
282*2fe8fb19SBen Gras.Xr rlogin 1 ,
283*2fe8fb19SBen Gras.Xr rsh 1 ,
284*2fe8fb19SBen Gras.Xr intro 2 ,
285*2fe8fb19SBen Gras.Xr rexec 3 ,
286*2fe8fb19SBen Gras.Xr hosts.equiv 5 ,
287*2fe8fb19SBen Gras.Xr rhosts 5 ,
288*2fe8fb19SBen Gras.Xr rexecd 8 ,
289*2fe8fb19SBen Gras.Xr rlogind 8 ,
290*2fe8fb19SBen Gras.Xr rshd 8
291*2fe8fb19SBen Gras.Sh HISTORY
292*2fe8fb19SBen GrasThe
293*2fe8fb19SBen Gras.Fn orcmd ,
294*2fe8fb19SBen Gras.Fn rresvport ,
295*2fe8fb19SBen Gras.Fn iruserok
296*2fe8fb19SBen Grasand
297*2fe8fb19SBen Gras.Fn ruserok
298*2fe8fb19SBen Grasfunctions appeared in
299*2fe8fb19SBen Gras.Bx 4.2 ,
300*2fe8fb19SBen Graswhere the
301*2fe8fb19SBen Gras.Fn orcmd
302*2fe8fb19SBen Grasfunction was called
303*2fe8fb19SBen Gras.Fn rcmd .
304*2fe8fb19SBen GrasThe (newer)
305*2fe8fb19SBen Gras.Fn rcmd
306*2fe8fb19SBen Grasfunction appeared in
307*2fe8fb19SBen Gras.Nx 1.3 .
308*2fe8fb19SBen Gras.Fn rcmd_af
309*2fe8fb19SBen Grasand
310*2fe8fb19SBen Gras.Fn rresvport_af
311*2fe8fb19SBen Graswere defined in RFC2292.
312