home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / ckv206.zip / ckcmai.c < prev    next >
C/C++ Source or Header  |  2002-10-27  |  129KB  |  3,552 lines

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