home *** CD-ROM | disk | FTP | other *** search
/ kermit.columbia.edu / kermit.columbia.edu.tar / kermit.columbia.edu / tmp4 / ckcmai.c < prev    next >
C/C++ Source or Header  |  2009-11-27  |  131KB  |  3,638 lines

  1. #define EDITDATE  "27 Nov 2009"        /* Last edit date dd mmm yyyy */
  2. #define EDITNDATE "20091127"        /* Keep them in sync */
  3. /* Fri Nov 27 12:54:23 2009 */
  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 = "02";            /* 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 = "";
  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, 2009, 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, 2009, Trustees of Columbia University, NYC.",
  182. "All rights reserved.",
  183. " ",
  184. #else
  185. #ifdef OS2
  186. "Copyright (C) 1985, 2009, 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, 2009,",
  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.     pktlog = 0,                         /* Flag for packet logging */
  1367.     seslog = 0,                         /* Session logging */
  1368.     dialog = 0,                         /* DIAL logging */
  1369.     tralog = 0,                         /* Transaction logging */
  1370.     tlogfmt = 1,                        /* Transaction log format (verbose) */
  1371.     tlogsep = (int)',',                 /* Transaction log field separator */
  1372.     displa = 0,                         /* File transfer display on/off */
  1373.     stdouf = 0,                         /* Flag for output to stdout */
  1374.     stdinf = 0,                         /* Flag for input from stdin */
  1375.     xflg   = 0,                         /* Flag for X instead of F packet */
  1376.     hcflg  = 0,                         /* Doing Host command */
  1377.     dest   = DEST_D,                    /* Destination for packet data */
  1378.     zchkod = 0,                         /* zchko() should work for dirs too? */
  1379.     zchkid = 0,                         /* zchki() should work for dirs too? */
  1380.  
  1381. /* If you change this, also see struct ptab above... */
  1382.  
  1383. #ifdef OS2                              /* Flag for file name conversion */
  1384.     fncnv  = XYFN_L,                    /* Default is Literal in OS/2, */
  1385.     f_save = XYFN_L,                    /* (saved copy of same) */
  1386. #else
  1387.     fncnv  = XYFN_C,                    /* elsewhere Convert them */
  1388.     f_save = XYFN_C,                    /* (ditto) */
  1389. #endif /* OS2 */
  1390.  
  1391.     fnspath = PATH_OFF,                 /* Send file path */
  1392.     fnrpath = PATH_AUTO,                /* Receive file path */
  1393.     fackpath = 1,                       /* Send back path in ACK to F */
  1394.     binary = XYFT_B,                    /* Default file transfer mode */
  1395.     b_save = XYFT_B,                    /* Saved file mode */
  1396.     eofmethod = 0,                      /* EOF detection method (length) */
  1397.  
  1398. #ifdef OS2
  1399.     cursor_save = -1,                   /* Cursor state */
  1400. #endif /* OS2 */
  1401.  
  1402.     xfermode = XMODE_A,                 /* Transfer mode, manual or auto */
  1403.     xfiletype = -1,                     /* Transfer only text (or binary) */
  1404.     recursive = 0,                      /* Recursive directory traversal */
  1405.     nolinks   = 2,                      /* Don't follow symbolic links */
  1406.     skipbup   = 0,                      /* Skip backup files when sending */
  1407.     sendmode = SM_SEND,                 /* Which type of SEND operation */
  1408.     slostart  = 1,                      /* Slow start (grow packet lengths) */
  1409.     cmask  = 0377,                      /* CONNECT (terminal) byte mask */
  1410.     fmask  = 0377,                      /* File byte mask */
  1411.     ckwarn = 0,                         /* Flag for file warning */
  1412.     quiet  = 0,                         /* Be quiet during file transfer */
  1413.     local  = 0,                         /* 1 = local mode, 0 = remote mode */
  1414.     cxtype = CXT_REMOTE,                /* Connection type */
  1415.     server = 0,                         /* Flag for I Am Server */
  1416.     query = 0,                          /* Flag for Query active */
  1417.     justone = 0,                        /* Server should do Just One command */
  1418.     urserver = 0,                       /* Flag for You Are Server */
  1419.     bye_active = 0,                     /* Flag for BYE command active */
  1420.     diractive = 0,                      /* Flag for DIRECTORY command active */
  1421.     cdactive = 0,                       /* Flag for CD command active */
  1422.     cflg   = 0,                         /* Connect before transaction */
  1423.     cnflg  = 0,                         /* Connect after transaction */
  1424.     cxseen = 0,                         /* Flag for cancelling a file */
  1425.     czseen = 0,                         /* Flag for cancelling file group */
  1426.     fatalio = 0,                        /* Flag for fatal i/o error */
  1427.     discard = 0,                        /* Flag for file to be discarded */
  1428.     keep = SET_AUTO,                    /* Keep incomplete files = AUTO */
  1429.     unkcs = 1,                          /* Keep file w/unknown character set */
  1430. #ifdef VMS
  1431.     filepeek = 0,                       /* Inspection of files */
  1432. #else
  1433. #ifdef datgeneral
  1434.     filepeek = 0,
  1435. #else
  1436.     filepeek = 1,
  1437. #endif /* datageneral */
  1438. #endif /* VMS */
  1439.     nakstate = 0,                       /* In a state where we can send NAKs */
  1440.     dblchar = -1,                       /* Character to double when sending */
  1441.     moving = 0,                         /* MOVE = send, then delete */
  1442.     reliable = SET_AUTO,                /* Nonzero if transport is reliable */
  1443.     xreliable = -1,
  1444.     setreliable = 0,
  1445.     urclear = 0,                        /* Nonzero for clear channel to you */
  1446.     clearrq = SET_AUTO,                 /* SET CLEARCHANEL value */
  1447.     cleared = 0,
  1448.     streaming = 0,                      /* Nonzero if streaming is active */
  1449.     streamok = 0,                       /* Nonzero if streaming negotiated */
  1450.     streamrq = SET_AUTO,                /* SET STREAMING value */
  1451.     streamed = -1;                      /* Whether we streamed last time */
  1452.  
  1453. char * snd_move = NULL;                 /* Move file after sending it */
  1454. char * snd_rename = NULL;               /* Rename file after sending it */
  1455. char * rcv_move = NULL;                 /* Move file after receiving it */
  1456. char * rcv_rename = NULL;               /* Rename file after receiving it */
  1457.  
  1458. char * g_snd_move = NULL;
  1459. char * g_snd_rename = NULL;
  1460. char * g_rcv_move = NULL;
  1461. char * g_rcv_rename = NULL;
  1462.  
  1463. #ifdef CK_TRIGGER
  1464. char *tt_trigger[TRIGGERS] = { NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL };
  1465. CHAR *tt_trmatch[TRIGGERS] = { NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL };
  1466. char *triggerval = NULL;
  1467. #endif /* CK_TRIGGER */
  1468.  
  1469. int ckxlogging = 0;                     /* Flag for syslogging active */
  1470. int ikdbopen = 0;                       /* Flag for IKSD database active */
  1471. int dbinited = 0;                       /* Flag for IKSDB record init'd */
  1472. #ifndef CKSYSLOG
  1473. int ckxsyslog = 0;                      /* Logging level 0 */
  1474. #else
  1475. #ifdef SYSLOGLEVEL
  1476. int ckxsyslog = SYSLOGLEVEL;            /* Logging level specified */
  1477. #else
  1478. int ckxsyslog = SYSLG_DF;               /* Default logging level */
  1479. #endif /* SYSLOGLEVEL */
  1480. #endif /* CKSYSLOG */
  1481.  
  1482. #ifndef NOHELP
  1483. #ifndef NOCMDL
  1484. _PROTOTYP( VOID iniopthlp, (void) );    /* Command-line help initializer */
  1485. #endif /* NOCMDL */
  1486. #endif /* NOHELP */
  1487.  
  1488. _PROTOTYP( VOID getexedir, (void) );
  1489. _PROTOTYP( int putnothing, (char) );
  1490.  
  1491. #ifdef IKSD
  1492. _PROTOTYP( VOID doiksdinit, (void) );
  1493. _PROTOTYP( VOID iksdinit, (void) );
  1494. _PROTOTYP( VOID doiklog, (void) );
  1495. _PROTOTYP( int dbinit, (void) );
  1496. #endif /* IKSD */
  1497.  
  1498. /* Variables passed from command parser to protocol module */
  1499.  
  1500. #ifndef NOSPL
  1501. #ifndef NOICP
  1502. #ifdef CK_APC
  1503. _PROTOTYP( VOID apconect, (void) );
  1504. #endif /* CK_APC */
  1505. #ifdef OS2
  1506. extern int initvik;
  1507. #endif /* OS2 */
  1508. #endif /* NOICP */
  1509. #endif /* NOSPL */
  1510. char *clcmds = NULL;                    /* Pointer to command-line commands */
  1511.  
  1512. #ifndef NOSETKEY
  1513. extern KEY *keymap;
  1514. extern MACRO *macrotab;
  1515. #endif /* NOSETKEY */
  1516.  
  1517. #ifndef NOPUSH
  1518. int nopush = 0;                         /* PUSH enabled */
  1519. #else
  1520. int nopush = 1;                         /* PUSH disabled */
  1521. #endif /* NOPUSH */
  1522.  
  1523. CHAR sstate  = (CHAR) 0;                /* Starting state for automaton */
  1524. CHAR zstate  = (CHAR) 0;                /* For remembering sstate */
  1525. char * printername = NULL;              /* NULL if printer not redirected */
  1526. int printpipe = 0;                      /* For SET PRINTER */
  1527. int noprinter = 0;
  1528.  
  1529. #ifndef NOXFER
  1530. char *cmarg  = "";                      /* Pointer to command data */
  1531. char *cmarg2 = "";                      /* Pointer to 2nd command data */
  1532. char **cmlist;                          /* Pointer to file list in argv */
  1533.  
  1534. #ifdef CK_AUTODL                        /* Autodownload */
  1535. int autodl = 1;                         /* Enabled by default */
  1536. #else
  1537. int autodl = 0;                         /* (or if not implemented). */
  1538. #endif /* CK_AUTODL */
  1539. int adl_err = 1;                        /* 1 = stop on error */
  1540. #ifdef KUI
  1541. int adl_ask = 1;            /* 1 = file dialog on autodownload */
  1542. #else
  1543. int adl_ask = 0;            /* 0 = no file dialog */
  1544. #endif /* KUI */
  1545. #ifdef OS2                              /* AUTODOWNLOAD parameters */
  1546. int adl_kmode = ADL_PACK,               /* Match Packet to signal download */
  1547.     adl_zmode = ADL_PACK;
  1548. char * adl_kstr = NULL;                 /* KERMIT Download String */
  1549. char * adl_zstr = NULL;                 /* ZMODEM Download String */
  1550. #endif /* OS2 */
  1551.  
  1552. int remfile = 0, rempipe = 0, remappd = 0; /* REMOTE output redirection */
  1553. char * remdest = NULL;
  1554.  
  1555. #ifndef NOSERVER
  1556. /*
  1557.   Server services:
  1558.    0 = disabled
  1559.    1 = enabled in local mode
  1560.    2 = enabled in remote mode
  1561.    3 = enabled in both local and remote modes
  1562.   only as initial (default) values.
  1563. */
  1564. int en_xit = 2;                         /* EXIT */
  1565. int en_cwd = 3;                         /* CD/CWD */
  1566. int en_cpy = 3;                         /* COPY   */
  1567. int en_del = 2;                         /* DELETE */
  1568. int en_mkd = 3;                         /* MKDIR */
  1569. int en_rmd = 2;                         /* RMDIR */
  1570. int en_dir = 3;                         /* DIRECTORY */
  1571. int en_fin = 3;                         /* FINISH */
  1572. int en_get = 3;                         /* GET */
  1573. #ifndef NOPUSH
  1574. int en_hos = 2;                         /* HOST enabled */
  1575. #else
  1576. int en_hos = 0;                         /* HOST disabled */
  1577. #endif /* NOPUSH */
  1578. int en_ren = 3;                         /* RENAME */
  1579. int en_sen = 3;                         /* SEND */
  1580. int en_set = 3;                         /* SET */
  1581. int en_spa = 3;                         /* SPACE */
  1582. int en_typ = 3;                         /* TYPE */
  1583. int en_who = 3;                         /* WHO */
  1584. #ifdef datageneral
  1585. /* Data General AOS/VS can't do this */
  1586. int en_bye = 0;                         /* BYE */
  1587. #else
  1588. int en_bye = 2;                         /* PCs in local mode... */
  1589. #endif /* datageneral */
  1590. int en_asg = 3;                         /* ASSIGN */
  1591. int en_que = 3;                         /* QUERY */
  1592. int en_ret = 2;                         /* RETRIEVE */
  1593. int en_mai = 3;                         /* MAIL */
  1594. int en_pri = 3;                         /* PRINT */
  1595. int en_ena = 3;                         /* ENABLE */
  1596. #else
  1597. int en_xit = 0, en_cwd = 0, en_cpy = 0, en_del = 0, en_mkd = 0, en_rmd = 0,
  1598.     en_dir = 0, en_fin = 0, en_get = 0, en_hos = 0, en_ren = 0, en_sen = 0,
  1599.     en_set = 0, en_spa = 0, en_typ = 0, en_who = 0, en_bye = 0, en_asg = 0,
  1600.     en_que = 0, en_ret = 0, en_mai = 0, en_pri = 0, en_ena = 0;
  1601. #endif /* NOSERVER */
  1602. #endif /* NOXFER */
  1603.  
  1604. /* Miscellaneous */
  1605.  
  1606. char **xargv;                           /* Global copies of argv */
  1607. int xargc;                              /* and argc  */
  1608. int xargs;                              /* an immutable copy of argc */
  1609. char *xarg0;                            /* and of argv[0] */
  1610. char *pipedata;                         /* Pointer to -P (pipe) data */
  1611.  
  1612. extern char *dftty;                     /* Default tty name from ck?tio.c */
  1613. extern int dfloc;                       /* Default location: remote/local */
  1614. extern int dfprty;                      /* Default parity */
  1615. extern int dfflow;                      /* Default flow control */
  1616.  
  1617. #ifdef TNCODE
  1618. extern int tn_deb;
  1619. #endif /* TNCODE */
  1620. /*
  1621.   Buffered file input and output buffers.  See getpkt() in ckcfns.c
  1622.   and zoutdump() in the system-dependent file i/o module (usually ck?fio.c).
  1623. */
  1624. #ifndef DYNAMIC
  1625. /* Now we allocate them dynamically, see getiobs() below. */
  1626. char zinbuffer[INBUFSIZE], zoutbuffer[OBUFSIZE];
  1627. #endif /* DYNAMIC */
  1628. char *zinptr, *zoutptr;
  1629. int zincnt, zoutcnt;
  1630. int zobufsize = OBUFSIZE;
  1631. int zofbuffer = 1;
  1632. int zofblock  = 1;
  1633.  
  1634. #ifdef SESLIMIT
  1635. int seslimit = 0;
  1636. #endif /* SESLIMIT */
  1637.  
  1638. #ifdef CK_AUTHENTICATION
  1639. #include "ckuath.h"
  1640. #endif /* CK_AUTHENTICATION */
  1641.  
  1642. _PROTOTYP( int getiobs, (VOID) );
  1643.  
  1644. /*  M A I N  --  C-Kermit main program  */
  1645.  
  1646. #include <signal.h>
  1647.  
  1648. #ifndef NOCCTRAP
  1649. #include <setjmp.h>
  1650. #include "ckcsig.h"
  1651. ckjmpbuf cmjbuf;
  1652. #ifdef GEMDOS                           /* Special for Atari ST */
  1653. cc_clean();                             /* This can't be right? */
  1654. #endif /* GEMDOS */
  1655. #endif /* NOCCTRAP */
  1656.  
  1657. #ifndef NOXFER
  1658. /* Info associated with a system ID */
  1659.  
  1660. struct sysdata sysidlist[] = {          /* Add others as needed... */
  1661.   { "0",  "anonymous",    0, NUL,  0, 0, 0 },
  1662.   { "A1", "Apple II",     0, NUL,  0, 0, 3 }, /* fix this */
  1663.   { "A3", "Macintosh",    1, ':',  0, 2, 1 },
  1664.   { "D7", "VMS",          0, ']',  1, 0, 0 },
  1665.   { "DA", "RSTS/E",       0, ']',  1, 0, 3 }, /* (i think...) */
  1666.   { "DB", "RT11",         0, NUL,  1, 0, 3 }, /* (maybe...) */
  1667.   { "F3", "AOS/VS",       1, ':',  0, 0, 2 },
  1668.   { "I1", "VM/CMS",       0, NUL,  0, 0, 0 },
  1669.   { "I2", "MVS/TSO",      0, NUL,  0, 0, 0 },
  1670.   { "I4", "MUSIC",        0, NUL,  0, 0, 0 },
  1671.   { "I7", "CICS",         0, NUL,  0, 0, 0 },
  1672.   { "I9", "MVS/ROSCOE",   0, NUL,  0, 0, 0 },
  1673.   { "K2", "Atari ST",     1, '\\', 1, 0, 3 },
  1674.   { "L3", "Amiga",        1, '/',  1, 0, 2 },
  1675.   { "MV", "Stratus VOS",  1, '>',  0, 1, 0 },
  1676.   { "N3", "Apollo Aegis", 1, '/',  0, 3, 2 },
  1677.   { "U1", "UNIX",         1, '/',  0, 3, 2 },
  1678.   { "U8", "MS-DOS",       1, '\\', 1, 0, 3 },
  1679.   { "UD", "OS-9",         1, '/',  0, 3, 2 },
  1680.   { "UN", "Windows-32",   1, '\\', 1, 2, 3 },
  1681.   { "UO", "OS/2",         1, '\\', 1, 2, 3 }
  1682. };
  1683. static int nxxsysids = (sizeof(sysidlist) / sizeof(struct sysdata));
  1684.  
  1685. /* Given a Kermit system ID code, return the associated name string */
  1686. /* and some properties of the filenames... */
  1687.  
  1688. char *
  1689. getsysid(s) char * s; {                 /* Get system-type name */
  1690.     int i;
  1691.     if (!s) return("");
  1692.     for (i = 0; i < nxxsysids; i++)
  1693.       if (!strcmp(sysidlist[i].sid_code,s))
  1694.         return(sysidlist[i].sid_name);
  1695.     return(s);
  1696. }
  1697.  
  1698. int
  1699. getsysix(s) char *s; {                  /* Get system-type index */
  1700.     int i;
  1701.     if (!s) return(-1);
  1702.     for (i = 0; i < nxxsysids; i++)
  1703.       if (!strcmp(sysidlist[i].sid_code,s))
  1704.         return(i);
  1705.     return(-1);
  1706. }
  1707. #endif /* NOXFER */
  1708.  
  1709. /* Tell if a pathname is absolute (versus relative) */
  1710. /* This should be parceled out to each of the ck*fio.c modules... */
  1711. int
  1712. isabsolute(path) char * path; {
  1713.     int rc = 0;
  1714.     int x;
  1715.     if (!path)
  1716.       return(0);
  1717.     if (!*path)
  1718.       return(0);
  1719.     x = (int) strlen(path);
  1720.     debug(F111,"isabsolute",path,x);
  1721. #ifdef VMS
  1722.     rc = 0;
  1723.     x = ckindex("[",path,0,0,0);        /* 1-based */
  1724.     if (!x)
  1725.        x = ckindex("<",path,0,0,0);
  1726.     debug(F111,"isabsolute left bracket",path,x);
  1727.     if (!x) {
  1728.         x = ckindex(":",path,-1,1,1);
  1729.         if (x)
  1730.           debug(F111,"isabsolute logical",path,x);
  1731.     }
  1732.     if (x > 0)
  1733.       if (path[x] != '.')               /* 0-based */
  1734.         rc = 1;
  1735. #else
  1736. #ifdef UNIX
  1737.     if (*path == '/'
  1738. #ifdef DTILDE
  1739.         || *path == '~'
  1740. #endif /* DTILDE */
  1741.         )
  1742.       rc = 1;
  1743. #else
  1744. #ifdef OS2
  1745.     if (*path == '/' || *path == '\\')
  1746.       rc = 1;
  1747.     else if (isalpha(*path) && x > 2)
  1748.       if (*(path+1) == ':' && (*(path +2) == '/' || *(path+2) == '\\'))
  1749.         rc = 1;
  1750. #else
  1751. #ifdef AMIGA
  1752.     if (*path == '/'
  1753. #ifdef DTILDE
  1754.         || *path == '~'
  1755. #endif /* DTILDE */
  1756.         )
  1757.       rc = 1;
  1758. #else
  1759. #ifdef OSK
  1760.     if (*path == '/'
  1761. #ifdef DTILDE
  1762.         || *path == '~'
  1763. #endif /* DTILDE */
  1764.         )
  1765.       rc = 1;
  1766. #else
  1767. #ifdef datageneral
  1768.     if (*path == ':')
  1769.       rc = 1;
  1770. #else
  1771. #ifdef MAC
  1772.     rc = 0;                             /* Fill in later... */
  1773. #else
  1774. #ifdef STRATUS
  1775.     rc = 0;                             /* Fill in later... */
  1776. #else
  1777. #ifdef GEMDOS
  1778.     if (*path == '/' || *path == '\\')
  1779.       rc = 1;
  1780.     else if (isalpha(*path) && x > 1)
  1781.       if (*(path+1) == ':')
  1782.         rc = 1;
  1783. #endif /* GEMDOS */
  1784. #endif /* STRATUS */
  1785. #endif /* MAC */
  1786. #endif /* datageneral */
  1787. #endif /* OSK */
  1788. #endif /* AMIGA */
  1789. #endif /* OS2 */
  1790. #endif /* UNIX */
  1791. #endif /* VMS */
  1792.     debug(F101,"isabsolute rc","",rc);
  1793.     return(rc);
  1794. }
  1795.  
  1796. /*  See if I have direct access to the keyboard  */
  1797.  
  1798. int
  1799. is_a_tty(n) int n; {
  1800. #ifdef UNIX
  1801.     extern int ttfdflg;
  1802.     if (ttfdflg > 0)
  1803.       return(1);
  1804. #endif /* UNIX */
  1805. #ifdef KUI
  1806.     return 1;
  1807. #else /* KUI */
  1808. #ifdef NT
  1809.     if (isWin95())
  1810.       return(1);
  1811.     else
  1812.       return(_isatty(n));
  1813. #else
  1814. #ifdef IKSD
  1815.    if (inserver)
  1816.      return(1);
  1817.    else
  1818. #endif /* IKSD */
  1819.      return(isatty(n));
  1820. #endif /* NT */
  1821. #endif /* KUI */
  1822. }
  1823.  
  1824. #ifndef NOXFER
  1825. VOID
  1826. initxlist() {
  1827.     extern char * sndexcept[], * rcvexcept[];
  1828.     int i;
  1829.     for (i = 0; i < NSNDEXCEPT; i++) {
  1830.     sndexcept[i] = NULL;
  1831.     rcvexcept[i] = NULL;
  1832.     }
  1833. }
  1834. #endif /* NOXFER */
  1835.  
  1836. /* Initialize flow control table */
  1837.  
  1838. VOID
  1839. initflow() {                            /* Default values for flow control */
  1840. #ifdef VMS                              /* for each kind of connection. */
  1841.     /* The VMS telnet terminal driver treats "none" as request to lose chars */
  1842.     cxflow[CXT_REMOTE]  = FLO_XONX;     /* Remote mode... */
  1843. #else
  1844. #ifdef HPUX
  1845.     /* Ditto for HP-UX */
  1846.     cxflow[CXT_REMOTE]  = FLO_XONX;     /* Remote mode... */
  1847. #else
  1848.     /* The temptation is to make this one FLO_KEEP but don't!!! */
  1849.     /* It totally wrecks binary-file transfer when coming in via Telnet. */
  1850.     /* In UNIX at least... */
  1851.     cxflow[CXT_REMOTE]  = FLO_NONE;
  1852. #endif /* HPUX */
  1853. #endif /* VMS */
  1854.  
  1855. #ifdef VMS
  1856.     cxflow[CXT_DIRECT]  = FLO_XONX;     /* Direct serial connections... */
  1857. #else
  1858.     cxflow[CXT_DIRECT]  = FLO_NONE;
  1859. #endif /* VMS */
  1860.  
  1861. #ifdef CK_RTSCTS
  1862.     cxflow[CXT_MODEM]   = FLO_RTSC;     /* Modem connections... */
  1863. #else
  1864. #ifdef VMS
  1865.     cxflow[CXT_MODEM]   = FLO_XONX;
  1866. #else
  1867.     cxflow[CXT_MODEM]   = FLO_NONE;
  1868. #endif /* VMS */
  1869. #endif /* CK_RTSCTS */
  1870.  
  1871. #ifdef VMS
  1872.     cxflow[CXT_TCPIP]   = FLO_XONX;     /* TCP/IP connections... */
  1873. #else
  1874.     cxflow[CXT_TCPIP]   = FLO_NONE;
  1875. #endif /* VMS */
  1876.  
  1877.     cxflow[CXT_SSH]     = FLO_NONE;
  1878.     cxflow[CXT_X25]     = FLO_NONE;     /* Other kinds of networks... */
  1879.     cxflow[CXT_DECNET]  = FLO_XONX;
  1880.     cxflow[CXT_LAT]     = FLO_XONX;
  1881.     cxflow[CXT_NETBIOS] = FLO_NONE;
  1882.     cxflow[CXT_NPIPE]   = FLO_NONE;
  1883.     cxflow[CXT_PIPE]    = FLO_NONE;
  1884.     flow = cxflow[cxtype];              /* Initial flow setting. */
  1885.     debug(F101,"initflow","",flow);
  1886. }
  1887.  
  1888. #ifndef NOXFER
  1889. /* Initialize file transfer protocols */
  1890.  
  1891. VOID
  1892. initproto(y, upbstr, uptstr, srvstr, sndbstr, sndtstr, rcvbstr, rcvtstr)
  1893.     int y;
  1894.     char * upbstr, * uptstr, * srvstr, * sndbstr, * sndtstr, * rcvbstr,
  1895.     * rcvtstr;
  1896. /* initproto */ {
  1897.  
  1898.     if (upbstr)                         /* Convert null strings */
  1899.       if (!*upbstr)                     /* to null pointers */
  1900.         upbstr = NULL;
  1901.  
  1902.     if (uptstr)                         /* Convert null strings */
  1903.       if (!*uptstr)                     /* to null pointers */
  1904.         uptstr = NULL;
  1905.  
  1906.     if (sndbstr)
  1907.       if (!*sndbstr)
  1908.         sndbstr = NULL;
  1909.  
  1910.     if (sndtstr)
  1911.       if (!*sndtstr)
  1912.         sndtstr = NULL;
  1913.  
  1914.     if (rcvbstr)
  1915.       if (!*rcvbstr)
  1916.         rcvbstr = NULL;
  1917.  
  1918.     if (rcvtstr)
  1919.       if (!*rcvtstr)
  1920.         rcvtstr = NULL;
  1921.  
  1922.     if (srvstr)
  1923.       if (!*srvstr)
  1924.         srvstr = NULL;
  1925.  
  1926.     protocol = y;                       /* Set protocol */
  1927.  
  1928.     if (ptab[protocol].rpktlen > -1)
  1929.       urpsiz = ptab[protocol].rpktlen;
  1930.     if (ptab[protocol].spktflg > -1)
  1931.       spsizf = ptab[protocol].spktflg;
  1932.     if (ptab[protocol].spktlen > -1) {
  1933.         spsiz = ptab[protocol].spktlen;
  1934.         debug(F101,"initproto spsiz","",spsiz);
  1935.         if (spsizf) {
  1936.             spsizr = spmax = spsiz;
  1937.             debug(F101,"initproto spsizr","",spsizr);
  1938.         }
  1939.     }
  1940.     if (ptab[protocol].winsize > -1)
  1941.       wslotr = ptab[protocol].winsize;
  1942.     if (ptab[protocol].prefix > -1)
  1943.       prefixing = ptab[protocol].prefix;
  1944.     if (ptab[protocol].fnca > -1)
  1945.       fncact  = ptab[protocol].fnca;
  1946.     if (ptab[protocol].fncn > -1)
  1947.       fncnv   = ptab[protocol].fncn;
  1948.     if (ptab[protocol].fnsp > -1)
  1949.       fnspath = ptab[protocol].fnsp;
  1950.     if (ptab[protocol].fnrp > -1)
  1951.       fnrpath = ptab[protocol].fnrp;
  1952.  
  1953.     makestr(&(ptab[protocol].h_b_init),upbstr);
  1954.     makestr(&(ptab[protocol].h_t_init),uptstr);
  1955.     makestr(&(ptab[protocol].h_x_init),srvstr);
  1956.     makestr(&(ptab[protocol].p_b_scmd),sndbstr);
  1957.     makestr(&(ptab[protocol].p_t_scmd),sndtstr);
  1958.     makestr(&(ptab[protocol].p_b_rcmd),rcvbstr);
  1959.     makestr(&(ptab[protocol].p_t_rcmd),rcvtstr);
  1960. }
  1961. #endif /* NOXFER */
  1962.  
  1963. #ifndef NOCMDL
  1964. VOID
  1965. #ifdef CK_ANSIC
  1966. docmdline(void * threadinfo)
  1967. #else /* CK_ANSIC */
  1968. docmdline(threadinfo) VOID * threadinfo;
  1969. #endif /* CK_ANSIC */
  1970. {
  1971. #ifdef NTSIG
  1972.     setint();
  1973.     if (threadinfo) {                   /* Thread local storage... */
  1974.        TlsSetValue(TlsIndex,threadinfo);
  1975.        debug( F100, "docmdline called with threadinfo block", "", 0 );
  1976.     } else
  1977.       debug( F100, "docmdline threadinfo is NULL","",0);
  1978. #endif /* NTSIG */
  1979. #ifdef CK_LOGIN
  1980. #ifdef NT
  1981. #ifdef IKSD
  1982.     if (inserver)
  1983.       setntcreds();
  1984. #endif /* IKSD */
  1985. #endif /* NT */
  1986. #endif /* CK_LOGIN */
  1987.     proto();                            /* Take any requested action, then */
  1988.     if (!quiet)                         /* put cursor back at left margin, */
  1989.       conoll("");
  1990. #ifndef NOLOCAL
  1991.     if (cnflg) {                        /* Re-connect if requested */
  1992.         cnflg = 0;
  1993.         doconect(0,0);
  1994.         if (ttchk() < 0)
  1995.           dologend();
  1996.     }
  1997. #endif /* NOLOCAL */
  1998.  
  1999. #ifdef NTSIG
  2000.      ckThreadEnd(threadinfo);
  2001. #endif /* NTSIG */
  2002.    return;
  2003. }
  2004.  
  2005. void
  2006. ikslogin() {
  2007.     if (sstelnet
  2008. #ifdef IKSD
  2009.         || inserver                     /* Internet server */
  2010. #endif /* IKSD */
  2011.         ) {
  2012.         char *s;
  2013.         extern int fdispla;             /* File-transfer display format */
  2014.         extern char * ikprompt;         /* IKSD prompt */
  2015.  
  2016. #ifdef IKSD
  2017. #ifdef CK_LOGIN
  2018.         if (inserver) {
  2019.             x_login = 1;                /* Login required */
  2020.             x_logged = 0;               /* Not logged in yet */
  2021.             cmsetp(ikprompt);           /* Set up IKSD's prompt */
  2022. #ifndef NOSERVER
  2023.             en_mai = 0;                 /* MAIL is disabled */
  2024.             en_who = 0;                 /* REMOTE WHO is disabled */
  2025.             en_hos = 0;                 /* REMOTE HOST is disabled */
  2026.             en_pri = 0;                 /* PRINT is disabled */
  2027. #endif /* NOSERVER */
  2028.         } else {
  2029.             x_login = 0;                /* Login not required */
  2030.             x_logged = 1;               /* Already logged in */
  2031.         }
  2032. #endif /* CK_LOGIN */
  2033. #endif /* IKSD */
  2034.         nolocal = 1;                    /* SET LINE/HOST not allowed */
  2035.         fdispla = XYFD_N;               /* No file-transfer display */
  2036. #ifdef NETCONN
  2037.         clienthost = ckgetpeer();       /* Get client's hostname */
  2038.         debug(F110,"ikslogin clienthost",clienthost,0);
  2039. #endif /* NETCONN */
  2040.         ztime(&s);                      /* Get current date and time */
  2041.  
  2042. #ifdef CK_LOGIN
  2043. #ifdef CK_AUTHENTICATION
  2044.         if (x_login) {
  2045.             x_logged = ck_tn_auth_valid(); /* Did Telnet Auth succeed? */
  2046.             debug(F111,"ikslogin","x_logged",x_logged);
  2047.  
  2048. #ifdef NT
  2049.             /* On Windows 9x, we do not have the ability in  */
  2050.             /* zvuser() at present to determine if the name  */
  2051.             /* approved in a Kerberos principal is really a  */
  2052.             /* an account in the Windows Access Control List */
  2053.             if (isWin95() && x_logged == AUTH_VALID
  2054.                  && (ck_tn_authenticated() != AUTHTYPE_NTLM)
  2055. #ifdef CK_SRP
  2056.                  && (ck_tn_authenticated() != AUTHTYPE_SRP)
  2057. #endif /* CK_SRP */
  2058.                  ) {
  2059.                 auth_finished(AUTH_USER);
  2060.                 x_logged = AUTH_USER;
  2061.                 printf("WARNING:\r\n");
  2062.                 printf(
  2063. " The Telnet authentication method used cannot provide for automated\r\n");
  2064.                 printf(
  2065. " login to Windows 95 or Windows 98.  A password must be entered\r\n");
  2066.                 printf(
  2067. " locally to validate your userid.  Telnet authentication (and encryption)\r\n"
  2068.                 );
  2069.                 printf(
  2070. " can be used to validate the host (and protect the privacy of your password.)\
  2071. \r\n"
  2072.                 );
  2073.             }
  2074. #endif /* NT */
  2075.  
  2076.             if (x_logged == AUTH_VALID) {
  2077. #ifdef CK_SSL
  2078.                 if ((ssl_active_flag || tls_active_flag) &&
  2079.                     (!TELOPT_U(TELOPT_AUTHENTICATION) ||
  2080.                      ck_tn_authenticated() == AUTHTYPE_NULL ||
  2081.                      ck_tn_authenticated() == AUTHTYPE_AUTO)
  2082.                     ) {
  2083. #ifdef SSL_KRB5
  2084.                     if (tls_is_krb5(0)) {
  2085.                         printf("Authenticated using Kerberos 5\r\n");
  2086. #ifdef CKSYSLOG
  2087.                         if (ckxsyslog >= SYSLG_LI && ckxlogging) {
  2088.                             extern char szUserNameAuthenticated[];
  2089.                             cksyslog(SYSLG_LI, 1, "AUTH_VALID",
  2090.                                      "Kerberos 5",
  2091.                                      szUserNameAuthenticated
  2092.                                      );
  2093.                         }
  2094. #endif /* CKSYSLOG */
  2095.                     } else
  2096. #endif /* SSL_KRB5 */
  2097.                     {
  2098.                         printf("Authenticated using X.509 certificate\r\n");
  2099. #ifdef CKSYSLOG
  2100.                         if (ckxsyslog >= SYSLG_LI && ckxlogging) {
  2101.                             extern char szUserNameAuthenticated[];
  2102.                             cksyslog(SYSLG_LI, 1, "AUTH_VALID",
  2103.                                      "X.509 certificate",
  2104.                                      szUserNameAuthenticated
  2105.                                      );
  2106.                         }
  2107. #endif /* CKSYSLOG */
  2108.                     }
  2109.                 } else
  2110. #endif /* CK_SSL */
  2111.                   {
  2112.                       printf("Authenticated using %s\r\n",
  2113.                              AUTHTYPE_NAME(ck_tn_authenticated()));
  2114. #ifdef CKSYSLOG
  2115.                       if (ckxsyslog >= SYSLG_LI && ckxlogging) {
  2116.                           extern char szUserNameAuthenticated[];
  2117.                           cksyslog(SYSLG_LI, 1, "AUTH_VALID",
  2118.                                    AUTHTYPE_NAME(ck_tn_authenticated()),
  2119.                                    szUserNameAuthenticated
  2120.                                    );
  2121.                       }
  2122. #endif /* CKSYSLOG */
  2123.                   }
  2124.                 zvuser(uidbuf);
  2125.                 if (zvpass("") == 0)
  2126.                   x_logged = 0;
  2127.             } else if (x_logged == AUTH_USER && !strcmp(uidbuf,"anonymous")) {
  2128.                 extern char szUserNameAuthenticated[];
  2129.                 zvuser(uidbuf);
  2130.                 debug(F110,"szUserNameAuthenticated",
  2131.                       szUserNameAuthenticated,0);
  2132.                 if (zvpass(szUserNameAuthenticated) == 0) {
  2133.                   /* Anonymous login failed.  Force a username prompt. */
  2134.                   x_logged = 0;
  2135.                   uidbuf[0] = '\0';
  2136.                 } else {
  2137. #ifdef CK_SSL
  2138.                     if ((ssl_active_flag || tls_active_flag) &&
  2139.                         (!TELOPT_U(TELOPT_AUTHENTICATION) ||
  2140.                          ck_tn_authenticated() == AUTHTYPE_NULL ||
  2141.                          ck_tn_authenticated() == AUTHTYPE_AUTO)) {
  2142.                         printf("Authenticated using X.509 certificate\r\n");
  2143. #ifdef CKSYSLOG
  2144.                         if (ckxsyslog >= SYSLG_LI && ckxlogging) {
  2145.                             extern char szUserNameAuthenticated[];
  2146.                             cksyslog(SYSLG_LI, 1, "AUTH_USER",
  2147.                                      "X.509 certificate",
  2148.                                      szUserNameAuthenticated
  2149.                                      );
  2150.                         }
  2151. #endif /* CKSYSLOG */
  2152.                     } else
  2153. #endif /* CK_SSL */
  2154.                       {
  2155.                           printf("Authenticated using %s\r\n",
  2156.                                  AUTHTYPE_NAME(ck_tn_authenticated())
  2157.                                  );
  2158. #ifdef CKSYSLOG
  2159.                           if (ckxsyslog >= SYSLG_LI && ckxlogging) {
  2160.                               cksyslog(SYSLG_LI, 1, "AUTH_USER",
  2161.                                        AUTHTYPE_NAME(ck_tn_authenticated()),
  2162.                                        szUserNameAuthenticated
  2163.                                        );
  2164.                           }
  2165. #endif /* CKSYSLOG */
  2166.                       }
  2167.                 }
  2168.             } else {
  2169. #ifdef CKSYSLOG
  2170.                 if (ckxsyslog >= SYSLG_LI && ckxlogging &&
  2171.                     x_logged == AUTH_USER) {
  2172.                     extern char szUserNameAuthenticated[];
  2173.                     cksyslog(SYSLG_LI, 1, "AUTH_USER",
  2174.                              AUTHTYPE_NAME(ck_tn_authenticated()),
  2175.                              szUserNameAuthenticated
  2176.                              );
  2177.                 }
  2178. #endif /* CKSYSLOG */
  2179.                 x_logged = 0;
  2180.                 if (!strcmp("(unknown)",uidbuf)
  2181. #ifdef NT
  2182.                     || !stricmp("administrator",uidbuf)
  2183. #ifdef UNIX
  2184.                     || !strcmp("root",uidbuf)
  2185. #else
  2186. #ifdef Plan9
  2187.                     || !strcmp("root",uidbuf)
  2188. #else
  2189. #ifdef OSK
  2190.                     || !strcmp("root",uidbuf)
  2191. #endif /* OSK */
  2192. #endif /* Plan9 */
  2193. #endif /* UNIX */
  2194. #endif /* NT */
  2195.                     )
  2196.                   uidbuf[0] = '\0';
  2197.             }
  2198.         }
  2199. #endif /* CK_AUTHENTICATION */
  2200. #endif /* CK_LOGIN */
  2201.  
  2202. #ifdef IKSD
  2203.         if (inserver)
  2204.           printf("\r\nInternet Kermit Service ready at %s%s\r\n",s,versio);
  2205.         else
  2206. #endif /* IKSD */
  2207.           printf("\r\nC-Kermit ready at %s%s\r\n",s,versio);
  2208.         if (*myhost)
  2209.           printf("%s\r\n", myhost);
  2210.         printf("\r\n");
  2211.     }
  2212. #ifdef CK_LOGIN
  2213. #ifdef IKSD
  2214.     if (inserver) {
  2215.         int i;
  2216.         extern int arg_x;               /* Flag for '-x' on command line */
  2217. #ifndef NOSPL
  2218.         extern struct mtab *mactab;         /* For ON_LOGIN macro. */
  2219.         extern int nmac;
  2220. #endif /* NOSPL */
  2221.  
  2222.         debug(F110,"MAIN clienthost",clienthost,0);
  2223.         srvidl = timelimit = logintimo; /* For interactive login */
  2224.         rtimer();                       /* Reset timer */
  2225.         for (i = 0; i < iks_retry && !x_logged; i++) { /* Count retries */
  2226.             if (gtimer() > logintimo)
  2227.               break;
  2228. #ifdef TNCODE
  2229.             tn_wait("login loop");
  2230.             tn_push();
  2231. #endif /* TNCODE */
  2232.             debug(F101,"MAIN LOGIN try","",i);
  2233.             what = W_NOTHING;           /* Because proto() changes this */
  2234.  
  2235. #ifdef IKS_OPTION
  2236.             debug(F111,"MAIN LOGIN",
  2237.                   "TELOPT_SB(TELOPT_KERMIT).kermit.me_start",
  2238.                   TELOPT_SB(TELOPT_KERMIT).kermit.me_start
  2239.                   );
  2240.             /* Kermit server negotiated */
  2241.             if (TELOPT_SB(TELOPT_KERMIT).kermit.me_start) {
  2242.                 debug(F101,"IKSD starting in server mode","",0);
  2243.                 arg_x = 1;              /* Enter server mode */
  2244.                 sstate = 'x';
  2245. #ifdef IKSDPOPBACK
  2246.                 justone = 1;            /* Execute one command at a time. */
  2247. #endif /* IKSDPOPBACK */
  2248.                 proto();                /* Enter protocol if requested. */
  2249. #ifdef NTSIG
  2250.                 ck_ih();
  2251. #endif /* NTSIG */
  2252.                 if (x_logged)           /* Logged in */
  2253.                   break;
  2254.             } else {                    /* Not in client/server mode */
  2255. #endif /* IKS_OPTION */
  2256.                 debug(F101,"IKSD starting with Username prompt","",0);
  2257.                 x_logged = ckxlogin((CHAR *)uidbuf,NULL,NULL,1);
  2258.                 if (sstate) {           /* Received a packet at prompt */
  2259. #ifdef IKSDPOPBACK
  2260.                     justone = 1;        /* Go handle it */
  2261. #endif /* IKSDPOPBACK */
  2262.                     proto();
  2263.                 }
  2264.                 if (!x_logged) {        /* In case we are at the prompt... */
  2265.                     printf("Access denied.\n");
  2266.                     uidbuf[0] = '\0';   /* Forget the name if we have one */
  2267.                 }
  2268. #ifdef IKS_OPTION
  2269.             }
  2270. #endif /* IKS_OPTION */
  2271.         }
  2272.         srvidl = timelimit = iks_timo;  /* Reset command timelimit */
  2273.         debug(F101,"MAIN LOGIN","",x_logged);
  2274.         if (!x_logged) {                /* Logins failed. */
  2275.             if (TELOPT_SB(TELOPT_KERMIT).kermit.me_start)
  2276.               errpkt((CHAR *)"Login Timeout");
  2277.             msleep(500);
  2278.             doexit(BAD_EXIT,0);
  2279.         }
  2280.         what = W_NOTHING;               /* Stay in known state */
  2281. #ifndef NOSERVER
  2282.         if (isguest) {
  2283.             en_pri = 0;                 /* No printing for anonymous users */
  2284.             en_mai = 0;                 /* No email for anonymous users */
  2285.             en_mkd = 0;                 /* Or directory creation */
  2286.             en_rmd = 0;                 /* Or directory removal */
  2287.             en_ena = 0;                 /* Or ENABLing DISABLEd items */
  2288.         }
  2289. #endif /* NOSERVER */
  2290.  
  2291. #ifndef NOSPL
  2292. /*
  2293.   If a macro named "on_login" is defined, execute it.  Also remove it from the
  2294.   macro table so the user cannot see what it does.  Execute it as part of the
  2295.   iksd.conf file.
  2296. */
  2297.         if (nmac) {                     /* Any macros defined? */
  2298.             int k;                      /* Yes */
  2299.             char * cmd = "on_login";    /* MSVC 2.x compiler error */
  2300.             k = mlook(mactab,cmd,nmac); /* Look up "on_login" */
  2301.             if (k >= 0) {               /* If found, */
  2302. #ifdef IKSDCONF
  2303.                 int saved = iksdcf;
  2304.                 iksdcf = 0;
  2305. #endif /* IKSDCONF */
  2306.                 if (dodo(k,"",0) > -1)  /* set it up, */
  2307.                   parser(1);            /* execute it */
  2308. #ifdef IKSDCONF
  2309.                 iksdcf = saved;
  2310. #endif /* IKSDCONF */
  2311.                 delmac(cmd,1);          /* and delete it */
  2312.             }
  2313.         }
  2314. #endif /* NOSPL */
  2315.     } /* if (inserver) */
  2316. #else /* CK_LOGIN */
  2317.     if (inserver)
  2318.         srvidl = timelimit = iks_timo;  /* Set idle limits for IKS */
  2319. #endif /* CK_LOGIN */
  2320. #endif /* IKSD */
  2321. }
  2322.  
  2323. VOID
  2324. #ifdef CK_ANSIC
  2325. failcmdline(void * foo)
  2326. #else /* CK_ANSIC */
  2327. failcmdline(foo) VOID * foo;
  2328. #endif /* CK_ANSIC */
  2329. {
  2330. #ifdef GEMDOS
  2331.     cc_clean();
  2332. #endif /* GEMDOS */
  2333. #ifndef NOLOCAL
  2334.     if (cnflg) doconect(0,0);           /* connect again if requested. */
  2335.     if (ttchk() < 0)
  2336.       dologend();
  2337. #endif /* NOLOCAL */
  2338. }
  2339. #endif /* NOCMDL */
  2340.  
  2341. #ifndef NOICP
  2342. VOID
  2343. #ifdef CK_ANSIC
  2344. dotakeini(void * threadinfo)            /* Execute init file. */
  2345. #else  /* CK_ANSIC */
  2346. dotakeini(threadinfo) VOID * threadinfo; /* Execute init file. */
  2347. #endif /* CK_ANSIC */
  2348. /* dotakeini */ {
  2349. #ifdef NTSIG
  2350.     setint();
  2351.     if (threadinfo) {                   /* Thread local storage... */
  2352.        TlsSetValue(TlsIndex,threadinfo);
  2353.        debug(F100, "dotakeini called with threadinfo block","", 0);
  2354.     } else
  2355.       debug(F100, "dotakeini - threadinfo is NULL", "", 0);
  2356. #endif /* NTSIG */
  2357. #ifdef CK_LOGIN
  2358. #ifdef NT
  2359. #ifdef IKSD
  2360.     if (inserver)
  2361.       setntcreds();
  2362. #endif /* IKSD */
  2363. #endif /* NT */
  2364. #endif /* CK_LOGIN */
  2365.     cmdini();                           /* Sets tlevel */
  2366.  
  2367.     debug(F111,"dotakeini","inserver",inserver);
  2368.     debug(F111,"dotakeini","sstelnet",sstelnet);
  2369.  
  2370. #ifdef COMMENT
  2371. /* Wrong place for this... */
  2372. #ifndef NOXFER
  2373. #ifdef CK_FAST
  2374.     dofast();                           /* By now FAST defaults should be OK */
  2375. #endif /* CK_FAST */
  2376. #endif /* NOXFER */
  2377. #endif /* COMMENT */
  2378.  
  2379.     doinit();                           /* Now do the initialization file */
  2380.     debug(F101,"main executing init file","",tlevel);
  2381.     while (tlevel > -1) {
  2382.         sstate = (CHAR) parser(1);      /* Execute one command at a time. */
  2383.         if (sstate) proto();            /* Enter protocol if requested. */
  2384. #ifdef NTSIG
  2385.         ck_ih();
  2386. #endif /* NTSIG */
  2387.     }
  2388.     debug(F101,"main exits init file","",tlevel);
  2389.  
  2390. #ifdef NTSIG
  2391.     ckThreadEnd(threadinfo);
  2392. #endif /* NTSIG */
  2393.     return;
  2394. }
  2395.  
  2396. VOID
  2397. #ifdef CK_ANSIC
  2398. failtakeini(void * threadinfo)
  2399. #else /* CK_ANSIC */
  2400. failtakeini(threadinfo) VOID * threadinfo;
  2401. #endif /* CK_ANSIC */
  2402. /* failtakeini */ {
  2403. #ifdef GEMDOS
  2404.     cc_clean();                         /* Atari: Clean up after ^C-trap. */
  2405. #endif /* GEMDOS */
  2406.     fixcmd();
  2407.     if (!cfilef) {
  2408.         conoll("Interrupted during initialization or \
  2409. command-line processing.");
  2410.         conoll("C-Kermit quitting...");
  2411.     }
  2412.     doexit(BAD_EXIT,-1);                /* Exit with bad status. */
  2413. }
  2414.  
  2415. VOID
  2416. #ifdef CK_ANSIC
  2417. doicp(void * threadinfo)
  2418. #else /* CK_ANSIC */
  2419. doicp(threadinfo) VOID * threadinfo;
  2420. #endif /* CK_ANSIC */
  2421. /* doicp */ {
  2422. #ifdef NTSIG
  2423.     setint();
  2424.     if (threadinfo) {                   /* Thread local storage... */
  2425.        if (!TlsSetValue(TlsIndex,threadinfo))
  2426.           debug(F101,"doicp TlsSetValue failed","",GetLastError());
  2427.        debug(F101, "doicp a threadinfo block - TlsIndex", "", TlsIndex);
  2428.     } else {
  2429.         debug(F100, "doicp received a null threadinfo", "", 0);
  2430.     }
  2431. #endif /* NTSIG */
  2432. #ifdef CK_LOGIN
  2433. #ifdef NT
  2434. #ifdef IKSD
  2435.     if (inserver)
  2436.       setntcreds();
  2437. #endif /* IKSD */
  2438. #endif /* NT */
  2439. #endif /* CK_LOGIN */
  2440. #ifdef MAC
  2441.     while (1) {
  2442.         extern char *lfiles;            /* Fake pointer cast */
  2443.  
  2444.         if (connected) {
  2445.             debug(F100, "doicp: calling macparser", "", 0);
  2446.             sstate = newparser(1, 1, 0L);
  2447.  
  2448.             /* ignore null command state */
  2449.             if (sstate == 'n')
  2450.               sstate = '\0';
  2451.  
  2452.             if (sstate)
  2453.               proto();
  2454.         } else {
  2455.             /*
  2456.              * process take files the finder gave us.
  2457.              */
  2458.             if ((tlevel == -1) && lfiles)
  2459.               startlfile();
  2460.  
  2461.             debug(F100, "doicp: calling parser", "", 0);
  2462.             sstate = (CHAR) parser(0);
  2463.             if (sstate == 'c')          /* if MAC connect */
  2464.               sstate = 0;
  2465.             if (sstate)
  2466.               proto();
  2467.         }
  2468.     }
  2469. #else /* Not MAC */
  2470.  
  2471. #ifndef NOSPL
  2472. /*
  2473.   If interactive commands were given on the command line (using the
  2474.   -C "command, command, ..." option), assign them to a macro called
  2475.   "cl_commands", then execute the macro and leave it defined for
  2476.   subsequent re-execution if desired.
  2477. */
  2478.     if (clcmds) {                       /* Check for -C commands */
  2479.         int x;
  2480.         x = addmac("cl_commands",clcmds); /* Put macro in table */
  2481.         if (x > -1) {                   /* If successful, */
  2482.             dodo(x,NULL,CF_CMDL);       /* set up for macro execution */
  2483.             while (maclvl > -1) {       /* Loop getting macro commands. */
  2484.                 sstate = (CHAR) parser(1);
  2485.                 if (sstate) proto();    /* Enter protocol if requested. */
  2486. #ifdef NTSIG
  2487.                 ck_ih();
  2488. #endif /* NTSIG */
  2489.             }
  2490.         }
  2491.         debug(F100,"doicp calling herald","",0);
  2492.         herald();
  2493.     }
  2494. #endif /* NOSPL */
  2495.     while(1) {                          /* Loop getting commands. */
  2496.         sstate = (CHAR) parser(0);
  2497.         if (sstate) proto();            /* Enter protocol if requested. */
  2498. #ifdef NTSIG
  2499.        ck_ih();
  2500. #endif /* NTSIG */
  2501.     }
  2502. #ifdef NTSIG
  2503.     ckThreadEnd(threadinfo);
  2504. #endif /* NTSIG */
  2505. #endif /* MAC */
  2506. }
  2507.  
  2508. VOID
  2509. #ifdef CK_ANSIC
  2510. failicp(void * threadinfo)
  2511. #else /* CK_ANSIC */
  2512. failicp(threadinfo) VOID * threadinfo;
  2513. #endif /* CK_ANSIC */
  2514. {
  2515. #ifdef GEMDOS
  2516.     cc_clean();
  2517. #endif /* GEMDOS */
  2518.     fixcmd();                           /* Pop command stacks, etc. */
  2519.     clcmds = NULL;
  2520.     debug(F100,"ckcmai got interrupt","",0);
  2521. }
  2522. #endif /* NOICP */
  2523.  
  2524. #ifndef NOICP
  2525. VOID
  2526. #ifdef CK_ANSIC
  2527. docmdfile(void * threadinfo)            /* Execute application file */
  2528. #else /* CK_ANSIC */
  2529. docmdfile(threadinfo) VOID * threadinfo;
  2530. #endif /* CK_ANSIC */
  2531. /* docmdfile */ {
  2532. #ifdef NTSIG
  2533.     concb((char)escape);
  2534.     setint();
  2535.     if (threadinfo) {                   /* Thread local storage... */
  2536.         TlsSetValue(TlsIndex,threadinfo);
  2537.         debug(F100, "docmdfile called with threadinfo block","", 0);
  2538.     } else debug(F100, "docmdfile - threadinfo is NULL", "", 0);
  2539. #endif /* NTSIG */
  2540. #ifdef CK_LOGIN
  2541. #ifdef IKSD
  2542. #ifdef NT
  2543.     if (inserver)
  2544.       setntcreds();
  2545. #endif /* NT */
  2546. #endif /* IKSD */
  2547. #endif /* CK_LOGIN */
  2548.     debug(F110,"main cmdfil",cmdfil,0);
  2549. #ifndef NOSPL
  2550.     addmac("\\%0",cmdfil);
  2551. #endif /* NOSPL */
  2552.     dotake(cmdfil);            /* Set up the command file */
  2553.     if (tlevel > -1)            /* Remember we did this */
  2554.       cfilef = 1;
  2555.     while (tlevel > -1) {               /* Execute it until it runs out. */
  2556.         sstate = parser(1);             /* Loop getting commands. */
  2557.         if (sstate) proto();            /* Enter protocol if requested. */
  2558. #ifdef NTSIG
  2559.         ck_ih();
  2560. #endif /* NTSIG */
  2561.     }
  2562.  
  2563. #ifdef NTSIG
  2564.     ckThreadEnd(threadinfo);
  2565. #endif /* NTSIG */
  2566.     return;
  2567. }
  2568.  
  2569. VOID
  2570. #ifdef CK_ANSIC
  2571. failcmdfile(void * threadinfo)
  2572. #else /* CK_ANSIC */
  2573. failcmdfile(threadinfo) VOID * threadinfo;
  2574. #endif /* CK_ANSIC */
  2575. /* failcmdfile */ {
  2576. #ifdef GEMDOS
  2577.     cc_clean();                         /* Atari: Clean up after ^C-trap. */
  2578. #endif /* GEMDOS */
  2579.     fixcmd();
  2580.     if (!cfilef) {
  2581.     conoll("Interrupted during initialization or \
  2582. command-line processing.");
  2583.     conoll("C-Kermit quitting...");
  2584.     }
  2585.     doexit(BAD_EXIT,-1);                /* Exit with bad status. */
  2586. }
  2587. #endif /* NOICP */
  2588.  
  2589. #ifndef NOXFER
  2590. VOID
  2591. setprefix(z) int z; {                   /* Initial control-char prefixing */
  2592. #ifdef CK_SPEED
  2593.     int i, val;
  2594.  
  2595.     prefixing = z;
  2596.     ptab[protocol].prefix = prefixing;
  2597.     debug(F101,"setprefix","",prefixing);
  2598.     switch (z) {
  2599.       case PX_ALL:                      /* All */
  2600. #ifdef COMMENT
  2601.         /* Don't let Clear-Channel be dependent on prefixing */
  2602.         clearrq = 0;                    /* Turn off clearchannel, fall thru */
  2603. #endif /* COMMENT */
  2604.       case PX_NON:                      /* None */
  2605.         val = (z == PX_ALL) ? 1 : 0;
  2606.         for (i =
  2607. #ifdef UNPREFIXZERO
  2608.              0
  2609. #else
  2610.              1
  2611. #endif /* UNPREFIXZERO */
  2612.              ; i < 32; i++)
  2613.           ctlp[i] = val;
  2614.         for (i = 127; i < 160; i++) ctlp[i] = val;
  2615.         ctlp[(unsigned)255] = val;
  2616.         if (z == PX_NON) {              /* These are never safe */
  2617.             if (network) {              /* Assume network = telnet or rlogin */
  2618.                 ctlp[CR] = 1;           /* Prefix CR because of NVT rules */
  2619.                 ctlp[XON] = ctlp[XOFF] = 1; /* Because of Telnet server */
  2620.                 ctlp[127] = ctlp[255] = 1;  /* Telnet IAC */
  2621.                 ctlp[mystch] = ctlp[mystch+128] = 1; /* Kermit packet start */
  2622.             } else {
  2623.                 ctlp[CR] = ctlp[255] = ctlp[mystch] = ctlp[mystch+128] = 1;
  2624.                 if (flow == FLO_XONX)       /* Xon/Xoff forces prefixing */
  2625.                   ctlp[XON] = ctlp[XOFF] = ctlp[XON+128] = ctlp[XOFF+128] = 1;
  2626.             }
  2627.         }
  2628.         break;
  2629.  
  2630.       case PX_CAU:                      /* Cautious or Minimal */
  2631. #ifdef COMMENT
  2632.         /* Don't let CLEAR-CHANNEL be dependent on Prefixing */
  2633.         clearrq = 0;                    /* Turn off clearchannel */
  2634. #endif /* COMMENT */
  2635.       case PX_WIL:                      /* Minimal ("wild") */
  2636.         ctlp[0] = 1;                    /* Does not include 0 */
  2637.         for (i = 1; i < 32; i++)
  2638.           ctlp[i] = 0;
  2639.         for (i = 127; i < 160; i++)
  2640.           ctlp[i] = 0;
  2641.         ctlp[mystch] = ctlp[mystch+128] = 1; /* Kermit start of packet */
  2642.         if (seol != 13)
  2643.           ctlp[seol] = ctlp[seol+128] = 1; /* Kermit end */
  2644.         ctlp[13] = ctlp[141] = 1;       /* In case of TELNET (NVT rules) */
  2645.         ctlp[(unsigned)255] = 1;        /* Ditto */
  2646.  
  2647.         /* ^D, ^J, ^M, or ^U followed by tilde trigger Rlogin escape */
  2648.  
  2649.         ctlp[4]  = ctlp[4+128]  = 1;    /* In case of RLOGIN */
  2650.         ctlp[10] = ctlp[10+128] = 1;    /* In case of RLOGIN */
  2651.         ctlp[21] = ctlp[21+128] = 1;    /* In case of RLOGIN */
  2652.  
  2653.         if (flow == FLO_XONX ||         /* Xon/Xoff forces prefixing these */
  2654.             prefixing == PX_CAU ||      /* So does CAUTIOUS */
  2655.             network)                    /* Networks too... */
  2656.           ctlp[XON] = ctlp[XOFF] = ctlp[XON+128] = ctlp[XOFF+128] = 1;
  2657.         if (prefixing == PX_CAU) {      /* Cautious - add some more */
  2658. #ifdef UNPREFIXZERO
  2659.             ctlp[0] = 1;
  2660. #endif /* UNPREFIXZERO */
  2661.             ctlp[3]   = ctlp[16]  = 1;             /* ^C, DLE */
  2662.             ctlp[14]  = ctlp[15]  = 1;             /* SO/SI */
  2663.             ctlp[24]  = ctlp[25]  = 1;             /* VMS might need these */
  2664.             ctlp[26]  = ctlp[26+128] = 1;          /* UNIX suspend */
  2665.             ctlp[28]  = ctlp[29]  = ctlp[30]  = 1; /* Assorted esc chars */
  2666.             ctlp[131] = ctlp[141] = ctlp[144] = 1; /* and 8-bit versions */
  2667.             ctlp[(unsigned)255] = ctlp[156] = ctlp[157] = ctlp[158] = 1;
  2668.         }
  2669.         break;
  2670.     }
  2671. #endif /* CK_SPEED */
  2672. }
  2673. #endif /* NOXFER */
  2674.  
  2675. VOID
  2676. makever() {                             /* Make version string from pieces */
  2677.     int x, y;
  2678. #ifndef OS2
  2679. #ifndef MAC
  2680.     ck_s_xver = ck_s_ver;               /* Fill in C-Kermit version number */
  2681.     ck_l_xver = ck_l_ver;               /* for UNIX, VMS, etc. */
  2682. #endif /* MAC */
  2683. #endif /* OS2 */
  2684.     x = strlen(ck_s_name);
  2685.     y = strlen(ck_s_xver);
  2686.     if (y + x + 1 < CKVERLEN) {
  2687.         ckmakmsg(versio,CKVERLEN,ck_s_name," ",ck_s_xver,NULL);
  2688.     } else {
  2689.         ckstrncpy(versio,"C-Kermit",CKVERLEN);
  2690.         return;
  2691.     }
  2692.     x += y + 1;
  2693.     if (*ck_s_who) {
  2694.         y = strlen(ck_s_who);
  2695.         if (CKVERLEN < x + y + 1)
  2696.           return;
  2697.         ckstrncat(versio,"-",CKVERLEN);
  2698.         ckstrncat(versio,ck_s_who,CKVERLEN);
  2699.     }
  2700.     x += y + 1;
  2701.     y = strlen(ck_s_test);
  2702.     if (y > 0 && y + x + 1 < CKVERLEN) {
  2703.         ckstrncat(versio," ",CKVERLEN);
  2704.         ckstrncat(versio,ck_s_test,CKVERLEN);
  2705.         x += y + 1;
  2706.         y = strlen(ck_s_tver);
  2707.         if (y > 0 && y + x + 1 < CKVERLEN) {
  2708.             ckstrncat(versio,".",CKVERLEN);
  2709.             ckstrncat(versio,ck_s_tver,CKVERLEN);
  2710.             x += y + 1;
  2711.         }
  2712.     }
  2713.     y = strlen(ck_s_date);
  2714.     if (y > 0 && y + x + 2 < CKVERLEN) {
  2715.         ckstrncat(versio,", ",CKVERLEN);
  2716.         ckstrncat(versio,ck_s_date,CKVERLEN);
  2717.     }
  2718.     vernum = ck_l_ver;
  2719.     xvernum = ck_l_xver;
  2720.     debug(F110,"Kermit version",versio,0);
  2721. }
  2722.  
  2723. union ck_short shortbytes;              /* For determining byte order */
  2724. int byteorder = 0;                      /* 0 = Big Endian; 1 = Little Endian */
  2725. int bigendian = 1;
  2726. /* NOTE: MUST BE 0 or 1 - nothing else */
  2727.  
  2728. #ifndef NOSPL
  2729. #define SCRIPTLEN 10240
  2730. #endif    /* NOSPL */
  2731.  
  2732. #ifdef NETCONN
  2733. #ifndef NOCMDL
  2734. #ifndef NOURL
  2735. VOID
  2736. dourl() {
  2737.     int rc = 0;
  2738.     char * port = NULL;
  2739.     extern int ttnproto;
  2740.     extern struct urldata g_url;
  2741.  
  2742. #ifdef COMMENT
  2743.     /* NOTE: debug() doesn't work yet - must use printf's */
  2744.     printf("URL:  %s\n",g_url.sav ? g_url.sav : "(none)");
  2745.     printf("Type: %s\n",g_url.svc ? g_url.svc : "(none)");
  2746.     printf("User: %s\n",g_url.usr ? g_url.usr : "(none)");
  2747.     printf("Pass: %s\n",g_url.psw ? g_url.psw : "(none)");
  2748.     printf("Host: %s\n",g_url.hos ? g_url.hos : "(none)");
  2749. /*  printf("Port: %s\n",g_url.por ? g_url.por : "(none)"); */
  2750.     printf("Path: %s\n",g_url.pth ? g_url.pth : "(none)");
  2751. #endif /* COMMENT */
  2752.  
  2753.     if (!ckstrcmp(g_url.svc,"iksd",-1,0) ||
  2754.         !ckstrcmp(g_url.svc,"kermit",-1,0)) {
  2755.         extern char pwbuf[];
  2756.         extern int pwflg;
  2757. #ifdef OS2
  2758.         extern int pwcrypt;
  2759. #endif /* OS2 */
  2760.  
  2761.         if (!g_url.hos) {
  2762.             printf("?Incomplete IKSD URL\n");
  2763.             doexit(BAD_EXIT,1);
  2764.         }
  2765.         if (!g_url.usr)
  2766.             makestr(&g_url.usr,"anonymous");
  2767.         if (!g_url.psw) {
  2768.             char * tmpbuf = NULL;
  2769.             if (!(tmpbuf = (char *)malloc(1024)))
  2770.                 fatal("dourl: out of memory");
  2771.             if (!ckstrcmp(g_url.usr,"anonymous",-1,0)) {
  2772.                 ckmakmsg(tmpbuf,1024,uidbuf,"@",myhost,NULL);
  2773.                 makestr(&g_url.psw,tmpbuf);
  2774.             } else {
  2775.                 readpass(" Password:",tmpbuf,1024);
  2776.                 makestr(&g_url.psw,tmpbuf);
  2777.             }
  2778.             free(tmpbuf);
  2779.         }
  2780.         port = "kermit";
  2781.         ttnproto = NP_TELNET;
  2782.         nettype = NET_TCPB;
  2783.         mdmtyp = -nettype;
  2784.         local = -1;
  2785.         ckstrncpy(uidbuf,g_url.usr,UIDBUFLEN);
  2786.         if (g_url.psw) {
  2787.             ckstrncpy(pwbuf,g_url.psw,PWBUFL);
  2788.             pwflg = 1;
  2789. #ifdef OS2
  2790.             pwcrypt = 0;
  2791. #endif /* OS2 */
  2792.         }
  2793.         ckmakmsg(ttname,
  2794.                  TTNAMLEN,
  2795.                  g_url.hos,
  2796.                  ":",
  2797.                  g_url.por ? g_url.por : port,
  2798.                  NULL
  2799.                  );
  2800.         rc = ttopen(ttname,&local,mdmtyp,0);
  2801.         if (rc > -1) {
  2802.             network = 1;
  2803.             exitonclose = 1;
  2804. #ifdef CKLOGDIAL
  2805.             dolognet();
  2806. #endif /* CKLOGDIAL */
  2807.         } else {
  2808.             printf("?Connection failed: %s\n",g_url.sav);
  2809.             doexit(BAD_EXIT,1);
  2810.         }
  2811.         /* Also need to check here for secure authentication already done */
  2812.  
  2813. #ifdef NOSPL
  2814.         cflg = 1;
  2815. #else
  2816.     {
  2817.             char * script = NULL;
  2818.             if (!(script = (char *)malloc(SCRIPTLEN)))
  2819.               fatal("dourl: out of memory");
  2820.             if (!g_url.pth) {           /* Write the appropriate script */
  2821.         cflg = 1;
  2822.                 ckmakxmsg(script,SCRIPTLEN,
  2823.               "if not eq {\\v(authstate)} {user} ",
  2824.               "if not eq {\\v(authstate)} {valid} { ",
  2825.                           "remote login ", /* No path */
  2826.                           g_url.usr,       /* Just log in and CONNECT */
  2827.                           " ",
  2828.                           g_url.psw,
  2829.                           ", if fail exit 1 {IKSD login failed} }",
  2830.                           ", connect",
  2831.                           NULL,NULL,NULL,NULL);
  2832.         /* printf("CLCMDS 1: %s\n",script); */
  2833.             } else {
  2834.                 /* does the path specify a file or a directory? */
  2835.                 int len = strlen(g_url.pth);
  2836.                 if (ISDIRSEP(g_url.pth[len-1])) {
  2837.             ckmakxmsg(script,SCRIPTLEN, /* Directory name given */
  2838.                   "if not eq {\\v(authstate)} {user} \
  2839. if not eq {\\v(authstate)} {valid} { remote login ",
  2840.                   g_url.usr,
  2841.                   " ",
  2842.                   g_url.psw,
  2843.                   ", if fail exit 1 {IKSD login failed} }",
  2844.                   ", set macro error on",
  2845.                   ", set xfer displ brief",
  2846.                   ", set xfer bell off",
  2847.                   ", remote cd ",
  2848.                   g_url.pth,
  2849.                   ", lineout directory",
  2850.                   ", connect"
  2851.                   );
  2852.             /* printf("CLCMDS 2: %s\n",script); */
  2853.         } else {
  2854.             ckmakxmsg(script,SCRIPTLEN, /* Path given, try to GET */
  2855.                   "if not eq {\\v(authstate)} {user} \
  2856. if not eq {\\v(authstate)} {valid} { remote login ",
  2857.                   g_url.usr,
  2858.                   " ",
  2859.                   g_url.psw,
  2860.                   ", if fail exit 1 {IKSD login failed} }",
  2861.                   ", set xfer displ brief",
  2862.                   ", set xfer bell off",
  2863.                   ", get ",
  2864.                   g_url.pth,
  2865.                   ", .rc := \\v(status)",
  2866.                   ", if open connection bye",
  2867.                   ", exit \\m(rc)"
  2868.                   );
  2869.             /* printf("CLCMDS 2: %s\n",script); */
  2870.         }
  2871.             }
  2872.             clcmds = script;        /* Make this our -C cmdline macro */
  2873.         /* printf("HAVEURL=%d\n",haveurl); */
  2874.         }
  2875. #endif /* NOSPL */
  2876.     } else {
  2877.         if (ckstrcmp(g_url.svc,"telnet",-1,0) &&
  2878. #ifdef SSHBUILTIN
  2879.             ckstrcmp(g_url.svc,"ssh",-1,0) &&
  2880. #endif /* SSHBUILTIN */
  2881.             ckstrcmp(g_url.svc,"ftp",-1,0)) {
  2882.             printf("?Sorry, %s URLs not supported\n",
  2883.                    g_url.svc ? g_url.svc : "");
  2884.             doexit(BAD_EXIT,1);
  2885.         }
  2886.     }
  2887. }
  2888. #endif /* NOCMDL */
  2889. #endif /* NETCONN */
  2890. #endif /* NOURL */
  2891.  
  2892. /*
  2893.   main()...
  2894.  
  2895.   If you get complaints about "main: return type is not blah",
  2896.   define MAINTYPE on the CC command line, e.g. "CFLAGS=-DMAINTYPE=blah"
  2897.   (where "blah" is int, long, or whatever).
  2898.  
  2899.   If the complaint is "Attempt to return a value from a function of type void"
  2900.   then add -DMAINISVOID.
  2901. */
  2902. #ifndef MAINTYPE
  2903. #ifndef MAINISVOID
  2904. #define MAINTYPE int
  2905. #endif /* MAINISVOID */
  2906. #endif /* MAINTYPE */
  2907.  
  2908. #ifdef MAINISVOID
  2909. #ifndef MAINTYPE
  2910. #define MAINTYPE void
  2911. #endif /* MAINTYPE */
  2912. #endif /* MAINISVOID */
  2913.  
  2914. #ifdef aegis
  2915. /* On the Apollo, intercept main to insert a cleanup handler */
  2916. int
  2917. ckcmai(argc,argv) int argc; char **argv;
  2918. #else
  2919. #ifdef MAC                              /* Macintosh */
  2920. int
  2921. main (void)
  2922. #else
  2923. #ifdef __GNUC__                         /* GCC compiler */
  2924. int
  2925. main(argc,argv) int argc; char **argv;
  2926. #else
  2927. #ifdef __DECC                           /* DEC Alpha with DEC C compiler */
  2928. #ifdef __ALPHA
  2929. int
  2930. main(argc,argv) int argc; char **argv;
  2931. #else                                   /* DEC C compiler, not Alpha */
  2932. #define MAINISVOID
  2933. VOID
  2934. main(argc,argv) int argc; char **argv;
  2935. #endif  /* __ALPHA */
  2936. #else
  2937. #ifdef STRATUS                          /* Stratus VOS */
  2938. int
  2939. main(argc,argv) int argc; char **argv;
  2940. #else                                   /* K-95 */
  2941. #ifdef OS2
  2942. #ifdef KUI
  2943. #define MAINISVOID
  2944. void
  2945. Main( int argc, char ** argv )
  2946. #else /* KUI */
  2947. #define MAINISVOID
  2948. VOID
  2949. main(argc,argv) int argc; char **argv;
  2950. #endif /* KUI */
  2951. #else  /* Not K95 */
  2952. MAINTYPE                                /* All others... */
  2953. main(argc,argv) int argc; char **argv;
  2954. #endif /* OS2 */
  2955. #endif /* STRATUS */
  2956. #endif /* __DECC */
  2957. #endif /* __GNUC__ */
  2958. #endif /* MAC */
  2959. #endif /* aegis */
  2960.  
  2961. /* main */ {
  2962.  
  2963.     char *p;
  2964.  
  2965. #ifndef NOSETKEY
  2966.     int i;
  2967. #endif /* NOSETKEY */
  2968.  
  2969. #ifdef datageneral
  2970.     short *pfha = 016000000036;         /* Get around LANG_RT problem */
  2971.     *pfha = (short) 0;                  /* No user protection fault handler */
  2972. #endif /* datageneral */
  2973.  
  2974.     int unbuf = 0;            /* nonzero for unbuffered stdout */
  2975.  
  2976. /* setbuf has to be called on the file descriptor before it is used */
  2977.  
  2978. #ifdef UNIX
  2979. #ifdef NONOSETBUF            /* Unbuffered console i/o */
  2980.     unbuf++;                /* as a compile-time option */
  2981. #endif    /* NONOSETBUF */
  2982.     if (!unbuf) {            /* Or as a command-line selection */
  2983.     int i, n;            /* We have to pre-pre-scan for */
  2984.     char * s;            /* this one. */
  2985.     for (i = 1; i < argc; i++) {
  2986.         s = argv[i];
  2987.         if (!s) n = 0; else n = (int)strlen(s);
  2988.         if (n > 4) {
  2989.         if (!ckstrcmp("--unbuffered",s,n,0)) {
  2990.             unbuf++;
  2991.             break;
  2992.         }
  2993.         }
  2994.     }
  2995.     }
  2996.     if (unbuf)
  2997.       setbuf(stdout,NULL);
  2998. #endif    /* UNIX */
  2999.  
  3000. /* Do some initialization */
  3001.  
  3002. #ifndef MAC
  3003.     xargc = xargs = argc;               /* Make global copies of argc */
  3004.     xargv = argv;                       /* ...and argv. */
  3005.     xarg0 = argv[0];
  3006. #ifdef NT
  3007.     setOSVer();
  3008. #endif /* NT */
  3009.     zstrip(argv[0],&p);                 /* Get name we were invoked with */
  3010.     makestr(&myname,p);
  3011.     if (!ckstrcmp(myname,"telnet",-1,0))       howcalled = I_AM_TELNET;
  3012. #ifdef CK_KERBEROS
  3013.     else if (!ckstrcmp(myname,"ktelnet",-1,0)) howcalled = I_AM_TELNET;
  3014. #endif /* CK_KERBEROS */
  3015.     else if (!ckstrcmp(myname,"rlogin",-1,0))  howcalled = I_AM_RLOGIN;
  3016.     else if (!ckstrcmp(myname,"iksd",-1,0))    howcalled = I_AM_IKSD;
  3017. #ifdef NEWFTP
  3018.     else if (!ckstrcmp(myname,"ftp",-1,0))     howcalled = I_AM_FTP;
  3019. #endif /* NEWFTP */
  3020. #ifndef NOHTTP
  3021.     else if (!ckstrcmp(myname,"http",-1,0))    howcalled = I_AM_HTTP;
  3022. #endif /* NOHTTP */
  3023. #ifdef OS2
  3024.     else if (!ckstrcmp(myname,"telnet.exe",-1,0))  howcalled = I_AM_TELNET;
  3025. #ifdef SSHBUILTIN
  3026.     else if (!ckstrcmp(myname,"ssh",-1,0))  howcalled = I_AM_SSH;
  3027.     else if (!ckstrcmp(myname,"ssh.exe",-1,0))  howcalled = I_AM_SSH;
  3028. #endif /* SSHBUILTIN */
  3029. #ifdef CK_KERBEROS
  3030.     else if (!ckstrcmp(myname,"ktelnet.exe",-1,0)) howcalled = I_AM_TELNET;
  3031. #endif /* CK_KERBEROS */
  3032.     else if (!ckstrcmp(myname,"rlogin.exe",-1,0))  howcalled = I_AM_RLOGIN;
  3033. #ifdef NT
  3034.     else if (!ckstrcmp(myname,"iksdnt",-1,0))    howcalled = I_AM_IKSD;
  3035.     else if (!ckstrcmp(myname,"iksdnt.exe",-1,0))    howcalled = I_AM_IKSD;
  3036. #endif /* NT */
  3037. #ifdef NEWFTP
  3038.     else if (!ckstrcmp(myname,"ftp.exe",-1,0))     howcalled = I_AM_FTP;
  3039. #endif /* NEWFTP */
  3040. #ifndef NOHTTP
  3041.     else if (!ckstrcmp(myname,"http.exe",-1,0))    howcalled = I_AM_HTTP;
  3042. #endif /* NOHTTP */
  3043. #endif /* OS2 */
  3044.     else if (!ckstrcmp(myname,"kermit-sshsub",-1,0)) howcalled = I_AM_SSHSUB;
  3045.  
  3046. #ifndef NOICP
  3047.     cmdini();                           /* Must come before prescan */
  3048.     debug(F100,"main cmdini() done","",0);
  3049. #endif /* NOICP */
  3050.     prescan(0);                         /* Pre-Check for debugging, etc */
  3051. #endif /* MAC */
  3052.     debug(F101,"MAIN feol","",feol);
  3053.     makever();                          /* Put together version strings */
  3054. #ifndef NOSETKEY                        /* Allocate & initialize the keymap */
  3055.     /* This code has been moved to before sysinit() for K95G */
  3056.     if (!(keymap = (KEY *) malloc(sizeof(KEY)*KMSIZE)))
  3057.       fatal("main: no memory for keymap");
  3058.     if (!(macrotab = (MACRO *) malloc(sizeof(MACRO)*KMSIZE)))
  3059.       fatal("main: no memory for macrotab");
  3060.     for (i = 0; i < KMSIZE; i++) {
  3061.        keymap[i] = (KEY) i;
  3062.        macrotab[i] = NULL;
  3063.     }
  3064. #endif /* NOSETKEY */
  3065.  
  3066.     shortbytes.x_short = 0xABCD;        /* Get Endianness */
  3067.     if (shortbytes.x_char[0] == 0xCD) { /* 0 = Big Endian */
  3068.         byteorder = 1;                  /* 1 = Little Endian */
  3069.         bigendian = 0;                  /* (for clarity in programming) */
  3070.     } else {
  3071.         byteorder = 0;                  /* Big Endian */
  3072.         bigendian = 1;
  3073.     }
  3074.     if (sizeof(CK_OFF_T) == 8)        /* Large files and ints? */
  3075.       havelfs = 1;
  3076.  
  3077.     if (sysinit() < 0)                  /* System-dependent initialization. */
  3078.       fatal("Can't initialize!");
  3079.     else
  3080.       initflg = 1;                      /* Remember we did. */
  3081.     debug(F111,"ckcmai myname",myname,howcalled);
  3082.  
  3083. #ifdef UNIX
  3084.     getexedir();                        /* Compute exedir variable */
  3085. #endif /* UNIX */
  3086.  
  3087. #ifdef CKSYSLOG
  3088. #ifdef SYSLOGLEVEL
  3089. /*
  3090.   If built with -DSYSLOGLEVEL on cc command line, this means we always
  3091.   do syslogging at the indicated level.
  3092. */
  3093.     zsyslog();                          /* Open syslog */
  3094. #else /* SYSLOGLEVEL */
  3095. #ifdef IKSD
  3096.     if (inserver)
  3097.       zsyslog();                        /* Open syslog */
  3098. #endif /* IKSD */
  3099. #endif /* SYSLOGLEVEL */
  3100. #endif /* CKSYSLOG */
  3101.  
  3102. #ifdef CK_KERBEROS
  3103.     ini_kerb();                         /* Initialize Kerberos data */
  3104. #endif /* CK_KERBEROS */
  3105. #ifdef CK_SSL
  3106.     ssl_once_init();
  3107. #endif /* CK_SSL */
  3108. #ifdef TNCODE
  3109.     tn_set_modes();                     /* Init Telnet Option tables */
  3110. #endif /* TNCODE */
  3111.  
  3112. #ifdef CK_TTGWSIZ                       /* Initialize screen dimensions */
  3113. #ifdef OS2
  3114.     ttgcwsz();
  3115. #else /* OS2 */
  3116.     if (ttgwsiz() > 0) {
  3117.         if (tt_rows > 0 && tt_cols > 0) {
  3118.             cmd_rows = tt_rows;
  3119.             cmd_cols = tt_cols;
  3120.         }
  3121.     }
  3122. #endif /* OS2 */
  3123. #endif /* CK_TTGWSIZ */
  3124.  
  3125. #ifndef OS2
  3126. #ifdef TCPSOCKET
  3127. #ifdef CK_SOCKS
  3128.     SOCKSinit(argv[0]);                 /* Internet relay package... */
  3129. #endif /* CK_SOCKS */
  3130. #endif /* TCPSOCKET */
  3131. #endif /* OS2 */
  3132.  
  3133.     initflow();                         /* Initialize flow-control table */
  3134.  
  3135. #ifndef NOICP
  3136. #ifdef CKFLOAT
  3137.     initfloat();                        /* Deduce floating-point precision */
  3138. #endif /* CKFLOAT */
  3139. #endif /* NOICP */
  3140.  
  3141. #ifndef NOXFER
  3142.     initxlist();            /* Init exception lists */
  3143.  
  3144. #ifdef CK_XYZ                           /* Initialize protocols...  */
  3145.  
  3146. #ifdef XYZ_INTERNAL /* XYZMODEM are internal ... */
  3147.  
  3148. #ifdef COMMENT
  3149.     /* Can't do this for XMODEM because if filename contains a "C" etc... */
  3150.     initproto(PROTO_X, "rx %s","rx %s", NULL, NULL, NULL, NULL, NULL);
  3151.     initproto(PROTO_XC,"rc %s","rc %s", NULL, NULL, NULL, NULL, NULL);
  3152. #else /* COMMENT */
  3153.     initproto(PROTO_X, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
  3154.     initproto(PROTO_XC,NULL, NULL, NULL, NULL, NULL, NULL, NULL);
  3155. #endif /* COMMENT */
  3156.     initproto(PROTO_Y, "rb","rb", NULL, NULL, NULL, NULL, NULL);
  3157.     initproto(PROTO_G, "rb","rb", NULL, NULL, NULL, NULL, NULL);
  3158.     initproto(PROTO_Z, "rz","rz", NULL, NULL, NULL, NULL, NULL);
  3159.    initproto(PROTO_K,"kermit -ir","kermit -r","kermit -x",NULL,NULL,NULL,NULL);
  3160.     /* Kermit Must be last */
  3161.  
  3162. #else /* XYZMODEM are external protocols ... */
  3163.  
  3164.  /*                  s1      s2     s3    s4      s5         s6      s7     */
  3165.  initproto(PROTO_X, "rx %s","rx %s",NULL,"sx %s","sx -a %s","rx %s", "rx %s");
  3166.  initproto(PROTO_XC,"rc %s","rc %s",NULL,"sx %s","sx -a %s","rc %s", "rc %s");
  3167.  initproto(PROTO_Y, "rb",   "rb",   NULL,"sb %s","sb -a %s","rb",    "rb"   );
  3168.  initproto(PROTO_G, "rb",   "rb",   NULL,"sb %s","sb -a %s","rb",    "rb"   );
  3169.  initproto(PROTO_Z, "rz",   "rz",   NULL,"sz %s","sz -a %s","rz",    "rz"   );
  3170.  initproto(PROTO_K, "kermit -ir","kermit -r","kermit -x",NULL,NULL,NULL,NULL);
  3171.  /* Kermit must be last */
  3172.  
  3173. #endif /* XYZ_INTERNAL */
  3174.  
  3175. #else  /* No XYZMODEM support */
  3176.  
  3177.    initproto(PROTO_K,"kermit -ir","kermit -r","kermit -x",NULL,NULL,NULL,NULL);
  3178.  
  3179. #endif /* CK_XYZ */
  3180. #endif /* NOXFER */
  3181.  
  3182.     connoi();                           /* Console interrupts off */
  3183.  
  3184. #ifndef NOXFER
  3185. #ifdef OS2
  3186.     /* Initialize Kermit and Zmodem Auto-Download Strings */
  3187.     adl_kstr = strdup("KERMIT READY TO SEND...");
  3188.     adl_zstr = strdup("rz\r");
  3189. #endif /* OS2 */
  3190.  
  3191. #ifdef PATTERNS
  3192.     initpat();                          /* Initialize filename patterns */
  3193. #endif /* PATTERNS */
  3194. #endif /* NOXFER */
  3195.  
  3196. #ifndef NOCSETS
  3197.     initcsets();                        /* Initialize character sets */
  3198. #endif /* NOCSETS */
  3199.  
  3200. #ifndef NOICP
  3201. #ifdef DFCDMSG
  3202.     makestr(&cdmsgstr,DFCDMSG);
  3203.     makelist(cdmsgstr,cdmsgfile,8);     /* Initialize CD message filenames */
  3204. #endif /* DFCDMSG */
  3205. #endif /* NOICP */
  3206.  
  3207.     sstate = 0;                         /* No default start state. */
  3208. #ifdef DYNAMIC
  3209.     if (getiobs() < 0)
  3210.       fatal("Can't allocate i/o buffers!");
  3211. #endif /* DYNAMIC */
  3212.  
  3213. #ifndef NOSPL
  3214. #ifndef NORANDOM
  3215.     {
  3216.         char stackdata[256];
  3217.         unsigned int c = 1234, n;
  3218.         /* try to make a random unsigned int to feed srand() */
  3219. #ifndef VMS
  3220.     /* time.h and MultiNet do not get along */
  3221.         c = time(NULL);
  3222. #endif /* VMS */
  3223.         c *= getpid();
  3224.     /* Referenced before set... DELIBERATELY */
  3225.         for (n = 0; n < sizeof(stackdata); n++) /* IGNORE WARNING */
  3226.       c += stackdata[n];        /* DELIBERATELY USED BEFORE SET */
  3227.         srand((unsigned int)c);
  3228.     }
  3229. #endif /* NORANDOM */
  3230. #endif /* NOSPL */
  3231.  
  3232.     ckhost(myhost,MYHOSTL);             /* Name of local host */
  3233.     debug(F110,"main ckhost",myhost,0);
  3234. #ifdef IKSD
  3235.     if (!inserver) {
  3236. #endif /* IKSD */
  3237.         ckstrncpy(ttname,dftty,TTNAMLEN); /* Set up default tty name. */
  3238.         local = nolocal ? 0 : dfloc;    /* And whether it's local or remote. */
  3239.         parity = dfprty;                /* Set initial parity, */
  3240. #ifndef NOXFER
  3241.         myindex = getsysix(cksysid);    /* System index */
  3242. #endif /* NOXFER */
  3243.         if (local) if (ttopen(ttname,&local,0,0) < 0) {
  3244. #ifndef OS2
  3245.             conol("Can't open device: ");
  3246.             conoll(ttname);
  3247. #endif /* OS2 */
  3248.             local = 0;
  3249.             ckstrncpy(ttname,CTTNAM,TTNAMLEN);
  3250.         }
  3251.         setflow();                      /* Set appropriate flow control */
  3252.         speed = ttgspd();               /* Get transmission speed. */
  3253. #ifdef IKSD
  3254.     }
  3255. #endif /* IKSD */
  3256.  
  3257. #ifdef ANYX25                           /* All X.25 implementations */
  3258. #ifndef IBMX25                          /* except IBM have PAD support */
  3259.     initpad();                          /* Initialize X.25 PAD */
  3260. #endif /* IBMX25 */
  3261. #endif /* ANYX25 */
  3262.  
  3263. #ifndef NOXFER
  3264.     if (inibufs(SBSIZ,RBSIZ) < 0)       /* Allocate packet buffers */
  3265.       fatal("Can't allocate packet buffers!");
  3266. #ifndef NOCKSPEED
  3267.     setprefix(prefixing);               /* Set up control char prefixing */
  3268. #endif /* NOCKSPEED */
  3269. #endif /* NOXFER */
  3270.  
  3271. #ifndef NOICP
  3272.     if (sstelnet
  3273. #ifdef IKSD
  3274.         || inserver
  3275. #endif /* IKSD */
  3276.         ) {
  3277.         int on = 1, x = 0;
  3278.         extern int ckxech, ttnet, ttnproto, cmdmsk;
  3279. #ifdef SO_SNDBUF
  3280.         extern int tcp_sendbuf;
  3281. #endif
  3282. #ifdef SO_RCVBUF
  3283.         extern int tcp_recvbuf;
  3284. #endif
  3285. #ifdef SO_KEEPALIVE
  3286.         extern int tcp_keepalive;
  3287. #endif
  3288. #ifdef SO_LINGER
  3289.         extern int tcp_linger, tcp_linger_tmo;
  3290. #endif /* SO_LINGER */
  3291. #ifdef SO_DONTROUTE
  3292.         extern int tcp_dontroute;
  3293. #endif /* SO_DONTROUTE */
  3294. #ifdef TCP_NODELAY
  3295.         extern int tcp_nodelay;
  3296. #endif /* TCP_NODELAY */
  3297. #ifdef IKSD
  3298.         extern int iklogopen;
  3299. #endif /* IKSD */
  3300.         extern int ttmdm;
  3301.  
  3302. #ifdef UNIX
  3303.         if (isatty(0))
  3304.           fatal("Internet Kermit Service cannot be started at a terminal.");
  3305. #endif /* UNIX */
  3306.  
  3307.         reliable = xreliable = SET_ON;  /* IKSD has reliable connection */
  3308. #ifndef VMS
  3309.         flow = 0;                       /* No flow control needed */
  3310. #endif /* VMS */
  3311.         bgset = 0;                      /* Not in background */
  3312.         nopush = 1;                     /* No external processes */
  3313.         parity = 0;                     /* 8 bits ... */
  3314.         cmdmsk = 0xff;                  /* all the way */
  3315.         cmask = 0xff;
  3316.  
  3317. #ifdef IKSD
  3318.         if (inserver) {                 /* If IKSD */
  3319.             doiksdinit();               /* Execute IKSD configuration file */
  3320.             while (tlevel > -1)
  3321.               parser(1);                /* (Ignore any file-xfer commands) */
  3322.             iksdcf = 1;                 /* IKSD c.f. has been processed */
  3323.         }
  3324.         if (!iklogopen) (VOID) doiklog(); /* Open Kermit-specific log */
  3325. #endif /* IKSD */
  3326.  
  3327. #ifdef UNIX
  3328.         setbuf(stdout,NULL);            /* Don't buffer the output */
  3329.         ckstrncpy(ttname,"0",TTNAMLEN); /* not "/dev/tty"... */
  3330. #endif /* UNIX */
  3331.         local = 0;                      /* We are in remote mode */
  3332.         ckxech = 1;                     /* We will echo */
  3333. #ifdef OS2
  3334.         nettype = NET_TCPB;             /* So ttopen() treats the connection */
  3335.         mdmtyp = -nettype;              /* as a network */
  3336. #endif /* OS2 */
  3337.         debug(F100,"main about to call ttopen() inserver","",0);
  3338.         if (ttopen(ttname,&local,mdmtyp,0) < 0) { /* Open comm channel */
  3339.             fatal("can't initialize i/o");
  3340.         }
  3341. #ifdef OS2
  3342.         local = 0;
  3343.         network = 1;                    /* Does use networking code */
  3344. #else  /* OS2 */
  3345.         network = 0;                    /* Does not use networking code */
  3346. #endif /* OS2 */
  3347.         ttmdm = -1;                     /* Does not use a modem */
  3348.         sstelnet = 1;                   /* Do server-side Telnet negotations */
  3349.         debug(F111,"MAIN","sstelnet",sstelnet);
  3350.         ttnet = NET_TCPB;               /* Network type is TCP sockets */
  3351.         ttnproto = NP_TELNET;           /* Netword protocol is Telnet */
  3352. #ifdef IKSDB
  3353.         dbinit();                       /* Initialize database record */
  3354. #endif /* IKSDB */
  3355. #ifndef OS2
  3356. #ifdef CK_AUTHENTICATION
  3357.         /* Before initializating Telnet/Rlogin negotiations, init Kerberos */
  3358.         ck_auth_init(ckgetpeer(),"","",0);
  3359. #endif /* CK_AUTHENTICATION */
  3360.  
  3361. #ifdef NON_BLOCK_IO
  3362.         on = 1;
  3363.         x = socket_ioctl(0,FIONBIO,&on);
  3364.         debug(F101,"main FIONBIO","",x);
  3365. #endif /* NON_BLOCK_IO */
  3366. #ifdef SO_OOBINLINE
  3367.         on = 1;
  3368.         x = setsockopt(0, SOL_SOCKET, SO_OOBINLINE, (char *)&on, sizeof(on));
  3369.         debug(F101,"main SO_OOBINLINE","",x);
  3370. #endif /* SO_OOBINLINE */
  3371.  
  3372. #ifndef NOTCPOPTS
  3373. #ifndef datageneral
  3374. #ifdef SOL_SOCKET
  3375. #ifdef TCP_NODELAY
  3376.         no_delay(0,tcp_nodelay);
  3377. #endif /* TCP_NODELAY */
  3378. #ifdef SO_KEEPALIVE
  3379.         keepalive(0,tcp_keepalive);
  3380. #endif /* SO_KEEPALIVE */
  3381. #ifdef SO_LINGER
  3382.         ck_linger(0,tcp_linger, tcp_linger_tmo);
  3383. #endif /* SO_LINGER */
  3384. #ifdef SO_DONTROUTE
  3385.         dontroute(0,tcp_dontroute);
  3386. #endif /* SO_DONTROUTE */
  3387. #ifdef SO_SNDBUF
  3388.         sendbuf(0,tcp_sendbuf);
  3389. #endif /* SO_SNDBUF */
  3390. #ifdef SO_RCVBUF
  3391.         recvbuf(0,tcp_recvbuf);
  3392. #endif /* SO_RCVBUF */
  3393. #endif /* SOL_SOCKET */
  3394. #endif /* datageneral */
  3395. #endif /* NOTCPOPTS */
  3396.  
  3397. #ifdef CK_SSL
  3398.         if (ck_ssleay_is_installed()) {
  3399.             if (!ssl_tn_init(SSL_SERVER)) {
  3400.                 if (bio_err != NULL) {
  3401.                     BIO_printf(bio_err,"do_ssleay_init() failed\r\n");
  3402.                     ERR_print_errors(bio_err);
  3403.                 } else {
  3404.                     fflush(stderr);
  3405.                     fprintf(stderr,"do_ssleay_init() failed\r\n");
  3406.                     ERR_print_errors_fp(stderr);
  3407.                 }
  3408.                 switch (ttnproto) {
  3409.           case NP_SSL:
  3410.           case NP_TLS:
  3411.             case NP_SSL_RAW:
  3412.           case NP_TLS_RAW:
  3413.           case NP_SSL_TELNET:
  3414.           case NP_TLS_TELNET:
  3415.                     doexit(BAD_EXIT,1);
  3416.                 }
  3417.                 /* otherwise we will continue to accept the connection   */
  3418.                 /* without SSL or TLS support unless required. */
  3419.                 if ( TELOPT_DEF_S_ME_MODE(TELOPT_START_TLS) != TN_NG_MU )
  3420.                     TELOPT_DEF_S_ME_MODE(TELOPT_START_TLS) = TN_NG_RF;
  3421.                 if ( TELOPT_DEF_S_U_MODE(TELOPT_START_TLS) != TN_NG_MU )
  3422.                     TELOPT_DEF_S_U_MODE(TELOPT_START_TLS) = TN_NG_RF;
  3423.                 if ( TELOPT_DEF_C_ME_MODE(TELOPT_START_TLS) != TN_NG_MU )
  3424.                     TELOPT_DEF_C_ME_MODE(TELOPT_START_TLS) = TN_NG_RF;
  3425.                 if ( TELOPT_DEF_C_U_MODE(TELOPT_START_TLS) != TN_NG_MU )
  3426.                     TELOPT_DEF_C_U_MODE(TELOPT_START_TLS) = TN_NG_RF;
  3427.             } else {
  3428.                 if ( ck_ssl_incoming(0) < 0 ) {
  3429.                     doexit(BAD_EXIT,1);
  3430.                 }
  3431.             }
  3432.         }
  3433. #endif /* CK_SSL */
  3434.  
  3435. #ifdef TNCODE
  3436.         tn_ini();                       /* Start Telnet negotiation now */
  3437. #endif /* TNCODE */
  3438. #endif /* OS2 */
  3439.     }
  3440.     debug(F101,"main argc after prescan()","",argc);
  3441.  
  3442.     /* Now process any relevant environment variables */
  3443.  
  3444. #ifndef NODIAL
  3445.     getdialenv();                       /* Dialing */
  3446. #ifdef NETCONN
  3447.     ndinit();                           /* Initialize network directory info */
  3448.     getnetenv();                        /* Network directories */
  3449. #endif /* NETCONN */
  3450. #endif /* NODIAL */
  3451.  
  3452. #ifndef NOXFER
  3453. #ifdef CK_FAST
  3454.     dofast();                           /* By now FAST defaults should be OK */
  3455. #endif /* CK_FAST */
  3456. #endif /* NOXFER */
  3457.  
  3458. #ifndef NOCMDL
  3459.     ikslogin();                          /* IKSD Login and other stuff */
  3460. #ifdef IKSD
  3461. #ifdef NT
  3462.     if ( inserver )
  3463.       setntcreds();
  3464. #endif /* NT */
  3465. #endif /* IKSD */
  3466. #endif /* NOCMDL */
  3467.  
  3468.     if (howcalled == I_AM_SSHSUB) {
  3469.         reliable = 1;            /* We say the connection is reliable */
  3470.         xreliable = 1;            /* And that we said it was */
  3471.         setreliable = 1;        /* And pretend the "user" did too */
  3472.         xfinish = 1;            /* For REMOTE HELP response */
  3473.         mdmtyp = 0;            /* For ttopen() */
  3474.         ckstrncpy(ttname,"0",TTNAMLEN+1);  /* Use file descriptor 0 */
  3475.         local = 0;                         /* And force remote mode */
  3476.         ttopen(ttname,&local,mdmtyp,0); /* Open the "connection" */
  3477.         sstate = 'x';            /* Initial state is Server */
  3478.         proto();            /* Enter protocol */
  3479.         doexit(GOOD_EXIT,xitsta);    /* Exit when done */
  3480.     }
  3481.     debug(F111,"howcalled",myname,howcalled);
  3482.  
  3483. #ifdef NOCCTRAP
  3484.     dotakeini(0);
  3485. #else /* NOCCTRAP */
  3486.     debug(F100,"main about to cc_execute","",0);
  3487.     setint();
  3488.     cc_execute( ckjaddr(cmjbuf), dotakeini, failtakeini );
  3489. #endif /* NOCCTRAP */
  3490.  
  3491.     debug(F111,"main 2 cfilef",cmdfil,cfilef);
  3492.     if (cmdfil[0]) {                    /* If we got one (see prescan())... */
  3493. #ifdef NOCCTRAP
  3494.         docmdfile(0);                   /* execute it. */
  3495. #else /* NOCCTRAP */
  3496.         setint();
  3497.         cc_execute( ckjaddr(cmjbuf), docmdfile, failcmdfile );
  3498. #endif /* NOCCTRAP */
  3499.     }
  3500. #ifndef OS2                             /* Preserve name so we can delete it */
  3501.     *cmdfil = '\0';                     /* Done, nullify the file name */
  3502. #endif /* OS2 */
  3503. #endif /* NOICP */
  3504.  
  3505. #ifndef NOCMDL
  3506. /* Look for a UNIX-style command line... */
  3507.  
  3508.     what = W_NOTHING;
  3509.  
  3510.     debug(F101,"main argc","",argc);
  3511. #ifndef NOHELP
  3512.     iniopthlp();                        /* Initialize cmdline arg help */
  3513. #endif /* NOHELP */
  3514.     if (
  3515. #ifdef COMMENT
  3516.         !cfilef &&
  3517. #endif /* COMMENT */
  3518.         argc > 1) {                     /* Command line arguments? */
  3519.         sstate = (CHAR) cmdlin();       /* Yes, parse. */
  3520. #ifdef NETCONN
  3521. #ifndef NOURL
  3522.         if (haveurl) {                  /* Was a URL given? */
  3523.             dourl();                    /* if so, do it. */
  3524.         }
  3525. #endif /* NOURL */
  3526. #endif /* NETCONN */
  3527. #ifndef NOXFER
  3528.         zstate = sstate;                /* Remember sstate around protocol */
  3529.         debug(F101,"main zstate","",zstate);
  3530. #endif /* NOXFER */
  3531.  
  3532. #ifndef NOLOCAL
  3533.         if (cflg) {                     /* Connect first if requested */
  3534.             doconect(0,0);
  3535.             if (ttchk() < 0)
  3536.               dologend();
  3537.             cflg = 0;
  3538.         }
  3539. #endif /* NOLOCAL */
  3540.  
  3541. #ifndef NOXFER
  3542.         if (sstate) {
  3543. #ifndef NOLOCAL
  3544.             if (displa) concb((char)escape); /* (for console "interrupts") */
  3545. #endif /* NOLOCAL */
  3546. #ifdef NOCCTRAP
  3547.             docmdline(1);
  3548. #else /* NOCCTRAP */
  3549.             setint();
  3550.             cc_execute( ckjaddr(cmjbuf), docmdline, failcmdline );
  3551. #endif /* NOCCTRAP */
  3552.         }
  3553. #endif /* NOXFER */
  3554.  
  3555. #ifndef NOICP
  3556. /*
  3557.   If a command-line action argument was given and -S ("stay") was not given,
  3558.   exit now.
  3559. */
  3560.         if ((cflg || cnflg || zstate) && !stayflg)
  3561. #endif /* NOICP */
  3562.           doexit(GOOD_EXIT,xitsta);     /* Exit with good status */
  3563.  
  3564. #ifndef NOLOCAL
  3565. #ifndef NOICP
  3566.         if (local) {
  3567. #ifdef NETCONN
  3568.             if ((cflg || cnflg) && tn_exit && ttchk() < 0)
  3569.               doexit(GOOD_EXIT,xitsta); /* Exit with good status */
  3570. #endif /* NETCONN */
  3571.             if (exitonclose && !network &&
  3572.                 (carrier != CAR_OFF && (ttgmdm() & BM_DCD) == 0))
  3573.               doexit(GOOD_EXIT,xitsta); /* Exit with good status */
  3574.             if (exitonclose && network && ttchk() < 0)
  3575.               doexit(GOOD_EXIT,xitsta); /* Exit with good status */
  3576.         }
  3577. #endif /* NOICP */
  3578. #endif /* NOLOCAL */
  3579.     }
  3580. #endif /* NOCMDL */
  3581.  
  3582. #ifdef NOICP                            /* No interactive command parser */
  3583. #ifndef NOCMDL
  3584.     else {
  3585.  
  3586.         /* Command-line-only version */
  3587.         fatal("?No command-line options given - type 'kermit -h' for help");
  3588.     }
  3589. #else                                   /* Neither one! */
  3590.         sstate = 'x';
  3591.         justone = 0;
  3592.         proto();                        /* So go into server mode */
  3593.         doexit(GOOD_EXIT,xitsta);       /* exit with good status */
  3594.  
  3595. #endif /* NOCMDL */
  3596. #else /* not NOICP */
  3597. /*
  3598.   If no action requested on command line, or if -S ("stay") was included,
  3599.   enter the interactive command parser.
  3600. */
  3601.     if (!clcmds)
  3602.       herald();                         /* Display program herald. */
  3603.  
  3604. #ifdef NOCCTRAP
  3605.     debug(F100,"main NOCCTRAP setting interrupt trap","",0);
  3606.     setint();                           /* Set up command interrupt traps */
  3607.     doicp(NULL);
  3608. #else /* NOCCTRAP */
  3609.     while (1) {
  3610.         debug(F100,"main setting interrupt trap","",0);
  3611.         setint();                       /* Set up command interrupt traps */
  3612.         if (!cc_execute(ckjaddr(cmjbuf), doicp, failicp))
  3613.           break;
  3614.     }
  3615. #endif /* NOCCTRAP */
  3616. #endif /* NOICP */
  3617. #ifndef MAINISVOID
  3618.     return(1);
  3619. #endif /* MAINISVOID */
  3620. }
  3621.  
  3622. #ifdef DYNAMIC
  3623. /* Allocate file i/o buffers */
  3624.  
  3625. char *zinbuffer = NULL, *zoutbuffer = NULL;
  3626.  
  3627. int
  3628. getiobs() {
  3629.     zinbuffer = (char *)malloc(INBUFSIZE);
  3630.     if (!zinbuffer) return(-1);
  3631.     zoutbuffer = (char *)malloc(zobufsize);
  3632.     debug(F101,"zoutbuffer malloc","",zobufsize);
  3633.     if (!zoutbuffer) return(-1);
  3634.     debug(F100,"getiobs ok","",0);
  3635.     return(0);
  3636. }
  3637. #endif /* DYNAMIC */
  3638.