Start development on 386BSD 0.0
[unix-history] / .ref-BSD-4_3_Net_2 / usr / src / lib / libc / net / rcmd.3
CommitLineData
af359dea 1.\" Copyright (c) 1983, 1991 The Regents of the University of California.
d20a1e6f 2.\" All rights reserved.
11a95b5f 3.\"
af359dea
C
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.
d20a1e6f 19.\"
af359dea
C
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.
11a95b5f 31.\"
af359dea
C
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
11a95b5f
KM
55a remote machine using an authentication scheme based
56on reserved port numbers.
af359dea
C
57The
58.Fn rresvport
59function
60returns a descriptor to a socket
11a95b5f 61with an address in the privileged port space.
af359dea
C
62The
63.Fn ruserok
64function
65is used by servers
11a95b5f 66to authenticate clients requesting service with
af359dea 67.Fn rcmd .
11a95b5f
KM
68All three functions are present in the same file and are used
69by the
af359dea 70.Xr rshd 8
11a95b5f 71server (among others).
af359dea
C
72.Pp
73The
74.Fn rcmd
75function
11a95b5f 76looks up the host
af359dea 77.Fa *ahost
11a95b5f 78using
af359dea 79.Xr gethostbyname 3 ,
11a95b5f
KM
80returning \-1 if the host does not exist.
81Otherwise
af359dea 82.Fa *ahost
11a95b5f
KM
83is set to the standard name of the host
84and a connection is established to a server
85residing at the well-known Internet port
af359dea
C
86.Fa inport .
87.Pp
7faf4e1f 88If the connection succeeds,
af359dea
C
89a socket in the Internet domain of type
90.Dv SOCK_STREAM
11a95b5f
KM
91is returned to the caller, and given to the remote
92command as
af359dea 93.Em stdin
11a95b5f 94and
af359dea 95.Em stdout .
11a95b5f 96If
af359dea 97.Fa fd2p
11a95b5f
KM
98is non-zero, then an auxiliary channel to a control
99process will be set up, and a descriptor for it will be placed
100in
af359dea 101.Fa *fd2p .
11a95b5f
KM
102The control process will return diagnostic
103output from the command (unit 2) on this channel, and will also
af359dea
C
104accept bytes on this channel as being
105.Tn UNIX
106signal numbers, to be
11a95b5f
KM
107forwarded to the process group of the command.
108If
af359dea 109.Fa fd2p
11a95b5f 110is 0, then the
af359dea 111.Em stderr
11a95b5f
KM
112(unit 2 of the remote
113command) will be made the same as the
af359dea 114.Em stdout
11a95b5f
KM
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.
af359dea 118.Pp
11a95b5f 119The protocol is described in detail in
af359dea
C
120.Xr rshd 8 .
121.Pp
11a95b5f 122The
af359dea
C
123.Fn rresvport
124function is used to obtain a socket with a privileged
11a95b5f
KM
125address bound to it. This socket is suitable for use
126by
af359dea
C
127.Fn rcmd
128and several other functions. Privileged Internet ports are those
7faf4e1f 129in the range 0 to 1023. Only the super-user
11a95b5f 130is allowed to bind an address of this sort to a socket.
af359dea
C
131.Pp
132The
133.Fn ruserok
134argument
d20a1e6f 135takes a remote host's name, as returned by the
af359dea 136.Xr gethostbyaddr 3
7faf4e1f 137routine, two user names and a flag indicating whether
d20a1e6f
KB
138the local user's name is that of the super-user. Then,
139if the user is
af359dea 140.Em NOT
d20a1e6f 141the super-user, it checks the files
af359dea 142.Pa /etc/hosts.equiv .
d20a1e6f 143If that lookup is not done, or is unsuccessful, the
af359dea 144.Pa .rhosts
d20a1e6f
KB
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
af359dea
C
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
d20a1e6f 156returns \-1.
af359dea
C
157If the local domain (as obtained from
158.Xr gethostname 2 )
0609943c 159is the same as the remote domain, only the machine name need be specified.
af359dea
C
160.Sh DIAGNOSTICS
161The
162.Fn rcmd
163function
7faf4e1f 164returns a valid socket descriptor on success.
af359dea
C
165It returns \-1 on error and prints a diagnostic message on the standard error.
166.Pp
167The
168.Fn rresvport
169function
7faf4e1f 170returns a valid, bound socket descriptor on success.
af359dea
C
171It returns \-1 on error with the global value
172.Va errno
7faf4e1f 173set according to the reason for failure.
af359dea
C
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 .