xref: /openbsd-src/lib/libc/net/rcmd.3 (revision 36bf49e74679c453fed2dad43d3abb15e64e4b1c)
1*36bf49e7Smillert.\"	$OpenBSD: rcmd.3,v 1.34 2016/05/28 15:48:30 millert Exp $
2df930be7Sderaadt.\"
3df930be7Sderaadt.\" Copyright (c) 1983, 1991, 1993
4df930be7Sderaadt.\"	The Regents of the University of California.  All rights reserved.
5df930be7Sderaadt.\"
6df930be7Sderaadt.\" Redistribution and use in source and binary forms, with or without
7df930be7Sderaadt.\" modification, are permitted provided that the following conditions
8df930be7Sderaadt.\" are met:
9df930be7Sderaadt.\" 1. Redistributions of source code must retain the above copyright
10df930be7Sderaadt.\"    notice, this list of conditions and the following disclaimer.
11df930be7Sderaadt.\" 2. Redistributions in binary form must reproduce the above copyright
12df930be7Sderaadt.\"    notice, this list of conditions and the following disclaimer in the
13df930be7Sderaadt.\"    documentation and/or other materials provided with the distribution.
146580fee3Smillert.\" 3. Neither the name of the University nor the names of its contributors
15df930be7Sderaadt.\"    may be used to endorse or promote products derived from this software
16df930be7Sderaadt.\"    without specific prior written permission.
17df930be7Sderaadt.\"
18df930be7Sderaadt.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19df930be7Sderaadt.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20df930be7Sderaadt.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21df930be7Sderaadt.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22df930be7Sderaadt.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23df930be7Sderaadt.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24df930be7Sderaadt.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25df930be7Sderaadt.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26df930be7Sderaadt.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27df930be7Sderaadt.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28df930be7Sderaadt.\" SUCH DAMAGE.
29df930be7Sderaadt.\"
30*36bf49e7Smillert.Dd $Mdocdate: May 28 2016 $
31df930be7Sderaadt.Dt RCMD 3
32fc8533a3Saaron.Os
33df930be7Sderaadt.Sh NAME
34df930be7Sderaadt.Nm rcmd ,
3516582178Sitojun.Nm rcmd_af ,
36df930be7Sderaadt.Nm rresvport ,
37dd389515Sderaadt.Nm rresvport_af ,
38df1557ebSguenther.Nm ruserok
39df930be7Sderaadt.Nd routines for returning a stream to a remote command
40df930be7Sderaadt.Sh SYNOPSIS
4164d4e987Stedu.In unistd.h
42df930be7Sderaadt.Ft int
43df930be7Sderaadt.Fn rcmd "char **ahost" "int inport" "const char *locuser" "const char *remuser" "const char *cmd" "int *fd2p"
44df930be7Sderaadt.Ft int
4516582178Sitojun.Fn rcmd_af "char **ahost" "int inport" "const char *locuser" "const char *remuser" "const char *cmd" "int *fd2p" "int af"
4616582178Sitojun.Ft int
47df930be7Sderaadt.Fn rresvport "int *port"
48df930be7Sderaadt.Ft int
4901cdefb0Sderaadt.Fn rresvport_af "int *port" "int af"
5001cdefb0Sderaadt.Ft int
51df930be7Sderaadt.Fn ruserok "const char *rhost" "int superuser" "const char *ruser" "const char *luser"
52df930be7Sderaadt.Sh DESCRIPTION
53df930be7SderaadtThe
54df930be7Sderaadt.Fn rcmd
5550772e64Saaronfunction is used by the superuser to execute a command on a remote
569c852636Smillertmachine using an authentication scheme based on reserved
5710cc2884Saaronport numbers.
5810cc2884SaaronIf the calling process is not setuid, the
593a03493dSaaron.Ev RSH
603a03493dSaaronenvironment variable is set, and
619c852636Smillert.Fa inport
629c852636Smillertis
633a03493dSaaron.Dq shell/tcp ,
640f664cb5Smillert.Xr rcmdsh 3
650f664cb5Smillertis called instead with the value of
663a03493dSaaron.Ev RSH .
67a3542fadSaaronAlternately, if the user is not the superuser,
6859afcb35Smillert.Fn rcmd
6959afcb35Smillertwill invoke
7059afcb35Smillert.Xr rcmdsh 3
7159afcb35Smillertto run the command via
72ced0a636Stedu.Xr ssh 1 .
7316582178SitojunWhile
7416582178Sitojun.Fn rcmd
7516582178Sitojuncan handle IPv4 cases only,
7616582178Sitojunthe
7716582178Sitojun.Fn rcmd_af
7816582178Sitojunfunction can handle other cases as well.
79e479143dSaaron.Pp
80df930be7SderaadtThe
81df930be7Sderaadt.Fn rresvport
8201cdefb0Sderaadtand
8301cdefb0Sderaadt.Fn rresvport_af
8450772e64Saaronfunctions return a descriptor to a socket
85df930be7Sderaadtwith an address in the privileged port space.
86df930be7SderaadtThe
87df930be7Sderaadt.Fn ruserok
88df1557ebSguentherfunction is used by servers
89df930be7Sderaadtto authenticate clients requesting service with
90df930be7Sderaadt.Fn rcmd .
91df930be7Sderaadt.Pp
92df930be7SderaadtThe
93df930be7Sderaadt.Fn rcmd
9450772e64Saaronfunction looks up the host
95df930be7Sderaadt.Fa *ahost
96df930be7Sderaadtusing
97*36bf49e7Smillert.Xr getaddrinfo 3
98934fc14bShalexand, if the host exists,
99df930be7Sderaadt.Fa *ahost
100*36bf49e7Smillertis set to the canonical name of the host.
101934fc14bShalexA connection is then established to a server
102df930be7Sderaadtresiding at the well-known Internet port
103df930be7Sderaadt.Fa inport .
104a3542fadSaaronIf the user is not the superuser, the only valid port is
1053a03493dSaaron.Dq shell/tcp
10659afcb35Smillert(usually port 514).
107df930be7Sderaadt.Pp
108df930be7SderaadtIf the connection succeeds,
109df930be7Sderaadta socket in the Internet domain of type
110df930be7Sderaadt.Dv SOCK_STREAM
111df930be7Sderaadtis returned to the caller, and given to the remote
1123a03493dSaaroncommand as stdin and stdout.
113df930be7SderaadtIf
114df930be7Sderaadt.Fa fd2p
115df930be7Sderaadtis non-zero, then an auxiliary channel to a control
116df930be7Sderaadtprocess will be set up, and a descriptor for it will be placed
117df930be7Sderaadtin
118df930be7Sderaadt.Fa *fd2p .
119df930be7SderaadtThe control process will return diagnostic
120df930be7Sderaadtoutput from the command (unit 2) on this channel, and will also
121df930be7Sderaadtaccept bytes on this channel as being
122df930be7Sderaadt.Tn UNIX
123df930be7Sderaadtsignal numbers, to be
124df930be7Sderaadtforwarded to the process group of the command.
125df930be7SderaadtIf
126df930be7Sderaadt.Fa fd2p
127c5d1ced9Sderaadtis
128c5d1ced9Sderaadt.Va NULL ,
129c5d1ced9Sderaadtthen the standard error (unit 2 of the remote command) will be made
130c5d1ced9Sderaadtthe same as the standard output and no provision is made for sending
131c5d1ced9Sderaadtarbitrary signals to the remote process, although you may be able to
132c5d1ced9Sderaadtget its attention by using out-of-band data.
133a3542fadSaaronNote that if the user is not the superuser,
13459afcb35Smillert.Fa fd2p
135c5d1ced9Sderaadtmust be
136c5d1ced9Sderaadt.Va NULL .
137df930be7Sderaadt.Pp
13816582178Sitojun.Fn rcmd_af
13916582178Sitojuntakes address family in the last argument.
14016582178SitojunIf the last argument is
141df1557ebSguenther.Dv AF_UNSPEC ,
14216582178Sitojuninterpretation of
14316582178Sitojun.Fa *ahost
14416582178Sitojunwill obey the underlying address resolution like DNS.
14516582178Sitojun.Pp
146df930be7SderaadtThe
147df930be7Sderaadt.Fn rresvport
14801cdefb0Sderaadtand
14901cdefb0Sderaadt.Fn rresvport_af
15001cdefb0Sderaadtfunctions are used to obtain a socket with a privileged
15110cc2884Saaronaddress bound to it.
15210cc2884SaaronThis socket is suitable for use by
153df930be7Sderaadt.Fn rcmd
15410cc2884Saaronand several other functions.
15592a72e13SderaadtPrivileged Internet ports are those in the range 0 to
15692a72e13Sderaadt.Va IPPORT_RESERVED - 1 ,
15792a72e13Sderaadtwhich happens to be 1023.
15810cc2884SaaronOnly the superuser is allowed to bind an address of this sort to a socket.
15916ef94eeSderaadt.Fn rresvport
16001cdefb0Sderaadtand
16101cdefb0Sderaadt.Fn rresvport_af
16201cdefb0Sderaadtneed to be seeded with a port number; if that port
16301cdefb0Sderaadtis not available these functions will find another.
164df930be7Sderaadt.Pp
165df930be7SderaadtThe
166df930be7Sderaadt.Fn ruserok
167df1557ebSguentherfunction takes a remote host's name, two user names,
168df1557ebSguentherand a flag indicating whether the local user's
169a3542fadSaaronname is that of the superuser.
170df930be7SderaadtThen, if the user is
1713a03493dSaaron.Em not
172a3542fadSaaronthe superuser, it checks the
173df930be7Sderaadt.Pa /etc/hosts.equiv
174df930be7Sderaadtfile.
175df930be7SderaadtIf that lookup is not done, or is unsuccessful, the
176df930be7Sderaadt.Pa .rhosts
177df930be7Sderaadtin the local user's home directory is checked to see if the request for
178df930be7Sderaadtservice is allowed.
179df930be7Sderaadt.Pp
180df930be7SderaadtIf this file does not exist, is not a regular file, is owned by anyone
181a3542fadSaaronother than the user or the superuser, or is writeable by anyone other
182df930be7Sderaadtthan the owner, the check automatically fails.
183df930be7SderaadtZero is returned if the machine name is listed in the
1843a03493dSaaron.Pa hosts.equiv
185df930be7Sderaadtfile, or the host and remote user name are found in the
1863a03493dSaaron.Pa .rhosts
187df930be7Sderaadtfile; otherwise
188df930be7Sderaadt.Fn ruserok
189df1557ebSguentherreturns \-1.
190df930be7SderaadtIf the local domain (as obtained from
191*36bf49e7Smillert.Xr getaddrinfo 3 )
192df930be7Sderaadtis the same as the remote domain, only the machine name need be specified.
193df930be7Sderaadt.Pp
19416582178Sitojun.Fn ruserok
195df1557ebSguentherimplicitly requires trusting the DNS server for the remote host's domain.
196df930be7Sderaadt.Sh DIAGNOSTICS
197df930be7SderaadtThe
198df930be7Sderaadt.Fn rcmd
19950772e64Saaronfunction returns a valid socket descriptor on success.
200df930be7SderaadtIt returns \-1 on error and prints a diagnostic message on the standard error.
201df930be7Sderaadt.Pp
202df930be7SderaadtThe
203df930be7Sderaadt.Fn rresvport
20401cdefb0Sderaadtand
20501cdefb0Sderaadt.Fn rresvport_af
20650772e64Saaronfunctions return a valid, bound socket descriptor on success.
207df930be7SderaadtIt returns \-1 on error with the global value
208df930be7Sderaadt.Va errno
209df930be7Sderaadtset according to the reason for failure.
210df930be7SderaadtThe error code
2113a03493dSaaron.Er EAGAIN
2123a03493dSaaronis overloaded to mean
2133a03493dSaaron.Dq all network ports in use .
214df930be7Sderaadt.Sh SEE ALSO
215ced0a636Stedu.Xr ssh 1 ,
216df930be7Sderaadt.Xr intro 2 ,
217350bb3b8Salex.Xr bindresvport 3 ,
2187be0ef42Sderaadt.Xr bindresvport_sa 3 ,
219fd49663cSjmc.Xr rcmdsh 3
220df930be7Sderaadt.Sh HISTORY
221df930be7SderaadtThese
222df930be7Sderaadtfunctions appeared in
223df930be7Sderaadt.Bx 4.2 .
224df1557ebSguenther.Pp
225df1557ebSguentherThe
226df1557ebSguenther.Fn iruserok
227df1557ebSguentherand
228df1557ebSguenther.Fn iruserok_sa
229df1557ebSguentherfunctions, IP address based versions of
230df1557ebSguenther.Fn ruserok ,
231df1557ebSguentherwere removed in
232df1557ebSguenther.Ox 6.0 .
233