HPUX rexec[3n]






 rexec(3N)                                                         rexec(3N)





 NAME
      rexec() - return stream to a remote command

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

 DESCRIPTION
      rexec() arranges for the remote execution of cmd on the host *ahost as
      user, who is authenticated with passwd.  It returns a file descriptor
      for the socket to which the standard input and standard output of cmd
      are attached.  A command-level interface to rexec() is provided by the
      rexec command (see remsh(1)).

      rexec() looks up host *ahost using gethostbyname() (see
      gethostbyname(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.  rexec() passes a username and password to the remote host
      for authentication.  These can be specified in the user and passwd
      parameters to rexec().  If either is NULL, rexec() searches for the
      appropriate information in the .netrc file (see netrc(4)) in the
      users's home directory.  If this fails, rexec() prompts the user for
      the remote user name and password, defaulting to the local user name
      and a NULL password.

      inport specifies which TCP port to use for the connection; it is
      normally the value returned by 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 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, 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.





 Hewlett-Packard Company            - 1 -     HP-UX Release 9.0: August 1992






 rexec(3N)                                                         rexec(3N)





 DIAGNOSTICS
      rexec() produces the following diagnostic messages:

      hostname: Unknown host
           The remote host name was not found by gethostbyname().

      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 the mode of .netrc (chmod 400 .netrc).

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

           Next step: Correct keyword in .netrc.





 Hewlett-Packard Company            - 2 -     HP-UX Release 9.0: August 1992






 rexec(3N)                                                         rexec(3N)





      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:...
           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 inetd is running.

 EXAMPLE
      To execute the date command on remote host hpxzgy using the remote
      account chm, rexec() could be used 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.



 Hewlett-Packard Company            - 3 -     HP-UX Release 9.0: August 1992






 rexec(3N)                                                         rexec(3N)





      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.

      The password is sent unencrypted through the socket connection.

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

 SEE ALSO
      remsh(1), rexecd(1M), gethostent(3N), getservent(3N), rcmd(3N),
      netrc(4).





































 Hewlett-Packard Company            - 4 -     HP-UX Release 9.0: August 1992