rcmd()

execute a command on a remote host

Synopsis:

#include <unix.h>

int rcmd( char **ahost, 
          u_short_t inport,
          const char *locuser,
          const char *remuser,
          const char *cmd, 
          int *fd2p );

Description:

The rcmd() function is used by the superuser to execute a command, cmd, on a remote machine using an authentication scheme based on reserved port numbers. This rcmd(), rresvport(), and ruserok() are used by the rshd server, among others.

The rcmd() function looks up the host *ahost by means of gethostbyname(), and returns -1 if the host doesn't exist. Otherwise, *ahost is set to the standard name of the host and a connection is established to a server residing at the well-known Internet port inport.

The locuser and remuser arguments are the user IDs on the local and remote machines.

If the connection succeeds, a SOCK_STREAM socket in the Internet domain is returned to the caller and given to the remote command as standard input and standard output.

If fd2p is: Then:
nonzero an auxiliary channel to a control process is set up, and a descriptor for it is placed in *fd2p. The control process will return diagnostic output from the command (unit 2) on this channel and will accept bytes as signal numbers to be forwarded to the command's process group.
zero the standard error (unit 2 of the remote command) is made the same as the standard output and no provision is made for sending arbitrary signals to the remote process (although you may be able to get its attention by using out-of-band data).

The protocol is described in detail in rshd in the TCP/IP User's Guide.

Returns:

A valid socket descriptor. If an error occurs, -1 is returned and a message is printed to standard error.

Errors:

The error code EAGAIN is overloaded to mean ``All network ports in use.''

Classification:

UNIX

Safety:
Interrupt handler No
Signal handler No
Thread No

See also:

rresvport(), ruserok()

rexecd, rlogin, rlogind, rsh, rshd in the TCP/IP User's Guide