xref: /freebsd/lib/libc/net/rcmd.3 (revision 265fb60da426dd7c83c49e648e767b99c70797ce)
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.\" 3. All advertising materials mentioning features or use of this software
1358f0484fSRodney W. Grimes.\"    must display the following acknowledgement:
1458f0484fSRodney W. Grimes.\"	This product includes software developed by the University of
1558f0484fSRodney W. Grimes.\"	California, Berkeley and its contributors.
1658f0484fSRodney W. Grimes.\" 4. Neither the name of the University nor the names of its contributors
1758f0484fSRodney W. Grimes.\"    may be used to endorse or promote products derived from this software
1858f0484fSRodney W. Grimes.\"    without specific prior written permission.
1958f0484fSRodney W. Grimes.\"
2058f0484fSRodney W. Grimes.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2158f0484fSRodney W. Grimes.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2258f0484fSRodney W. Grimes.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2358f0484fSRodney W. Grimes.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2458f0484fSRodney W. Grimes.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2558f0484fSRodney W. Grimes.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2658f0484fSRodney W. Grimes.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2758f0484fSRodney W. Grimes.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2858f0484fSRodney W. Grimes.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2958f0484fSRodney W. Grimes.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3058f0484fSRodney W. Grimes.\" SUCH DAMAGE.
3158f0484fSRodney W. Grimes.\"
325900c007SGarrett Wollman.\"     From: @(#)rcmd.3	8.1 (Berkeley) 6/4/93
337f3dea24SPeter Wemm.\" $FreeBSD$
3458f0484fSRodney W. Grimes.\"
35a56a8ad1SYoshinobu Inoue.Dd March 3, 2000
3658f0484fSRodney W. Grimes.Dt RCMD 3
3758f0484fSRodney W. Grimes.Os BSD 4.2
3858f0484fSRodney W. Grimes.Sh NAME
3958f0484fSRodney W. Grimes.Nm rcmd ,
4058f0484fSRodney W. Grimes.Nm rresvport ,
413573df98SRodney W. Grimes.Nm iruserok ,
4242b4f28eSYoshinobu Inoue.Nm ruserok ,
430cac72f4SYoshinobu Inoue.Nm rcmd_af ,
4442b4f28eSYoshinobu Inoue.Nm rresvport_af ,
45a56a8ad1SYoshinobu Inoue.Nm iruserok_sa
4658f0484fSRodney W. Grimes.Nd routines for returning a stream to a remote command
4758f0484fSRodney W. Grimes.Sh SYNOPSIS
4858f0484fSRodney W. Grimes.Fd #include <unistd.h>
4958f0484fSRodney W. Grimes.Ft int
5058f0484fSRodney W. Grimes.Fn rcmd "char **ahost" "int inport" "const char *locuser" "const char *remuser" "const char *cmd" "int *fd2p"
5158f0484fSRodney W. Grimes.Ft int
5258f0484fSRodney W. Grimes.Fn rresvport "int *port"
5358f0484fSRodney W. Grimes.Ft int
5458f0484fSRodney W. Grimes.Fn iruserok "u_long raddr" "int superuser" "const char *ruser" "const char *luser"
5558f0484fSRodney W. Grimes.Ft int
5658f0484fSRodney W. Grimes.Fn ruserok "const char *rhost" "int superuser" "const char *ruser" "const char *luser"
5742b4f28eSYoshinobu Inoue.Ft int
580cac72f4SYoshinobu Inoue.Fn rcmd_af "char **ahost" "int inport" "const char *locuser" "const char *remuser" "const char *cmd" "int *fd2p" "int af"
590cac72f4SYoshinobu Inoue.Ft int
600cac72f4SYoshinobu Inoue.Fn rresvport_af "int *port" "int af"
6142b4f28eSYoshinobu Inoue.Ft int
62a56a8ad1SYoshinobu Inoue.Fn iruserok_sa "const void *addr" "int addrlen" "int superuser" "const char *ruser" "const char *luser"
6358f0484fSRodney W. Grimes.Sh DESCRIPTION
6458f0484fSRodney W. GrimesThe
6558f0484fSRodney W. Grimes.Fn rcmd
6658f0484fSRodney W. Grimesfunction
6758f0484fSRodney W. Grimesis used by the super-user to execute a command on
6858f0484fSRodney W. Grimesa remote machine using an authentication scheme based
6958f0484fSRodney W. Grimeson reserved port numbers.
7058f0484fSRodney W. GrimesThe
7158f0484fSRodney W. Grimes.Fn rresvport
7258f0484fSRodney W. Grimesfunction
7358f0484fSRodney W. Grimesreturns a descriptor to a socket
7458f0484fSRodney W. Grimeswith an address in the privileged port space.
7558f0484fSRodney W. GrimesThe
7658f0484fSRodney W. Grimes.Fn ruserok
7758f0484fSRodney W. Grimesfunction
7858f0484fSRodney W. Grimesis used by servers
7958f0484fSRodney W. Grimesto authenticate clients requesting service with
8058f0484fSRodney W. Grimes.Fn rcmd .
8158f0484fSRodney W. GrimesAll three functions are present in the same file and are used
8258f0484fSRodney W. Grimesby the
8358f0484fSRodney W. Grimes.Xr rshd 8
8458f0484fSRodney W. Grimesserver (among others).
8558f0484fSRodney W. Grimes.Pp
8658f0484fSRodney W. GrimesThe
8758f0484fSRodney W. Grimes.Fn rcmd
8858f0484fSRodney W. Grimesfunction
8958f0484fSRodney W. Grimeslooks up the host
9058f0484fSRodney W. Grimes.Fa *ahost
9158f0484fSRodney W. Grimesusing
9258f0484fSRodney W. Grimes.Xr gethostbyname 3 ,
93a56a8ad1SYoshinobu Inouereturning -1 if the host does not exist.
9458f0484fSRodney W. GrimesOtherwise
9558f0484fSRodney W. Grimes.Fa *ahost
9658f0484fSRodney W. Grimesis set to the standard name of the host
9758f0484fSRodney W. Grimesand a connection is established to a server
9858f0484fSRodney W. Grimesresiding at the well-known Internet port
9958f0484fSRodney W. Grimes.Fa inport .
10058f0484fSRodney W. Grimes.Pp
10158f0484fSRodney W. GrimesIf the connection succeeds,
10258f0484fSRodney W. Grimesa socket in the Internet domain of type
10358f0484fSRodney W. Grimes.Dv SOCK_STREAM
10458f0484fSRodney W. Grimesis returned to the caller, and given to the remote
10558f0484fSRodney W. Grimescommand as
10658f0484fSRodney W. Grimes.Em stdin
10758f0484fSRodney W. Grimesand
10858f0484fSRodney W. Grimes.Em stdout .
10958f0484fSRodney W. GrimesIf
11058f0484fSRodney W. Grimes.Fa fd2p
11158f0484fSRodney W. Grimesis non-zero, then an auxiliary channel to a control
11258f0484fSRodney W. Grimesprocess will be set up, and a descriptor for it will be placed
11358f0484fSRodney W. Grimesin
11458f0484fSRodney W. Grimes.Fa *fd2p .
11558f0484fSRodney W. GrimesThe control process will return diagnostic
11658f0484fSRodney W. Grimesoutput from the command (unit 2) on this channel, and will also
11758f0484fSRodney W. Grimesaccept bytes on this channel as being
11858f0484fSRodney W. Grimes.Tn UNIX
11958f0484fSRodney W. Grimessignal numbers, to be
12058f0484fSRodney W. Grimesforwarded to the process group of the command.
12158f0484fSRodney W. GrimesIf
12258f0484fSRodney W. Grimes.Fa fd2p
12358f0484fSRodney W. Grimesis 0, then the
12458f0484fSRodney W. Grimes.Em stderr
12558f0484fSRodney W. Grimes(unit 2 of the remote
12658f0484fSRodney W. Grimescommand) will be made the same as the
12758f0484fSRodney W. Grimes.Em stdout
12858f0484fSRodney W. Grimesand no
12958f0484fSRodney W. Grimesprovision is made for sending arbitrary signals to the remote process,
13058f0484fSRodney W. Grimesalthough you may be able to get its attention by using out-of-band data.
13158f0484fSRodney W. Grimes.Pp
13258f0484fSRodney W. GrimesThe protocol is described in detail in
13358f0484fSRodney W. Grimes.Xr rshd 8 .
13458f0484fSRodney W. Grimes.Pp
13558f0484fSRodney W. GrimesThe
13658f0484fSRodney W. Grimes.Fn rresvport
137a56a8ad1SYoshinobu Inouefunction is used to obtain a socket to which an address with a Privileged
138a56a8ad1SYoshinobu InoueInternet port is bound.
139a56a8ad1SYoshinobu InoueThis socket is suitable for use by
14058f0484fSRodney W. Grimes.Fn rcmd
141a56a8ad1SYoshinobu Inoueand several other functions.
142a56a8ad1SYoshinobu InouePrivileged Internet ports are those in the range 0 to 1023.
143a56a8ad1SYoshinobu InoueOnly the super-user is allowed to bind an address of this sort
144a56a8ad1SYoshinobu Inoueto a socket.
14558f0484fSRodney W. Grimes.Pp
14658f0484fSRodney W. GrimesThe
14758f0484fSRodney W. Grimes.Fn iruserok
14858f0484fSRodney W. Grimesand
14958f0484fSRodney W. Grimes.Fn ruserok
15058f0484fSRodney W. Grimesfunctions take a remote host's IP address or name, as returned by the
15158f0484fSRodney W. Grimes.Xr gethostbyname 3
15258f0484fSRodney W. Grimesroutines, two user names and a flag indicating whether the local user's
15358f0484fSRodney W. Grimesname is that of the super-user.
15458f0484fSRodney W. GrimesThen, if the user is
15558f0484fSRodney W. Grimes.Em NOT
15658f0484fSRodney W. Grimesthe super-user, it checks the
15758f0484fSRodney W. Grimes.Pa /etc/hosts.equiv
15858f0484fSRodney W. Grimesfile.
15958f0484fSRodney W. GrimesIf that lookup is not done, or is unsuccessful, the
16058f0484fSRodney W. Grimes.Pa .rhosts
16158f0484fSRodney W. Grimesin the local user's home directory is checked to see if the request for
16258f0484fSRodney W. Grimesservice is allowed.
16358f0484fSRodney W. Grimes.Pp
16458f0484fSRodney W. GrimesIf this file does not exist, is not a regular file, is owned by anyone
165a5ed710cSMike Pritchardother than the user or the super-user, or is writable by anyone other
16658f0484fSRodney W. Grimesthan the owner, the check automatically fails.
16758f0484fSRodney W. GrimesZero is returned if the machine name is listed in the
16858f0484fSRodney W. Grimes.Dq Pa hosts.equiv
16958f0484fSRodney W. Grimesfile, or the host and remote user name are found in the
17058f0484fSRodney W. Grimes.Dq Pa .rhosts
17158f0484fSRodney W. Grimesfile; otherwise
17258f0484fSRodney W. Grimes.Fn iruserok
17358f0484fSRodney W. Grimesand
17458f0484fSRodney W. Grimes.Fn ruserok
175a56a8ad1SYoshinobu Inouereturn -1.
17658f0484fSRodney W. GrimesIf the local domain (as obtained from
177e1f4e80cSMike Pritchard.Xr gethostname 3 )
17858f0484fSRodney W. Grimesis the same as the remote domain, only the machine name need be specified.
17958f0484fSRodney W. Grimes.Pp
18058f0484fSRodney W. GrimesThe
18158f0484fSRodney W. Grimes.Fn iruserok
18258f0484fSRodney W. Grimesfunction is strongly preferred for security reasons.
18358f0484fSRodney W. GrimesIt requires trusting the local DNS at most, while the
18458f0484fSRodney W. Grimes.Fn ruserok
18558f0484fSRodney W. Grimesfunction requires trusting the entire DNS, which can be spoofed.
18642b4f28eSYoshinobu Inoue.Pp
187a56a8ad1SYoshinobu InoueThe functions with an
1880cac72f4SYoshinobu Inoue.Dq Li _af
189265fb60dSYoshinobu Inoueor
190a56a8ad1SYoshinobu Inoue.Dq Li _sa
191a56a8ad1SYoshinobu Inouesuffix, i.e.,
192a56a8ad1SYoshinobu Inoue.Fn rcmd_af ,
193a56a8ad1SYoshinobu Inoue.Fn rresvport_af
194a56a8ad1SYoshinobu Inoueand
195a56a8ad1SYoshinobu Inoue.Fn iruserok_sa ,
196265fb60dSYoshinobu Inouework the same as the corresponding functions without a
197a56a8ad1SYoshinobu Inouesuffix, except that they are capable of handling both IPv6 and IPv4 ports.
198a56a8ad1SYoshinobu Inoue.Pp
199a56a8ad1SYoshinobu InoueThe
200a56a8ad1SYoshinobu Inoue.Dq Li _af
201265fb60dSYoshinobu Inouesuffix means that the function has an additional
202a56a8ad1SYoshinobu Inoue.Fa af
203265fb60dSYoshinobu Inoueargument which is used to specify the address family,
204265fb60dSYoshinobu Inoue(see below).
205a56a8ad1SYoshinobu InoueThe
206a56a8ad1SYoshinobu Inoue.Fa af
207a56a8ad1SYoshinobu Inoueargument extension is implemented for functions
208265fb60dSYoshinobu Inouethat have no binary address argument.
209a56a8ad1SYoshinobu InoueInstead, the
210a56a8ad1SYoshinobu Inoue.Fa af
211a56a8ad1SYoshinobu Inoueargument specifies which address family is desired.
212a56a8ad1SYoshinobu Inoue.Pp
213a56a8ad1SYoshinobu InoueThe
214a56a8ad1SYoshinobu Inoue.Dq Li _sa
215265fb60dSYoshinobu Inouesuffix means that the function has general socket address and
216265fb60dSYoshinobu Inouelength arguments.
217a56a8ad1SYoshinobu InoueAs the socket address is a protocol independent data structure,
218a56a8ad1SYoshinobu InoueIPv4 and IPv6 socket address can be passed as desired.
219265fb60dSYoshinobu InoueThe
220a56a8ad1SYoshinobu Inoue.Fa sa
221a56a8ad1SYoshinobu Inoueargument extension is implemented for functions
222265fb60dSYoshinobu Inouethat pass a protocol dependent binary address argument.
223265fb60dSYoshinobu InoueThe argument needs to be replaced with a more general address structure
224a56a8ad1SYoshinobu Inoueto support multiple address families in a general way.
225a56a8ad1SYoshinobu Inoue.Pp
226265fb60dSYoshinobu InoueThe functions with neither an
227a56a8ad1SYoshinobu Inoue.Dq Li _af
228265fb60dSYoshinobu Inouesuffix nor an
229a56a8ad1SYoshinobu Inoue.Dq Li _sa
230a56a8ad1SYoshinobu Inouesuffix work for IPv4 only, except for
231a56a8ad1SYoshinobu Inoue.Fn ruserok
232a56a8ad1SYoshinobu Inouewhich can handle both IPv6 and IPv4.
233265fb60dSYoshinobu InoueTo switch the address family, the
23442b4f28eSYoshinobu Inoue.Fa af
23542b4f28eSYoshinobu Inoueargument must be filled with
2360cac72f4SYoshinobu Inoue.Dv AF_INET ,
23742b4f28eSYoshinobu Inoueor
23842b4f28eSYoshinobu Inoue.Dv AF_INET6 .
2390cac72f4SYoshinobu InoueFor
2400cac72f4SYoshinobu Inoue.Fn rcmd_af ,
2410cac72f4SYoshinobu Inoue.Dv PF_UNSPEC
2420cac72f4SYoshinobu Inoueis also allowed.
24358f0484fSRodney W. Grimes.Sh DIAGNOSTICS
24458f0484fSRodney W. GrimesThe
24558f0484fSRodney W. Grimes.Fn rcmd
24658f0484fSRodney W. Grimesfunction
24758f0484fSRodney W. Grimesreturns a valid socket descriptor on success.
248a56a8ad1SYoshinobu InoueIt returns -1 on error and prints a diagnostic message
249a56a8ad1SYoshinobu Inoueon the standard error.
25058f0484fSRodney W. Grimes.Pp
25158f0484fSRodney W. GrimesThe
25258f0484fSRodney W. Grimes.Fn rresvport
25358f0484fSRodney W. Grimesfunction
25458f0484fSRodney W. Grimesreturns a valid, bound socket descriptor on success.
255a56a8ad1SYoshinobu InoueIt returns -1 on error with the global value
25658f0484fSRodney W. Grimes.Va errno
25758f0484fSRodney W. Grimesset according to the reason for failure.
25858f0484fSRodney W. GrimesThe error code
25958f0484fSRodney W. Grimes.Dv EAGAIN
26058f0484fSRodney W. Grimesis overloaded to mean ``All network ports in use.''
26158f0484fSRodney W. Grimes.Sh SEE ALSO
26258f0484fSRodney W. Grimes.Xr rlogin 1 ,
26358f0484fSRodney W. Grimes.Xr rsh 1 ,
26458f0484fSRodney W. Grimes.Xr intro 2 ,
26558f0484fSRodney W. Grimes.Xr rexec 3 ,
26658f0484fSRodney W. Grimes.Xr rexecd 8 ,
26758f0484fSRodney W. Grimes.Xr rlogind 8 ,
26858f0484fSRodney W. Grimes.Xr rshd 8
26942b4f28eSYoshinobu Inoue.Pp
270a56a8ad1SYoshinobu Inoue.Rs
271a56a8ad1SYoshinobu Inoue.%A W. Stevens and M. Thomas
272265fb60dSYoshinobu Inoue.%T "Advanced Socket API for IPv6"
273265fb60dSYoshinobu Inoue.%O RFC2292
274a56a8ad1SYoshinobu Inoue.Re
275a56a8ad1SYoshinobu Inoue.Rs
276a56a8ad1SYoshinobu Inoue.%A W. Stevens, M. Thomas and E. Nordmark
277265fb60dSYoshinobu Inoue.%T "Advanced Socket API for IPv6"
278265fb60dSYoshinobu Inoue.%O draft-ietf-ipngwg-rfc2292bis-01.txt
279a56a8ad1SYoshinobu Inoue.Re
28058f0484fSRodney W. Grimes.Sh HISTORY
281265fb60dSYoshinobu InoueMost of these
28258f0484fSRodney W. Grimesfunctions appeared in
28358f0484fSRodney W. Grimes.Bx 4.2 .
28442b4f28eSYoshinobu Inoue.Fn rresvport_af
285a56a8ad1SYoshinobu Inoueappeared in RFC2292, and was implemented by the WIDE project
286a56a8ad1SYoshinobu Inouefor the Hydrangea IPv6 protocol stack kit.
2870cac72f4SYoshinobu Inoue.Fn rcmd_af
2880cac72f4SYoshinobu Inoueappeared in draft-ietf-ipngwg-rfc2292bis-01.txt,
289a56a8ad1SYoshinobu Inoueand was implemented in the WIDE/KAME IPv6 protocol stack kit.
290a56a8ad1SYoshinobu Inoue.Fn iruserok_sa
291a56a8ad1SYoshinobu Inoueappeared in discussion on the IETF ipngwg mailing list,
292a56a8ad1SYoshinobu Inoueand was implemented in
293a56a8ad1SYoshinobu Inoue.Fx 4.0 .
294