* Copyright (c) 1983 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
static char sccsid
[] = "@(#)rcmd.c 5.2 (Berkeley) %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
);
if (write(s
, num
, strlen(num
)+1) != strlen(num
)+1) {
perror("write: setting up stderr");
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
;
sin
.sin_addr
.s_addr
= INADDR_ANY
;
s
= socket(AF_INET
, SOCK_STREAM
, 0);
sin
.sin_port
= htons((u_short
)*alport
);
if (bind(s
, (caddr_t
)&sin
, sizeof (sin
), 0) >= 0)
if (errno
== EADDRNOTAVAIL
)
if (errno
!= EADDRINUSE
) {
if (*alport
== IPPORT_RESERVED
/2) {
fprintf(stderr
, "socket: All ports in use\n");
ruserok(rhost
, superuser
, ruser
, luser
)
hostf
= superuser
? (FILE *)0 : fopen("/etc/hosts.equiv", "r");
while (fgets(ahost
, sizeof (ahost
), hostf
)) {
while (*p
!= '\n' && *p
!= ' ' && *p
!= '\t' && *p
!= '\0')
if (*p
== ' ' || *p
== '\t') {
while (*p
== ' ' || *p
== '\t')
while (*p
!= '\n' && *p
!= ' ' && *p
!= '\t' && *p
!= '\0')
if (!strcmp(rhost
, ahost
) &&
!strcmp(ruser
, *user
? user
: luser
)) {
hostf
= fopen(".rhosts", "r");