static char sccsid
[] = "@(#)rlogind.c 4.22 (Berkeley) %G%";
struct passwd
*getpwnam();
char *crypt(), *rindex(), *index(), *malloc(), *ntoa();
int on
= 1, options
= 0, fromlen
;
if (getpeername(0, &from
, &fromlen
) < 0) {
fprintf(stderr
, "%s: ", argv
[0]);
if (setsockopt(0, SOL_SOCKET
, SO_KEEPALIVE
, &on
, sizeof (on
)) < 0) {
openlog(argv
[0], LOG_PID
, 0);
syslog(LOG_WARNING
, "setsockopt (SO_KEEPALIVE): %m");
char locuser
[32], remuser
[32];
struct sockaddr_in
*fromp
;
int stop
= TIOCPKT_DOSTOP
;
register struct hostent
*hp
;
fromp
->sin_port
= ntohs((u_short
)fromp
->sin_port
);
hp
= gethostbyaddr(&fromp
->sin_addr
, sizeof (struct in_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
;
register pcc
= 0, fcc
= 0;
/* FILE *console = fopen("/dev/console", "w"); */
/* setbuf(console, 0); */
/* fprintf(console, "f %d p %d\r\n", f, p); */
signal(SIGTSTP
, SIG_IGN
);
signal(SIGCHLD
, cleanup
);
int ibits
= 0, obits
= 0;
/* fprintf(console, "ibits from %d obits from %d\r\n", ibits, obits); */
if (select(16, &ibits
, &obits
, 0, 0) < 0) {
fatalperror(f
, "select", errno
);
/* fprintf(console, "ibits %d obits %d\r\n", ibits, obits); */
if (ibits
== 0 && obits
== 0) {
/* shouldn't happen... */
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
|
/* The following 3 lines do nothing. */
send(f
,&pibuf
[0],1,MSG_OOB
);
if ((obits
& (1<<f
)) && pcc
> 0) {
if (cc
< 0 && errno
== EWOULDBLOCK
) {
/* also shouldn't happen */
/* 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.\r\n", msg
);
(void) write(f
, buf
, strlen(buf
));
fatalperror(f
, msg
, errno
)
extern char *sys_errlist
[];
if ((unsigned) errno
< sys_nerr
)
(void) sprintf(buf
, "%s: %s", msg
, sys_errlist
[errno
]);
(void) sprintf(buf
, "%s: Error %d", msg
, 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]));