xref: /freebsd/lib/libc/net/rcmd.3 (revision 4e543e5c372b259a8df99b3358d3cc24418369a7)
158f0484fSRodney W. Grimes.\" Copyright (c) 1983, 1991, 1993
258f0484fSRodney W. Grimes.\"	The Regents of the University of California.  All rights reserved.
358f0484fSRodney W. Grimes.\"
458f0484fSRodney W. Grimes.\" Redistribution and use in source and binary forms, with or without
558f0484fSRodney W. Grimes.\" modification, are permitted provided that the following conditions
658f0484fSRodney W. Grimes.\" are met:
758f0484fSRodney W. Grimes.\" 1. Redistributions of source code must retain the above copyright
858f0484fSRodney W. Grimes.\"    notice, this list of conditions and the following disclaimer.
958f0484fSRodney W. Grimes.\" 2. Redistributions in binary form must reproduce the above copyright
1058f0484fSRodney W. Grimes.\"    notice, this list of conditions and the following disclaimer in the
1158f0484fSRodney W. Grimes.\"    documentation and/or other materials provided with the distribution.
1258f0484fSRodney W. Grimes.\" 4. Neither the name of the University nor the names of its contributors
1358f0484fSRodney W. Grimes.\"    may be used to endorse or promote products derived from this software
1458f0484fSRodney W. Grimes.\"    without specific prior written permission.
1558f0484fSRodney W. Grimes.\"
1658f0484fSRodney W. Grimes.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
1758f0484fSRodney W. Grimes.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1858f0484fSRodney W. Grimes.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1958f0484fSRodney W. Grimes.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2058f0484fSRodney W. Grimes.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2158f0484fSRodney W. Grimes.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2258f0484fSRodney W. Grimes.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2358f0484fSRodney W. Grimes.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2458f0484fSRodney W. Grimes.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2558f0484fSRodney W. Grimes.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2658f0484fSRodney W. Grimes.\" SUCH DAMAGE.
2758f0484fSRodney W. Grimes.\"
285900c007SGarrett Wollman.\"     From: @(#)rcmd.3	8.1 (Berkeley) 6/4/93
297f3dea24SPeter Wemm.\" $FreeBSD$
3058f0484fSRodney W. Grimes.\"
31a56a8ad1SYoshinobu Inoue.Dd March 3, 2000
3258f0484fSRodney W. Grimes.Dt RCMD 3
33a307d598SRuslan Ermilov.Os
3458f0484fSRodney W. Grimes.Sh NAME
3558f0484fSRodney W. Grimes.Nm rcmd ,
3658f0484fSRodney W. Grimes.Nm rresvport ,
373573df98SRodney W. Grimes.Nm iruserok ,
3842b4f28eSYoshinobu Inoue.Nm ruserok ,
390cac72f4SYoshinobu Inoue.Nm rcmd_af ,
4042b4f28eSYoshinobu Inoue.Nm rresvport_af ,
41a56a8ad1SYoshinobu Inoue.Nm iruserok_sa
4258f0484fSRodney W. Grimes.Nd routines for returning a stream to a remote command
4325bb73e0SAlexey Zelkin.Sh LIBRARY
4425bb73e0SAlexey Zelkin.Lb libc
4558f0484fSRodney W. Grimes.Sh SYNOPSIS
4632eef9aeSRuslan Ermilov.In unistd.h
4758f0484fSRodney W. Grimes.Ft int
4858f0484fSRodney W. Grimes.Fn rcmd "char **ahost" "int inport" "const char *locuser" "const char *remuser" "const char *cmd" "int *fd2p"
4958f0484fSRodney W. Grimes.Ft int
5058f0484fSRodney W. Grimes.Fn rresvport "int *port"
5158f0484fSRodney W. Grimes.Ft int
5258f0484fSRodney W. Grimes.Fn iruserok "u_long raddr" "int superuser" "const char *ruser" "const char *luser"
5358f0484fSRodney W. Grimes.Ft int
5458f0484fSRodney W. Grimes.Fn ruserok "const char *rhost" "int superuser" "const char *ruser" "const char *luser"
5542b4f28eSYoshinobu Inoue.Ft int
560cac72f4SYoshinobu Inoue.Fn rcmd_af "char **ahost" "int inport" "const char *locuser" "const char *remuser" "const char *cmd" "int *fd2p" "int af"
570cac72f4SYoshinobu Inoue.Ft int
580cac72f4SYoshinobu Inoue.Fn rresvport_af "int *port" "int af"
5942b4f28eSYoshinobu Inoue.Ft int
60a56a8ad1SYoshinobu Inoue.Fn iruserok_sa "const void *addr" "int addrlen" "int superuser" "const char *ruser" "const char *luser"
6158f0484fSRodney W. Grimes.Sh DESCRIPTION
6258f0484fSRodney W. GrimesThe
6358f0484fSRodney W. Grimes.Fn rcmd
6458f0484fSRodney W. Grimesfunction
6558f0484fSRodney W. Grimesis used by the super-user to execute a command on
6658f0484fSRodney W. Grimesa remote machine using an authentication scheme based
6758f0484fSRodney W. Grimeson reserved port numbers.
6858f0484fSRodney W. GrimesThe
6958f0484fSRodney W. Grimes.Fn rresvport
7058f0484fSRodney W. Grimesfunction
7158f0484fSRodney W. Grimesreturns a descriptor to a socket
7258f0484fSRodney W. Grimeswith an address in the privileged port space.
7358f0484fSRodney W. GrimesThe
7458f0484fSRodney W. Grimes.Fn ruserok
7558f0484fSRodney W. Grimesfunction
7658f0484fSRodney W. Grimesis used by servers
7758f0484fSRodney W. Grimesto authenticate clients requesting service with
7858f0484fSRodney W. Grimes.Fn rcmd .
7958f0484fSRodney W. GrimesAll three functions are present in the same file and are used
8058f0484fSRodney W. Grimesby the
8158f0484fSRodney W. Grimes.Xr rshd 8
8258f0484fSRodney W. Grimesserver (among others).
8358f0484fSRodney W. Grimes.Pp
8458f0484fSRodney W. GrimesThe
8558f0484fSRodney W. Grimes.Fn rcmd
8658f0484fSRodney W. Grimesfunction
8758f0484fSRodney W. Grimeslooks up the host
8858f0484fSRodney W. Grimes.Fa *ahost
8958f0484fSRodney W. Grimesusing
9058f0484fSRodney W. Grimes.Xr gethostbyname 3 ,
91a56a8ad1SYoshinobu Inouereturning -1 if the host does not exist.
9258f0484fSRodney W. GrimesOtherwise
9358f0484fSRodney W. Grimes.Fa *ahost
9458f0484fSRodney W. Grimesis set to the standard name of the host
9558f0484fSRodney W. Grimesand a connection is established to a server
9658f0484fSRodney W. Grimesresiding at the well-known Internet port
9758f0484fSRodney W. Grimes.Fa inport .
9858f0484fSRodney W. Grimes.Pp
9958f0484fSRodney W. GrimesIf the connection succeeds,
10058f0484fSRodney W. Grimesa socket in the Internet domain of type
10158f0484fSRodney W. Grimes.Dv SOCK_STREAM
10258f0484fSRodney W. Grimesis returned to the caller, and given to the remote
10358f0484fSRodney W. Grimescommand as
104ae828962SRuslan Ermilov.Dv stdin
10558f0484fSRodney W. Grimesand
106ae828962SRuslan Ermilov.Dv stdout .
10758f0484fSRodney W. GrimesIf
10858f0484fSRodney W. Grimes.Fa fd2p
10958f0484fSRodney W. Grimesis non-zero, then an auxiliary channel to a control
11058f0484fSRodney W. Grimesprocess will be set up, and a descriptor for it will be placed
11158f0484fSRodney W. Grimesin
11258f0484fSRodney W. Grimes.Fa *fd2p .
11358f0484fSRodney W. GrimesThe control process will return diagnostic
11458f0484fSRodney W. Grimesoutput from the command (unit 2) on this channel, and will also
11558f0484fSRodney W. Grimesaccept bytes on this channel as being
1161798791dSRuslan Ermilov.Ux
11758f0484fSRodney W. Grimessignal numbers, to be
11858f0484fSRodney W. Grimesforwarded to the process group of the command.
11958f0484fSRodney W. GrimesIf
12058f0484fSRodney W. Grimes.Fa fd2p
12158f0484fSRodney W. Grimesis 0, then the
122ae828962SRuslan Ermilov.Dv stderr
12358f0484fSRodney W. Grimes(unit 2 of the remote
12458f0484fSRodney W. Grimescommand) will be made the same as the
125ae828962SRuslan Ermilov.Dv stdout
12658f0484fSRodney W. Grimesand no
12758f0484fSRodney W. Grimesprovision is made for sending arbitrary signals to the remote process,
12858f0484fSRodney W. Grimesalthough you may be able to get its attention by using out-of-band data.
12958f0484fSRodney W. Grimes.Pp
13058f0484fSRodney W. GrimesThe protocol is described in detail in
13158f0484fSRodney W. Grimes.Xr rshd 8 .
13258f0484fSRodney W. Grimes.Pp
13358f0484fSRodney W. GrimesThe
13458f0484fSRodney W. Grimes.Fn rresvport
135a56a8ad1SYoshinobu Inouefunction is used to obtain a socket to which an address with a Privileged
136a56a8ad1SYoshinobu InoueInternet port is bound.
137a56a8ad1SYoshinobu InoueThis socket is suitable for use by
13858f0484fSRodney W. Grimes.Fn rcmd
139a56a8ad1SYoshinobu Inoueand several other functions.
140a56a8ad1SYoshinobu InouePrivileged Internet ports are those in the range 0 to 1023.
141a56a8ad1SYoshinobu InoueOnly the super-user is allowed to bind an address of this sort
142a56a8ad1SYoshinobu Inoueto a socket.
14358f0484fSRodney W. Grimes.Pp
14458f0484fSRodney W. GrimesThe
14558f0484fSRodney W. Grimes.Fn iruserok
14658f0484fSRodney W. Grimesand
14758f0484fSRodney W. Grimes.Fn ruserok
14858f0484fSRodney W. Grimesfunctions take a remote host's IP address or name, as returned by the
14958f0484fSRodney W. Grimes.Xr gethostbyname 3
15058f0484fSRodney W. Grimesroutines, two user names and a flag indicating whether the local user's
15158f0484fSRodney W. Grimesname is that of the super-user.
15258f0484fSRodney W. GrimesThen, if the user is
15358f0484fSRodney W. Grimes.Em NOT
15458f0484fSRodney W. Grimesthe super-user, it checks the
15558f0484fSRodney W. Grimes.Pa /etc/hosts.equiv
15658f0484fSRodney W. Grimesfile.
15758f0484fSRodney W. GrimesIf that lookup is not done, or is unsuccessful, the
15858f0484fSRodney W. Grimes.Pa .rhosts
15958f0484fSRodney W. Grimesin the local user's home directory is checked to see if the request for
16058f0484fSRodney W. Grimesservice is allowed.
16158f0484fSRodney W. Grimes.Pp
16258f0484fSRodney W. GrimesIf this file does not exist, is not a regular file, is owned by anyone
163a5ed710cSMike Pritchardother than the user or the super-user, or is writable by anyone other
16458f0484fSRodney W. Grimesthan the owner, the check automatically fails.
16558f0484fSRodney W. GrimesZero is returned if the machine name is listed in the
16658f0484fSRodney W. Grimes.Dq Pa hosts.equiv
16758f0484fSRodney W. Grimesfile, or the host and remote user name are found in the
16858f0484fSRodney W. Grimes.Dq Pa .rhosts
16958f0484fSRodney W. Grimesfile; otherwise
17058f0484fSRodney W. Grimes.Fn iruserok
17158f0484fSRodney W. Grimesand
17258f0484fSRodney W. Grimes.Fn ruserok
173a56a8ad1SYoshinobu Inouereturn -1.
17458f0484fSRodney W. GrimesIf the local domain (as obtained from
175e1f4e80cSMike Pritchard.Xr gethostname 3 )
17658f0484fSRodney W. Grimesis the same as the remote domain, only the machine name need be specified.
17758f0484fSRodney W. Grimes.Pp
17858f0484fSRodney W. GrimesThe
17958f0484fSRodney W. Grimes.Fn iruserok
18058f0484fSRodney W. Grimesfunction is strongly preferred for security reasons.
18158f0484fSRodney W. GrimesIt requires trusting the local DNS at most, while the
18258f0484fSRodney W. Grimes.Fn ruserok
18358f0484fSRodney W. Grimesfunction requires trusting the entire DNS, which can be spoofed.
18442b4f28eSYoshinobu Inoue.Pp
185a56a8ad1SYoshinobu InoueThe functions with an
1860cac72f4SYoshinobu Inoue.Dq Li _af
187265fb60dSYoshinobu Inoueor
188a56a8ad1SYoshinobu Inoue.Dq Li _sa
189a56a8ad1SYoshinobu Inouesuffix, i.e.,
190a56a8ad1SYoshinobu Inoue.Fn rcmd_af ,
191a56a8ad1SYoshinobu Inoue.Fn rresvport_af
192a56a8ad1SYoshinobu Inoueand
193a56a8ad1SYoshinobu Inoue.Fn iruserok_sa ,
194265fb60dSYoshinobu Inouework the same as the corresponding functions without a
195a56a8ad1SYoshinobu Inouesuffix, except that they are capable of handling both IPv6 and IPv4 ports.
196a56a8ad1SYoshinobu Inoue.Pp
197a56a8ad1SYoshinobu InoueThe
198a56a8ad1SYoshinobu Inoue.Dq Li _af
199265fb60dSYoshinobu Inouesuffix means that the function has an additional
200a56a8ad1SYoshinobu Inoue.Fa af
201265fb60dSYoshinobu Inoueargument which is used to specify the address family,
202265fb60dSYoshinobu Inoue(see below).
203a56a8ad1SYoshinobu InoueThe
204a56a8ad1SYoshinobu Inoue.Fa af
205a56a8ad1SYoshinobu Inoueargument extension is implemented for functions
206265fb60dSYoshinobu Inouethat have no binary address argument.
207a56a8ad1SYoshinobu InoueInstead, the
208a56a8ad1SYoshinobu Inoue.Fa af
209a56a8ad1SYoshinobu Inoueargument specifies which address family is desired.
210a56a8ad1SYoshinobu Inoue.Pp
211a56a8ad1SYoshinobu InoueThe
212a56a8ad1SYoshinobu Inoue.Dq Li _sa
213265fb60dSYoshinobu Inouesuffix means that the function has general socket address and
214265fb60dSYoshinobu Inouelength arguments.
215a56a8ad1SYoshinobu InoueAs the socket address is a protocol independent data structure,
216a56a8ad1SYoshinobu InoueIPv4 and IPv6 socket address can be passed as desired.
217265fb60dSYoshinobu InoueThe
218a56a8ad1SYoshinobu Inoue.Fa sa
219a56a8ad1SYoshinobu Inoueargument extension is implemented for functions
220265fb60dSYoshinobu Inouethat pass a protocol dependent binary address argument.
221265fb60dSYoshinobu InoueThe argument needs to be replaced with a more general address structure
222a56a8ad1SYoshinobu Inoueto support multiple address families in a general way.
223a56a8ad1SYoshinobu Inoue.Pp
224265fb60dSYoshinobu InoueThe functions with neither an
225a56a8ad1SYoshinobu Inoue.Dq Li _af
226265fb60dSYoshinobu Inouesuffix nor an
227a56a8ad1SYoshinobu Inoue.Dq Li _sa
228a56a8ad1SYoshinobu Inouesuffix work for IPv4 only, except for
229a56a8ad1SYoshinobu Inoue.Fn ruserok
230a56a8ad1SYoshinobu Inouewhich can handle both IPv6 and IPv4.
231265fb60dSYoshinobu InoueTo switch the address family, the
23242b4f28eSYoshinobu Inoue.Fa af
23342b4f28eSYoshinobu Inoueargument must be filled with
2340cac72f4SYoshinobu Inoue.Dv AF_INET ,
23542b4f28eSYoshinobu Inoueor
23642b4f28eSYoshinobu Inoue.Dv AF_INET6 .
2370cac72f4SYoshinobu InoueFor
2380cac72f4SYoshinobu Inoue.Fn rcmd_af ,
2390cac72f4SYoshinobu Inoue.Dv PF_UNSPEC
2400cac72f4SYoshinobu Inoueis also allowed.
2414e543e5cSMurray Stokely.Sh ENVIRONMENT
2424e543e5cSMurray Stokely.Bl -tag -width RSH
2434e543e5cSMurray Stokely.It Ev RSH
2444e543e5cSMurray StokelyWhen using the
2454e543e5cSMurray Stokely.Fn rcmd
2464e543e5cSMurray Stokelyfunction, this variable is used as the program to run instead of
2474e543e5cSMurray Stokely.Xr rsh 1 .
24858f0484fSRodney W. Grimes.Sh DIAGNOSTICS
24958f0484fSRodney W. GrimesThe
25058f0484fSRodney W. Grimes.Fn rcmd
25158f0484fSRodney W. Grimesfunction
25258f0484fSRodney W. Grimesreturns a valid socket descriptor on success.
253a56a8ad1SYoshinobu InoueIt returns -1 on error and prints a diagnostic message
254a56a8ad1SYoshinobu Inoueon the standard error.
25558f0484fSRodney W. Grimes.Pp
25658f0484fSRodney W. GrimesThe
25758f0484fSRodney W. Grimes.Fn rresvport
25858f0484fSRodney W. Grimesfunction
25958f0484fSRodney W. Grimesreturns a valid, bound socket descriptor on success.
260a56a8ad1SYoshinobu InoueIt returns -1 on error with the global value
26158f0484fSRodney W. Grimes.Va errno
26258f0484fSRodney W. Grimesset according to the reason for failure.
26358f0484fSRodney W. GrimesThe error code
264c23155a4SRuslan Ermilov.Er EAGAIN
26558f0484fSRodney W. Grimesis overloaded to mean ``All network ports in use.''
26658f0484fSRodney W. Grimes.Sh SEE ALSO
26758f0484fSRodney W. Grimes.Xr rlogin 1 ,
26858f0484fSRodney W. Grimes.Xr rsh 1 ,
26958f0484fSRodney W. Grimes.Xr intro 2 ,
27058f0484fSRodney W. Grimes.Xr rlogind 8 ,
27158f0484fSRodney W. Grimes.Xr rshd 8
27242b4f28eSYoshinobu Inoue.Pp
273a56a8ad1SYoshinobu Inoue.Rs
2740f5fcaa3SSheldon Hearn.%A W. Stevens
2750f5fcaa3SSheldon Hearn.%A M. Thomas
276265fb60dSYoshinobu Inoue.%T "Advanced Socket API for IPv6"
277265fb60dSYoshinobu Inoue.%O RFC2292
278a56a8ad1SYoshinobu Inoue.Re
279a56a8ad1SYoshinobu Inoue.Rs
2800f5fcaa3SSheldon Hearn.%A W. Stevens
2810f5fcaa3SSheldon Hearn.%A M. Thomas
2820f5fcaa3SSheldon Hearn.%A E. Nordmark
283265fb60dSYoshinobu Inoue.%T "Advanced Socket API for IPv6"
284d84e2130SHajimu UMEMOTO.%O RFC3542
285a56a8ad1SYoshinobu Inoue.Re
28658f0484fSRodney W. Grimes.Sh HISTORY
287265fb60dSYoshinobu InoueMost of these
28858f0484fSRodney W. Grimesfunctions appeared in
28958f0484fSRodney W. Grimes.Bx 4.2 .
2901fae73b1SRuslan ErmilovThe
29142b4f28eSYoshinobu Inoue.Fn rresvport_af
2921fae73b1SRuslan Ermilovfunction
293a56a8ad1SYoshinobu Inoueappeared in RFC2292, and was implemented by the WIDE project
294a56a8ad1SYoshinobu Inouefor the Hydrangea IPv6 protocol stack kit.
2951fae73b1SRuslan ErmilovThe
2960cac72f4SYoshinobu Inoue.Fn rcmd_af
2971fae73b1SRuslan Ermilovfunction
2980cac72f4SYoshinobu Inoueappeared in draft-ietf-ipngwg-rfc2292bis-01.txt,
299a56a8ad1SYoshinobu Inoueand was implemented in the WIDE/KAME IPv6 protocol stack kit.
3001fae73b1SRuslan ErmilovThe
301a56a8ad1SYoshinobu Inoue.Fn iruserok_sa
3021fae73b1SRuslan Ermilovfunction
303a56a8ad1SYoshinobu Inoueappeared in discussion on the IETF ipngwg mailing list,
304a56a8ad1SYoshinobu Inoueand was implemented in
305a56a8ad1SYoshinobu Inoue.Fx 4.0 .
306