diff options
Diffstat (limited to 'src/lib/libc/net/rcmd.3')
| -rw-r--r-- | src/lib/libc/net/rcmd.3 | 174 |
1 files changed, 118 insertions, 56 deletions
diff --git a/src/lib/libc/net/rcmd.3 b/src/lib/libc/net/rcmd.3 index 4db847c392..87e9a760a8 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.27 2007/05/31 19:19:30 jmc 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. |
| @@ -11,11 +11,7 @@ | |||
| 11 | .\" 2. Redistributions in binary form must reproduce the above copyright | 11 | .\" 2. Redistributions in binary form must reproduce the above copyright |
| 12 | .\" notice, this list of conditions and the following disclaimer in the | 12 | .\" notice, this list of conditions and the following disclaimer in the |
| 13 | .\" documentation and/or other materials provided with the distribution. | 13 | .\" documentation and/or other materials provided with the distribution. |
| 14 | .\" 3. All advertising materials mentioning features or use of this software | 14 | .\" 3. Neither the name of the University nor the names of its contributors |
| 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 | 15 | .\" may be used to endorse or promote products derived from this software |
| 20 | .\" without specific prior written permission. | 16 | .\" without specific prior written permission. |
| 21 | .\" | 17 | .\" |
| @@ -31,38 +27,67 @@ | |||
| 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 27 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 32 | .\" SUCH DAMAGE. | 28 | .\" SUCH DAMAGE. |
| 33 | .\" | 29 | .\" |
| 34 | .\" @(#)rcmd.3 8.1 (Berkeley) 6/4/93 | 30 | .Dd $Mdocdate: May 31 2007 $ |
| 35 | .\" | ||
| 36 | .Dd June 4, 1993 | ||
| 37 | .Dt RCMD 3 | 31 | .Dt RCMD 3 |
| 38 | .Os BSD 4.2 | 32 | .Os |
| 39 | .Sh NAME | 33 | .Sh NAME |
| 40 | .Nm rcmd , | 34 | .Nm rcmd , |
| 35 | .Nm rcmd_af , | ||
| 41 | .Nm rresvport , | 36 | .Nm rresvport , |
| 37 | .Nm rresvport_af , | ||
| 42 | .Nm iruserok , | 38 | .Nm iruserok , |
| 43 | .Nm ruserok | 39 | .Nm ruserok , |
| 40 | .Nm iruserok_sa | ||
| 44 | .Nd routines for returning a stream to a remote command | 41 | .Nd routines for returning a stream to a remote command |
| 45 | .Sh SYNOPSIS | 42 | .Sh SYNOPSIS |
| 46 | .Fd #include <unistd.h> | 43 | .Fd #include <unistd.h> |
| 47 | .Ft int | 44 | .Ft int |
| 48 | .Fn rcmd "char **ahost" "int inport" "const char *locuser" "const char *remuser" "const char *cmd" "int *fd2p" | 45 | .Fn rcmd "char **ahost" "int inport" "const char *locuser" "const char *remuser" "const char *cmd" "int *fd2p" |
| 49 | .Ft int | 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 | ||
| 50 | .Fn rresvport "int *port" | 49 | .Fn rresvport "int *port" |
| 51 | .Ft int | 50 | .Ft int |
| 52 | .Fn iruserok "u_long raddr" "int superuser" "const char *ruser" "const char *luser" | 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" | ||
| 53 | .Ft int | 54 | .Ft int |
| 54 | .Fn ruserok "const char *rhost" "int superuser" "const char *ruser" "const char *luser" | 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" | ||
| 55 | .Sh DESCRIPTION | 58 | .Sh DESCRIPTION |
| 56 | The | 59 | The |
| 57 | .Fn rcmd | 60 | .Fn rcmd |
| 58 | function | 61 | function is used by the superuser to execute a command on a remote |
| 59 | is used by the super-user to execute a command on | 62 | machine using an authentication scheme based on reserved |
| 60 | a remote machine using an authentication scheme based | 63 | port numbers. |
| 61 | on reserved 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 | ||
| 62 | The | 86 | The |
| 63 | .Fn rresvport | 87 | .Fn rresvport |
| 64 | function | 88 | and |
| 65 | returns a descriptor to a socket | 89 | .Fn rresvport_af |
| 90 | functions return a descriptor to a socket | ||
| 66 | with an address in the privileged port space. | 91 | with an address in the privileged port space. |
| 67 | The | 92 | The |
| 68 | .Fn iruserok | 93 | .Fn iruserok |
| @@ -75,11 +100,13 @@ All four functions are present in the same file and are used | |||
| 75 | by the | 100 | by the |
| 76 | .Xr rshd 8 | 101 | .Xr rshd 8 |
| 77 | server (among others). | 102 | server (among others). |
| 103 | .Fn iruserok_sa | ||
| 104 | is an address family independent variant of | ||
| 105 | .Fn iruserok . | ||
| 78 | .Pp | 106 | .Pp |
| 79 | The | 107 | The |
| 80 | .Fn rcmd | 108 | .Fn rcmd |
| 81 | function | 109 | function looks up the host |
| 82 | looks up the host | ||
| 83 | .Fa *ahost | 110 | .Fa *ahost |
| 84 | using | 111 | using |
| 85 | .Xr gethostbyname 3 , | 112 | .Xr gethostbyname 3 , |
| @@ -90,15 +117,15 @@ is set to the standard name of the host | |||
| 90 | and a connection is established to a server | 117 | and a connection is established to a server |
| 91 | residing at the well-known Internet port | 118 | residing at the well-known Internet port |
| 92 | .Fa inport . | 119 | .Fa inport . |
| 120 | If the user is not the superuser, the only valid port is | ||
| 121 | .Dq shell/tcp | ||
| 122 | (usually port 514). | ||
| 93 | .Pp | 123 | .Pp |
| 94 | If the connection succeeds, | 124 | If the connection succeeds, |
| 95 | a socket in the Internet domain of type | 125 | a socket in the Internet domain of type |
| 96 | .Dv SOCK_STREAM | 126 | .Dv SOCK_STREAM |
| 97 | is returned to the caller, and given to the remote | 127 | is returned to the caller, and given to the remote |
| 98 | command as | 128 | command as stdin and stdout. |
| 99 | .Em stdin | ||
| 100 | and | ||
| 101 | .Em stdout . | ||
| 102 | If | 129 | If |
| 103 | .Fa fd2p | 130 | .Fa fd2p |
| 104 | is non-zero, then an auxiliary channel to a control | 131 | is non-zero, then an auxiliary channel to a control |
| @@ -113,27 +140,46 @@ signal numbers, to be | |||
| 113 | forwarded to the process group of the command. | 140 | forwarded to the process group of the command. |
| 114 | If | 141 | If |
| 115 | .Fa fd2p | 142 | .Fa fd2p |
| 116 | is 0, then the | 143 | is |
| 117 | .Em stderr | 144 | .Va NULL , |
| 118 | (unit 2 of the remote | 145 | then the standard error (unit 2 of the remote command) will be made |
| 119 | command) will be made the same as the | 146 | the same as the standard output and no provision is made for sending |
| 120 | .Em stdout | 147 | arbitrary signals to the remote process, although you may be able to |
| 121 | and no | 148 | get its attention by using out-of-band data. |
| 122 | provision is made for sending arbitrary signals to the remote process, | 149 | Note that if the user is not the superuser, |
| 123 | although you may be able to get its attention by using out-of-band data. | 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. | ||
| 124 | .Pp | 161 | .Pp |
| 125 | The protocol is described in detail in | 162 | The protocol is described in detail in |
| 126 | .Xr rshd 8 . | 163 | .Xr rshd 8 . |
| 127 | .Pp | 164 | .Pp |
| 128 | The | 165 | The |
| 129 | .Fn rresvport | 166 | .Fn rresvport |
| 130 | function is used to obtain a socket with a privileged | 167 | and |
| 131 | address bound to it. This socket is suitable for use | 168 | .Fn rresvport_af |
| 132 | by | 169 | functions are used to obtain a socket with a privileged |
| 170 | address bound to it. | ||
| 171 | This socket is suitable for use by | ||
| 133 | .Fn rcmd | 172 | .Fn rcmd |
| 134 | and several other functions. Privileged Internet ports are those | 173 | and several other functions. |
| 135 | in the range 0 to 1023. Only the super-user | 174 | Privileged Internet ports are those in the range 0 to |
| 136 | is allowed to bind an address of this sort to a socket. | 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. | ||
| 137 | .Pp | 183 | .Pp |
| 138 | The | 184 | The |
| 139 | .Fn iruserok | 185 | .Fn iruserok |
| @@ -141,10 +187,10 @@ and | |||
| 141 | .Fn ruserok | 187 | .Fn ruserok |
| 142 | functions take a remote host's IP address or name, respectively, | 188 | functions take a remote host's IP address or name, respectively, |
| 143 | two user names and a flag indicating whether the local user's | 189 | two user names and a flag indicating whether the local user's |
| 144 | name is that of the super-user. | 190 | name is that of the superuser. |
| 145 | Then, if the user is | 191 | Then, if the user is |
| 146 | .Em NOT | 192 | .Em not |
| 147 | the super-user, it checks the | 193 | the superuser, it checks the |
| 148 | .Pa /etc/hosts.equiv | 194 | .Pa /etc/hosts.equiv |
| 149 | file. | 195 | file. |
| 150 | If that lookup is not done, or is unsuccessful, the | 196 | If that lookup is not done, or is unsuccessful, the |
| @@ -153,19 +199,19 @@ in the local user's home directory is checked to see if the request for | |||
| 153 | service is allowed. | 199 | service is allowed. |
| 154 | .Pp | 200 | .Pp |
| 155 | If this file does not exist, is not a regular file, is owned by anyone | 201 | If this file does not exist, is not a regular file, is owned by anyone |
| 156 | other than the user or the super-user, or is writeable by anyone other | 202 | other than the user or the superuser, or is writeable by anyone other |
| 157 | than the owner, the check automatically fails. | 203 | than the owner, the check automatically fails. |
| 158 | Zero is returned if the machine name is listed in the | 204 | Zero is returned if the machine name is listed in the |
| 159 | .Dq Pa hosts.equiv | 205 | .Pa hosts.equiv |
| 160 | file, or the host and remote user name are found in the | 206 | file, or the host and remote user name are found in the |
| 161 | .Dq Pa .rhosts | 207 | .Pa .rhosts |
| 162 | file; otherwise | 208 | file; otherwise |
| 163 | .Fn iruserok | 209 | .Fn iruserok |
| 164 | and | 210 | and |
| 165 | .Fn ruserok | 211 | .Fn ruserok |
| 166 | return \-1. | 212 | return \-1. |
| 167 | If the local domain (as obtained from | 213 | If the local domain (as obtained from |
| 168 | .Xr gethostname 2 ) | 214 | .Xr gethostname 3 ) |
| 169 | is the same as the remote domain, only the machine name need be specified. | 215 | is the same as the remote domain, only the machine name need be specified. |
| 170 | .Pp | 216 | .Pp |
| 171 | If the IP address of the remote host is known, | 217 | If the IP address of the remote host is known, |
| @@ -173,32 +219,48 @@ If the IP address of the remote host is known, | |||
| 173 | should be used in preference to | 219 | should be used in preference to |
| 174 | .Fn ruserok , | 220 | .Fn ruserok , |
| 175 | as it does not require trusting the DNS server for the remote host's domain. | 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 . | ||
| 176 | .Sh DIAGNOSTICS | 238 | .Sh DIAGNOSTICS |
| 177 | The | 239 | The |
| 178 | .Fn rcmd | 240 | .Fn rcmd |
| 179 | function | 241 | function returns a valid socket descriptor on success. |
| 180 | returns a valid socket descriptor on success. | ||
| 181 | It returns \-1 on error and prints a diagnostic message on the standard error. | 242 | It returns \-1 on error and prints a diagnostic message on the standard error. |
| 182 | .Pp | 243 | .Pp |
| 183 | The | 244 | The |
| 184 | .Fn rresvport | 245 | .Fn rresvport |
| 185 | function | 246 | and |
| 186 | returns a valid, bound socket descriptor on success. | 247 | .Fn rresvport_af |
| 248 | functions return a valid, bound socket descriptor on success. | ||
| 187 | It returns \-1 on error with the global value | 249 | It returns \-1 on error with the global value |
| 188 | .Va errno | 250 | .Va errno |
| 189 | set according to the reason for failure. | 251 | set according to the reason for failure. |
| 190 | The error code | 252 | The error code |
| 191 | .Dv EAGAIN | 253 | .Er EAGAIN |
| 192 | is overloaded to mean ``All network ports in use.'' | 254 | is overloaded to mean |
| 255 | .Dq all network ports in use . | ||
| 193 | .Sh SEE ALSO | 256 | .Sh SEE ALSO |
| 194 | .Xr rlogin 1 , | ||
| 195 | .Xr rsh 1 , | 257 | .Xr rsh 1 , |
| 196 | .Xr intro 2 , | 258 | .Xr intro 2 , |
| 197 | .Xr rexec 3 , | 259 | .Xr bindresvport 3 , |
| 198 | .Xr rexecd 8 , | 260 | .Xr bindresvport_sa 3 , |
| 199 | .Xr rlogind 8 , | 261 | .Xr rcmdsh 3 , |
| 200 | .Xr rshd 8 | 262 | .Xr rshd 8 |
| 201 | .Sh HISTORY | 263 | .Sh HISTORY |
| 202 | These | 264 | These |
| 203 | functions appeared in | 265 | functions appeared in |
| 204 | .Bx 4.2 . | 266 | .Bx 4.2 . |
