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.\" @(#)rcmd.3 6.11 (Berkeley) 4/19/91 33.\" 34.Dd April 19, 1991 35.Dt RCMD 3 36.Os BSD 4.2 37.Sh NAME 38.Nm rcmd , 39.Nm rresvport , 40.Nm ruserok 41.Nd routines for returning a stream to a remote command 42.Sh SYNOPSIS 43.Fd #include <unistd.h> 44.Ft int 45.Fn rcmd "char **ahost" "int inport" "const char *locuser" "const char *remuser" "const char *cmd" "int *fd2p" 46.Ft int 47.Fn rresvport "int *port" 48.Ft int 49.Fn ruserok "const char *rhost" "int superuser" "const char *ruser" "const char *luser" 50.Sh DESCRIPTION 51The 52.Fn rcmd 53function 54is used by the super-user to execute a command on 55a remote machine using an authentication scheme based 56on reserved port numbers. 57The 58.Fn rresvport 59function 60returns a descriptor to a socket 61with an address in the privileged port space. 62The 63.Fn ruserok 64function 65is used by servers 66to authenticate clients requesting service with 67.Fn rcmd . 68All three functions are present in the same file and are used 69by the 70.Xr rshd 8 71server (among others). 72.Pp 73The 74.Fn rcmd 75function 76looks up the host 77.Fa *ahost 78using 79.Xr gethostbyname 3 , 80returning \-1 if the host does not exist. 81Otherwise 82.Fa *ahost 83is set to the standard name of the host 84and a connection is established to a server 85residing at the well-known Internet port 86.Fa inport . 87.Pp 88If the connection succeeds, 89a socket in the Internet domain of type 90.Dv SOCK_STREAM 91is returned to the caller, and given to the remote 92command as 93.Em stdin 94and 95.Em stdout . 96If 97.Fa fd2p 98is non-zero, then an auxiliary channel to a control 99process will be set up, and a descriptor for it will be placed 100in 101.Fa *fd2p . 102The control process will return diagnostic 103output from the command (unit 2) on this channel, and will also 104accept bytes on this channel as being 105.Tn UNIX 106signal numbers, to be 107forwarded to the process group of the command. 108If 109.Fa fd2p 110is 0, then the 111.Em stderr 112(unit 2 of the remote 113command) will be made the same as the 114.Em stdout 115and no 116provision is made for sending arbitrary signals to the remote process, 117although you may be able to get its attention by using out-of-band data. 118.Pp 119The protocol is described in detail in 120.Xr rshd 8 . 121.Pp 122The 123.Fn rresvport 124function is used to obtain a socket with a privileged 125address bound to it. This socket is suitable for use 126by 127.Fn rcmd 128and several other functions. Privileged Internet ports are those 129in the range 0 to 1023. Only the super-user 130is allowed to bind an address of this sort to a socket. 131.Pp 132The 133.Fn ruserok 134argument 135takes a remote host's name, as returned by the 136.Xr gethostbyaddr 3 137routine, two user names and a flag indicating whether 138the local user's name is that of the super-user. Then, 139if the user is 140.Em NOT 141the super-user, it checks the files 142.Pa /etc/hosts.equiv . 143If that lookup is not done, or is unsuccessful, the 144.Pa .rhosts 145in the local user's home directory is checked to see if the request for 146service is allowed. If this file is owned by anyone other than the 147user or the super-user, or if it is writeable by anyone other than the 148owner, the check automatically fails. A 0 is returned if the machine 149name is listed in the 150.Dq Pa hosts.equiv 151file, or the host and remote 152user name are found in the 153.Dq Pa .rhosts 154file; otherwise 155.Fn ruserok 156returns \-1. 157If the local domain (as obtained from 158.Xr gethostname 2 ) 159is the same as the remote domain, only the machine name need be specified. 160.Sh DIAGNOSTICS 161The 162.Fn rcmd 163function 164returns a valid socket descriptor on success. 165It returns \-1 on error and prints a diagnostic message on the standard error. 166.Pp 167The 168.Fn rresvport 169function 170returns a valid, bound socket descriptor on success. 171It returns \-1 on error with the global value 172.Va errno 173set according to the reason for failure. 174The error code 175.Dv EAGAIN 176is overloaded to mean ``All network ports in use.'' 177.Sh SEE ALSO 178.Xr rlogin 1 , 179.Xr rsh 1 , 180.Xr intro 2 , 181.Xr rexec 3 , 182.Xr rexecd 8 , 183.Xr rlogind 8 , 184.Xr rshd 8 185.Sh HISTORY 186These 187functions appeared in 188.Bx 4.2 . 189