OSDN Git Service

LDP: Update original to LDP v3.68
[linuxjm/LDP_man-pages.git] / original / man3 / rcmd.3
1 .\"     $NetBSD: rcmd.3,v 1.9 1996/05/28 02:07:39 mrg Exp $
2 .\"
3 .\" Copyright (c) 1983, 1991, 1993
4 .\"     The Regents of the University of California.  All rights reserved.
5 .\"
6 .\" %%%LICENSE_START(BSD_4_CLAUSE_UCB)
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
9 .\" are met:
10 .\" 1. Redistributions of source code must retain the above copyright
11 .\"    notice, this list of conditions and the following disclaimer.
12 .\" 2. Redistributions in binary form must reproduce the above copyright
13 .\"    notice, this list of conditions and the following disclaimer in the
14 .\"    documentation and/or other materials provided with the distribution.
15 .\" 3. All advertising materials mentioning features or use of this software
16 .\"    must display the following acknowledgement:
17 .\"     This product includes software developed by the University of
18 .\"     California, Berkeley and its contributors.
19 .\" 4. Neither the name of the University nor the names of its contributors
20 .\"    may be used to endorse or promote products derived from this software
21 .\"    without specific prior written permission.
22 .\"
23 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 .\" SUCH DAMAGE.
34 .\" %%%LICENSE_END
35 .\"
36 .\"     @(#)rcmd.3      8.1 (Berkeley) 6/4/93
37 .\"
38 .\" Contributed as Linux man page by David A. Holland, 970908
39 .\" I have not checked whether the Linux situation is exactly the same.
40 .\"
41 .\" 2007-12-08, mtk, Converted from mdoc to man macros
42 .\"
43 .TH RCMD 3 2014-05-28 "Linux" "Linux Programmer's Manual"
44 .SH NAME
45 rcmd, rresvport, iruserok, ruserok, rcmd_af,
46 rresvport_af, iruserok_af, ruserok_af \- routines for returning a
47 stream to a remote command
48 .SH SYNOPSIS
49 .nf
50 .B #include <netdb.h> \ \ \fP/* Or <unistd.h> on some systems */
51 .sp
52 .BI "int rcmd(char **" ahost ", unsigned short " inport ", const char *" locuser ", "
53 .BI "         const char *" remuser ", const char *" cmd ", int *" fd2p );
54 .sp
55 .BI "int rresvport(int *" port );
56 .sp
57 .BI "int iruserok(uint32_t " raddr ", int " superuser ", "
58 .BI "             const char *" ruser ", const char *" luser );
59 .sp
60 .BI "int ruserok(const char *" rhost ", int " superuser ", "
61 .BI "            const char *" ruser ", const char *" luser );
62 .sp
63 .BI "int rcmd_af(char **" ahost ", unsigned short " inport ", const char *" locuser ", "
64 .BI "            const char *" remuser ", const char *" cmd ", int *" fd2p ,
65 .BI "            sa_family_t " af );
66 .sp
67 .BI "int rresvport_af(int *" port ", sa_family_t " af );
68 .sp
69 .BI "int iruserok_af(const void *" raddr ", int " superuser ", "
70 .BI "                const char *" ruser ", const char *" luser \
71 ", sa_family_t " af );
72 .sp
73 .BI "int ruserok_af(const char *" rhost ", int " superuser ", "
74 .BI "               const char *" ruser ", const char *" luser \
75 ", sa_family_t " af );
76 .fi
77 .sp
78 .in -4n
79 Feature Test Macro Requirements for glibc (see
80 .BR feature_test_macros (7)):
81 .in
82 .sp
83 .BR rcmd (),
84 .BR rcmd_af (),
85 .BR rresvport (),
86 .BR rresvport_af (),
87 .BR iruserok (),
88 .BR iruserok_af (),
89 .BR ruserok (),
90 .BR ruserok_af ():
91 _BSD_SOURCE
92 .SH DESCRIPTION
93 The
94 .BR rcmd ()
95 function is used by the superuser to execute a command on
96 a remote machine using an authentication scheme based
97 on privileged port numbers.
98 The
99 .BR rresvport ()
100 function
101 returns a descriptor to a socket
102 with an address in the privileged port space.
103 The
104 .BR iruserok ()
105 and
106 .BR ruserok ()
107 functions are used by servers
108 to authenticate clients requesting service with
109 .BR rcmd ().
110 All four functions are used by the
111 .BR rshd (8)
112 server (among others).
113 .SS rcmd()
114 .PP
115 The
116 .BR rcmd ()
117 function
118 looks up the host
119 .I *ahost
120 using
121 .BR gethostbyname (3),
122 returning \-1 if the host does not exist.
123 Otherwise,
124 .I *ahost
125 is set to the standard name of the host
126 and a connection is established to a server
127 residing at the well-known Internet port
128 .IR inport .
129 .PP
130 If the connection succeeds,
131 a socket in the Internet domain of type
132 .BR SOCK_STREAM
133 is returned to the caller, and given to the remote
134 command as
135 .IR stdin
136 and
137 .IR stdout .
138 If
139 .I fd2p
140 is nonzero, then an auxiliary channel to a control
141 process will be set up, and a descriptor for it will be placed
142 in
143 .IR *fd2p .
144 The control process will return diagnostic
145 output from the command (unit 2) on this channel, and will also
146 accept bytes on this channel as being UNIX signal numbers, to be
147 forwarded to the process group of the command.
148 If
149 .I fd2p
150 is 0, then the
151 .IR stderr
152 (unit 2 of the remote
153 command) will be made the same as the
154 .IR stdout
155 and no
156 provision is made for sending arbitrary signals to the remote process,
157 although you may be able to get its attention by using out-of-band data.
158 .PP
159 The protocol is described in detail in
160 .BR rshd (8).
161 .SS rresvport()
162 .PP
163 The
164 .BR rresvport ()
165 function is used to obtain a socket with a privileged
166 port bound to it.
167 This socket is suitable for use by
168 .BR rcmd ()
169 and several other functions.
170 Privileged ports are those in the range 0 to 1023.
171 Only a privileged process
172 .RB ( CAP_NET_BIND_SERVICE )
173 is allowed to bind to a privileged port.
174 In the glibc implementation,
175 this function restricts its search to the ports from 512 to 1023.
176 The
177 .I port
178 argument is value-result:
179 the value it supplies to the call is used as the starting point
180 for a circular search of the port range;
181 on (successful) return, it contains the port number that was bound to.
182 .\"
183 .SS iruserok() and ruserok()
184 .PP
185 The
186 .BR iruserok ()
187 and
188 .BR ruserok ()
189 functions take a remote host's IP address or name, respectively,
190 two usernames and a flag indicating whether the local user's
191 name is that of the superuser.
192 Then, if the user is
193 .I not
194 the superuser, it checks the
195 .IR /etc/hosts.equiv
196 file.
197 If that lookup is not done, or is unsuccessful, the
198 .IR .rhosts
199 in the local user's home directory is checked to see if the request for
200 service is allowed.
201 .PP
202 If this file does not exist, is not a regular file, is owned by anyone
203 other than the user or the superuser, or is writable by anyone other
204 than the owner, the check automatically fails.
205 Zero is returned if the machine name is listed in the
206 .IR hosts.equiv
207 file, or the host and remote username are found in the
208 .IR .rhosts
209 file; otherwise
210 .BR iruserok ()
211 and
212 .BR ruserok ()
213 return \-1.
214 If the local domain (as obtained from
215 .BR gethostname (2))
216 is the same as the remote domain, only the machine name need be specified.
217 .PP
218 If the IP address of the remote host is known,
219 .BR iruserok ()
220 should be used in preference to
221 .BR ruserok (),
222 as it does not require trusting the DNS server for the remote host's domain.
223 .SS *_af() variants
224 All of the functions described above work with IPv4
225 .RB ( AF_INET )
226 sockets.
227 The "_af" variants take an extra argument that allows the
228 socket address family to be specified.
229 For these functions, the
230 .I af
231 argument can be specified as
232 .BR AF_INET
233 or
234 .BR AF_INET6 .
235 In addition,
236 .BR rcmd_af ()
237 supports the use of
238 .BR AF_UNSPEC .
239 .SH RETURN VALUE
240 The
241 .BR rcmd ()
242 function
243 returns a valid socket descriptor on success.
244 It returns \-1 on error and prints a diagnostic message on the standard error.
245 .PP
246 The
247 .BR rresvport ()
248 function
249 returns a valid, bound socket descriptor on success.
250 It returns \-1 on error with the global value
251 .I errno
252 set according to the reason for failure.
253 The error code
254 .BR EAGAIN
255 is overloaded to mean "All network ports in use."
256
257 For information on the return from
258 .BR ruserok ()
259 and
260 .BR iruserok (),
261 see above.
262 .SH VERSIONS
263 The functions
264 .BR iruserok_af (),
265 .BR rcmd_af (),
266 .BR rresvport_af (),
267 and
268 .BR ruserok_af ()
269 functions are provide in glibc since version 2.2.
270 .SH CONFORMING TO
271 Not in POSIX.1-2001.
272 Present on the BSDs, Solaris, and many other systems.
273 These
274 functions appeared in
275 4.2BSD.
276 The "_af" variants are more recent additions,
277 and are not present on as wide a range of systems.
278 .SH BUGS
279 .BR iruserok ()
280 and
281 .BR iruserok_af ()
282 are declared in glibc headers only since version 2.12.
283 .\" Bug filed 25 Nov 2007:
284 .\" http://sources.redhat.com/bugzilla/show_bug.cgi?id=5399
285 .SH SEE ALSO
286 .BR rlogin (1),
287 .BR rsh (1),
288 .BR intro (2),
289 .BR rexec (3),
290 .BR rexecd (8),
291 .BR rlogind (8),
292 .BR rshd (8)
293 .SH COLOPHON
294 This page is part of release 3.68 of the Linux
295 .I man-pages
296 project.
297 A description of the project,
298 information about reporting bugs,
299 and the latest version of this page,
300 can be found at
301 \%http://www.kernel.org/doc/man\-pages/.