summaryrefslogtreecommitdiff
path: root/src/lib/libc/net/rcmd.3
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libc/net/rcmd.3')
-rw-r--r--src/lib/libc/net/rcmd.3166
1 files changed, 116 insertions, 50 deletions
diff --git a/src/lib/libc/net/rcmd.3 b/src/lib/libc/net/rcmd.3
index 4db847c392..62f370efad 100644
--- a/src/lib/libc/net/rcmd.3
+++ b/src/lib/libc/net/rcmd.3
@@ -1,4 +1,4 @@
1.\" $NetBSD: rcmd.3,v 1.8 1995/02/25 06:20:52 cgd Exp $ 1.\" $OpenBSD: rcmd.3,v 1.25 2002/09/25 17:30:02 deraadt Exp $
2.\" 2.\"
3.\" Copyright (c) 1983, 1991, 1993 3.\" Copyright (c) 1983, 1991, 1993
4.\" The Regents of the University of California. All rights reserved. 4.\" The Regents of the University of California. All rights reserved.
@@ -31,38 +31,67 @@
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE. 32.\" SUCH DAMAGE.
33.\" 33.\"
34.\" @(#)rcmd.3 8.1 (Berkeley) 6/4/93
35.\"
36.Dd June 4, 1993 34.Dd June 4, 1993
37.Dt RCMD 3 35.Dt RCMD 3
38.Os BSD 4.2 36.Os
39.Sh NAME 37.Sh NAME
40.Nm rcmd , 38.Nm rcmd ,
39.Nm rcmd_af ,
41.Nm rresvport , 40.Nm rresvport ,
41.Nm rresvport_af ,
42.Nm iruserok , 42.Nm iruserok ,
43.Nm ruserok 43.Nm ruserok ,
44.Nm iruserok_sa
44.Nd routines for returning a stream to a remote command 45.Nd routines for returning a stream to a remote command
45.Sh SYNOPSIS 46.Sh SYNOPSIS
46.Fd #include <unistd.h> 47.Fd #include <unistd.h>
47.Ft int 48.Ft int
48.Fn rcmd "char **ahost" "int inport" "const char *locuser" "const char *remuser" "const char *cmd" "int *fd2p" 49.Fn rcmd "char **ahost" "int inport" "const char *locuser" "const char *remuser" "const char *cmd" "int *fd2p"
49.Ft int 50.Ft int
51.Fn rcmd_af "char **ahost" "int inport" "const char *locuser" "const char *remuser" "const char *cmd" "int *fd2p" "int af"
52.Ft int
50.Fn rresvport "int *port" 53.Fn rresvport "int *port"
51.Ft int 54.Ft int
52.Fn iruserok "u_long raddr" "int superuser" "const char *ruser" "const char *luser" 55.Fn rresvport_af "int *port" "int af"
56.Ft int
57.Fn iruserok "u_int32_t raddr" "int superuser" "const char *ruser" "const char *luser"
53.Ft int 58.Ft int
54.Fn ruserok "const char *rhost" "int superuser" "const char *ruser" "const char *luser" 59.Fn ruserok "const char *rhost" "int superuser" "const char *ruser" "const char *luser"
60.Ft int
61.Fn iruserok_sa "const void *sa" "int salen" "int superuser" "const char *ruser" "const char *luser"
55.Sh DESCRIPTION 62.Sh DESCRIPTION
56The 63The
57.Fn rcmd 64.Fn rcmd
58function 65function is used by the superuser to execute a command on a remote
59is used by the super-user to execute a command on 66machine using an authentication scheme based on reserved
60a remote machine using an authentication scheme based 67port numbers.
61on reserved port numbers. 68If the calling process is not setuid, the
69.Ev RSH
70environment variable is set, and
71.Fa inport
72is
73.Dq shell/tcp ,
74.Xr rcmdsh 3
75is called instead with the value of
76.Ev RSH .
77Alternately, if the user is not the superuser,
78.Fn rcmd
79will invoke
80.Xr rcmdsh 3
81to run the command via
82.Xr rsh 1 .
83While
84.Fn rcmd
85can handle IPv4 cases only,
86the
87.Fn rcmd_af
88function can handle other cases as well.
89.Pp
62The 90The
63.Fn rresvport 91.Fn rresvport
64function 92and
65returns a descriptor to a socket 93.Fn rresvport_af
94functions return a descriptor to a socket
66with an address in the privileged port space. 95with an address in the privileged port space.
67The 96The
68.Fn iruserok 97.Fn iruserok
@@ -75,11 +104,13 @@ All four functions are present in the same file and are used
75by the 104by the
76.Xr rshd 8 105.Xr rshd 8
77server (among others). 106server (among others).
107.Fn iruserok_sa
108is an address family independent variant of
109.Fn iruserok .
78.Pp 110.Pp
79The 111The
80.Fn rcmd 112.Fn rcmd
81function 113function looks up the host
82looks up the host
83.Fa *ahost 114.Fa *ahost
84using 115using
85.Xr gethostbyname 3 , 116.Xr gethostbyname 3 ,
@@ -90,15 +121,15 @@ is set to the standard name of the host
90and a connection is established to a server 121and a connection is established to a server
91residing at the well-known Internet port 122residing at the well-known Internet port
92.Fa inport . 123.Fa inport .
124If the user is not the superuser, the only valid port is
125.Dq shell/tcp
126(usually port 514).
93.Pp 127.Pp
94If the connection succeeds, 128If the connection succeeds,
95a socket in the Internet domain of type 129a socket in the Internet domain of type
96.Dv SOCK_STREAM 130.Dv SOCK_STREAM
97is returned to the caller, and given to the remote 131is returned to the caller, and given to the remote
98command as 132command as stdin and stdout.
99.Em stdin
100and
101.Em stdout .
102If 133If
103.Fa fd2p 134.Fa fd2p
104is non-zero, then an auxiliary channel to a control 135is non-zero, then an auxiliary channel to a control
@@ -113,27 +144,46 @@ signal numbers, to be
113forwarded to the process group of the command. 144forwarded to the process group of the command.
114If 145If
115.Fa fd2p 146.Fa fd2p
116is 0, then the 147is
117.Em stderr 148.Va NULL ,
118(unit 2 of the remote 149then the standard error (unit 2 of the remote command) will be made
119command) will be made the same as the 150the same as the standard output and no provision is made for sending
120.Em stdout 151arbitrary signals to the remote process, although you may be able to
121and no 152get its attention by using out-of-band data.
122provision is made for sending arbitrary signals to the remote process, 153Note that if the user is not the superuser,
123although you may be able to get its attention by using out-of-band data. 154.Fa fd2p
155must be
156.Va NULL .
157.Pp
158.Fn rcmd_af
159takes address family in the last argument.
160If the last argument is
161.Dv PF_UNSPEC ,
162interpretation of
163.Fa *ahost
164will obey the underlying address resolution like DNS.
124.Pp 165.Pp
125The protocol is described in detail in 166The protocol is described in detail in
126.Xr rshd 8 . 167.Xr rshd 8 .
127.Pp 168.Pp
128The 169The
129.Fn rresvport 170.Fn rresvport
130function is used to obtain a socket with a privileged 171and
131address bound to it. This socket is suitable for use 172.Fn rresvport_af
132by 173functions are used to obtain a socket with a privileged
174address bound to it.
175This socket is suitable for use by
133.Fn rcmd 176.Fn rcmd
134and several other functions. Privileged Internet ports are those 177and several other functions.
135in the range 0 to 1023. Only the super-user 178Privileged Internet ports are those in the range 0 to
136is allowed to bind an address of this sort to a socket. 179.Va IPPORT_RESERVED - 1 ,
180which happens to be 1023.
181Only the superuser is allowed to bind an address of this sort to a socket.
182.Fn rresvport
183and
184.Fn rresvport_af
185need to be seeded with a port number; if that port
186is not available these functions will find another.
137.Pp 187.Pp
138The 188The
139.Fn iruserok 189.Fn iruserok
@@ -141,10 +191,10 @@ and
141.Fn ruserok 191.Fn ruserok
142functions take a remote host's IP address or name, respectively, 192functions take a remote host's IP address or name, respectively,
143two user names and a flag indicating whether the local user's 193two user names and a flag indicating whether the local user's
144name is that of the super-user. 194name is that of the superuser.
145Then, if the user is 195Then, if the user is
146.Em NOT 196.Em not
147the super-user, it checks the 197the superuser, it checks the
148.Pa /etc/hosts.equiv 198.Pa /etc/hosts.equiv
149file. 199file.
150If that lookup is not done, or is unsuccessful, the 200If that lookup is not done, or is unsuccessful, the
@@ -153,19 +203,19 @@ in the local user's home directory is checked to see if the request for
153service is allowed. 203service is allowed.
154.Pp 204.Pp
155If this file does not exist, is not a regular file, is owned by anyone 205If this file does not exist, is not a regular file, is owned by anyone
156other than the user or the super-user, or is writeable by anyone other 206other than the user or the superuser, or is writeable by anyone other
157than the owner, the check automatically fails. 207than the owner, the check automatically fails.
158Zero is returned if the machine name is listed in the 208Zero is returned if the machine name is listed in the
159.Dq Pa hosts.equiv 209.Pa hosts.equiv
160file, or the host and remote user name are found in the 210file, or the host and remote user name are found in the
161.Dq Pa .rhosts 211.Pa .rhosts
162file; otherwise 212file; otherwise
163.Fn iruserok 213.Fn iruserok
164and 214and
165.Fn ruserok 215.Fn ruserok
166return \-1. 216return \-1.
167If the local domain (as obtained from 217If the local domain (as obtained from
168.Xr gethostname 2 ) 218.Xr gethostname 3 )
169is the same as the remote domain, only the machine name need be specified. 219is the same as the remote domain, only the machine name need be specified.
170.Pp 220.Pp
171If the IP address of the remote host is known, 221If the IP address of the remote host is known,
@@ -173,32 +223,48 @@ If the IP address of the remote host is known,
173should be used in preference to 223should be used in preference to
174.Fn ruserok , 224.Fn ruserok ,
175as it does not require trusting the DNS server for the remote host's domain. 225as it does not require trusting the DNS server for the remote host's domain.
226.Pp
227While
228.Fn iruserok
229can handle IPv4 addresses only,
230.Fn iruserok_sa
231and
232.Fn ruserok
233can handle other address families as well, like IPv6.
234The first argument of
235.Fn iruserok_sa
236is typed as
237.Li "void *"
238to avoid dependency between
239.Aq Pa unistd.h
240and
241.Aq Pa sys/socket.h .
176.Sh DIAGNOSTICS 242.Sh DIAGNOSTICS
177The 243The
178.Fn rcmd 244.Fn rcmd
179function 245function returns a valid socket descriptor on success.
180returns a valid socket descriptor on success.
181It returns \-1 on error and prints a diagnostic message on the standard error. 246It returns \-1 on error and prints a diagnostic message on the standard error.
182.Pp 247.Pp
183The 248The
184.Fn rresvport 249.Fn rresvport
185function 250and
186returns a valid, bound socket descriptor on success. 251.Fn rresvport_af
252functions return a valid, bound socket descriptor on success.
187It returns \-1 on error with the global value 253It returns \-1 on error with the global value
188.Va errno 254.Va errno
189set according to the reason for failure. 255set according to the reason for failure.
190The error code 256The error code
191.Dv EAGAIN 257.Er EAGAIN
192is overloaded to mean ``All network ports in use.'' 258is overloaded to mean
259.Dq all network ports in use .
193.Sh SEE ALSO 260.Sh SEE ALSO
194.Xr rlogin 1 ,
195.Xr rsh 1 , 261.Xr rsh 1 ,
196.Xr intro 2 , 262.Xr intro 2 ,
197.Xr rexec 3 , 263.Xr bindresvport 3 ,
198.Xr rexecd 8 , 264.Xr bindresvport_sa 3 ,
199.Xr rlogind 8 , 265.Xr rcmdsh 3 ,
200.Xr rshd 8 266.Xr rshd 8
201.Sh HISTORY 267.Sh HISTORY
202These 268These
203functions appeared in 269functions appeared in
204.Bx 4.2 . 270.Bx 4.2 .