1RCMD(3)                    Linux Programmer's Manual                   RCMD(3)
2
3
4

NAME

6       rcmd, rresvport, iruserok, ruserok, rcmd_af, rresvport_af, iruserok_af,
7       ruserok_af - routines for returning a stream to a remote command
8

SYNOPSIS

10       #include <netdb.h>   /* Or <unistd.h> on some systems */
11
12       int rcmd(char **ahost, unsigned short 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, unsigned short 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(const void *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():
39           Since glibc 2.19:
40               _DEFAULT_SOURCE
41           Glibc 2.19 and earlier:
42               _BSD_SOURCE
43

DESCRIPTION

45       The  rcmd() function is used by the superuser to execute a command on a
46       remote machine using an authentication scheme based on privileged  port
47       numbers.   The  rresvport()  function  returns  a  file descriptor to a
48       socket with an address in the privileged port  space.   The  iruserok()
49       and  ruserok()  functions  are  used by servers to authenticate clients
50       requesting service with rcmd().  All four functions  are  used  by  the
51       rshd(8) server (among others).
52
53   rcmd()
54       The  rcmd()  function  looks up the host *ahost using gethostbyname(3),
55       returning -1 if the host does not exist.  Otherwise, *ahost is  set  to
56       the  standard  name  of  the  host and a connection is established to a
57       server residing at the well-known Internet port inport.
58
59       If the connection succeeds, a socket in the  Internet  domain  of  type
60       SOCK_STREAM  is returned to the caller, and given to the remote command
61       as stdin and stdout.  If fd2p is nonzero, then an auxiliary channel  to
62       a  control process will be set up, and a file descriptor for it will be
63       placed in *fd2p.  The control process  will  return  diagnostic  output
64       from  the  command (unit 2) on this channel, and will also accept bytes
65       on this channel as being UNIX signal numbers, to be  forwarded  to  the
66       process group of the command.  If fd2p is 0, then the stderr (unit 2 of
67       the remote command) will be made the same as the stdout and  no  provi‐
68       sion  is  made  for  sending  arbitrary  signals to the remote process,
69       although you may be able to get  its  attention  by  using  out-of-band
70       data.
71
72       The protocol is described in detail in rshd(8).
73
74   rresvport()
75       The  rresvport()  function is used to obtain a socket with a privileged
76       port bound to it.  This socket is suitable for use by rcmd()  and  sev‐
77       eral  other  functions.   Privileged  ports are those in the range 0 to
78       1023.  Only a privileged process (on Linux:  a  process  that  has  the
79       CAP_NET_BIND_SERVICE  capability  in  the  user namespace governing its
80       network namespace).  is allowed to bind to a privileged port.   In  the
81       glibc  implementation,  this function restricts its search to the ports
82       from 512 to 1023.  The port argument is value-result: the value it sup‐
83       plies  to  the call is used as the starting point for a circular search
84       of the port range; on (successful) return, it contains the port  number
85       that was bound to.
86
87   iruserok() and ruserok()
88       The  iruserok() and ruserok() functions take a remote host's IP address
89       or name, respectively, two usernames and a flag indicating whether  the
90       local  user's  name is that of the superuser.  Then, if the user is not
91       the superuser, it checks the /etc/hosts.equiv file.  If that lookup  is
92       not  done,  or  is  unsuccessful,  the .rhosts in the local user's home
93       directory is checked to see if the request for service is allowed.
94
95       If this file does not exist, is not a regular file, is owned by  anyone
96       other  than the user or the superuser, is writable by anyone other than
97       the owner, or is hardlinked anywhere, the  check  automatically  fails.
98       Zero is returned if the machine name is listed in the hosts.equiv file,
99       or the host and remote username are found in the .rhosts  file;  other‐
100       wise  iruserok()  and  ruserok()  return  -1.   If the local domain (as
101       obtained from gethostname(2)) is the same as the  remote  domain,  only
102       the machine name need be specified.
103
104       If  the  IP  address  of the remote host is known, iruserok() should be
105       used in preference to ruserok(), as it does not  require  trusting  the
106       DNS server for the remote host's domain.
107
108   *_af() variants
109       All  of the functions described above work with IPv4 (AF_INET) sockets.
110       The "_af" variants take  an  extra  argument  that  allows  the  socket
111       address  family  to be specified.  For these functions, the af argument
112       can be specified as AF_INET or AF_INET6.  In addition,  rcmd_af()  sup‐
113       ports the use of AF_UNSPEC.
114

RETURN VALUE

116       The  rcmd()  function returns a valid socket descriptor on success.  It
117       returns -1 on error and prints a diagnostic  message  on  the  standard
118       error.
119
120       The  rresvport()  function  returns a valid, bound socket descriptor on
121       success.  It returns -1 on  error  with  the  global  value  errno  set
122       according  to  the  reason for failure.  The error code EAGAIN is over‐
123       loaded to mean "All network ports in use."
124
125       For information on the return from ruserok() and iruserok(), see above.
126

VERSIONS

128       The   functions   iruserok_af(),   rcmd_af(),    rresvport_af(),    and
129       ruserok_af() functions are provide in glibc since version 2.2.
130

ATTRIBUTES

132       For   an   explanation   of   the  terms  used  in  this  section,  see
133       attributes(7).
134
135       ┌────────────────────────────┬───────────────┬────────────────┐
136Interface                   Attribute     Value          
137       ├────────────────────────────┼───────────────┼────────────────┤
138rcmd(), rcmd_af()           │ Thread safety │ MT-Unsafe      │
139       ├────────────────────────────┼───────────────┼────────────────┤
140rresvport(), rresvport_af() │ Thread safety │ MT-Safe        │
141       ├────────────────────────────┼───────────────┼────────────────┤
142iruserok(), ruserok(),      │ Thread safety │ MT-Safe locale │
143iruserok_af(), ruserok_af() │               │                │
144       └────────────────────────────┴───────────────┴────────────────┘
145

CONFORMING TO

147       Not in POSIX.1.  Present on the BSDs, Solaris, and many other  systems.
148       These functions appeared in 4.2BSD.  The "_af" variants are more recent
149       additions, and are not present on as wide a range of systems.
150

BUGS

152       iruserok() and iruserok_af() are declared in glibc headers  only  since
153       version 2.12.
154

SEE ALSO

156       rlogin(1), rsh(1), intro(2), rexec(3), rexecd(8), rlogind(8), rshd(8)
157

COLOPHON

159       This  page  is  part of release 5.07 of the Linux man-pages project.  A
160       description of the project, information about reporting bugs,  and  the
161       latest     version     of     this    page,    can    be    found    at
162       https://www.kernel.org/doc/man-pages/.
163
164
165
166Linux                             2017-09-15                           RCMD(3)
Impressum