1*48352Scael.\" Copyright (c) 1983, 1991 The Regents of the University of California. 236313Sbostic.\" All rights reserved. 320580Smckusick.\" 443572Strent.\" %sccs.include.redist.man% 520580Smckusick.\" 6*48352Scael.\" @(#)rcmd.3 6.11 (Berkeley) 04/19/91 736313Sbostic.\" 8*48352Scael.Dd 9*48352Scael.Dt RCMD 3 10*48352Scael.Os BSD 4.2 11*48352Scael.Sh NAME 12*48352Scael.Nm rcmd , 13*48352Scael.Nm rresvport , 14*48352Scael.Nm ruserok 15*48352Scael.Nd routines for returning a stream to a remote command 16*48352Scael.Sh SYNOPSIS 17*48352Scael.Fd #include <unistd.h> 18*48352Scael.Ft int 19*48352Scael.Fn rcmd "char **ahost" "int inport" "const char *locuser" "const char *remuser" "const char *cmd" "int *fd2p" 20*48352Scael.Ft int 21*48352Scael.Fn rresvport "int *port" 22*48352Scael.Ft int 23*48352Scael.Fn ruserok "const char *rhost" "int superuser" "const char *ruser" "const char *luser" 24*48352Scael.Sh DESCRIPTION 25*48352ScaelThe 26*48352Scael.Fn rcmd 27*48352Scaelfunction 28*48352Scaelis used by the super-user to execute a command on 2920580Smckusicka remote machine using an authentication scheme based 3020580Smckusickon reserved port numbers. 31*48352ScaelThe 32*48352Scael.Fn rresvport 33*48352Scaelfunction 34*48352Scaelreturns a descriptor to a socket 3520580Smckusickwith an address in the privileged port space. 36*48352ScaelThe 37*48352Scael.Fn ruserok 38*48352Scaelfunction 39*48352Scaelis used by servers 4020580Smckusickto authenticate clients requesting service with 41*48352Scael.Fn rcmd . 4220580SmckusickAll three functions are present in the same file and are used 4320580Smckusickby the 44*48352Scael.Xr rshd 8 4520580Smckusickserver (among others). 46*48352Scael.Pp 47*48352ScaelThe 48*48352Scael.Fn rcmd 49*48352Scaelfunction 5020580Smckusicklooks up the host 51*48352Scael.Fa *ahost 5220580Smckusickusing 53*48352Scael.Xr gethostbyname 3 , 5420580Smckusickreturning \-1 if the host does not exist. 5520580SmckusickOtherwise 56*48352Scael.Fa *ahost 5720580Smckusickis set to the standard name of the host 5820580Smckusickand a connection is established to a server 5920580Smckusickresiding at the well-known Internet port 60*48352Scael.Fa inport . 61*48352Scael.Pp 6228174SkarelsIf the connection succeeds, 63*48352Scaela socket in the Internet domain of type 64*48352Scael.Dv SOCK_STREAM 6520580Smckusickis returned to the caller, and given to the remote 6620580Smckusickcommand as 67*48352Scael.Em stdin 6820580Smckusickand 69*48352Scael.Em stdout . 7020580SmckusickIf 71*48352Scael.Fa fd2p 7220580Smckusickis non-zero, then an auxiliary channel to a control 7320580Smckusickprocess will be set up, and a descriptor for it will be placed 7420580Smckusickin 75*48352Scael.Fa *fd2p . 7620580SmckusickThe control process will return diagnostic 7720580Smckusickoutput from the command (unit 2) on this channel, and will also 78*48352Scaelaccept bytes on this channel as being 79*48352Scael.Tn UNIX 80*48352Scaelsignal numbers, to be 8120580Smckusickforwarded to the process group of the command. 8220580SmckusickIf 83*48352Scael.Fa fd2p 8420580Smckusickis 0, then the 85*48352Scael.Em stderr 8620580Smckusick(unit 2 of the remote 8720580Smckusickcommand) will be made the same as the 88*48352Scael.Em stdout 8920580Smckusickand no 9020580Smckusickprovision is made for sending arbitrary signals to the remote process, 9120580Smckusickalthough you may be able to get its attention by using out-of-band data. 92*48352Scael.Pp 9320580SmckusickThe protocol is described in detail in 94*48352Scael.Xr rshd 8 . 95*48352Scael.Pp 9620580SmckusickThe 97*48352Scael.Fn rresvport 98*48352Scaelfunction is used to obtain a socket with a privileged 9920580Smckusickaddress bound to it. This socket is suitable for use 10020580Smckusickby 101*48352Scael.Fn rcmd 102*48352Scaeland several other functions. Privileged Internet ports are those 10328174Skarelsin the range 0 to 1023. Only the super-user 10420580Smckusickis allowed to bind an address of this sort to a socket. 105*48352Scael.Pp 106*48352ScaelThe 107*48352Scael.Fn ruserok 108*48352Scaelargument 10936313Sbostictakes a remote host's name, as returned by the 110*48352Scael.Xr gethostbyaddr 3 11128174Skarelsroutine, two user names and a flag indicating whether 11236313Sbosticthe local user's name is that of the super-user. Then, 11336313Sbosticif the user is 114*48352Scael.Em NOT 11536313Sbosticthe super-user, it checks the files 116*48352Scael.Pa /etc/hosts.equiv . 11736313SbosticIf that lookup is not done, or is unsuccessful, the 118*48352Scael.Pa .rhosts 11936313Sbosticin the local user's home directory is checked to see if the request for 12036313Sbosticservice is allowed. If this file is owned by anyone other than the 12136313Sbosticuser or the super-user, or if it is writeable by anyone other than the 12236313Sbosticowner, the check automatically fails. A 0 is returned if the machine 123*48352Scaelname is listed in the 124*48352Scael.Dq Pa hosts.equiv 125*48352Scaelfile, or the host and remote 126*48352Scaeluser name are found in the 127*48352Scael.Dq Pa .rhosts 128*48352Scaelfile; otherwise 129*48352Scael.Fn ruserok 13036313Sbosticreturns \-1. 131*48352ScaelIf the local domain (as obtained from 132*48352Scael.Xr gethostname 2 ) 13328021Skarelsis the same as the remote domain, only the machine name need be specified. 134*48352Scael.Sh DIAGNOSTICS 135*48352ScaelThe 136*48352Scael.Fn rcmd 137*48352Scaelfunction 13828174Skarelsreturns a valid socket descriptor on success. 139*48352ScaelIt returns \-1 on error and prints a diagnostic message on the standard error. 140*48352Scael.Pp 141*48352ScaelThe 142*48352Scael.Fn rresvport 143*48352Scaelfunction 14428174Skarelsreturns a valid, bound socket descriptor on success. 145*48352ScaelIt returns \-1 on error with the global value 146*48352Scael.Va errno 14728174Skarelsset according to the reason for failure. 148*48352ScaelThe error code 149*48352Scael.Dv EAGAIN 150*48352Scaelis overloaded to mean ``All network ports in use.'' 151*48352Scael.Sh SEE ALSO 152*48352Scael.Xr rlogin 1 , 153*48352Scael.Xr rsh 1 , 154*48352Scael.Xr intro 2 , 155*48352Scael.Xr rexec 3 , 156*48352Scael.Xr rexecd 8 , 157*48352Scael.Xr rlogind 8 , 158*48352Scael.Xr rshd 8 159*48352Scael.Sh HISTORY 160*48352ScaelThese 161*48352Scaelfunctions appeared in 162*48352Scael.Bx 4.2 . 163