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