static char sccsid
[] = "@(#)rlogind.c 4.3 82/11/14";
struct passwd
*getpwnam();
char *crypt(), *rindex(), *index(), *malloc();
int options
= SO_ACCEPTCONN
|SO_KEEPALIVE
;
struct sockaddr_in sin
= { AF_INET
};
sp
= getservbyname("login", "tcp");
fprintf(stderr
, "rlogind: tcp/rlogin: unknown service\n");
{ int tt
= open("/dev/tty", 2);
sin
.sin_port
= htons(sp
->s_port
);
if (argc
> 0 && !strcmp(argv
[0], "-d")) {
int port
= atoi(argv
[0]);
fprintf(stderr
, "%s: bad port #\n", argv
[0]);
sin
.sin_port
= htons(port
);
f
= socket(0, SOCK_STREAM
, 0, 0);
perror("rlogind: socket");
if (bind(f
, &sin
, sizeof (sin
), 0) < 0) {
int s
, len
= sizeof (from
);
s
= accept(f
, &from
, &len
, 0);
while (wait3(status
, WNOHANG
, 0) > 0)
char locuser
[32], remuser
[32];
struct sockaddr_in
*fromp
;
int stop
= TIOCPKT_DOSTOP
;
register struct hostent
*hp
;
fromp
->sin_port
= htons(fromp
->sin_port
);
hp
= gethostbyaddr(&fromp
->sin_addr
, sizeof (struct in_addr
),
if (fromp
->sin_family
!= AF_INET
||
fromp
->sin_port
>= IPPORT_RESERVED
||
write(f
, "\01Permission denied.\n", 20);
for (c
= 'p'; c
<= 's'; c
++) {
line
[strlen("/dev/pty")] = c
;
line
[strlen("/dev/ptyp")] = '0';
if (stat(line
, &stb
) < 0)
for (i
= 0; i
< 16; i
++) {
line
[strlen("/dev/ptyp")] = "0123456789abcdef"[i
];
printf("All network ports in use.\r\n");
line
[strlen("/dev/")] = 't';
{ int tt
= open("/dev/tty", 2);
gtty(t
, &b
); b
.sg_flags
= RAW
|ANYP
; stty(t
, &b
);
char pibuf
[1024], fibuf
[1024], *pbp
, *fbp
;
int pcc
= 0, fcc
= 0, on
= 1;
/* FILE *console = fopen("/dev/console", "w"); */
/* setbuf(console, 0); */
/* fprintf(console, "f %d p %d\r\n", f, p); */
signal(SIGTSTP
, SIG_IGN
);
sigset(SIGCHLD
, cleanup
);
int ibits
= 0, obits
= 0;
if (fcc
) obits
|= (1<<p
); else ibits
|= (1<<f
);
if (pcc
) obits
|= (1<<f
); else ibits
|= (1<<p
);
if (fcc
< 0 && pcc
< 0) break;
/* fprintf(console, "ibits from %d obits from %d\r\n", ibits, obits); */
select(16, &ibits
, &obits
, 0, 0, 0);
/* fprintf(console, "ibits %d obits %d\r\n", ibits, obits); */
if (ibits
== 0 && obits
== 0) {
fcc
= read(f
, fibuf
, sizeof (fibuf
));
/* fprintf(console, "%d from f\r\n", fcc); */
if (fcc
< 0 && errno
== EWOULDBLOCK
)
pcc
= read(p
, pibuf
, sizeof (pibuf
));
/* fprintf(console, "%d from p, buf[0] %x, errno %d\r\n", pcc, buf[0], errno); */
if (pcc
< 0 && errno
== EWOULDBLOCK
)
if (pibuf
[0]&(TIOCPKT_FLUSHWRITE
|
send(f
,&pibuf
[0],1,SOF_OOB
);
if ((obits
& (1<<f
)) && pcc
> 0) {
/* fprintf(console, "%d of %d to f\r\n", cc, pcc); */
if ((obits
& (1<<p
)) && fcc
> 0) {
/* fprintf(console, "%d of %d to p\r\n", cc, fcc); */
execl("/bin/login", "login", "-r", hp
->h_name
, 0);
ioctl(netf
, SIOCDONE
, &how
);
char wtmpf
[] = "/usr/adm/wtmp";
char utmp
[] = "/etc/utmp";
#define SCPYN(a, b) strncpy(a, b, sizeof(a))
#define SCMPN(a, b) strncmp(a, b, sizeof(a))
while(read(f
, (char *)&wtmp
, sizeof(wtmp
)) == sizeof(wtmp
)) {
if (SCMPN(wtmp
.ut_line
, line
+5) || wtmp
.ut_name
[0]==0)
lseek(f
, -(long)sizeof(wtmp
), 1);
write(f
, (char *)&wtmp
, sizeof(wtmp
));
SCPYN(wtmp
.ut_line
, line
+5);
write(f
, (char *)&wtmp
, sizeof(wtmp
));
line
[strlen("/dev/")] = 'p';