diff options
Diffstat (limited to 'src/lib/libc/net/rcmd.3')
-rw-r--r-- | src/lib/libc/net/rcmd.3 | 270 |
1 files changed, 270 insertions, 0 deletions
diff --git a/src/lib/libc/net/rcmd.3 b/src/lib/libc/net/rcmd.3 new file mode 100644 index 0000000000..7cf5af9519 --- /dev/null +++ b/src/lib/libc/net/rcmd.3 | |||
@@ -0,0 +1,270 @@ | |||
1 | .\" $OpenBSD: rcmd.3,v 1.24 2002/05/06 23:34:33 millert Exp $ | ||
2 | .\" | ||
3 | .\" Copyright (c) 1983, 1991, 1993 | ||
4 | .\" The Regents of the University of California. All rights reserved. | ||
5 | .\" | ||
6 | .\" Redistribution and use in source and binary forms, with or without | ||
7 | .\" modification, are permitted provided that the following conditions | ||
8 | .\" are met: | ||
9 | .\" 1. Redistributions of source code must retain the above copyright | ||
10 | .\" notice, this list of conditions and the following disclaimer. | ||
11 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
12 | .\" notice, this list of conditions and the following disclaimer in the | ||
13 | .\" documentation and/or other materials provided with the distribution. | ||
14 | .\" 3. All advertising materials mentioning features or use of this software | ||
15 | .\" must display the following acknowledgement: | ||
16 | .\" This product includes software developed by the University of | ||
17 | .\" California, Berkeley and its contributors. | ||
18 | .\" 4. Neither the name of the University nor the names of its contributors | ||
19 | .\" may be used to endorse or promote products derived from this software | ||
20 | .\" without specific prior written permission. | ||
21 | .\" | ||
22 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
23 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
24 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
25 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
26 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
27 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
28 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
29 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
30 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
32 | .\" SUCH DAMAGE. | ||
33 | .\" | ||
34 | .Dd June 4, 1993 | ||
35 | .Dt RCMD 3 | ||
36 | .Os | ||
37 | .Sh NAME | ||
38 | .Nm rcmd , | ||
39 | .Nm rcmd_af , | ||
40 | .Nm rresvport , | ||
41 | .Nm rresvport_af , | ||
42 | .Nm iruserok , | ||
43 | .Nm ruserok , | ||
44 | .Nm iruserok_sa | ||
45 | .Nd routines for returning a stream to a remote command | ||
46 | .Sh SYNOPSIS | ||
47 | .Fd #include <unistd.h> | ||
48 | .Ft int | ||
49 | .Fn rcmd "char **ahost" "int inport" "const char *locuser" "const char *remuser" "const char *cmd" "int *fd2p" | ||
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 | ||
53 | .Fn rresvport "int *port" | ||
54 | .Ft int | ||
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" | ||
58 | .Ft int | ||
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" | ||
62 | .Sh DESCRIPTION | ||
63 | The | ||
64 | .Fn rcmd | ||
65 | function is used by the superuser to execute a command on a remote | ||
66 | machine using an authentication scheme based on reserved | ||
67 | port numbers. | ||
68 | If the calling process is not setuid, the | ||
69 | .Ev RSH | ||
70 | environment variable is set, and | ||
71 | .Fa inport | ||
72 | is | ||
73 | .Dq shell/tcp , | ||
74 | .Xr rcmdsh 3 | ||
75 | is called instead with the value of | ||
76 | .Ev RSH . | ||
77 | Alternately, if the user is not the superuser, | ||
78 | .Fn rcmd | ||
79 | will invoke | ||
80 | .Xr rcmdsh 3 | ||
81 | to run the command via | ||
82 | .Xr rsh 1 . | ||
83 | While | ||
84 | .Fn rcmd | ||
85 | can handle IPv4 cases only, | ||
86 | the | ||
87 | .Fn rcmd_af | ||
88 | function can handle other cases as well. | ||
89 | .Pp | ||
90 | The | ||
91 | .Fn rresvport | ||
92 | and | ||
93 | .Fn rresvport_af | ||
94 | functions return a descriptor to a socket | ||
95 | with an address in the privileged port space. | ||
96 | The | ||
97 | .Fn iruserok | ||
98 | and | ||
99 | .Fn ruserok | ||
100 | functions are used by servers | ||
101 | to authenticate clients requesting service with | ||
102 | .Fn rcmd . | ||
103 | All four functions are present in the same file and are used | ||
104 | by the | ||
105 | .Xr rshd 8 | ||
106 | server (among others). | ||
107 | .Fn iruserok_sa | ||
108 | is an address family independent variant of | ||
109 | .Fn iruserok . | ||
110 | .Pp | ||
111 | The | ||
112 | .Fn rcmd | ||
113 | function looks up the host | ||
114 | .Fa *ahost | ||
115 | using | ||
116 | .Xr gethostbyname 3 , | ||
117 | returning \-1 if the host does not exist. | ||
118 | Otherwise | ||
119 | .Fa *ahost | ||
120 | is set to the standard name of the host | ||
121 | and a connection is established to a server | ||
122 | residing at the well-known Internet port | ||
123 | .Fa inport . | ||
124 | If the user is not the superuser, the only valid port is | ||
125 | .Dq shell/tcp | ||
126 | (usually port 514). | ||
127 | .Pp | ||
128 | If the connection succeeds, | ||
129 | a socket in the Internet domain of type | ||
130 | .Dv SOCK_STREAM | ||
131 | is returned to the caller, and given to the remote | ||
132 | command as stdin and stdout. | ||
133 | If | ||
134 | .Fa fd2p | ||
135 | is non-zero, then an auxiliary channel to a control | ||
136 | process will be set up, and a descriptor for it will be placed | ||
137 | in | ||
138 | .Fa *fd2p . | ||
139 | The control process will return diagnostic | ||
140 | output from the command (unit 2) on this channel, and will also | ||
141 | accept bytes on this channel as being | ||
142 | .Tn UNIX | ||
143 | signal numbers, to be | ||
144 | forwarded to the process group of the command. | ||
145 | If | ||
146 | .Fa fd2p | ||
147 | is | ||
148 | .Va NULL , | ||
149 | then the standard error (unit 2 of the remote command) will be made | ||
150 | the same as the standard output and no provision is made for sending | ||
151 | arbitrary signals to the remote process, although you may be able to | ||
152 | get its attention by using out-of-band data. | ||
153 | Note that if the user is not the superuser, | ||
154 | .Fa fd2p | ||
155 | must be | ||
156 | .Va NULL . | ||
157 | .Pp | ||
158 | .Fn rcmd_af | ||
159 | takes address family in the last argument. | ||
160 | If the last argument is | ||
161 | .Dv PF_UNSPEC , | ||
162 | interpretation of | ||
163 | .Fa *ahost | ||
164 | will obey the underlying address resolution like DNS. | ||
165 | .Pp | ||
166 | The protocol is described in detail in | ||
167 | .Xr rshd 8 . | ||
168 | .Pp | ||
169 | The | ||
170 | .Fn rresvport | ||
171 | and | ||
172 | .Fn rresvport_af | ||
173 | functions are used to obtain a socket with a privileged | ||
174 | address bound to it. | ||
175 | This socket is suitable for use by | ||
176 | .Fn rcmd | ||
177 | and several other functions. | ||
178 | Privileged Internet ports are those in the range 0 to | ||
179 | .Va IPPORT_RESERVED - 1 , | ||
180 | which happens to be 1023. | ||
181 | Only the superuser is allowed to bind an address of this sort to a socket. | ||
182 | .Fn rresvport | ||
183 | and | ||
184 | .Fn rresvport_af | ||
185 | need to be seeded with a port number; if that port | ||
186 | is not available these functions will find another. | ||
187 | .Pp | ||
188 | The | ||
189 | .Fn iruserok | ||
190 | and | ||
191 | .Fn ruserok | ||
192 | functions take a remote host's IP address or name, respectively, | ||
193 | two user names and a flag indicating whether the local user's | ||
194 | name is that of the superuser. | ||
195 | Then, if the user is | ||
196 | .Em not | ||
197 | the superuser, it checks the | ||
198 | .Pa /etc/hosts.equiv | ||
199 | file. | ||
200 | If that lookup is not done, or is unsuccessful, the | ||
201 | .Pa .rhosts | ||
202 | in the local user's home directory is checked to see if the request for | ||
203 | service is allowed. | ||
204 | .Pp | ||
205 | If this file does not exist, is not a regular file, is owned by anyone | ||
206 | other than the user or the superuser, or is writeable by anyone other | ||
207 | than the owner, the check automatically fails. | ||
208 | Zero is returned if the machine name is listed in the | ||
209 | .Pa hosts.equiv | ||
210 | file, or the host and remote user name are found in the | ||
211 | .Pa .rhosts | ||
212 | file; otherwise | ||
213 | .Fn iruserok | ||
214 | and | ||
215 | .Fn ruserok | ||
216 | return \-1. | ||
217 | If the local domain (as obtained from | ||
218 | .Xr gethostname 3 ) | ||
219 | is the same as the remote domain, only the machine name need be specified. | ||
220 | .Pp | ||
221 | If the IP address of the remote host is known, | ||
222 | .Fn iruserok | ||
223 | should be used in preference to | ||
224 | .Fn ruserok , | ||
225 | as it does not require trusting the DNS server for the remote host's domain. | ||
226 | .Pp | ||
227 | While | ||
228 | .Fn iruserok | ||
229 | can handle IPv4 addresses only, | ||
230 | .Fn iruserok_sa | ||
231 | and | ||
232 | .Fn ruserok | ||
233 | can handle other address families as well, like IPv6. | ||
234 | The first argument of | ||
235 | .Fn iruserok_sa | ||
236 | is typed as | ||
237 | .Li "void *" | ||
238 | to avoid dependency between | ||
239 | .Aq Pa unistd.h | ||
240 | and | ||
241 | .Aq Pa sys/socket.h . | ||
242 | .Sh DIAGNOSTICS | ||
243 | The | ||
244 | .Fn rcmd | ||
245 | function returns a valid socket descriptor on success. | ||
246 | It returns \-1 on error and prints a diagnostic message on the standard error. | ||
247 | .Pp | ||
248 | The | ||
249 | .Fn rresvport | ||
250 | and | ||
251 | .Fn rresvport_af | ||
252 | functions return a valid, bound socket descriptor on success. | ||
253 | It returns \-1 on error with the global value | ||
254 | .Va errno | ||
255 | set according to the reason for failure. | ||
256 | The error code | ||
257 | .Er EAGAIN | ||
258 | is overloaded to mean | ||
259 | .Dq all network ports in use . | ||
260 | .Sh SEE ALSO | ||
261 | .Xr rsh 1 , | ||
262 | .Xr intro 2 , | ||
263 | .Xr bindresvport 3 , | ||
264 | .Xr bindresvport_sa 3 , | ||
265 | .Xr rcmdsh 3 , | ||
266 | .Xr rshd 8 | ||
267 | .Sh HISTORY | ||
268 | These | ||
269 | functions appeared in | ||
270 | .Bx 4.2 . | ||