OSDN Git Service

(split) LDP: Update original to LDP v3.40.
[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 .\" 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 .\"     @(#)rcmd.3      8.1 (Berkeley) 6/4/93
35 .\"
36 .\" Contributed as Linux man page by David A. Holland, 970908
37 .\" I have not checked whether the Linux situation is exactly the same.
38 .\"
39 .\" 2007-12-08, mtk, Converted from mdoc to man macros
40 .\"
41 .TH RCMD 3 2012-04-23 "Linux" "Linux Programmer's Manual"
42 .SH NAME
43 rcmd, rresvport, iruserok, ruserok, rcmd_af,
44 rresvport_af, iruserok_af, ruserok_af \- routines for returning a
45 stream to a remote command
46 .SH SYNOPSIS
47 .nf
48 .B #include <netdb.h> \ \ \fP/* Or <unistd.h> on some systems */
49 .sp
50 .BI "int rcmd(char **" ahost ", int " inport ", const char *" locuser ", "
51 .BI "         const char *" remuser ", const char *" cmd ", int *" fd2p );
52 .sp
53 .BI "int rresvport(int *" port );
54 .sp
55 .BI "int iruserok(uint32_t " raddr ", int " superuser ", "
56 .BI "             const char *" ruser ", const char *" luser );
57 .sp
58 .BI "int ruserok(const char *" rhost ", int " superuser ", "
59 .BI "            const char *" ruser ", const char *" luser );
60 .sp
61 .BI "int rcmd_af(char **" ahost ", int " inport ", const char *" locuser ", "
62 .BI "            const char *" remuser ", const char *" cmd ", int *" fd2p ,
63 .BI "            sa_family_t " af );
64 .sp
65 .BI "int rresvport_af(int *" port ", sa_family_t " af );
66 .sp
67 .BI "int iruserok_af(uint32_t " raddr ", int " superuser ", "
68 .BI "                const char *" ruser ", const char *" luser \
69 ", sa_family_t " af );
70 .sp
71 .BI "int ruserok_af(const char *" rhost ", int " superuser ", "
72 .BI "               const char *" ruser ", const char *" luser \
73 ", sa_family_t " af );
74 .fi
75 .sp
76 .in -4n
77 Feature Test Macro Requirements for glibc (see
78 .BR feature_test_macros (7)):
79 .in
80 .sp
81 .BR rcmd (),
82 .BR rcmd_af (),
83 .BR rresvport (),
84 .BR rresvport_af (),
85 .BR iruserok (),
86 .BR iruserok_af (),
87 .BR ruserok (),
88 .BR ruserok_af ():
89 _BSD_SOURCE
90 .SH DESCRIPTION
91 The
92 .BR rcmd ()
93 function is used by the superuser to execute a command on
94 a remote machine using an authentication scheme based
95 on privileged port numbers.
96 The
97 .BR rresvport ()
98 function
99 returns a descriptor to a socket
100 with an address in the privileged port space.
101 The
102 .BR iruserok ()
103 and
104 .BR ruserok ()
105 functions are used by servers
106 to authenticate clients requesting service with
107 .BR rcmd ().
108 All four functions are used by the
109 .BR rshd (8)
110 server (among others).
111 .SS rcmd()
112 .PP
113 The
114 .BR rcmd ()
115 function
116 looks up the host
117 .I *ahost
118 using
119 .BR gethostbyname (3),
120 returning \-1 if the host does not exist.
121 Otherwise
122 .I *ahost
123 is set to the standard name of the host
124 and a connection is established to a server
125 residing at the well-known Internet port
126 .IR inport .
127 .PP
128 If the connection succeeds,
129 a socket in the Internet domain of type
130 .BR SOCK_STREAM
131 is returned to the caller, and given to the remote
132 command as
133 .IR stdin
134 and
135 .IR stdout .
136 If
137 .I fd2p
138 is nonzero, then an auxiliary channel to a control
139 process will be set up, and a descriptor for it will be placed
140 in
141 .IR *fd2p .
142 The control process will return diagnostic
143 output from the command (unit 2) on this channel, and will also
144 accept bytes on this channel as being UNIX signal numbers, to be
145 forwarded to the process group of the command.
146 If
147 .I fd2p
148 is 0, then the
149 .IR stderr
150 (unit 2 of the remote
151 command) will be made the same as the
152 .IR stdout
153 and no
154 provision is made for sending arbitrary signals to the remote process,
155 although you may be able to get its attention by using out-of-band data.
156 .PP
157 The protocol is described in detail in
158 .BR rshd (8).
159 .SS rresvport()
160 .PP
161 The
162 .BR rresvport ()
163 function is used to obtain a socket with a privileged
164 port bound to it.
165 This socket is suitable for use by
166 .BR rcmd ()
167 and several other functions.
168 Privileged ports are those in the range 0 to 1023.
169 Only a privileged process
170 .RB ( CAP_NET_BIND_SERVICE )
171 is allowed to bind to a privileged port.
172 In the glibc implementation,
173 this function restricts its search to the ports from 512 to 1023.
174 The
175 .I port
176 argument is value-result:
177 the value it supplies to the call is used as the starting point
178 for a circular search of the port range;
179 on (successful) return, it contains the port number that was bound to.
180 .\"
181 .SS iruserok() and ruserok()
182 .PP
183 The
184 .BR iruserok ()
185 and
186 .BR ruserok ()
187 functions take a remote host's IP address or name, respectively,
188 two usernames and a flag indicating whether the local user's
189 name is that of the superuser.
190 Then, if the user is
191 .I not
192 the superuser, it checks the
193 .IR /etc/hosts.equiv
194 file.
195 If that lookup is not done, or is unsuccessful, the
196 .IR .rhosts
197 in the local user's home directory is checked to see if the request for
198 service is allowed.
199 .PP
200 If this file does not exist, is not a regular file, is owned by anyone
201 other than the user or the superuser, or is writable by anyone other
202 than the owner, the check automatically fails.
203 Zero is returned if the machine name is listed in the
204 .IR hosts.equiv
205 file, or the host and remote username are found in the
206 .IR .rhosts
207 file; otherwise
208 .BR iruserok ()
209 and
210 .BR ruserok ()
211 return \-1.
212 If the local domain (as obtained from
213 .BR gethostname (2))
214 is the same as the remote domain, only the machine name need be specified.
215 .PP
216 If the IP address of the remote host is known,
217 .BR iruserok ()
218 should be used in preference to
219 .BR ruserok (),
220 as it does not require trusting the DNS server for the remote host's domain.
221 .SS *_af() variants
222 All of the functions described above work with IPv4
223 .RB ( AF_INET )
224 sockets.
225 The "_af" variants take an extra argument that allows the
226 socket address family to be specified.
227 For these functions, the
228 .I af
229 argument can be specified as
230 .BR AF_INET
231 or
232 .BR AF_INET6 .
233 In addition,
234 .BR rcmd_af ()
235 supports the use of
236 .BR AF_UNSPEC .
237 .SH RETURN VALUE
238 The
239 .BR rcmd ()
240 function
241 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 .BR rresvport ()
246 function
247 returns a valid, bound socket descriptor on success.
248 It returns \-1 on error with the global value
249 .I errno
250 set according to the reason for failure.
251 The error code
252 .BR EAGAIN
253 is overloaded to mean "All network ports in use."
254
255 For information on the return from
256 .BR ruserok ()
257 and
258 .BR iruserok (),
259 see above.
260 .SH VERSIONS
261 The functions
262 .BR iruserok_af (),
263 .BR rcmd_af (),
264 .BR rresvport_af (),
265 and
266 .BR ruserok_af ()
267 functions are provide in glibc since version 2.2.
268 .SH "CONFORMING TO"
269 Not in POSIX.1-2001.
270 Present on the BSDs, Solaris, and many other systems.
271 These
272 functions appeared in
273 4.2BSD.
274 The "_af" variants are more recent additions,
275 and are not present on as wide a range of systems.
276 .SH BUGS
277 .BR iruserok ()
278 and
279 .BR iruserok_af ()
280 are declared in glibc headers only since version 2.12.
281 .\" Bug filed 25 Nov 2007:
282 .\" http://sources.redhat.com/bugzilla/show_bug.cgi?id=5399
283 .SH SEE ALSO
284 .BR rlogin (1),
285 .BR rsh (1),
286 .BR intro (2),
287 .BR rexec (3),
288 .BR rexecd (8),
289 .BR rlogind (8),
290 .BR rshd (8)