home *** CD-ROM | disk | FTP | other *** search
/ kermit.columbia.edu / kermit.columbia.edu.tar / kermit.columbia.edu / test / tar / x28.tar.Z / x28.tar / ckcmai.c < prev    next >
C/C++ Source or Header  |  2010-03-30  |  128KB  |  3,639 lines

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