home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / os / linux / 8523 < prev    next >
Encoding:
Text File  |  1992-08-17  |  6.4 KB  |  218 lines

  1. Newsgroups: comp.os.linux
  2. Path: sparky!uunet!wupost!darwin.sura.net!jvnc.net!princeton!phoenix.Princeton.EDU!qpliu
  3. From: qpliu@phoenix.princeton.edu (q.p.liu)
  4. Subject: ka9q telunix (incoming telnet server) patches
  5. Message-ID: <1992Aug18.075232.25541@Princeton.EDU>
  6. Originator: news@nimaster
  7. Keywords: ka9q, telunix, telnet
  8. Sender: news@Princeton.EDU (USENET News System)
  9. Nntp-Posting-Host: phoenix.princeton.edu
  10. Reply-To: qpliu@princeton.edu
  11. Organization: Princeton University
  12. Date: Tue, 18 Aug 1992 07:52:32 GMT
  13. Lines: 203
  14.  
  15.  
  16. These are some minor patches to ka9q that will provide the minimal
  17. incoming telnet (telunix server) capability for those who want it
  18. now.  THE SECURITY CONSCIOUS SHOULD READ THE CAVEATS.
  19.  
  20. First, if it gets EAGAIN from reading the pty, it won't shut down
  21. the connection.
  22.  
  23. Second, it acknowledges DO ECHO and DO SGA with WILL.  (Don't know what
  24. SGA is, it's required for character mode.  Ask a telnetd wizard.)
  25.  
  26. Third, it initially sends WILL ECHO and DONT ECHO.  (And a few other
  27. things, just in case.)
  28.  
  29. Fourth, it sets the pty to -icanon.
  30.  
  31. Fifth, it does cr-nl and cr-nul to cr conversion.
  32.  
  33. Sixth, it responds to AYT (as part of learning how telnetd works.)
  34.  
  35. Limitations and caveats:
  36. It assumes that there is already a process connected to the other end of
  37. the pty.  (A more complete server would fork a login on a connection, and
  38. close the connection when it dies, and kill it when the connection dies,
  39. and clean up utmp and ... be a real telnetd.)  I have init putting a getty
  40. there.  This means connecting/disconnecting does not affect anything on
  41. the other end of the pty.  If the connection shuts down in the shell, the
  42. next connection will resume in the shell.  THE SECURITY CONSCIOUS SHOULD
  43. BE AWARE OF THIS.
  44.  
  45. Opening a pty that is already open doesn't seem to give an error, (at least
  46. with 0.95c, this may not be a problem with later versions of the kernel.)
  47. This means all incoming telnets get connected to the same pty.  There is
  48. probably a simple fix, but a simpler hack is to limit the number of telnet
  49. clients to 1 (the current default is 3.)  AGAIN, THE SECURITY CONSCIOUS
  50. SHOULD BE AWARE OF THIS.
  51.  
  52. qpliu@princeton.edu
  53.  
  54. -cut here-
  55. *** sys5_io.c.orig    Mon Aug 17 00:59:18 1992
  56. --- sys5_io.c    Mon Aug 17 01:11:42 1992
  57. ***************
  58. *** 486,491 ****
  59. --- 486,492 ----
  60.       extern int    errno;
  61.       int        pty;
  62.       int        letcnt=0, numcnt=0;
  63. +     struct termio    tio;
  64.   
  65.       static char    *letters = "pqrs",
  66.               *numbers = "0123456789abcdef";
  67. ***************
  68. *** 512,517 ****
  69. --- 513,522 ----
  70.               numcnt = 0;
  71.           } 
  72.       } while ((pty=open(master, O_RDWR | O_NDELAY)) < 0);
  73. +     ioctl (pty, TCGETA, &tio);
  74. +     tio.c_lflag &= ~(ICANON);
  75. +     ioctl (pty, TCSETA, &tio);
  76.   
  77.       return(pty);
  78.   }
  79. *** telnet.c.orig    Sun Aug 16 20:53:16 1992
  80. --- telnet.c    Sun Aug 16 23:55:55 1992
  81. ***************
  82. *** 622,627 ****
  83. --- 622,639 ----
  84.           tel_setterm(tn);  /* enable flow */
  85.           ack = WILL;
  86.           break;
  87. +     case TN_ECHO:
  88. +         if(tn->local[uchar(opt)] == 1)
  89. +             return;        /* Already set, ignore to prevent loop */
  90. +         tn->local[uchar(opt)] = 1;
  91. +         ack = WILL;
  92. +         break;
  93. +     case TN_SUPPRESS_GA:
  94. +         if(tn->local[uchar(opt)] == 1)
  95. +             return;        /* Already set, ignore to prevent loop */
  96. +         tn->local[uchar(opt)] = 1;
  97. +         ack = WILL;
  98. +         break;
  99.       default:
  100.           ack = WONT;    /* Don't know what it is */
  101.       }
  102. *** telnet.h.orig    Sun Aug 16 23:38:34 1992
  103. --- telnet.h    Sun Aug 16 23:38:43 1992
  104. ***************
  105. *** 7,12 ****
  106. --- 7,13 ----
  107.   #define    WONT        252
  108.   #define    DO        253
  109.   #define    DONT        254
  110. + #define    AYT        246
  111.   #define    TN_DM        242        /* data mark--for connect. cleaning */
  112.   #define    SB        250        /* interpret as subnegotiation */
  113.   #define    SE        240        /* end sub negotiation */
  114. ***************
  115. *** 35,40 ****
  116. --- 36,42 ----
  117.   #define    TS_DONT    5    /* Received IAC-DONT */
  118.   #define    TS_SB    7        /* sub-option collection */
  119.   #define    TS_SE    8        /* looking for sub-option end */
  120. + #define    TS_CR    9        /* stripping out nul with cr-nul */
  121.   
  122.   #define SUBBUFSIZE 64
  123.   
  124. *** telunix.c.orig    Sun Aug 16 17:58:43 1992
  125. --- telunix.c    Mon Aug 17 01:20:38 1992
  126. ***************
  127. *** 1,4 ****
  128. --- 1,5 ----
  129.   #include <stdio.h>
  130. + #include <errno.h>
  131.   #include "global.h"
  132.   #include "config.h"
  133.   #include "mbuf.h"
  134. ***************
  135. *** 102,107 ****
  136. --- 103,117 ----
  137.           selmask |= (1 << tn->fd);
  138.   #endif
  139.           log(tcb,"open Telunix - (%d %x %d %d)",tn->fd,tcb,old,new);
  140. +         {
  141. +             char data[] = { IAC, WILL, TN_ECHO, IAC, WILL,
  142. +                 TN_SUPPRESS_GA, IAC, WILL, TN_TRANSMIT_BINARY,
  143. +                 IAC, WILL, TN_STATUS, IAC, DO, TN_LFLOW, IAC,
  144. +                 DONT, ECHO};
  145. +             send_tcp (tcb, qdata (data, 18));
  146. +         }
  147.           break;
  148.   
  149.       case FINWAIT1:
  150. ***************
  151. *** 199,204 ****
  152. --- 209,215 ----
  153.           if(tn->outbuf->cnt < TURQSIZ) {
  154.               if((i = read(tn->fd, tn->outbuf->data + tn->outbuf->cnt,
  155.                   (int)(TURQSIZ - tn->outbuf->cnt))) == -1) {
  156. +                 if (errno == EAGAIN) return;
  157.                   log(tcb,"error Telunix - read (%d %d %d)",
  158.                       errno, tn->fd,
  159.                       TURQSIZ - tn->outbuf->cnt);
  160. ***************
  161. *** 240,246 ****
  162.       /* Optimization for very common special case -- no special chars */
  163.       if(tn->state == TS_DATA){
  164.           while(bp != NULLBUF &&
  165. !               memchr(bp->data,IAC,(int)bp->cnt) == NULLCHAR) {
  166.               if((i = write(tn->fd, bp->data, (int)bp->cnt)) == bp->cnt) {
  167.                   tn->inbuf = bp = free_mbuf(bp);
  168.               } else if(i == -1) {
  169. --- 251,258 ----
  170.       /* Optimization for very common special case -- no special chars */
  171.       if(tn->state == TS_DATA){
  172.           while(bp != NULLBUF &&
  173. !               memchr(bp->data,IAC,(int)bp->cnt) == NULLCHAR &&
  174. !               memchr(bp->data,'\r',(int)bp->cnt) == NULLCHAR) {
  175.               if((i = write(tn->fd, bp->data, (int)bp->cnt)) == bp->cnt) {
  176.                   tn->inbuf = bp = free_mbuf(bp);
  177.               } else if(i == -1) {
  178. ***************
  179. *** 260,268 ****
  180. --- 272,290 ----
  181.       while(pullup(&(tn->inbuf),&c,1) == 1){
  182.           bp = tn->inbuf;
  183.           switch(tn->state){
  184. +         case TS_CR:
  185. +             tn->state = TS_DATA;
  186. +             /* strip from cr-nl and cr-nul */
  187. +             if (c == 0 || c == '\n') break;
  188.           case TS_DATA:
  189.               if(uchar(c) == IAC){
  190.                   tn->state = TS_IAC;
  191. +             } else if (uchar (c) == '\r') {
  192. +                 tn->state = TS_CR;
  193. +                 if(write(tn->fd, &c, 1) != 1) {
  194. +                     /* we drop a character here */
  195. +                     return;
  196. +                 }
  197.               } else {
  198.                   if(!tn->remote[TN_TRANSMIT_BINARY])
  199.                       c &= 0x7f;
  200. ***************
  201. *** 285,290 ****
  202. --- 307,316 ----
  203.                   break;
  204.               case DONT:
  205.                   tn->state = TS_DONT;
  206. +                 break;
  207. +             case AYT:
  208. +                 tn->state = TS_DATA;
  209. +                 sndmsg (tn->tcb,"\r\n[Um...Yeah!]\r\n");
  210.                   break;
  211.               case IAC:
  212.                   if(write(tn->fd, &c, 1) != 1) {
  213. -- 
  214. qpliu@princeton.edu           Standard opinion: Opinions are delta-correlated.
  215.