Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
HP-UX Reference > R

rexec(3N)

HP-UX 11i Version 3: February 2007
» 

Technical documentation

» Feedback
Content starts here

 » Table of Contents

 » Index

NAME

rexec(), rexec_af() — return stream to a remote command

SYNOPSIS

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

int rexec_af(char **ahost, int inport, const char *user, const char *passwd, const char *cmd, int *fd2p, int af);

DESCRIPTION

The rexec() routine performs the necessary tasks to arrange for the remote execution of cmd on the remote host *ahost as user, who is authenticated with passwd. Upon completion of authentication, a file descriptor is returned for the socket to which standard input and standard output of cmd are attached. A command-level interface to rexec() is provided by the rexec command (see remsh(1)).

When invoked, rexec() looks up host *ahost using gethostbyname() (see gethostent(3N)) and returns -1 if the host does not exist. The host name can be either the official name or an alias. If the gethostbyname() call succeeds, *ahost is set to the standard name of the host. Next, rexec() passes a user name and password to the remote host for authentication, as specified in the user and passwd parameters to rexec(). If either user or passwd are NULL, rexec() searches for the appropriate information in the .netrc file (see netrc(4)) in the user's home directory. If no user or passwd are found, rexec() prompts the user for the remote user name and password, defaulting to the local user name and a NULL password.

The inport variable specifies which TCP port to use for the connection; it is normally the value returned by the following call to getservbyname:

getservbyname("exec", "tcp")

(see getservent(3N)). The protocol used by rexec() 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 connection to a socket is denied after five tries, or for some other reason (other than the port is in use), rexec() returns -1. If fd2p is non-zero, 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, interpreting them as UNIX signal numbers to be forwarded to the process group of the command. If the auxiliary port cannot be set up, rexec() returns -1. If fd2p is 0, stderr of the remote command is made the same as stdout and no provision is made for sending arbitrary signals to the remote process.

The rexec_af() routine is similar to the rexec() routine except for the additional parameter af. The af parameter in the rexec_af() routine can be used to specify an AF_INET6 TCP socket or an AF_INET TCP socket. If the address family specified in the af argument is not supported, rexec_af() fails with the following error code: EAFNOSUPPORT.

DIAGNOTISCS

When invoked, rexec() produces the following diagnostic messages:

hostname: Unknown host

  • The remote host name was not found by gethostbyname().

system call: message

  • Error in executing the system call. The message specifies the cause of the failure.

connect: hostname: message

  • Error in connecting to the socket obtained for rexec(). The message specifies the cause of the failure.

Secondary socket: message

  • Error in creating a secondary socket for error transmission to be used by rexec().

read: hostname: message

  • Error in reading information transmitted over the socket. The message specifies the cause of the failure.

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: message

  • 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 someone other than the owner.

  • Next step: Check whether .netrc has been modified by someone else and change the mode of .netrc (chmod 400 .netrc).

Unknown .netrc option keyword

  • An unrecognized keyword has been found in .netrc (see netrc(4)).

  • Next step: Correct the 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 an inetd security failure (see inetd(1M)).

recv: 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 time out.

  • Next step: Repeat the command. If a timeout occurs, check whether the Internet Services are installed and inetd is running.

EXAMPLES

To execute the date command on remote host hpxzgy using the remote account chm, rexec() is invoked 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

There is no way to specify options to the socket() call that rexec() makes.

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

Since rexec() replaces the pointer to the host name (*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.

The password is sent unencrypted through the socket connection.

AUTHOR

rexec() was developed by the University of California, Berkeley.

Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© 1983-2007 Hewlett-Packard Development Company, L.P.