mount_setattr.2: ffix
[man-pages.git] / man3 / rcmd.3
blobb2f06c01d379eacb6ce855c1faaef41017da3705
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 2021-03-22 "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 .BR "#include <netdb.h>    " "/* Or <unistd.h> on some systems */"
51 .PP
52 .BI "int rcmd(char **restrict " ahost ", unsigned short " inport ,
53 .BI "            const char *restrict " locuser ,
54 .BI "            const char *restrict " remuser ,
55 .BI "            const char *restrict " cmd ", int *restrict " fd2p );
56 .PP
57 .BI "int rresvport(int *" port );
58 .PP
59 .BI "int iruserok(uint32_t " raddr ", int " superuser ,
60 .BI "            const char *" ruser ", const char *" luser );
61 .BI "int ruserok(const char *" rhost ", int " superuser ,
62 .BI "            const char *" ruser ", const char *" luser );
63 .PP
64 .BI "int rcmd_af(char **restrict " ahost ", unsigned short " inport ,
65 .BI "            const char *restrict " locuser ,
66 .BI "            const char *restrict " remuser ,
67 .BI "            const char *restrict " cmd ", int *restrict " fd2p ,
68 .BI "            sa_family_t " af );
69 .PP
70 .BI "int rresvport_af(int *" port ", sa_family_t " af );
71 .PP
72 .BI "int iruserok_af(const void *restrict " raddr ", int " superuser ,
73 .BI "            const char *restrict " ruser ", const char *restrict " luser ,
74 .BI "            sa_family_t " af );
75 .BI "int ruserok_af(const char *" rhost ", int " superuser ,
76 .BI "            const char *" ruser ", const char *" luser ,
77 .BI "            sa_family_t " af );
78 .fi
79 .PP
80 .RS -4
81 Feature Test Macro Requirements for glibc (see
82 .BR feature_test_macros (7)):
83 .RE
84 .ad l
85 .PP
86 .BR rcmd (),
87 .BR rcmd_af (),
88 .BR rresvport (),
89 .BR rresvport_af (),
90 .BR iruserok (),
91 .BR iruserok_af (),
92 .BR ruserok (),
93 .BR ruserok_af ():
94 .nf
95     Since glibc 2.19:
96         _DEFAULT_SOURCE
97     Glibc 2.19 and earlier:
98         _BSD_SOURCE
99 .fi
101 .SH DESCRIPTION
103 .BR rcmd ()
104 function is used by the superuser to execute a command on
105 a remote machine using an authentication scheme based
106 on privileged port numbers.
108 .BR rresvport ()
109 function
110 returns a file descriptor to a socket
111 with an address in the privileged port space.
113 .BR iruserok ()
115 .BR ruserok ()
116 functions are used by servers
117 to authenticate clients requesting service with
118 .BR rcmd ().
119 All four functions are used by the
120 .BR rshd (8)
121 server (among others).
122 .SS rcmd()
124 .BR rcmd ()
125 function
126 looks up the host
127 .I *ahost
128 using
129 .BR gethostbyname (3),
130 returning \-1 if the host does not exist.
131 Otherwise,
132 .I *ahost
133 is set to the standard name of the host
134 and a connection is established to a server
135 residing at the well-known Internet port
136 .IR inport .
138 If the connection succeeds,
139 a socket in the Internet domain of type
140 .BR SOCK_STREAM
141 is returned to the caller, and given to the remote
142 command as
143 .IR stdin
145 .IR stdout .
147 .I fd2p
148 is nonzero, then an auxiliary channel to a control
149 process will be set up, and a file descriptor for it will be placed
151 .IR *fd2p .
152 The control process will return diagnostic
153 output from the command (unit 2) on this channel, and will also
154 accept bytes on this channel as being UNIX signal numbers, to be
155 forwarded to the process group of the command.
157 .I fd2p
158 is 0, then the
159 .IR stderr
160 (unit 2 of the remote
161 command) will be made the same as the
162 .IR stdout
163 and no
164 provision is made for sending arbitrary signals to the remote process,
165 although you may be able to get its attention by using out-of-band data.
167 The protocol is described in detail in
168 .BR rshd (8).
169 .SS rresvport()
171 .BR rresvport ()
172 function is used to obtain a socket with a privileged
173 port bound to it.
174 This socket is suitable for use by
175 .BR rcmd ()
176 and several other functions.
177 Privileged ports are those in the range 0 to 1023.
178 Only a privileged process
179 (on Linux, a process that has the
180 .B CAP_NET_BIND_SERVICE
181 capability in the user namespace governing its network namespace)
182 is allowed to bind to a privileged port.
183 In the glibc implementation,
184 this function restricts its search to the ports from 512 to 1023.
186 .I port
187 argument is value-result:
188 the value it supplies to the call is used as the starting point
189 for a circular search of the port range;
190 on (successful) return, it contains the port number that was bound to.
192 .SS iruserok() and ruserok()
194 .BR iruserok ()
196 .BR ruserok ()
197 functions take a remote host's IP address or name, respectively,
198 two usernames and a flag indicating whether the local user's
199 name is that of the superuser.
200 Then, if the user is
201 .I not
202 the superuser, it checks the
203 .IR /etc/hosts.equiv
204 file.
205 If that lookup is not done, or is unsuccessful, the
206 .IR .rhosts
207 in the local user's home directory is checked to see if the request for
208 service is allowed.
210 If this file does not exist, is not a regular file, is owned by anyone
211 other than the user or the superuser, is writable by anyone other
212 than the owner, or is hardlinked anywhere, the check automatically fails.
213 Zero is returned if the machine name is listed in the
214 .IR hosts.equiv
215 file, or the host and remote username are found in the
216 .IR .rhosts
217 file; otherwise
218 .BR iruserok ()
220 .BR ruserok ()
221 return \-1.
222 If the local domain (as obtained from
223 .BR gethostname (2))
224 is the same as the remote domain, only the machine name need be specified.
226 If the IP address of the remote host is known,
227 .BR iruserok ()
228 should be used in preference to
229 .BR ruserok (),
230 as it does not require trusting the DNS server for the remote host's domain.
231 .SS *_af() variants
232 All of the functions described above work with IPv4
233 .RB ( AF_INET )
234 sockets.
235 The "_af" variants take an extra argument that allows the
236 socket address family to be specified.
237 For these functions, the
238 .I af
239 argument can be specified as
240 .BR AF_INET
242 .BR AF_INET6 .
243 In addition,
244 .BR rcmd_af ()
245 supports the use of
246 .BR AF_UNSPEC .
247 .SH RETURN VALUE
249 .BR rcmd ()
250 function
251 returns a valid socket descriptor on success.
252 It returns \-1 on error and prints a diagnostic message on the standard error.
255 .BR rresvport ()
256 function
257 returns a valid, bound socket descriptor on success.
258 On failure, it returns \-1 and sets
259 .I errno
260 to indicate the error.
261 The error code
262 .BR EAGAIN
263 is overloaded to mean: "All network ports in use".
265 For information on the return from
266 .BR ruserok ()
268 .BR iruserok (),
269 see above.
270 .SH VERSIONS
271 The functions
272 .BR iruserok_af (),
273 .BR rcmd_af (),
274 .BR rresvport_af (),
276 .BR ruserok_af ()
277 functions are provide in glibc since version 2.2.
278 .SH ATTRIBUTES
279 For an explanation of the terms used in this section, see
280 .BR attributes (7).
281 .ad l
284 allbox;
285 lbx lb lb
286 l l l.
287 Interface       Attribute       Value
289 .BR rcmd (),
290 .BR rcmd_af ()
291 T}      Thread safety   MT-Unsafe
293 .BR rresvport (),
294 .BR rresvport_af ()
295 T}      Thread safety   MT-Safe
297 .BR iruserok (),
298 .BR ruserok (),
299 .BR iruserok_af (),
300 .BR ruserok_af ()
301 T}      Thread safety   MT-Safe locale
305 .sp 1
306 .SH CONFORMING TO
307 Not in POSIX.1.
308 Present on the BSDs, Solaris, and many other systems.
309 These
310 functions appeared in
311 4.2BSD.
312 The "_af" variants are more recent additions,
313 and are not present on as wide a range of systems.
314 .SH BUGS
315 .BR iruserok ()
317 .BR iruserok_af ()
318 are declared in glibc headers only since version 2.12.
319 .\" Bug filed 25 Nov 2007:
320 .\" http://sources.redhat.com/bugzilla/show_bug.cgi?id=5399
321 .SH SEE ALSO
322 .BR rlogin (1),
323 .BR rsh (1),
324 .BR rexec (3),
325 .BR rexecd (8),
326 .BR rlogind (8),
327 .BR rshd (8)