5373 connect(3SOCKET) could talk about non-blocking mode
[unleashed.git] / usr / src / man / man3socket / rcmd.3socket
blobcd9517a569f258e4d651acacc2856b7615986aa1
1 '\" te
2 .\"  Copyright (c) 1983 Regents of the University of California.  All rights reserved.  The Berkeley software License Agreement  specifies the terms and conditions for redistribution.
3 .\" Copyright (C) 2004, Sun Microsystems, Inc. All Rights Reserved
4 .TH RCMD 3SOCKET "Feb 10, 2004"
5 .SH NAME
6 rcmd, rcmd_af, rresvport, rresvport_af, ruserok \- routines for returning a
7 stream to a remote command
8 .SH SYNOPSIS
9 .LP
10 .nf
11 \fBcc\fR [ \fIflag\fR ... ] \fIfile\fR... \fB-lsocket\fR \fB -lnsl \fR [ \fIlibrary\fR... ]
12 #include <netdb.h>
13 #include <unistd.h>
15 \fBint\fR \fBrcmd\fR(\fBchar **\fR\fIahost\fR, \fBunsigned short\fR \fIinport\fR, \fBconst char *\fR\fIluser\fR,
16      \fBconst char *\fR\fIruser\fR, \fBconst char *\fR\fIcmd\fR, \fBint *\fR\fIfd2p\fR);
17 .fi
19 .LP
20 .nf
21 \fBint\fR \fBrcmd_af\fR(\fBchar **\fR\fIahost\fR, \fBunsigned short\fR \fIinport\fR, \fBconst char *\fR\fIluser\fR,
22      \fBconst char *\fR\fIruser\fR, \fBconst char *\fR\fIcmd\fR, \fBint *\fR\fIfd2p\fR, \fBint\fR \fIaf\fR);
23 .fi
25 .LP
26 .nf
27 \fBint\fR \fBrresvport\fR(\fBint *\fR\fIport\fR);
28 .fi
30 .LP
31 .nf
32 \fBint\fR \fBrresvport_af\fR(\fBint *\fR\fIport\fR, \fBint\fR \fIaf\fR);
33 .fi
35 .LP
36 .nf
37 \fBint\fR \fBruserok\fR(\fBconst char *\fR\fIrhost\fR, \fBint\fR \fIsuser\fR, \fBconst char *\fR\fIruser\fR,
38      \fBconst char *\fR\fIluser\fR);
39 .fi
41 .SH DESCRIPTION
42 .sp
43 .LP
44 The \fBrcmd()\fR function is used by the superuser to execute a command on a
45 remote machine with an authentication scheme based on reserved port numbers. An
46 \fBAF_INET\fR socket is returned with \fBrcmd()\fR. The \fBrcmd_af()\fR
47 function supports \fBAF_INET\fR, \fBAF_INET6\fR or \fBAF_UNSPEC\fR for the
48 address family. An application can choose which type of socket is returned by
49 passing \fBAF_INET\fR or \fBAF_INET6\fR as the address family. The use of
50 \fBAF_UNSPEC\fR means that the caller will accept any address family. Choosing
51 \fBAF_UNSPEC\fR provides a socket that best suits the connectivity to the
52 remote host.
53 .sp
54 .LP
55 The \fBrresvport()\fR function returns a descriptor to a socket with an address
56 in the privileged port space. The \fBrresvport_af()\fR function is the
57 equivalent to \fBrresvport()\fR, except that you can choose \fBAF_INET\fR or
58 \fBAF_INET6\fR as the socket address family to be returned by
59 \fBrresvport_af()\fR. \fBAF_UNSPEC\fR does not apply to the \fBrresvport()\fR
60 function.
61 .sp
62 .LP
63 The \fBruserok()\fR function is a routine used by servers to authenticate
64 clients that request as service with \fBrcmd\fR.
65 .sp
66 .LP
67 All of these functions are present in the same file and are used by the
68 \fBin.rshd\fR(1M) server among others.
69 .sp
70 .LP
71 The \fBrcmd()\fR and \fBrcmd_af()\fR functions look up the host \fI*ahost\fR
72 using \fBgetaddrinfo\fR(3SOCKET) and return \fB\(mi1\fR if the host does not
73 exist. Otherwise, *\fIahost\fR is set to the standard name of the host and a
74 connection is established to a server residing at the Internet port
75 \fIinport\fR.
76 .sp
77 .LP
78 If the connection succeeds, a socket in the Internet domain of type
79 \fBSOCK_STREAM\fR is returned to the caller. The socket is given to the remote
80 command as standard input (file descriptor 0) and standard output (file
81 descriptor 1). If \fIfd2p\fR is non-zero, an auxiliary channel to a control
82 process is set up and a descriptor for it is placed in \fI*fd2p\fR. The control
83 process returns diagnostic output file (descriptor 2) from the command on the
84 auxiliary channel. The control process also accepts bytes on this channel as
85 signal numbers to be forwarded to the process group of the command. If
86 \fIfd2p\fR is 0, the standard error (file descriptor 2) of the remote command
87 is made the same as its standard output. No provision is made for sending
88 arbitrary signals to the remote process, other than possibly sending
89 out-of-band data.
90 .sp
91 .LP
92 The protocol is described in detail in \fBin.rshd\fR(1M).
93 .sp
94 .LP
95 The \fBrresvport()\fR and \fBrresvport_af()\fR functions are used to obtain a
96 socket bound to a privileged port number. The socket is suitable for use by
97 \fBrcmd()\fR and \fBrresvport_af()\fR and several other routines. Privileged
98 Internet ports are those in the range 1 to 1023. Only the superuser is allowed
99 to bind a socket to a privileged port number. The application must pass in
100 \fIport\fR, which must be in the range 512 to 1023. The system first tries to
101 bind to that port number.  If it fails, the system then tries to bind to
102 another unused privileged port, if one is available.
105 The \fBruserok()\fR function takes a remote host name returned by the
106 \fBgethostbyaddr()\fR function with two user names and a flag to indicate
107 whether the local user's name is that of the superuser. See
108 \fBgethostbyname\fR(3NSL). The \fBruserok()\fR function then checks the files
109 \fB/etc/hosts.equiv\fR and possibly \fB\&.rhosts\fR in the local user's home
110 directory to see if the request for service is allowed. A \fB0\fR value is
111 returned if the machine name is listed in the \fB/etc/hosts.equiv\fR file, or
112 if the host and remote user name are found in the \fB\&.rhosts\fR file.
113 Otherwise, the \fBruserok()\fR function returns \fB\(mi1\fR\&. If the superuser
114 flag is \fB1\fR, the \fB/etc/hosts.equiv\fR is not checked.
117 The error code \fBEAGAIN\fR is overloaded to mean "All network ports in use."
118 .SH RETURN VALUES
121 The \fBrcmd()\fR and \fBrcmd_af()\fR functions return a valid socket descriptor
122 upon success. The functions returns \fB\(mi1\fR upon error and print a
123 diagnostic message to standard error.
126 The \fBrresvport()\fR and \fBrresvport_af()\fR functions return a valid, bound
127 socket descriptor upon success. The functions return \fB\(mi1\fR upon error
128 with the global value \fIerrno\fR set according to the reason for failure.
129 .SH FILES
131 .ne 2
133 \fB\fB/etc/hosts.equiv\fR\fR
135 .RS 20n
136 system trusted hosts and users
140 .ne 2
142 \fB\fB~/.rhosts\fR\fR
144 .RS 20n
145 user's trusted hosts and users
148 .SH ATTRIBUTES
151 See \fBattributes\fR(5) for descriptions of the following attributes:
156 box;
157 c | c
158 l | l .
159 ATTRIBUTE TYPE  ATTRIBUTE VALUE
161 MT-Level        Unsafe
166 This interface is Unsafe in multithreaded applications. Unsafe interfaces
167 should be called only from the main thread.
168 .SH SEE ALSO
171 \fBrlogin\fR(1), \fBrsh\fR(1), \fBin.rexecd\fR(1M), \fBin.rshd\fR(1M),
172 \fBIntro\fR(2), \fBgetaddrinfo\fR(3SOCKET), \fBgethostbyname\fR(3NSL),
173 \fBrexec\fR(3SOCKET), \fBattributes\fR(5)