diff options
Diffstat (limited to 'src/lib/libc/net/rcmd.3')
| -rw-r--r-- | src/lib/libc/net/rcmd.3 | 166 |
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 |
| 56 | The | 63 | The |
| 57 | .Fn rcmd | 64 | .Fn rcmd |
| 58 | function | 65 | 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 | 66 | machine using an authentication scheme based on reserved |
| 60 | a remote machine using an authentication scheme based | 67 | port numbers. |
| 61 | on reserved 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 | ||
| 62 | The | 90 | The |
| 63 | .Fn rresvport | 91 | .Fn rresvport |
| 64 | function | 92 | and |
| 65 | returns a descriptor to a socket | 93 | .Fn rresvport_af |
| 94 | functions return a descriptor to a socket | ||
| 66 | with an address in the privileged port space. | 95 | with an address in the privileged port space. |
| 67 | The | 96 | The |
| 68 | .Fn iruserok | 97 | .Fn iruserok |
| @@ -75,11 +104,13 @@ All four functions are present in the same file and are used | |||
| 75 | by the | 104 | by the |
| 76 | .Xr rshd 8 | 105 | .Xr rshd 8 |
| 77 | server (among others). | 106 | server (among others). |
| 107 | .Fn iruserok_sa | ||
| 108 | is an address family independent variant of | ||
| 109 | .Fn iruserok . | ||
| 78 | .Pp | 110 | .Pp |
| 79 | The | 111 | The |
| 80 | .Fn rcmd | 112 | .Fn rcmd |
| 81 | function | 113 | function looks up the host |
| 82 | looks up the host | ||
| 83 | .Fa *ahost | 114 | .Fa *ahost |
| 84 | using | 115 | using |
| 85 | .Xr gethostbyname 3 , | 116 | .Xr gethostbyname 3 , |
| @@ -90,15 +121,15 @@ is set to the standard name of the host | |||
| 90 | and a connection is established to a server | 121 | and a connection is established to a server |
| 91 | residing at the well-known Internet port | 122 | residing at the well-known Internet port |
| 92 | .Fa inport . | 123 | .Fa inport . |
| 124 | If the user is not the superuser, the only valid port is | ||
| 125 | .Dq shell/tcp | ||
| 126 | (usually port 514). | ||
| 93 | .Pp | 127 | .Pp |
| 94 | If the connection succeeds, | 128 | If the connection succeeds, |
| 95 | a socket in the Internet domain of type | 129 | a socket in the Internet domain of type |
| 96 | .Dv SOCK_STREAM | 130 | .Dv SOCK_STREAM |
| 97 | is returned to the caller, and given to the remote | 131 | is returned to the caller, and given to the remote |
| 98 | command as | 132 | command as stdin and stdout. |
| 99 | .Em stdin | ||
| 100 | and | ||
| 101 | .Em stdout . | ||
| 102 | If | 133 | If |
| 103 | .Fa fd2p | 134 | .Fa fd2p |
| 104 | is non-zero, then an auxiliary channel to a control | 135 | is non-zero, then an auxiliary channel to a control |
| @@ -113,27 +144,46 @@ signal numbers, to be | |||
| 113 | forwarded to the process group of the command. | 144 | forwarded to the process group of the command. |
| 114 | If | 145 | If |
| 115 | .Fa fd2p | 146 | .Fa fd2p |
| 116 | is 0, then the | 147 | is |
| 117 | .Em stderr | 148 | .Va NULL , |
| 118 | (unit 2 of the remote | 149 | then the standard error (unit 2 of the remote command) will be made |
| 119 | command) will be made the same as the | 150 | the same as the standard output and no provision is made for sending |
| 120 | .Em stdout | 151 | arbitrary signals to the remote process, although you may be able to |
| 121 | and no | 152 | get its attention by using out-of-band data. |
| 122 | provision is made for sending arbitrary signals to the remote process, | 153 | 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. | 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. | ||
| 124 | .Pp | 165 | .Pp |
| 125 | The protocol is described in detail in | 166 | The protocol is described in detail in |
| 126 | .Xr rshd 8 . | 167 | .Xr rshd 8 . |
| 127 | .Pp | 168 | .Pp |
| 128 | The | 169 | The |
| 129 | .Fn rresvport | 170 | .Fn rresvport |
| 130 | function is used to obtain a socket with a privileged | 171 | and |
| 131 | address bound to it. This socket is suitable for use | 172 | .Fn rresvport_af |
| 132 | by | 173 | functions are used to obtain a socket with a privileged |
| 174 | address bound to it. | ||
| 175 | This socket is suitable for use by | ||
| 133 | .Fn rcmd | 176 | .Fn rcmd |
| 134 | and several other functions. Privileged Internet ports are those | 177 | and several other functions. |
| 135 | in the range 0 to 1023. Only the super-user | 178 | Privileged Internet ports are those in the range 0 to |
| 136 | is allowed to bind an address of this sort to a socket. | 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. | ||
| 137 | .Pp | 187 | .Pp |
| 138 | The | 188 | The |
| 139 | .Fn iruserok | 189 | .Fn iruserok |
| @@ -141,10 +191,10 @@ and | |||
| 141 | .Fn ruserok | 191 | .Fn ruserok |
| 142 | functions take a remote host's IP address or name, respectively, | 192 | functions take a remote host's IP address or name, respectively, |
| 143 | two user names and a flag indicating whether the local user's | 193 | two user names and a flag indicating whether the local user's |
| 144 | name is that of the super-user. | 194 | name is that of the superuser. |
| 145 | Then, if the user is | 195 | Then, if the user is |
| 146 | .Em NOT | 196 | .Em not |
| 147 | the super-user, it checks the | 197 | the superuser, it checks the |
| 148 | .Pa /etc/hosts.equiv | 198 | .Pa /etc/hosts.equiv |
| 149 | file. | 199 | file. |
| 150 | If that lookup is not done, or is unsuccessful, the | 200 | If 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 | |||
| 153 | service is allowed. | 203 | service is allowed. |
| 154 | .Pp | 204 | .Pp |
| 155 | If this file does not exist, is not a regular file, is owned by anyone | 205 | 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 | 206 | other than the user or the superuser, or is writeable by anyone other |
| 157 | than the owner, the check automatically fails. | 207 | than the owner, the check automatically fails. |
| 158 | Zero is returned if the machine name is listed in the | 208 | Zero is returned if the machine name is listed in the |
| 159 | .Dq Pa hosts.equiv | 209 | .Pa hosts.equiv |
| 160 | file, or the host and remote user name are found in the | 210 | file, or the host and remote user name are found in the |
| 161 | .Dq Pa .rhosts | 211 | .Pa .rhosts |
| 162 | file; otherwise | 212 | file; otherwise |
| 163 | .Fn iruserok | 213 | .Fn iruserok |
| 164 | and | 214 | and |
| 165 | .Fn ruserok | 215 | .Fn ruserok |
| 166 | return \-1. | 216 | return \-1. |
| 167 | If the local domain (as obtained from | 217 | If the local domain (as obtained from |
| 168 | .Xr gethostname 2 ) | 218 | .Xr gethostname 3 ) |
| 169 | is the same as the remote domain, only the machine name need be specified. | 219 | is the same as the remote domain, only the machine name need be specified. |
| 170 | .Pp | 220 | .Pp |
| 171 | If the IP address of the remote host is known, | 221 | If the IP address of the remote host is known, |
| @@ -173,32 +223,48 @@ If the IP address of the remote host is known, | |||
| 173 | should be used in preference to | 223 | should be used in preference to |
| 174 | .Fn ruserok , | 224 | .Fn ruserok , |
| 175 | as it does not require trusting the DNS server for the remote host's domain. | 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 . | ||
| 176 | .Sh DIAGNOSTICS | 242 | .Sh DIAGNOSTICS |
| 177 | The | 243 | The |
| 178 | .Fn rcmd | 244 | .Fn rcmd |
| 179 | function | 245 | 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. | 246 | It returns \-1 on error and prints a diagnostic message on the standard error. |
| 182 | .Pp | 247 | .Pp |
| 183 | The | 248 | The |
| 184 | .Fn rresvport | 249 | .Fn rresvport |
| 185 | function | 250 | and |
| 186 | returns a valid, bound socket descriptor on success. | 251 | .Fn rresvport_af |
| 252 | functions return a valid, bound socket descriptor on success. | ||
| 187 | It returns \-1 on error with the global value | 253 | It returns \-1 on error with the global value |
| 188 | .Va errno | 254 | .Va errno |
| 189 | set according to the reason for failure. | 255 | set according to the reason for failure. |
| 190 | The error code | 256 | The error code |
| 191 | .Dv EAGAIN | 257 | .Er EAGAIN |
| 192 | is overloaded to mean ``All network ports in use.'' | 258 | is 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 |
| 202 | These | 268 | These |
| 203 | functions appeared in | 269 | functions appeared in |
| 204 | .Bx 4.2 . | 270 | .Bx 4.2 . |
