1 #define EDITDATE "21 Jun 2011" /* Last edit date dd mmm yyyy */
2 #define EDITNDATE "20110621" /* Keep them in sync */
3 /* Tue Jun 21 11:32:48 2011 */
5 /* ckcmai.c - Main program for C-Kermit plus some miscellaneous functions */
8 ckcsym.h is used for for defining symbols that normally would be defined
9 using -D or -d on the cc command line, for use with compilers that don't
10 support this feature. Must come before any tests for preprocessor symbols.
14 Consolidated program C-Kermit version information for all platforms
15 (but for UNIX also see ckuver.h). See makever() below for how they are used.
17 #ifdef COMMENT /* Uncomment this for real K95 version */
18 #ifndef OS2 /* OS2 actually means Kermit 95. */
19 #ifndef BETATEST /* It's because Kermit 95 started */
20 #define BETATEST /* out as C-Kermit for OS/2. */
33 char * ck_cryear = "2011"; /* C-Kermit copyright year */
35 #ifndef MAC /* MAC = Kermit for MAC OS 6, 7, ... */
37 Note: initialize ck_s_test to "" if this is not a test version.
38 Use (*ck_s_test != '\0') to decide whether to print test-related messages.
42 #ifndef OS2 /* UNIX, VMS, etc... (i.e. C-Kermit) */
43 char *ck_s_test = "Beta"; /* "Dev","Alpha","Beta","RC", or "" */
44 char *ck_s_tver = "02"; /* Test version number or "" */
46 char *ck_s_test = ""; /* (i.e. K95) */
50 char *ck_s_test = ""; /* Development */
54 char *ck_s_test = "Pre-Alpha"; /* Mac Kermit is always a test... */
55 char *ck_s_tver = ""; /* (pre Mac OS X 10, that is!) */
58 #ifdef BETADATE /* Date of this version or edit */
59 char *ck_s_date = __DATE__; /* Compilation date */
61 char *ck_s_date = EDITDATE; /* See top */
64 char *buildid = EDITNDATE; /* See top */
67 static char sccsid[] = "@(#)C-Kermit 9.0.299";
70 char *ck_s_ver = "9.0.299"; /* C-Kermit version string */
71 long ck_l_ver = 900299L; /* C-Kermit version number */
74 char *ck_s_xver = "3.0.0"; /* Product-specific version string */
75 long ck_l_xver = 3000L; /* Product-specific version number */
78 char *ck_s_xver = "0.995"; /* Product-specific version string */
79 long ck_l_xver = 995L; /* Product-specific version number */
81 char *ck_s_xver = ""; /* Don't touch these... */
82 long ck_l_xver = 0L; /* they are computed at runtime */
89 char *ck_s_name = "IKS-NT";
91 char *ck_s_name = "IKS-OS/2";
94 char *ck_s_name = "Kermit 95"; /* Program name */
98 char *ck_s_name = "Mac Kermit";
100 char *ck_s_name = "C-Kermit";
104 char *ck_s_who = ""; /* Where customized, "" = not. */
105 char *ck_patch = ""; /* Patch info, if any. */
108 char versiox[CKVERLEN]; /* Version string buffer */
109 char *versio = versiox; /* These are filled in at */
110 long vernum, xvernum; /* runtime from above. */
114 #include "ckcasc.h" /* ASCII character symbols */
115 #include "ckcdeb.h" /* Debug & other symbols */
117 char * myname = NULL; /* The name I am called by */
119 char * exedir = NULL; /* Directory I was executed from */
121 char * myhome = NULL; /* Home directory override */
123 /* C K C M A I -- C-Kermit Main program */
126 Author: Frank da Cruz (fdc@columbia.edu),
127 Columbia University in the city of New York,
128 Computer Center / Center for Computing Activities / Information Technology.
129 I am no longer at Columbia U as of 1 July 2011, but the email address
130 should still work. The Kermit website http://kermit.columbia.edu should
131 still be available and under my control, as well as the Kermit FTP site,
132 ftp://kermit.columbia.edu/kermit/.
137 char *copyright[] = {
140 "Copyright (C) 1985, %s, Trustees of Columbia University, NYC.",
141 "All rights reserved.",
144 "Copyright (C) 1985, %s,",
145 " The Trustees of Columbia University in the City of New York.",
146 " All rights reserved.",
148 "Redistribution and use in source and binary forms, with or without",
149 "modification, are permitted provided that the following conditions",
152 " + Redistributions of source code must retain the above copyright",
153 " notice, this list of conditions and the following disclaimer.",
155 " + Redistributions in binary form must reproduce the above copyright",
156 " notice, this list of conditions and the following disclaimer in",
157 " the documentation and/or other materials provided with the",
160 " + Neither the name of the <ORGANIZATION> nor the names of its",
161 " contributors may be used to endorse or promote products derived",
162 " from this software without specific prior written permission.",
164 "THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS",
165 "\"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT",
166 "LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR",
167 "A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT",
168 "HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,",
169 "SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT",
170 "LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,",
171 "DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY",
172 "THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT",
173 "(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE",
174 "OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.",
178 "Portions Copyright (C) 2002-2005, Secure Endpoints Inc, New York NY USA.",
179 "Portions Copyright (C) 1995, Oy Online Solutions Ltd., Jyvaskyla, Finland.",
182 #ifdef CK_AUTHENTICATION
183 "Portions Copyright (C) 1990, Massachusetts Institute of Technology.",
185 "Portions Copyright (C) 1991, 1993 Regents of the University of California.",
186 "Portions Copyright (C) 1991, 1992, 1993, 1994, 1995 by AT&T.",
187 "Portions Copyright (C) 1995, 1997, Eric Young <eay@cryptosoft.com>.",
188 #endif /* CK_ENCRYPTION */
190 "Portions Copyright (C) 1997, Stanford University.",
192 #endif /* CK_AUTHENTICATION */
196 "For further information, visit the Kermit Project website:",
197 "http://www.columbia.edu/kermit/ .",
201 /* Windows IKSD copyright used to be separate */
202 char *wiksdcpr = (char *) copyright;
208 "Using C-Kermit" by Frank da Cruz and Christine M. Gianone,
209 Digital Press / Butterworth-Heinemann, Woburn MA, USA.
210 Second edition (1997), ISBN 1-55558-164-1.
211 Order from Digital Press: +1 (800) 366-2665
212 Or from Columbia University: +1 (212) 854-3703
216 "Kermit 95" by Christine M. Gianone and Frank da Cruz,
217 Manning Publications, Greenwich CT, USA (1998) - Online.
221 The Kermit file transfer protocol was developed at the Columbia University
222 Center for Computing Activities (CUCCA), which was since renamed to Columbia
223 University Academic Information Systems (AcIS) and after that Columbia
224 University Information Technology (CUIT). Kermit is named after Kermit the
225 Frog, star of the television series THE MUPPET SHOW; the name is used by
226 permission of Henson Associates, Inc.
228 Thanks to at least the following people for their contributions to this
229 program over the years, and apologies to anyone who was inadvertantly
232 Chris Adie, Edinburgh U, Scotland (OS/2)
233 Robert Adsett, University of Waterloo, Canada
234 Larry Afrin, Clemson U
235 Russ Allbery, Stanford U
236 Jeffrey Altman, Columbia University
237 Greg Andrews, Telebit Corp
238 Barry Archer, U of Missouri
239 Robert Andersson, International Systems A/S, Oslo, Norway
240 Chris Armstrong, Brookhaven National Lab (OS/2)
241 William Bader, Software Consulting Services, Nazareth, PA
242 Fuat Baran, Columbia U
244 Jim Barbour, U of Colorado
245 Donn Baumgartner, Dell
246 Ian Beckwith, Debian Project
247 Nelson Beebe, U of Utah
248 Gerry Belanger, Cognitronics
251 Dean W Bettinger, SUNY
253 Peter Binderup, Denmark
254 David Bolen, Advanced Networks and Services, Inc.
256 Marc Boucher, U of Montreal
261 Jack Bryans, California State U at Long Beach
263 Fernando Cabral, Padrao iX, Brasilia
264 Bjorn Carlsson, Stockholm University Computer Centre QZ, Sweden
265 Bill Catchings, (formerly of) Columbia U
266 Bob Cattani, Columbia U CS Dept
267 Davide Cervone, Rochester U
268 Seth Chaiklin, Denmark
269 John Chandler, Harvard U / Smithsonian Astronomical Observatory
271 Andrew A Chernov, RELCOM Team, Moscow
272 John L Chmielewski, AT&T, Lisle, IL
273 Howard Chu, U of Michigan
274 Bill Coalson, McDonnell Douglas
275 Bertie Coopersmith, London
277 Chet Creider, U of Western Ontario
278 Alan Crosswell, Columbia U
279 Jeff Damens, (formerly of) Columbia U
280 Mark Davies, Bath U, UK
281 Sin-itirou Dezawa, Fujifilm, Japan
282 Joe R. Doupnik, Utah State U
283 Frank Dreano, Honeywell
284 John Dunlap, U of Washington
285 Alex Dupuy, SMART.COM
286 David Dyck, John Fluke Mfg Co.
287 Stefaan A. Eeckels, Eurokom, Luxembourg
289 Paul Eggert, Twin Sun, Inc., El Segundo, CA
291 Peter Eichhorn, Assyst International
292 Kristoffer Eriksson, Peridot Konsult AB, Oerebro, Sweden
293 John R. Evans, IRS, Kansas City
294 Glenn Everhart, RCA Labs
295 Charlie Finan, Cray Research
296 Herm Fischer, Encino, CA (extensive contributions to version 4.0)
297 Carl Fongheiser, CWRU
298 Mike Freeman, Bonneville Power Authority
300 Marcello Frutig, Catholic University, Sao Paulo, Brazil (X.25 support)
301 Hirofumi Fujii, Japan Nat'l Lab for High Energy Physics, Tokyo (Kanji)
302 Chuck Fuller, Westinghouse Corporate Computer Services
304 Christine M. Gianone, Columbia U
305 John Gilmore, UC Berkeley
306 Madhusudan Giyyarpuram, HP
307 Rainer Glaschick, Siemens AG, Paderborn
309 German Goldszmidt, IBM
311 Alistair Gorman, New Zealand
312 Richard Gration, ADFA, Australia
313 Chris Green, Essex U, UK
314 Alan Grieg, Dundee Tech, Scotland
316 Jim Guyton, Rand Corp
320 Marion Hakanson, ORST
322 John Hamilston, Iowa State U
323 Simon Hania, Netherlands
326 Eugenia Harris, Data General (AOS/VS)
327 David Harrison, Kingston Warren Corp
328 Lucas Hart, Oregon State University
329 James Harvey, Indiana/Purdue U (VMS)
331 Chuck Hedrick, Rutgers U
332 Ron Heiby, Technical Systems Division, Motorola Computer Group
333 Steve Hemminger, Tektronix
334 Christian Hemsing, RWTH Aachen, Germany (OS-9)
335 Randolph Herber, US DOE,
336 Andrew Herbert, Monash Univ, Australia
337 Marcus Herbert, Germany
339 Dan Hildebrand, QNX Software Systems Inc, Kanata, ON (QNX)
341 Stephan Hoffman-Emden
342 Sven Holmstrom, ABB Utilities AB, Sweden
343 Bill Homer, Cray Research
344 Ray Hunter, The Wollongong Group
345 Randy Huntziger, National Library of Medicine
346 Larry Jacobs, Transarc
347 Steve Jenkins, Lancaster University, UK
348 Dave Johnson, Gradient Technologies
349 Mark B Johnson, Apple Computer
350 Jyke Jokinen, Tampere University of Technology, Finland (QNX)
353 Peter Jones, U of Quebec Montreal
354 Phil Julian, SAS Institute
355 Peter Kabal, U of Quebec
356 Mic Kaczmarczik, U of Texas at Austin
357 Sergey Kartashoff, Inst. of Precise Mechanics & Computer Equipment, Moscow
358 Howie Kaye, Columbia U
359 Rob Kedoin, Linotype Co, Hauppauge, NY (OS/2)
362 Terry Kennedy, St Peter's College, Jersey City, NJ (VMS and more)
363 "Carlo Kid", Technical University of Delft, Netherlands
365 Paul Kimoto, Cornell U
366 Douglas Kingston, morgan.com
367 Lawrence Kirby, Wiltshire, UK
368 Tom Kloos, Sequent Computer Systems
370 Jim Knutson, U of Texas at Austin
372 Scott Kramer, SRI International, Menlo Park, CA
373 John Kraynack, US Postal Service
374 David Kricker, Encore Computer
376 Bo Kullmar, ABC Klubben, Stockholm, and Central Bank of Sweden, Kista
377 R. Brad Kummer, AT&T Bell Labs, Atlanta, GA
378 John Kunze, UC Berkeley
379 David Lane, BSSI / BellSouth (Stratus VOS, X.25)
380 Bob Larson, USC (OS-9)
381 Bert Laverman, Groningen U, Netherlands
383 David Lawyer, UC Irvine
385 David LeVine, National Semiconductor Corporation
386 Daniel S. Lewart, UIUC
388 Tor Lillqvist, Helsinki U, Finland
389 David-Michael Lincke, U of St Gallen, Switzerland
390 Robert Lipe (for SCO makefile entries & advice)
392 Mike Long, Analog Devices, Norwood MA
393 Kevin Lowey, U of Saskatchewan (OS/2)
394 Andy Lowry, Columbia U
395 James Lummel, Caprica Telecomputing Resources (QNX)
397 David MacKenzie, Environmental Defense Fund, U of Maryland
398 John Mackin, University of Sidney, Australia
399 Martin Maclaren, Bath U, UK
400 Chris Maio, Columbia U CS Dept
401 Montserrat Mane, HP, Grenoble, France
402 Fulvio Marino, Olivetti, Ivrea, Italy
403 Arthur Marsh, dircsa.org.au
404 Peter Mauzey, Lucent Technologies
405 Tye McQueen, Utah State U
407 Hellmuth Michaelis, Hanseatischer Computerservice GmbH, Hamburg, Germany
408 Leslie Mikesell, American Farm Bureau
409 Todd Miller, Courtesan Consulting
411 Martin Minow, DEC (VMS)
412 Pawan Misra, Bellcore
413 Ken Mizialko, IBM, Manassas, VA
414 Wolfgang Moeller, DECUS Germany
416 Bruce J Moore, Allen-Bradley Co, Highland Heights, OH (Atari ST)
418 Peter Mossel, Columbia U
420 Lou Muccioli, Swanson Analysis Systems
422 Neal P. Murphy, Harsof Systems, Wonder Lake IL
425 Jack Nelson, U of Pittsburgh
426 Jim Noble, Planning Research Corporation (Macintosh)
427 Ian O'Brien, Bath U, UK
430 Thomas Pinkl, Health Business Systems Inc.
431 Michael Pins, Iowa Computer Aided Engineering Network
432 Andre' Pirard, University of Liege, Belgium
433 Paul Placeway, Ohio State U
434 Piet W. Plomp, ICCE, Groningen University, Netherlands
436 Manfred Prange, Oakland U
437 Christopher Pratt, APV Baker, UK
439 Tony Querubin, U of Hawaii
444 Alan Robiette, Oxford University, UK
445 Michel Robitaille, U of Montreal (Mac)
446 Huw Rogers, Schweizerische Kreditanstalt, Zuerich
447 Nigel Roles, Cambridge, England
448 Kai Uwe Rommel, Technische Universitaet Muenchen (OS/2)
449 Larry Rosenman (Amiga)
450 Jay Rouman, U of Michigan
451 Jack Rouse, SAS Institute (Data General and/or Apollo)
452 Stew Rubenstein, Harvard U (VMS)
453 Gerhard Rueckle, FH Darmstadt, Fb. E/Automatisierungstechnik
455 Bill Schilit, Columbia U
456 Ulli Schlueter, RWTH Aachen, Germany (OS-9, etc)
457 Michael Schmidt, U of Paderborn, Germany
458 Eric Schnoebelen, Convex
460 Dan Schullman, DEC (modems, DIAL command, etc)
462 Steven Schultz, Contel (PDP-11)
464 APPP Scorer, Leeds Polytechnic, UK
465 Gordon Scott, Micro Focus, Newbury UK
466 Gisbert W. Selke, WIdO, Bonn, Germany
468 David Singer, IBM Almaden Research Labs
469 David Sizeland, U of London Medical School
470 Fridrik Skulason, Iceland
474 Fred Smith, Merk / Computrition
475 Richard S Smith, Cal State
477 Bertil Stenstroem, Stockholm University Computer Centre (QZ), Sweden
478 James Sturdevant, CAP GEMENI AMERICA, Minneapolis
479 Peter Svanberg, Royal Techn. HS, Sweden
480 James R. Swenson, Accu-Weather, Inc.
481 Ted T'so, MIT (Linux)
482 Andy Tanenbaum, Vrije U, Amsterdam, Netherlands
483 Seth Theriault, Columbia U
485 Markku Toijala, Helsinki U of Technology
486 Teemu Torma, Helsinki U of Technology
487 Linus Torvalds, Helsinki
489 Warren Tucker, Tridom Corp, Mountain Park, GA
490 Dave Tweten, AMES-NAS
492 Walter Underwood, Ford Aerospace
493 Pieter Van Der Linden, Centre Mondial, Paris
494 Ge van Geldorp, Netherlands
495 Fred van Kempen, MINIX User Group, Voorhout, Netherlands
496 Wayne Van Pelt, GE/CRD
497 Mark Vasoll, Oklahoma State U (V7 UNIX)
498 Konstantin Vinogradov, ICSTI, Moscow
500 Bernie Volz, Process Software
501 Eduard Vopicka, Prague University of Economics, Czech Republic
504 Roger Wallace, Raytheon
505 Stephen Walton, Calif State U, Northridge (Amiga)
506 Jamie Watson, Adasoft, Switzerland (AIX)
507 Rick Watson, U of Texas (Macintosh)
508 Eric Weaver, Columbia U
509 Scott Weikart (Association for Progressive Communications)
510 Robert Weiner, Programming Plus, New York City
511 Lauren Weinstein, Vortex Technlogy
512 David Wexelblat, AT&T
513 Clark Wierda, Illuminati Online
514 Joachim Wiesel, U of Karlsruhe
515 Lon Willett, U of Utah
516 Michael Williams, UCLA
517 Nate Williams, U of Montana
519 Joellen Windsor, U of Arizona
520 Patrick Wolfe, Kuck & Associates, Inc.
521 Gregg Wonderly, Oklahoma State U (V7 UNIX)
522 Farrell Woods, Concurrent (formerly Masscomp)
523 Dave Woolley, CAP Communication Systems, London
524 Jack Woolley, SCT Corp
526 Ken Yap, formerly of U of Rochester
527 John Zeeff, Ann Arbor, MI
530 #include "ckcker.h" /* Kermit symbols */
531 #include "ckcnet.h" /* Network symbols */
542 #define INCL_VIO /* Needed for ckocon.h */
554 /* Text message definitions.. each should be 256 chars long, or less. */
556 char *srvtxt = "\r\n\
557 Entering server mode.\r\n\0";
561 It seems there was a large installation that was using C-Kermit 5A(165)
562 or thereabouts, which had deployed thousands of MS-DOS Kermit scripts in
563 scattered locations that looked for strings in the old server message,
564 which changed in 5A(183), August 1992.
566 char *srvtxt = "\r\n\
567 C-Kermit server starting. Return to your local machine by typing\r\n\
568 its escape sequence for closing the connection, and issue further\r\n\
569 commands from there. To shut down the C-Kermit server, issue the\r\n\
570 FINISH or BYE command and then reconnect.\n\
574 char *srvtxt = "\r\012\
575 Entering server mode. If your local Kermit software is menu driven, use\r\012\
576 the menus to send commands to the server. Otherwise, enter the escape\r\012\
577 sequence to return to your local Kermit prompt and issue commands from\r\012\
578 there. Use SEND and GET for file transfer. Use REMOTE HELP for a list of\r\012\
579 other available services. Use BYE or FINISH to end server mode.\r\012\0";
580 #else /* UNIX, VMS, AOS/VS, and all others */
581 char *srvtxt = "\r\n\
582 Entering server mode. If your local Kermit software is menu driven, use\r\n\
583 the menus to send commands to the server. Otherwise, enter the escape\r\n\
584 sequence to return to your local Kermit prompt and issue commands from\r\n\
585 there. Use SEND and GET for file transfer. Use REMOTE HELP for a list of\r\n\
586 other available services. Use BYE or FINISH to end server mode.\r\n\0";
590 #else /* server mode disabled */
592 #endif /* NOSERVER */
594 int initflg = 0; /* sysinit() has executed... */
595 int howcalled = I_AM_KERMIT; /* How I was called */
597 int quitting = 0; /* I'm in the act of quitting */
600 char * iksdconf = IKSDCONF; /* IKSD configuration file */
601 int iksdcf = 0; /* Has IKSD c.f. been processed? */
602 #endif /* IKSDCONF */
604 int srvcdmsg = 0; /* [Server] CD message */
605 char * cdmsgfile[8] = { NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL };
606 char * cdmsgstr = NULL;
607 char * ckcdpath = NULL;
609 #ifdef NLCHAR /* Text-file line terminator */
615 int fblksiz = DBLKSIZ; /* File blocksize */
616 int frecl = DLRECL; /* File record length */
617 int frecfm = XYFF_S; /* File record format (default = stream) */
618 int forg = XYFO_S; /* File organization (sequential) */
619 int fcctrl = XYFP_N; /* File carriage control (ctrl chars) */
620 int filecase = FILECASE; /* Case matters in filenames */
621 int stathack = 1; /* Fast directory lookups by default */
623 char uidbuf[UIDBUFLEN] = { NUL, NUL }; /* User ID buffer */
624 int cfilef = 0; /* Application ("kerbang") file flag */
625 char cmdfil[CKMAXPATH + 1] = { NUL, NUL }; /* Application file name */
626 int haveurl = 0; /* URL given on command line */
629 /* Multi-protocol support */
631 struct ck_p ptab[NPROTOS] = { /* Initialize the Kermit part ... */
633 DRPSIZ, /* Receive packet size */
634 DSPSIZ, /* Send packet size */
635 0, /* Send-packet-size-set flag */
636 DFWSIZ, /* Window size */
639 PX_CAU, /* Control char unprefixing... */
642 #endif /* NEWDEFAULTS */
644 #ifdef VMS /* Default filename collision action */
645 XYFX_X, /* REPLACE for VAX/VMS */
647 XYFX_B, /* BACKUP for everybody else */
650 #ifdef OS2 /* Flag for file name conversion */
651 XYFN_L, /* Literal for OS2 */
653 XYFN_C, /* Converted for others */
656 PATH_OFF, /* Send pathnames OFF */
657 PATH_AUTO, /* Receive pathnames AUTO */
658 NULL, /* Host receive initiation string (binary) */
659 NULL, /* Host receive initiation string (text) */
660 NULL, /* Host server string */
661 NULL, /* External protocol send command (binary) */
662 NULL, /* External protocol send command (text) */
663 NULL, /* External protocol receive command (bin) */
664 NULL } /* External protocol receive command (txt) */
667 {"XMODEM", 128,128,-1,-1, 1,-1,-1,0,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL},
668 {"XMODEM-CRC",128,128,-1,-1, -1,-1,-1,0,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL},
669 {"YMODEM", -1, -1,-1,-1, -1,-1,-1,0,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL},
670 {"YMODEM-g", -1, -1,-1,-1, -1,-1,-1,0,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL},
671 {"ZMODEM", -1, -1,-1,-1,PX_WIL,-1,-1,0,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL},
672 {"Other", -1, -1,-1,-1, -1,-1,-1,0,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL}
676 /* Declarations for Send-Init Parameters */
678 int spsiz = DSPSIZ, /* Current packet size to send */
679 spmax = DSPSIZ, /* Biggest packet size we can send */
680 lastspmax = DSPSIZ, /* Send-packet size last used */
681 spsizr = DSPSIZ, /* Send-packet size requested */
682 spsizf = 0, /* Flag to override size negotiation */
683 rpsiz = DRPSIZ, /* Biggest we want to receive */
684 urpsiz = DRPSIZ, /* User-requested receive pkt size */
685 maxrps = MAXRP, /* Maximum incoming long packet size */
686 maxsps = MAXSP, /* Maximum outbound l.p. size */
687 maxtry = MAXTRY, /* Maximum retries per packet */
688 wslots = 1, /* Window size currently in use */
689 wslotr = DFWSIZ, /* Window size from SET WINDOW */
690 wslotn = 1, /* Window size negotiated in S-pkt */
691 timeouts = 0, /* For statistics reporting */
692 spackets = 0, /* ... */
693 rpackets = 0, /* ... */
694 retrans = 0, /* ... */
695 crunched = 0, /* ... */
698 srvidl = 0, /* Server idle timeout */
699 srvdis = 1, /* Server file xfer display */
700 srvtim = DSRVTIM, /* Server command wait timeout */
701 srvping = 1, /* Server keepalive */
703 timint is the timeout interval I use when waiting for a packet.
704 pkttim is the SET RECEIVE TIMEOUT value, sent to the other Kermit.
705 rtimo is the SET SEND TIMEOUT value. rtimo is the initial value of
706 timint. timint is changed by the value in the incoming negotiation
707 packet unless a SET SEND TIMEOUT command was given.
709 timint = DMYTIM, /* Timeout interval I use */
710 pkttim = URTIME, /* Timeout I want you to use */
711 rtimo = DMYTIM, /* Normal packet wait timeout */
712 timef = 0, /* Flag to override what you ask */
714 rttflg = 1, /* Use dynamic round-trip timers */
716 rttflg = 0, /* Use fixed timer */
717 #endif /* CK_TIMERS */
718 mintime = 1, /* Minimum timeout */
719 maxtime = 0, /* Maximum timeout */
721 npad = MYPADN, /* How much padding to send */
722 mypadn = MYPADN, /* How much padding to ask for */
723 bctr = DFBCT, /* Block check type requested */
724 bctu = 1, /* Block check type used */
725 bctl = 1, /* Block check length */
726 bctf = 0, /* Block check type 3 forced on all */
727 c_save = -1, /* Block check saving and restoring */
728 ss_save = -1, /* Slow-start saving and restoring */
729 ebq = MYEBQ, /* 8th bit prefix */
730 ebqflg = 0, /* 8th-bit quoting flag */
731 rqf = -1, /* Flag used in 8bq negotiation */
732 rq = 0, /* Received 8bq bid */
733 sq = 'Y', /* Sent 8bq bid */
734 rpt = 0, /* Repeat count */
735 rptq = MYRPTQ, /* Repeat prefix */
736 rptflg = 0, /* Repeat processing flag */
737 rptena = 1, /* Repeat processing enabled */
738 xfrcan = 1, /* Transfer cancellation enabled */
739 xfrint = 1, /* Transfer interruption enabled */
740 xfrchr = 3, /* Transfer cancel char = Ctrl-C */
741 xfrnum = 3, /* Need three of them by default */
743 char * xfrmsg = NULL; /* Message for f.t. display screen */
747 int xfrxla = 0; /* Character-set translation */
749 int xfrxla = 1; /* enabled or disabled */
752 int havelfs = 0; /* Large file support available */
755 int epktflg = 0; /* E-PACKET command active */
757 int capas = 9, /* Position of Capabilities */
758 lpcapb = 2, /* Long Packet capability */
759 lpcapr = 1, /* requested */
760 lpcapu = 0, /* used */
761 swcapb = 4, /* Sliding Window capability */
762 swcapr = 1, /* requested (allowed) */
763 swcapu = 0, /* used */
764 atcapb = 8, /* Attribute capability */
765 atcapr = 1, /* requested */
766 atcapu = 0, /* used */
767 rscapb = 16, /* RESEND capability */
768 rscapr = 1, /* requested by default */
769 rscapu = 0, /* used */
770 lscapb = 32, /* Locking Shift capability */
771 lscapr = 1, /* requested by default */
772 lscapu = 0; /* used */
774 /* Flags for whether to use particular attributes */
776 int atenci = 1, /* Encoding in */
777 atenco = 1, /* Encoding out */
778 atdati = 1, /* Date in */
779 atdato = 1, /* Date out */
780 atdisi = 1, /* Disposition in/out */
782 atleni = 1, /* Length in/out (both kinds) */
784 atblki = 1, /* Blocksize in/out */
786 attypi = 1, /* File type in/out */
788 atsidi = 1, /* System ID in/out */
790 atsysi = 1, /* System-dependent parameters in/out */
793 int dispos = 0; /* Disposition */
800 #endif /* CK_PERMS */
802 int atfrmi = 1, /* Record Format in/out */
806 int atcrei = 1, /* Creator ID in/out */
808 atacti = 1, /* Account in/out */
812 int sprmlen = -1; /* Send/Receive protocol parameter */
813 int rprmlen = -1; /* string length limits */
814 int sendipkts = 1; /* Send I packets */
816 CHAR padch = MYPADC, /* Padding character to send */
817 mypadc = MYPADC, /* Padding character to ask for */
818 seol = MYEOL, /* End-Of-Line character to send */
819 eol = MYEOL, /* End-Of-Line character to look for */
820 ctlq = CTLQ, /* Control prefix in incoming data */
821 myctlq = CTLQ, /* Outbound control character prefix */
822 myrptq = MYRPTQ; /* Repeat prefix I want to use */
824 int rptmin = 3; /* Repeat-count minimum */
826 int usepipes = 0, /* Used for xfer to/from pipes */
829 char * filefile = NULL; /* File containing list of filenames */
830 /* CD message filename list */
832 char whoareu[16] = { NUL, NUL }; /* System ID of other Kermit */
833 int sysindex = -1; /* and index to its system ID struct */
835 int wearealike = 0; /* 2 Kermits have compatible sysids */
836 char * cksysid = /* My system ID */
871 #endif /* datageneral */
880 int oopts = -1; /* O-Packet Options */
881 int omode = -1; /* O-Packet Transfer Mode */
882 int oname = -1; /* O-Packet Filename Options */
883 int opath = -1; /* O-Packet Pathname Options */
885 struct zattr iattr; /* Incoming file attributes */
888 /* VMS labeled file default options - name only. */
889 int lf_opts = LBL_NAM;
892 /* OS/2 labeled file default options, all attributes but archived. */
893 unsigned long int lf_opts = LBL_EXT|LBL_HID|LBL_RO|LBL_SYS;
899 /* Packet-related variables */
901 int pktnum = 0, /* Current packet number */
902 sndtyp = 0, /* Type of packet just sent */
903 rcvtyp = 0, /* Type of packet just received */
904 rsn, /* Received packet sequence number */
905 rln, /* Received packet length */
906 size, /* Current size of output pkt data */
907 osize, /* Previous output packet data size */
908 maxsize, /* Max size for building data field */
909 spktl = 0, /* Length packet being sent */
910 rpktl = 0, /* Length of packet just received */
911 pktpaus = 0, /* Interpacket pause interval, msec */
912 rprintf, /* REMOTE PRINT flag */
913 rmailf, /* MAIL flag */
914 xferstat = -1, /* Status of last transaction */
915 filestatus = 0; /* Status of last file transfer */
917 CHAR pktmsgbuf[PKTMSGLEN+1];
918 CHAR *epktmsg = pktmsgbuf;
921 int srvcmdlen = MAXRP; /* srvcmd buffer length */
924 int srvcmdlen = MAXRP;
936 *srvcmd = (CHAR *)0, /* Where to decode server command */
942 padbuf[96], /* Buffer for send-padding */
944 *rdatap, /* Pointer to received packet data */
945 *data = (CHAR *)0, /* Pointer to send-packet data */
946 *srvptr, /* Pointer to srvcmd */
947 mystch = SOH, /* Outbound packet-start character */
948 stchr = SOH; /* Incoming packet-start character */
950 /* File-related variables */
952 #ifndef NOMSEND /* Multiple SEND */
953 struct filelist * filehead = NULL; /* SEND list */
954 struct filelist * filetail = NULL;
955 struct filelist * filenext = NULL;
959 char filnam[CKMAXPATH + 1]; /* Name of current file. */
960 char ofilnam[CKMAXPATH + 1]; /* Original name. */
962 int pipesend = 0; /* Nonzero if sending from pipe */
964 char * sndfilter = NULL; /* Send and receive filters */
965 char * rcvfilter = NULL;
966 #endif /* PIPESEND */
968 char ** sndarray = NULL; /* SEND /ARRAY pointer and range */
970 int sndxlo = -1, sndxhi = -1, sndxin = -1;
975 int ngetpath = 0; /* GET search path */
977 char * getpath[MAXGETPATH];
978 char * x_user = NULL; /* Server login information */
979 char * x_passwd = NULL;
980 char * x_acct = NULL;
981 #endif /* NOSERVER */
983 int x_login = 0; /* Login required */
984 int x_logged = 0; /* User is logged in */
986 extern int timelimit;
989 int logintimo = 300; /* Login timeout */
990 char * userfile = NULL; /* Forbidden user file */
991 #endif /* CK_LOGIN */
993 char * anonfile = NULL; /* Anonymous login init file */
994 char * anonroot = NULL; /* Anonymous file-system root */
995 int iks_timo = 300; /* 5 minutes idle timo */
996 int iks_retry = 3; /* 3 attempts at login */
1000 extern VOID zsyslog();
1001 extern int ckxlogging, ckxsyslog;
1002 #endif /* CKSYSLOG */
1004 CK_OFF_T fsize = (CK_OFF_T)0, /* Size of current file */
1005 sendstart = (CK_OFF_T)0, /* SEND start position */
1006 calibrate = (CK_OFF_T)0; /* Nonzero if calibration run */
1008 int nzxopts = 0; /* Options for nzxpand() */
1009 int nfils = 0; /* Number of files in file group */
1010 int wildena = 1; /* Wildcard expansion enabled */
1012 int wildxpand = 0; /* Who expands wildcards, 0=Kermit.. */
1015 int wildxpand = 1; /* 1=Shell. */
1016 #endif /* STRATUS */
1019 int matchdot = 0; /* Whether to match dot files */
1022 #endif /* UNIXOROSK */
1023 int matchfifo = 0; /* Whether to match FIFO "files" */
1024 int clfils = 0; /* Flag for command-line files */
1025 int stayflg = 0; /* Flag for "stay", i.e. "-S" */
1026 int xfinish = 0; /* Flag for FINISH = EXIT */
1027 long ztusec = -1L; /* Used with ztime() */
1028 long ztmsec = -1L; /* Ditto */
1030 /* Communication device / connection variables */
1032 char ttname[TTNAMLEN+1]; /* Name of communication device */
1035 int connected = 0; /* True if connected */
1036 int startconnected; /* initial state of connected */
1039 long speed = -1L; /* Communication device speed */
1040 int wasclosed = 0; /* Connection was just closed */
1041 int whyclosed = WC_REMO; /* why it was closed */
1042 int qnxportlock = 0; /* QNX port locking on/off */
1046 #endif /* CLSONDISC */
1048 int cxflow[CXT_MAX+1]; /* See initflow() */
1051 char * floname[] = { /* Flow control names */
1052 "none", "xon/xoff", "rts/cts", "dtr/cd", "etx/ack", "string",
1053 "xxx1", "xxx2", "dtr/cts", "keep", "auto"
1055 int nfloname = (sizeof(floname) / sizeof(char *));
1057 char * cxname[] = { /* Connection type names */
1058 "remote", "direct-serial", "modem", "tcp/ip", "x.25", "decnet",
1059 "lat", "netbios", "named-pipe", "ssh", "pipe"
1061 int ncxname = (sizeof(cxname) / sizeof(char *));
1064 int parity = DEFPAR, /* Parity specified, 0,'e','o',etc */
1065 hwparity = 0, /* Hardware parity for serial port */
1066 stopbits = -1, /* Stop bits for serial port */
1067 clsondisc = CLSONDISC, /* Serial port close on disconnect */
1068 autopar = 0, /* Automatic parity change flag */
1069 sosi = 0, /* Shift-In/Out flag */
1070 flow = 0, /* Flow control (see initflow()) */
1071 autoflow = 1, /* Automatic flow control */
1072 turn = 0, /* Line turnaround handshake flag */
1073 turnch = XON, /* Line turnaround character */
1074 duplex = 0, /* Duplex, full by default */
1075 escape = DFESC, /* Escape character for connect */
1076 ckdelay = DDELAY, /* Initial delay before sending */
1077 tnlm = 0; /* Terminal newline mode */
1079 /* Networks for SET HOST */
1082 #define MYHOSTL 1024
1085 #endif /* BIGBUFOK */
1087 char myhost[MYHOSTL]; /* Local host name */
1088 int network = 0; /* Network vs serial connection */
1089 int inserver = 0; /* Running as an Internet server */
1090 int isguest = 0; /* User is anonymous */
1091 char * clienthost = NULL; /* Peer host name or address */
1092 int tcp_incoming = 0; /* Incoming TCP connection? */
1096 int nettype = NET_TCPB; /* Default network type */
1099 int nettype = NET_SX25;
1102 int nettype = NET_IX25;
1105 int nettype = NET_HX25;
1108 int nettype = NET_VX25;
1111 int nettype = NET_DEC;
1114 int nettype = NET_SLAT;
1116 int nettype = NET_NONE;
1117 #endif /* SUPERLAT */
1119 #endif /* STRATUSX25 */
1123 #endif /* TCPSOCKET */
1125 int nettype = NET_NONE;
1126 #endif /* NETCONN */
1129 int revcall = 0; /* X.25 reverse call not selected */
1130 int closgr = -1; /* X.25 closed user group */
1131 int cudata = 0; /* X.25 call user data not specified */
1132 char udata[MAXCUDATA]; /* X.25 call user data */
1136 I was unable to find any pre-defined MAX values for x25 addresses - the
1137 addresses that I've seen have been around 10-12 characters 32 is probably
1138 enough, 64 is hopefully safe for everyone.
1140 x25addr_t local_nua = {'\0'}; /* local x.25 address */
1141 x25addr_t remote_nua = {'\0'}; /* remote x.25 address */
1142 char x25name[32] = {'\0'}; /* x25 device name, sx25a0 or sx25a1 */
1143 char x25dev[64] = "/dev/x25pkt"; /* x25 device in /dev */
1144 int x25port = 0; /* port used for X.25 - AIX only */
1149 This condition is unrelated to the above IBMX25 condition.
1150 IBM X.25 doesn't have PAD support.
1152 CHAR padparms[MAXPADPARMS+1]; /* X.3 parameters */
1158 int isinterrupted = 0; /* Used in exception handling */
1159 int what = W_INIT; /* What I am doing */
1160 int lastxfer = 0; /* Last transfer (send or receive) */
1162 extern int mdmtyp; /* Modem (/network) type */
1165 extern int StartedFromDialer;
1167 extern int TlsIndex;
1170 unsigned long ESPToRestore; /* Ditto */
1175 int os2pm = 0; /* OS/2 Presentation Manager flag */
1178 /* Terminal screen size, if known, -1 means unknown. */
1183 int tt_rows[VNUM] = {24,24,25,1}; /* Rows (height) */
1184 int tt_cols[VNUM] = {80,80,80,80}; /* Columns (width) */
1185 int cmd_rows = 24, cmd_cols = 80; /* Command/console screen dimensions */
1187 int tt_rows[VNUM] = {-1,24,25,1}; /* Rows (height) */
1188 int tt_cols[VNUM] = {-1,80,80,80}; /* Columns (width) */
1189 int cmd_rows = -1, cmd_cols = -1; /* Command/console screen dimensions */
1191 int k95stdio = 0; /* Stdio threads */
1192 int tt_bell = XYB_AUD | XYB_SYS; /* BELL AUDIBLE (system sounds) */
1194 int tt_rows = -1; /* Rows (height) */
1195 int tt_cols = -1; /* Columns (width) */
1196 int cmd_rows = 24, cmd_cols = 80; /* Command/console screen dimensions */
1197 int tt_bell = XYB_AUD; /* BELL ON */
1200 int tt_print = 0; /* Transparent print disabled */
1201 int tt_escape = 1; /* Escaping back is enabled */
1202 int tt_scroll = 1; /* Scrolling operations are enabled */
1204 int tn_exit = 0; /* Exit on disconnect */
1206 int exitonclose = 0; /* Exit on close */
1207 int exithangup = 1; /* Hangup on exit */
1208 int haveline = 0; /* SET LINE or SET HOST in effect */
1209 int tlevel = -1; /* Take-file command level */
1210 int hints = 1; /* Whether to give hints */
1213 int remonly = 1; /* Remote-mode-only advisory (-R) */
1214 int nolocal = 1; /* Remote-only strictly enforced */
1218 int cx_status = 0; /* CONNECT return status */
1219 #endif /* NOLOCAL */
1222 extern int cmdlvl; /* Command level */
1223 extern int maclvl; /* Macro invocation level */
1226 int protocol = PROTO_K; /* File transfer protocol = Kermit */
1229 int prefixing = PX_CAU;
1231 int prefixing = PX_ALL;
1232 #endif /* NEWDEFAULTS */
1234 extern short ctlp[]; /* Control-prefix table */
1236 int carrier = CAR_AUT; /* Pay attention to carrier signal */
1237 int cdtimo = 0; /* Carrier wait timeout */
1238 int xitsta = GOOD_EXIT; /* Program exit status */
1240 #ifdef VMS /* Default filename collision action */
1241 int fncact = XYFX_X; /* REPLACE for VMS */
1243 int fncact = XYFX_B; /* BACKUP for everybody else */
1246 int fncsav = -1; /* For saving & restoring the above */
1247 int bgset = -1; /* BACKGROUND mode set explicitly */
1249 int cmdint = 1; /* Interrupts are allowed */
1251 int xsuspend = DFSUSP; /* Whether SUSPEND command, etc, */
1252 #else /* is to be allowed. */
1256 /* Statistics variables */
1259 flci, /* Characters from line, current file */
1260 flco, /* Chars to line, current file */
1261 tlci, /* Chars from line in transaction */
1262 tlco, /* Chars to line in transaction */
1263 ffc, /* Chars to/from current file */
1264 tfc; /* Chars to/from files in transaction */
1266 long filcnt, /* Number of files in transaction */
1267 filrej, /* Number of files rejected in transaction */
1268 cps = 0L, /* Chars/sec last transfer */
1269 peakcps = 0L, /* Peak chars/sec last transfer */
1270 ccu, /* Control chars unprefixed in transaction */
1271 ccp, /* Control chars prefixed in transaction */
1272 rptn; /* Repeated characters compressed */
1274 int tsecs = 0; /* Seconds for transaction */
1275 int fsecs = 0; /* Per-file timer */
1279 fpfsecs = 0.0, /* Floating point per-file timer */
1280 fptsecs = 0.0; /* and per-transaction timer */
1281 #endif /* GFTIMER */
1285 int deblog = 0, /* Debug log is open */
1286 debok = 1, /* Debug log is not disabled */
1287 debxlen = 54, /* Default length for debug strings */
1288 debses = 0, /* Flag for DEBUG SESSION */
1289 debtim = 0, /* Include timestamp in debug log */
1290 debmsg = 0, /* Debug messages on/off */
1291 pktlog = 0, /* Flag for packet logging */
1292 seslog = 0, /* Session logging */
1293 dialog = 0, /* DIAL logging */
1294 tralog = 0, /* Transaction logging */
1295 tlogfmt = 1, /* Transaction log format (verbose) */
1296 tlogsep = (int)',', /* Transaction log field separator */
1297 displa = 0, /* File transfer display on/off */
1298 stdouf = 0, /* Flag for output to stdout */
1299 stdinf = 0, /* Flag for input from stdin */
1300 xflg = 0, /* Flag for X instead of F packet */
1301 hcflg = 0, /* Doing Host command */
1302 dest = DEST_D, /* Destination for packet data */
1303 zchkod = 0, /* zchko() should work for dirs too? */
1304 zchkid = 0, /* zchki() should work for dirs too? */
1306 /* If you change this, also see struct ptab above... */
1308 #ifdef OS2 /* Flag for file name conversion */
1309 fncnv = XYFN_L, /* Default is Literal in OS/2, */
1310 f_save = XYFN_L, /* (saved copy of same) */
1312 fncnv = XYFN_C, /* elsewhere Convert them */
1313 f_save = XYFN_C, /* (ditto) */
1316 fnspath = PATH_OFF, /* Send file path */
1317 fnrpath = PATH_AUTO, /* Receive file path */
1318 fackpath = 1, /* Send back path in ACK to F */
1319 binary = XYFT_B, /* Default file transfer mode */
1320 b_save = XYFT_B, /* Saved file mode */
1321 eofmethod = 0, /* EOF detection method (length) */
1324 cursor_save = -1, /* Cursor state */
1327 xfermode = XMODE_A, /* Transfer mode, manual or auto */
1328 xfiletype = -1, /* Transfer only text (or binary) */
1329 recursive = 0, /* Recursive directory traversal */
1330 nolinks = 2, /* Don't follow symbolic links */
1331 skipbup = 0, /* Skip backup files when sending */
1332 sendmode = SM_SEND, /* Which type of SEND operation */
1333 slostart = 1, /* Slow start (grow packet lengths) */
1334 cmask = 0377, /* CONNECT (terminal) byte mask */
1335 fmask = 0377, /* File byte mask */
1336 ckwarn = 0, /* Flag for file warning */
1337 quiet = 0, /* Be quiet during file transfer */
1338 local = 0, /* 1 = local mode, 0 = remote mode */
1339 cxtype = CXT_REMOTE, /* Connection type */
1340 server = 0, /* Flag for I Am Server */
1341 query = 0, /* Flag for Query active */
1342 justone = 0, /* Server should do Just One command */
1343 urserver = 0, /* Flag for You Are Server */
1344 bye_active = 0, /* Flag for BYE command active */
1345 diractive = 0, /* Flag for DIRECTORY command active */
1346 cdactive = 0, /* Flag for CD command active */
1347 cflg = 0, /* Connect before transaction */
1348 cnflg = 0, /* Connect after transaction */
1349 cxseen = 0, /* Flag for cancelling a file */
1350 czseen = 0, /* Flag for cancelling file group */
1351 fatalio = 0, /* Flag for fatal i/o error */
1352 discard = 0, /* Flag for file to be discarded */
1353 keep = SET_AUTO, /* Keep incomplete files = AUTO */
1354 unkcs = 1, /* Keep file w/unknown character set */
1356 filepeek = 0, /* Inspection of files */
1362 #endif /* datageneral */
1364 nakstate = 0, /* In a state where we can send NAKs */
1365 dblchar = -1, /* Character to double when sending */
1366 moving = 0, /* MOVE = send, then delete */
1367 reliable = SET_AUTO, /* Nonzero if transport is reliable */
1370 urclear = 0, /* Nonzero for clear channel to you */
1371 clearrq = SET_AUTO, /* SET CLEARCHANEL value */
1373 streaming = 0, /* Nonzero if streaming is active */
1374 streamok = 0, /* Nonzero if streaming negotiated */
1375 streamrq = SET_AUTO, /* SET STREAMING value */
1376 streamed = -1; /* Whether we streamed last time */
1378 char * snd_move = NULL; /* Move file after sending it */
1379 char * snd_rename = NULL; /* Rename file after sending it */
1380 char * rcv_move = NULL; /* Move file after receiving it */
1381 char * rcv_rename = NULL; /* Rename file after receiving it */
1383 char * g_snd_move = NULL;
1384 char * g_snd_rename = NULL;
1385 char * g_rcv_move = NULL;
1386 char * g_rcv_rename = NULL;
1389 char *tt_trigger[TRIGGERS] = { NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL };
1390 CHAR *tt_trmatch[TRIGGERS] = { NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL };
1391 char *triggerval = NULL;
1392 #endif /* CK_TRIGGER */
1394 int ckxlogging = 0; /* Flag for syslogging active */
1395 int ikdbopen = 0; /* Flag for IKSD database active */
1396 int dbinited = 0; /* Flag for IKSDB record init'd */
1398 int ckxsyslog = 0; /* Logging level 0 */
1401 int ckxsyslog = SYSLOGLEVEL; /* Logging level specified */
1403 int ckxsyslog = SYSLG_DF; /* Default logging level */
1404 #endif /* SYSLOGLEVEL */
1405 #endif /* CKSYSLOG */
1409 _PROTOTYP( VOID iniopthlp, (void) ); /* Command-line help initializer */
1413 _PROTOTYP( VOID getexedir, (void) );
1414 _PROTOTYP( int putnothing, (char) );
1417 _PROTOTYP( VOID doiksdinit, (void) );
1418 _PROTOTYP( VOID iksdinit, (void) );
1419 _PROTOTYP( VOID doiklog, (void) );
1420 _PROTOTYP( int dbinit, (void) );
1423 /* Variables passed from command parser to protocol module */
1428 _PROTOTYP( VOID apconect, (void) );
1435 char *clcmds = NULL; /* Pointer to command-line commands */
1439 extern MACRO *macrotab;
1440 #endif /* NOSETKEY */
1443 int nopush = 0; /* PUSH enabled */
1445 int nopush = 1; /* PUSH disabled */
1448 CHAR sstate = (CHAR) 0; /* Starting state for automaton */
1449 CHAR zstate = (CHAR) 0; /* For remembering sstate */
1450 char * printername = NULL; /* NULL if printer not redirected */
1451 int printpipe = 0; /* For SET PRINTER */
1455 char *cmarg = ""; /* Pointer to command data */
1456 char *cmarg2 = ""; /* Pointer to 2nd command data */
1457 char **cmlist; /* Pointer to file list in argv */
1459 #ifdef CK_AUTODL /* Autodownload */
1460 int autodl = 1; /* Enabled by default */
1462 int autodl = 0; /* (or if not implemented). */
1463 #endif /* CK_AUTODL */
1464 int adl_err = 1; /* 1 = stop on error */
1466 int adl_ask = 1; /* 1 = file dialog on autodownload */
1468 int adl_ask = 0; /* 0 = no file dialog */
1470 #ifdef OS2 /* AUTODOWNLOAD parameters */
1471 int adl_kmode = ADL_PACK, /* Match Packet to signal download */
1472 adl_zmode = ADL_PACK;
1473 char * adl_kstr = NULL; /* KERMIT Download String */
1474 char * adl_zstr = NULL; /* ZMODEM Download String */
1477 int remfile = 0, rempipe = 0, remappd = 0; /* REMOTE output redirection */
1478 char * remdest = NULL;
1484 1 = enabled in local mode
1485 2 = enabled in remote mode
1486 3 = enabled in both local and remote modes
1487 only as initial (default) values.
1489 int en_xit = 2; /* EXIT */
1490 int en_cwd = 3; /* CD/CWD */
1491 int en_cpy = 3; /* COPY */
1492 int en_del = 2; /* DELETE */
1493 int en_mkd = 3; /* MKDIR */
1494 int en_rmd = 2; /* RMDIR */
1495 int en_dir = 3; /* DIRECTORY */
1496 int en_fin = 3; /* FINISH */
1497 int en_get = 3; /* GET */
1499 int en_hos = 2; /* HOST enabled */
1501 int en_hos = 0; /* HOST disabled */
1503 int en_ren = 3; /* RENAME */
1504 int en_sen = 3; /* SEND */
1505 int en_set = 3; /* SET */
1506 int en_spa = 3; /* SPACE */
1507 int en_typ = 3; /* TYPE */
1508 int en_who = 3; /* WHO */
1510 /* Data General AOS/VS can't do this */
1511 int en_bye = 0; /* BYE */
1513 int en_bye = 2; /* PCs in local mode... */
1514 #endif /* datageneral */
1515 int en_asg = 3; /* ASSIGN */
1516 int en_que = 3; /* QUERY */
1517 int en_ret = 2; /* RETRIEVE */
1518 int en_mai = 3; /* MAIL */
1519 int en_pri = 3; /* PRINT */
1520 int en_ena = 3; /* ENABLE */
1522 int en_xit = 0, en_cwd = 0, en_cpy = 0, en_del = 0, en_mkd = 0, en_rmd = 0,
1523 en_dir = 0, en_fin = 0, en_get = 0, en_hos = 0, en_ren = 0, en_sen = 0,
1524 en_set = 0, en_spa = 0, en_typ = 0, en_who = 0, en_bye = 0, en_asg = 0,
1525 en_que = 0, en_ret = 0, en_mai = 0, en_pri = 0, en_ena = 0;
1526 #endif /* NOSERVER */
1531 char **xargv; /* Global copies of argv */
1532 int xargc; /* and argc */
1533 int xargs; /* an immutable copy of argc */
1534 char *xarg0; /* and of argv[0] */
1535 char *pipedata; /* Pointer to -P (pipe) data */
1537 extern char *dftty; /* Default tty name from ck?tio.c */
1538 extern int dfloc; /* Default location: remote/local */
1539 extern int dfprty; /* Default parity */
1540 extern int dfflow; /* Default flow control */
1546 Buffered file input and output buffers. See getpkt() in ckcfns.c
1547 and zoutdump() in the system-dependent file i/o module (usually ck?fio.c).
1550 /* Now we allocate them dynamically, see getiobs() below. */
1551 char zinbuffer[INBUFSIZE], zoutbuffer[OBUFSIZE];
1552 #endif /* DYNAMIC */
1553 char *zinptr, *zoutptr;
1554 int zincnt, zoutcnt;
1555 int zobufsize = OBUFSIZE;
1561 #endif /* SESLIMIT */
1563 #ifdef CK_AUTHENTICATION
1565 #endif /* CK_AUTHENTICATION */
1567 _PROTOTYP( int getiobs, (VOID) );
1569 /* M A I N -- C-Kermit main program */
1577 #ifdef GEMDOS /* Special for Atari ST */
1578 cc_clean(); /* This can't be right? */
1580 #endif /* NOCCTRAP */
1583 /* Info associated with a system ID */
1585 struct sysdata sysidlist[] = { /* Add others as needed... */
1586 { "0", "anonymous", 0, NUL, 0, 0, 0 },
1587 { "A1", "Apple II", 0, NUL, 0, 0, 3 }, /* fix this */
1588 { "A3", "Macintosh", 1, ':', 0, 2, 1 },
1589 { "D7", "VMS", 0, ']', 1, 0, 0 },
1590 { "DA", "RSTS/E", 0, ']', 1, 0, 3 }, /* (i think...) */
1591 { "DB", "RT11", 0, NUL, 1, 0, 3 }, /* (maybe...) */
1592 { "F3", "AOS/VS", 1, ':', 0, 0, 2 },
1593 { "I1", "VM/CMS", 0, NUL, 0, 0, 0 },
1594 { "I2", "MVS/TSO", 0, NUL, 0, 0, 0 },
1595 { "I4", "MUSIC", 0, NUL, 0, 0, 0 },
1596 { "I7", "CICS", 0, NUL, 0, 0, 0 },
1597 { "I9", "MVS/ROSCOE", 0, NUL, 0, 0, 0 },
1598 { "K2", "Atari ST", 1, '\\', 1, 0, 3 },
1599 { "L3", "Amiga", 1, '/', 1, 0, 2 },
1600 { "MV", "Stratus VOS", 1, '>', 0, 1, 0 },
1601 { "N3", "Apollo Aegis", 1, '/', 0, 3, 2 },
1602 { "U1", "UNIX", 1, '/', 0, 3, 2 },
1603 { "U8", "MS-DOS", 1, '\\', 1, 0, 3 },
1604 { "UD", "OS-9", 1, '/', 0, 3, 2 },
1605 { "UN", "Windows-32", 1, '\\', 1, 2, 3 },
1606 { "UO", "OS/2", 1, '\\', 1, 2, 3 }
1608 static int nxxsysids = (sizeof(sysidlist) / sizeof(struct sysdata));
1610 /* Given a Kermit system ID code, return the associated name string */
1611 /* and some properties of the filenames... */
1614 getsysid(s) char * s; { /* Get system-type name */
1617 for (i = 0; i < nxxsysids; i++)
1618 if (!strcmp(sysidlist[i].sid_code,s))
1619 return(sysidlist[i].sid_name);
1624 getsysix(s) char *s; { /* Get system-type index */
1627 for (i = 0; i < nxxsysids; i++)
1628 if (!strcmp(sysidlist[i].sid_code,s))
1634 /* Tell if a pathname is absolute (versus relative) */
1635 /* This should be parceled out to each of the ck*fio.c modules... */
1636 /* VMS isabsolute() is now in ckvfio.c. */
1639 isabsolute(path) char * path; {
1646 x = (int) strlen(path);
1647 debug(F111,"isabsolute",path,x);
1655 #else /* def UNIX */
1657 if (*path == '/' || *path == '\\')
1659 else if (isalpha(*path) && x > 2)
1660 if (*(path+1) == ':' && (*(path +2) == '/' || *(path+2) == '\\'))
1670 #else /* def AMIGA */
1682 #else /* def datageneral */
1684 rc = 0; /* Fill in later... */
1687 rc = 0; /* Fill in later... */
1688 #else /* def STRATUS */
1690 if (*path == '/' || *path == '\\')
1692 else if (isalpha(*path) && x > 1)
1693 if (*(path+1) == ':')
1696 #endif /* STRATUS */
1698 #endif /* datageneral */
1703 debug(F101,"isabsolute rc","",rc);
1706 #endif /* ndef VMS */
1708 /* See if I have direct access to the keyboard */
1711 is_a_tty(n) int n; {
1739 extern char * sndexcept[], * rcvexcept[];
1741 for (i = 0; i < NSNDEXCEPT; i++) {
1742 sndexcept[i] = NULL;
1743 rcvexcept[i] = NULL;
1748 /* Initialize flow control table */
1751 initflow() { /* Default values for flow control */
1752 #ifdef VMS /* for each kind of connection. */
1753 /* The VMS telnet terminal driver treats "none" as request to lose chars */
1754 cxflow[CXT_REMOTE] = FLO_XONX; /* Remote mode... */
1757 /* Ditto for HP-UX */
1758 cxflow[CXT_REMOTE] = FLO_XONX; /* Remote mode... */
1760 /* The temptation is to make this one FLO_KEEP but don't!!! */
1761 /* It totally wrecks binary-file transfer when coming in via Telnet. */
1762 /* In UNIX at least... */
1763 cxflow[CXT_REMOTE] = FLO_NONE;
1768 cxflow[CXT_DIRECT] = FLO_XONX; /* Direct serial connections... */
1770 cxflow[CXT_DIRECT] = FLO_NONE;
1774 cxflow[CXT_MODEM] = FLO_RTSC; /* Modem connections... */
1777 cxflow[CXT_MODEM] = FLO_XONX;
1779 cxflow[CXT_MODEM] = FLO_NONE;
1781 #endif /* CK_RTSCTS */
1784 cxflow[CXT_TCPIP] = FLO_XONX; /* TCP/IP connections... */
1786 cxflow[CXT_TCPIP] = FLO_NONE;
1789 cxflow[CXT_SSH] = FLO_NONE;
1790 cxflow[CXT_X25] = FLO_NONE; /* Other kinds of networks... */
1791 cxflow[CXT_DECNET] = FLO_XONX;
1792 cxflow[CXT_LAT] = FLO_XONX;
1793 cxflow[CXT_NETBIOS] = FLO_NONE;
1794 cxflow[CXT_NPIPE] = FLO_NONE;
1795 cxflow[CXT_PIPE] = FLO_NONE;
1796 flow = cxflow[cxtype]; /* Initial flow setting. */
1797 debug(F101,"initflow","",flow);
1801 /* Initialize file transfer protocols */
1804 initproto(y, upbstr, uptstr, srvstr, sndbstr, sndtstr, rcvbstr, rcvtstr)
1806 char * upbstr, * uptstr, * srvstr, * sndbstr, * sndtstr, * rcvbstr,
1810 if (upbstr) /* Convert null strings */
1811 if (!*upbstr) /* to null pointers */
1814 if (uptstr) /* Convert null strings */
1815 if (!*uptstr) /* to null pointers */
1838 protocol = y; /* Set protocol */
1840 if (ptab[protocol].rpktlen > -1)
1841 urpsiz = ptab[protocol].rpktlen;
1842 if (ptab[protocol].spktflg > -1)
1843 spsizf = ptab[protocol].spktflg;
1844 if (ptab[protocol].spktlen > -1) {
1845 spsiz = ptab[protocol].spktlen;
1846 debug(F101,"initproto spsiz","",spsiz);
1848 spsizr = spmax = spsiz;
1849 debug(F101,"initproto spsizr","",spsizr);
1852 if (ptab[protocol].winsize > -1)
1853 wslotr = ptab[protocol].winsize;
1854 if (ptab[protocol].prefix > -1)
1855 prefixing = ptab[protocol].prefix;
1856 if (ptab[protocol].fnca > -1)
1857 fncact = ptab[protocol].fnca;
1858 if (ptab[protocol].fncn > -1)
1859 fncnv = ptab[protocol].fncn;
1860 if (ptab[protocol].fnsp > -1)
1861 fnspath = ptab[protocol].fnsp;
1862 if (ptab[protocol].fnrp > -1)
1863 fnrpath = ptab[protocol].fnrp;
1865 makestr(&(ptab[protocol].h_b_init),upbstr);
1866 makestr(&(ptab[protocol].h_t_init),uptstr);
1867 makestr(&(ptab[protocol].h_x_init),srvstr);
1868 makestr(&(ptab[protocol].p_b_scmd),sndbstr);
1869 makestr(&(ptab[protocol].p_t_scmd),sndtstr);
1870 makestr(&(ptab[protocol].p_b_rcmd),rcvbstr);
1871 makestr(&(ptab[protocol].p_t_rcmd),rcvtstr);
1878 docmdline(void * threadinfo)
1879 #else /* CK_ANSIC */
1880 docmdline(threadinfo) VOID * threadinfo;
1881 #endif /* CK_ANSIC */
1885 if (threadinfo) { /* Thread local storage... */
1886 TlsSetValue(TlsIndex,threadinfo);
1887 debug( F100, "docmdline called with threadinfo block", "", 0 );
1889 debug( F100, "docmdline threadinfo is NULL","",0);
1898 #endif /* CK_LOGIN */
1899 proto(); /* Take any requested action, then */
1900 if (!quiet) /* put cursor back at left margin, */
1903 if (cnflg) { /* Re-connect if requested */
1909 #endif /* NOLOCAL */
1912 ckThreadEnd(threadinfo);
1921 || inserver /* Internet server */
1925 extern int fdispla; /* File-transfer display format */
1926 extern char * ikprompt; /* IKSD prompt */
1931 x_login = 1; /* Login required */
1932 x_logged = 0; /* Not logged in yet */
1933 cmsetp(ikprompt); /* Set up IKSD's prompt */
1935 en_mai = 0; /* MAIL is disabled */
1936 en_who = 0; /* REMOTE WHO is disabled */
1937 en_hos = 0; /* REMOTE HOST is disabled */
1938 en_pri = 0; /* PRINT is disabled */
1939 #endif /* NOSERVER */
1941 x_login = 0; /* Login not required */
1942 x_logged = 1; /* Already logged in */
1944 #endif /* CK_LOGIN */
1946 nolocal = 1; /* SET LINE/HOST not allowed */
1947 fdispla = XYFD_N; /* No file-transfer display */
1949 clienthost = ckgetpeer(); /* Get client's hostname */
1950 debug(F110,"ikslogin clienthost",clienthost,0);
1951 #endif /* NETCONN */
1952 ztime(&s); /* Get current date and time */
1955 #ifdef CK_AUTHENTICATION
1957 x_logged = ck_tn_auth_valid(); /* Did Telnet Auth succeed? */
1958 debug(F111,"ikslogin","x_logged",x_logged);
1961 /* On Windows 9x, we do not have the ability in */
1962 /* zvuser() at present to determine if the name */
1963 /* approved in a Kerberos principal is really a */
1964 /* an account in the Windows Access Control List */
1965 if (isWin95() && x_logged == AUTH_VALID
1966 && (ck_tn_authenticated() != AUTHTYPE_NTLM)
1968 && (ck_tn_authenticated() != AUTHTYPE_SRP)
1971 auth_finished(AUTH_USER);
1972 x_logged = AUTH_USER;
1973 printf("WARNING:\r\n");
1975 " The Telnet authentication method used cannot provide for automated\r\n");
1977 " login to Windows 95 or Windows 98. A password must be entered\r\n");
1979 " locally to validate your userid. Telnet authentication (and encryption)\r\n"
1982 " can be used to validate the host (and protect the privacy of your password.)\
1988 if (x_logged == AUTH_VALID) {
1990 if ((ssl_active_flag || tls_active_flag) &&
1991 (!TELOPT_U(TELOPT_AUTHENTICATION) ||
1992 ck_tn_authenticated() == AUTHTYPE_NULL ||
1993 ck_tn_authenticated() == AUTHTYPE_AUTO)
1996 if (tls_is_krb5(0)) {
1997 printf("Authenticated using Kerberos 5\r\n");
1999 if (ckxsyslog >= SYSLG_LI && ckxlogging) {
2000 extern char szUserNameAuthenticated[];
2001 cksyslog(SYSLG_LI, 1, "AUTH_VALID",
2003 szUserNameAuthenticated
2006 #endif /* CKSYSLOG */
2008 #endif /* SSL_KRB5 */
2010 printf("Authenticated using X.509 certificate\r\n");
2012 if (ckxsyslog >= SYSLG_LI && ckxlogging) {
2013 extern char szUserNameAuthenticated[];
2014 cksyslog(SYSLG_LI, 1, "AUTH_VALID",
2015 "X.509 certificate",
2016 szUserNameAuthenticated
2019 #endif /* CKSYSLOG */
2024 printf("Authenticated using %s\r\n",
2025 AUTHTYPE_NAME(ck_tn_authenticated()));
2027 if (ckxsyslog >= SYSLG_LI && ckxlogging) {
2028 extern char szUserNameAuthenticated[];
2029 cksyslog(SYSLG_LI, 1, "AUTH_VALID",
2030 AUTHTYPE_NAME(ck_tn_authenticated()),
2031 szUserNameAuthenticated
2034 #endif /* CKSYSLOG */
2037 if (zvpass("") == 0)
2039 } else if (x_logged == AUTH_USER && !strcmp(uidbuf,"anonymous")) {
2040 extern char szUserNameAuthenticated[];
2042 debug(F110,"szUserNameAuthenticated",
2043 szUserNameAuthenticated,0);
2044 if (zvpass(szUserNameAuthenticated) == 0) {
2045 /* Anonymous login failed. Force a username prompt. */
2050 if ((ssl_active_flag || tls_active_flag) &&
2051 (!TELOPT_U(TELOPT_AUTHENTICATION) ||
2052 ck_tn_authenticated() == AUTHTYPE_NULL ||
2053 ck_tn_authenticated() == AUTHTYPE_AUTO)) {
2054 printf("Authenticated using X.509 certificate\r\n");
2056 if (ckxsyslog >= SYSLG_LI && ckxlogging) {
2057 extern char szUserNameAuthenticated[];
2058 cksyslog(SYSLG_LI, 1, "AUTH_USER",
2059 "X.509 certificate",
2060 szUserNameAuthenticated
2063 #endif /* CKSYSLOG */
2067 printf("Authenticated using %s\r\n",
2068 AUTHTYPE_NAME(ck_tn_authenticated())
2071 if (ckxsyslog >= SYSLG_LI && ckxlogging) {
2072 cksyslog(SYSLG_LI, 1, "AUTH_USER",
2073 AUTHTYPE_NAME(ck_tn_authenticated()),
2074 szUserNameAuthenticated
2077 #endif /* CKSYSLOG */
2082 if (ckxsyslog >= SYSLG_LI && ckxlogging &&
2083 x_logged == AUTH_USER) {
2084 extern char szUserNameAuthenticated[];
2085 cksyslog(SYSLG_LI, 1, "AUTH_USER",
2086 AUTHTYPE_NAME(ck_tn_authenticated()),
2087 szUserNameAuthenticated
2090 #endif /* CKSYSLOG */
2092 if (!strcmp("(unknown)",uidbuf)
2094 || !stricmp("administrator",uidbuf)
2096 || !strcmp("root",uidbuf)
2099 || !strcmp("root",uidbuf)
2102 || !strcmp("root",uidbuf)
2111 #endif /* CK_AUTHENTICATION */
2112 #endif /* CK_LOGIN */
2116 printf("\r\nInternet Kermit Service ready at %s%s\r\n",s,versio);
2119 printf("\r\nC-Kermit ready at %s%s\r\n",s,versio);
2121 printf("%s\r\n", myhost);
2128 extern int arg_x; /* Flag for '-x' on command line */
2130 extern struct mtab *mactab; /* For ON_LOGIN macro. */
2134 debug(F110,"MAIN clienthost",clienthost,0);
2135 srvidl = timelimit = logintimo; /* For interactive login */
2136 rtimer(); /* Reset timer */
2137 for (i = 0; i < iks_retry && !x_logged; i++) { /* Count retries */
2138 if (gtimer() > logintimo)
2141 tn_wait("login loop");
2144 debug(F101,"MAIN LOGIN try","",i);
2145 what = W_NOTHING; /* Because proto() changes this */
2148 debug(F111,"MAIN LOGIN",
2149 "TELOPT_SB(TELOPT_KERMIT).kermit.me_start",
2150 TELOPT_SB(TELOPT_KERMIT).kermit.me_start
2152 /* Kermit server negotiated */
2153 if (TELOPT_SB(TELOPT_KERMIT).kermit.me_start) {
2154 debug(F101,"IKSD starting in server mode","",0);
2155 arg_x = 1; /* Enter server mode */
2158 justone = 1; /* Execute one command at a time. */
2159 #endif /* IKSDPOPBACK */
2160 proto(); /* Enter protocol if requested. */
2164 if (x_logged) /* Logged in */
2166 } else { /* Not in client/server mode */
2167 #endif /* IKS_OPTION */
2168 debug(F101,"IKSD starting with Username prompt","",0);
2169 x_logged = ckxlogin((CHAR *)uidbuf,NULL,NULL,1);
2170 if (sstate) { /* Received a packet at prompt */
2172 justone = 1; /* Go handle it */
2173 #endif /* IKSDPOPBACK */
2176 if (!x_logged) { /* In case we are at the prompt... */
2177 printf("Access denied.\n");
2178 uidbuf[0] = '\0'; /* Forget the name if we have one */
2182 #endif /* IKS_OPTION */
2184 srvidl = timelimit = iks_timo; /* Reset command timelimit */
2185 debug(F101,"MAIN LOGIN","",x_logged);
2186 if (!x_logged) { /* Logins failed. */
2187 if (TELOPT_SB(TELOPT_KERMIT).kermit.me_start)
2188 errpkt((CHAR *)"Login Timeout");
2192 what = W_NOTHING; /* Stay in known state */
2195 en_pri = 0; /* No printing for anonymous users */
2196 en_mai = 0; /* No email for anonymous users */
2197 en_mkd = 0; /* Or directory creation */
2198 en_rmd = 0; /* Or directory removal */
2199 en_ena = 0; /* Or ENABLing DISABLEd items */
2201 #endif /* NOSERVER */
2205 If a macro named "on_login" is defined, execute it. Also remove it from the
2206 macro table so the user cannot see what it does. Execute it as part of the
2209 if (nmac) { /* Any macros defined? */
2211 char * cmd = "on_login"; /* MSVC 2.x compiler error */
2212 k = mlook(mactab,cmd,nmac); /* Look up "on_login" */
2213 if (k >= 0) { /* If found, */
2217 #endif /* IKSDCONF */
2218 if (dodo(k,"",0) > -1) /* set it up, */
2219 parser(1); /* execute it */
2222 #endif /* IKSDCONF */
2223 delmac(cmd,1); /* and delete it */
2227 } /* if (inserver) */
2228 #else /* CK_LOGIN */
2230 srvidl = timelimit = iks_timo; /* Set idle limits for IKS */
2231 #endif /* CK_LOGIN */
2237 failcmdline(void * foo)
2238 #else /* CK_ANSIC */
2239 failcmdline(foo) VOID * foo;
2240 #endif /* CK_ANSIC */
2246 if (cnflg) doconect(0,0); /* connect again if requested. */
2249 #endif /* NOLOCAL */
2256 dotakeini(void * threadinfo) /* Execute init file. */
2257 #else /* CK_ANSIC */
2258 dotakeini(threadinfo) VOID * threadinfo; /* Execute init file. */
2259 #endif /* CK_ANSIC */
2263 if (threadinfo) { /* Thread local storage... */
2264 TlsSetValue(TlsIndex,threadinfo);
2265 debug(F100, "dotakeini called with threadinfo block","", 0);
2267 debug(F100, "dotakeini - threadinfo is NULL", "", 0);
2276 #endif /* CK_LOGIN */
2277 cmdini(); /* Sets tlevel */
2279 debug(F111,"dotakeini","inserver",inserver);
2280 debug(F111,"dotakeini","sstelnet",sstelnet);
2283 /* Wrong place for this... */
2286 dofast(); /* By now FAST defaults should be OK */
2287 #endif /* CK_FAST */
2289 #endif /* COMMENT */
2291 doinit(); /* Now do the initialization file */
2292 debug(F101,"main executing init file","",tlevel);
2293 while (tlevel > -1) {
2294 sstate = (CHAR) parser(1); /* Execute one command at a time. */
2295 if (sstate) proto(); /* Enter protocol if requested. */
2300 debug(F101,"main exits init file","",tlevel);
2303 ckThreadEnd(threadinfo);
2310 failtakeini(void * threadinfo)
2311 #else /* CK_ANSIC */
2312 failtakeini(threadinfo) VOID * threadinfo;
2313 #endif /* CK_ANSIC */
2316 cc_clean(); /* Atari: Clean up after ^C-trap. */
2320 conoll("Interrupted during initialization or \
2321 command-line processing.");
2322 conoll("C-Kermit quitting...");
2324 doexit(BAD_EXIT,-1); /* Exit with bad status. */
2329 doicp(void * threadinfo)
2330 #else /* CK_ANSIC */
2331 doicp(threadinfo) VOID * threadinfo;
2332 #endif /* CK_ANSIC */
2336 if (threadinfo) { /* Thread local storage... */
2337 if (!TlsSetValue(TlsIndex,threadinfo))
2338 debug(F101,"doicp TlsSetValue failed","",GetLastError());
2339 debug(F101, "doicp a threadinfo block - TlsIndex", "", TlsIndex);
2341 debug(F100, "doicp received a null threadinfo", "", 0);
2351 #endif /* CK_LOGIN */
2354 extern char *lfiles; /* Fake pointer cast */
2357 debug(F100, "doicp: calling macparser", "", 0);
2358 sstate = newparser(1, 1, 0L);
2360 /* ignore null command state */
2368 * process take files the finder gave us.
2370 if ((tlevel == -1) && lfiles)
2373 debug(F100, "doicp: calling parser", "", 0);
2374 sstate = (CHAR) parser(0);
2375 if (sstate == 'c') /* if MAC connect */
2385 If interactive commands were given on the command line (using the
2386 -C "command, command, ..." option), assign them to a macro called
2387 "cl_commands", then execute the macro and leave it defined for
2388 subsequent re-execution if desired.
2390 if (clcmds) { /* Check for -C commands */
2392 x = addmac("cl_commands",clcmds); /* Put macro in table */
2393 if (x > -1) { /* If successful, */
2394 dodo(x,NULL,CF_CMDL); /* set up for macro execution */
2395 while (maclvl > -1) { /* Loop getting macro commands. */
2396 sstate = (CHAR) parser(1);
2397 if (sstate) proto(); /* Enter protocol if requested. */
2403 debug(F100,"doicp calling herald","",0);
2407 while(1) { /* Loop getting commands. */
2408 sstate = (CHAR) parser(0);
2409 if (sstate) proto(); /* Enter protocol if requested. */
2415 ckThreadEnd(threadinfo);
2422 failicp(void * threadinfo)
2423 #else /* CK_ANSIC */
2424 failicp(threadinfo) VOID * threadinfo;
2425 #endif /* CK_ANSIC */
2430 fixcmd(); /* Pop command stacks, etc. */
2432 debug(F100,"ckcmai got interrupt","",0);
2439 docmdfile(void * threadinfo) /* Execute application file */
2440 #else /* CK_ANSIC */
2441 docmdfile(threadinfo) VOID * threadinfo;
2442 #endif /* CK_ANSIC */
2445 concb((char)escape);
2447 if (threadinfo) { /* Thread local storage... */
2448 TlsSetValue(TlsIndex,threadinfo);
2449 debug(F100, "docmdfile called with threadinfo block","", 0);
2450 } else debug(F100, "docmdfile - threadinfo is NULL", "", 0);
2459 #endif /* CK_LOGIN */
2460 debug(F110,"main cmdfil",cmdfil,0);
2462 addmac("\\%0",cmdfil);
2464 dotake(cmdfil); /* Set up the command file */
2465 if (tlevel > -1) /* Remember we did this */
2467 while (tlevel > -1) { /* Execute it until it runs out. */
2468 sstate = parser(1); /* Loop getting commands. */
2469 if (sstate) proto(); /* Enter protocol if requested. */
2476 ckThreadEnd(threadinfo);
2483 failcmdfile(void * threadinfo)
2484 #else /* CK_ANSIC */
2485 failcmdfile(threadinfo) VOID * threadinfo;
2486 #endif /* CK_ANSIC */
2489 cc_clean(); /* Atari: Clean up after ^C-trap. */
2493 conoll("Interrupted during initialization or \
2494 command-line processing.");
2495 conoll("C-Kermit quitting...");
2497 doexit(BAD_EXIT,-1); /* Exit with bad status. */
2503 setprefix(z) int z; { /* Initial control-char prefixing */
2508 ptab[protocol].prefix = prefixing;
2509 debug(F101,"setprefix","",prefixing);
2511 case PX_ALL: /* All */
2513 /* Don't let Clear-Channel be dependent on prefixing */
2514 clearrq = 0; /* Turn off clearchannel, fall thru */
2515 #endif /* COMMENT */
2516 case PX_NON: /* None */
2517 val = (z == PX_ALL) ? 1 : 0;
2523 #endif /* UNPREFIXZERO */
2526 for (i = 127; i < 160; i++) ctlp[i] = val;
2527 ctlp[(unsigned)255] = val;
2528 if (z == PX_NON) { /* These are never safe */
2529 if (network) { /* Assume network = telnet or rlogin */
2530 ctlp[CR] = 1; /* Prefix CR because of NVT rules */
2531 ctlp[XON] = ctlp[XOFF] = 1; /* Because of Telnet server */
2532 ctlp[127] = ctlp[255] = 1; /* Telnet IAC */
2533 ctlp[mystch] = ctlp[mystch+128] = 1; /* Kermit packet start */
2535 ctlp[CR] = ctlp[255] = ctlp[mystch] = ctlp[mystch+128] = 1;
2536 if (flow == FLO_XONX) /* Xon/Xoff forces prefixing */
2537 ctlp[XON] = ctlp[XOFF] = ctlp[XON+128] = ctlp[XOFF+128] = 1;
2542 case PX_CAU: /* Cautious or Minimal */
2544 /* Don't let CLEAR-CHANNEL be dependent on Prefixing */
2545 clearrq = 0; /* Turn off clearchannel */
2546 #endif /* COMMENT */
2547 case PX_WIL: /* Minimal ("wild") */
2548 ctlp[0] = 1; /* Does not include 0 */
2549 for (i = 1; i < 32; i++)
2551 for (i = 127; i < 160; i++)
2553 ctlp[mystch] = ctlp[mystch+128] = 1; /* Kermit start of packet */
2555 ctlp[seol] = ctlp[seol+128] = 1; /* Kermit end */
2556 ctlp[13] = ctlp[141] = 1; /* In case of TELNET (NVT rules) */
2557 ctlp[(unsigned)255] = 1; /* Ditto */
2559 /* ^D, ^J, ^M, or ^U followed by tilde trigger Rlogin escape */
2561 ctlp[4] = ctlp[4+128] = 1; /* In case of RLOGIN */
2562 ctlp[10] = ctlp[10+128] = 1; /* In case of RLOGIN */
2563 ctlp[21] = ctlp[21+128] = 1; /* In case of RLOGIN */
2565 if (flow == FLO_XONX || /* Xon/Xoff forces prefixing these */
2566 prefixing == PX_CAU || /* So does CAUTIOUS */
2567 network) /* Networks too... */
2568 ctlp[XON] = ctlp[XOFF] = ctlp[XON+128] = ctlp[XOFF+128] = 1;
2569 if (prefixing == PX_CAU) { /* Cautious - add some more */
2572 #endif /* UNPREFIXZERO */
2573 ctlp[3] = ctlp[16] = 1; /* ^C, DLE */
2574 ctlp[14] = ctlp[15] = 1; /* SO/SI */
2575 ctlp[24] = ctlp[25] = 1; /* VMS might need these */
2576 ctlp[26] = ctlp[26+128] = 1; /* UNIX suspend */
2577 ctlp[28] = ctlp[29] = ctlp[30] = 1; /* Assorted esc chars */
2578 ctlp[131] = ctlp[141] = ctlp[144] = 1; /* and 8-bit versions */
2579 ctlp[(unsigned)255] = ctlp[156] = ctlp[157] = ctlp[158] = 1;
2583 #endif /* CK_SPEED */
2588 makever() { /* Make version string from pieces */
2593 ck_s_xver = ck_s_ver; /* Fill in C-Kermit version number */
2594 ck_l_xver = ck_l_ver; /* for UNIX, VMS, etc. */
2597 x = strlen(ck_s_name);
2598 y = strlen(ck_s_xver);
2599 if (y + x + 1 < CKVERLEN) {
2600 ckmakmsg(versio,CKVERLEN,ck_s_name," ",ck_s_xver,NULL);
2602 ckstrncpy(versio,"C-Kermit",CKVERLEN);
2607 s = " OPEN SOURCE:"; /* C-Kermit 9.0 and later */
2609 if (CKVERLEN < x + y + 1)
2611 ckstrncat(versio,s,CKVERLEN);
2615 y = strlen(ck_s_who);
2616 if (CKVERLEN < x + y + 1)
2618 ckstrncat(versio,"-",CKVERLEN);
2619 ckstrncat(versio,ck_s_who,CKVERLEN);
2622 y = strlen(ck_s_test);
2623 if (y > 0 && y + x + 1 < CKVERLEN) {
2624 ckstrncat(versio," ",CKVERLEN);
2625 ckstrncat(versio,ck_s_test,CKVERLEN);
2627 y = strlen(ck_s_tver);
2628 if (y > 0 && y + x + 1 < CKVERLEN) {
2629 ckstrncat(versio,".",CKVERLEN);
2630 ckstrncat(versio,ck_s_tver,CKVERLEN);
2634 y = strlen(ck_s_date);
2635 if (y > 0 && y + x + 2 < CKVERLEN) {
2636 ckstrncat(versio,", ",CKVERLEN);
2637 ckstrncat(versio,ck_s_date,CKVERLEN);
2640 xvernum = ck_l_xver;
2641 debug(F110,"Kermit version",versio,0);
2644 union ck_short shortbytes; /* For determining byte order */
2645 int byteorder = 0; /* 0 = Big Endian; 1 = Little Endian */
2647 /* NOTE: MUST BE 0 or 1 - nothing else */
2650 #define SCRIPTLEN 10240
2660 extern int ttnproto;
2661 extern struct urldata g_url;
2664 /* NOTE: debug() doesn't work yet - must use printf's */
2665 printf("URL: %s\n",g_url.sav ? g_url.sav : "(none)");
2666 printf("Type: %s\n",g_url.svc ? g_url.svc : "(none)");
2667 printf("User: %s\n",g_url.usr ? g_url.usr : "(none)");
2668 printf("Pass: %s\n",g_url.psw ? g_url.psw : "(none)");
2669 printf("Host: %s\n",g_url.hos ? g_url.hos : "(none)");
2670 /* printf("Port: %s\n",g_url.por ? g_url.por : "(none)"); */
2671 printf("Path: %s\n",g_url.pth ? g_url.pth : "(none)");
2672 #endif /* COMMENT */
2674 if (!ckstrcmp(g_url.svc,"iksd",-1,0) ||
2675 !ckstrcmp(g_url.svc,"kermit",-1,0)) {
2676 extern char pwbuf[];
2683 printf("?Incomplete IKSD URL\n");
2687 makestr(&g_url.usr,"anonymous");
2689 char * tmpbuf = NULL;
2690 if (!(tmpbuf = (char *)malloc(1024)))
2691 fatal("dourl: out of memory");
2692 if (!ckstrcmp(g_url.usr,"anonymous",-1,0)) {
2693 ckmakmsg(tmpbuf,1024,uidbuf,"@",myhost,NULL);
2694 makestr(&g_url.psw,tmpbuf);
2696 readpass(" Password:",tmpbuf,1024);
2697 makestr(&g_url.psw,tmpbuf);
2702 ttnproto = NP_TELNET;
2706 ckstrncpy(uidbuf,g_url.usr,UIDBUFLEN);
2708 ckstrncpy(pwbuf,g_url.psw,PWBUFL);
2718 g_url.por ? g_url.por : port,
2721 rc = ttopen(ttname,&local,mdmtyp,0);
2727 #endif /* CKLOGDIAL */
2729 printf("?Connection failed: %s\n",g_url.sav);
2732 /* Also need to check here for secure authentication already done */
2738 char * script = NULL;
2739 if (!(script = (char *)malloc(SCRIPTLEN)))
2740 fatal("dourl: out of memory");
2741 if (!g_url.pth) { /* Write the appropriate script */
2743 ckmakxmsg(script,SCRIPTLEN,
2744 "if not eq {\\v(authstate)} {user} ",
2745 "if not eq {\\v(authstate)} {valid} { ",
2746 "remote login ", /* No path */
2747 g_url.usr, /* Just log in and CONNECT */
2750 ", if fail exit 1 {IKSD login failed} }",
2752 NULL,NULL,NULL,NULL);
2753 /* printf("CLCMDS 1: %s\n",script); */
2755 /* does the path specify a file or a directory? */
2756 int len = strlen(g_url.pth);
2757 if (ISDIRSEP(g_url.pth[len-1])) {
2758 ckmakxmsg(script,SCRIPTLEN, /* Directory name given */
2759 "if not eq {\\v(authstate)} {user} \
2760 if not eq {\\v(authstate)} {valid} { remote login ",
2764 ", if fail exit 1 {IKSD login failed} }",
2765 ", set macro error on",
2766 ", set xfer displ brief",
2767 ", set xfer bell off",
2770 ", lineout directory",
2773 /* printf("CLCMDS 2: %s\n",script); */
2775 ckmakxmsg(script,SCRIPTLEN, /* Path given, try to GET */
2776 "if not eq {\\v(authstate)} {user} \
2777 if not eq {\\v(authstate)} {valid} { remote login ",
2781 ", if fail exit 1 {IKSD login failed} }",
2782 ", set xfer displ brief",
2783 ", set xfer bell off",
2786 ", .rc := \\v(status)",
2787 ", if open connection bye",
2790 /* printf("CLCMDS 2: %s\n",script); */
2793 clcmds = script; /* Make this our -C cmdline macro */
2794 /* printf("HAVEURL=%d\n",haveurl); */
2798 if (ckstrcmp(g_url.svc,"telnet",-1,0) &&
2800 ckstrcmp(g_url.svc,"ssh",-1,0) &&
2801 #endif /* SSHBUILTIN */
2802 ckstrcmp(g_url.svc,"ftp",-1,0)) {
2803 printf("?Sorry, %s URLs not supported\n",
2804 g_url.svc ? g_url.svc : "");
2810 #endif /* NETCONN */
2816 If you get complaints about "main: return type is not blah",
2817 define MAINTYPE on the CC command line, e.g. "CFLAGS=-DMAINTYPE=blah"
2818 (where "blah" is int, long, or whatever).
2820 If the complaint is "Attempt to return a value from a function of type void"
2821 then add -DMAINISVOID.
2825 #define MAINTYPE int
2826 #endif /* MAINISVOID */
2827 #endif /* MAINTYPE */
2831 #define MAINTYPE void
2832 #endif /* MAINTYPE */
2833 #endif /* MAINISVOID */
2836 /* On the Apollo, intercept main to insert a cleanup handler */
2838 ckcmai(argc,argv) int argc; char **argv;
2840 #ifdef MAC /* Macintosh */
2844 #ifdef __GNUC__ /* GCC compiler */
2846 main(argc,argv) int argc; char **argv;
2848 #ifdef __DECC /* DEC Alpha with DEC C compiler */
2851 main(argc,argv) int argc; char **argv;
2852 #else /* DEC C compiler, not Alpha */
2855 main(argc,argv) int argc; char **argv;
2856 #endif /* __ALPHA */
2858 #ifdef STRATUS /* Stratus VOS */
2860 main(argc,argv) int argc; char **argv;
2866 Main( int argc, char ** argv )
2870 main(argc,argv) int argc; char **argv;
2873 MAINTYPE /* All others... */
2874 main(argc,argv) int argc; char **argv;
2876 #endif /* STRATUS */
2878 #endif /* __GNUC__ */
2888 #endif /* NOSETKEY */
2891 short *pfha = 016000000036; /* Get around LANG_RT problem */
2892 *pfha = (short) 0; /* No user protection fault handler */
2893 #endif /* datageneral */
2895 int unbuf = 0; /* nonzero for unbuffered stdout */
2897 /* setbuf has to be called on the file descriptor before it is used */
2900 #ifdef NONOSETBUF /* Unbuffered console i/o */
2901 unbuf++; /* as a compile-time option */
2902 #endif /* NONOSETBUF */
2903 if (!unbuf) { /* Or as a command-line selection */
2904 int i, n; /* We have to pre-pre-scan for */
2905 char * s; /* this one. */
2906 for (i = 1; i < argc; i++) {
2908 if (!s) n = 0; else n = (int)strlen(s);
2910 if (!ckstrcmp("--unbuffered",s,n,0)) {
2918 setbuf(stdout,NULL);
2921 /* Do some initialization */
2925 /* Get some RMS default settings. */
2927 #endif /* def __DECC */
2928 #endif /* def VMS */
2931 xargc = xargs = argc; /* Make global copies of argc */
2932 xargv = argv; /* ...and argv. */
2937 zstrip(argv[0],&p); /* Get name we were invoked with */
2939 if (!ckstrcmp(myname,"telnet",-1,0)) howcalled = I_AM_TELNET;
2941 else if (!ckstrcmp(myname,"ktelnet",-1,0)) howcalled = I_AM_TELNET;
2942 #endif /* CK_KERBEROS */
2943 else if (!ckstrcmp(myname,"rlogin",-1,0)) howcalled = I_AM_RLOGIN;
2944 else if (!ckstrcmp(myname,"iksd",-1,0)) howcalled = I_AM_IKSD;
2946 else if (!ckstrcmp(myname,"ftp",-1,0)) howcalled = I_AM_FTP;
2949 else if (!ckstrcmp(myname,"http",-1,0)) howcalled = I_AM_HTTP;
2952 else if (!ckstrcmp(myname,"telnet.exe",-1,0)) howcalled = I_AM_TELNET;
2954 else if (!ckstrcmp(myname,"ssh",-1,0)) howcalled = I_AM_SSH;
2955 else if (!ckstrcmp(myname,"ssh.exe",-1,0)) howcalled = I_AM_SSH;
2956 #endif /* SSHBUILTIN */
2958 else if (!ckstrcmp(myname,"ktelnet.exe",-1,0)) howcalled = I_AM_TELNET;
2959 #endif /* CK_KERBEROS */
2960 else if (!ckstrcmp(myname,"rlogin.exe",-1,0)) howcalled = I_AM_RLOGIN;
2962 else if (!ckstrcmp(myname,"iksdnt",-1,0)) howcalled = I_AM_IKSD;
2963 else if (!ckstrcmp(myname,"iksdnt.exe",-1,0)) howcalled = I_AM_IKSD;
2966 else if (!ckstrcmp(myname,"ftp.exe",-1,0)) howcalled = I_AM_FTP;
2969 else if (!ckstrcmp(myname,"http.exe",-1,0)) howcalled = I_AM_HTTP;
2972 else if (!ckstrcmp(myname,"kermit-sshsub",-1,0)) howcalled = I_AM_SSHSUB;
2975 cmdini(); /* Must come before prescan */
2976 debug(F100,"main cmdini() done","",0);
2978 prescan(0); /* Pre-Check for debugging, etc */
2980 debug(F101,"MAIN feol","",feol);
2981 makever(); /* Put together version strings */
2982 #ifndef NOSETKEY /* Allocate & initialize the keymap */
2983 /* This code has been moved to before sysinit() for K95G */
2984 if (!(keymap = (KEY *) malloc(sizeof(KEY)*KMSIZE)))
2985 fatal("main: no memory for keymap");
2986 if (!(macrotab = (MACRO *) malloc(sizeof(MACRO)*KMSIZE)))
2987 fatal("main: no memory for macrotab");
2988 for (i = 0; i < KMSIZE; i++) {
2989 keymap[i] = (KEY) i;
2992 #endif /* NOSETKEY */
2994 shortbytes.x_short = 0xABCD; /* Get Endianness */
2995 if (shortbytes.x_char[0] == 0xCD) { /* 0 = Big Endian */
2996 byteorder = 1; /* 1 = Little Endian */
2997 bigendian = 0; /* (for clarity in programming) */
2999 byteorder = 0; /* Big Endian */
3002 if (sizeof(CK_OFF_T) == 8) /* Large files and ints? */
3005 if (sysinit() < 0) /* System-dependent initialization. */
3006 fatal("Can't initialize!");
3008 initflg = 1; /* Remember we did. */
3009 debug(F111,"ckcmai myname",myname,howcalled);
3012 getexedir(); /* Compute exedir variable */
3018 If built with -DSYSLOGLEVEL on cc command line, this means we always
3019 do syslogging at the indicated level.
3021 zsyslog(); /* Open syslog */
3022 #else /* SYSLOGLEVEL */
3025 zsyslog(); /* Open syslog */
3027 #endif /* SYSLOGLEVEL */
3028 #endif /* CKSYSLOG */
3031 ini_kerb(); /* Initialize Kerberos data */
3032 #endif /* CK_KERBEROS */
3037 tn_set_modes(); /* Init Telnet Option tables */
3040 #ifdef CK_TTGWSIZ /* Initialize screen dimensions */
3044 if (ttgwsiz() > 0) {
3045 if (tt_rows > 0 && tt_cols > 0) {
3051 #endif /* CK_TTGWSIZ */
3056 SOCKSinit(argv[0]); /* Internet relay package... */
3057 #endif /* CK_SOCKS */
3058 #endif /* TCPSOCKET */
3061 initflow(); /* Initialize flow-control table */
3065 initfloat(); /* Deduce floating-point precision */
3066 #endif /* CKFLOAT */
3070 initxlist(); /* Init exception lists */
3072 #ifdef CK_XYZ /* Initialize protocols... */
3074 #ifdef XYZ_INTERNAL /* XYZMODEM are internal ... */
3077 /* Can't do this for XMODEM because if filename contains a "C" etc... */
3078 initproto(PROTO_X, "rx %s","rx %s", NULL, NULL, NULL, NULL, NULL);
3079 initproto(PROTO_XC,"rc %s","rc %s", NULL, NULL, NULL, NULL, NULL);
3081 initproto(PROTO_X, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
3082 initproto(PROTO_XC,NULL, NULL, NULL, NULL, NULL, NULL, NULL);
3083 #endif /* COMMENT */
3084 initproto(PROTO_Y, "rb","rb", NULL, NULL, NULL, NULL, NULL);
3085 initproto(PROTO_G, "rb","rb", NULL, NULL, NULL, NULL, NULL);
3086 initproto(PROTO_Z, "rz","rz", NULL, NULL, NULL, NULL, NULL);
3087 initproto(PROTO_K,"kermit -ir","kermit -r","kermit -x",NULL,NULL,NULL,NULL);
3088 /* Kermit Must be last */
3090 #else /* XYZMODEM are external protocols ... */
3092 /* s1 s2 s3 s4 s5 s6 s7 */
3093 initproto(PROTO_X, "rx %s","rx %s",NULL,"sx %s","sx -a %s","rx %s", "rx %s");
3094 initproto(PROTO_XC,"rc %s","rc %s",NULL,"sx %s","sx -a %s","rc %s", "rc %s");
3095 initproto(PROTO_Y, "rb", "rb", NULL,"sb %s","sb -a %s","rb", "rb" );
3096 initproto(PROTO_G, "rb", "rb", NULL,"sb %s","sb -a %s","rb", "rb" );
3097 initproto(PROTO_Z, "rz", "rz", NULL,"sz %s","sz -a %s","rz", "rz" );
3098 initproto(PROTO_K, "kermit -ir","kermit -r","kermit -x",NULL,NULL,NULL,NULL);
3099 /* Kermit must be last */
3101 #endif /* XYZ_INTERNAL */
3103 #else /* No XYZMODEM support */
3105 initproto(PROTO_K,"kermit -ir","kermit -r","kermit -x",NULL,NULL,NULL,NULL);
3110 connoi(); /* Console interrupts off */
3114 /* Initialize Kermit and Zmodem Auto-Download Strings */
3115 adl_kstr = strdup("KERMIT READY TO SEND...");
3116 adl_zstr = strdup("rz\r");
3120 initpat(); /* Initialize filename patterns */
3121 #endif /* PATTERNS */
3125 initcsets(); /* Initialize character sets */
3126 #endif /* NOCSETS */
3130 makestr(&cdmsgstr,DFCDMSG);
3131 makelist(cdmsgstr,cdmsgfile,8); /* Initialize CD message filenames */
3132 #endif /* DFCDMSG */
3135 sstate = 0; /* No default start state. */
3138 fatal("Can't allocate i/o buffers!");
3139 #endif /* DYNAMIC */
3144 char stackdata[256];
3145 unsigned int c = 1234, n;
3146 /* try to make a random unsigned int to feed srand() */
3148 /* time.h and MultiNet do not get along */
3152 /* Referenced before set... DELIBERATELY */
3153 for (n = 0; n < sizeof(stackdata); n++) /* IGNORE WARNING */
3154 c += stackdata[n]; /* DELIBERATELY USED BEFORE SET */
3155 srand((unsigned int)c);
3157 #endif /* NORANDOM */
3160 ckhost(myhost,MYHOSTL); /* Name of local host */
3161 debug(F110,"main ckhost",myhost,0);
3165 ckstrncpy(ttname,dftty,TTNAMLEN); /* Set up default tty name. */
3166 local = nolocal ? 0 : dfloc; /* And whether it's local or remote. */
3167 parity = dfprty; /* Set initial parity, */
3169 myindex = getsysix(cksysid); /* System index */
3171 if (local) if (ttopen(ttname,&local,0,0) < 0) {
3173 conol("Can't open device: ");
3177 ckstrncpy(ttname,CTTNAM,TTNAMLEN);
3179 setflow(); /* Set appropriate flow control */
3180 speed = ttgspd(); /* Get transmission speed. */
3185 #ifdef ANYX25 /* All X.25 implementations */
3186 #ifndef IBMX25 /* except IBM have PAD support */
3187 initpad(); /* Initialize X.25 PAD */
3192 if (inibufs(SBSIZ,RBSIZ) < 0) /* Allocate packet buffers */
3193 fatal("Can't allocate packet buffers!");
3195 setprefix(prefixing); /* Set up control char prefixing */
3196 #endif /* NOCKSPEED */
3206 extern int ckxech, ttnet, ttnproto, cmdmsk;
3208 extern int tcp_sendbuf;
3211 extern int tcp_recvbuf;
3214 extern int tcp_keepalive;
3217 extern int tcp_linger, tcp_linger_tmo;
3218 #endif /* SO_LINGER */
3220 extern int tcp_dontroute;
3221 #endif /* SO_DONTROUTE */
3223 extern int tcp_nodelay;
3224 #endif /* TCP_NODELAY */
3226 extern int iklogopen;
3232 fatal("Internet Kermit Service cannot be started at a terminal.");
3235 reliable = xreliable = SET_ON; /* IKSD has reliable connection */
3237 flow = 0; /* No flow control needed */
3239 bgset = 0; /* Not in background */
3240 nopush = 1; /* No external processes */
3241 parity = 0; /* 8 bits ... */
3242 cmdmsk = 0xff; /* all the way */
3246 if (inserver) { /* If IKSD */
3247 doiksdinit(); /* Execute IKSD configuration file */
3249 parser(1); /* (Ignore any file-xfer commands) */
3250 iksdcf = 1; /* IKSD c.f. has been processed */
3252 if (!iklogopen) (VOID) doiklog(); /* Open Kermit-specific log */
3256 setbuf(stdout,NULL); /* Don't buffer the output */
3257 ckstrncpy(ttname,"0",TTNAMLEN); /* not "/dev/tty"... */
3259 local = 0; /* We are in remote mode */
3260 ckxech = 1; /* We will echo */
3262 nettype = NET_TCPB; /* So ttopen() treats the connection */
3263 mdmtyp = -nettype; /* as a network */
3265 debug(F100,"main about to call ttopen() inserver","",0);
3266 if (ttopen(ttname,&local,mdmtyp,0) < 0) { /* Open comm channel */
3267 fatal("can't initialize i/o");
3271 network = 1; /* Does use networking code */
3273 network = 0; /* Does not use networking code */
3275 ttmdm = -1; /* Does not use a modem */
3276 sstelnet = 1; /* Do server-side Telnet negotations */
3277 debug(F111,"MAIN","sstelnet",sstelnet);
3278 ttnet = NET_TCPB; /* Network type is TCP sockets */
3279 ttnproto = NP_TELNET; /* Netword protocol is Telnet */
3281 dbinit(); /* Initialize database record */
3284 #ifdef CK_AUTHENTICATION
3285 /* Before initializating Telnet/Rlogin negotiations, init Kerberos */
3286 ck_auth_init(ckgetpeer(),"","",0);
3287 #endif /* CK_AUTHENTICATION */
3291 x = socket_ioctl(0,FIONBIO,&on);
3292 debug(F101,"main FIONBIO","",x);
3293 #endif /* NON_BLOCK_IO */
3296 x = setsockopt(0, SOL_SOCKET, SO_OOBINLINE, (char *)&on, sizeof(on));
3297 debug(F101,"main SO_OOBINLINE","",x);
3298 #endif /* SO_OOBINLINE */
3304 no_delay(0,tcp_nodelay);
3305 #endif /* TCP_NODELAY */
3307 keepalive(0,tcp_keepalive);
3308 #endif /* SO_KEEPALIVE */
3310 ck_linger(0,tcp_linger, tcp_linger_tmo);
3311 #endif /* SO_LINGER */
3313 dontroute(0,tcp_dontroute);
3314 #endif /* SO_DONTROUTE */
3316 sendbuf(0,tcp_sendbuf);
3317 #endif /* SO_SNDBUF */
3319 recvbuf(0,tcp_recvbuf);
3320 #endif /* SO_RCVBUF */
3321 #endif /* SOL_SOCKET */
3322 #endif /* datageneral */
3323 #endif /* NOTCPOPTS */
3326 if (ck_ssleay_is_installed()) {
3327 if (!ssl_tn_init(SSL_SERVER)) {
3328 if (bio_err != NULL) {
3329 BIO_printf(bio_err,"do_ssleay_init() failed\r\n");
3330 ERR_print_errors(bio_err);
3333 fprintf(stderr,"do_ssleay_init() failed\r\n");
3334 ERR_print_errors_fp(stderr);
3345 /* otherwise we will continue to accept the connection */
3346 /* without SSL or TLS support unless required. */
3347 if ( TELOPT_DEF_S_ME_MODE(TELOPT_START_TLS) != TN_NG_MU )
3348 TELOPT_DEF_S_ME_MODE(TELOPT_START_TLS) = TN_NG_RF;
3349 if ( TELOPT_DEF_S_U_MODE(TELOPT_START_TLS) != TN_NG_MU )
3350 TELOPT_DEF_S_U_MODE(TELOPT_START_TLS) = TN_NG_RF;
3351 if ( TELOPT_DEF_C_ME_MODE(TELOPT_START_TLS) != TN_NG_MU )
3352 TELOPT_DEF_C_ME_MODE(TELOPT_START_TLS) = TN_NG_RF;
3353 if ( TELOPT_DEF_C_U_MODE(TELOPT_START_TLS) != TN_NG_MU )
3354 TELOPT_DEF_C_U_MODE(TELOPT_START_TLS) = TN_NG_RF;
3356 if ( ck_ssl_incoming(0) < 0 ) {
3364 tn_ini(); /* Start Telnet negotiation now */
3368 debug(F101,"main argc after prescan()","",argc);
3370 /* Now process any relevant environment variables */
3373 getdialenv(); /* Dialing */
3375 ndinit(); /* Initialize network directory info */
3376 getnetenv(); /* Network directories */
3377 #endif /* NETCONN */
3382 dofast(); /* By now FAST defaults should be OK */
3383 #endif /* CK_FAST */
3387 ikslogin(); /* IKSD Login and other stuff */
3396 if (howcalled == I_AM_SSHSUB) {
3397 reliable = 1; /* We say the connection is reliable */
3398 xreliable = 1; /* And that we said it was */
3399 setreliable = 1; /* And pretend the "user" did too */
3400 xfinish = 1; /* For REMOTE HELP response */
3401 mdmtyp = 0; /* For ttopen() */
3402 ckstrncpy(ttname,"0",TTNAMLEN+1); /* Use file descriptor 0 */
3403 local = 0; /* And force remote mode */
3404 ttopen(ttname,&local,mdmtyp,0); /* Open the "connection" */
3405 sstate = 'x'; /* Initial state is Server */
3406 proto(); /* Enter protocol */
3407 doexit(GOOD_EXIT,xitsta); /* Exit when done */
3409 debug(F111,"howcalled",myname,howcalled);
3413 #else /* NOCCTRAP */
3414 debug(F100,"main about to cc_execute","",0);
3416 cc_execute( ckjaddr(cmjbuf), dotakeini, failtakeini );
3417 #endif /* NOCCTRAP */
3419 debug(F111,"main 2 cfilef",cmdfil,cfilef);
3420 if (cmdfil[0]) { /* If we got one (see prescan())... */
3422 docmdfile(0); /* execute it. */
3423 #else /* NOCCTRAP */
3425 cc_execute( ckjaddr(cmjbuf), docmdfile, failcmdfile );
3426 #endif /* NOCCTRAP */
3428 #ifndef OS2 /* Preserve name so we can delete it */
3429 *cmdfil = '\0'; /* Done, nullify the file name */
3434 /* Look for a UNIX-style command line... */
3438 debug(F101,"main argc","",argc);
3440 iniopthlp(); /* Initialize cmdline arg help */
3445 #endif /* COMMENT */
3446 argc > 1) { /* Command line arguments? */
3447 sstate = (CHAR) cmdlin(); /* Yes, parse. */
3450 if (haveurl) { /* Was a URL given? */
3451 dourl(); /* if so, do it. */
3454 #endif /* NETCONN */
3456 zstate = sstate; /* Remember sstate around protocol */
3457 debug(F101,"main zstate","",zstate);
3461 if (cflg) { /* Connect first if requested */
3467 #endif /* NOLOCAL */
3472 if (displa) concb((char)escape); /* (for console "interrupts") */
3473 #endif /* NOLOCAL */
3476 #else /* NOCCTRAP */
3478 cc_execute( ckjaddr(cmjbuf), docmdline, failcmdline );
3479 #endif /* NOCCTRAP */
3485 If a command-line action argument was given and -S ("stay") was not given,
3488 if ((cflg || cnflg || zstate) && !stayflg)
3490 doexit(GOOD_EXIT,xitsta); /* Exit with good status */
3496 if ((cflg || cnflg) && tn_exit && ttchk() < 0)
3497 doexit(GOOD_EXIT,xitsta); /* Exit with good status */
3498 #endif /* NETCONN */
3499 if (exitonclose && !network &&
3500 (carrier != CAR_OFF && (ttgmdm() & BM_DCD) == 0))
3501 doexit(GOOD_EXIT,xitsta); /* Exit with good status */
3502 if (exitonclose && network && ttchk() < 0)
3503 doexit(GOOD_EXIT,xitsta); /* Exit with good status */
3506 #endif /* NOLOCAL */
3510 #ifdef NOICP /* No interactive command parser */
3514 /* Command-line-only version */
3515 fatal("?No command-line options given - type 'kermit -h' for help");
3517 #else /* Neither one! */
3520 proto(); /* So go into server mode */
3521 doexit(GOOD_EXIT,xitsta); /* exit with good status */
3524 #else /* not NOICP */
3526 If no action requested on command line, or if -S ("stay") was included,
3527 enter the interactive command parser.
3530 herald(); /* Display program herald. */
3533 debug(F100,"main NOCCTRAP setting interrupt trap","",0);
3534 setint(); /* Set up command interrupt traps */
3536 #else /* NOCCTRAP */
3538 debug(F100,"main setting interrupt trap","",0);
3539 setint(); /* Set up command interrupt traps */
3540 if (!cc_execute(ckjaddr(cmjbuf), doicp, failicp))
3543 #endif /* NOCCTRAP */
3547 #endif /* MAINISVOID */
3551 /* Allocate file i/o buffers */
3553 char *zinbuffer = NULL, *zoutbuffer = NULL;
3557 zinbuffer = (char *)malloc(INBUFSIZE);
3558 if (!zinbuffer) return(-1);
3559 zoutbuffer = (char *)malloc(zobufsize);
3560 debug(F101,"zoutbuffer malloc","",zobufsize);
3561 if (!zoutbuffer) return(-1);
3562 debug(F100,"getiobs ok","",0);
3565 #endif /* DYNAMIC */