static char sccsid
[] = "@(#)rlogind.c 4.12 83/02/28";
struct passwd
*getpwnam();
char *crypt(), *rindex(), *index(), *malloc(), *ntoa();
struct sockaddr_in sin
= { AF_INET
};
int f
, options
= SO_KEEPALIVE
;
sp
= getservbyname("login", "tcp");
fprintf(stderr
, "rlogind: tcp/rlogin: unknown service\n");
{ int tt
= open("/dev/tty", 2);
sin
.sin_port
= 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((u_short
)port
);
f
= socket(AF_INET
, SOCK_STREAM
, 0, 0);
perror("rlogind: socket");
if (setsockopt(f
, SOL_SOCKET
, SO_DEBUG
, 0, 0) < 0)
perror("rlogind: setsockopt (SO_DEBUG)");
if (setsockopt(f
, SOL_SOCKET
, SO_KEEPALIVE
, 0, 0) < 0)
perror("rlogind: setsocktopt (SO_KEEPALIVE)");
if (bind(f
, &sin
, sizeof (sin
), 0) < 0) {
sigset(SIGCHLD
, reapchild
);
int s
, len
= sizeof (from
);
s
= accept(f
, &from
, &len
, 0);
perror("rlogind: accept");
signal(SIGCHLD
, SIG_IGN
);
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((u_short
)fromp
->sin_port
);
hp
= gethostbyaddr(&fromp
->sin_addr
, sizeof (struct in_addr
),
char buf
[BUFSIZ
], *cp
= (char *)&fromp
->sin_addr
;
fatal(f
, sprintf(buf
, "Host name for your address (%s) unknown",
if (fromp
->sin_family
!= AF_INET
||
fromp
->sin_port
>= IPPORT_RESERVED
||
fatal(f
, "Permission denied");
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
];
fatal(f
, "All network ports in use");
line
[strlen("/dev/")] = 't';
{ int tt
= open("/dev/tty", 2);
fatalperror(f
, line
, errno
);
gtty(t
, &b
); b
.sg_flags
= RAW
|ANYP
; stty(t
, &b
);
fatalperror(f
, "", errno
);
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;
/* 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);
fatalperror(2, "/bin/login", errno
);
buf
[0] = '\01'; /* error indicator */
(void) sprintf(buf
+ 1, "rlogind: %s.\n", msg
);
(void) write(f
, buf
, strlen(buf
));
fatalperror(f
, msg
, errno
)
extern char *sys_errlist
[];
(void) sprintf(buf
, "%s: %s", msg
, sys_errlist
[errno
]);
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';
* Convert network-format internet address
* to base 256 d.d.d.d representation.
#define UC(b) (((int)b)&0xff)
sprintf(b
, "%d.%d.%d.%d", UC(p
[0]), UC(p
[1]), UC(p
[2]), UC(p
[3]));