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