home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / ckv197.zip / ckcmai.c < prev    next >
C/C++ Source or Header  |  2000-02-20  |  116KB  |  3,237 lines

  1. /*
  2.   ckcsym.h is used for for defining symbols that normally would be defined
  3.   using -D or -d on the cc command line, for use with compilers that don't
  4.   support this feature.  Must be before any tests for preprocessor symbols.
  5. */
  6. #include "ckcsym.h"
  7.  
  8. /*
  9.   Consolidated program version information (for UNIX also see ckuver.h).
  10.   See makever() below for how they are used.
  11. */
  12. #ifdef COMMENT
  13. #ifndef OS2                             /* Remove this for release */
  14. #ifndef BETATEST
  15. #define BETATEST
  16. #endif /* BETATEST */
  17. #endif /* OS2 */
  18. #endif /* COMMENT */
  19.  
  20. #ifdef BETATEST
  21. #ifdef OS2
  22. #ifdef __DATE__
  23. #define BETADATE
  24. #endif /* __DATE__ */
  25. #endif /* OS2 */
  26. #endif /* BETATEST */
  27.  
  28. #ifndef MAC
  29. /*
  30.   Note: initialize ck_s_test to "" if this is not a test version.
  31.   (*ck_s_test != '\0') can be used to decide whether to print
  32.   test-related messages.
  33. */
  34. #ifdef BETATEST
  35. char *ck_s_test = "Beta";               /* "Alpha", "Beta", or "" */
  36. char *ck_s_tver = "11+";        /* Test version number or "" */
  37. #else
  38. char *ck_s_test = "";                   /* Not a test */
  39. char *ck_s_tver = "";
  40. #endif /* BETATEST */
  41. #else /* MAC */
  42. char *ck_s_test = "Pre-Alpha";          /* Mac Kermit is always a test... */
  43. char *ck_s_tver = "";
  44. #endif /* MAC */
  45.  
  46. #ifdef BETADATE                         /* Date of this version or edit */
  47. char *ck_s_date = __DATE__;             /* Compilation date */
  48. #else
  49. char *ck_s_date = "8 Feb 2000";        /* Hand-crafted date */
  50. #endif /* BETADATE */
  51.  
  52. #ifdef UNIX
  53. static char sccsid[] = "@(#)C-Kermit 7.0.197";
  54. #endif /* UNIX */
  55.  
  56. char *ck_s_ver = "7.0.197";             /* C-Kermit version string */
  57. long  ck_l_ver = 700197L;               /* C-Kermit version number */
  58.  
  59. #ifdef OS2
  60. char *ck_s_xver = "1.1.19";             /* Product-specific version string */
  61. long  ck_l_xver = 1119L;                /* Product-specific version number */
  62. #else
  63. #ifdef MAC
  64. char *ck_s_xver = "0.995";              /* Product-specific version string */
  65. long  ck_l_xver = 995L;                 /* Product-specific version number */
  66. #else
  67. char *ck_s_xver = "";                   /* Don't touch these... */
  68. long  ck_l_xver = 0L;                   /* they are filled in at runtime */
  69. #endif /* MAC */
  70. #endif /* OS2 */
  71.  
  72. #ifdef OS2
  73. char *ck_s_name = "Kermit 95";          /* Program name */
  74. #else
  75. #ifdef MAC
  76. char *ck_s_name = "Mac Kermit";
  77. #else
  78. char *ck_s_name = "C-Kermit";
  79. #endif /* MAC */
  80. #endif /* OS2 */
  81.  
  82. char *ck_s_who = "";                    /* Where customized, "" = not. */
  83. char *ck_patch = "";                    /* Patch info, if any. */
  84.  
  85. #define CKVERLEN 128
  86. char versiox[CKVERLEN];                 /* Version string buffer  */
  87. char *versio = versiox;                 /* These are filled in at */
  88. long vernum, xvernum;                   /* runtime from above.    */
  89.  
  90. #define CKCMAI
  91.  
  92. #include "ckcasc.h"                     /* ASCII character symbols */
  93. #include "ckcdeb.h"                     /* Debug & other symbols */
  94.  
  95. char * myname = NULL;                   /* The name I am called by */
  96.  
  97. /*  C K C M A I  --  C-Kermit Main program  */
  98.  
  99. /*
  100.   Author: Frank da Cruz (fdc@columbia.edu),
  101.   Columbia University Academic Information Systems, New York City.
  102.  
  103. COPYRIGHT NOTICE:
  104. */
  105.  
  106. char *copyright[] = {
  107.  
  108. #ifdef pdp11
  109. "Copyright (C) 1985, 2000, Trustees of Columbia University, NYC.",
  110. "All rights reserved.",
  111. " ",
  112. #else
  113. #ifdef OS2
  114. "Copyright (C) 1985, 2000, Trustees of Columbia University in the City of New",
  115. "York.  All rights reserved.  This software is furnished under license",
  116. "and may not be reproduced without license to do so.  This copyright notice",
  117. "must not be removed, altered, or obscured.",
  118. " ",
  119. "  THIS SOFTWARE IS PROVIDED AS IS, WITHOUT REPRESENTATION FROM THE",
  120. "  TRUSTEES OF COLUMBIA UNIVERSITY IN THE CITY OF NEW YORK AS TO ITS",
  121. "  FITNESS FOR ANY PURPOSE, AND WITHOUT WARRANTY BY THE TRUSTEES OF",
  122. "  COLUMBIA UNIVERSITY IN THE CITY OF NEW YORK OF ANY KIND, EITHER",
  123. "  EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED",
  124. "  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.",
  125. "  THE TRUSTEES OF COLUMBIA UNIVERSITY IN THE CITY OF NEW YORK SHALL NOT",
  126. "  BE LIABLE FOR ANY DAMAGES, INCLUDING SPECIAL, INDIRECT, INCIDENTAL,",
  127. "  OR CONSEQUENTIAL DAMAGES, WITH RESPECT TO ANY CLAIM ARISING OUT OR IN",
  128. "  CONNECTION WITH THE USE OF THE SOFTWARE, EVEN IF IT HAS BEEN OR IS",
  129. "  HEREAFTER ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.  YOU SHALL",
  130. "  INDEMNIFY AND HOLD HARMLESS THE TRUSTEES OF COLUMBIA UNIVERSITY IN",
  131. "  THE CITY OF NEW YORK, ITS EMPLOYEES AND AGENTS FROM AND AGAINST ANY",
  132. "  AND ALL CLAIMS, DEMANDS, LOSS, DAMAGE OR EXPENSE (INCLUDING",
  133. "  ATTORNEYS' FEES) ARISING OUT OF YOUR USE OF THIS SOFTWARE.",
  134. " ",
  135. #else
  136. "Copyright (C) 1985, 2000,",
  137. "  The Trustees of Columbia University in the City of New York.",
  138. "  All rights reserved.",
  139. " ",
  140. "PERMISSIONS:",
  141. " ",
  142. "The C-Kermit software may be obtained directly from the Kermit Project at",
  143. "Columbia University (or from any source explicitly licensed by the Kermit",
  144. "Project or implicitly licensed by Clause (A) below) by any individual for",
  145. "his or her OWN USE, and by any company or other organization for its own",
  146. "INTERNAL DISTRIBUTION and use, including installation on servers that are",
  147. "accessed by customers or clients, WITHOUT EXPLICIT LICENSE.",
  148. " ",
  149. "Conditions for REDISTRIBUTION are as follows:",
  150. " ",
  151. "(A) The C-Kermit software, in source and/or binary form, may be",
  152. "    included WITHOUT EXPLICIT LICENSE in distributions of OPERATING",
  153. "    SYSTEMS that have OSI (Open Source Initiative, www.opensource.org)",
  154. "    approved licenses, even if non-Open-Source applications (but not",
  155. "    operating systems) are included in the same distribution.  Such",
  156. "    distributions include, but are not limited to, CD-ROM, FTP site,",
  157. "    Web site, or preinstalled software on a new GENERAL-PURPOSE",
  158. "    computer, as long as the primary character of the distribution is",
  159. "    an Open Source operating system with accompanying utilities.  The",
  160. "    C-Kermit source code may not be changed without the consent of the",
  161. "    Kermit Project, which will not be unreasonably withheld (this is",
  162. "    simply a matter of keeping a consistent and supportable code base).",
  163. " ",
  164. "(B) Inclusion of C-Kermit software in whole or in part, in any form, in",
  165. "    or with any product not covered by Clause (A), or its distribution",
  166. "    by any commercial enterprise to its actual or potential customers",
  167. "    or clients except as in Clause (A), requires a license from the",
  168. "    Kermit Project, Columbia University; contact kermit@columbia.edu.",
  169. " ",
  170. "The name of Columbia University may not be used to endorse or promote",
  171. "products derived from or including the C-Kermit software without specific",
  172. "prior written permission.",
  173. " ",
  174. "DISCLAIMER:",
  175. " ",
  176. "  THIS SOFTWARE IS PROVIDED AS IS, WITHOUT REPRESENTATION FROM THE",
  177. "  TRUSTEES OF COLUMBIA UNIVERSITY IN THE CITY OF NEW YORK AS TO ITS",
  178. "  FITNESS FOR ANY PURPOSE, AND WITHOUT WARRANTY BY THE TRUSTEES OF",
  179. "  COLUMBIA UNIVERSITY IN THE CITY OF NEW YORK OF ANY KIND, EITHER",
  180. "  EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED",
  181. "  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.",
  182. "  THE TRUSTEES OF COLUMBIA UNIVERSITY IN THE CITY OF NEW YORK SHALL NOT",
  183. "  BE LIABLE FOR ANY DAMAGES, INCLUDING SPECIAL, INDIRECT, INCIDENTAL,",
  184. "  OR CONSEQUENTIAL DAMAGES, WITH RESPECT TO ANY CLAIM ARISING OUT OF OR",
  185. "  IN CONNECTION WITH THE USE OF THE SOFTWARE, EVEN IF IT HAS BEEN OR IS",
  186. "  HEREAFTER ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.  YOU SHALL",
  187. "  INDEMNIFY AND HOLD HARMLESS THE TRUSTEES OF COLUMBIA UNIVERSITY IN",
  188. "  THE CITY OF NEW YORK, ITS EMPLOYEES AND AGENTS FROM AND AGAINST ANY",
  189. "  AND ALL CLAIMS, DEMANDS, LOSS, DAMAGE OR EXPENSE (INCLUDING",
  190. "  ATTORNEYS' FEES) ARISING OUT OF YOUR USE OF THIS SOFTWARE.",
  191. " ",
  192. "The above copyright notice, permissions notice, and disclaimer may not be",
  193. "removed, altered, or obscured and shall be included in all copies of the",
  194. "C-Kermit software.  The Trustees of Columbia University in the City of",
  195. "New York reserve the right to revoke this permission if any of the terms",
  196. "of use set forth above are breached.",
  197. #endif /* OS2 */
  198. #endif /* pdp11 */
  199.  
  200. #ifdef OS2
  201. "Portions Copyright (C) 1995, Oy Online Solutions Ltd., Jyvaskyla, Finland.",
  202. #endif /* OS2 */
  203.  
  204. #ifdef CK_AUTHENTICATION
  205. "Portions Copyright (C) 1990, Massachusetts Institute of Technology.",
  206. #ifdef CK_ENCRYPTION
  207. "Portions Copyright (C) 1991, 1993 Regents of the University of California.",
  208. "Portions Copyright (C) 1991, 1992, 1993, 1994, 1995 by AT&T.",
  209. "Portions Copyright (C) 1995, 1997, Eric Young <eay@cryptosoft.com>.",
  210. #endif /* CK_ENCRYPTION */
  211. #ifdef CK_SRP
  212. "Portions Copyright (C) 1997, Stanford University.",
  213. #endif /* CK_SRP */
  214. #endif /* CK_AUTHENTICATION */
  215.  
  216. #ifndef pdp11
  217. " ",
  218. "For further information, contact the Kermit Project, Columbia University,",
  219. "612 West 115th Street, New York NY 10025-7799, USA; phone +1 (212) 854 3703,",
  220. "fax +1 (212) 663 8202 or +1 (212) 662 6442, email kermit@columbia.edu,",
  221. "Web http://www.columbia.edu/kermit/ or http://www.kermit-project.org/.",
  222. #endif /* pdp11 */
  223. ""};
  224.  
  225. /*
  226. DOCUMENTATION:
  227.  
  228.  "Using C-Kermit" by Frank da Cruz and Christine M. Gianone,
  229.   Digital Press / Butterworth-Heinemann, Woburn MA, USA.
  230.   Second edition (1997), ISBN 1-55558-164-1.
  231.   Order from Digital Press:    +1 (800) 366-2665
  232.   Or from Columbia University: +1 (212) 854-3703
  233.  
  234. For Kermit 95, also:
  235.  
  236.   "Kermit 95" by Christine M. Gianone and Frank da Cruz,
  237.   Manning Publications, Greenwich CT, USA (1998) - Online.
  238.  
  239. ACKNOWLEDGMENTS:
  240.  
  241.   The Kermit file transfer protocol was developed at the Columbia University
  242.   Center for Computing Activities (CUCCA), which was since renamed to Columbia
  243.   University Academic Information Systems (AcIS).  Kermit is named after
  244.   Kermit the Frog, star of the television series THE MUPPET SHOW; the name is
  245.   used by permission of Henson Associates, Inc.
  246.  
  247.   Thanks to at least the following people for their contributions to this
  248.   program over the years, and apologies to anyone who was inadvertantly
  249.   omitted:
  250.  
  251.    Chris Adie, Edinburgh U, Scotland (OS/2)
  252.    Robert Adsett, University of Waterloo, Canada
  253.    Larry Afrin, Clemson U
  254.    Jeffrey Altman, Columbia University
  255.    Greg Andrews, Telebit Corp
  256.    Barry Archer, U of Missouri
  257.    Robert Andersson, International Systems A/S, Oslo, Norway
  258.    Chris Armstrong, Brookhaven National Lab (OS/2)
  259.    William Bader, Software Consulting Services, Nazareth, PA
  260.    Fuat Baran, Columbia U
  261.    Stan Barber, Rice U
  262.    Jim Barbour, U of Colorado
  263.    Donn Baumgartner, Dell
  264.    Nelson Beebe, U of Utah
  265.    Gerry Belanger, Cognitronics
  266.    Karl Berry, UMB
  267.    Mark Berryman, SAIC
  268.    Dean W Bettinger, SUNY
  269.    Gary Bilkus
  270.    Peter Binderup, Denmark
  271.    David Bolen, Advanced Networks and Services, Inc.
  272.    Marc Boucher, U of Montreal
  273.    Charles Brooks, EDN
  274.    Bob Brown
  275.    Mike Brown, Purdue U
  276.    Jack Bryans, California State U at Long Beach
  277.    Mark Buda, DEC (VMS)
  278.    Fernando Cabral, Padrao iX, Brasilia
  279.    Bjorn Carlsson, Stockholm University Computer Centre QZ, Sweden
  280.    Bill Catchings, (formerly of) Columbia U
  281.    Bob Cattani, Columbia U CS Dept
  282.    Davide Cervone, Rochester U
  283.    Seth Chaiklin, Denmark
  284.    John Chandler, Harvard U / Smithsonian Astronomical Observatory
  285.    Bernard Chen, UCLA
  286.    Andrew A Chernov, RELCOM Team, Moscow
  287.    John L Chmielewski, AT&T, Lisle, IL
  288.    Howard Chu, U of Michigan
  289.    Bill Coalson, McDonnell Douglas
  290.    Bertie Coopersmith, London
  291.    Chet Creider, U of Western Ontario
  292.    Alan Crosswell, Columbia U
  293.    Jeff Damens, (formerly of) Columbia U
  294.    Mark Davies, Bath U, UK
  295.    Sin-itirou Dezawa, Fujifilm, Japan
  296.    Joe R. Doupnik, Utah State U
  297.    Frank Dreano, Honeywell
  298.    John Dunlap, U of Washington
  299.    Alex Dupuy, SMART.COM
  300.    David Dyck, John Fluke Mfg Co.
  301.    Stefaan A. Eeckels, Eurokom, Luxembourg
  302.    Paul Eggert, Twin Sun, Inc., El Segundo, CA
  303.    Bernie Eiben, DEC
  304.    Peter Eichhorn, Assyst International
  305.    Kristoffer Eriksson, Peridot Konsult AB, Oerebro, Sweden
  306.    John R. Evans, IRS, Kansas City
  307.    Glenn Everhart, RCA Labs
  308.    Charlie Finan, Cray Research
  309.    Herm Fischer, Encino, CA (extensive contributions to version 4.0)
  310.    Carl Fongheiser, CWRU
  311.    Mike Freeman, Bonneville Power Authority
  312.    Marcello Frutig, Catholic University, Sao Paulo, Brazil (X.25 support)
  313.    Hirofumi Fujii, Japan Nat'l Lab for High Energy Physics, Tokyo (Kanji)
  314.    Chuck Fuller, Westinghouse Corporate Computer Services
  315.    Andy Fyfe, Caltech
  316.    Christine M. Gianone, Columbia U
  317.    John Gilmore, UC Berkeley
  318.    Madhusudan Giyyarpuram, HP
  319.    Rainer Glaschick, Siemens AG, Paderborn
  320.    William H. Glass
  321.    German Goldszmidt, IBM
  322.    Chuck Goodhart, NASA
  323.    Alistair Gorman, New Zealand
  324.    Richard Gration, ADFA, Australia
  325.    Chris Green, Essex U, UK
  326.    Alan Grieg, Dundee Tech, Scotland
  327.    Yekta Gursel, MIT
  328.    Jim Guyton, Rand Corp
  329.    Michael Haertel
  330.    Bob Hain, UMN
  331.    Marion Hakanson, ORST
  332.    Richard Hamilton
  333.    John Hamilston, Iowa State U
  334.    Simon Hania, Netherlands
  335.    Stan Hanks, Rice U.
  336.    Ken Harrenstein, SRI
  337.    Eugenia Harris, Data General (AOS/VS)
  338.    David Harrison, Kingston Warren Corp
  339.    Lucas Hart, Oregon State University
  340.    James Harvey, Indiana/Purdue U (VMS)
  341.    Rob Healey
  342.    Chuck Hedrick, Rutgers U
  343.    Ron Heiby, Technical Systems Division, Motorola Computer Group
  344.    Steve Hemminger, Tektronix
  345.    Christian Hemsing, RWTH Aachen, Germany (OS-9)
  346.    Randolph Herber, US DOE,
  347.    Andrew Herbert, Monash Univ, Australia
  348.    Mike Hickey, ITI
  349.    Dan Hildebrand, QNX Software Systems Inc, Kanata, ON (QNX)
  350.    R E Hill
  351.    Stephan Hoffman-Emden
  352.    Bill Homer, Cray Research
  353.    Ray Hunter, The Wollongong Group
  354.    Randy Huntziger, National Library of Medicine
  355.    Larry Jacobs, Transarc
  356.    Steve Jenkins, Lancaster University, UK
  357.    Dave Johnson, Gradient Technologies
  358.    Mark B Johnson, Apple Computer
  359.    Jyke Jokinen, Tampere University of Technology, Finland (QNX)
  360.    Eric F Jones, AT&T
  361.    Luke Jones, AT&T
  362.    Peter Jones, U of Quebec Montreal
  363.    Phil Julian, SAS Institute
  364.    Peter Kabal, U of Quebec
  365.    Mic Kaczmarczik, U of Texas at Austin
  366.    Sergey Kartashoff, Inst. of Precise Mechanics & Computer Equipment, Moscow
  367.    Howie Kaye, Columbia U
  368.    Rob Kedoin, Linotype Co, Hauppauge, NY (OS/2)
  369.    Phil Keegstra
  370.    Mark Kennedy, IBM
  371.    Terry Kennedy, St Peter's College, Jersey City, NJ (VMS and more)
  372.    "Carlo Kid", Technical University of Delft, Netherlands
  373.    Tim Kientzle
  374.    Paul Kimoto, Cornell U
  375.    Douglas Kingston, morgan.com
  376.    Lawrence Kirby, Wiltshire, UK
  377.    Tom Kloos, Sequent Computer Systems
  378.    Jim Knutson, U of Texas at Austin
  379.    John T. Kohl (BSDI)
  380.    Scott Kramer, SRI International, Menlo Park, CA
  381.    John Kraynack, US Postal Service
  382.    David Kricker, Encore Computer
  383.    Thomas Krueger, UWM
  384.    Bo Kullmar, ABC Klubben, Stockholm, and Central Bank of Sweden, Kista
  385.    R. Brad Kummer, AT&T Bell Labs, Atlanta, GA
  386.    John Kunze, UC Berkeley
  387.    David Lane, BSSI / BellSouth (Stratus VOS, X.25)
  388.    Bob Larson, USC (OS-9)
  389.    Bert Laverman, Groningen U, Netherlands
  390.    Steve Layton
  391.    David Lawyer, UC Irvine
  392.    David LeVine, National Semiconductor Corporation
  393.    Daniel S. Lewart, UIUC
  394.    S.O. Lidie, Lehigh U
  395.    Tor Lillqvist, Helsinki U, Finland
  396.    David-Michael Lincke, U of St Gallen, Switzerland
  397.    Robert Lipe (for SCO makefile entries & advice)
  398.    Dean Long
  399.    Mike Long, Analog Devices, Norwood MA
  400.    Kevin Lowey, U of Saskatchewan (OS/2)
  401.    Andy Lowry, Columbia U
  402.    James Lummel, Caprica Telecomputing Resources (QNX)
  403.    David MacKenzie, Environmental Defense Fund, U of Maryland
  404.    John Mackin, University of Sidney, Australia
  405.    Martin Maclaren, Bath U, UK
  406.    Chris Maio, Columbia U CS Dept
  407.    Montserrat Mane, HP, Grenoble, France
  408.    Fulvio Marino, Olivetti, Ivrea, Italy
  409.    Arthur Marsh, dircsa.org.au
  410.    Peter Mauzey, Lucent Technologies
  411.    Tye McQueen, Utah State U
  412.    Ted Medin
  413.    Hellmuth Michaelis, Hanseatischer Computerservice GmbH, Hamburg, Germany
  414.    Leslie Mikesell, American Farm Bureau
  415.    Todd Miller, Courtesan Consulting
  416.    Martin Minow, DEC (VMS)
  417.    Pawan Misra, Bellcore
  418.    Ken Mizialko, IBM, Manassas, VA
  419.    Wolfgang Moeller, DECUS Germany
  420.    Ray Moody, Purdue U
  421.    Bruce J Moore, Allen-Bradley Co, Highland Heights, OH (Atari ST)
  422.    Steve Morley, Convex
  423.    Peter Mossel, Columbia U
  424.    Tony Movshon, NYU
  425.    Lou Muccioli, Swanson Analysis Systems
  426.    Dan Murphy
  427.    Neal P. Murphy, Harsof Systems, Wonder Lake IL
  428.    Gary Mussar
  429.    John Nall, FSU
  430.    Jack Nelson, U of Pittsburgh
  431.    Jim Noble, Planning Research Corporation (Macintosh)
  432.    Ian O'Brien, Bath U, UK
  433.    Melissa O'Neill, SFU
  434.    John Owens
  435.    Michael Pins, Iowa Computer Aided Engineering Network
  436.    Andre' Pirard, University of Liege, Belgium
  437.    Paul Placeway, Ohio State U
  438.    Piet W. Plomp, ICCE, Groningen University, Netherlands
  439.    Ken Poulton, HP Labs
  440.    Manfred Prange, Oakland U
  441.    Christopher Pratt, APV Baker, UK
  442.    Frank Prindle, NADC
  443.    Tony Querubin, U of Hawaii
  444.    Jean-Pierre Radley
  445.    Anton Rang
  446.    Scott Ribe
  447.    Alan Robiette, Oxford University, UK
  448.    Michel Robitaille, U of Montreal (Mac)
  449.    Huw Rogers, Schweizerische Kreditanstalt, Zuerich
  450.    Nigel Roles, Cambridge, England
  451.    Kai Uwe Rommel, Technische Universitaet Muenchen (OS/2)
  452.    Larry Rosenman (Amiga)
  453.    Jay Rouman, U of Michigan
  454.    Jack Rouse, SAS Institute (Data General and/or Apollo)
  455.    Stew Rubenstein, Harvard U (VMS)
  456.    Gerhard Rueckle, FH Darmstadt, Fb. E/Automatisierungstechnik
  457.    John Santos, EG&H
  458.    Bill Schilit, Columbia U
  459.    Ulli Schlueter, RWTH Aachen, Germany (OS-9, etc)
  460.    Michael Schmidt, U of Paderborn, Germany
  461.    Eric Schnoebelen, Convex
  462.    Benn Schreiber, DEC
  463.    Dan Schullman, DEC (modems, DIAL command, etc)
  464.    John Schultz, 3M
  465.    Steven Schultz, Contel (PDP-11)
  466.    APPP Scorer, Leeds Polytechnic, UK
  467.    Gordon Scott, Micro Focus, Newbury UK
  468.    Gisbert W. Selke, WIdO, Bonn, Germany
  469.    David Singer, IBM Almaden Research Labs
  470.    David Sizeland, U of London Medical School
  471.    Fridrik Skulason, Iceland
  472.    Rick Sladkey (Linux)
  473.    Dave Slate
  474.    Bradley Smith, UCLA
  475.    Fred Smith, Merk / Computrition
  476.    Richard S Smith, Cal State
  477.    Ryan Stanisfer, UNT
  478.    Bertil Stenstroem, Stockholm University Computer Centre (QZ), Sweden
  479.    James Sturdevant, CAP GEMENI AMERICA, Minneapolis
  480.    Peter Svanberg, Royal Techn. HS, Sweden
  481.    James R. Swenson, Accu-Weather, Inc.
  482.    Ted T'so, MIT (Linux)
  483.    Andy Tanenbaum, Vrije U, Amsterdam, Netherlands
  484.    Glen Thobe
  485.    Markku Toijala, Helsinki U of Technology
  486.    Teemu Torma, Helsinki U of Technology
  487.    Linus Torvalds, Helsinki
  488.    Rick Troxel, NIH
  489.    Warren Tucker, Tridom Corp, Mountain Park, GA
  490.    Dave Tweten, AMES-NAS
  491.    G Uddeborg, Sweden
  492.    Walter Underwood, Ford Aerospace
  493.    Pieter Van Der Linden, Centre Mondial, Paris
  494.    Ge van Geldorp, Netherlands
  495.    Fred van Kempen, MINIX User Group, Voorhout, Netherlands
  496.    Wayne Van Pelt, GE/CRD
  497.    Mark Vasoll, Oklahoma State U (V7 UNIX)
  498.    Konstantin Vinogradov, ICSTI, Moscow
  499.    Paul Vixie, DEC
  500.    Bernie Volz, Process Software
  501.    Eduard Vopicka, Prague University of Economics, Czech Republic
  502.    Dimitri Vulis, CUNY
  503.    Roger Wallace, Raytheon
  504.    Stephen Walton, Calif State U, Northridge (Amiga)
  505.    Jamie Watson, Adasoft, Switzerland (AIX)
  506.    Rick Watson, U of Texas (Macintosh)
  507.    Robert Weiner, Programming Plus, New York City
  508.    Lauren Weinstein, Vortex Technlogy
  509.    David Wexelblat, AT&T
  510.    Clark Wierda, Illuminati Online
  511.    Joachim Wiesel, U of Karlsruhe
  512.    Lon Willett, U of Utah
  513.    Michael Williams, UCLA
  514.    Nate Williams, U of Montana
  515.    David Wilson
  516.    Joellen Windsor, U of Arizona
  517.    Patrick Wolfe, Kuck & Associates, Inc.
  518.    Gregg Wonderly, Oklahoma State U (V7 UNIX)
  519.    Farrell Woods, Concurrent (formerly Masscomp)
  520.    Dave Woolley, CAP Communication Systems, London
  521.    Jack Woolley, SCT Corp
  522.    Frank Wortner
  523.    Ken Yap, formerly of U of Rochester
  524.    John Zeeff, Ann Arbor, MI
  525. */
  526.  
  527. #include "ckcker.h"                     /* Kermit symbols */
  528. #include "ckcnet.h"                     /* Network symbols */
  529.  
  530. #ifdef CK_SSL
  531. #include "ck_ssl.h"
  532. #endif /* CK_SSL */
  533.  
  534. #ifndef NOSPL
  535. #include "ckuusr.h"
  536. #endif /* NOSPL */
  537.  
  538. #ifdef OS2ONLY
  539. #define INCL_VIO                        /* Needed for ckocon.h */
  540. #include <os2.h>
  541. #undef COMMENT
  542. #endif /* OS2ONLY */
  543.  
  544. #ifdef NT
  545. #include <windows.h>
  546. #include <tapi.h>
  547. #include "ckntap.h"
  548. #endif /* NT */
  549.  
  550. #ifndef NOSERVER
  551. /* Text message definitions.. each should be 256 chars long, or less. */
  552. #ifdef MINIX
  553. char *srvtxt = "\r\n\
  554. Entering server mode.\r\n\0";
  555. #else
  556. #ifdef OLDMSG
  557. /*
  558.   It seems there was a large installation that was using C-Kermit 5A(165)
  559.   or thereabouts, which had deployed thousands of MS-DOS Kermit scripts in
  560.   scattered locations that looked for strings in the old server message,
  561.   which changed in 5A(183), August 1992.
  562. */
  563. char *srvtxt = "\r\n\
  564. C-Kermit server starting.  Return to your local machine by typing\r\n\
  565. its escape sequence for closing the connection, and issue further\r\n\
  566. commands from there.  To shut down the C-Kermit server, issue the\r\n\
  567. FINISH or BYE command and then reconnect.\n\
  568. \r\n\0";
  569. #else
  570. #ifdef OSK
  571. char *srvtxt = "\r\012\
  572. Entering server mode.  If your local Kermit software is menu driven, use\r\012\
  573. the menus to send commands to the server.  Otherwise, enter the escape\r\012\
  574. sequence to return to your local Kermit prompt and issue commands from\r\012\
  575. there. Use SEND and GET for file transfer. Use REMOTE HELP for a list of\r\012\
  576. other available services.  Use BYE or FINISH to end server mode.\r\012\0";
  577. #else /* UNIX, VMS, AOS/VS, and all others */
  578. char *srvtxt = "\r\n\
  579. Entering server mode.  If your local Kermit software is menu driven, use\r\n\
  580. the menus to send commands to the server.  Otherwise, enter the escape\r\n\
  581. sequence to return to your local Kermit prompt and issue commands from\r\n\
  582. there.  Use SEND and GET for file transfer.  Use REMOTE HELP for a list of\r\n\
  583. other available services.  Use BYE or FINISH to end server mode.\r\n\0";
  584. #endif /* OSK */
  585. #endif /* OLDMSG */
  586. #endif /* MINIX */
  587. #else  /* server mode disabled */
  588. char *srvtxt = "";
  589. #endif /* NOSERVER */
  590.  
  591. int initflg = 0;                        /* sysinit() has executed... */
  592. int howcalled = I_AM_KERMIT;            /* How I was called */
  593. int hmtopline = 0;
  594.  
  595. #ifdef IKSDCONF
  596. char * iksdconf = IKSDCONF;             /* IKSD configuration file */
  597. int    iksdcf   = 0;                    /* Has IKSD c.f. been processed? */
  598. #endif /* IKSDCONF */
  599.  
  600. int srvcdmsg = 0;                       /* [Server] CD message */
  601. char * cdmsgfile[8] = { NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL };
  602. char * cdmsgstr = NULL;
  603. char * ckcdpath = NULL;
  604.  
  605. #ifdef NLCHAR                           /* Text-file line terminator */
  606. CHAR feol = NLCHAR;
  607. #else
  608. CHAR feol = 0;
  609. #endif /* NLCHAR */
  610.  
  611. int fblksiz = DBLKSIZ;          /* File blocksize */
  612. int frecl = DLRECL;             /* File record length */
  613. int frecfm = XYFF_S;            /* File record format (default = stream) */
  614. int forg = XYFO_S;              /* File organization (sequential) */
  615. int fcctrl = XYFP_N;            /* File carriage control (ctrl chars) */
  616. int filecase = FILECASE;        /* Case matters in filenames */
  617. int stathack = 1;        /* Fast directory lookups by default */
  618.  
  619. char uidbuf[UIDBUFLEN] = { NUL, NUL };  /* User ID buffer */
  620. int cfilef = 0;                         /* Application ("kerbang") file flag */
  621. char cmdfil[CKMAXPATH + 1] = { NUL, NUL }; /* Application file name */
  622.  
  623. #ifndef NOXFER
  624. /* Multi-protocol support */
  625.  
  626. struct ck_p ptab[NPROTOS] = {           /* Initialize the Kermit part ... */
  627.   { "Kermit",
  628.     DRPSIZ,                             /* Receive packet size */
  629.     DSPSIZ,                             /* Send packet size */
  630.     0,                                  /* Send-packet-size-set flag */
  631.     DFWSIZ,                             /* Window size */
  632.  
  633. #ifdef NEWDEFAULTS
  634.     PX_CAU,                             /* Control char unprefixing... */
  635. #else
  636.     PX_ALL,
  637. #endif /* NEWDEFAULTS */
  638.  
  639. #ifdef VMS                              /* Default filename collision action */
  640.     XYFX_X,                             /* REPLACE for VAX/VMS */
  641. #else
  642.     XYFX_B,                             /* BACKUP for everybody else */
  643. #endif /* VMS */
  644.  
  645. #ifdef OS2                              /* Flag for file name conversion */
  646.     XYFN_L,                             /* Literal for OS2 */
  647. #else
  648.     XYFN_C,                             /* Converted for others */
  649. #endif /* OS2 */
  650.  
  651.     PATH_OFF,                   /* Send pathnames OFF */
  652.     PATH_AUTO,                  /* Receive pathnames AUTO */
  653.     NULL,                       /* Host receive initiation string (binary) */
  654.     NULL,                       /* Host receive initiation string (text)   */
  655.     NULL,                       /* Host server string */
  656.     NULL,                       /* External protocol send command (binary) */
  657.     NULL,                       /* External protocol send command (text)   */
  658.     NULL,                       /* External protocol receive command (bin) */
  659.     NULL }                      /* External protocol receive command (txt) */
  660. #ifdef CK_XYZ
  661. ,
  662. {"XMODEM",    128,128,-1,-1,   1,-1,-1,0,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL},
  663. {"XMODEM-CRC",128,128,-1,-1,  -1,-1,-1,0,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL},
  664. {"YMODEM",   -1, -1,-1,-1,    -1,-1,-1,0,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL},
  665. {"YMODEM-g", -1, -1,-1,-1,    -1,-1,-1,0,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL},
  666. {"ZMODEM",   -1, -1,-1,-1,PX_WIL,-1,-1,0,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL},
  667. {"Other",    -1, -1,-1,-1,    -1,-1,-1,0,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL}
  668. #endif /* CK_XYZ */
  669. };
  670.  
  671. /* Declarations for Send-Init Parameters */
  672.  
  673. int spsiz = DSPSIZ,                     /* Current packet size to send */
  674.     spmax = DSPSIZ,                     /* Biggest packet size we can send */
  675.     lastspmax = DSPSIZ,                 /* Send-packet size last used */
  676.     spsizr = DSPSIZ,                    /* Send-packet size requested */
  677.     spsizf = 0,                         /* Flag to override size negotiation */
  678.     rpsiz = DRPSIZ,                     /* Biggest we want to receive */
  679.     urpsiz = DRPSIZ,                    /* User-requested receive pkt size */
  680.     maxrps = MAXRP,                     /* Maximum incoming long packet size */
  681.     maxsps = MAXSP,                     /* Maximum outbound l.p. size */
  682.     maxtry = MAXTRY,                    /* Maximum retries per packet */
  683.     wslots = 1,                         /* Window size currently in use */
  684.     wslotr = DFWSIZ,                    /* Window size from SET WINDOW */
  685.     wslotn = 1,                         /* Window size negotiated in S-pkt */
  686.     timeouts = 0,                       /* For statistics reporting */
  687.     spackets = 0,                       /*  ... */
  688.     rpackets = 0,                       /*  ... */
  689.     retrans = 0,                        /*  ... */
  690.     crunched = 0,                       /*  ... */
  691.     wmax = 0,                           /*  ... */
  692.     wcur = 0,                           /*  ... */
  693.     srvidl = 0,                         /* Server idle timeout */
  694.     srvdis = 1,                         /* Server file xfer display */
  695.     srvtim = DSRVTIM,                   /* Server command wait timeout */
  696.     srvping = 1,                        /* Server keepalive */
  697. /*
  698.   timint is the timeout interval I use when waiting for a packet.
  699.   pkttim is the SET RECEIVE TIMEOUT value, sent to the other Kermit.
  700.   rtimo is the SET SEND TIMEOUT value.  rtimo is the initial value of
  701.   timint.  timint is changed by the value in the incoming negotiation
  702.   packet unless a SET SEND TIMEOUT command was given.
  703. */
  704.     timint = DMYTIM,                    /* Timeout interval I use */
  705.     pkttim = URTIME,                    /* Timeout I want you to use */
  706.     rtimo = DMYTIM,                     /* Normal packet wait timeout */
  707.     timef = 0,                          /* Flag to override what you ask */
  708. #ifdef CK_TIMERS
  709.     rttflg = 1,                         /* Use dynamic round-trip timers */
  710. #else
  711.     rttflg = 0,                         /* Use fixed timer */
  712. #endif /* CK_TIMERS */
  713.     mintime = 1,                        /* Minimum timeout */
  714.     maxtime = 0,                        /* Maximum timeout */
  715.  
  716.     npad = MYPADN,                      /* How much padding to send */
  717.     mypadn = MYPADN,                    /* How much padding to ask for */
  718.     bctr = DFBCT,                       /* Block check type requested */
  719.     bctu = 1,                           /* Block check type used */
  720.     bctl = 1,                           /* Block check length */
  721.     c_save = -1,                        /* Block check saving and restoring */
  722.     ss_save = -1,                       /* Slow-start saving and restoring */
  723.     ebq =  MYEBQ,                       /* 8th bit prefix */
  724.     ebqflg = 0,                         /* 8th-bit quoting flag */
  725.     rqf = -1,                           /* Flag used in 8bq negotiation */
  726.     rq = 0,                             /* Received 8bq bid */
  727.     sq = 'Y',                           /* Sent 8bq bid */
  728.     rpt = 0,                            /* Repeat count */
  729.     rptq = MYRPTQ,                      /* Repeat prefix */
  730.     rptflg = 0,                         /* Repeat processing flag */
  731.     rptena = 1,                         /* Repeat processing enabled */
  732.     xfrcan = 1,                         /* Transfer cancellation enabled */
  733.     xfrint = 1,                         /* Transfer interruption enabled */
  734.     xfrchr = 3,                         /* Transfer cancel char = Ctrl-C */
  735.     xfrnum = 3;                         /* Need three of them. */
  736.  
  737. int epktflg = 0;                        /* E-PACKET command active */
  738.  
  739. int capas  = 9,                         /* Position of Capabilities */
  740.     lpcapb = 2,                         /* Long Packet capability */
  741.     lpcapr = 1,                         /*  requested */
  742.     lpcapu = 0,                         /*  used */
  743.     swcapb = 4,                         /* Sliding Window capability */
  744.     swcapr = 1,                         /*  requested (allowed) */
  745.     swcapu = 0,                         /*  used */
  746.     atcapb = 8,                         /* Attribute capability */
  747.     atcapr = 1,                         /*  requested */
  748.     atcapu = 0,                         /*  used */
  749.     rscapb = 16,                        /* RESEND capability */
  750.     rscapr = 1,                         /*  requested by default */
  751.     rscapu = 0,                         /*  used */
  752.     lscapb = 32,                        /* Locking Shift capability */
  753.     lscapr = 1,                         /*  requested by default */
  754.     lscapu = 0;                         /*  used */
  755.  
  756. /* Flags for whether to use particular attributes */
  757.  
  758. int atenci = 1,                         /* Encoding in */
  759.     atenco = 1,                         /* Encoding out */
  760.     atdati = 1,                         /* Date in */
  761.     atdato = 1,                         /* Date out */
  762.     atdisi = 1,                         /* Disposition in/out */
  763.     atdiso = 1,
  764.     atleni = 1,                         /* Length in/out (both kinds) */
  765.     atleno = 1,
  766.     atblki = 1,                         /* Blocksize in/out */
  767.     atblko = 1,
  768.     attypi = 1,                         /* File type in/out */
  769.     attypo = 1,
  770.     atsidi = 1,                         /* System ID in/out */
  771.     atsido = 1,
  772.     atsysi = 1,                        /* System-dependent parameters in/out */
  773.     atsyso = 1;
  774.  
  775. #ifdef CK_PERMS
  776. int atlpri = 1,
  777.     atlpro = 1,
  778.     atgpri = 1,
  779.     atgpro = 1;
  780. #endif /* CK_PERMS */
  781.  
  782. #ifdef STRATUS
  783. int atfrmi = 1,                         /* Format in/out */
  784.     atfrmo = 1,
  785.     atcrei = 1,                         /* Creator ID in/out */
  786.     atcreo = 1,
  787.     atacti = 1,                         /* Account in/out */
  788.     atacto = 1;
  789. #endif /* STRATUS */
  790.  
  791. int sprmlen = -1;                       /* Send/Recieve protocol parameter */
  792. int rprmlen = -1;                       /* string length limits */
  793.  
  794. CHAR padch = MYPADC,                    /* Padding character to send */
  795.     mypadc = MYPADC,                    /* Padding character to ask for */
  796.     seol = MYEOL,                       /* End-Of-Line character to send */
  797.     eol = MYEOL,                        /* End-Of-Line character to look for */
  798.     ctlq = CTLQ,                        /* Control prefix in incoming data */
  799.     myctlq = CTLQ,                      /* Outbound control character prefix */
  800.     myrptq = MYRPTQ;                    /* Repeat prefix I want to use */
  801.  
  802. int rptmin = 3;                         /* Repeat-count minimum */
  803.  
  804. int usepipes = 0;                       /* Used for xfer to/from pipes */
  805.  
  806. char * filefile = NULL;                 /* File containing list of filenames */
  807. /* CD message filename list */
  808.  
  809. char whoareu[16] = { NUL, NUL };        /* System ID of other Kermit */
  810. int sysindex = -1;                      /* and index to its system ID struct */
  811. int myindex  = -1;
  812. int wearealike = 0;                     /* 2 Kermits have compatible sysids */
  813. char * cksysid =                        /* My system ID */
  814. #ifdef UNIX
  815.     "U1"
  816. #else
  817. #ifdef VMS
  818.     "D7"
  819. #else
  820. #ifdef OSK
  821.     "UD"
  822. #else
  823. #ifdef AMIGA
  824.     "L3"
  825. #else
  826. #ifdef MAC
  827.     "A3"
  828. #else
  829. #ifdef OS2
  830. #ifdef NT
  831.     "UN"
  832. #else /* NT */
  833.     "UO"
  834. #endif /* NT */
  835. #else /* OS2 */
  836. #ifdef datageneral
  837.     "F3"
  838. #else
  839. #ifdef GEMDOS
  840.     "K2"
  841. #else
  842. #ifdef STRATUS
  843.     "MV"
  844. #else
  845.     ""
  846. #endif /* STRATUS */
  847. #endif /* GEMDOS */
  848. #endif /* datageneral */
  849. #endif /* OS2 */
  850. #endif /* MAC */
  851. #endif /* AMIGA */
  852. #endif /* OSK */
  853. #endif /* VMS */
  854. #endif /* UNIX */
  855.     ;
  856.  
  857. int oopts = -1;                         /* O-Packet Options */
  858. int omode = -1;                         /* O-Packet Transfer Mode */
  859. int oname = -1;                         /* O-Packet Filename Options */
  860. int opath = -1;                         /* O-Packet Pathname Options */
  861.  
  862. struct zattr iattr;                     /* Incoming file attributes */
  863.  
  864. #ifdef VMS
  865. /* VMS labeled file default options - name only. */
  866. int lf_opts = LBL_NAM;
  867. #else
  868. #ifdef OS2
  869. /* OS/2 labeled file default options, all attributes but archived. */
  870. unsigned long int lf_opts = LBL_EXT|LBL_HID|LBL_RO|LBL_SYS;
  871. #else
  872. int lf_opts = 0;
  873. #endif /* OS2 */
  874. #endif /* VMS */
  875.  
  876. /* Packet-related variables */
  877.  
  878. int pktnum = 0,                         /* Current packet number */
  879.     sndtyp = 0,                         /* Type of packet just sent */
  880.     rcvtyp = 0,                         /* Type of packet just received */
  881.     rsn,                                /* Received packet sequence number */
  882.     rln,                                /* Received packet length */
  883.     size,                               /* Current size of output pkt data */
  884.     osize,                              /* Previous output packet data size */
  885.     maxsize,                            /* Max size for building data field */
  886.     spktl = 0,                          /* Length packet being sent */
  887.     rpktl = 0,                          /* Length of packet just received */
  888.     pktpaus = 0,                        /* Interpacket pause interval, msec */
  889.     rprintf,                            /* REMOTE PRINT flag */
  890.     rmailf,                             /* MAIL flag */
  891.     xferstat = -1,                      /* Status of last transaction */
  892.     filestatus = 0;                     /* Status of last file transfer */
  893.  
  894. CHAR pktmsgbuf[PKTMSGLEN+1];
  895. CHAR *epktmsg = pktmsgbuf;
  896.  
  897. CHAR
  898. #ifdef pdp11
  899.     srvcmdbuf[MAXRP+4],
  900.     *srvcmd = srvcmdbuf,
  901. #else
  902. #ifdef DYNAMIC
  903.     *srvcmd = (CHAR *)0,                /* Where to decode server command */
  904. #else
  905.     srvcmdbuf[MAXRP+4],
  906.     *srvcmd = srvcmdbuf,
  907. #endif /* DYNAMIC */
  908. #endif /* pdp11 */
  909.     padbuf[96],                         /* Buffer for send-padding */
  910.     *recpkt,
  911.     *rdatap,                            /* Pointer to received packet data */
  912.     *data = (CHAR *)0,                  /* Pointer to send-packet data */
  913.     *srvptr,                            /* Pointer to srvcmd */
  914.     mystch = SOH,                       /* Outbound packet-start character */
  915.     stchr = SOH;                        /* Incoming packet-start character */
  916.  
  917. /* File-related variables */
  918.  
  919. #ifndef NOMSEND                         /* Multiple SEND */
  920. struct filelist * filehead = NULL;      /* SEND list */
  921. struct filelist * filetail = NULL;
  922. struct filelist * filenext = NULL;
  923. int addlist = 0;
  924. #endif /* NOMSEND */
  925.  
  926. char filnam[CKMAXPATH + 1];             /* Name of current file. */
  927.  
  928. #ifdef PIPESEND
  929. char * sndfilter = NULL;
  930. char * rcvfilter = NULL;
  931. #endif /* PIPESEND */
  932.  
  933. char ** sndarray = NULL;                /* SEND /ARRAY pointer and range */
  934. #ifndef NOSPL
  935. int sndxlo = -1, sndxhi = -1, sndxin = -1;
  936. #endif /* NOSPL */
  937.  
  938. #endif /* NOXFER */
  939.  
  940. #ifndef NOSERVER
  941. int ngetpath = 0;                       /* GET search path */
  942. int fromgetpath = 0;
  943. char * getpath[MAXGETPATH];
  944. char * x_user = NULL;                   /* Server login information */
  945. char * x_passwd = NULL;
  946. char * x_acct = NULL;
  947. #endif /* NOSERVER */
  948.  
  949. int x_login = 0;                        /* Login required */
  950. int x_logged = 0;                       /* User is logged in */
  951.  
  952. extern int timelimit;
  953.  
  954. #ifdef CK_LOGIN
  955. int logintimo = 300;                    /* Login timeout */
  956. char * userfile = NULL;                 /* Forbidden user file */
  957. #endif /* CK_LOGIN */
  958. #ifdef IKSD
  959. char * anonfile = NULL;                 /* Anonymous login init file */
  960. char * anonroot = NULL;                 /* Anonymous file-system root */
  961. int iks_timo  = 300;                    /* 5 minutes idle timo */
  962. int iks_retry = 3;                      /* 3 attempts at login */
  963. #endif /* IKSD */
  964.  
  965. #ifdef CKSYSLOG
  966. extern VOID zsyslog();
  967. extern int ckxlogging, ckxsyslog;
  968. #endif /* CKSYSLOG */
  969.  
  970. int nzxopts = 0;                        /* Options for nzxpand() */
  971. int nfils = 0;                          /* Number of files in file group */
  972. long fsize = 0L;                        /* Size of current file */
  973. #ifdef UNIX
  974. int wildxpand = 0;                      /* Who expands wildcards */
  975. #else /* UNIX */
  976. #ifdef STRATUS
  977. int wildxpand = 1;
  978. #endif /* STRATUS */
  979. #endif /* UNIX */
  980. #ifdef UNIXOROSK
  981. int matchdot = 0;                       /* Whether to match dot files */
  982. #else
  983. int matchdot = 1;
  984. #endif /* UNIXOROSK */
  985. int clfils = 0;                         /* Flag for command-line files */
  986. int stayflg = 0;                        /* Flag for "stay", i.e. "-S" */
  987. int xfinish = 0;                        /* Flag for FINISH = EXIT */
  988. long ztusec = -1L;                      /* Used with ztime() */
  989. long ztmsec = -1L;                      /* Ditto */
  990.  
  991. /* Communication device / connection variables */
  992.  
  993. char ttname[TTNAMLEN+1];                /* Name of communication device */
  994.  
  995. #ifdef MAC
  996. int connected = 0;                      /* True if connected */
  997. int startconnected;                     /* initial state of connected */
  998. #endif /* MAC */
  999.  
  1000. long speed = -1L;                       /* Communication device speed */
  1001. int wasclosed = 0;                      /* Connection was just closed */
  1002. int whyclosed = WC_REMO;                /* why it was closed */
  1003. int qnxportlock = 0;                    /* QNX port locking on/off */
  1004.  
  1005. #ifndef CLSONDISC
  1006. #define CLSONDISC 0
  1007. #endif /* CLSONDISC */
  1008.  
  1009. int cxflow[CXT_MAX+1];                  /* See initflow() */
  1010.  
  1011. #ifndef NOSHOW
  1012. char * floname[] = {                    /* Flow control names */
  1013.   "none", "xon/xoff", "rts/cts", "dtr/cd", "etx/ack", "string",
  1014.   "xxx1", "xxx2", "dtr/cts", "keep", "auto"
  1015. };
  1016. int nfloname = (sizeof(floname) / sizeof(char *));
  1017.  
  1018. char * cxname[] = {                     /* Connection type names */
  1019.   "remote", "direct-serial", "modem", "tcp/ip", "x.25", "decnet",
  1020.   "lat", "netbios", "named-pipe", "ssh", "pipe"
  1021. };
  1022. int ncxname = (sizeof(cxname) / sizeof(char *));
  1023. #endif /* NOSHOW */
  1024.  
  1025. int parity = DEFPAR,                    /* Parity specified, 0,'e','o',etc */
  1026.     hwparity = 0,                       /* Hardware parity for serial port */
  1027.     stopbits = -1,                      /* Stop bits for serial port */
  1028.     clsondisc = CLSONDISC,              /* Serial port close on disconnect */
  1029.     autopar = 0,                        /* Automatic parity change flag */
  1030.     sosi = 0,                           /* Shift-In/Out flag */
  1031.     flow = 0,                           /* Flow control (see initflow()) */
  1032.     autoflow = 1,                       /* Automatic flow control */
  1033.     turn = 0,                           /* Line turnaround handshake flag */
  1034.     turnch = XON,                       /* Line turnaround character */
  1035.     duplex = 0,                         /* Duplex, full by default */
  1036.     escape = DFESC,                     /* Escape character for connect */
  1037.     ckdelay = DDELAY,                   /* Initial delay before sending */
  1038.     tnlm = 0,                           /* Terminal newline mode */
  1039.     mdmtyp = 0;                         /* Modem type (initially none)  */
  1040.  
  1041. /* Networks for SET HOST */
  1042.  
  1043. #ifdef BIGBUFOK
  1044. #define MYHOSTL 1024
  1045. #else
  1046. #define MYHOSTL 100
  1047. #endif /* BIGBUFOK */
  1048.  
  1049. char myhost[MYHOSTL];                   /* Local host name */
  1050. int network = 0;                        /* Network vs serial connection */
  1051. int inserver = 0;                       /* Running as an Internet server */
  1052. int isguest = 0;                        /* User is anonymous */
  1053. char * clienthost = NULL;               /* Peer host name or address */
  1054. int tcp_incoming = 0;                   /* Incoming TCP connection? */
  1055.  
  1056. #ifdef NETCONN
  1057. #ifdef TCPSOCKET
  1058. int nettype = NET_TCPB;                 /* Default network type */
  1059. #else
  1060. #ifdef SUNX25
  1061. int nettype = NET_SX25;
  1062. #else
  1063. #ifdef IBMX25
  1064. int nettype = NET_IX25;
  1065. #else
  1066. #ifdef HPX25
  1067. int nettype = NET_HX25;
  1068. #else
  1069. #ifdef STRATUSX25
  1070. int nettype = NET_VX25;
  1071. #else
  1072. #ifdef DECNET
  1073. int nettype = NET_DEC;
  1074. #else
  1075. #ifdef SUPERLAT
  1076. int nettype = NET_SLAT;
  1077. #else
  1078. int nettype = NET_NONE;
  1079. #endif /* SUPERLAT */
  1080. #endif /* DECNET */
  1081. #endif /* STRATUSX25 */
  1082. #endif /* HPX25 */
  1083. #endif /* IBMX25 */
  1084. #endif /* SUNX25 */
  1085. #endif /* TCPSOCKET */
  1086. #else  /* NETCONN */
  1087. int nettype = NET_NONE;
  1088. #endif /* NETCONN */
  1089.  
  1090. #ifdef ANYX25
  1091. int revcall = 0;                        /* X.25 reverse call not selected */
  1092. int closgr  = -1;                       /* X.25 closed user group  */
  1093. int cudata = 0;                         /* X.25 call user data not specified */
  1094. char udata[MAXCUDATA];                  /* X.25 call user data */
  1095.  
  1096. #ifdef IBMX25
  1097. /*
  1098.   I was unable to find any pre-defined MAX values for x25 addresses - the
  1099.   addresses that I've seen have been around 10-12 characters 32 is probably
  1100.   enough, 64 is hopefully safe for everyone.
  1101. */
  1102.     x25addr_t local_nua = {'\0'};       /* local x.25 address */
  1103.     x25addr_t remote_nua = {'\0'};      /* remote x.25 address */
  1104.     char x25name[32] = {'\0'};          /* x25 device name, sx25a0 or sx25a1 */
  1105.     char x25dev[64] =  "/dev/x25pkt";   /* x25 device in /dev */
  1106.     int x25port = 0;                    /* port used for X.25 - AIX only */
  1107. #endif /* IBMX25 */
  1108.  
  1109. #ifndef IBMX25
  1110. /*
  1111.   This condition is unrelated to the above IBMX25 condition.
  1112.   IBM X.25 doesn't have PAD support.
  1113. */
  1114.     CHAR padparms[MAXPADPARMS+1]; /* X.3 parameters */
  1115. #endif /* IBMX25 */
  1116. #endif /* ANYX25 */
  1117.  
  1118. /* Other items */
  1119.  
  1120. int isinterrupted = 0;                  /* Used in exception handling */
  1121. int what = W_INIT;                      /* What I am doing */
  1122. int lastxfer = 0;                       /* Last transfer (send or receive) */
  1123.  
  1124. #ifdef NT
  1125. extern int StartedFromDialer;
  1126. #ifdef NTSIG
  1127. extern int TlsIndex;
  1128. #endif /* NTSIG */
  1129. #ifdef NTASM
  1130. unsigned long ESPToRestore;             /* Ditto */
  1131. #endif /* NTASM */
  1132. #endif /* NT */
  1133.  
  1134. #ifdef OS2PM
  1135. int os2pm = 0;                          /* OS/2 Presentation Manager flag */
  1136. #endif /* OS2PM */
  1137.  
  1138. /* Terminal screen size, if known, -1 means unknown. */
  1139.  
  1140. #ifdef OS2
  1141. #include "ckocon.h"
  1142. int tt_rows[VNUM] = {25,24,25,1};       /* Rows (height) */
  1143. int tt_cols[VNUM] = {80,80,80,80};      /* Columns (width) */
  1144. int k95stdio = 0;                       /* Stdio threads */
  1145. #else /* OS2 */
  1146. int tt_rows = -1;                       /* Rows (height) */
  1147. int tt_cols = -1;                       /* Columns (width) */
  1148. #endif /* OS2 */
  1149.  
  1150. #ifdef OS2
  1151. int tt_bell = XYB_AUD | XYB_SYS;        /* BELL AUDIBLE (system sounds) */
  1152. #else
  1153. int tt_bell = XYB_AUD;                  /* BELL ON */
  1154. #endif /* OS2 */
  1155.  
  1156. int tt_print = 0;                       /* Transparent print disabled */
  1157. int tt_escape = 1;                      /* Escaping back is enabled */
  1158. int cmd_rows = 24, cmd_cols = 80;       /* Command/console screen dimensions */
  1159.  
  1160. int tn_exit = 0;                        /* Exit on disconnect */
  1161.  
  1162. int exitonclose = 0;                    /* Exit on close */
  1163. int haveline = 0;                       /* SET LINE or SET HOST in effect */
  1164. int tlevel = -1;                        /* Take-file command level */
  1165. int hints = 1;                          /* Whether to give hints */
  1166.  
  1167. #ifdef NOLOCAL
  1168. int remonly = 1;                        /* Remote-mode-only advisory (-R) */
  1169. int nolocal = 1;                        /* Remote-only strictly enforced */
  1170. #else
  1171. int remonly = 0;
  1172. int nolocal = 0;
  1173. #endif /* NOLOCAL */
  1174.  
  1175. #ifndef NOSPL
  1176. extern int cmdlvl;                      /* Command level */
  1177. extern int maclvl;                      /* Macro invocation level */
  1178. #endif /* NOSPL */
  1179.  
  1180. int protocol  = PROTO_K;                /* File transfer protocol = Kermit */
  1181.  
  1182. #ifdef NEWDEFAULTS
  1183. int prefixing = PX_CAU;
  1184. #else
  1185. int prefixing = PX_ALL;
  1186. #endif /* NEWDEFAULTS */
  1187.  
  1188. extern short ctlp[];                    /* Control-prefix table */
  1189.  
  1190. int carrier = CAR_AUT;                  /* Pay attention to carrier signal */
  1191. int cdtimo = 0;                         /* Carrier wait timeout */
  1192. int xitsta = GOOD_EXIT;                 /* Program exit status */
  1193.  
  1194. #ifdef VMS                              /* Default filename collision action */
  1195. int fncact = XYFX_X;                    /* REPLACE for VMS */
  1196. #else
  1197. int fncact = XYFX_B;                    /* BACKUP for everybody else */
  1198. #endif /* VMS */
  1199.  
  1200. int fncsav = -1;                        /* For saving & restoring the above */
  1201. int bgset = -1;                         /* BACKGROUND mode set explicitly */
  1202.  
  1203. int cmdint = 1;                         /* Interrupts are allowed */
  1204. #ifdef UNIX
  1205. int suspend = DFSUSP;                   /* Whether SUSPEND command, etc, */
  1206. #else                                   /* is to be allowed. */
  1207. int suspend = 0;
  1208. #endif /* UNIX */
  1209.  
  1210. /* Statistics variables */
  1211.  
  1212. long filcnt,                    /* Number of files in transaction */
  1213.     filrej,                     /* Number of files rejected in transaction */
  1214.     flci,                       /* Characters from line, current file */
  1215.     flco,                       /* Chars to line, current file  */
  1216.     tlci,                       /* Chars from line in transaction */
  1217.     tlco,                       /* Chars to line in transaction */
  1218.     ffc,                        /* Chars to/from current file */
  1219.     tfc,                        /* Chars to/from files in transaction */
  1220.     cps = 0L,                   /* Chars/sec last transfer */
  1221.     peakcps = 0L,               /* Peak chars/sec last transfer */
  1222.     ccu,                        /* Control chars unprefixed in transaction */
  1223.     ccp,                        /* Control chars prefixed in transaction */
  1224.     rptn;                       /* Repeated characters compressed */
  1225.  
  1226. int tsecs = 0;                          /* Seconds for transaction */
  1227. int fsecs = 0;                          /* Per-file timer */
  1228.  
  1229. #ifdef GFTIMER
  1230. CKFLOAT
  1231.   fpfsecs = 0.0,                        /* Floating point per-file timer */
  1232.   fptsecs = 0.0;                        /* and per-transaction timer */
  1233. #endif /* GFTIMER */
  1234.  
  1235. /* Flags */
  1236.  
  1237. int deblog = 0,                         /* Flag for debug logging */
  1238.     debses = 0,                         /* Flag for DEBUG SESSION */
  1239.     debtim = 0,                         /* Include timestamp in debug log */
  1240.     pktlog = 0,                         /* Flag for packet logging */
  1241.     seslog = 0,                         /* Session logging */
  1242.     dialog = 0,                         /* DIAL logging */
  1243.     tralog = 0,                         /* Transaction logging */
  1244.     tlogfmt = 1,                        /* Transaction log format (verbose) */
  1245.     tlogsep = (int)',',                 /* Transaction log field separator */
  1246.     displa = 0,                         /* File transfer display on/off */
  1247.     stdouf = 0,                         /* Flag for output to stdout */
  1248.     stdinf = 0,                         /* Flag for input from stdin */
  1249.     xflg   = 0,                         /* Flag for X instead of F packet */
  1250.     hcflg  = 0,                         /* Doing Host command */
  1251.     dest   = DEST_D,                    /* Destination for packet data */
  1252.     zchkod = 0,                         /* zchko() should work for dirs too? */
  1253.     zchkid = 0,                         /* zchki() should work for dirs too? */
  1254.  
  1255. /* If you change this, also see struct ptab above... */
  1256.  
  1257. #ifdef OS2                              /* Flag for file name conversion */
  1258.     fncnv  = XYFN_L,                    /* Default is Literal in OS/2, */
  1259.     f_save = XYFN_L,                    /* (saved copy of same) */
  1260. #else
  1261.     fncnv  = XYFN_C,                    /* elsewhere Convert them */
  1262.     f_save = XYFN_C,                    /* (ditto) */
  1263. #endif /* OS2 */
  1264.  
  1265.     fnspath = PATH_OFF,                 /* Send file path */
  1266.     fnrpath = PATH_AUTO,                /* Receive file path */
  1267.     fackpath = 1,                       /* Send back path in ACK to F */
  1268.     binary = XYFT_B,                    /* Default file transfer mode */
  1269.     b_save = XYFT_B,                    /* Saved file mode */
  1270.     eofmethod = 0,                      /* EOF detection method (length) */
  1271.  
  1272. #ifdef OS2
  1273.     cursor_save = -1,                   /* Cursor state */
  1274. #endif /* OS2 */
  1275.  
  1276.     xfermode = XMODE_A,                 /* Transfer mode, manual or auto */
  1277.     recursive = 0,                      /* Recursive directory traversal */
  1278.     skipbup   = 0,                      /* Skip backup files when sending */
  1279.     sendmode = SM_SEND,                 /* Which type of SEND operation */
  1280.     slostart  = 1,                      /* Slow start (grow packet lengths) */
  1281.     cmask  = 0177,                      /* CONNECT (terminal) byte mask */
  1282.     fmask  = 0377,                      /* File byte mask */
  1283.     ckwarn = 0,                         /* Flag for file warning */
  1284.     quiet  = 0,                         /* Be quiet during file transfer */
  1285.     local  = 0,                         /* 1 = local mode, 0 = remote mode */
  1286.     cxtype = CXT_REMOTE,                /* Connection type */
  1287.     server = 0,                         /* Flag for I Am Server */
  1288.     query = 0,                          /* Flag for Query active */
  1289.     justone = 0,                        /* Server should do Just One command */
  1290.     urserver = 0,                       /* Flag for You Are Server */
  1291.     bye_active = 0,                     /* Flag for BYE command active */
  1292.     diractive = 0,                      /* Flag for DIRECTORY command active */
  1293.     cflg   = 0,                         /* Connect before transaction */
  1294.     cnflg  = 0,                         /* Connect after transaction */
  1295.     cxseen = 0,                         /* Flag for cancelling a file */
  1296.     czseen = 0,                         /* Flag for cancelling file group */
  1297.     fatalio = 0,                        /* Flag for fatal i/o error */
  1298.     discard = 0,                        /* Flag for file to be discarded */
  1299.     keep = SET_AUTO,                    /* Keep incomplete files = AUTO */
  1300.     unkcs = 1,                          /* Keep file w/unknown character set */
  1301.     nakstate = 0,                       /* In a state where we can send NAKs */
  1302.     dblchar = -1,                       /* Character to double when sending */
  1303.     moving = 0,                         /* MOVE = send, then delete */
  1304.     reliable = SET_AUTO,                /* Nonzero if transport is reliable */
  1305.     xreliable = -1,
  1306.     setreliable = 0,
  1307.     urclear = 0,                        /* Nonzero for clear channel to you */
  1308.     clearrq = SET_AUTO,                 /* SET CLEARCHANEL value */
  1309.     cleared = 0,
  1310.     streaming = 0,                      /* Nonzero if streaming is active */
  1311.     streamok = 0,                       /* Nonzero if streaming negotiated */
  1312.     streamrq = SET_AUTO,                /* SET STREAMING value */
  1313.     streamed = -1;                      /* Whether we streamed last time */
  1314.  
  1315. char * snd_move = NULL;                 /* Move file after sending it */
  1316. char * snd_rename = NULL;               /* Rename file after sending it */
  1317. char * rcv_move = NULL;                 /* Move file after receiving it */
  1318. char * rcv_rename = NULL;               /* Rename file after receiving it */
  1319.  
  1320. char * g_snd_move = NULL;
  1321. char * g_snd_rename = NULL;
  1322. char * g_rcv_move = NULL;
  1323. char * g_rcv_rename = NULL;
  1324.  
  1325. long sendstart = 0L;                    /* SEND start position */
  1326. long calibrate = 0L;                    /* Nonzero if calibration run */
  1327.  
  1328. #ifdef CK_TRIGGER
  1329. char *tt_trigger[TRIGGERS] = { NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL };
  1330. CHAR *tt_trmatch[TRIGGERS] = { NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL };
  1331. char *triggerval = NULL;
  1332. #endif /* CK_TRIGGER */
  1333.  
  1334. int ckxlogging = 0;                     /* Flag for syslogging active */
  1335. int ikdbopen = 0;                       /* Flag for IKSD database active */
  1336. int dbinited = 0;                       /* Flag for IKSDB record init'd */
  1337. #ifndef CKSYSLOG
  1338. int ckxsyslog = 0;                      /* Logging level 0 */
  1339. #else
  1340. #ifdef SYSLOGLEVEL
  1341. int ckxsyslog = SYSLOGLEVEL;            /* Logging level specified */
  1342. #else
  1343. int ckxsyslog = SYSLG_DF;               /* Default logging level */
  1344. #endif /* SYSLOGLEVEL */
  1345. #endif /* CKSYSLOG */
  1346.  
  1347. #ifndef NOICP
  1348. #ifndef NOHELP
  1349. #ifndef NOCMDL
  1350. _PROTOTYP( VOID iniopthlp, (void) );    /* Command-line help initializer */
  1351. #endif /* NOCMDL */
  1352. #endif /* NOHELP */
  1353. #endif /* NOICP */
  1354.  
  1355. #ifdef IKSD
  1356. _PROTOTYP( VOID iksdinit, (int) );
  1357. #endif /* IKSD */
  1358.  
  1359. /* Variables passed from command parser to protocol module */
  1360.  
  1361. #ifndef NOSPL
  1362. #ifndef NOICP
  1363. #ifdef CK_APC
  1364. _PROTOTYP( VOID apconect, (void) );
  1365. #endif /* CK_APC */
  1366. #ifdef OS2
  1367. extern int initvik;
  1368. #endif /* OS2 */
  1369. #endif /* NOICP */
  1370. #endif /* NOSPL */
  1371. char *clcmds = NULL;                    /* Pointer to command-line commands */
  1372.  
  1373. #ifndef NOSETKEY
  1374. extern KEY *keymap;
  1375. extern MACRO *macrotab;
  1376. #endif /* NOSETKEY */
  1377.  
  1378. #ifndef NOPUSH
  1379. int nopush = 0;                         /* PUSH enabled */
  1380. #else
  1381. int nopush = 1;                         /* PUSH disabled */
  1382. #endif /* NOPUSH */
  1383.  
  1384. CHAR sstate  = (CHAR) 0;                /* Starting state for automaton */
  1385. CHAR zstate  = (CHAR) 0;                /* For remembering sstate */
  1386. char * printername = NULL;              /* NULL if printer not redirected */
  1387. int printpipe = 0;                      /* For SET PRINTER */
  1388. int noprinter = 0;
  1389.  
  1390. #ifndef NOXFER
  1391. char *cmarg  = "";                      /* Pointer to command data */
  1392. char *cmarg2 = "";                      /* Pointer to 2nd command data */
  1393. char **cmlist;                          /* Pointer to file list in argv */
  1394.  
  1395. #ifdef CK_AUTODL                        /* Autodownload */
  1396. int autodl = 1;                         /* Enabled by default */
  1397. #else
  1398. int autodl = 0;                         /* (or if not implemented). */
  1399. #endif /* CK_AUTODL */
  1400. #ifdef OS2                              /* AUTODOWNLOAD parameters */
  1401. int adl_kmode = ADL_PACK,               /* Match Packet to signal download */
  1402.     adl_zmode = ADL_PACK;
  1403. char * adl_kstr = NULL;                 /* KERMIT Download String */
  1404. char * adl_zstr = NULL;                 /* ZMODEM Download String */
  1405. #endif /* OS2 */
  1406.  
  1407. int remfile = 0, rempipe = 0, remappd = 0; /* REMOTE output redirection */
  1408. char * remdest = NULL;
  1409.  
  1410. #ifndef NOSERVER
  1411. /*
  1412.   Server services:
  1413.    0 = disabled
  1414.    1 = enabled in local mode
  1415.    2 = enabled in remote mode
  1416.    3 = enabled in both local and remote modes
  1417.   only as initial (default) values.
  1418. */
  1419. int en_xit = 2;                         /* EXIT */
  1420. int en_cwd = 3;                         /* CD/CWD */
  1421. int en_cpy = 3;                         /* COPY   */
  1422. int en_del = 2;                         /* DELETE */
  1423. int en_mkd = 3;                         /* MKDIR */
  1424. int en_rmd = 2;                         /* RMDIR */
  1425. int en_dir = 3;                         /* DIRECTORY */
  1426. int en_fin = 3;                         /* FINISH */
  1427. int en_get = 3;                         /* GET */
  1428. #ifndef NOPUSH
  1429. int en_hos = 2;                         /* HOST enabled */
  1430. #else
  1431. int en_hos = 0;                         /* HOST disabled */
  1432. #endif /* NOPUSH */
  1433. int en_ren = 3;                         /* RENAME */
  1434. int en_sen = 3;                         /* SEND */
  1435. int en_set = 3;                         /* SET */
  1436. int en_spa = 3;                         /* SPACE */
  1437. int en_typ = 3;                         /* TYPE */
  1438. int en_who = 3;                         /* WHO */
  1439. #ifdef datageneral
  1440. /* Data General AOS/VS can't do this */
  1441. int en_bye = 0;                         /* BYE */
  1442. #else
  1443. int en_bye = 2;                         /* PCs in local mode... */
  1444. #endif /* datageneral */
  1445. int en_asg = 3;                         /* ASSIGN */
  1446. int en_que = 3;                         /* QUERY */
  1447. int en_ret = 2;                         /* RETRIEVE */
  1448. int en_mai = 3;                         /* MAIL */
  1449. int en_pri = 3;                         /* PRINT */
  1450. int en_ena = 3;                         /* ENABLE */
  1451. #else
  1452. int en_xit = 0, en_cwd = 0, en_cpy = 0, en_del = 0, en_mkd = 0, en_rmd = 0,
  1453.     en_dir = 0, en_fin = 0, en_get = 0, en_hos = 0, en_ren = 0, en_sen = 0,
  1454.     en_set = 0, en_spa = 0, en_typ = 0, en_who = 0, en_bye = 0, en_asg = 0,
  1455.     en_que = 0, en_ret = 0, en_mai = 0, en_pri = 0, en_ena = 0;
  1456. #endif /* NOSERVER */
  1457. #endif /* NOXFER */
  1458.  
  1459. /* Miscellaneous */
  1460.  
  1461. char **xargv;                           /* Global copies of argv */
  1462. int  xargc;                             /* and argc  */
  1463. int xargs;                              /* an immutable copy of argc */
  1464. char *xarg0;                            /* and of argv[0] */
  1465. char *pipedata;                         /* Pointer to -P (pipe) data */
  1466.  
  1467. extern char *dftty;                     /* Default tty name from ck?tio.c */
  1468. extern int dfloc;                       /* Default location: remote/local */
  1469. extern int dfprty;                      /* Default parity */
  1470. extern int dfflow;                      /* Default flow control */
  1471.  
  1472. #ifdef TNCODE
  1473. extern int tn_deb;
  1474. #endif /* TNCODE */
  1475. /*
  1476.   Buffered file input and output buffers.  See getpkt() in ckcfns.c
  1477.   and zoutdump() in the system-dependent file i/o module (usually ck?fio.c).
  1478. */
  1479. #ifndef DYNAMIC
  1480. /* Now we allocate them dynamically, see getiobs() below. */
  1481. char zinbuffer[INBUFSIZE], zoutbuffer[OBUFSIZE];
  1482. #endif /* DYNAMIC */
  1483. char *zinptr, *zoutptr;
  1484. int zincnt, zoutcnt;
  1485. int zobufsize = OBUFSIZE;
  1486. int zofbuffer = 1;
  1487. int zofblock  = 1;
  1488.  
  1489. #ifdef SESLIMIT
  1490. int seslimit = 0;
  1491. #endif /* SESLIMIT */
  1492.  
  1493. #ifdef CK_AUTHENTICATION
  1494. #include "ckuath.h"
  1495. #endif /* CK_AUTHENTICATION */
  1496.  
  1497. _PROTOTYP( int getiobs, (VOID) );
  1498.  
  1499. /*  M A I N  --  C-Kermit main program  */
  1500.  
  1501. #include <signal.h>
  1502.  
  1503. #ifndef NOCCTRAP
  1504. #include <setjmp.h>
  1505. #include "ckcsig.h"
  1506. ckjmpbuf cmjbuf;
  1507. #ifdef GEMDOS                           /* Special for Atari ST */
  1508. cc_clean();                             /* This can't be right? */
  1509. #endif /* GEMDOS */
  1510. #endif /* NOCCTRAP */
  1511.  
  1512. #ifndef NOXFER
  1513. /* Info associated with a system ID */
  1514.  
  1515. struct sysdata sysidlist[] = {          /* Add others as needed... */
  1516.   { "0",  "anonymous",    0, NUL,  0, 0, 0 },
  1517.   { "A1", "Apple II",     0, NUL,  0, 0, 3 }, /* fix this */
  1518.   { "A3", "Macintosh",    1, ':',  0, 2, 1 },
  1519.   { "D7", "VMS",          0, ']',  1, 0, 0 },
  1520.   { "DA", "RSTS/E",       0, ']',  1, 0, 3 }, /* (i think...) */
  1521.   { "DB", "RT11",         0, NUL,  1, 0, 3 }, /* (maybe...) */
  1522.   { "F3", "AOS/VS",       1, ':',  0, 0, 2 },
  1523.   { "I1", "VM/CMS",       0, NUL,  0, 0, 0 },
  1524.   { "I2", "MVS/TSO",      0, NUL,  0, 0, 0 },
  1525.   { "I4", "MUSIC",        0, NUL,  0, 0, 0 },
  1526.   { "I7", "CICS",         0, NUL,  0, 0, 0 },
  1527.   { "I9", "MVS/ROSCOE",   0, NUL,  0, 0, 0 },
  1528.   { "K2", "Atari ST",     1, '\\', 1, 0, 3 },
  1529.   { "L3", "Amiga",        1, '/',  1, 0, 2 },
  1530.   { "MV", "Stratus VOS",  1, '>',  0, 1, 0 },
  1531.   { "N3", "Apollo Aegis", 1, '/',  0, 3, 2 },
  1532.   { "U1", "UNIX",         1, '/',  0, 3, 2 },
  1533.   { "U8", "MS-DOS",       1, '\\', 1, 0, 3 },
  1534.   { "UD", "OS-9",         1, '/',  0, 3, 2 },
  1535.   { "UN", "Windows-32",   1, '\\', 1, 2, 3 },
  1536.   { "UO", "OS/2",         1, '\\', 1, 2, 3 }
  1537. };
  1538. static int nxxsysids = (sizeof(sysidlist) / sizeof(struct sysdata));
  1539.  
  1540. /* Given a Kermit system ID code, return the associated name string */
  1541. /* and some properties of the filenames... */
  1542.  
  1543. char *
  1544. getsysid(s) char * s; {                 /* Get system-type name */
  1545.     int i;
  1546.     if (!s) return("");
  1547.     for (i = 0; i < nxxsysids; i++)
  1548.       if (!strcmp(sysidlist[i].sid_code,s))
  1549.         return(sysidlist[i].sid_name);
  1550.     return(s);
  1551. }
  1552.  
  1553. int
  1554. getsysix(s) char *s; {                  /* Get system-type index */
  1555.     int i;
  1556.     if (!s) return(-1);
  1557.     for (i = 0; i < nxxsysids; i++)
  1558.       if (!strcmp(sysidlist[i].sid_code,s))
  1559.         return(i);
  1560.     return(-1);
  1561. }
  1562. #endif /* NOXFER */
  1563.  
  1564. /* Tell if a pathname is absolute (versus relative) */
  1565. /* This should be parceled out to each of the ck*fio.c modules... */
  1566. int
  1567. isabsolute(path) char * path; {
  1568.     int rc = 0;
  1569.     int x;
  1570.     if (!path)
  1571.       return(0);
  1572.     if (!*path)
  1573.       return(0);
  1574.     x = (int) strlen(path);
  1575.     debug(F111,"isabsolute",path,x);
  1576. #ifdef VMS
  1577.     rc = 0;
  1578.     x = ckindex("[",path,0,0,0);        /* 1-based */
  1579.     if (!x)
  1580.        x = ckindex("<",path,0,0,0);
  1581.     debug(F111,"isabsolute left bracket",path,x);
  1582.     if (!x) {
  1583.         x = ckindex(":",path,-1,1,1);
  1584.         if (x)
  1585.           debug(F111,"isabsolute logical",path,x);
  1586.     }
  1587.     if (x > 0)
  1588.       if (path[x] != '.')               /* 0-based */
  1589.         rc = 1;
  1590. #else
  1591. #ifdef UNIX
  1592.     if (*path == '/'
  1593. #ifdef DTILDE
  1594.         || *path == '~'
  1595. #endif /* DTILDE */
  1596.         )
  1597.       rc = 1;
  1598. #else
  1599. #ifdef OS2
  1600.     if (*path == '/' || *path == '\\')
  1601.       rc = 1;
  1602.     else if (isalpha(*path) && x > 1)
  1603.       if (*(path+1) == ':')
  1604.         rc = 1;
  1605. #else
  1606. #ifdef AMIGA
  1607.     if (*path == '/'
  1608. #ifdef DTILDE
  1609.         || *path == '~'
  1610. #endif /* DTILDE */
  1611.         )
  1612.       rc = 1;
  1613. #else
  1614. #ifdef OSK
  1615.     if (*path == '/'
  1616. #ifdef DTILDE
  1617.         || *path == '~'
  1618. #endif /* DTILDE */
  1619.         )
  1620.       rc = 1;
  1621. #else
  1622. #ifdef datageneral
  1623.     if (*path == ':')
  1624.       rc = 1;
  1625. #else
  1626. #ifdef MAC
  1627.     rc = 0;                             /* Fill in later... */
  1628. #else
  1629. #ifdef STRATUS
  1630.     rc = 0;                             /* Fill in later... */
  1631. #else
  1632. #ifdef GEMDOS
  1633.     if (*path == '/' || *path == '\\')
  1634.       rc = 1;
  1635.     else if (isalpha(*path) && x > 1)
  1636.       if (*(path+1) == ':')
  1637.         rc = 1;
  1638. #endif /* GEMDOS */
  1639. #endif /* STRATUS */
  1640. #endif /* MAC */
  1641. #endif /* datageneral */
  1642. #endif /* OSK */
  1643. #endif /* AMIGA */
  1644. #endif /* OS2 */
  1645. #endif /* UNIX */
  1646. #endif /* VMS */
  1647.     debug(F101,"isabsolute rc","",rc);
  1648.     return(rc);
  1649. }
  1650.  
  1651. /*  See if I have direct access to the keyboard  */
  1652.  
  1653. int
  1654. is_a_tty(n) int n; {
  1655. #ifdef KUI
  1656.    return 1;
  1657. #else /* KUI */
  1658. #ifdef NT
  1659.     if (isWin95())
  1660.       return(1);
  1661.     else
  1662.       return(_isatty(n));
  1663. #else
  1664. #ifdef IKSD
  1665.    if (inserver)
  1666.      return(1);
  1667.    else
  1668. #endif /* IKSD */
  1669.      return(isatty(n));
  1670. #endif /* NT */
  1671. #endif /* KUI */
  1672. }
  1673.  
  1674. /* Initialize flow control table */
  1675.  
  1676. VOID
  1677. initflow() {                            /* Default values for flow control */
  1678. #ifdef VMS                              /* for each kind of connection. */
  1679.     /* The VMS telnet terminal driver treats "none" as request to lose chars */
  1680.     cxflow[CXT_REMOTE]  = FLO_XONX;     /* Remote mode... */
  1681. #else
  1682. #ifdef HPUX
  1683.     /* Ditto for HP-UX */
  1684.     cxflow[CXT_REMOTE]  = FLO_XONX;     /* Remote mode... */
  1685. #else
  1686.     /* The temptation is to make this one FLO_KEEP but don't!!! */
  1687.     /* It totally wrecks binary-file transfer when coming in via Telnet. */
  1688.     /* In UNIX at least... */
  1689.     cxflow[CXT_REMOTE]  = FLO_NONE;
  1690. #endif /* HPUX */
  1691. #endif /* VMS */
  1692.  
  1693. #ifdef VMS
  1694.     cxflow[CXT_DIRECT]  = FLO_XONX;     /* Direct serial connections... */
  1695. #else
  1696.     cxflow[CXT_DIRECT]  = FLO_NONE;
  1697. #endif /* VMS */
  1698.  
  1699. #ifdef CK_RTSCTS
  1700.     cxflow[CXT_MODEM]   = FLO_RTSC;     /* Modem connections... */
  1701. #else
  1702. #ifdef VMS
  1703.     cxflow[CXT_MODEM]   = FLO_XONX;
  1704. #else
  1705.     cxflow[CXT_MODEM]   = FLO_NONE;
  1706. #endif /* VMS */
  1707. #endif /* CK_RTSCTS */
  1708.  
  1709. #ifdef VMS
  1710.     cxflow[CXT_TCPIP]   = FLO_XONX;     /* TCP/IP connections... */
  1711. #else
  1712.     cxflow[CXT_TCPIP]   = FLO_NONE;
  1713. #endif /* VMS */
  1714.  
  1715.     cxflow[CXT_X25]     = FLO_NONE;     /* Other kinds of networks... */
  1716.     cxflow[CXT_DECNET]  = FLO_XONX;
  1717.     cxflow[CXT_LAT]     = FLO_XONX;
  1718.     cxflow[CXT_NETBIOS] = FLO_NONE;
  1719.     cxflow[CXT_NPIPE]   = FLO_NONE;
  1720.     cxflow[CXT_SSH]     = FLO_NONE;
  1721.     cxflow[CXT_PIPE]    = FLO_NONE;
  1722.     flow = cxflow[cxtype];              /* Initial flow setting. */
  1723.     debug(F101,"initflow","",flow);
  1724. }
  1725.  
  1726. #ifndef NOXFER
  1727. /* Initialize file transfer protocols */
  1728.  
  1729. VOID
  1730. initproto(y, upbstr, uptstr, srvstr, sndbstr, sndtstr, rcvbstr, rcvtstr)
  1731.     int y;
  1732.     char * upbstr, * uptstr, * srvstr, * sndbstr, * sndtstr, * rcvbstr,
  1733.     * rcvtstr;
  1734. /* initproto */ {
  1735.  
  1736.     if (upbstr)                         /* Convert null strings */
  1737.       if (!*upbstr)                     /* to null pointers */
  1738.         upbstr = NULL;
  1739.  
  1740.     if (uptstr)                         /* Convert null strings */
  1741.       if (!*uptstr)                     /* to null pointers */
  1742.         uptstr = NULL;
  1743.  
  1744.     if (sndbstr)
  1745.       if (!*sndbstr)
  1746.         sndbstr = NULL;
  1747.  
  1748.     if (sndtstr)
  1749.       if (!*sndtstr)
  1750.         sndtstr = NULL;
  1751.  
  1752.     if (rcvbstr)
  1753.       if (!*rcvbstr)
  1754.         rcvbstr = NULL;
  1755.  
  1756.     if (rcvtstr)
  1757.       if (!*rcvtstr)
  1758.         rcvtstr = NULL;
  1759.  
  1760.     if (srvstr)
  1761.       if (!*srvstr)
  1762.         srvstr = NULL;
  1763.  
  1764.     protocol = y;                       /* Set protocol */
  1765.  
  1766.     if (ptab[protocol].rpktlen > -1)
  1767.       urpsiz = ptab[protocol].rpktlen;
  1768.     if (ptab[protocol].spktflg > -1)
  1769.       spsizf = ptab[protocol].spktflg;
  1770.     if (ptab[protocol].spktlen > -1) {
  1771.         spsiz = ptab[protocol].spktlen;
  1772.         debug(F101,"initproto spsiz","",spsiz);
  1773.         if (spsizf) {
  1774.             spsizr = spmax = spsiz;
  1775.             debug(F101,"initproto spsizr","",spsizr);
  1776.         }
  1777.     }
  1778.     if (ptab[protocol].winsize > -1)
  1779.       wslotr = ptab[protocol].winsize;
  1780.     if (ptab[protocol].prefix > -1)
  1781.       prefixing = ptab[protocol].prefix;
  1782.     if (ptab[protocol].fnca > -1)
  1783.       fncact  = ptab[protocol].fnca;
  1784.     if (ptab[protocol].fncn > -1)
  1785.       fncnv   = ptab[protocol].fncn;
  1786.     if (ptab[protocol].fnsp > -1)
  1787.       fnspath = ptab[protocol].fnsp;
  1788.     if (ptab[protocol].fnrp > -1)
  1789.       fnrpath = ptab[protocol].fnrp;
  1790.  
  1791.     makestr(&(ptab[protocol].h_b_init),upbstr);
  1792.     makestr(&(ptab[protocol].h_t_init),uptstr);
  1793.     makestr(&(ptab[protocol].h_x_init),srvstr);
  1794.     makestr(&(ptab[protocol].p_b_scmd),sndbstr);
  1795.     makestr(&(ptab[protocol].p_t_scmd),sndtstr);
  1796.     makestr(&(ptab[protocol].p_b_rcmd),rcvbstr);
  1797.     makestr(&(ptab[protocol].p_t_rcmd),rcvtstr);
  1798. }
  1799.  
  1800. /* Filename pattern recognition lists for automatic text/binary switching */
  1801.  
  1802. #ifdef PATTERNS
  1803.  
  1804. int patterns = SET_AUTO;                /* Whether to use filename patterns */
  1805. char *txtpatterns[FTPATTERNS+1] = { NULL, NULL };
  1806. char *binpatterns[FTPATTERNS+1] = { NULL, NULL };
  1807. /*
  1808.   Default pattern lists for each platform...
  1809.  
  1810.   NOTE: We leave ".doc", ".hlp", ".ini", and ".scr" alone; although they are
  1811.   traditionally text types, they are binary in Windows.  So they are handled
  1812.   by the prevailing SET FILE TYPE, rather than automatically.  Similarly for
  1813.   ".dat", ".inf", and so on.  Also ".ps" since PostScript files are not
  1814.   always text.  ".log" is omitted since logs can be text or binary.
  1815. */
  1816. #ifdef UNIX
  1817. static char *txtp[FTPATTERNS] = {
  1818.     "*.txt","*.c","*.h","*.r","*.w","*.cpp","*.ksc","*.bwr","*.upd",
  1819.     "*.html","*.htm","*.mss","*.tex","*.nr","[Mm]akefile", "*.hex", "*.hqx",
  1820.     "*.for","*.f77","*.f","*.F","*.s","*.pas","*.java","*.el","*.lisp",
  1821.     "*.sh","*.perl","*.awk","*.sno","*.spt","*.sed",
  1822.     "*.TXT", "*read.me", "*READ.ME", ".*", "*/.*", NULL
  1823. };
  1824. /* Note: .DOC added to binary patterns June 1998... Microsoft wins. */
  1825.  
  1826. static char *binp[FTPATTERNS] = {
  1827.     "*.gz","*.Z","*.tgz","*.gif", "*.tar","*.zip","*.o","*.so","*.a","*.out",
  1828.     "*.exe", "*.jpg", "*.jpeg", "*.tif","*.tiff", "*.pdf", "*.so.*", "*.class",
  1829.     "*.rpm", "*.bmp", "*.bz2", "*.BMP", "*.dll", "*.doc", "*.vxd", "*.pdf",
  1830.     "*.xl*", "*.lzh", "*.lhz", "[wk]ermit",
  1831.     NULL
  1832. };
  1833. #else
  1834. #ifdef OSK
  1835. static char *txtp[FTPATTERNS] = {
  1836.     /* program sources */
  1837.     "*.c","*.cpp","*.h","*.a","*akefile",
  1838.     "*.for","*.f77","*.f","*.F","*.s","*.pas","*.java","*.el",".lisp",
  1839.     "*.sh","*.perl","*.awk","*.sno","*.spt","*.sed",
  1840.  
  1841.     /* general text */
  1842.     "*.txt","*.w",
  1843.     "*.ksc","*.bwr","*.upd",
  1844.     "*.html","*.htm","*.mss","*.tex","*.nr","*.hex", "*.hqx",
  1845.     "*.TXT", "*read.me", "*READ.ME", ".*", "*/.*",
  1846.     NULL
  1847. };
  1848. static char *binp[FTPATTERNS] = {
  1849.     /* archivers */
  1850.     "*.gz","*.Z","*.z","*.tgz","*.lhz","*.tar","*.zip","*.ar","*.zoo","*.rpm",
  1851.     "*.lzh",
  1852.     /* object files, libraries, executables */
  1853.     "*.r","*.l","*.exe", "*.dll", "*.so.*", "*.class",
  1854.     /* images */
  1855.     "*.gif", "*.jpg", "*.jpeg", "*.tif","*.tiff", "*.pdf",
  1856.     "*.bmp", ".bz2", "*.BMP","*.pcx",
  1857.     NULL
  1858. };
  1859. #else
  1860. #ifdef OS2
  1861. static char *txtp[FTPATTERNS] = {
  1862.     "*.txt","*.ksc","*.htm","*.html","*.bat","*.cmd","*.jav","*.asm", "*.hex",
  1863.      "*.hqx", "*.c", "*.h", "*.w", "*.java", "*.bwr", "*.upd",
  1864.      "read.me", "makefile", NULL
  1865. };
  1866. static char *binp[FTPATTERNS] = {       /* But note that .COM is text in VMS */
  1867.     "*.exe", "*.zip", "*.obj", "*.com", "*.gif", "*.jpg", "*.wav", "*.ram",
  1868.     "*.class", "*.cla", "*.dll", "*.drv", "*.ocx", "*.vbx", "*.lib", "*.ico",
  1869.     "*.bmp", "*.tif", "*.tar", "*.gz", "*.tgz", "*.xl*", "*.doc", "*.vxd",
  1870.     "*.pdf", "*.lzh", NULL
  1871. };
  1872. #else
  1873. #ifdef datageneral
  1874. static char *txtp[FTPATTERNS] = {
  1875.     "*.txt", "*.c", "*.h", "*.w", "*.er", "*.bwr", "*.upd", "read.me",
  1876.     "*.cli", "*.ksc", NULL
  1877. };
  1878. static char *binp[FTPATTERNS] = {       /* Add foreign types if anybody */
  1879.     "*.ob", "*.pr", "*.dmp", NULL       /* cares -- .exe, .zip, etc */
  1880. };
  1881. #else
  1882. #ifdef STRATUS
  1883. static char *txtp[FTPATTERNS] = {
  1884.     "*.txt","*.ksc","*.htm","*.html","*.bat","*.cmd","*.jav","*.asm", "*.hex",
  1885.      "*.hqx", "*.c", "*.h", "*.w", "*.java", "*.bwr", "*.upd","*.ttp","*.cm",
  1886.      "*.pl1", "*.emacs", "read.me", "*.pl", "makefile", NULL
  1887. };
  1888. static char *binp[FTPATTERNS] = {       /* But note that .COM is text in VMS */
  1889.     "*.exe", "*.zip", "*.obj", "*.com", "*.gif", "*.jpg", "*.wav", "*.ram",
  1890.     "*.class", "*.cla", "*.dll", "*.drv", "*.ocx", "*.vbx", "*.lib", "*.ico",
  1891.     "*.bmp", "*.tif", "*.tar", "*.gz", "*.tgz", "*.xl*", "*.doc", "*.vxd",
  1892.     "*.pdf", "*.lzh", "*.pm", NULL
  1893. };
  1894. #else
  1895. /* Fill in others here if appropriate */
  1896. static char *binp[FTPATTERNS] = { NULL, NULL };
  1897. static char *txtp[FTPATTERNS] = { NULL, NULL };
  1898. #endif /* STRATUS */
  1899. #endif /* datageneral */
  1900. #endif /* OS2 */
  1901. #endif /* OSK */
  1902. #endif /* UNIX */
  1903. /*
  1904.   Set up default pattern lists so they can be freed and re-malloc'd.
  1905.   Each pattern list must terminated by a null element.
  1906. */
  1907. VOID
  1908. initpat() {
  1909.     int i;
  1910.     for (i = 0; i < FTPATTERNS; i++) {
  1911.         txtpatterns[i] = NULL;
  1912.         binpatterns[i] = NULL;
  1913.     }
  1914.     for (i = 0; i < FTPATTERNS; i++) {
  1915.         makestr(&(txtpatterns[i]),txtp[i]);
  1916.         if (!txtp[i])
  1917.           break;
  1918.     }
  1919.     for (i = 0; i < FTPATTERNS; i++) {
  1920.         makestr(&(binpatterns[i]),binp[i]);
  1921.         if (!binp[i])
  1922.           break;
  1923.     }
  1924. }
  1925. #endif /* PATTERNS */
  1926. #endif /* NOXFER */
  1927.  
  1928. #ifndef NOCMDL
  1929. VOID
  1930. #ifdef CK_ANSIC
  1931. docmdline(void * threadinfo)
  1932. #else /* CK_ANSIC */
  1933. docmdline(threadinfo) VOID * threadinfo;
  1934. #endif /* CK_ANSIC */
  1935. {
  1936. #ifdef NTSIG
  1937.     setint();
  1938.     if (threadinfo) {                   /* Thread local storage... */
  1939.        TlsSetValue(TlsIndex,threadinfo);
  1940.        debug( F100, "docmdline called with threadinfo block", "", 0 );
  1941.     } else
  1942.       debug( F100, "docmdline threadinfo is NULL","",0);
  1943. #endif /* NTSIG */
  1944. #ifdef CK_LOGIN
  1945. #ifdef NT
  1946. #ifdef IKSD
  1947.     if (inserver)
  1948.       setntcreds();
  1949. #endif /* IKSD */
  1950. #endif /* NT */
  1951. #endif /* CK_LOGIN */
  1952.     proto();                            /* Take any requested action, then */
  1953.     if (!quiet)                         /* put cursor back at left margin, */
  1954.       conoll("");
  1955. #ifndef NOLOCAL
  1956.     if (cnflg) {                        /* Re-connect if requested */
  1957.         cnflg = 0;
  1958.         doconect(0);
  1959. #ifdef CKLOGDIAL
  1960.         if (ttchk() < 0)
  1961.           dologend();
  1962. #endif /* CKLOGDIAL */
  1963.     }
  1964. #endif /* NOLOCAL */
  1965.  
  1966. #ifdef NTSIG
  1967.      ckThreadEnd(threadinfo);
  1968. #endif /* NTSIG */
  1969.    return;
  1970. }
  1971.  
  1972. void
  1973. ikslogin()
  1974. {
  1975.     if (sstelnet
  1976. #ifdef IKSD
  1977.         || inserver                     /* Internet server */
  1978. #endif /* IKSD */
  1979.         ) {
  1980.         char *s;
  1981.         extern int ckxech;              /* Echo state for command parser */
  1982.         extern int fdispla;             /* File-transfer display format */
  1983.         extern char * ikprompt;         /* IKSD prompt */
  1984.  
  1985. #ifdef IKSD
  1986. #ifdef CK_LOGIN
  1987.         if (inserver) {
  1988.             x_login = 1;                /* Login required */
  1989.             x_logged = 0;               /* Not logged in yet */
  1990.             cmsetp(ikprompt);           /* Set up IKSD's prompt */
  1991. #ifndef NOSERVER
  1992.             en_mai = 0;                 /* MAIL is disabled */
  1993.             en_who = 0;                 /* REMOTE WHO is disabled */
  1994.             en_hos = 0;                 /* REMOTE HOST is disabled */
  1995.             en_pri = 0;                 /* PRINT is disabled */
  1996. #endif /* NOSERVER */
  1997.         } else {
  1998.             x_login = 0;                /* Login not required */
  1999.             x_logged = 1;               /* Already logged in */
  2000.         }
  2001. #endif /* CK_LOGIN */
  2002. #endif /* IKSD */
  2003.         nolocal = 1;                    /* SET LINE/HOST not allowed */
  2004.         fdispla = XYFD_N;               /* No file-transfer display */
  2005. #ifdef NETCONN
  2006.         clienthost = ckgetpeer();       /* Get client's hostname */
  2007.         debug(F110,"ikslogin clienthost",clienthost,0);
  2008. #endif /* NETCONN */
  2009.         ztime(&s);                      /* Get current date and time */
  2010.  
  2011. #ifdef CK_LOGIN
  2012. #ifdef CK_AUTHENTICATION
  2013.         if (x_login) {
  2014.             x_logged = ck_tn_auth_valid(); /* Did Telnet Auth succeed? */
  2015.             debug(F111,"ikslogin","x_logged",x_logged);
  2016.             if (x_logged == AUTH_VALID) {
  2017. #ifdef CK_SSL
  2018.                 if ((ssl_active_flag || tls_active_flag) &&
  2019.                      (!TELOPT_U(TELOPT_AUTHENTICATION) ||
  2020.                        ck_tn_authenticated() == AUTHTYPE_NULL ||
  2021.                        ck_tn_authenticated() == AUTHTYPE_AUTO)) {
  2022.                     printf("Authenticated using X.509 certificate\r\n");
  2023. #ifdef CKSYSLOG
  2024.             if (ckxsyslog >= SYSLG_LI && ckxlogging) {
  2025.             extern char szUserNameAuthenticated[];
  2026.             cksyslog(SYSLG_LI, 1, "AUTH_VALID",
  2027.                  "X.509 certificate",
  2028.                  szUserNameAuthenticated
  2029.                  );
  2030.             }
  2031. #endif /* CKSYSLOG */
  2032.                 } else
  2033. #endif /* CK_SSL */
  2034.           {
  2035.               printf("Authenticated using %s\r\n",
  2036.                  AUTHTYPE_NAME(ck_tn_authenticated()));
  2037. #ifdef CKSYSLOG
  2038.               if (ckxsyslog >= SYSLG_LI && ckxlogging) {
  2039.               extern char szUserNameAuthenticated[];
  2040.               cksyslog(SYSLG_LI, 1, "AUTH_VALID",
  2041.                    AUTHTYPE_NAME(ck_tn_authenticated()),
  2042.                    szUserNameAuthenticated
  2043.                    );
  2044.               }
  2045. #endif /* CKSYSLOG */
  2046.           }
  2047. #ifdef NT
  2048.                 /* On Windows, only NTLM provides actual account login */
  2049.                 /* and therefore does not require a call to zvpass()   */
  2050.                 /* other authentication systems can't provide actual   */
  2051.                 /* account login.                                      */
  2052.                 if (isWin95()) {
  2053.                     x_logged = 0;
  2054.                     printf("WARNING:\r\n");
  2055.                     printf(
  2056.  "  Telnet authentication methods cannot be used for automated login to\r\n");
  2057.                     printf(
  2058.  "  Windows 95 or Windows 98.  A password must be entered locally to\r\n");
  2059.                     printf(
  2060.  "  validate your userid.  Telnet authentication (and encryption) may be\r\n");
  2061.                     printf(
  2062.  "  used to validate the host and protect the privacy of your password.\r\n");
  2063.                     zvuser(uidbuf);
  2064.                 } else {
  2065.                     zvuser(uidbuf);
  2066.                     if (zvpass("") == 0)
  2067.                         x_logged = 0;
  2068.                 }
  2069. #else /* NT */
  2070.                 zvuser(uidbuf);
  2071.                 if (zvpass("") == 0)
  2072.                     x_logged = 0;
  2073. #endif /* NT */
  2074.             } else if (x_logged == AUTH_USER &&
  2075.                        !strcmp(uidbuf,"anonymous")) {
  2076.                 extern char szUserNameAuthenticated[];
  2077.                 zvuser(uidbuf);
  2078.                 debug(F110,"XXX szUserNameAuthenticated",
  2079.                       szUserNameAuthenticated,0);
  2080.                 if (zvpass(szUserNameAuthenticated) == 0)
  2081.                   x_logged = 0;
  2082.                 else
  2083.                   printf("Authenticated using %s\r\n",
  2084.                          AUTHTYPE_NAME(ck_tn_authenticated())
  2085.                          );
  2086. #ifdef CKSYSLOG
  2087.                 if (ckxsyslog >= SYSLG_LI && ckxlogging) {
  2088.                     cksyslog(SYSLG_LI, 1, "AUTH_USER",
  2089.                              AUTHTYPE_NAME(ck_tn_authenticated()),
  2090.                              szUserNameAuthenticated
  2091.                              );
  2092.                 }
  2093. #endif /* CKSYSLOG */
  2094.             } else {
  2095. #ifdef CKSYSLOG
  2096.                 if (ckxsyslog >= SYSLG_LI && ckxlogging &&
  2097.                     x_logged == AUTH_USER) {
  2098.                     extern char szUserNameAuthenticated[];
  2099.                     cksyslog(SYSLG_LI, 1, "AUTH_USER",
  2100.                              AUTHTYPE_NAME(ck_tn_authenticated()),
  2101.                              szUserNameAuthenticated
  2102.                              );
  2103.                 }
  2104. #endif /* CKSYSLOG */
  2105.                 x_logged = 0;
  2106.                 if (!strcmp("(unknown)",uidbuf)
  2107. #ifdef NT
  2108.                     || !stricmp("administrator",uidbuf)
  2109. #ifdef UNIX
  2110.                     || !strcmp("root",uidbuf)
  2111. #else
  2112. #ifdef Plan9
  2113.                     || !strcmp("root",uidbuf)
  2114. #else
  2115. #ifdef OSK
  2116.                     || !strcmp("root",uidbuf)
  2117. #endif /* OSK */
  2118. #endif /* Plan9 */
  2119. #endif /* UNIX */
  2120. #endif /* NT */
  2121.                     )
  2122.                   uidbuf[0] = '\0';
  2123.             }
  2124.         }
  2125. #endif /* CK_AUTHENTICATION */
  2126. #endif /* CK_LOGIN */
  2127.  
  2128. #ifdef IKSD
  2129.         if (inserver)
  2130.           printf("\r\nInternet Kermit Service ready at %s%s\r\n",s,versio);
  2131.         else
  2132. #endif /* IKSD */
  2133.           printf("\r\nC-Kermit ready at %s%s\r\n",s,versio);
  2134.         if (*myhost)
  2135.           printf("%s\r\n", myhost);
  2136.         printf("\r\n");
  2137.     }
  2138. #ifdef CK_LOGIN
  2139. #ifdef IKSD
  2140.     if (inserver) {
  2141.         int i;
  2142.         extern int arg_x;               /* Flag for '-x' on command line */
  2143.         debug(F110,"MAIN clienthost",clienthost,0);
  2144.         srvidl = timelimit = logintimo;    /* For interactive login */
  2145.         rtimer();                       /* Reset timer */
  2146.         for (i = 0; i < iks_retry && !x_logged; i++) { /* Count retries */
  2147.             if (gtimer() > logintimo)
  2148.               break;
  2149. #ifdef TNCODE
  2150.             tn_wait("login loop");
  2151.             tn_push();
  2152. #endif /* TNCODE */
  2153.             debug(F101,"MAIN LOGIN try","",i);
  2154.             what = W_NOTHING;           /* Because proto() changes this */
  2155.  
  2156. #ifdef IKS_OPTION
  2157.             debug(F111,"MAIN LOGIN",
  2158.                   "TELOPT_SB(TELOPT_KERMIT).kermit.me_start",
  2159.                   TELOPT_SB(TELOPT_KERMIT).kermit.me_start
  2160.                   );
  2161.             /* Kermit server negotiated */
  2162.             if (TELOPT_SB(TELOPT_KERMIT).kermit.me_start) {
  2163.                 debug(F101,"IKSD starting in server mode","",0);
  2164.                 arg_x = 1;              /* Enter server mode */
  2165.                 sstate = 'x';
  2166. #ifdef IKSDPOPBACK
  2167.                 justone = 1;            /* Execute one command at a time. */
  2168. #endif /* IKSDPOPBACK */
  2169.                 proto();                /* Enter protocol if requested. */
  2170. #ifdef NTSIG
  2171.                 ck_ih();
  2172. #endif /* NTSIG */
  2173.                 if (x_logged)           /* Logged in */
  2174.                   break;
  2175.             } else {                    /* Not in client/server mode */
  2176. #endif /* IKS_OPTION */
  2177.                 debug(F101,"IKSD starting with Username prompt","",0);
  2178.                 x_logged = ckxlogin((CHAR *)uidbuf,NULL,NULL,1);
  2179.                 if (sstate) {           /* Received a packet at prompt */
  2180. #ifdef IKSDPOPBACK
  2181.                     justone = 1;        /* Go handle it */
  2182. #endif /* IKSDPOPBACK */
  2183.                     proto();
  2184.                 }
  2185.                 if (!x_logged) {        /* In case we are at the prompt... */
  2186.                     printf("Access denied.\n");
  2187.                     uidbuf[0] = '\0';   /* Forget the name if we have one */
  2188.                 }
  2189. #ifdef IKS_OPTION
  2190.             }
  2191. #endif /* IKS_OPTION */
  2192.         }
  2193.         srvidl = timelimit = iks_timo;  /* Reset command timelimit */
  2194.         debug(F101,"MAIN LOGIN","",x_logged);
  2195.         if (!x_logged) {                /* Logins failed. */
  2196.             if (TELOPT_SB(TELOPT_KERMIT).kermit.me_start)
  2197.               errpkt((CHAR *)"Login Timeout");
  2198.             msleep(500);
  2199.             doexit(BAD_EXIT,0);
  2200.         }
  2201.         what = W_NOTHING;               /* Stay in known state */
  2202. #ifndef NOSERVER
  2203.         if (isguest) {
  2204.             en_pri = 0;                 /* No printing for anonymous users */
  2205.             en_mai = 0;                 /* No email for anonymous users */
  2206.             en_mkd = 0;                 /* Or directory creation */
  2207.             en_rmd = 0;                 /* Or directory removal */
  2208.             en_ena = 0;                 /* Or ENABLing DISABLEd items */
  2209.         }
  2210. #endif /* NOSERVER */
  2211.     } /* if (inserver) */
  2212. #else /* CK_LOGIN */
  2213.     if (inserver)
  2214.         srvidl = timelimit = iks_timo;  /* Set idle limits for IKS */
  2215. #endif /* CK_LOGIN */
  2216. #endif /* IKSD */
  2217. }
  2218.  
  2219. VOID
  2220. #ifdef CK_ANSIC
  2221. failcmdline(void * foo)
  2222. #else /* CK_ANSIC */
  2223. failcmdline(foo) VOID * foo;
  2224. #endif /* CK_ANSIC */
  2225. {
  2226. #ifdef GEMDOS
  2227.     cc_clean();
  2228. #endif /* GEMDOS */
  2229. #ifndef NOLOCAL
  2230.     if (cnflg) doconect(0);             /* connect again if requested. */
  2231. #ifdef CKLOGDIAL
  2232.     if (ttchk() < 0)
  2233.       dologend();
  2234. #endif /* CKLOGDIAL */
  2235. #endif /* NOLOCAL */
  2236. }
  2237. #endif /* NOCMDL */
  2238.  
  2239. #ifndef NOICP
  2240. VOID
  2241. #ifdef CK_ANSIC
  2242. dotakeini(void * threadinfo)            /* Execute init file. */
  2243. #else  /* CK_ANSIC */
  2244. dotakeini(threadinfo) VOID * threadinfo; /* Execute init file. */
  2245. #endif /* CK_ANSIC */
  2246. /* dotakeini */ {
  2247. #ifdef NTSIG
  2248.     setint();
  2249.     if (threadinfo) {                   /* Thread local storage... */
  2250.        TlsSetValue(TlsIndex,threadinfo);
  2251.        debug(F100, "dotakeini called with threadinfo block","", 0);
  2252.     } else
  2253.       debug(F100, "dotakeini - threadinfo is NULL", "", 0);
  2254. #endif /* NTSIG */
  2255. #ifdef CK_LOGIN
  2256. #ifdef NT
  2257. #ifdef IKSD
  2258.     if (inserver)
  2259.       setntcreds();
  2260. #endif /* IKSD */
  2261. #endif /* NT */
  2262. #endif /* CK_LOGIN */
  2263.     cmdini();                           /* Sets tlevel */
  2264.  
  2265.     debug(F111,"dotakeini","inserver",inserver);
  2266.     debug(F111,"dotakeini","sstelnet",sstelnet);
  2267.  
  2268. #ifdef COMMENT
  2269. /* Wrong place for this... */
  2270. #ifndef NOXFER
  2271. #ifdef CK_FAST
  2272.     dofast();                           /* By now FAST defaults should be OK */
  2273. #endif /* CK_FAST */
  2274. #endif /* NOXFER */
  2275. #endif /* COMMENT */
  2276.  
  2277.     doinit();                           /* Now do the initialization file */
  2278.     debug(F101,"main executing init file","",tlevel);
  2279.     while (tlevel > -1) {
  2280.         sstate = (CHAR) parser(1);      /* Execute one command at a time. */
  2281.         if (sstate) proto();            /* Enter protocol if requested. */
  2282. #ifdef NTSIG
  2283.         ck_ih();
  2284. #endif /* NTSIG */
  2285.     }
  2286.     debug(F101,"main exits init file","",tlevel);
  2287.  
  2288. #ifdef NTSIG
  2289.     ckThreadEnd(threadinfo);
  2290. #endif /* NTSIG */
  2291.     return;
  2292. }
  2293.  
  2294. VOID
  2295. #ifdef CK_ANSIC
  2296. failtakeini(void * threadinfo)
  2297. #else /* CK_ANSIC */
  2298. failtakeini(threadinfo) VOID * threadinfo;
  2299. #endif /* CK_ANSIC */
  2300. /* failtakeini */ {
  2301. #ifdef GEMDOS
  2302.     cc_clean();                         /* Atari: Clean up after ^C-trap. */
  2303. #endif /* GEMDOS */
  2304.     if (!cfilef) {
  2305.         conoll("Interrupt during initialization or command-line processing.");
  2306.         conoll("C-Kermit quitting...");
  2307.     }
  2308.     doexit(BAD_EXIT,-1);                /* Exit with bad status. */
  2309. }
  2310.  
  2311. VOID
  2312. #ifdef CK_ANSIC
  2313. doicp(void * threadinfo)
  2314. #else /* CK_ANSIC */
  2315. doicp(threadinfo) VOID * threadinfo;
  2316. #endif /* CK_ANSIC */
  2317. /* doicp */ {
  2318. #ifdef NTSIG
  2319.     setint();
  2320.     if (threadinfo) {                   /* Thread local storage... */
  2321.        if (!TlsSetValue(TlsIndex,threadinfo))
  2322.           debug(F101,"doicp TlsSetValue failed","",GetLastError());
  2323.        debug(F101, "doicp a threadinfo block - TlsIndex", "", TlsIndex);
  2324.     } else {
  2325.         debug(F100, "doicp received a null threadinfo", "", 0);
  2326.     }
  2327. #endif /* NTSIG */
  2328. #ifdef CK_LOGIN
  2329. #ifdef NT
  2330. #ifdef IKSD
  2331.     if (inserver)
  2332.       setntcreds();
  2333. #endif /* IKSD */
  2334. #endif /* NT */
  2335. #endif /* CK_LOGIN */
  2336. #ifdef MAC
  2337.     while (1) {
  2338.         extern char *lfiles;            /* Fake pointer cast */
  2339.  
  2340.         if (connected) {
  2341.             debug(F100, "doicp: calling macparser", "", 0);
  2342.             sstate = newparser(1, 1, 0L);
  2343.  
  2344.             /* ignore null command state */
  2345.             if (sstate == 'n')
  2346.               sstate = '\0';
  2347.  
  2348.             if (sstate)
  2349.               proto();
  2350.         } else {
  2351.             /*
  2352.              * process take files the finder gave us.
  2353.              */
  2354.             if ((tlevel == -1) && lfiles)
  2355.               startlfile();
  2356.  
  2357.             debug(F100, "doicp: calling parser", "", 0);
  2358.             sstate = (CHAR) parser(0);
  2359.             if (sstate == 'c')          /* if MAC connect */
  2360.               sstate = 0;
  2361.             if (sstate)
  2362.               proto();
  2363.         }
  2364.     }
  2365. #else /* Not MAC */
  2366.  
  2367. #ifndef NOSPL
  2368. /*
  2369.   If interactive commands were given on the command line (using the
  2370.   -C "command, command, ..." option), assign them to a macro called
  2371.   "cl_commands", then execute the macro and leave it defined for
  2372.   subsequent re-execution if desired.
  2373. */
  2374.     if (clcmds) {                       /* Check for -C commands */
  2375.         int x;
  2376.         x = addmac("cl_commands",clcmds); /* Put macro in table */
  2377.         if (x > -1) {                   /* If successful, */
  2378.             dodo(x,NULL,CF_CMDL);       /* set up for macro execution */
  2379.             while (maclvl > -1) {       /* Loop getting macro commands. */
  2380.                 sstate = (CHAR) parser(1);
  2381.                 if (sstate) proto();    /* Enter protocol if requested. */
  2382. #ifdef NTSIG
  2383.                 ck_ih();
  2384. #endif /* NTSIG */
  2385.             }
  2386.         }
  2387.         herald();
  2388.     }
  2389. #endif /* NOSPL */
  2390.     while(1) {                          /* Loop getting commands. */
  2391.         sstate = (CHAR) parser(0);
  2392.         if (sstate) proto();            /* Enter protocol if requested. */
  2393. #ifdef NTSIG
  2394.        ck_ih();
  2395. #endif /* NTSIG */
  2396.     }
  2397. #ifdef NTSIG
  2398.     ckThreadEnd(threadinfo);
  2399. #endif /* NTSIG */
  2400. #endif /* MAC */
  2401. }
  2402.  
  2403. VOID
  2404. #ifdef CK_ANSIC
  2405. failicp(void * threadinfo)
  2406. #else /* CK_ANSIC */
  2407. failicp(threadinfo) VOID * threadinfo;
  2408. #endif /* CK_ANSIC */
  2409. {
  2410. #ifdef GEMDOS
  2411.     cc_clean();
  2412. #endif /* GEMDOS */
  2413.     fixcmd();                           /* Pop command stacks, etc. */
  2414.     clcmds = NULL;
  2415.     debug(F100,"ckcmai got interrupt","",0);
  2416. }
  2417. #endif /* NOICP */
  2418.  
  2419. #ifndef NOICP
  2420. VOID
  2421. #ifdef CK_ANSIC
  2422. docmdfile(void * threadinfo)            /* Execute application file */
  2423. #else /* CK_ANSIC */
  2424. docmdfile(threadinfo) VOID * threadinfo;
  2425. #endif /* CK_ANSIC */
  2426. /* docmdfile */ {
  2427. #ifdef NTSIG
  2428.     concb((char)escape);
  2429.     setint();
  2430.     if (threadinfo) {                   /* Thread local storage... */
  2431.         TlsSetValue(TlsIndex,threadinfo);
  2432.         debug(F100, "docmdfile called with threadinfo block","", 0);
  2433.     } else debug(F100, "docmdfile - threadinfo is NULL", "", 0);
  2434. #endif /* NTSIG */
  2435. #ifdef CK_LOGIN
  2436. #ifdef IKSD
  2437. #ifdef NT
  2438.     if (inserver)
  2439.       setntcreds();
  2440. #endif /* NT */
  2441. #endif /* IKSD */
  2442. #endif /* CK_LOGIN */
  2443.     debug(F110,"main cmdfil",cmdfil,0);
  2444. #ifndef NOSPL
  2445.     addmac("\\%0",cmdfil);
  2446. #endif /* NOSPL */
  2447.     dotake(cmdfil);                     /* execute it */
  2448.     while (tlevel > -1) {               /* until it runs out. */
  2449.         sstate = parser(1);             /* Loop getting commands. */
  2450.         if (sstate) proto();            /* Enter protocol if requested. */
  2451. #ifdef NTSIG
  2452.         ck_ih();
  2453. #endif /* NTSIG */
  2454.     }
  2455.     cfilef = 1;                         /* Remember we did this */
  2456.  
  2457. #ifdef NTSIG
  2458.     ckThreadEnd(threadinfo);
  2459. #endif /* NTSIG */
  2460.     return;
  2461. }
  2462.  
  2463. VOID
  2464. #ifdef CK_ANSIC
  2465. failcmdfile(void * threadinfo)
  2466. #else /* CK_ANSIC */
  2467. failcmdfile(threadinfo) VOID * threadinfo;
  2468. #endif /* CK_ANSIC */
  2469. /* failcmdfile */ {
  2470. #ifdef GEMDOS
  2471.     cc_clean();                         /* Atari: Clean up after ^C-trap. */
  2472. #endif /* GEMDOS */
  2473.     if (!cfilef) {
  2474.         conoll("Interrupt during initialization or command-line processing.");
  2475.         conoll("C-Kermit quitting...");
  2476.     }
  2477.     doexit(BAD_EXIT,-1);                /* Exit with bad status. */
  2478. }
  2479. #endif /* NOICP */
  2480.  
  2481. #ifndef NOXFER
  2482. VOID
  2483. setprefix(z) int z; {                   /* Initial control-char prefixing */
  2484. #ifdef CK_SPEED
  2485.     int i, val;
  2486.  
  2487.     prefixing = z;
  2488.     ptab[protocol].prefix = prefixing;
  2489.     debug(F101,"setprefix","",prefixing);
  2490.     switch (z) {
  2491.       case PX_ALL:                      /* All */
  2492. #ifdef COMMENT
  2493.         /* Don't let Clear-Channel be dependent on prefixing */
  2494.         clearrq = 0;                    /* Turn off clearchannel, fall thru */
  2495. #endif /* COMMENT */
  2496.       case PX_NON:                      /* None */
  2497.         val = (z == PX_ALL) ? 1 : 0;
  2498.         for (i =
  2499. #ifdef UNPREFIXZERO
  2500.              0
  2501. #else
  2502.              1
  2503. #endif /* UNPREFIXZERO */
  2504.              ; i < 32; i++)
  2505.           ctlp[i] = val;
  2506.         for (i = 127; i < 160; i++) ctlp[i] = val;
  2507.         ctlp[(unsigned)255] = val;
  2508.         if (z == PX_NON) {              /* These are never safe */
  2509.         if (network) {        /* Assume network = telnet or rlogin */
  2510.         ctlp[CR] = 1;        /* Prefix CR because of NVT rules */
  2511.         ctlp[XON] = ctlp[XOFF] = 1; /* Because of Telnet server */
  2512.         ctlp[127] = ctlp[255] = 1;  /* Telnet IAC */
  2513.         ctlp[mystch] = ctlp[mystch+128] = 1; /* Kermit packet start */
  2514.         } else {
  2515.         ctlp[CR] = ctlp[255] = ctlp[mystch] = ctlp[mystch+128] = 1;
  2516.         if (flow == FLO_XONX)       /* Xon/Xoff forces prefixing */
  2517.           ctlp[XON] = ctlp[XOFF] = ctlp[XON+128] = ctlp[XOFF+128] = 1;
  2518.         }
  2519.         }
  2520.         break;
  2521.  
  2522.       case PX_CAU:                      /* Cautious or Minimal */
  2523. #ifdef COMMENT
  2524.         /* Don't let CLEAR-CHANNEL be dependent on Prefixing */
  2525.         clearrq = 0;                    /* Turn off clearchannel */
  2526. #endif /* COMMENT */
  2527.       case PX_WIL:                      /* Minimal ("wild") */
  2528.         ctlp[0] = 1;                    /* Does not include 0 */
  2529.         for (i = 1; i < 32; i++)
  2530.           ctlp[i] = 0;
  2531.         for (i = 127; i < 160; i++)
  2532.           ctlp[i] = 0;
  2533.         ctlp[mystch] = ctlp[mystch+128] = 1; /* Kermit start of packet */
  2534.         if (seol != 13)
  2535.           ctlp[seol] = ctlp[seol+128] = 1; /* Kermit end */
  2536.         ctlp[13] = ctlp[141] = 1;       /* In case of TELNET (NVT rules) */
  2537.         ctlp[(unsigned)255] = 1;        /* Ditto */
  2538.  
  2539.         /* ^D, ^J, ^M, or ^U followed by tilde trigger Rlogin escape */
  2540.  
  2541.         ctlp[4]  = ctlp[4+128]  = 1;    /* In case of RLOGIN */
  2542.         ctlp[10] = ctlp[10+128] = 1;    /* In case of RLOGIN */
  2543.         ctlp[21] = ctlp[21+128] = 1;    /* In case of RLOGIN */
  2544.  
  2545.         if (flow == FLO_XONX ||         /* Xon/Xoff forces prefixing these */
  2546.             prefixing == PX_CAU ||    /* So does CAUTIOUS */
  2547.         network)            /* Networks too... */
  2548.           ctlp[XON] = ctlp[XOFF] = ctlp[XON+128] = ctlp[XOFF+128] = 1;
  2549.         if (prefixing == PX_CAU) {      /* Cautious - add some more */
  2550. #ifdef UNPREFIXZERO
  2551.             ctlp[0] = 1;
  2552. #endif /* UNPREFIXZERO */
  2553.             ctlp[3]   = ctlp[16]  = 1;             /* ^C, DLE */
  2554.             ctlp[14]  = ctlp[15]  = 1;             /* SO/SI */
  2555.             ctlp[24]  = ctlp[25]  = 1;             /* VMS might need these */
  2556.             ctlp[26]  = ctlp[26+128] = 1;          /* UNIX suspend */
  2557.             ctlp[28]  = ctlp[29]  = ctlp[30]  = 1; /* Assorted esc chars */
  2558.             ctlp[131] = ctlp[141] = ctlp[144] = 1; /* and 8-bit versions */
  2559.             ctlp[(unsigned)255] = ctlp[156] = ctlp[157] = ctlp[158] = 1;
  2560.         }
  2561.         break;
  2562.     }
  2563. #endif /* CK_SPEED */
  2564. }
  2565. #endif /* NOXFER */
  2566.  
  2567. VOID
  2568. makever() {                             /* Make version string from pieces */
  2569.     int x, y;
  2570. #ifndef OS2
  2571. #ifndef MAC
  2572.     ck_s_xver = ck_s_ver;               /* Fill in C-Kermit version number */
  2573.     ck_l_xver = ck_l_ver;               /* for UNIX, VMS, etc. */
  2574. #endif /* MAC */
  2575. #endif /* OS2 */
  2576.     x = strlen(ck_s_name);
  2577.     y = strlen(ck_s_xver);
  2578.     if (y + x + 1 < CKVERLEN) {
  2579.         sprintf(versio,"%s %s",ck_s_name,ck_s_xver);
  2580.     } else {
  2581.         sprintf(versio,"C-Kermit");
  2582.         return;
  2583.     }
  2584.     x += y + 1;
  2585.     if (*ck_s_who) {
  2586.         y = strlen(ck_s_who);
  2587.         if (CKVERLEN < x + y + 1)
  2588.           return;
  2589.         strcat(versio,"-");
  2590.         strcat(versio,ck_s_who);
  2591.     }
  2592.     x += y + 1;
  2593.     y = strlen(ck_s_test);
  2594.     if (y > 0 && y + x + 1 < CKVERLEN) {
  2595.         strcat(versio," ");
  2596.         strcat(versio,ck_s_test);
  2597.         x += y + 1;
  2598.         y = strlen(ck_s_tver);
  2599.         if (y > 0 && y + x + 1 < CKVERLEN) {
  2600.             strcat(versio,".");
  2601.             strcat(versio,ck_s_tver);
  2602.             x += y + 1;
  2603.         }
  2604.     }
  2605.     y = strlen(ck_s_date);
  2606.     if (y > 0 && y + x + 2 < CKVERLEN) {
  2607.         strcat(versio,", ");
  2608.         strcat(versio,ck_s_date);
  2609.     }
  2610.     vernum = ck_l_ver;
  2611.     xvernum = ck_l_xver;
  2612.     debug(F110,"Kermit version",versio,0);
  2613. }
  2614.  
  2615. union ck_short shortbytes;              /* For determining byte order */
  2616. int byteorder = 0;                      /* 0 = Big Endian; 1 = Little Endian */
  2617. int bigendian = 1;
  2618. /* NOTE: MUST BE 0 or 1 - nothing else */
  2619.  
  2620. /*
  2621.   main()...
  2622.  
  2623.   If you get complaints about "main: return type is not blah",
  2624.   define MAINTYPE on the CC command line, e.g. "CFLAGS=-DMAINTYPE=blah"
  2625.   (where "blah" is int, long, or whatever).
  2626.  
  2627.   If the complaint is "Attempt to return a value from a function of type void"
  2628.   then add -DMAINISVOID.
  2629. */
  2630. #ifndef MAINTYPE
  2631. #ifndef MAINISVOID
  2632. #define MAINTYPE int
  2633. #endif /* MAINISVOID */
  2634. #endif /* MAINTYPE */
  2635.  
  2636. #ifdef MAINISVOID
  2637. #ifndef MAINTYPE
  2638. #define MAINTYPE void
  2639. #endif /* MAINTYPE */
  2640. #endif /* MAINISVOID */
  2641.  
  2642. #ifdef aegis
  2643. /* On the Apollo, intercept main to insert a cleanup handler */
  2644. int
  2645. ckcmai(argc,argv) int argc; char **argv;
  2646. #else
  2647. #ifdef MAC                              /* Macintosh */
  2648. int
  2649. main (void)
  2650. #else
  2651. #ifdef __GNUC__                         /* GCC compiler */
  2652. int
  2653. main(argc,argv) int argc; char **argv;
  2654. #else
  2655. #ifdef __DECC                           /* DEC Alpha with DEC C compiler */
  2656. #ifdef __ALPHA
  2657. int
  2658. main(argc,argv) int argc; char **argv;
  2659. #else                                   /* DEC C compiler, not Alpha */
  2660. #define MAINISVOID
  2661. VOID
  2662. main(argc,argv) int argc; char **argv;
  2663. #endif  /* __ALPHA */
  2664. #else
  2665. #ifdef STRATUS                          /* Stratus VOS */
  2666. int
  2667. main(argc,argv) int argc; char **argv;
  2668. #else                                   /* K-95 */
  2669. #ifdef OS2
  2670. #ifdef KUI
  2671. #define MAINISVOID
  2672. void
  2673. Main( int argc, char ** argv )
  2674. #else /* KUI */
  2675. #define MAINISVOID
  2676. VOID
  2677. main(argc,argv) int argc; char **argv;
  2678. #endif /* KUI */
  2679. #else  /* Not K95 */
  2680. MAINTYPE                                /* All others... */
  2681. main(argc,argv) int argc; char **argv;
  2682. #endif /* OS2 */
  2683. #endif /* STRATUS */
  2684. #endif /* __DECC */
  2685. #endif /* __GNUC__ */
  2686. #endif /* MAC */
  2687. #endif /* aegis */
  2688.  
  2689. /* main */ {
  2690.  
  2691.     char *p;
  2692.  
  2693. #ifndef NOSETKEY
  2694.     int i;
  2695. #endif /* NOSETKEY */
  2696.  
  2697. #ifdef datageneral
  2698.     short *pfha = 016000000036;         /* Get around LANG_RT problem */
  2699.     *pfha = (short) 0;                  /* No user protection fault handler */
  2700. #endif /* datageneral */
  2701.  
  2702. /* Do some initialization */
  2703.  
  2704. #ifndef MAC
  2705.     xargc = xargs = argc;               /* Make global copies of argc */
  2706.     xargv = argv;                       /* ...and argv. */
  2707.     xarg0 = argv[0];
  2708. #ifdef NT
  2709.     setOSVer();
  2710. #endif /* NT */
  2711.     zstrip(argv[0],&p);                 /* Get name we were invoked with */
  2712.     makestr(&myname,p);
  2713.     if (!ckstrcmp(myname,"telnet",6,0)) howcalled = I_AM_TELNET;
  2714.     if (!ckstrcmp(myname,"rlogin",6,0)) howcalled = I_AM_RLOGIN;
  2715.     if (!ckstrcmp(myname,"iksd",4,0))   howcalled = I_AM_IKSD;
  2716.     debug(F111,"howcalled",myname,howcalled);
  2717.  
  2718.     shortbytes.x_short = 0xABCD;        /* Get Endianness */
  2719.     if (shortbytes.x_char[0] == 0xCD) { /* 0 = Big Endian */
  2720.         byteorder = 1;                  /* 1 = Little Endian */
  2721.         bigendian = 0;                  /* (for clarity in programming) */
  2722.     }
  2723.  
  2724. #ifndef NOICP
  2725.     cmdini();                           /* Must come before prescan */
  2726.     debug(F100,"main cmdini() done","",0);
  2727. #endif /* NOICP */
  2728.     prescan(0);                         /* Pre-Check for debugging, etc */
  2729. #endif /* MAC */
  2730.     debug(F101,"MAIN feol","",feol);
  2731.     makever();                          /* Put together version strings */
  2732. #ifndef NOSETKEY                        /* Allocate & initialize the keymap */
  2733.     /* This code has been moved to before sysinit() for K95G */
  2734.     if (!(keymap = (KEY *) malloc(sizeof(KEY)*KMSIZE)))
  2735.       fatal("main: no memory for keymap");
  2736.     if (!(macrotab = (MACRO *) malloc(sizeof(MACRO)*KMSIZE)))
  2737.       fatal("main: no memory for macrotab");
  2738.     for (i = 0; i < KMSIZE; i++) {
  2739.        keymap[i] = (KEY) i;
  2740.        macrotab[i] = NULL;
  2741.     }
  2742. #endif /* NOSETKEY */
  2743.  
  2744.     if (sysinit() < 0)                  /* System-dependent initialization. */
  2745.       fatal("Can't initialize!");
  2746.     else
  2747.       initflg = 1;                      /* Remember we did. */
  2748.     debug(F111,"ckcmai myname",myname,howcalled);
  2749.  
  2750. #ifdef CKSYSLOG
  2751. #ifdef SYSLOGLEVEL
  2752. /*
  2753.   If built with -DSYSLOGLEVEL on cc command line, this means we always
  2754.   do syslogging at the indicated level.
  2755. */
  2756.     zsyslog();                          /* Open syslog */
  2757. #else /* SYSLOGLEVEL */
  2758. #ifdef IKSD
  2759.     if (inserver)
  2760.       zsyslog();                        /* Open syslog */
  2761. #endif /* IKSD */
  2762. #endif /* SYSLOGLEVEL */
  2763. #endif /* CKSYSLOG */
  2764.  
  2765. #ifdef TNCODE
  2766.     tn_set_modes();                     /* Init Telnet Option tables */
  2767. #endif /* TNCODE */
  2768.  
  2769. #ifdef CK_AUTHENTICATION
  2770. #ifdef CK_KERBEROS
  2771.     ini_kerb();                         /* Initialize Kerberos data */
  2772. #endif /* CK_KERBEROS */
  2773. #endif /* CK_AUTHENTICATION */
  2774.  
  2775. #ifdef CK_TTGWSIZ                       /* Initialize screen dimensions */
  2776. #ifdef OS2
  2777.     ttgcwsz();
  2778. #else /* OS2 */
  2779.     if (ttgwsiz() > 0) {
  2780.         if (tt_rows > 0 && tt_cols > 0) {
  2781.             cmd_rows = tt_rows;
  2782.             cmd_cols = tt_cols;
  2783.         }
  2784.     }
  2785. #endif /* OS2 */
  2786. #endif /* CK_TTGWSIZ */
  2787.  
  2788. #ifdef TCPSOCKET
  2789. #ifdef CK_SOCKS
  2790.     SOCKSinit(argv[0]);                 /* Internet relay package... */
  2791. #endif /* CK_SOCKS */
  2792. #endif /* TCPSOCKET */
  2793.  
  2794.     initflow();                         /* Initialize flow-control table */
  2795. #ifdef FNFLOAT
  2796.     initfloat();                        /* Deduce floating-point precision */
  2797. #endif /* FNFLOAT */
  2798.  
  2799. #ifndef NOXFER
  2800. #ifdef CK_XYZ                           /* Initialize protocols...  */
  2801.  
  2802. #ifdef XYZ_INTERNAL /* XYZMODEM are internal ... */
  2803.  
  2804. #ifdef COMMENT
  2805. /* Can't do this for XMODEM because if filename contains a "C" etc... */
  2806.     initproto(PROTO_X, "rx %s","rx %s", NULL, NULL, NULL, NULL, NULL);
  2807.     initproto(PROTO_XC,"rc %s","rc %s", NULL, NULL, NULL, NULL, NULL);
  2808. #else /* COMMENT */
  2809.     initproto(PROTO_X, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
  2810.     initproto(PROTO_XC,NULL, NULL, NULL, NULL, NULL, NULL, NULL);
  2811. #endif /* COMMENT */
  2812.     initproto(PROTO_Y, "rb","rb", NULL, NULL, NULL, NULL, NULL);
  2813.     initproto(PROTO_G, "rb","rb", NULL, NULL, NULL, NULL, NULL);
  2814.     initproto(PROTO_Z, "rz","rz", NULL, NULL, NULL, NULL, NULL);
  2815.    initproto(PROTO_K,"kermit -ir","kermit -r","kermit -x",NULL,NULL,NULL,NULL);
  2816.     /* Kermit Must be last */
  2817.  
  2818. #else /* XYZMODEM are external protocols ... */
  2819.  
  2820. /*                  s1      s2     s3    s4      s5         s6      s7     */
  2821. initproto(PROTO_X, "rx %s","rx %s",NULL,"sx %s","sx -a %s","rx %s", "rx %s");
  2822. initproto(PROTO_XC,"rc %s","rc %s",NULL,"sx %s","sx -a %s","rc %s", "rc %s");
  2823. initproto(PROTO_Y, "rb",   "rb",   NULL,"sb %s","sb -a %s","rb",    "rb"   );
  2824. initproto(PROTO_G, "rb",   "rb",   NULL,"sb %s","sb -a %s","rb",    "rb"   );
  2825. initproto(PROTO_Z, "rz",   "rz",   NULL,"sz %s","sz -a %s","rz",    "rz"   );
  2826. initproto(PROTO_K, "kermit -ir","kermit -r","kermit -x",NULL,NULL,NULL,NULL);
  2827. /* Kermit must be last */
  2828.  
  2829. #endif /* XYZ_INTERNAL */
  2830.  
  2831. #else  /* No XYZMODEM support */
  2832.  
  2833.    initproto(PROTO_K,"kermit -ir","kermit -r","kermit -x",NULL,NULL,NULL,NULL);
  2834.  
  2835. #endif /* CK_XYZ */
  2836. #endif /* NOXFER */
  2837.  
  2838. #ifndef NOXFER
  2839. #ifdef OS2
  2840.     /* Initialize Kermit and Zmodem Auto-Download Strings */
  2841.     adl_kstr = strdup("KERMIT READY TO SEND...");
  2842.     adl_zstr = strdup("rz\r");
  2843. #endif /* OS2 */
  2844.  
  2845. #ifdef PATTERNS
  2846.     initpat();                          /* Initialize filename patterns */
  2847. #endif /* PATTERNS */
  2848. #endif /* NOXFER */
  2849.  
  2850. #ifndef NOCSETS
  2851.     initcsets();                        /* Initialize character sets */
  2852. #endif /* NOCSETS */
  2853.  
  2854. #ifndef NOICP
  2855. #ifdef DFCDMSG
  2856.     makestr(&cdmsgstr,DFCDMSG);
  2857.     makelist(cdmsgstr,cdmsgfile,8);     /* Initialize CD message filenames */
  2858. #endif /* DFCDMSG */
  2859. #endif /* NOICP */
  2860.  
  2861.     connoi();                           /* Console interrupts off */
  2862.     sstate = 0;                         /* No default start state. */
  2863. #ifdef DYNAMIC
  2864.     if (getiobs() < 0)
  2865.       fatal("Can't allocate i/o buffers!");
  2866. #endif /* DYNAMIC */
  2867.  
  2868. #ifndef NOSPL
  2869. #ifndef NORANDOM
  2870.     srand((unsigned int)gtimer());
  2871. #endif /* NORANDOM */
  2872. #endif /* NOSPL */
  2873.  
  2874.     ckhost(myhost,MYHOSTL);             /* Name of local host */
  2875.     debug(F110,"main ckhost",myhost,0);
  2876. #ifdef IKSD
  2877.     if (!inserver) {
  2878. #endif /* IKSD */
  2879.         strcpy(ttname,dftty);           /* Set up default tty name. */
  2880.         local = nolocal ? 0 : dfloc;    /* And whether it's local or remote. */
  2881.         parity = dfprty;                /* Set initial parity, */
  2882. #ifndef NOXFER
  2883.         myindex = getsysix(cksysid);    /* System index */
  2884. #endif /* NOXFER */
  2885.         if (local) if (ttopen(ttname,&local,0,0) < 0) {
  2886. #ifndef OS2
  2887.             conol("Can't open device: ");
  2888.             conoll(ttname);
  2889. #endif /* OS2 */
  2890.             local = 0;
  2891.             strcpy(ttname,CTTNAM);
  2892.         }
  2893.         setflow();                      /* Set appropriate flow control */
  2894.         speed = ttgspd();               /* Get transmission speed. */
  2895. #ifdef IKSD
  2896.     }
  2897. #endif /* IKSD */
  2898.  
  2899. #ifdef ANYX25                           /* All X.25 implementations */
  2900. #ifndef IBMX25                          /* except IBM have PAD support */
  2901.     initpad();                          /* Initialize X.25 PAD */
  2902. #endif /* IBMX25 */
  2903. #endif /* ANYX25 */
  2904.  
  2905. #ifndef NOXFER
  2906.     if (inibufs(SBSIZ,RBSIZ) < 0)       /* Allocate packet buffers */
  2907.       fatal("Can't allocate packet buffers!");
  2908. #ifndef NOCKSPEED
  2909.     setprefix(prefixing);               /* Set up control char prefixing */
  2910. #endif /* NOCKSPEED */
  2911. #endif /* NOXFER */
  2912.  
  2913. #ifndef NOICP
  2914.     if (sstelnet
  2915. #ifdef IKSD
  2916.         || inserver
  2917. #endif /* IKSD */
  2918.         ) {
  2919.         int on = 1, x = 0;
  2920.         extern int ckxech, ttnet, ttnproto, cmdmsk;
  2921. #ifdef SO_SNDBUF
  2922.         extern int tcp_sendbuf;
  2923. #endif
  2924. #ifdef SO_RCVBUF
  2925.         extern int tcp_recvbuf;
  2926. #endif
  2927. #ifdef SO_KEEPALIVE
  2928.         extern int tcp_keepalive;
  2929. #endif
  2930. #ifdef SO_LINGER
  2931.         extern int tcp_linger, tcp_linger_tmo;
  2932. #endif /* SO_LINGER */
  2933. #ifdef SO_DONTROUTE
  2934.         extern int tcp_dontroute;
  2935. #endif /* SO_DONTROUTE */
  2936. #ifdef TCP_NODELAY
  2937.         extern int tcp_nodelay;
  2938. #endif /* TCP_NODELAY */
  2939.  
  2940.         reliable = xreliable = SET_ON;  /* Reliable connection */
  2941. #ifndef VMS
  2942.         flow = 0;                       /* No flow control needed */
  2943. #endif /* VMS */
  2944.         bgset = 0;                      /* Not in background */
  2945.         nopush = 1;                     /* No external processes */
  2946.         parity = 0;                     /* 8 bits ... */
  2947.         cmdmsk = 0xff;                  /* all the way */
  2948.         cmask = 0xff;
  2949.  
  2950. #ifdef IKSD
  2951.         if (inserver) {                 /* If IKSD */
  2952. #ifdef COMMENT
  2953. /*
  2954.   We can't do it here because ttopen() hasn't been called yet so we
  2955.   can't get our client's IP address.  In theory the execution of the
  2956.   IKSD configuration file shouldn't take more than a sec...
  2957. */
  2958. #ifdef IKSDB
  2959.             dbinit();                   /* Initialize database record */
  2960. #endif /* IKSDB */
  2961. #endif /* COMMENT */
  2962.             doiksdinit();               /* Execute IKSD configuration file */
  2963.             while (tlevel > -1)
  2964.               parser(1);                /* (Ignore any file-xfer commands) */
  2965.             iksdcf = 1;                 /* IKSD c.f. has been processed */
  2966.         }
  2967. #endif /* IKSD */
  2968.  
  2969. #ifdef UNIX
  2970.         setbuf(stdout,NULL);            /* Don't buffer the output */
  2971.         strcpy(ttname,"0");             /* not "/dev/tty"... */
  2972. #endif /* UNIX */
  2973.         local = 0;                      /* We are in remote mode */
  2974.         ckxech = 1;                     /* We will echo */
  2975. #ifdef OS2
  2976.         nettype = NET_TCPB;             /* So ttopen() treats the connection */
  2977.         mdmtyp = -nettype;              /* as a network */
  2978. #endif /* OS2 */
  2979.         debug(F100,"main about to call ttopen() inserver","",0);
  2980.         if (ttopen(ttname,&local,mdmtyp,0) < 0) { /* Open comm channel */
  2981.             fatal("can't initialize i/o");
  2982.         }
  2983. #ifdef OS2
  2984.         local = 0;
  2985. #endif /* OS2 */
  2986.         network = 0;                    /* Does not use networking code */
  2987.         sstelnet = 1;                   /* Do server-side Telnet negotations */
  2988.         debug(F111,"MAIN","sstelnet",sstelnet);
  2989.         ttnet = NET_TCPB;               /* Network type is TCP sockets */
  2990.         ttnproto = NP_TELNET;           /* Netword protocol is Telnet */
  2991. #ifdef IKSDB
  2992.         dbinit();                       /* Initialize database record */
  2993. #endif /* IKSDB */
  2994. #ifndef OS2
  2995. #ifdef CK_AUTHENTICATION
  2996.         /* Before initializating Telnet/Rlogin negotiations, init Kerberos */
  2997.         ck_auth_init(ckgetpeer(),"","",0);
  2998. #endif /* CK_AUTHENTICATION */
  2999.  
  3000. #ifdef NON_BLOCK_IO
  3001.         on = 1;
  3002.         x = socket_ioctl(0,FIONBIO,&on);
  3003.         debug(F101,"main FIONBIO","",x);
  3004. #endif /* NON_BLOCK_IO */
  3005. #ifdef SO_OOBINLINE
  3006.         on = 1;
  3007.         x = setsockopt(0, SOL_SOCKET, SO_OOBINLINE, (char *)&on, sizeof(on));
  3008.         debug(F101,"main SO_OOBINLINE","",x);
  3009. #endif /* SO_OOBINLINE */
  3010.  
  3011. #ifndef NOTCPOPTS
  3012. #ifndef datageneral
  3013. #ifdef SOL_SOCKET
  3014. #ifdef TCP_NODELAY
  3015.         no_delay(tcp_nodelay);
  3016. #endif /* TCP_NODELAY */
  3017. #ifdef SO_KEEPALIVE
  3018.         keepalive(tcp_keepalive);
  3019. #endif /* SO_KEEPALIVE */
  3020. #ifdef SO_LINGER
  3021.         ck_linger(tcp_linger, tcp_linger_tmo);
  3022. #endif /* SO_LINGER */
  3023. #ifdef SO_DONTROUTE
  3024.         dontroute(tcp_dontroute);
  3025. #endif /* SO_DONTROUTE */
  3026. #ifdef SO_SNDBUF
  3027.         sendbuf(tcp_sendbuf);
  3028. #endif /* SO_SNDBUF */
  3029. #ifdef SO_RCVBUF
  3030.         recvbuf(tcp_recvbuf);
  3031. #endif /* SO_RCVBUF */
  3032. #endif /* SOL_SOCKET */
  3033. #endif /* datageneral */
  3034. #endif /* NOTCPOPTS */
  3035.  
  3036. #ifdef CK_SSL
  3037.         if (ck_ssleay_is_installed()) {
  3038.             if (!ssl_do_init(1)) {
  3039.                 if (bio_err != NULL) {
  3040.                     BIO_printf(bio_err,"do_ssleay_init() failed\r\n");
  3041.                     ERR_print_errors(bio_err);
  3042.                 } else {
  3043.                     fflush(stderr);
  3044.                     fprintf(stderr,"do_ssleay_init() failed\r\n");
  3045.                     ERR_print_errors_fp(stderr);
  3046.                 }
  3047.                 /* we will continue to accept the connection */
  3048.                 /* without SSL or TLS support.               */
  3049.                 TELOPT_DEF_S_ME_MODE(TELOPT_START_TLS) = TN_NG_RF;
  3050.                 TELOPT_DEF_S_U_MODE(TELOPT_START_TLS) = TN_NG_RF;
  3051.                 TELOPT_DEF_C_ME_MODE(TELOPT_START_TLS) = TN_NG_RF;
  3052.                 TELOPT_DEF_C_U_MODE(TELOPT_START_TLS) = TN_NG_RF;
  3053.  
  3054.             } else {
  3055.                 if ( ck_ssl_incoming(0) < 0 ) {
  3056.                     doexit(BAD_EXIT,1);
  3057.                 }
  3058.             }
  3059.         }
  3060. #endif /* CK_SSL */
  3061.  
  3062. #ifdef TNCODE
  3063.         tn_ini();                       /* Start Telnet negotiation now */
  3064. #endif /* TNCODE */
  3065. #endif /* OS2 */
  3066.     }
  3067.     debug(F101,"main argc after prescan()","",argc);
  3068.  
  3069. /* Now process any relevant environment variables */
  3070.  
  3071. #ifndef NODIAL
  3072.     getdialenv();                       /* Dialing */
  3073. #ifdef NETCONN
  3074.     ndinit();                           /* Initialize network directory info */
  3075.     getnetenv();                        /* Network directories */
  3076. #endif /* NETCONN */
  3077. #endif /* NODIAL */
  3078.  
  3079. #ifndef NOXFER
  3080. #ifdef CK_FAST
  3081.     dofast();                           /* By now FAST defaults should be OK */
  3082. #endif /* CK_FAST */
  3083. #endif /* NOXFER */
  3084.  
  3085.     ikslogin();                          /* IKSD Login and other stuff */
  3086.  
  3087. #ifdef NOCCTRAP
  3088.     dotakeini(0);
  3089. #else /* NOCCTRAP */
  3090.     debug(F100,"main about to cc_execute","",0);
  3091.     setint();
  3092.     cc_execute( ckjaddr(cmjbuf), dotakeini, failtakeini );
  3093. #endif /* NOCCTRAP */
  3094.  
  3095.     debug(F111,"main 2 cfilef",cmdfil,cfilef);
  3096.     if (cmdfil[0]) {                    /* If we got one (see prescan())... */
  3097. #ifdef NOCCTRAP
  3098.         docmdfile(0);                   /* execute it. */
  3099. #else /* NOCCTRAP */
  3100.         setint();
  3101.         cc_execute( ckjaddr(cmjbuf), docmdfile, failcmdfile );
  3102. #endif /* NOCCTRAP */
  3103.     }
  3104. #ifndef OS2                             /* Preserve name so we can delete it */
  3105.     *cmdfil = '\0';                     /* Done, nullify the file name */
  3106. #endif /* OS2 */
  3107. #endif /* NOICP */
  3108.  
  3109. #ifndef NOCMDL
  3110. /* Look for a UNIX-style command line... */
  3111.  
  3112.     what = W_NOTHING;
  3113.  
  3114.     debug(F101,"main argc","",argc);
  3115. #ifndef NOHELP
  3116. #ifndef NOICP
  3117.     iniopthlp();                        /* Initialize cmdline arg help */
  3118. #endif /* NOICP */
  3119. #endif /* NOHELP */
  3120.     if (
  3121. #ifdef COMMENT
  3122.         !cfilef &&
  3123. #endif /* COMMENT */
  3124.         argc > 1) {                     /* Command line arguments? */
  3125.         sstate = (CHAR) cmdlin();       /* Yes, parse. */
  3126. #ifndef NOXFER
  3127.         zstate = sstate;                /* Remember sstate around protocol */
  3128.         debug(F101,"main zstate","",zstate);
  3129. #endif /* NOXFER */
  3130.  
  3131. #ifndef NOLOCAL
  3132.         if (cflg) {                     /* Connect first if requested */
  3133.             doconect(0);
  3134. #ifdef CKLOGDIAL
  3135.             if (ttchk() < 0)
  3136.               dologend();
  3137. #endif /* CKLOGDIAL */
  3138.             cflg = 0;
  3139.         }
  3140. #endif /* NOLOCAL */
  3141.  
  3142. #ifndef NOXFER
  3143.         if (sstate) {
  3144. #ifndef NOLOCAL
  3145.             if (displa) concb((char)escape); /* (for console "interrupts") */
  3146. #endif /* NOLOCAL */
  3147. #ifdef NOCCTRAP
  3148.             docmdline(1);
  3149. #else /* NOCCTRAP */
  3150.             setint();
  3151.             cc_execute( ckjaddr(cmjbuf), docmdline, failcmdline );
  3152. #endif /* NOCCTRAP */
  3153.         }
  3154. #endif /* NOXFER */
  3155.  
  3156. #ifndef NOICP
  3157. /*
  3158.   If a command-line action argument was given and -S ("stay") was not given,
  3159.   exit now.
  3160. */
  3161.         if ((cflg || cnflg || zstate) && !stayflg)
  3162. #endif /* NOICP */
  3163.           doexit(GOOD_EXIT,xitsta);     /* Exit with good status */
  3164.  
  3165. #ifndef NOLOCAL
  3166. #ifndef NOICP
  3167.         if (local) {
  3168. #ifdef NETCONN
  3169.             if ((cflg || cnflg) && tn_exit && ttchk() < 0)
  3170.               doexit(GOOD_EXIT,xitsta); /* Exit with good status */
  3171. #endif /* NETCONN */
  3172.             if (exitonclose && !network &&
  3173.                 (carrier != CAR_OFF && (ttgmdm() & BM_DCD) == 0))
  3174.               doexit(GOOD_EXIT,xitsta); /* Exit with good status */
  3175.             if (exitonclose && network && ttchk() < 0)
  3176.               doexit(GOOD_EXIT,xitsta); /* Exit with good status */
  3177.         }
  3178. #endif /* NOICP */
  3179. #endif /* NOLOCAL */
  3180.     }
  3181. #endif /* NOCMDL */
  3182.  
  3183. #ifdef NOICP                            /* No interactive command parser */
  3184.     else {
  3185. #ifndef NOCMDL
  3186.         /* Command-line-only version */
  3187.         fatal("?No command-line options given - type 'kermit -h' for help");
  3188. #else                                   /* Neither one! */
  3189.         sstate = 'x';
  3190.         justone = 0;
  3191.         proto();                        /* So go into server mode */
  3192.         doexit(GOOD_EXIT,xitsta);       /* exit with good status */
  3193. #endif /* NOCMDL */
  3194.     }
  3195. #else /* not NOICP */
  3196. /*
  3197.   If no action requested on command line, or if -S ("stay") was included,
  3198.   enter the interactive command parser.
  3199. */
  3200.     if (!clcmds)
  3201.       herald();                         /* Display program herald. */
  3202.  
  3203. #ifdef NOCCTRAP
  3204.     debug(F100,"main NOCCTRAP setting interrupt trap","",0);
  3205.     setint();                           /* Set up command interrupt traps */
  3206.     doicp(NULL);
  3207. #else /* NOCCTRAP */
  3208.     while (1) {
  3209.         debug(F100,"main setting interrupt trap","",0);
  3210.         setint();                       /* Set up command interrupt traps */
  3211.         if (!cc_execute(ckjaddr(cmjbuf), doicp, failicp))
  3212.           break;
  3213.     }
  3214. #endif /* NOCCTRAP */
  3215. #endif /* NOICP */
  3216. #ifndef MAINISVOID
  3217.     return(1);
  3218. #endif /* MAINISVOID */
  3219. }
  3220.  
  3221. #ifdef DYNAMIC
  3222. /* Allocate file i/o buffers */
  3223.  
  3224. char *zinbuffer, *zoutbuffer;
  3225.  
  3226. int
  3227. getiobs() {
  3228.     zinbuffer = (char *)malloc(INBUFSIZE);
  3229.     if (!zinbuffer) return(-1);
  3230.     zoutbuffer = (char *)malloc(zobufsize);
  3231.     debug(F101,"zoutbuffer malloc","",zobufsize);
  3232.     if (!zoutbuffer) return(-1);
  3233.     debug(F100,"getiobs ok","",0);
  3234.     return(0);
  3235. }
  3236. #endif /* DYNAMIC */
  3237.