xref: /freebsd/lib/libc/net/rcmd.3 (revision dc36d6f9bb1753f3808552f3afd30eda9a7b206a)
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.
12*fbbd9655SWarner Losh.\" 3. 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.\"
28a56a8ad1SYoshinobu Inoue.Dd March 3, 2000
2958f0484fSRodney W. Grimes.Dt RCMD 3
30a307d598SRuslan Ermilov.Os
3158f0484fSRodney W. Grimes.Sh NAME
3258f0484fSRodney W. Grimes.Nm rcmd ,
3358f0484fSRodney W. Grimes.Nm rresvport ,
343573df98SRodney W. Grimes.Nm iruserok ,
3542b4f28eSYoshinobu Inoue.Nm ruserok ,
360cac72f4SYoshinobu Inoue.Nm rcmd_af ,
3742b4f28eSYoshinobu Inoue.Nm rresvport_af ,
38a56a8ad1SYoshinobu Inoue.Nm iruserok_sa
3958f0484fSRodney W. Grimes.Nd routines for returning a stream to a remote command
4025bb73e0SAlexey Zelkin.Sh LIBRARY
4125bb73e0SAlexey Zelkin.Lb libc
4258f0484fSRodney W. Grimes.Sh SYNOPSIS
4332eef9aeSRuslan Ermilov.In unistd.h
4458f0484fSRodney W. Grimes.Ft int
4558f0484fSRodney W. Grimes.Fn rcmd "char **ahost" "int inport" "const char *locuser" "const char *remuser" "const char *cmd" "int *fd2p"
4658f0484fSRodney W. Grimes.Ft int
4758f0484fSRodney W. Grimes.Fn rresvport "int *port"
4858f0484fSRodney W. Grimes.Ft int
4958f0484fSRodney W. Grimes.Fn iruserok "u_long raddr" "int superuser" "const char *ruser" "const char *luser"
5058f0484fSRodney W. Grimes.Ft int
5158f0484fSRodney W. Grimes.Fn ruserok "const char *rhost" "int superuser" "const char *ruser" "const char *luser"
5242b4f28eSYoshinobu Inoue.Ft int
530cac72f4SYoshinobu Inoue.Fn rcmd_af "char **ahost" "int inport" "const char *locuser" "const char *remuser" "const char *cmd" "int *fd2p" "int af"
540cac72f4SYoshinobu Inoue.Ft int
550cac72f4SYoshinobu Inoue.Fn rresvport_af "int *port" "int af"
5642b4f28eSYoshinobu Inoue.Ft int
57a56a8ad1SYoshinobu Inoue.Fn iruserok_sa "const void *addr" "int addrlen" "int superuser" "const char *ruser" "const char *luser"
5858f0484fSRodney W. Grimes.Sh DESCRIPTION
5958f0484fSRodney W. GrimesThe
6058f0484fSRodney W. Grimes.Fn rcmd
6158f0484fSRodney W. Grimesfunction
6258f0484fSRodney W. Grimesis used by the super-user to execute a command on
6358f0484fSRodney W. Grimesa remote machine using an authentication scheme based
6458f0484fSRodney W. Grimeson reserved port numbers.
6558f0484fSRodney W. GrimesThe
6658f0484fSRodney W. Grimes.Fn rresvport
6758f0484fSRodney W. Grimesfunction
6858f0484fSRodney W. Grimesreturns a descriptor to a socket
6958f0484fSRodney W. Grimeswith an address in the privileged port space.
7058f0484fSRodney W. GrimesThe
7158f0484fSRodney W. Grimes.Fn ruserok
7258f0484fSRodney W. Grimesfunction
7358f0484fSRodney W. Grimesis used by servers
7458f0484fSRodney W. Grimesto authenticate clients requesting service with
7558f0484fSRodney W. Grimes.Fn rcmd .
7658f0484fSRodney W. GrimesAll three functions are present in the same file and are used
7758f0484fSRodney W. Grimesby the
7858f0484fSRodney W. Grimes.Xr rshd 8
7958f0484fSRodney W. Grimesserver (among others).
8058f0484fSRodney W. Grimes.Pp
8158f0484fSRodney W. GrimesThe
8258f0484fSRodney W. Grimes.Fn rcmd
8358f0484fSRodney W. Grimesfunction
8458f0484fSRodney W. Grimeslooks up the host
8558f0484fSRodney W. Grimes.Fa *ahost
8658f0484fSRodney W. Grimesusing
8758f0484fSRodney W. Grimes.Xr gethostbyname 3 ,
88a56a8ad1SYoshinobu Inouereturning -1 if the host does not exist.
8958f0484fSRodney W. GrimesOtherwise
9058f0484fSRodney W. Grimes.Fa *ahost
9158f0484fSRodney W. Grimesis set to the standard name of the host
9258f0484fSRodney W. Grimesand a connection is established to a server
9358f0484fSRodney W. Grimesresiding at the well-known Internet port
9458f0484fSRodney W. Grimes.Fa inport .
9558f0484fSRodney W. Grimes.Pp
9658f0484fSRodney W. GrimesIf the connection succeeds,
9758f0484fSRodney W. Grimesa socket in the Internet domain of type
9858f0484fSRodney W. Grimes.Dv SOCK_STREAM
9958f0484fSRodney W. Grimesis returned to the caller, and given to the remote
10058f0484fSRodney W. Grimescommand as
101ae828962SRuslan Ermilov.Dv stdin
10258f0484fSRodney W. Grimesand
103ae828962SRuslan Ermilov.Dv stdout .
10458f0484fSRodney W. GrimesIf
10558f0484fSRodney W. Grimes.Fa fd2p
10658f0484fSRodney W. Grimesis non-zero, then an auxiliary channel to a control
10758f0484fSRodney W. Grimesprocess will be set up, and a descriptor for it will be placed
10858f0484fSRodney W. Grimesin
10958f0484fSRodney W. Grimes.Fa *fd2p .
11058f0484fSRodney W. GrimesThe control process will return diagnostic
11158f0484fSRodney W. Grimesoutput from the command (unit 2) on this channel, and will also
11258f0484fSRodney W. Grimesaccept bytes on this channel as being
1131798791dSRuslan Ermilov.Ux
11458f0484fSRodney W. Grimessignal numbers, to be
11558f0484fSRodney W. Grimesforwarded to the process group of the command.
11658f0484fSRodney W. GrimesIf
11758f0484fSRodney W. Grimes.Fa fd2p
11858f0484fSRodney W. Grimesis 0, then the
119ae828962SRuslan Ermilov.Dv stderr
12058f0484fSRodney W. Grimes(unit 2 of the remote
12158f0484fSRodney W. Grimescommand) will be made the same as the
122ae828962SRuslan Ermilov.Dv stdout
12358f0484fSRodney W. Grimesand no
12458f0484fSRodney W. Grimesprovision is made for sending arbitrary signals to the remote process,
12558f0484fSRodney W. Grimesalthough you may be able to get its attention by using out-of-band data.
12658f0484fSRodney W. Grimes.Pp
12758f0484fSRodney W. GrimesThe protocol is described in detail in
12858f0484fSRodney W. Grimes.Xr rshd 8 .
12958f0484fSRodney W. Grimes.Pp
13058f0484fSRodney W. GrimesThe
13158f0484fSRodney W. Grimes.Fn rresvport
132a56a8ad1SYoshinobu Inouefunction is used to obtain a socket to which an address with a Privileged
133a56a8ad1SYoshinobu InoueInternet port is bound.
134a56a8ad1SYoshinobu InoueThis socket is suitable for use by
13558f0484fSRodney W. Grimes.Fn rcmd
136a56a8ad1SYoshinobu Inoueand several other functions.
137a56a8ad1SYoshinobu InouePrivileged Internet ports are those in the range 0 to 1023.
138a56a8ad1SYoshinobu InoueOnly the super-user is allowed to bind an address of this sort
139a56a8ad1SYoshinobu Inoueto a socket.
14058f0484fSRodney W. Grimes.Pp
14158f0484fSRodney W. GrimesThe
14258f0484fSRodney W. Grimes.Fn iruserok
14358f0484fSRodney W. Grimesand
14458f0484fSRodney W. Grimes.Fn ruserok
14558f0484fSRodney W. Grimesfunctions take a remote host's IP address or name, as returned by the
14658f0484fSRodney W. Grimes.Xr gethostbyname 3
14758f0484fSRodney W. Grimesroutines, two user names and a flag indicating whether the local user's
14858f0484fSRodney W. Grimesname is that of the super-user.
14958f0484fSRodney W. GrimesThen, if the user is
15058f0484fSRodney W. Grimes.Em NOT
15158f0484fSRodney W. Grimesthe super-user, it checks the
15258f0484fSRodney W. Grimes.Pa /etc/hosts.equiv
15358f0484fSRodney W. Grimesfile.
15458f0484fSRodney W. GrimesIf that lookup is not done, or is unsuccessful, the
15558f0484fSRodney W. Grimes.Pa .rhosts
15658f0484fSRodney W. Grimesin the local user's home directory is checked to see if the request for
15758f0484fSRodney W. Grimesservice is allowed.
15858f0484fSRodney W. Grimes.Pp
15958f0484fSRodney W. GrimesIf this file does not exist, is not a regular file, is owned by anyone
160a5ed710cSMike Pritchardother than the user or the super-user, or is writable by anyone other
16158f0484fSRodney W. Grimesthan the owner, the check automatically fails.
16258f0484fSRodney W. GrimesZero is returned if the machine name is listed in the
16358f0484fSRodney W. Grimes.Dq Pa hosts.equiv
16458f0484fSRodney W. Grimesfile, or the host and remote user name are found in the
16558f0484fSRodney W. Grimes.Dq Pa .rhosts
16658f0484fSRodney W. Grimesfile; otherwise
16758f0484fSRodney W. Grimes.Fn iruserok
16858f0484fSRodney W. Grimesand
16958f0484fSRodney W. Grimes.Fn ruserok
170a56a8ad1SYoshinobu Inouereturn -1.
17158f0484fSRodney W. GrimesIf the local domain (as obtained from
172e1f4e80cSMike Pritchard.Xr gethostname 3 )
17358f0484fSRodney W. Grimesis the same as the remote domain, only the machine name need be specified.
17458f0484fSRodney W. Grimes.Pp
17558f0484fSRodney W. GrimesThe
17658f0484fSRodney W. Grimes.Fn iruserok
17758f0484fSRodney W. Grimesfunction is strongly preferred for security reasons.
17858f0484fSRodney W. GrimesIt requires trusting the local DNS at most, while the
17958f0484fSRodney W. Grimes.Fn ruserok
18058f0484fSRodney W. Grimesfunction requires trusting the entire DNS, which can be spoofed.
18142b4f28eSYoshinobu Inoue.Pp
182a56a8ad1SYoshinobu InoueThe functions with an
1830cac72f4SYoshinobu Inoue.Dq Li _af
184265fb60dSYoshinobu Inoueor
185a56a8ad1SYoshinobu Inoue.Dq Li _sa
186a56a8ad1SYoshinobu Inouesuffix, i.e.,
187a56a8ad1SYoshinobu Inoue.Fn rcmd_af ,
188a56a8ad1SYoshinobu Inoue.Fn rresvport_af
189a56a8ad1SYoshinobu Inoueand
190a56a8ad1SYoshinobu Inoue.Fn iruserok_sa ,
191265fb60dSYoshinobu Inouework the same as the corresponding functions without a
192a56a8ad1SYoshinobu Inouesuffix, except that they are capable of handling both IPv6 and IPv4 ports.
193a56a8ad1SYoshinobu Inoue.Pp
194a56a8ad1SYoshinobu InoueThe
195a56a8ad1SYoshinobu Inoue.Dq Li _af
196265fb60dSYoshinobu Inouesuffix means that the function has an additional
197a56a8ad1SYoshinobu Inoue.Fa af
198265fb60dSYoshinobu Inoueargument which is used to specify the address family,
199265fb60dSYoshinobu Inoue(see below).
200a56a8ad1SYoshinobu InoueThe
201a56a8ad1SYoshinobu Inoue.Fa af
202a56a8ad1SYoshinobu Inoueargument extension is implemented for functions
203265fb60dSYoshinobu Inouethat have no binary address argument.
204a56a8ad1SYoshinobu InoueInstead, the
205a56a8ad1SYoshinobu Inoue.Fa af
206a56a8ad1SYoshinobu Inoueargument specifies which address family is desired.
207a56a8ad1SYoshinobu Inoue.Pp
208a56a8ad1SYoshinobu InoueThe
209a56a8ad1SYoshinobu Inoue.Dq Li _sa
210265fb60dSYoshinobu Inouesuffix means that the function has general socket address and
211265fb60dSYoshinobu Inouelength arguments.
212a56a8ad1SYoshinobu InoueAs the socket address is a protocol independent data structure,
213a56a8ad1SYoshinobu InoueIPv4 and IPv6 socket address can be passed as desired.
214265fb60dSYoshinobu InoueThe
215a56a8ad1SYoshinobu Inoue.Fa sa
216a56a8ad1SYoshinobu Inoueargument extension is implemented for functions
217265fb60dSYoshinobu Inouethat pass a protocol dependent binary address argument.
218265fb60dSYoshinobu InoueThe argument needs to be replaced with a more general address structure
219a56a8ad1SYoshinobu Inoueto support multiple address families in a general way.
220a56a8ad1SYoshinobu Inoue.Pp
221265fb60dSYoshinobu InoueThe functions with neither an
222a56a8ad1SYoshinobu Inoue.Dq Li _af
223265fb60dSYoshinobu Inouesuffix nor an
224a56a8ad1SYoshinobu Inoue.Dq Li _sa
225a56a8ad1SYoshinobu Inouesuffix work for IPv4 only, except for
226a56a8ad1SYoshinobu Inoue.Fn ruserok
227a56a8ad1SYoshinobu Inouewhich can handle both IPv6 and IPv4.
228265fb60dSYoshinobu InoueTo switch the address family, the
22942b4f28eSYoshinobu Inoue.Fa af
23042b4f28eSYoshinobu Inoueargument must be filled with
2310cac72f4SYoshinobu Inoue.Dv AF_INET ,
23242b4f28eSYoshinobu Inoueor
23342b4f28eSYoshinobu Inoue.Dv AF_INET6 .
2340cac72f4SYoshinobu InoueFor
2350cac72f4SYoshinobu Inoue.Fn rcmd_af ,
2360cac72f4SYoshinobu Inoue.Dv PF_UNSPEC
2370cac72f4SYoshinobu Inoueis also allowed.
2384e543e5cSMurray Stokely.Sh ENVIRONMENT
2394e543e5cSMurray Stokely.Bl -tag -width RSH
2404e543e5cSMurray Stokely.It Ev RSH
2414e543e5cSMurray StokelyWhen using the
2424e543e5cSMurray Stokely.Fn rcmd
2434e543e5cSMurray Stokelyfunction, this variable is used as the program to run instead of
2444e543e5cSMurray Stokely.Xr rsh 1 .
245a8da143aSXin LI.El
24658f0484fSRodney W. Grimes.Sh DIAGNOSTICS
24758f0484fSRodney W. GrimesThe
24858f0484fSRodney W. Grimes.Fn rcmd
24958f0484fSRodney W. Grimesfunction
25058f0484fSRodney W. Grimesreturns a valid socket descriptor on success.
251a56a8ad1SYoshinobu InoueIt returns -1 on error and prints a diagnostic message
252a56a8ad1SYoshinobu Inoueon the standard error.
25358f0484fSRodney W. Grimes.Pp
25458f0484fSRodney W. GrimesThe
25558f0484fSRodney W. Grimes.Fn rresvport
25658f0484fSRodney W. Grimesfunction
25758f0484fSRodney W. Grimesreturns a valid, bound socket descriptor on success.
258a56a8ad1SYoshinobu InoueIt returns -1 on error with the global value
25958f0484fSRodney W. Grimes.Va errno
26058f0484fSRodney W. Grimesset according to the reason for failure.
26158f0484fSRodney W. GrimesThe error code
262c23155a4SRuslan Ermilov.Er EAGAIN
26358f0484fSRodney W. Grimesis overloaded to mean ``All network ports in use.''
26458f0484fSRodney W. Grimes.Sh SEE ALSO
26558f0484fSRodney W. Grimes.Xr rlogin 1 ,
26658f0484fSRodney W. Grimes.Xr rsh 1 ,
26758f0484fSRodney W. Grimes.Xr intro 2 ,
26858f0484fSRodney W. Grimes.Xr rlogind 8 ,
26958f0484fSRodney W. Grimes.Xr rshd 8
27042b4f28eSYoshinobu Inoue.Pp
271a56a8ad1SYoshinobu Inoue.Rs
2720f5fcaa3SSheldon Hearn.%A W. Stevens
2730f5fcaa3SSheldon Hearn.%A M. Thomas
274265fb60dSYoshinobu Inoue.%T "Advanced Socket API for IPv6"
275265fb60dSYoshinobu Inoue.%O RFC2292
276a56a8ad1SYoshinobu Inoue.Re
277a56a8ad1SYoshinobu Inoue.Rs
2780f5fcaa3SSheldon Hearn.%A W. Stevens
2790f5fcaa3SSheldon Hearn.%A M. Thomas
2800f5fcaa3SSheldon Hearn.%A E. Nordmark
281265fb60dSYoshinobu Inoue.%T "Advanced Socket API for IPv6"
282d84e2130SHajimu UMEMOTO.%O RFC3542
283a56a8ad1SYoshinobu Inoue.Re
28458f0484fSRodney W. Grimes.Sh HISTORY
285265fb60dSYoshinobu InoueMost of these
28658f0484fSRodney W. Grimesfunctions appeared in
28758f0484fSRodney W. Grimes.Bx 4.2 .
2881fae73b1SRuslan ErmilovThe
28942b4f28eSYoshinobu Inoue.Fn rresvport_af
2901fae73b1SRuslan Ermilovfunction
291a56a8ad1SYoshinobu Inoueappeared in RFC2292, and was implemented by the WIDE project
292a56a8ad1SYoshinobu Inouefor the Hydrangea IPv6 protocol stack kit.
2931fae73b1SRuslan ErmilovThe
2940cac72f4SYoshinobu Inoue.Fn rcmd_af
2951fae73b1SRuslan Ermilovfunction
2960cac72f4SYoshinobu Inoueappeared in draft-ietf-ipngwg-rfc2292bis-01.txt,
297a56a8ad1SYoshinobu Inoueand was implemented in the WIDE/KAME IPv6 protocol stack kit.
2981fae73b1SRuslan ErmilovThe
299a56a8ad1SYoshinobu Inoue.Fn iruserok_sa
3001fae73b1SRuslan Ermilovfunction
301a56a8ad1SYoshinobu Inoueappeared in discussion on the IETF ipngwg mailing list,
302a56a8ad1SYoshinobu Inoueand was implemented in
303a56a8ad1SYoshinobu Inoue.Fx 4.0 .
304