home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / k95source / ckcmai.c < prev    next >
C/C++ Source or Header  |  2020-01-01  |  122KB  |  3,527 lines

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