home *** CD-ROM | disk | FTP | other *** search
/ GRIPS 2: Government Rast…rocessing Software & Data / GRIPS_2.cdr / dos / ncsa_tel / tel_2_2_ / source / confile.c < prev    next >
C/C++ Source or Header  |  1988-07-15  |  31KB  |  1,387 lines

  1. /*
  2. *   Confile.c
  3. *   Split from util.c 5/88
  4. *   Reads and stores the appropriate information for the config file
  5. *
  6. *   version 2, full session layer, TK started 6/17/87
  7. *
  8. ****************************************************************************
  9. *                                                                          *
  10. *      part of:                                                            *
  11. *      Network kernel for NCSA Telnet                                      *
  12. *      by Tim Krauskopf                                                    *
  13. *                                                                          *
  14. *      National Center for Supercomputing Applications                     *
  15. *      152 Computing Applications Building                                 *
  16. *      605 E. Springfield Ave.                                             *
  17. *      Champaign, IL  61820                                                *
  18. *                                                                          *
  19. ****************************************************************************
  20. */
  21. #include "stdio.h"
  22. #include "whatami.h"
  23. #include "hostform.h"
  24.  
  25. #ifdef PC
  26. #include "string.h"
  27. #else
  28. char *index();
  29. #define strchr(A,B) index(A,B)
  30. #endif
  31.  
  32. #define NUMSPECS 128
  33.  
  34. char                             /* special function types */
  35.             *neterrstring(),
  36.             *malloc();
  37. int32 time();                    /* don't forget this sucker! */
  38.  
  39. static struct machinfo *Smachlist,*Smptr;
  40. struct machinfo *Sns=NULL;
  41.  
  42. static unsigned char *Smachfile = {"config.tel"},
  43.             Sflags[NUMSPECS-95],    /* which parms we have or have not */
  44.             *Sspace;
  45.  
  46. struct config Scon = {
  47.         0,0,0,0,
  48.         0,
  49.         3,
  50.         127,0,0,1,
  51.         "",
  52.         7,1,0x70,
  53.         "atalk",
  54.         "ega",
  55.         0,
  56.         1,
  57.         1,
  58.         1,
  59.         0,
  60.         "DEC-VT100",
  61.         "*",
  62.         NULL,
  63.         NULL,
  64.         NULL,
  65.         NULL,
  66.         NULL,
  67.         NULL,
  68.         1,
  69.         4,
  70.         3,
  71.         -1,
  72.         0x0d000,
  73.         0x0300
  74. };
  75.  
  76. int
  77. Sxxnf[3] = NFDEF,
  78. Sxxnb[3] = NBDEF,
  79. Sxxbf[3] = BFDEF,
  80. Sxxbb[3] = BBDEF,
  81. Sxxuf[3] = UFDEF,
  82. Sxxub[3] = UBDEF;
  83.  
  84. static int
  85.         mno=0,                    /* how many machines in host file */
  86.         lineno,                    /* line number in hosts file */
  87.         position,                /* position for scanning string */
  88.         constate,                /* state for config file parser */
  89.         inquote;                /* flag, inside quotes now */
  90.  
  91. /*
  92. *   States for config file reading state machine.
  93. *   One for each type of keyword and some for controlling.
  94. */
  95.  
  96. #define    CONNAME    101
  97. #define CONHOST    102
  98. #define CONIP    103
  99. #define CONGATE    104
  100. #define CONCOLOR 105
  101. #define CONBKSP    106
  102. #define CONBKSC    107
  103. #define CONRETR    108
  104. #define CONWIND    109
  105. #define CONSEG    110
  106. #define CONMTU    111
  107. #define CONNS    112
  108. #define CONTO    113
  109. #define CONCRMAP 114
  110. #define CONDUP  115
  111. #define CONWRAP 116
  112. #define CONWIDE 117
  113. #define CONFONT 118
  114. #define CONFSIZE 119
  115. #define CONNF 120
  116. #define CONNB 121
  117. #define CONBF 122
  118. #define CONBB 123
  119. #define CONUF 124
  120. #define CONUB 125
  121. #define CONRF 126
  122. #define CONRB 127
  123. #define CONCLMODE 128
  124. /*
  125. *  above this line are per machine entries, below are configuration entries
  126. */
  127. #define CONDOMTO 129
  128. #define CONNDOM  130
  129. #define    CONMASK    131
  130. #define CONMYIP    132
  131. #define CONHPF  133
  132. #define CONPSF  134
  133. #define CONTEKF 135
  134. #define CONJTIME 136
  135. #define CONME    137
  136. #define CONCCOL    138
  137. #define CONHW    139
  138. #define CONADDR    140
  139. #define CONIOA    141
  140. #define CONDEF  142
  141. #define CONCKEYS 143
  142. #define CONINT    144
  143. #define CONBIOS    145
  144. #define CONTEK    146
  145. #define CONVIDEO    147
  146. #define CONFTP    148
  147. #define CONRCP    149
  148. #define CONPASS    150
  149. #define CONCAP    151
  150. #define CONTTYPE    152
  151. #define CONNSTYPE     153
  152. #define CONFROM    154
  153. #define CONARPTO 155
  154. #define CONZONE 156
  155.  
  156. char *Skeyw[] = {
  157.         "",    
  158.         "name",                            /* name of session */
  159.         "host",                            /* name of host */
  160.         "hostip",                        /* IP number */
  161.         "gateway",                        /* gateway level */
  162.         "color",                        /* color code  ==5== */
  163.         "erase",                        /* value to use for backspace */
  164.         "scrollback",                    /* how many lines to backscroll */
  165.         "retrans",                        /* initial retrans time */
  166.         "rwin",                            /* window to allow for this host */
  167.         "maxseg",                        /* maximum transfer size (in) ==10== */
  168.         "mtu",                            /* transfer unit (out) */
  169.         "nameserver",                    /* name server level */
  170.         "contime",                        /* timeout for opening connection */
  171.         "crmap",                        /* map for Berkeley 4.3 compatibility */
  172.         "duplex",                        /* half duplex for IBM machines */
  173.         "vtwrap",                        /* should VT wrap? */
  174.         "vtwidth",                        /* width of VT100 screen */
  175.         "font",                            /* font to use, when given a choice */
  176.         "fsize",                        /* font size, in points */
  177.         "nfcolor",                        /* normal foreground color */
  178.         "nbcolor",                        /* normal background color */
  179.         "bfcolor",                        /* blink foreground color */
  180.         "bbcolor",                        /* blink background color */
  181.         "ufcolor",                        /* underline foreground color */
  182.         "ubcolor",                        /* underline background color */
  183.         "rfcolor",                        /* reverse foreground color */
  184.         "rbcolor",                        /* reverse background color */
  185.         "clearsave",                    /* clear screen saves lines */
  186.  
  187. /*
  188. *  following are one-time entries, above are part of the data structure
  189. */
  190.         "domaintime",                    /* time-out for DOMAIN */
  191.         "domainretry",                    /* # of retries */
  192.         "netmask",                        /* subnetting mask */
  193.         "myip",                            /* local machine's IP # */
  194.         "hpfile",                        /* HPGL output file */
  195.         "psfile",                        /* postscript output file */
  196.         "tekfile",                        /* tektronix output file */
  197.         "timeslice",                    /* timer slice for multi-tasking */
  198.         "myname",                        /* identifying info ==15==*/
  199.         "concolor",                        /* console colors */
  200.         "hardware",                        /* network hardware */
  201.         "address",                        /* Address of hardware */
  202.         "ioaddr",                        /* ioaddress of hardware */
  203.         "domain",                        /* default domain for lookup */
  204.         "commandkeys",                    /* use command keys on mac */
  205.         "interrupt",                    /* interrupt request 3 or 5 */
  206.         "bios",                            /* use BIOS screen */
  207.         "tek",                            /* tektronix graphics ==20==*/
  208.         "video",                        /* type of video hardware */
  209.         "ftp",                            /* enable ftp? */
  210.         "rcp",                            /* enable rcp? */
  211.         "passfile",                        /* password file name */
  212.         "capfile",                        /* capture file name */
  213.         "termtype",                        /* terminal type */
  214.         "nameservertype",                /* nameserver type */
  215.         "copyfrom",                        /* copy from another machine */
  216.         "arptime",                        /* time-out for ARPs */
  217.         "zone",                            /* NBP zone for Macs */
  218.         ""
  219.     };
  220.  
  221.  
  222.  
  223. /************************************************************************/
  224. /*  Sgetconfig
  225. *   copy the configuration information into the user's data structure
  226. *   directly.  The user can do with it what he feels like.
  227. */
  228. Sgetconfig(cp)
  229.     struct config *cp;
  230.     {
  231.  
  232.     movebytes(cp,&Scon,sizeof(struct config));
  233.     return(0);
  234.  
  235. }
  236.  
  237. /************************************************************************/
  238. /*  Sreadhosts
  239. *   read in the hosts file into our in-memory data structure.
  240. *   Handle everything by keyword, see docs for specifications about file.
  241. */
  242. Sreadhosts()
  243.     {
  244.     FILE *fp;
  245.     int c,retval;
  246.  
  247.     Smachlist = Smptr = NULL;
  248.     mno = 0;
  249.  
  250.     Sspace = malloc(256);                /* get room for gathering stuff */
  251.     if (Sspace == NULL) {
  252.         Serrline(901);
  253.         return(1);
  254.     }
  255.     position = constate = inquote = lineno = 0;   /* state vars */    
  256.  
  257.     if (NULL == (fp = fopen(Smachfile,"r"))) {
  258.         Serrline(900);
  259.         return(1);
  260.     }
  261.  
  262.     retval = 0;
  263.     while (!retval) {
  264.         c = fgetc(fp);
  265.         if (c == '#' && !inquote) {
  266.             while (c != EOF && c != '\n' && c != '\r')        /* skip to EOL */
  267.                 c = fgetc(fp);
  268.         }
  269.         if (c == '\n' || c == '\r')
  270.             lineno++;
  271.         retval = Scontoken(c);        /* add character to token */
  272.     }
  273.  
  274.     fclose(fp);
  275.     free(Sspace);
  276.  
  277.     Smadd("default");                /* make sure name is in list */
  278.  
  279.     if (retval == EOF)                /* EOF is normal end */
  280.         return(0);
  281.     else
  282.         return(retval);
  283.  
  284. }
  285.  
  286.  
  287. /************************************************************************/
  288. /*  ncstrcmp
  289. *   No case string compare.
  290. *   Only returns 0=match, 1=no match, does not compare greater or less
  291. *   There is a tiny bit of overlap with the | 32 trick, but shouldn't be
  292. *   a problem.  It causes some different symbols to match.
  293. */
  294. ncstrcmp(sa,sb)
  295.     char *sa,*sb;
  296.     {
  297.  
  298.     while (*sa && *sa < 33)        /* don't compare leading spaces */
  299.         sa++;
  300.     while (*sb && *sb < 33)
  301.         sb++;
  302.  
  303.     while (*sa && *sb) {
  304.         if ((*sa != *sb) && ((*sa | 32) != (*sb | 32)))
  305.             return(1);
  306.         sa++;sb++;
  307.     }
  308.     if (!*sa && !*sb)        /* if both at end of string */
  309.         return(0);
  310.     else
  311.         return(1);
  312. }
  313.  
  314. /************************************************************************/
  315. /*  Serrline
  316. *   prints the line number of the host file error and posts the event
  317. *   for the line number error and posts the hosts file error.
  318. */
  319.  
  320. Serrline(n)
  321.     int n;
  322.     {
  323.     char *p;
  324.  
  325.     p = neterrstring(-1);
  326.     sprintf(p,"Config file: error in line %4d",lineno+1);
  327.     netposterr(-1);
  328.  
  329.     netposterr(n);
  330. }
  331.  
  332. /************************************************************************/
  333. /* Scontoken
  334. *  tokenize the strings which get passed to Sconfile.
  335. *  Handles quotes and uses separators:  <33, ;:=
  336. */
  337. Scontoken(c)
  338.     int c;
  339.     {
  340.     int retval;
  341.  
  342.     if (c == EOF) {
  343.         Sspace[position++] = '\0';
  344.         Sconfile(Sspace);
  345.         if (!Sflags[0]) {            /* make sure last entry gets copied */
  346.             if (ncstrcmp("default",Smptr->sname))
  347.                 Scopyfrom("default");
  348.             else
  349.                 Scopyfrom("==");
  350.         }
  351.         return(-1);
  352.     }
  353.  
  354.     if (!position && Sissep(c))        /* skip over junk before token */
  355.         return(0);
  356.  
  357.     if (inquote || !Sissep(c)) {
  358.  
  359.         if (position > 200) {
  360.             Serrline(903);
  361.             return(1);
  362.         }
  363. /*
  364. *  check for quotes, a little mixed up here, could be reorganized
  365. */
  366.         if (c == '"' ) {
  367.             if (!inquote) {            /* beginning of quotes */
  368.                 inquote = 1;
  369.                 return(0);
  370.             }
  371.             else
  372.                 inquote = 0;        /* turn off flag and drop through */
  373.  
  374.         }
  375.         else {                        
  376.             if (c == '\n') {            /* check for EOL inside quotes */
  377.                 Serrline(904);
  378.                 return(1);
  379.             }
  380.             Sspace[position++] = c;    /* include in current string */
  381.             return(0);
  382.         }
  383.                 
  384.     }
  385.  
  386.     Sspace[position++] = '\0';
  387.  
  388.     retval = Sconfile(Sspace);            /* pass the token along */
  389.  
  390.     position = 0;
  391.     inquote = 0;
  392.     Sspace[0] = '\0';
  393.  
  394.     return(retval);
  395. }
  396.  
  397. /************************************************************************/
  398. /*  Sconfile
  399. *   take the characters read from the file and parse them for keywords
  400. *   which require configuration action.
  401. */
  402. Sconfile(s)
  403.     char *s;
  404.     {
  405.     int i,a,b,c,d;
  406.  
  407.     switch (constate) {
  408.         case 0:                                /* lookup keyword */
  409.             if (!(*s))                        /* empty token */
  410.                 return(0);
  411.  
  412.  
  413.             for (i=1; *Skeyw[i] && ncstrcmp(Skeyw[i],s); i++)
  414.                     ;
  415.             if (!(*Skeyw[i])) {            /* not in list */
  416.                 Serrline(902);
  417.                 return(0);                /* don't die - helps backward compatibility */
  418.             }
  419.             constate = 100+i;    /* change to state for keyword */
  420. /*
  421. *  check if this is a machine specific parm without a machine to
  422. *  give it to.  "name" being the only machine specific parm allowed, of course
  423. */
  424.             if (Smptr == NULL && constate > 101 && constate <= NUMSPECS) {
  425.                 Serrline(905);
  426.                 return(1);
  427.             }
  428.             break;
  429.  
  430.         case CONNAME:
  431. /*
  432. *  allocate space for upcoming parameters
  433. */
  434.             if (Smachlist == NULL) {
  435.                 Smachlist = (struct machinfo *)malloc(sizeof(struct machinfo));
  436.                 Smptr = Smachlist;
  437.                 Smptr->sname = NULL;
  438.                 Smptr->hname = NULL;
  439.             }
  440.             else {
  441.                 if (!Sflags[0]) {
  442.                     if (ncstrcmp("default",Smptr->sname))
  443.                         Scopyfrom("default");
  444.                     else
  445.                         Scopyfrom("==");    /* to make sure 'default' gets set */
  446.                 }
  447.                 Smptr->next = 
  448.                     (struct machinfo *)malloc(sizeof(struct machinfo));
  449.                 Smptr = Smptr->next;
  450.             }
  451.             Smptr->next = NULL;
  452.             Smptr->hname = NULL;                /* guarantee to be null */
  453.             Smptr->sname = malloc(position);    /* size of name string */
  454.             strcpy(Smptr->sname,s);                /* keep name field */
  455.             constate = 0;                        /* back to new keyword */
  456.             for (i=0; i<NUMSPECS-99; i++)
  457.                 Sflags[i] = 0;                    /* we have no parms */
  458.             Smptr->mno = ++mno;                    /* new machine number */
  459.             break;
  460.  
  461.         case CONHOST:                            /* also a name */
  462.             Smptr->hname = malloc(position);
  463.             strcpy(Smptr->hname,s);
  464.             constate = 0;
  465.             Sflags[CONHOST-100] = 1;
  466.             break;
  467.  
  468.         case CONIP:                                /* IP number for host */
  469.             if ( 4 != sscanf(s,"%d.%d.%d.%d",&a,&b,&c,&d)) {
  470.                 Serrline(906);
  471.                 return(3);
  472.             }
  473.             Smptr->hostip[0]=a; Smptr->hostip[1] =b;     /* keep number */
  474.             Smptr->hostip[2]=c; Smptr->hostip[3] =d;
  475.             Smptr->mstat = HFILE;
  476.             constate = 0;
  477.             Sflags[CONIP-100] = 1;
  478.             break;
  479.  
  480.         case CONGATE:
  481.             Smptr->gateway = atoi(s);            /* gateway level */
  482.             constate = 0;
  483.             Sflags[CONGATE-100] = 1;
  484.             break;
  485.  
  486.         case CONCOLOR:                    /* support old format */
  487.             Smptr->nfcolor[0] = s[1]-48;
  488.             Smptr->nbcolor[0] = s[0]-48;
  489.             Smptr->bfcolor[0] = s[5]-48;
  490.             Smptr->bbcolor[0] = s[4]-48;
  491.             Smptr->ufcolor[0] = s[3]-48;
  492.             Smptr->ubcolor[0] = s[2]-48;
  493.             constate = 0;
  494.             Sflags[CONNF-100] = 1;        /* sets them all at one shot */
  495.             Sflags[CONNB-100] = 1;
  496.             Sflags[CONBF-100] = 1;
  497.             Sflags[CONBB-100] = 1;
  498.             Sflags[CONUF-100] = 1;
  499.             Sflags[CONUB-100] = 1;
  500.             break;
  501.  
  502.         case CONNF:                        /* foreground normal color */
  503.             if (Scolorset(Smptr->nfcolor,s))
  504.                 Sflags[CONNF-100] = 1;
  505.             constate = 0;
  506.             break;
  507.         case CONNB:                        /* background normal color */
  508.             if (Scolorset(Smptr->nbcolor,s))
  509.                 Sflags[CONNB-100] = 1;
  510.             constate = 0;
  511.             break;
  512.         case CONRF:
  513.         case CONBF:                        /* blink foreg color */
  514.             if (Scolorset(Smptr->bfcolor,s))
  515.                 Sflags[CONBF-100] = 1;    /* in copyfrom, r's are really b's */
  516.             constate = 0;
  517.             break;
  518.         case CONRB:
  519.         case CONBB:                        /* blink bg color */
  520.             if (Scolorset(Smptr->bbcolor,s))
  521.                 Sflags[CONBB-100] = 1;
  522.             constate = 0;
  523.             break;
  524.         case CONUF:                        /* foreground underline color */
  525.             if (Scolorset(Smptr->ufcolor,s))
  526.                 Sflags[CONUF-100] = 1;
  527.             constate = 0;
  528.             break;
  529.         case CONUB:                        /* bg underline color */
  530.             if (Scolorset(Smptr->ubcolor,s))
  531.                 Sflags[CONUB-100] = 1;
  532.             constate = 0;
  533.             break;
  534.  
  535.         case CONBKSP:
  536.             if (!ncstrcmp(s,"backspace"))
  537.                 Smptr->bksp = 8;
  538.             else
  539.                 Smptr->bksp = 127;
  540.             constate = 0;
  541.             Sflags[CONBKSP-100] = 1;
  542.             break;
  543.  
  544.         case CONBKSC:
  545.             Smptr->bkscroll = atoi(s);
  546.             constate = 0;
  547.             Sflags[CONBKSC-100] = 1;
  548.             break;
  549.  
  550.         case CONRETR:
  551.             Smptr->retrans = atoi(s);
  552.             constate = 0;
  553.             Sflags[CONRETR-100] = 1;
  554.             break;
  555.  
  556.         case CONWIND:
  557.             Smptr->window = atoi(s);
  558.             constate = 0;
  559.             Sflags[CONWIND-100] = 1;
  560.             break;
  561.  
  562.         case CONSEG:
  563.             Smptr->maxseg = atoi(s);
  564.             constate = 0;
  565.             Sflags[CONSEG-100] = 1;
  566.             break;
  567.  
  568.         case CONMTU:
  569.             Smptr->mtu = atoi(s);
  570.             constate = 0;
  571.             Sflags[CONMTU-100] = 1;
  572.             break;
  573.  
  574.         case CONNS:
  575.             Smptr->nameserv = atoi(s);
  576.             if (!Sns || (Sns->nameserv > Smptr->nameserv))    /* keep NS */
  577.                 Sns = Smptr;
  578.             constate = 0;
  579.             Sflags[CONNS-100] = 1;
  580.             break;
  581.  
  582.         case CONTO:
  583.             i = atoi(s);
  584.             if (i > 2) {
  585.                 Smptr->conto = i;
  586.                 Sflags[CONTO-100] = 1;
  587.             }
  588.             constate = 0;
  589.             break;
  590.  
  591.         case CONCRMAP:
  592.             if (!ncstrcmp(s,"4.3BSDCRNUL")) 
  593.                 Smptr->crmap = 0;
  594.             else
  595.                 Smptr->crmap = 10;
  596.             Sflags[CONCRMAP-100] = 1;
  597.             constate = 0;
  598.             break;
  599.  
  600.         case CONDUP:
  601.             if (!ncstrcmp(s,"half")) {
  602.                 Smptr->halfdup = 1;
  603.                 Sflags[CONDUP-100] = 1;
  604.             }
  605.             constate = 0;
  606.             break;
  607.  
  608.         case CONWRAP:
  609.             if ('Y' == toupper(s[0])) 
  610.                 Smptr->vtwrap = 1;
  611.             else
  612.                 Smptr->vtwrap = 0;
  613.             Sflags[CONWRAP-100] = 1;
  614.             constate = 0;
  615.             break;
  616.  
  617.         case CONCLMODE:
  618.             if ('N' == toupper(s[0])) 
  619.                 Smptr->clearsave = 0;
  620.             else
  621.                 Smptr->clearsave = 1;
  622.             Sflags[CONCLMODE-100] = 1;
  623.             constate = 0;
  624.             break;
  625.  
  626.         case CONFONT:
  627.             Smptr->font = malloc(position);
  628.             strcpy(Smptr->font,s);
  629.             Sflags[CONFONT-100] = 1;
  630.             constate = 0;
  631.             break;
  632.  
  633.         case CONFSIZE:
  634.             Smptr->fsize = atoi(s);
  635.             Sflags[CONFSIZE-100] = 1;
  636.             constate = 0;
  637.             break;
  638.  
  639.         case CONWIDE:
  640.             if (132 == atoi(s)) 
  641.                 Smptr->vtwidth = 132;
  642.             else
  643.                 Smptr->vtwidth = 80;
  644.  
  645.             Sflags[CONWIDE-100] = 1;
  646.             constate = 0;
  647.             break;
  648.  
  649. /*
  650. *  now the one-time entries
  651. *  Generally this information goes into the "Scon" structure for later
  652. *  retrieval by other routines.
  653. *
  654. */
  655. #ifdef PC
  656.         case CONMASK:
  657.             if ( 4 != sscanf(s,"%d.%d.%d.%d",&a,&b,&c,&d)) {
  658.                 Serrline(907);
  659.                 return(3);
  660.             }
  661.             Scon.netmask[0]=a; Scon.netmask[1] =b;     
  662.             Scon.netmask[2]=c; Scon.netmask[3] =d;
  663.             Scon.havemask=1;
  664.             constate = 0;
  665.             break;
  666.  
  667.         case CONMYIP:
  668.             constate = 0;
  669.             if (!ncstrcmp(s,"rarp")) {
  670.                 movebytes(Scon.myipnum,s,4);
  671.                 netsetip("RARP");
  672.                 break;
  673.             }
  674.             if ( 4 != sscanf(s,"%d.%d.%d.%d",&a,&b,&c,&d)) {
  675.                 Serrline(908);
  676.                 return(3);
  677.             }
  678.             Scon.myipnum[0]=a; Scon.myipnum[1] =b;     /* put number back in s */
  679.             Scon.myipnum[2]=c; Scon.myipnum[3] =d;
  680.             netsetip(Scon.myipnum);        /* make permanent set */
  681.             break;
  682. #endif
  683.         case CONME:                /* what my name is  */
  684.             strncpy(Scon.me,s,30);
  685.             Scon.me[30] = '\0';
  686.             constate = 0;
  687.             break;
  688.  
  689.         case CONHW:                /* what hardware are we using? */
  690.             i = strlen(s);
  691.             if (i > 9) i = 9;
  692.             s[i] = '\0';
  693.             i--;
  694.             while (i--)
  695.                 s[i] = tolower(s[i]);
  696.             strcpy(Scon.hw,s);
  697.             constate = 0;
  698.             break;
  699.  
  700. #ifdef PC
  701.         case CONINT:            /* what IRQ to use */
  702.             sscanf(s,"%x",&i);
  703.             Scon.irqnum = i;
  704.             constate = 0;
  705.             break;
  706.  
  707.         case CONBIOS:
  708.             if (toupper(*s) == 'Y') {
  709.                 Scwritemode(0);
  710.                 Scon.bios = 1;
  711.             }
  712.             constate = 0;
  713.             break;
  714.  
  715.         case CONADDR:                /* segment address for board */
  716.             sscanf(s,"%x",&i);
  717.             Scon.address = i;
  718.             constate = 0;
  719.             break;
  720.  
  721.         case CONIOA:                /* io address for board */
  722.             sscanf(s,"%x",&i);
  723.             Scon.ioaddr = i;
  724.             constate = 0;
  725.             break;
  726. #endif
  727. #ifdef MAC
  728.         case CONCKEYS:
  729.             if (toupper(*s) == 'Y') {
  730.                 Scon.comkeys = 1;
  731.             }
  732.             constate = 0;
  733.             break;
  734.  
  735.         case CONZONE:
  736.             Scon.zone = malloc(position);    /* space for name */
  737.             strcpy(Scon.zone,s);            /* copy it in */
  738.             constate = 0;
  739.             break;
  740.  
  741.         case CONJTIME:                /* Time slice */
  742.             i = atoi(s);
  743.             if (i > 1)
  744.                 Scon.timesl = i;
  745.             constate = 0;
  746.             break;
  747. #endif        
  748.  
  749.         case CONTEK:
  750.             if (toupper(*s) == 'N') {
  751.                 Stekmode(0);
  752.                 Scon.tek = 0;
  753.             }
  754.             constate = 0;
  755.             break;
  756.  
  757.         case CONVIDEO:
  758.             i = strlen(s);
  759.             if (i > 9) i = 9;
  760.             s[i] = '\0';
  761.             strcpy(Scon.video,s);
  762.             i--;
  763.             while (i--)
  764.                 s[i] = tolower(s[i]);
  765.             constate = 0;
  766.             break;
  767.  
  768.         case CONTTYPE:
  769.             Scon.termtype = malloc(position);
  770.             strcpy(Scon.termtype,s);
  771.             constate = 0;
  772.             break;
  773.  
  774.         case CONCCOL:
  775.             for (i=0; i<3; i++)
  776.                 Scon.color[i] = ((s[i*2]-48)<<4) + (s[i*2+1]-48);
  777.             constate = 0;
  778.             break;
  779.  
  780.         case CONFTP:
  781.             if (toupper(*s) == 'N') 
  782.                 Scon.ftp = 0;    
  783.             constate = 0;
  784.             break;
  785.  
  786.         case CONRCP:
  787.             if (toupper(*s) == 'N')
  788.                 Scon.rcp = 0;
  789.             constate = 0;
  790.             break;
  791.  
  792.         case CONPASS:
  793.             Scon.pass = malloc(position);    /* space for name */
  794.             strcpy(Scon.pass,s);            /* copy it in */
  795.             constate = 0;
  796.             break;
  797.  
  798.         case CONDEF:                        /* default domain */
  799.             Scon.defdom = malloc(position);    /* space for name */
  800.             strcpy(Scon.defdom,s);            /* copy it in */
  801.             constate = 0;
  802.             break;
  803.  
  804.         case CONCAP:                        /* capture file name */
  805.             Snewcap(s);
  806.             constate = 0;
  807.             break;
  808.  
  809.         case CONFROM:                        /* copy the rest from another */
  810.                                             /* entry in the table */
  811.             if (Scopyfrom(s))
  812.                 return(1);
  813.             Sflags[0] = 1;                    /* indicate did copy from */
  814.             constate = 0;
  815.             break;
  816.  
  817.         case CONARPTO:                /* need to lengthen arp time-out (secs) */
  818.             i = atoi(s);
  819.             if (i > 0)
  820.                 netarptime(i);
  821.             constate = 0;            /* don't forget me! */
  822.             break;
  823.  
  824.         case CONDOMTO:                /* DOMAIN timeout value */
  825.             i = atoi(s);
  826.             if (i > 1)
  827.                 Scon.domto = i;
  828.             constate = 0;
  829.             break;
  830.  
  831.         case CONNDOM:                /* DOMAIN number of retries */
  832.             i = atoi(s);
  833.             if (i > 1)
  834.                 Scon.ndom = i;
  835.             constate = 0;
  836.             break;
  837.  
  838.         case CONHPF:                /* File name for HP dump */
  839.             Snewhpfile(s);
  840.             constate = 0;
  841.             break;
  842.  
  843.         case CONPSF:                /* File name for PS dump */
  844.             Snewpsfile(s);
  845.             constate = 0;
  846.             break;
  847.  
  848.         case CONTEKF:                /* File name for Tek dump */
  849.             Snewtekfile(s);
  850.             constate = 0;
  851.             break;
  852.  
  853.         default:
  854.             constate = 0;
  855.             break;
  856.     }
  857.  
  858.     return(0);
  859. }
  860.  
  861. /************************************************************************/
  862. /*  Scopyfrom
  863. *   Look at the Sflags array to determine which elements to copy from
  864. *   a previous machine's entries.  If a machine name as been given as
  865. *   "default", the state machine will fill in the fields from that
  866. *   machine's entries.
  867. *
  868. *   If the machine name to copyfrom is not present in the list, set the
  869. *   program default values for each field.
  870. */
  871. Scopyfrom(s)
  872.     char *s;
  873.     {
  874.     struct machinfo *m;
  875.     int i;
  876.  
  877.     m = Shostlook(s);            /* search list */
  878.  
  879.     for (i=3; i <= NUMSPECS-100; i++)         /* through list of parms */
  880.         if (!Sflags[i]) {
  881.             if (m)                             /* copy old value */
  882.             switch (100+i) {
  883.                 case CONHOST:
  884.                     Smptr->hname = m->hname;
  885.                     break;
  886.                 case CONIP:
  887.                     movebytes(Smptr->hostip,m->hostip,4);
  888.                     Smptr->mstat = m->mstat;
  889.                     break;
  890.                 case CONGATE:            /* gateways cannot be copied from */
  891.                     Smptr->gateway = 0;
  892.                     break;
  893.                 case CONNS:                    /* can't copy nameservers either */
  894.                     Smptr->nameserv = 0;
  895.                     break;
  896.  
  897.                 case CONBKSP:
  898.                     Smptr->bksp = m->bksp;
  899.                     break;
  900.                 case CONBKSC:
  901.                     Smptr->bkscroll = m->bkscroll;
  902.                     break;
  903.                 case CONCLMODE:
  904.                     Smptr->clearsave = m->clearsave;
  905.                     break;
  906.                 case CONRETR:
  907.                     Smptr->retrans = m->retrans;
  908.                     break;
  909.                 case CONWIND:
  910.                     Smptr->window = m->window;
  911.                     break;
  912.                 case CONSEG:
  913.                     Smptr->maxseg = m->maxseg;
  914.                     break;
  915.                 case CONMTU:
  916.                     Smptr->mtu = m->mtu;
  917.                     break;
  918.  
  919.                 case CONTO:
  920.                     Smptr->conto = m->conto;
  921.                     break;
  922.                 case CONCRMAP:
  923.                     Smptr->crmap = m->crmap;
  924.                     break;
  925.                 case CONDUP:
  926.                     Smptr->halfdup = m->halfdup;
  927.                     break;
  928.                 case CONWRAP:
  929.                     Smptr->vtwrap = m->vtwrap;
  930.                     break;
  931.                 case CONWIDE:
  932.                     Smptr->vtwidth = m->vtwidth;
  933.                     break;
  934.  
  935.                 case CONNF:
  936.                     movebytes(Smptr->nfcolor,m->nfcolor,3*sizeof(int));
  937.                     break;
  938.                 case CONNB:
  939.                     movebytes(Smptr->nbcolor, m->nbcolor,3*sizeof(int));
  940.                     break;
  941.                 case CONBF:
  942.                     movebytes(Smptr->bfcolor,m->bfcolor,3*sizeof(int));
  943.                     break;
  944.                 case CONBB:
  945.                     movebytes(Smptr->bbcolor,m->bbcolor,3*sizeof(int));
  946.                     break;
  947.                 case CONUF:
  948.                     movebytes(Smptr->ufcolor,m->ufcolor,3*sizeof(int));
  949.                     break;
  950.                 case CONUB:
  951.                     movebytes(Smptr->ubcolor,m->ubcolor,3*sizeof(int));
  952.                     break;
  953.  
  954.                 case CONFONT:
  955.                     Smptr->font = m->font;
  956.                     break;
  957.                 case CONFSIZE:
  958.                     Smptr->fsize = m->fsize;
  959.                     break;
  960.  
  961.                 default:
  962.                     break;
  963.             }
  964.             else
  965.             switch (100+i) {        /* m=NULL, install default values */
  966.                 case CONHOST:
  967.                     Smptr->hname = NULL;
  968.                     break;
  969.                 case CONIP:
  970.                     Smptr->mstat = NOIP;
  971.                     break;
  972.                 case CONGATE:            /* gateways cannot be copied from */
  973.                     Smptr->gateway = 0;
  974.                     break;
  975.                 case CONBKSP:
  976.                     Smptr->bksp = 127;
  977.                     break;
  978.                 case CONBKSC:
  979.                     Smptr->bkscroll = 0;
  980.                     break;
  981.                 case CONCLMODE:
  982.                     Smptr->clearsave = 1;
  983.                     break;
  984.                 case CONRETR:
  985.                     Smptr->retrans = SMINRTO;
  986.                     break;
  987.                 case CONWIND:
  988. #ifdef MAC
  989.                     Smptr->window = 512;
  990. #else
  991.                     Smptr->window = DEFWINDOW;
  992. #endif
  993.                     break;
  994.                 case CONSEG:
  995. #ifdef MAC
  996.                     Smptr->maxseg = 512;
  997. #else
  998.                     Smptr->maxseg = DEFSEG;
  999. #endif
  1000.                     break;
  1001.                 case CONMTU:
  1002. #ifdef MAC
  1003.                     Smptr->mtu = 512;
  1004. #else
  1005.                     Smptr->mtu = TSENDSIZE;
  1006. #endif
  1007.                     break;
  1008.  
  1009.                 case CONNS:                    /* can't copy nameservers either */
  1010.                     Smptr->nameserv = 0;
  1011.                     break;
  1012.         
  1013.                 case CONTO:
  1014.                     Smptr->conto = CONNWAITTIME;
  1015.                     break;
  1016.  
  1017.                 case CONCRMAP:
  1018.                     Smptr->crmap = 10;
  1019.                     break;
  1020.  
  1021.                 case CONDUP:
  1022.                     Smptr->halfdup = 0;
  1023.                     break;
  1024.                 case CONWRAP:
  1025.                     Smptr->vtwrap = 0;
  1026.                     break;
  1027.                 case CONWIDE:
  1028.                     Smptr->vtwidth = 80;
  1029.                     break;
  1030.                 case CONNF:
  1031.                     movebytes(Smptr->nfcolor,Sxxnf,3*sizeof(int));
  1032.                     break;
  1033.                 case CONNB:
  1034.                     movebytes(Smptr->nbcolor,Sxxnb,3*sizeof(int));
  1035.                     break;
  1036.                 case CONBF:
  1037.                     movebytes(Smptr->bfcolor,Sxxbf,3*sizeof(int));
  1038.                     break;
  1039.                 case CONBB:
  1040.                     movebytes(Smptr->bbcolor,Sxxbb,3*sizeof(int));
  1041.                     break;
  1042.                 case CONUF:
  1043.                     movebytes(Smptr->ufcolor,Sxxuf,3*sizeof(int));
  1044.                     break;
  1045.                 case CONUB:
  1046.                     movebytes(Smptr->ubcolor,Sxxub,3*sizeof(int));
  1047.                     break;
  1048.  
  1049.                 case CONFONT:
  1050.                     Smptr->font = "Monaco";
  1051.                     break;
  1052.                 case CONFSIZE:
  1053.                     Smptr->fsize = 9;
  1054.                     break;
  1055.                 default:
  1056.                     break;
  1057.             }
  1058.         }
  1059.  
  1060.     Sflags[0] = 1;                    /* set that this machine was copied */
  1061.     return(0);
  1062. }
  1063.  
  1064. /************************************************************************/
  1065. /*  Smadd
  1066. *   If machine is there, just returns pointer, else
  1067. *   Add a machine to the list. Increments machine number of machine.
  1068. *   Puts in parameters copied from the "default" entry.
  1069. *
  1070. */
  1071. struct machinfo 
  1072. *Smadd(mname)
  1073.     char *mname;
  1074.     {
  1075.     int i;
  1076.     struct machinfo *m;
  1077. /*
  1078. *  First, do we have the name already?
  1079. */
  1080.     m = Shostlook(mname);
  1081.     if (m)
  1082.         return(m);
  1083. /*
  1084. *   Don't have name, add another record
  1085. */
  1086.     Smptr = (struct machinfo *)malloc(sizeof(struct machinfo));
  1087.     if (Smptr == NULL)
  1088.         return(NULL);
  1089.  
  1090.     for (i=0; i < NUMSPECS-99; i++)
  1091.         Sflags[i] = 0;                    /* we have no parms */
  1092.     Scopyfrom("default");
  1093.  
  1094.     Smptr->sname = NULL;
  1095.     Smptr->hname = malloc(strlen(mname)+1);
  1096.     if (Smptr->hname)
  1097.         strcpy(Smptr->hname,mname);        /* copy in name of machine */
  1098.     Smptr->mno = ++mno;
  1099.     Smptr->mstat = NOIP;
  1100.  
  1101.     Smptr->next = Smachlist;            /* add to front of machlist */
  1102.     Smachlist = Smptr;
  1103.  
  1104.     return(Smptr);
  1105.  
  1106. }
  1107.  
  1108.  
  1109. /************************************************************************/
  1110. /* Shostfile
  1111. *   if the user wants to change the host file name from 'config.tel' to
  1112. *   something else.
  1113. */
  1114. Shostfile(ptr)
  1115.     char *ptr;
  1116.     {
  1117.     Smachfile = ptr;    
  1118. /*
  1119. *  note that the area with the file name must stay allocated for
  1120. *  later reference, typically it is in some argv[] parm.
  1121. */
  1122.  
  1123. }
  1124.  
  1125. /************************************************************************/
  1126. /*  get host by name
  1127. *   Given the name of a host machine, search our database to see if we
  1128. *   have that host ip number.  Search first the name field, and then the
  1129. *   hostname field.  If the IP # is given, returns a ptr to the
  1130. *   default machine record with that IP # installed.
  1131. *   Returns the pointer to a valid record, or NULL if the IP # cannot
  1132. *   be deciphered.  
  1133. */
  1134. struct machinfo 
  1135. *Sgethost(machine)
  1136.     char *machine;
  1137.     {
  1138.     int i,j,k,l;
  1139.     unsigned char ipto[4],myipnum[4],xmask[4];
  1140.     unsigned long hnum;
  1141.     struct machinfo *m;
  1142.  
  1143.     m = NULL;
  1144. /*
  1145. *  First, check for the pound sign character which means we should use
  1146. *  the current netmask to build an IP number for the local network.
  1147. *  Take the host number, install it in the ipto[] array.  Then mask
  1148. *  in my IP number's network portion to build the final IP address.
  1149. */
  1150.  
  1151.     if ('#' == machine[0]) {        /* on my local network */
  1152.         netgetip(myipnum);
  1153.         netgetmask(xmask);            /* mask of network portion of IP # */
  1154.  
  1155.         sscanf(&machine[1],"%ld",&hnum);/* host number for local network */
  1156.         for (i=3; i >= 0; i--) {
  1157.             ipto[i] = hnum & 255L;    /* take off a byte */
  1158.             hnum >>= 8;                /* shift it over */
  1159.         }
  1160.  
  1161.         for (i=0; i < 4; i++) 
  1162.             ipto[i] |= (myipnum[i] & xmask[i]);        /* mask new one in */
  1163.  
  1164.     }
  1165. /*
  1166. *  next, is it an IP number?  We take it if the number is in four
  1167. *  parts, separated by periods.
  1168. */
  1169.     else 
  1170.     if (4 == sscanf(machine,"%d.%d.%d.%d",&i,&j,&k,&l)) {    /* given ip num */
  1171.         ipto[0] = i;
  1172.         ipto[1] = j;
  1173.         ipto[2] = k;
  1174.         ipto[3] = l;
  1175.     }
  1176. /*
  1177. *  lastly, it must be a name, first check the local host table
  1178. *  A first number of 127 means that it doesn't have an IP number, but
  1179. *  is in the table (strange occurrence)
  1180. */
  1181.     else {                                    /* look it up */
  1182.  
  1183.         m = Shostlook(machine);
  1184.         if (m == NULL) {
  1185.             netposterr(805);            /* informative */
  1186.             return(NULL);
  1187.         } 
  1188.         if (m->mstat < HAVEIP) {
  1189.             netposterr(806);            /* informative */
  1190.             return(NULL);
  1191.         }
  1192.     }
  1193.  
  1194.     if (!m) {
  1195.         m = Shostlook("default");
  1196.         movebytes(m->hostip,ipto,4);        /* copy in newest host # */
  1197.         m->mstat = HAVEIP;                    /* we have the IP # */
  1198.     }
  1199.  
  1200.     return(m);
  1201. }
  1202.  
  1203. /************************************************************************/
  1204. /*  Shostlook
  1205. *   The straightforward list searcher.  Looks for either the
  1206. *   session name matching or the host name matching.  NULL if neither.
  1207. */
  1208. struct machinfo 
  1209. *Shostlook(hname)
  1210.     char *hname;
  1211.     {
  1212.     struct machinfo *m;
  1213.     m = Smachlist;
  1214.     while (m != NULL) {
  1215.  
  1216.         if (m->sname && !ncstrcmp(hname,m->sname)) 
  1217.             return(m);
  1218.  
  1219.         m = m->next;
  1220.     }
  1221.  
  1222.     m = Smachlist;
  1223.     while (m != NULL) {
  1224.         if (m->hname && !ncstrcmp(hname,m->hname))
  1225.             return(m);
  1226.  
  1227.         m = m->next;
  1228.     }
  1229.  
  1230.     return(NULL);
  1231.  
  1232. }
  1233.  
  1234. /************************************************************************/
  1235. /*  Slooknum
  1236. *   get the host record by machine number, used primarily in DOMAIN name
  1237. *   lookup.
  1238. */
  1239. struct machinfo 
  1240. *Slooknum(num)
  1241.     int num;
  1242.     {
  1243.     struct machinfo *m;
  1244.  
  1245.     m = Smachlist;
  1246.     while (m) {
  1247.         if (m->mno == num)
  1248.             return(m);
  1249.         m = m->next;
  1250.     }
  1251.  
  1252.     return(NULL);
  1253.  
  1254. }
  1255.  
  1256. /**************************************************************************/
  1257. /*  Slookip
  1258. *   For FTP to look up the transfer options to use when running
  1259. *
  1260. */
  1261. struct machinfo 
  1262. *Slookip(ipnum)
  1263.     unsigned char *ipnum;
  1264.     {
  1265.     struct machinfo *m;
  1266.  
  1267.     m = Smachlist;
  1268.     while (m) {
  1269.         if (comparen(m->hostip,ipnum,4))
  1270.             return(m);
  1271.         m = m->next;
  1272.     }
  1273.  
  1274.     return(NULL);
  1275.  
  1276. }
  1277.  
  1278. /**************************************************************************/
  1279. /*  Sissep
  1280. *   is the character a valid separator for the hosts file?
  1281. *   separators are white space, special chars and :;=
  1282. *
  1283. */
  1284. Sissep(c)
  1285.     int c;
  1286.     {
  1287.     if (c < 33)
  1288.         return(1);
  1289.     if (c == ':' || c == ';' || c == '=')
  1290.         return(1);
  1291.     return(0);
  1292. }
  1293.  
  1294. /*********************************************************************/
  1295. /*  Snewns()
  1296. *   Rotate to the next nameserver
  1297. *   Chooses the next highest number from the nameserv field
  1298. */
  1299. Snewns()
  1300.     {
  1301.     struct machinfo *m,*low;
  1302.     int i;
  1303.  
  1304.     if (!Sns)                    /* safety, should never happen */
  1305.         Sns = Smachlist;
  1306.  
  1307.     low = Sns;
  1308.     i = Sns->nameserv;            /* what is value now? */
  1309.  
  1310.     m = Smachlist;
  1311.     while (m) {
  1312.         if (m->nameserv == i+1) {
  1313.             Sns = m;
  1314.             return(0);
  1315.         }
  1316.         if ((m->nameserv > 0) && (m->nameserv < low->nameserv))
  1317.             low = m;
  1318.         m = m->next;
  1319.     }
  1320.  
  1321.     if (Sns == low)
  1322.         return(1);                /* no alternate */
  1323.     else
  1324.         Sns = low;
  1325.  
  1326.     return(0);
  1327. }
  1328.  
  1329.  
  1330. Ssetns(ipn)
  1331.     unsigned char ipn[4];
  1332.     {
  1333.     struct machinfo *m;
  1334.     int i;
  1335.  
  1336.     i = 0;
  1337.     if (NULL == (m = Slookip(ipn))) {        /* have already? */
  1338.         m = Smadd("=nameserv=");
  1339.         movebytes(m->hostip,ipn,4);
  1340.         m->mstat = FROMKIP;
  1341.         i = 1;
  1342.     }
  1343.  
  1344.     m->nameserv = 1;
  1345.     Sns = m;
  1346.  
  1347.     return(i);
  1348. }
  1349.  
  1350. /************************************************************************/
  1351. /*  setgates
  1352. *   set up the gateway machines and the subnet mask after netinit()
  1353. *   and start up ftp and rcp for them.
  1354. */
  1355. Ssetgates()
  1356.     {
  1357.     struct machinfo *m;
  1358.     int level,again;
  1359.  
  1360.     if (Scon.havemask)                    /* leave default unless specified */
  1361.         netsetmask(Scon.netmask);
  1362. /*
  1363. *  Search the list of machines for gateway flags.
  1364. *  Invoke netsetgate in increasing order of gateway level #s.
  1365. *  Terminates when it gets through list without finding next higher number.
  1366. */
  1367.     level = 0;
  1368.     do {
  1369.         level++;
  1370.         again = 0;
  1371.         m = Smachlist;
  1372.         while (m != NULL) {
  1373.             if (m->gateway == level && m->mstat >= HAVEIP) 
  1374.                 netsetgate(m->hostip);
  1375.             if (m->gateway == level+1)
  1376.                 again=1;
  1377.             m = m->next;
  1378.         }
  1379.     } while (again);
  1380.  
  1381.     Sftpmode(Scon.ftp);
  1382. #ifdef PC
  1383.     Srcpmode(Scon.rcp);
  1384. #endif
  1385.     return(0);
  1386. }
  1387.