afd3af2308da9f6079fd37eadd3a73dcef97306a
static char sccsid
[] = "@(#)rcmd.c 4.5 %G%";
char *index(), *sprintf();
rcmd(ahost
, rport
, locuser
, remuser
, cmd
, fd2p
)
char *locuser
, *remuser
, *cmd
;
struct sockaddr_in sin
, sin2
, from
;
int lport
= IPPORT_RESERVED
- 1;
hp
= gethostbyname(*ahost
);
fprintf(stderr
, "%s: unknown host\n", *ahost
);
sin
.sin_family
= hp
->h_addrtype
;
bcopy(hp
->h_addr
, (caddr_t
)&sin
.sin_addr
, hp
->h_length
);
if (connect(s
, (caddr_t
)&sin
, sizeof (sin
), 0) < 0) {
if (errno
== EADDRINUSE
) {
if (errno
== ECONNREFUSED
&& timo
<= 16) {
int s2
= rresvport(&lport
), s3
;
(void) sprintf(num
, "%d", lport
);
(void) write(s
, num
, strlen(num
)+1);
{ int len
= sizeof (from
);
s3
= accept(s2
, &from
, &len
, 0);
from
.sin_port
= ntohs((u_short
)from
.sin_port
);
if (from
.sin_family
!= AF_INET
||
from
.sin_port
>= IPPORT_RESERVED
) {
"socket: protocol failure in circuit setup.\n");
(void) write(s
, locuser
, strlen(locuser
)+1);
(void) write(s
, remuser
, strlen(remuser
)+1);
(void) write(s
, cmd
, strlen(cmd
)+1);
if (read(s
, &c
, 1) != 1) {
while (read(s
, &c
, 1) == 1) {
sin
.sin_family
= AF_INET
;
s
= socket(AF_INET
, SOCK_STREAM
, 0, 0);
sin
.sin_port
= htons((u_short
)*alport
);
if (bind(s
, (caddr_t
)&sin
, sizeof (sin
), 0) >= 0)
if (errno
!= EADDRINUSE
&& errno
!= EADDRNOTAVAIL
) {
if (*alport
== IPPORT_RESERVED
/2) {
fprintf(stderr
, "socket: All ports in use\n");
ruserok(rhost
, ruser
, luser
)
char *rhost
, *ruser
, *luser
;
hostf
= fopen("/etc/hosts.equiv", "r");
while (fgets(ahost
, sizeof (ahost
), hostf
)) {
user
= index(ahost
, ' ');
if (!strcmp(rhost
, ahost
) &&
!strcmp(ruser
, user
? user
: luser
))
hostf
= fopen(".rhosts", "r");