The Remote Command protocol enables an application to execute
commands on a server, with the output of the command returned to
the client. The SocketTools library actually implements three related
protocols: rexec, rshell and rlogin. The choice of protocols is
determined by the port that is selected when a connection is
established.
Rexec
The rexec protocol enables a client application to execute a
command on a server. Output from the command is returned to the
client and the connection is closed when the command terminates. The
client connects on port 512 and must provide a user name and password
to authenticate the session.
Rshell
The rshell protocol is similar to rexec in that it enables a client
to execute a command on a server. Output from the command is
returned to the client and the connection is closed when the command
terminates. The client connects on port 514 and must provide a user
name. The primary difference between the rexec and rshell protocols
is that rshell does not require a password. Instead, it uses what is
called "host equivalence" to determine if the client is
permitted to execute commands as that user. On a UNIX based operating
system, host equivalence is controlled by the /etc/hosts.equiv and
the .rhosts file in the user's home directory. These files list the
host names and user names which are permitted to execute commands
using the rshell protocol. Consult your operating system manual pages
for more information about how to configure host equivalence.
Rlogin
The rlogin protocol is similar to Telnet in that it provides an
interactive terminal session. The connection is closed when the user
logs out or the shell process on the server is terminated. The
client connects on port 513 and must provide a user name and terminal
type. If there is an entry in the host equivalence tables for the
user and local host, then the client will be automatically logged in
and provided with a shell prompt. If there is no host equivalence,
the client will be prompted for a password. The terminal emulation
library can be used to provide ANSI or DEC VT-220 emulation services
if needed.
An important consideration when deciding whether to use rexec,
rshell or rlogin is how the server is configured and the type of
command being executed. If there is no entry for the local host in the
server's host equivalence tables, then the rexec command should be used
instead of rshell.
When using rexec or rshell, it is important to keep in mind that
although the command is executed with the privileges of the specified
user, that user is not actually logged in. The user's login script is
not executed and the program will not inherit the user's normal
environment as it would during an interactive session. If you are
connecting to a UNIX system, you should not attempt to execute programs
which try to put standard input into raw mode; an example of this would
be the vi editor. If you are connecting to a Windows system, you should
not execute a program which uses a graphical interface. Only programs
which read standard input and write to standard output are suitable for
use with rexec or rshell.
The first step that your application must take is to initialize the
library and then establish a connection. The following functions are
available for use by your application:
RshInitialize
Initialize the library and load the Windows Sockets library for the
current process. This must be the first function call that the
application makes before calling the other Remote Command API
functions.
RshExecute
Execute the specified command on the server. The rshell or rexec
protocol is selected based on the port number that is specified.
Output from the command will be returned to the client to be read.
When the command terminates, the connection to the server will be
closed.
RshLogin
Establish an interactive login session which is similar to how the
Telnet protocol works. If there is no host equivalence with the local
host, you will be prompted for a password. Output from the session
will be returned to the client, and when the client logs out the
connection will be closed.
RshRead
Read the output generated by the command. Your application would
typically call this function in a loop until all of the data has been
read or an error occurs.
RshSearch
Search for a specific sequence of characters in the output returned
by the server. The function returns when the sequence is
encountered or when a timeout occurs. The data captured up to the
point where the character sequence was matched is returned to the
caller for processing.
RshDisconnect
Disconnect from the server and release the memory allocated for that
client session. After this function is called, the client handle is
no longer valid.
RshUninitialize
Unload the Windows Sockets library and release any resources that
have been allocated for the current process. This is the last
function call that the application should make prior to
terminating.
|