1RCMD(3) Linux Programmer's Manual RCMD(3)
2
3
4
6 rcmd, rresvport, iruserok, ruserok, rcmd_af, rresvport_af, iruserok_af,
7 ruserok_af - routines for returning a stream to a remote command
8
10 #include <netdb.h> /* Or <unistd.h> on some systems */
11
12 int rcmd(char **ahost, int inport, const char *locuser,
13 const char *remuser, const char *cmd, int *fd2p);
14
15 int rresvport(int *port);
16
17 int iruserok(uint32_t raddr, int superuser,
18 const char *ruser, const char *luser);
19
20 int ruserok(const char *rhost, int superuser,
21 const char *ruser, const char *luser);
22
23 int rcmd_af(char **ahost, int inport, const char *locuser,
24 const char *remuser, const char *cmd, int *fd2p,
25 sa_family_t af);
26
27 int rresvport_af(int *port, sa_family_t af);
28
29 int iruserok_af(uint32_t raddr, int superuser,
30 const char *ruser, const char *luser, sa_family_t af);
31
32 int ruserok_af(const char *rhost, int superuser,
33 const char *ruser, const char *luser, sa_family_t af);
34
35 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
36
37 rcmd(), rcmd_af(), rresvport(), rresvport_af(), iruserok(),
38 iruserok_af(), ruserok(), ruserok_af(): _BSD_SOURCE
39
41 The rcmd() function is used by the superuser to execute a command on a
42 remote machine using an authentication scheme based on privileged port
43 numbers. The rresvport() function returns a descriptor to a socket
44 with an address in the privileged port space. The iruserok() and
45 ruserok() functions are used by servers to authenticate clients
46 requesting service with rcmd(). All four functions are used by the
47 rshd(8) server (among others).
48
49 rcmd()
50 The rcmd() function looks up the host *ahost using gethostbyname(3),
51 returning -1 if the host does not exist. Otherwise *ahost is set to
52 the standard name of the host and a connection is established to a
53 server residing at the well-known Internet port inport.
54
55 If the connection succeeds, a socket in the Internet domain of type
56 SOCK_STREAM is returned to the caller, and given to the remote command
57 as stdin and stdout. If fd2p is nonzero, then an auxiliary channel to
58 a control process will be set up, and a descriptor for it will be
59 placed in *fd2p. The control process will return diagnostic output
60 from the command (unit 2) on this channel, and will also accept bytes
61 on this channel as being UNIX signal numbers, to be forwarded to the
62 process group of the command. If fd2p is 0, then the stderr (unit 2 of
63 the remote command) will be made the same as the stdout and no provi‐
64 sion is made for sending arbitrary signals to the remote process,
65 although you may be able to get its attention by using out-of-band
66 data.
67
68 The protocol is described in detail in rshd(8).
69
70 rresvport()
71 The rresvport() function is used to obtain a socket with a privileged
72 port bound to it. This socket is suitable for use by rcmd() and sev‐
73 eral other functions. Privileged ports are those in the range 0 to
74 1023. Only a privileged process (CAP_NET_BIND_SERVICE) is allowed to
75 bind to a privileged port. In the glibc implementation, this function
76 restricts its search to the ports from 512 to 1023. The port argument
77 is value-result: the value it supplies to the call is used as the
78 starting point for a circular search of the port range; on (successful)
79 return, it contains the port number that was bound to.
80
81 iruserok() and ruserok()
82 The iruserok() and ruserok() functions take a remote host's IP address
83 or name, respectively, two usernames and a flag indicating whether the
84 local user's name is that of the superuser. Then, if the user is not
85 the superuser, it checks the /etc/hosts.equiv file. If that lookup is
86 not done, or is unsuccessful, the .rhosts in the local user's home
87 directory is checked to see if the request for service is allowed.
88
89 If this file does not exist, is not a regular file, is owned by anyone
90 other than the user or the superuser, or is writable by anyone other
91 than the owner, the check automatically fails. Zero is returned if the
92 machine name is listed in the hosts.equiv file, or the host and remote
93 username are found in the .rhosts file; otherwise iruserok() and
94 ruserok() return -1. If the local domain (as obtained from gethost‐
95 name(2)) is the same as the remote domain, only the machine name need
96 be specified.
97
98 If the IP address of the remote host is known, iruserok() should be
99 used in preference to ruserok(), as it does not require trusting the
100 DNS server for the remote host's domain.
101
102 *_af() variants
103 All of the functions described above work with IPv4 (AF_INET) sockets.
104 The "_af" variants take an extra argument that allows the socket
105 address family to be specified. For these functions, the af argument
106 can be specified as AF_INET or AF_INET6. In addition, rcmd_af() sup‐
107 ports the use of AF_UNSPEC.
108
110 The rcmd() function returns a valid socket descriptor on success. It
111 returns -1 on error and prints a diagnostic message on the standard
112 error.
113
114 The rresvport() function returns a valid, bound socket descriptor on
115 success. It returns -1 on error with the global value errno set
116 according to the reason for failure. The error code EAGAIN is over‐
117 loaded to mean "All network ports in use."
118
119 For information on the return from ruserok() and iruserok(), see above.
120
122 The functions iruserok_af(), rcmd_af(), rresvport_af(), and
123 ruserok_af() functions are provide in glibc since version 2.2.
124
126 Not in POSIX.1-2001. Present on the BSDs, Solaris, and many other sys‐
127 tems. These functions appeared in 4.2BSD. The "_af" variants are more
128 recent additions, and are not present on as wide a range of systems.
129
131 iruserok() and iruserok_af() are declared in glibc headers only since
132 version 2.12.
133
135 rlogin(1), rsh(1), intro(2), rexec(3), rexecd(8), rlogind(8), rshd(8)
136
138 This page is part of release 3.53 of the Linux man-pages project. A
139 description of the project, and information about reporting bugs, can
140 be found at http://www.kernel.org/doc/man-pages/.
141
142
143
144Linux 2012-04-23 RCMD(3)