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