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 4725bb73e0SAlexey Zelkin.Sh LIBRARY 4825bb73e0SAlexey Zelkin.Lb libc 4958f0484fSRodney W. Grimes.Sh SYNOPSIS 5058f0484fSRodney W. Grimes.Fd #include <unistd.h> 5158f0484fSRodney W. Grimes.Ft int 5258f0484fSRodney W. Grimes.Fn rcmd "char **ahost" "int inport" "const char *locuser" "const char *remuser" "const char *cmd" "int *fd2p" 5358f0484fSRodney W. Grimes.Ft int 5458f0484fSRodney W. Grimes.Fn rresvport "int *port" 5558f0484fSRodney W. Grimes.Ft int 5658f0484fSRodney W. Grimes.Fn iruserok "u_long raddr" "int superuser" "const char *ruser" "const char *luser" 5758f0484fSRodney W. Grimes.Ft int 5858f0484fSRodney W. Grimes.Fn ruserok "const char *rhost" "int superuser" "const char *ruser" "const char *luser" 5942b4f28eSYoshinobu Inoue.Ft int 600cac72f4SYoshinobu Inoue.Fn rcmd_af "char **ahost" "int inport" "const char *locuser" "const char *remuser" "const char *cmd" "int *fd2p" "int af" 610cac72f4SYoshinobu Inoue.Ft int 620cac72f4SYoshinobu Inoue.Fn rresvport_af "int *port" "int af" 6342b4f28eSYoshinobu Inoue.Ft int 64a56a8ad1SYoshinobu Inoue.Fn iruserok_sa "const void *addr" "int addrlen" "int superuser" "const char *ruser" "const char *luser" 6558f0484fSRodney W. Grimes.Sh DESCRIPTION 6658f0484fSRodney W. GrimesThe 6758f0484fSRodney W. Grimes.Fn rcmd 6858f0484fSRodney W. Grimesfunction 6958f0484fSRodney W. Grimesis used by the super-user to execute a command on 7058f0484fSRodney W. Grimesa remote machine using an authentication scheme based 7158f0484fSRodney W. Grimeson reserved port numbers. 7258f0484fSRodney W. GrimesThe 7358f0484fSRodney W. Grimes.Fn rresvport 7458f0484fSRodney W. Grimesfunction 7558f0484fSRodney W. Grimesreturns a descriptor to a socket 7658f0484fSRodney W. Grimeswith an address in the privileged port space. 7758f0484fSRodney W. GrimesThe 7858f0484fSRodney W. Grimes.Fn ruserok 7958f0484fSRodney W. Grimesfunction 8058f0484fSRodney W. Grimesis used by servers 8158f0484fSRodney W. Grimesto authenticate clients requesting service with 8258f0484fSRodney W. Grimes.Fn rcmd . 8358f0484fSRodney W. GrimesAll three functions are present in the same file and are used 8458f0484fSRodney W. Grimesby the 8558f0484fSRodney W. Grimes.Xr rshd 8 8658f0484fSRodney W. Grimesserver (among others). 8758f0484fSRodney W. Grimes.Pp 8858f0484fSRodney W. GrimesThe 8958f0484fSRodney W. Grimes.Fn rcmd 9058f0484fSRodney W. Grimesfunction 9158f0484fSRodney W. Grimeslooks up the host 9258f0484fSRodney W. Grimes.Fa *ahost 9358f0484fSRodney W. Grimesusing 9458f0484fSRodney W. Grimes.Xr gethostbyname 3 , 95a56a8ad1SYoshinobu Inouereturning -1 if the host does not exist. 9658f0484fSRodney W. GrimesOtherwise 9758f0484fSRodney W. Grimes.Fa *ahost 9858f0484fSRodney W. Grimesis set to the standard name of the host 9958f0484fSRodney W. Grimesand a connection is established to a server 10058f0484fSRodney W. Grimesresiding at the well-known Internet port 10158f0484fSRodney W. Grimes.Fa inport . 10258f0484fSRodney W. Grimes.Pp 10358f0484fSRodney W. GrimesIf the connection succeeds, 10458f0484fSRodney W. Grimesa socket in the Internet domain of type 10558f0484fSRodney W. Grimes.Dv SOCK_STREAM 10658f0484fSRodney W. Grimesis returned to the caller, and given to the remote 10758f0484fSRodney W. Grimescommand as 10858f0484fSRodney W. Grimes.Em stdin 10958f0484fSRodney W. Grimesand 11058f0484fSRodney W. Grimes.Em stdout . 11158f0484fSRodney W. GrimesIf 11258f0484fSRodney W. Grimes.Fa fd2p 11358f0484fSRodney W. Grimesis non-zero, then an auxiliary channel to a control 11458f0484fSRodney W. Grimesprocess will be set up, and a descriptor for it will be placed 11558f0484fSRodney W. Grimesin 11658f0484fSRodney W. Grimes.Fa *fd2p . 11758f0484fSRodney W. GrimesThe control process will return diagnostic 11858f0484fSRodney W. Grimesoutput from the command (unit 2) on this channel, and will also 11958f0484fSRodney W. Grimesaccept bytes on this channel as being 12058f0484fSRodney W. Grimes.Tn UNIX 12158f0484fSRodney W. Grimessignal numbers, to be 12258f0484fSRodney W. Grimesforwarded to the process group of the command. 12358f0484fSRodney W. GrimesIf 12458f0484fSRodney W. Grimes.Fa fd2p 12558f0484fSRodney W. Grimesis 0, then the 12658f0484fSRodney W. Grimes.Em stderr 12758f0484fSRodney W. Grimes(unit 2 of the remote 12858f0484fSRodney W. Grimescommand) will be made the same as the 12958f0484fSRodney W. Grimes.Em stdout 13058f0484fSRodney W. Grimesand no 13158f0484fSRodney W. Grimesprovision is made for sending arbitrary signals to the remote process, 13258f0484fSRodney W. Grimesalthough you may be able to get its attention by using out-of-band data. 13358f0484fSRodney W. Grimes.Pp 13458f0484fSRodney W. GrimesThe protocol is described in detail in 13558f0484fSRodney W. Grimes.Xr rshd 8 . 13658f0484fSRodney W. Grimes.Pp 13758f0484fSRodney W. GrimesThe 13858f0484fSRodney W. Grimes.Fn rresvport 139a56a8ad1SYoshinobu Inouefunction is used to obtain a socket to which an address with a Privileged 140a56a8ad1SYoshinobu InoueInternet port is bound. 141a56a8ad1SYoshinobu InoueThis socket is suitable for use by 14258f0484fSRodney W. Grimes.Fn rcmd 143a56a8ad1SYoshinobu Inoueand several other functions. 144a56a8ad1SYoshinobu InouePrivileged Internet ports are those in the range 0 to 1023. 145a56a8ad1SYoshinobu InoueOnly the super-user is allowed to bind an address of this sort 146a56a8ad1SYoshinobu Inoueto a socket. 14758f0484fSRodney W. Grimes.Pp 14858f0484fSRodney W. GrimesThe 14958f0484fSRodney W. Grimes.Fn iruserok 15058f0484fSRodney W. Grimesand 15158f0484fSRodney W. Grimes.Fn ruserok 15258f0484fSRodney W. Grimesfunctions take a remote host's IP address or name, as returned by the 15358f0484fSRodney W. Grimes.Xr gethostbyname 3 15458f0484fSRodney W. Grimesroutines, two user names and a flag indicating whether the local user's 15558f0484fSRodney W. Grimesname is that of the super-user. 15658f0484fSRodney W. GrimesThen, if the user is 15758f0484fSRodney W. Grimes.Em NOT 15858f0484fSRodney W. Grimesthe super-user, it checks the 15958f0484fSRodney W. Grimes.Pa /etc/hosts.equiv 16058f0484fSRodney W. Grimesfile. 16158f0484fSRodney W. GrimesIf that lookup is not done, or is unsuccessful, the 16258f0484fSRodney W. Grimes.Pa .rhosts 16358f0484fSRodney W. Grimesin the local user's home directory is checked to see if the request for 16458f0484fSRodney W. Grimesservice is allowed. 16558f0484fSRodney W. Grimes.Pp 16658f0484fSRodney W. GrimesIf this file does not exist, is not a regular file, is owned by anyone 167a5ed710cSMike Pritchardother than the user or the super-user, or is writable by anyone other 16858f0484fSRodney W. Grimesthan the owner, the check automatically fails. 16958f0484fSRodney W. GrimesZero is returned if the machine name is listed in the 17058f0484fSRodney W. Grimes.Dq Pa hosts.equiv 17158f0484fSRodney W. Grimesfile, or the host and remote user name are found in the 17258f0484fSRodney W. Grimes.Dq Pa .rhosts 17358f0484fSRodney W. Grimesfile; otherwise 17458f0484fSRodney W. Grimes.Fn iruserok 17558f0484fSRodney W. Grimesand 17658f0484fSRodney W. Grimes.Fn ruserok 177a56a8ad1SYoshinobu Inouereturn -1. 17858f0484fSRodney W. GrimesIf the local domain (as obtained from 179e1f4e80cSMike Pritchard.Xr gethostname 3 ) 18058f0484fSRodney W. Grimesis the same as the remote domain, only the machine name need be specified. 18158f0484fSRodney W. Grimes.Pp 18258f0484fSRodney W. GrimesThe 18358f0484fSRodney W. Grimes.Fn iruserok 18458f0484fSRodney W. Grimesfunction is strongly preferred for security reasons. 18558f0484fSRodney W. GrimesIt requires trusting the local DNS at most, while the 18658f0484fSRodney W. Grimes.Fn ruserok 18758f0484fSRodney W. Grimesfunction requires trusting the entire DNS, which can be spoofed. 18842b4f28eSYoshinobu Inoue.Pp 189a56a8ad1SYoshinobu InoueThe functions with an 1900cac72f4SYoshinobu Inoue.Dq Li _af 191265fb60dSYoshinobu Inoueor 192a56a8ad1SYoshinobu Inoue.Dq Li _sa 193a56a8ad1SYoshinobu Inouesuffix, i.e., 194a56a8ad1SYoshinobu Inoue.Fn rcmd_af , 195a56a8ad1SYoshinobu Inoue.Fn rresvport_af 196a56a8ad1SYoshinobu Inoueand 197a56a8ad1SYoshinobu Inoue.Fn iruserok_sa , 198265fb60dSYoshinobu Inouework the same as the corresponding functions without a 199a56a8ad1SYoshinobu Inouesuffix, except that they are capable of handling both IPv6 and IPv4 ports. 200a56a8ad1SYoshinobu Inoue.Pp 201a56a8ad1SYoshinobu InoueThe 202a56a8ad1SYoshinobu Inoue.Dq Li _af 203265fb60dSYoshinobu Inouesuffix means that the function has an additional 204a56a8ad1SYoshinobu Inoue.Fa af 205265fb60dSYoshinobu Inoueargument which is used to specify the address family, 206265fb60dSYoshinobu Inoue(see below). 207a56a8ad1SYoshinobu InoueThe 208a56a8ad1SYoshinobu Inoue.Fa af 209a56a8ad1SYoshinobu Inoueargument extension is implemented for functions 210265fb60dSYoshinobu Inouethat have no binary address argument. 211a56a8ad1SYoshinobu InoueInstead, the 212a56a8ad1SYoshinobu Inoue.Fa af 213a56a8ad1SYoshinobu Inoueargument specifies which address family is desired. 214a56a8ad1SYoshinobu Inoue.Pp 215a56a8ad1SYoshinobu InoueThe 216a56a8ad1SYoshinobu Inoue.Dq Li _sa 217265fb60dSYoshinobu Inouesuffix means that the function has general socket address and 218265fb60dSYoshinobu Inouelength arguments. 219a56a8ad1SYoshinobu InoueAs the socket address is a protocol independent data structure, 220a56a8ad1SYoshinobu InoueIPv4 and IPv6 socket address can be passed as desired. 221265fb60dSYoshinobu InoueThe 222a56a8ad1SYoshinobu Inoue.Fa sa 223a56a8ad1SYoshinobu Inoueargument extension is implemented for functions 224265fb60dSYoshinobu Inouethat pass a protocol dependent binary address argument. 225265fb60dSYoshinobu InoueThe argument needs to be replaced with a more general address structure 226a56a8ad1SYoshinobu Inoueto support multiple address families in a general way. 227a56a8ad1SYoshinobu Inoue.Pp 228265fb60dSYoshinobu InoueThe functions with neither an 229a56a8ad1SYoshinobu Inoue.Dq Li _af 230265fb60dSYoshinobu Inouesuffix nor an 231a56a8ad1SYoshinobu Inoue.Dq Li _sa 232a56a8ad1SYoshinobu Inouesuffix work for IPv4 only, except for 233a56a8ad1SYoshinobu Inoue.Fn ruserok 234a56a8ad1SYoshinobu Inouewhich can handle both IPv6 and IPv4. 235265fb60dSYoshinobu InoueTo switch the address family, the 23642b4f28eSYoshinobu Inoue.Fa af 23742b4f28eSYoshinobu Inoueargument must be filled with 2380cac72f4SYoshinobu Inoue.Dv AF_INET , 23942b4f28eSYoshinobu Inoueor 24042b4f28eSYoshinobu Inoue.Dv AF_INET6 . 2410cac72f4SYoshinobu InoueFor 2420cac72f4SYoshinobu Inoue.Fn rcmd_af , 2430cac72f4SYoshinobu Inoue.Dv PF_UNSPEC 2440cac72f4SYoshinobu Inoueis also allowed. 24558f0484fSRodney W. Grimes.Sh DIAGNOSTICS 24658f0484fSRodney W. GrimesThe 24758f0484fSRodney W. Grimes.Fn rcmd 24858f0484fSRodney W. Grimesfunction 24958f0484fSRodney W. Grimesreturns a valid socket descriptor on success. 250a56a8ad1SYoshinobu InoueIt returns -1 on error and prints a diagnostic message 251a56a8ad1SYoshinobu Inoueon the standard error. 25258f0484fSRodney W. Grimes.Pp 25358f0484fSRodney W. GrimesThe 25458f0484fSRodney W. Grimes.Fn rresvport 25558f0484fSRodney W. Grimesfunction 25658f0484fSRodney W. Grimesreturns a valid, bound socket descriptor on success. 257a56a8ad1SYoshinobu InoueIt returns -1 on error with the global value 25858f0484fSRodney W. Grimes.Va errno 25958f0484fSRodney W. Grimesset according to the reason for failure. 26058f0484fSRodney W. GrimesThe error code 261c23155a4SRuslan Ermilov.Er EAGAIN 26258f0484fSRodney W. Grimesis overloaded to mean ``All network ports in use.'' 26358f0484fSRodney W. Grimes.Sh SEE ALSO 26458f0484fSRodney W. Grimes.Xr rlogin 1 , 26558f0484fSRodney W. Grimes.Xr rsh 1 , 26658f0484fSRodney W. Grimes.Xr intro 2 , 26758f0484fSRodney W. Grimes.Xr rexec 3 , 26858f0484fSRodney W. Grimes.Xr rexecd 8 , 26958f0484fSRodney W. Grimes.Xr rlogind 8 , 27058f0484fSRodney W. Grimes.Xr rshd 8 27142b4f28eSYoshinobu Inoue.Pp 272a56a8ad1SYoshinobu Inoue.Rs 2730f5fcaa3SSheldon Hearn.%A W. Stevens 2740f5fcaa3SSheldon Hearn.%A M. Thomas 275265fb60dSYoshinobu Inoue.%T "Advanced Socket API for IPv6" 276265fb60dSYoshinobu Inoue.%O RFC2292 277a56a8ad1SYoshinobu Inoue.Re 278a56a8ad1SYoshinobu Inoue.Rs 2790f5fcaa3SSheldon Hearn.%A W. Stevens 2800f5fcaa3SSheldon Hearn.%A M. Thomas 2810f5fcaa3SSheldon Hearn.%A E. Nordmark 282265fb60dSYoshinobu Inoue.%T "Advanced Socket API for IPv6" 283265fb60dSYoshinobu Inoue.%O draft-ietf-ipngwg-rfc2292bis-01.txt 284a56a8ad1SYoshinobu Inoue.Re 28558f0484fSRodney W. Grimes.Sh HISTORY 286265fb60dSYoshinobu InoueMost of these 28758f0484fSRodney W. Grimesfunctions appeared in 28858f0484fSRodney W. Grimes.Bx 4.2 . 28942b4f28eSYoshinobu Inoue.Fn rresvport_af 290a56a8ad1SYoshinobu Inoueappeared in RFC2292, and was implemented by the WIDE project 291a56a8ad1SYoshinobu Inouefor the Hydrangea IPv6 protocol stack kit. 2920cac72f4SYoshinobu Inoue.Fn rcmd_af 2930cac72f4SYoshinobu Inoueappeared in draft-ietf-ipngwg-rfc2292bis-01.txt, 294a56a8ad1SYoshinobu Inoueand was implemented in the WIDE/KAME IPv6 protocol stack kit. 295a56a8ad1SYoshinobu Inoue.Fn iruserok_sa 296a56a8ad1SYoshinobu Inoueappeared in discussion on the IETF ipngwg mailing list, 297a56a8ad1SYoshinobu Inoueand was implemented in 298a56a8ad1SYoshinobu Inoue.Fx 4.0 . 299