Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ rexec(3X) — HP-UX 6.20

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

rexecd(1M)

getservent(3N)

rcmd(3X)

netrc(4)

REXEC(3X)  —  Series 300 and 800 Only

NAME

rexec − return stream to a remote command

SYNOPSIS

int rem;
rem = rexec(ahost, inport, user, passwd, cmd, fd2p);
char **ahost;
int inport;
char *user, *passwd, *cmd;
int *fd2p;

DESCRIPTION

Rexec looks up the host ∗ahost using gethostbyname(3N) and returns −1 if the host does not exist. The host name can be either the official name or an alias as listed in /etc/hosts; see hosts(4). If the gethostbyname(3n) call succeeds, ∗ahost is set to the standard name of the host.  If a username and password are both specified, then these are used to authenticate the foreign host; otherwise the user’s .netrc (see netrc(4)) file in his home directory is searched for the appropriate information. If all this fails, the user is prompted for the information. When the user is prompted for the information, the default used for the remote user name is the local user name and the default password is no password.

The port inport specifies which DARPA internet port to use for the connection; it is normally the value returned from the call getservbyname("exec", "tcp") (see getservent(3N)). The protocol for connection is described in detail in rexecd(1M).

If the call succeeds, a socket of type SOCK_STREAM is returned to the caller, and given to the remote command as stdin and stdout.  If the connection to the socket is refused after five tries, or if it was refused for a reason other than the port being in use, then rexec returns −1.  If fd2p is non-zero, then an auxiliary connection to a control process is set up, and a file descriptor for it is placed in ∗fd2p. The control process returns diagnostic output from the command on this connection and accepts bytes on this connection as being UNIX signal numbers to be forwarded to the process group of the command. If the auxiliary port cannot be set up, then rexec returns −1.  If fd2p is 0, then stderr of the remote command is made the same as stdout and no provision is made for sending arbitrary signals to the remote process. 

Note: There is no way to specify options to the socket call which rexec makes. 

DIAGNOSTICS

The diagnostic messages for rexec are the following:

<hostname>: Unknown host
Remote host name not found in /etc/hosts. 

<system call>:... 
Error in executing the system call. A message specifying the cause of the failure is appended to this message.

connect: <hostname>:... 
Error in connecting to the socket obtained for rexec. A message specifying the cause of the failure is appended to this diagnostic.

Secondary socket:... 
Error in creating a secondary socket for error transmission to be used by rexec.

read: <hostname>:... 
Error in reading information transmitted over the socket. A message specifying the cause of the failure is appended to this diagnostic.

Connection timeout
The remote host did not connect within 30 seconds to the secondary socket set up as an error connection.

Lost connection
The program attempts to read from the socket and fails. This means the socket connection with the remote host was lost.

.netrc:... 
Error in opening .netrc file in the home directory for a reason other than the file not existing. 

Error- .netrc file not correct mode.  Remove password or correct mode. 

The .netrc file is readable, writable or executable by anyone other than the user. 
 
Next step: Check whether .netrc has been modified by someone else and change mode of .netrc ( chmod 400 .netrc ). 

Unknown .netrc option ... 
A keyword not recognized has been found in .netrc (see netrc(4)).
 
Next step: Correct keyword in .netrc. 

primary connection shutdown
While waiting for the secondary socket to be set up, rexec had its primary connection shut down.  This may have been caused by the inetd security failure. 

recv: <system error message>
While trying to set up the secondary ( stderr) socket, rexec had an error condition on its primary connection. 

accept:  Interrupted system call
While trying to set up a secondary socket, rexec ran out of a resource, which caused the accept to be timed out. 
 
Next step: Repeat the command. If a timeout occurs, check whether the ARPA Services are installed and the inetd is running. 

EXAMPLE

To execute the command date on the remote host “hpxzgy” using the remote account “chm”, you can use rexec as follows:

#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>
char *host[] = { "hpxzgy" };
char *user = "chm";
char *passwd = "password";
char *cmd = "date";
main(argc, argv)
char **argv;
int argc;
{
char ch;
struct servent *servent;
FILE *fp;
int sd;
servent = getservbyname("exec", "tcp");
sd = rexec(host, servent->s_port, user, passwd, cmd, 0);
fp = fdopen(sd, "r");
while ((ch = getc(fp)) != EOF)
putchar(ch);
}

 

WARNINGS

A program using rexec should not be put in the background when rexec is expected to prompt for a password or user name.  If it is put in the background it will compete with the shell for input. 

Since rexec replaces the pointer to the hostname (*ahost) with a pointer to the standard name of the host in a static data area, this value must be copied into the user’s data area if it is to be used later. 

DEPENDENCIES

Implemented on the Series 300 and 800 only. 

AUTHOR

UCB (University of California at Berkeley)

SEE ALSO

rexecd(1M), getservent(3N), rcmd(3X), netrc(4). 
 

Hewlett-Packard Company  —  May 11, 2021

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026