rcmd_af Subroutine

Purpose

Allows execution of commands on a remote host.

Syntax

int rcmd_af(char **ahost, unsigned short rport,
                  const char *locuser, const char *remuser,
                  const char *cmd, int *fd2p, int af)

Description

The rcmd_af subroutine allows execution of certain commands on a remote host that supports rshd, rlogin, and rpc among others. It behaves the same as the existing rcmd() function, but instead of creating only an AF_INET TCP socket, it can also create an AF_INET6 TCP socket. The existing rcmd() function cannot transparently use AF_INET6 sockets because an application would not be prepared to handle AF_INET6 addresses returned by subroutines such as getpeername() on the file descriptor created by rcmd().

Only processes with an effective user ID of root user can use the rcmd_af subroutine. An authentication scheme based on remote port numbers is used to verify permissions. Ports in the range between 0 and 1023 can only be used by a root user.

The rcmd_af subroutine looks up a host by way of the name server or if the local name server is not running, in the /etc/hosts file.

If the connection succeeds, a socket in the Internet domain of type SOCK_STREAM is returned to the calling process and given to the remote command as standard input (stdin) and standard output (stdout).

Always specify the ahost parameter. If the local domain and remote domain are the same, specifying the domain parts is optional.

Parameters

Item Description
ahost Specifies the name of a remote host that is listed in the /etc/hosts file. If the specified name of the host is not found in this file, the rcmd_af subroutine is unsuccessful.
rport Specifies the well-known port to use for the connection. The /etc/services file contains the DARPA Internet services, their ports, and socket types.
locuser Points to user names that are valid at the local host. Any valid user name can be given.
remuser Points to user names that are valid at the remote host. Any valid user name can be given.
cmd Specifies the name of the command to be started at the remote host.
fd2p Specifies an integer controlling the set up of communication channels. Integer options are as follows:
Non-zero
Indicates an auxiliary channel to a control process is set up, and the fd2p parameter points to the file descriptor for the channel. The control process provides diagnostic output from the remote command on this channel and also accepts bytes as signal numbers to be forwarded to the process group of the command.
0
Indicates the standard error (stderr) of the remote command is the same as standard output (stdout). No provision is made for sending arbitrary signals to the remote process. However, it is possible to send out-of-band data to the remote command.
af The family argument is AF_INET, AF_INET6, or AF_UNSPEC. When either AF_INET or AF_INET6 is specified, this function will create a socket of the specified address family. When AF_UNSPEC is specified, it will try all possible address families until a connection can be established, and will return the associated socket of the connection.

Return Values

Upon successful completion, the rcmd_af subroutine returns a valid socket descriptor. Upon unsuccessful completion, the rcmd_af subroutine returns a value of –1. The subroutine returns a –1 if the effective user ID of the calling process is not the root user or if the subroutine is unsuccessful to resolve the host.

Files

Item Description
/etc/services Contains the service names, ports, and socket type.
/etc/hosts Contains host names and their addresses for hosts in a network.
/etc/resolv.conf Contains the name server and domain name.