1 | /*
|
---|
2 | * TNET A server program for MINIX which implements the TCP/IP
|
---|
3 | * suite of networking protocols. It is based on the
|
---|
4 | * TCP/IP code written by Phil Karn et al, as found in
|
---|
5 | * his NET package for Packet Radio communications.
|
---|
6 | *
|
---|
7 | * Handle the TERMINAL module.
|
---|
8 | *
|
---|
9 | * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
|
---|
10 | * Michael Temari, <temari@temari.ae.ge.com>
|
---|
11 | *
|
---|
12 | * 07/29/92 MT Telnet options hack which seems to work okay
|
---|
13 | * 01/12/93 MT Better telnet options processing instead of hack
|
---|
14 | */
|
---|
15 | #include <sys/types.h>
|
---|
16 | #include <errno.h>
|
---|
17 | #if 0
|
---|
18 | #include <fcntl.h>
|
---|
19 | #endif
|
---|
20 | #include <stdlib.h>
|
---|
21 | #include <unistd.h>
|
---|
22 | #include <string.h>
|
---|
23 | #include <stdio.h>
|
---|
24 | #include <signal.h>
|
---|
25 | #include "telnet.h"
|
---|
26 | #include "telnetd.h"
|
---|
27 |
|
---|
28 | _PROTOTYPE(void sig_done, (int sig));
|
---|
29 |
|
---|
30 | static char buff[4096];
|
---|
31 |
|
---|
32 | void term_init()
|
---|
33 | {
|
---|
34 | tel_init();
|
---|
35 |
|
---|
36 | telopt(1, WILL, TELOPT_SGA);
|
---|
37 | telopt(1, DO, TELOPT_SGA);
|
---|
38 | telopt(1, WILL, TELOPT_BINARY);
|
---|
39 | telopt(1, DO, TELOPT_BINARY);
|
---|
40 | telopt(1, WILL, TELOPT_ECHO);
|
---|
41 | telopt(1, DO, TELOPT_WINCH);
|
---|
42 | }
|
---|
43 |
|
---|
44 | static int io_done = 0;
|
---|
45 |
|
---|
46 | void term_inout(pty_fd)
|
---|
47 | int pty_fd;
|
---|
48 | {
|
---|
49 | register int i;
|
---|
50 | pid_t pid;
|
---|
51 | struct sigaction sa;
|
---|
52 |
|
---|
53 | sigemptyset(&sa.sa_mask);
|
---|
54 | sa.sa_flags = 0;
|
---|
55 | sa.sa_handler = sig_done;
|
---|
56 | sigaction(SIGALRM, &sa, (struct sigaction *) NULL);
|
---|
57 |
|
---|
58 | if ((pid = fork()) == -1) {
|
---|
59 | sprintf(buff, "telnetd: fork() failed: %s\r\n", strerror(errno));
|
---|
60 | (void) write(1, buff, strlen(buff));
|
---|
61 | }
|
---|
62 |
|
---|
63 | if (pid != 0) {
|
---|
64 | /* network -> login process */
|
---|
65 | while (!io_done && (i = read(0, buff, sizeof(buff))) > 0) {
|
---|
66 | tel_in(pty_fd, 1, buff, i);
|
---|
67 | }
|
---|
68 | /* EOF, kill opposite number and exit. */
|
---|
69 | (void) kill(pid, SIGKILL);
|
---|
70 | } else {
|
---|
71 | /* login process -> network */
|
---|
72 | while ((i = read(pty_fd, buff, sizeof(buff))) > 0) {
|
---|
73 | tel_out(1, buff, i);
|
---|
74 | }
|
---|
75 | /* EOF, alert opposite number and exit. */
|
---|
76 | (void) kill(getppid(), SIGALRM);
|
---|
77 | }
|
---|
78 | /* EOF. */
|
---|
79 | }
|
---|
80 |
|
---|
81 | void sig_done(sig)
|
---|
82 | int sig;
|
---|
83 | {
|
---|
84 | io_done = 1;
|
---|
85 | alarm(1); /* there is always a chance... */
|
---|
86 | }
|
---|