1.\" Copyright (c) 1983, 1991 The Regents of the University of California. 2.\" All rights reserved. 3.\" 4.\" Redistribution and use in source and binary forms, with or without 5.\" modification, are permitted provided that the following conditions 6.\" are met: 7.\" 1. Redistributions of source code must retain the above copyright 8.\" notice, this list of conditions and the following disclaimer. 9.\" 2. Redistributions in binary form must reproduce the above copyright 10.\" notice, this list of conditions and the following disclaimer in the 11.\" documentation and/or other materials provided with the distribution. 12.\" 3. All advertising materials mentioning features or use of this software 13.\" must display the following acknowledgement: 14.\" This product includes software developed by the University of 15.\" California, Berkeley and its contributors. 16.\" 4. Neither the name of the University nor the names of its contributors 17.\" may be used to endorse or promote products derived from this software 18.\" without specific prior written permission. 19.\" 20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30.\" SUCH DAMAGE. 31.\" 32.\" from: @(#)rcmd.3 6.11 (Berkeley) 4/19/91 33.\" $Id: rcmd.3,v 1.2 1993/08/01 07:45:16 mycroft Exp $ 34.\" 35.Dd April 19, 1991 36.Dt RCMD 3 37.Os BSD 4.2 38.Sh NAME 39.Nm rcmd , 40.Nm rresvport , 41.Nm ruserok 42.Nd routines for returning a stream to a remote command 43.Sh SYNOPSIS 44.Fd #include <unistd.h> 45.Ft int 46.Fn rcmd "char **ahost" "int inport" "const char *locuser" "const char *remuser" "const char *cmd" "int *fd2p" 47.Ft int 48.Fn rresvport "int *port" 49.Ft int 50.Fn ruserok "const char *rhost" "int superuser" "const char *ruser" "const char *luser" 51.Sh DESCRIPTION 52The 53.Fn rcmd 54function 55is used by the super-user to execute a command on 56a remote machine using an authentication scheme based 57on reserved port numbers. 58The 59.Fn rresvport 60function 61returns a descriptor to a socket 62with an address in the privileged port space. 63The 64.Fn ruserok 65function 66is used by servers 67to authenticate clients requesting service with 68.Fn rcmd . 69All three functions are present in the same file and are used 70by the 71.Xr rshd 8 72server (among others). 73.Pp 74The 75.Fn rcmd 76function 77looks up the host 78.Fa *ahost 79using 80.Xr gethostbyname 3 , 81returning \-1 if the host does not exist. 82Otherwise 83.Fa *ahost 84is set to the standard name of the host 85and a connection is established to a server 86residing at the well-known Internet port 87.Fa inport . 88.Pp 89If the connection succeeds, 90a socket in the Internet domain of type 91.Dv SOCK_STREAM 92is returned to the caller, and given to the remote 93command as 94.Em stdin 95and 96.Em stdout . 97If 98.Fa fd2p 99is non-zero, then an auxiliary channel to a control 100process will be set up, and a descriptor for it will be placed 101in 102.Fa *fd2p . 103The control process will return diagnostic 104output from the command (unit 2) on this channel, and will also 105accept bytes on this channel as being 106.Tn UNIX 107signal numbers, to be 108forwarded to the process group of the command. 109If 110.Fa fd2p 111is 0, then the 112.Em stderr 113(unit 2 of the remote 114command) will be made the same as the 115.Em stdout 116and no 117provision is made for sending arbitrary signals to the remote process, 118although you may be able to get its attention by using out-of-band data. 119.Pp 120The protocol is described in detail in 121.Xr rshd 8 . 122.Pp 123The 124.Fn rresvport 125function is used to obtain a socket with a privileged 126address bound to it. This socket is suitable for use 127by 128.Fn rcmd 129and several other functions. Privileged Internet ports are those 130in the range 0 to 1023. Only the super-user 131is allowed to bind an address of this sort to a socket. 132.Pp 133The 134.Fn ruserok 135argument 136takes a remote host's name, as returned by the 137.Xr gethostbyaddr 3 138routine, two user names and a flag indicating whether 139the local user's name is that of the super-user. Then, 140if the user is 141.Em NOT 142the super-user, it checks the files 143.Pa /etc/hosts.equiv . 144If that lookup is not done, or is unsuccessful, the 145.Pa .rhosts 146in the local user's home directory is checked to see if the request for 147service is allowed. If this file is owned by anyone other than the 148user or the super-user, or if it is writeable by anyone other than the 149owner, the check automatically fails. A 0 is returned if the machine 150name is listed in the 151.Dq Pa hosts.equiv 152file, or the host and remote 153user name are found in the 154.Dq Pa .rhosts 155file; otherwise 156.Fn ruserok 157returns \-1. 158If the local domain (as obtained from 159.Xr gethostname 2 ) 160is the same as the remote domain, only the machine name need be specified. 161.Sh DIAGNOSTICS 162The 163.Fn rcmd 164function 165returns a valid socket descriptor on success. 166It returns \-1 on error and prints a diagnostic message on the standard error. 167.Pp 168The 169.Fn rresvport 170function 171returns a valid, bound socket descriptor on success. 172It returns \-1 on error with the global value 173.Va errno 174set according to the reason for failure. 175The error code 176.Dv EAGAIN 177is overloaded to mean ``All network ports in use.'' 178.Sh SEE ALSO 179.Xr rlogin 1 , 180.Xr rsh 1 , 181.Xr intro 2 , 182.Xr rexec 3 , 183.Xr rexecd 8 , 184.Xr rlogind 8 , 185.Xr rshd 8 186.Sh HISTORY 187These 188functions appeared in 189.Bx 4.2 . 190