static char sccsid
[] = "@(#)rlogin.c 4.9 83/02/09";
char *index(), *rindex(), *malloc(), *getenv();
struct passwd
*getpwuid();
{ "0", "50", "75", "110", "134", "150", "200", "300",
"600", "1200", "1800", "2400", "4800", "9600", "19200", "38400" };
char term
[64] = "network";
host
= rindex(argv
[0], '/');
if (!strcmp(host
, "rlogin"))
if (argc
> 0 && !strcmp(*argv
, "-d")) {
if (argc
> 0 && !strcmp(*argv
, "-l")) {
if (argc
> 0 && !strncmp(*argv
, "-e", 2)) {
if (argc
> 0 && !strcmp(*argv
, "-8")) {
pwd
= getpwuid(getuid());
fprintf(stderr
, "Who are you?\n");
sp
= getservbyname("login", "tcp");
fprintf(stderr
, "rlogin: login/tcp: unknown service\n");
if (ioctl(0, TIOCGETP
, &ttyb
)==0) {
strcat(term
, speeds
[ttyb
.sg_ospeed
]);
signal(SIGPIPE
, lostpeer
);
rem
= rcmd(&host
, sp
->s_port
, pwd
->pw_name
,
name
? name
: pwd
->pw_name
, term
, 0);
if (options
& SO_DEBUG
&&
setsockopt(rem
, SOL_SOCKET
, SO_DEBUG
, 0, 0) < 0)
perror("rlogin: setsockopt (SO_DEBUG)");
perror("rlogin: setuid");
"usage: rlogin host [ -ex ] [ -l username ]\n");
ioctl(0, TIOCGET
, (char *)&defflags
);
defflags
&= ECHO
| CRMOD
;
ioctl(0, TIOCCGET
, (char *)&deftc
);
notc
.tc_startc
= deftc
.tc_startc
;
notc
.tc_stopc
= deftc
.tc_stopc
;
prf("\007Lost connection.");
if (child
> 0 && kill(child
, SIGKILL
) >= 0)
* writer: write to remote: 0 -> line.
* ~^Z suspend rlogin process.
* ~^Y suspend rlogin process, but leave reader alone.
while (read(0, &c
, 1) > 0) {
* If we're at the beginning of the line
* and recognize a command character, then
* we echo locally. Otherwise, characters
* are echo'd remotely. If the command
* character is doubled, this acts as a
* force and local echo is suppressed.
if (p
== b
+ 1 && *b
== cmdchar
)
if (write(rem
, &c
, 1) == 0) {
if (c
== '\r' || c
== '\n') {
if (cmdc
== '.' || cmdc
== deftc
.tc_eofc
) {
write(0, CRLF
, sizeof(CRLF
));
if (cmdc
== deftc
.tc_suspc
||
cmdc
== deftc
.tc_dsuspc
) {
write(0, CRLF
, sizeof(CRLF
));
signal(SIGCHLD
, SIG_IGN
);
kill(cmdc
== deftc
.tc_suspc
?
if (c
== deftc
.tc_erase
) {
if (c
== deftc
.tc_kill
|| c
== 0177 || c
== deftc
.tc_eofc
||
char waste
[BUFSIZ
], mark
;
ioctl(1, TIOCFLUSH
, (char *)&out
);
if (ioctl(rem
, SIOCATMARK
, &atmark
) < 0) {
(void) read(rem
, waste
, sizeof (waste
));
recv(rem
, &mark
, 1, SOF_OOB
);
if (mark
& TIOCPKT_NOSTOP
) {
ioctl(0, TIOCCSET
, (char *)¬c
);
if (mark
& TIOCPKT_DOSTOP
) {
notc
.tc_stopc
= deftc
.tc_stopc
;
notc
.tc_startc
= deftc
.tc_startc
;
ioctl(0, TIOCCSET
, (char *)¬c
);
* reader: read from remote: line -> 1
ioctl(rem
, SIOCSPGRP
, (char *)&pid
); }
cnt
= read(rem
, rb
, sizeof (rb
));
ioctl(0, TIOCGET
, (char *)&flags
);
ioctl(0, TIOCSET
, (char *)&flags
);
ioctl(0, TIOCCSET
, (char *)tc
);
fprintf(stderr
, f
, a1
, a2
, a3
);
signal(SIGPIPE
, SIG_IGN
);
prf("\007Lost connection");