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