home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / cku201.zip / ckcmai.c < prev    next >
C/C++ Source or Header  |  2002-02-09  |  125KB  |  3,453 lines

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