document conditions wherein ruserok will fail
[unix-history] / usr / src / lib / libc / net / rcmd.3
CommitLineData
d20a1e6f
KB
1.\" Copyright (c) 1983 The Regents of the University of California.
2.\" All rights reserved.
11a95b5f 3.\"
d20a1e6f
KB
4.\" Redistribution and use in source and binary forms are permitted
5.\" provided that the above copyright notice and this paragraph are
6.\" duplicated in all such forms and that any documentation,
7.\" advertising materials, and other materials related to such
8.\" distribution and use acknowledge that the software was developed
9.\" by the University of California, Berkeley. The name of the
10.\" University may not be used to endorse or promote products derived
11.\" from this software without specific prior written permission.
12.\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
13.\" IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
14.\" WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
15.\"
16.\" @(#)rcmd.3 6.9 (Berkeley) %G%
11a95b5f 17.\"
0609943c 18.TH RCMD 3 ""
11a95b5f
KM
19.UC 5
20.SH NAME
21rcmd, rresvport, ruserok \- routines for returning a stream to a remote command
22.SH SYNOPSIS
23.nf
4fb1c171 24.PP
11a95b5f
KM
25.B "rem = rcmd(ahost, inport, locuser, remuser, cmd, fd2p);"
26.B char **ahost;
f3f0480d 27.B int inport;
11a95b5f
KM
28.B "char *locuser, *remuser, *cmd;"
29.B int *fd2p;
30.PP
31.B s = rresvport(port);
32.B int *port;
33.PP
34.B "ruserok(rhost, superuser, ruser, luser);"
35.B char *rhost;
36.B int superuser;
37.B char *ruser, *luser;
38.fi
39.SH DESCRIPTION
40.I Rcmd
41is a routine used by the super-user to execute a command on
42a remote machine using an authentication scheme based
43on reserved port numbers.
44.I Rresvport
45is a routine which returns a descriptor to a socket
46with an address in the privileged port space.
47.I Ruserok
48is a routine used by servers
49to authenticate clients requesting service with
50.IR rcmd .
51All three functions are present in the same file and are used
52by the
d20a1e6f 53.IR rshd (8)
11a95b5f
KM
54server (among others).
55.PP
56.I Rcmd
57looks up the host
58.I *ahost
59using
d20a1e6f 60.IR gethostbyname (3),
11a95b5f
KM
61returning \-1 if the host does not exist.
62Otherwise
63.I *ahost
64is set to the standard name of the host
65and a connection is established to a server
66residing at the well-known Internet port
67.IR inport .
68.PP
7faf4e1f
MK
69If the connection succeeds,
70a socket in the Internet domain of type SOCK_STREAM
11a95b5f
KM
71is returned to the caller, and given to the remote
72command as
73.B stdin
74and
75.BR stdout .
76If
77.I fd2p
78is non-zero, then an auxiliary channel to a control
79process will be set up, and a descriptor for it will be placed
80in
81.IR *fd2p .
82The control process will return diagnostic
83output from the command (unit 2) on this channel, and will also
84accept bytes on this channel as being UNIX signal numbers, to be
85forwarded to the process group of the command.
86If
87.I fd2p
88is 0, then the
89.B stderr
90(unit 2 of the remote
91command) will be made the same as the
92.B stdout
93and no
94provision is made for sending arbitrary signals to the remote process,
95although you may be able to get its attention by using out-of-band data.
96.PP
97The protocol is described in detail in
d20a1e6f 98.IR rshd (8).
11a95b5f
KM
99.PP
100The
101.I rresvport
102routine is used to obtain a socket with a privileged
103address bound to it. This socket is suitable for use
104by
105.I rcmd
7faf4e1f
MK
106and several other routines. Privileged Internet ports are those
107in the range 0 to 1023. Only the super-user
11a95b5f
KM
108is allowed to bind an address of this sort to a socket.
109.PP
110.I Ruserok
d20a1e6f
KB
111takes a remote host's name, as returned by the
112.IR gethostbyaddr (3)
7faf4e1f 113routine, two user names and a flag indicating whether
d20a1e6f
KB
114the local user's name is that of the super-user. Then,
115if the user is
116.B NOT
117the super-user, it checks the files
118.IR /etc/hosts.equiv .
119If that lookup is not done, or is unsuccessful, the
11a95b5f 120.I .rhosts
d20a1e6f
KB
121in the local user's home directory is checked to see if the request for
122service is allowed. If this file is owned by anyone other than the
123user or the super-user, or if it is writeable by anyone other than the
124owner, the check automatically fails. A 0 is returned if the machine
125name is listed in the ``hosts.equiv'' file, or the host and remote
126user name are found in the ``.rhosts'' file; otherwise
11a95b5f 127.I ruserok
d20a1e6f 128returns \-1.
0609943c
MK
129If the local domain (as obtained from \fIgethostname\fP\|(2))
130is the same as the remote domain, only the machine name need be specified.
11a95b5f 131.SH SEE ALSO
d20a1e6f 132rlogin(1), rsh(1), intro(2), rexec(3), rexecd(8), rlogind(8), rshd(8)
7faf4e1f
MK
133.SH DIAGNOSTICS
134.I Rcmd
135returns a valid socket descriptor on success.
136It returns -1 on error and prints a diagnostic message on the standard error.
137.PP
138.I Rresvport
139returns a valid, bound socket descriptor on success.
140It returns -1 on error with the global value
141.I errno
142set according to the reason for failure.
143The error code EAGAIN is overloaded to mean ``All network ports in use.''