home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / cku196.zip / ckcpro.c < prev    next >
C/C++ Source or Header  |  2000-01-06  |  106KB  |  3,488 lines

  1.  
  2. /* WARNING -- This C source program generated by Wart preprocessor. */
  3. /* Do not edit this file; edit the Wart-format source file instead, */
  4. /* and then run it through Wart to produce a new C source file.     */
  5.  
  6. /* Wart Version Info: */
  7. char *wartv = "Wart Version 2.14, 10 Nov 1999";
  8.  
  9. char *protv =                                                     /* -*-C-*- */
  10. "C-Kermit Protocol Module 7.0.135, 1 Jan 2000";
  11.  
  12. int kactive = 0;            /* Kermit protocol is active */
  13.  
  14. #define PKTZEROHACK
  15.  
  16. /* C K C P R O  -- C-Kermit Protocol Module, in Wart preprocessor notation. */
  17. /*
  18.   Author: Frank da Cruz <fdc@columbia.edu>,
  19.   Columbia University Academic Information Systems, New York City.
  20.  
  21.   Copyright (C) 1985, 2000,
  22.     Trustees of Columbia University in the City of New York.
  23.     All rights reserved.  See the C-Kermit COPYING.TXT file or the
  24.     copyright text in the ckcmai.c module for disclaimer and permissions.
  25. */
  26. #ifndef NOXFER
  27. #include "ckcsym.h"
  28. #include "ckcdeb.h"
  29. #include "ckcasc.h"
  30. #include "ckcker.h"
  31. #ifdef OS2
  32. #ifndef NT
  33. #define INCL_NOPM
  34. #define INCL_VIO            /* Needed for ckocon.h */
  35. #include <os2.h>
  36. #undef COMMENT
  37. #endif /* NT */
  38. #include "ckocon.h"
  39. #endif /* OS2 */
  40.  
  41. /*
  42.  Note -- This file may also be preprocessed by the UNIX Lex program, but
  43.  you must indent the above #include statements before using Lex, and then
  44.  restore them to the left margin in the resulting C program before compilation.
  45.  Also, the invocation of the "wart()" function below must be replaced by an
  46.  invocation  of the "yylex()" function.  It might also be necessary to remove
  47.  comments in the (%)(%)...(%)(%) section.
  48. */
  49.  
  50. /* State definitions for Wart (or Lex) */
  51. #define ipkt 1
  52. #define rfile 2
  53. #define rattr 3
  54. #define rdpkt 4
  55. #define ssinit 5
  56. #define ssfile 6
  57. #define ssattr 7
  58. #define ssdata 8
  59. #define sseof 9
  60. #define sseot 10
  61. #define serve 11
  62. #define generic 12
  63. #define get 13
  64. #define rgen 14
  65. #define ssopkt 15
  66. #define ropkt 16
  67.  
  68. _PROTOTYP(static VOID xxproto,(void));
  69. _PROTOTYP(int wart,(void));
  70. _PROTOTYP(static int sgetinit,(int,int));
  71. _PROTOTYP(int sndspace,(int));
  72.  
  73. /* External C-Kermit variable declarations */
  74.   extern char *versio, *srvtxt, *cmarg, *cmarg2, **cmlist, *rf_err;
  75.   extern char *cdmsgfile[];
  76.   extern char * snd_move, * snd_rename, * srimsg;
  77.   extern char filnam[], fspec[], ttname[], ofn1[];
  78.   extern CHAR sstate, *srvptr, *data;
  79.   extern int timint, rtimo, nfils, hcflg, xflg, flow, mdmtyp, network;
  80.   extern int oopts, omode, oname, opath, nopush, isguest;
  81.   extern int rejection, moving, fncact, bye_active, urserver, fatalio;
  82.   extern int protocol, prefixing, filcnt, carrier, fnspath, interrupted;
  83.   extern int recursive, inserver, nzxopts, idletmo, srvidl, xfrint;
  84.   extern struct ck_p ptab[];
  85.   extern int remfile, rempipe, xferstat, filestatus, wearealike, fackpath;
  86.   extern char * remdest;
  87.  
  88. #ifdef PKTZEROHACK
  89. #define PKTZEROLEN 32
  90. static char ipktack[PKTZEROLEN];
  91. static int ipktlen = 0;
  92. #endif /* PKTZEROHACK */
  93.  
  94. static int s_timint = -1;        /* For saving timeout value */
  95. static int havefs = 0;
  96. #ifdef CK_LOGIN
  97. static int logtries = 0;
  98. #endif /* CK_LOGIN */
  99.  
  100. #ifdef STREAMING
  101. extern int streaming, streamok;
  102. static int cancel = 0;
  103.  
  104. int fackbug = 0;
  105.  
  106. static VOID
  107. streamon() {
  108.     if (streamok) {
  109.     debug(F100,"streamon","",0);
  110.     streaming = 1;
  111.     timint = 0;            /* No timeouts while streaming. */
  112.     }
  113. }
  114.  
  115. #ifdef COMMENT                /* (not used) */
  116. static VOID
  117. streamoff() {
  118.     if (streaming) {
  119.     debug(F100,"streamoff","",0);
  120.     streaming = 0;
  121.     timint = s_timint;        /* Restore timeout */
  122.     }
  123. }
  124. #endif /* COMMENT */
  125. #else /* STREAMING */
  126. #define streamon()
  127. #define streamoff()
  128. #endif /* STREAMING */
  129.  
  130. #ifndef NOSPL
  131. _PROTOTYP( int addmac, (char *, char *) );
  132. _PROTOTYP( int zzstring, (char *, char **, int *) );
  133. #endif /* NOSPL */
  134. #ifndef NOICP
  135. _PROTOTYP( int cmdsrc, (void) );
  136. #endif /* NOICP */
  137.  
  138. #ifndef NOSERVER
  139.   extern char * x_user, * x_passwd, * x_acct;
  140.   extern int x_login, x_logged;
  141. #endif /* NOSERVER */
  142.  
  143. #ifdef CK_SPEED
  144.   extern int ttnproto;            /* Network protocol */
  145.   extern short ctlp[];            /* Control-character prefix table */
  146. #endif /* CK_SPEED */
  147.  
  148. #include "ckcnet.h"
  149. #ifdef TNCODE
  150.   extern int tn_b_nlm, tn_b_xfer, tn_nlm;
  151. #ifdef CK_ENCRYPTION
  152.   extern int tn_no_encrypt_xfer;
  153. #endif /* CK_ENCRYPTION */
  154. #endif /* TNCODE */
  155.  
  156. #ifdef TCPSOCKET
  157. #ifndef NOLISTEN
  158.   extern int tcpsrfd;
  159. #endif /* NOLISTEN */
  160. #endif /* TCPSOCKET */
  161.  
  162.   extern int cxseen, czseen, server, srvdis, local, displa, bctu, bctr, bctl;
  163.   extern int quiet, tsecs, parity, backgrd, nakstate, atcapu, wslotn, winlo;
  164.   extern int wslots, success, xitsta, rprintf, discard, cdtimo, keep, fdispla;
  165.   extern int timef, stdinf, rscapu, sendmode, epktflg, epktrcvd, epktsent;
  166.   extern int binary, fncnv;
  167.   extern long speed, ffc, crc16, calibrate, dest;
  168. #ifdef COMMENT
  169.   extern char *TYPCMD, *DIRCMD, *DIRCM2;
  170. #endif /* COMMENT */
  171. #ifndef OS2
  172.   extern char *SPACMD, *SPACM2, *WHOCMD;
  173. #endif /* OS2 */
  174.   extern CHAR *rdatap;
  175.   extern struct zattr iattr;
  176.  
  177. #ifdef VMS
  178.   extern int batch;
  179. #endif /* VMS */
  180.  
  181. #ifdef GFTIMER
  182.   extern CKFLOAT fptsecs;
  183. #endif /* GFTIMER */
  184.  
  185.   extern CHAR *srvcmd;
  186.   extern CHAR *epktmsg;
  187.  
  188. #ifdef CK_TMPDIR
  189. extern int f_tmpdir;            /* Directory changed temporarily */
  190. extern char savdir[];            /* For saving current directory */
  191. extern char * dldir;
  192. #endif /* CK_TMPDIR */
  193.  
  194.   extern int query;            /* Query-active flag */
  195. #ifndef NOSPL
  196.   extern int cmdlvl;
  197.   char querybuf[QBUFL+1] = { NUL, NUL }; /* QUERY response buffer */
  198.   char *qbufp = querybuf;        /* Pointer to it */
  199.   int qbufn = 0;            /* Length of data in it */
  200. #else
  201.   extern int tlevel;
  202. #endif /* NOSPL */
  203.  
  204. #ifndef NOICP
  205.   extern int escape;
  206. #endif /* NOICP */
  207. /*
  208.   If the following flag is nonzero when the protocol module is entered,
  209.   then server mode persists for exactly one transaction, rather than
  210.   looping until BYE or FINISH is received.
  211. */
  212. extern int justone;
  213.  
  214. static int r_save = -1;
  215. static int p_save = -1;
  216.  
  217. static VOID
  218. rdebug() {
  219.     if (server)
  220.       debug(F111,"RESUME","server=1",justone);
  221.     else
  222.       debug(F111,"RESUME","server=0",justone);
  223. }
  224.  
  225. /* Flags for the ENABLE and DISABLE commands */
  226. extern int
  227.   en_cpy, en_cwd, en_del, en_dir, en_fin, en_get, en_bye, en_mai, en_pri,
  228.   en_hos, en_ren, en_sen, en_spa, en_set, en_typ, en_who, en_ret, en_xit,
  229.   en_mkd, en_rmd;
  230. #ifndef NOSPL
  231. extern int en_asg, en_que;
  232. #endif /* NOSPL */
  233. extern int what, lastxfer;
  234.  
  235. /* Global variables declared here */
  236.  
  237.   int whatru = 0;            /* What are you. */
  238.   int whatru2 = 0;            /* What are you, cont'd. */
  239.  
  240. /* Local variables */
  241.  
  242.   static char vstate = 0;          /* Saved State   */
  243.   static char vcmd = 0;            /* Saved Command */
  244.   static int reget = 0;            /* Flag for executing REGET */
  245.   static int retrieve = 0;        /* Flag for executing RETRIEVE */
  246.   static int opkt = 0;            /* Send Extended GET packet */
  247.  
  248.   static int x;                /* General-purpose integer */
  249.   static char *s;            /* General-purpose string pointer */
  250.  
  251. /* Macros - Note, BEGIN is predefined by Wart (and Lex) as "state = ", */
  252. /* BEGIN is NOT a GOTO! */
  253. #define TINIT if (tinit(1) < 0) return(-9)
  254. #define SERVE { TINIT; resetc(); nakstate=1; what=W_NOTHING; cmarg2=""; \
  255. sendmode=SM_SEND; havefs=0; recursive=r_save; fnspath=p_save; BEGIN serve; }
  256. #define RESUME { rdebug(); if (!server) { return(0); } else \
  257. if (justone) { justone=0; return(0); } else { SERVE; } }
  258.  
  259. #ifdef GFTIMER
  260. #define QUIT x=quiet; quiet=1; clsif(); clsof(1); tsecs=gtimer(); \
  261.  fptsecs=gftimer(); quiet=x; return(success)
  262. #else
  263. #define QUIT x=quiet; quiet=1; clsif(); clsof(1); tsecs=gtimer(); quiet=x; \
  264.  return(success)
  265. #endif /* GFTIMER */
  266.  
  267. /*
  268.   By late 1999, the big switch() statement generated from the following state
  269.   table began choking even gcc, so here we extract the code from the larger
  270.   states into static void routines to reduce the size of the cases and the
  271.   switch() overall.  The routines follow the state table; the prototypes are
  272.   here.  Each of these routines simply contains the text from the
  273.   corresponding case, but with return(-1) added in appropriate places; see
  274.   instructions after the state table switcher.
  275. */
  276. static int rc;                /* Return code for these routines */
  277. static int rcv_s_pkt();            /* Received an S packet */
  278. static int rcv_firstdata();        /* Received first Data packet */
  279. static int rcv_shortreply();        /* Short reply to a REMOTE command  */
  280. static int srv_query();            /* Server answers an query */
  281. static int srv_copy();            /* Server executes REMOTE COPY */
  282. static int srv_rename();        /* Server executes REMOTE RENAME */
  283. static int srv_login();            /* Server executes REMOTE LOGIN */
  284. static int srv_timeout();        /* Server times out */
  285.  
  286.  
  287. #define BEGIN state =
  288.  
  289. int state = 0;
  290.  
  291. int
  292. wart()
  293. {
  294.     int c,actno;
  295.     extern char tbl[];
  296.     while (1) {
  297.     c = input() - 32;
  298.     debug(F000,"PROTO input",ckitoa(state),c+32);
  299.     if (c < 0 || c > 95) c = 0;
  300.     if ((actno = tbl[c + state*96]) != -1)
  301.         switch(actno) {
  302. case 1:
  303.     { TINIT;                /* Send file(s) */
  304.     if (sinit() > 0) BEGIN ssinit;
  305.        else RESUME; }
  306.     break;
  307. case 2:
  308.     { TINIT; nakstate = 1; BEGIN get; }
  309.     break;
  310. case 3:
  311.     {                    /* Client sends a GET command */
  312.     TINIT;
  313.     vstate = get;
  314.     reget = 0;
  315.     retrieve = 0;
  316.     opkt = 0;
  317.     vcmd = 0;
  318. #ifdef PKTZEROHACK
  319.     ipktack[0] = NUL;
  320. #endif /* PKTZEROHACK */
  321.     if (sipkt('I') >= 0)
  322.       BEGIN ipkt;
  323.     else
  324.       RESUME;
  325. }
  326.     break;
  327. case 4:
  328.     {                    /* Client sends a RETRIEVE command */
  329.     TINIT;
  330.     vstate = get;
  331.     reget = 0;
  332.     retrieve = 1;
  333.     opkt = 0;
  334.     vcmd = 0;
  335.     if (sipkt('I') >= 0)
  336.       BEGIN ipkt;
  337.     else
  338.       RESUME;
  339. }
  340.     break;
  341. case 5:
  342.     {                    /* Client sends a REGET command */
  343.     TINIT;
  344.     vstate = get;
  345.     reget = 1;
  346.     retrieve = 0;
  347.     opkt = 0;
  348.     vcmd = 0;
  349.     if (sipkt('I') >= 0)
  350.       BEGIN ipkt;
  351.     else
  352.       RESUME;
  353. }
  354.     break;
  355. case 6:
  356.     {                    /* Client sends Extended GET Packet */
  357.     TINIT;
  358.     vstate = get;
  359.     reget = oopts & GOPT_RES;
  360.     retrieve = oopts & GOPT_DEL;
  361.     opkt = 1;
  362.     vcmd = 0;
  363.     if (sipkt('I') >= 0)
  364.       BEGIN ipkt;
  365.     else
  366.       RESUME;
  367. }
  368.     break;
  369. case 7:
  370.     {                    /* Client sends a Host command */
  371.     TINIT;
  372.     vstate = rgen;
  373.     vcmd = 'C';
  374.     if (sipkt('I') >= 0)
  375.       BEGIN ipkt;
  376.     else
  377.       RESUME;
  378. }
  379.     break;
  380. case 8:
  381.     { TINIT;                /* Client sends a Kermit command */
  382.     vstate = rgen;
  383.     vcmd = 'K';
  384.     if (sipkt('I') >= 0)
  385.       BEGIN ipkt;
  386.     else
  387.       RESUME;
  388. }
  389.     break;
  390. case 9:
  391.     {                    /* Client sends a REMOTE command */
  392.     TINIT;
  393.     vstate = rgen;
  394.     vcmd = 'G';
  395.     if (sipkt('I') >= 0)
  396.       BEGIN ipkt;
  397.     else
  398.       RESUME;
  399. }
  400.     break;
  401. case 10:
  402.     {                    /* Enter server mode */
  403.     int x;
  404.     x = justone;
  405.     if (!ENABLED(en_del)) {        /* If DELETE is disabled */
  406.     if (fncact == XYFX_B ||        /* undo any file collision action */
  407.         fncact == XYFX_U ||        /* that could result in deletion or */
  408.         fncact == XYFX_A ||        /* modification of existing files. */
  409.         fncact == XYFX_X) {
  410. #ifndef NOICP
  411.         extern int g_fncact;
  412.         g_fncact = fncact;        /* Save current setting */
  413. #endif /* NOICP */
  414.         fncact = XYFX_R;        /* Change to RENAME */
  415.         debug(F101,"server DELETE disabled so fncact RENAME","",fncact);
  416.     }
  417.     }
  418.     SERVE;                /* tinit() clears justone... */
  419.     justone = x;
  420. #ifdef IKSDB
  421.     if (ikdbopen) slotstate(what, "SERVER", "", "");
  422. #endif /* IKSDB */
  423. }
  424.     break;
  425. case 11:
  426.     {
  427.     int b1 = 0, b2 = 0;
  428.     if (!data) TINIT;            /* "ABEND" -- Tell other side. */
  429. #ifndef pdp11
  430.     if (epktflg) {            /* If because of E-PACKET command */
  431.     b1 = bctl; b2 = bctu;        /* Save block check type */
  432.     bctl = bctu = 1;        /* set it to 1 */
  433.     }
  434. #endif /* pdp11 */
  435.     errpkt((CHAR *)"User cancelled");    /* Send the packet */
  436. #ifndef pdp11
  437.     if (epktflg) {            /* Restore the block check */
  438.     epktflg = 0;
  439.     bctl = b1; bctu = b2;
  440.     }
  441. #endif /* pdp11 */
  442.     success = 0;
  443.     return(0);                /* Return from protocol. */
  444. }
  445.     break;
  446. case 12:
  447.     {        /* Receive Send-Init packet. */
  448.     rc = rcv_s_pkt();
  449.     debug(F101,"rcv_s_pkt","",rc);
  450.     if (rc > -1) return(rc);        /* (see below) */
  451. }
  452.     break;
  453. case 13:
  454.     {                /* Get ack for I-packet */
  455.     int x = 0;
  456. #ifdef PKTZEROHACK
  457.     ckstrncpy(ipktack,(char *)rdatap,PKTZEROLEN); /* Save a copy of the ACK */
  458.     ipktlen = strlen(ipktack);
  459. #endif /* PKTZEROHACK */
  460.     spar(rdatap);            /* Set parameters */
  461.     winlo = 0;                /* Set window-low back to zero */
  462.     debug(F101,"<ipkt>Y winlo","",winlo);
  463.     urserver = 1;            /* So I know I'm talking to a server */
  464.     if (vcmd) {                /* If sending a generic command */
  465.     if (tinit(0) < 0) return(-9);    /* Initialize many things */
  466.     x = scmd(vcmd,(CHAR *)cmarg);    /* Do that */
  467.     if (x >= 0) x = 0;        /* (because of O-Packet) */
  468.     debug(F101,"proto G packet scmd","",x);
  469.     vcmd = 0;            /* and then un-remember it. */
  470.     } else if (vstate == get) {
  471.     debug(F101,"REGET sstate","",sstate);
  472.     x = srinit(reget, retrieve, opkt); /* GET or REGET, etc */
  473.     }
  474.     if (x < 0) {            /* If command was too long */
  475.     if (!srimsg)
  476.       srimsg = "Error sending string";
  477.     errpkt((CHAR *)srimsg);        /* cancel both sides. */
  478.     success = 0;
  479.     RESUME;
  480.     } else if (x > 0) {            /* Need to send more O-Packets */
  481.     BEGIN ssopkt;
  482.     } else {
  483.     rtimer();            /* Reset the elapsed seconds timer. */
  484. #ifdef GFTIMER
  485.     rftimer();
  486. #endif /* GFTIMER */
  487.     winlo = 0;            /* Window back to 0, again. */
  488.     debug(F101,"<ipkt>Y vstate","",vstate);
  489.     nakstate = 1;            /* Can send NAKs from here. */
  490.     BEGIN vstate;            /* Switch to desired state */
  491.     }
  492. }
  493.     break;
  494. case 14:
  495.     {                /* Got ACK to O-Packet */
  496.     debug(F100,"CPCPRO <ssopkt>Y","",0);
  497.     x = sopkt();
  498.     debug(F101,"CPCPRO <ssopkt>Y x","",x);
  499.     if (x < 0) {            /* If error */
  500.     errpkt((CHAR *)srimsg);        /* cancel both sides. */
  501.     success = 0;
  502.     RESUME;
  503.     } else if (x == 0) {        /* This was the last O-Packet */
  504.     rtimer();            /* Reset the elapsed seconds timer. */
  505. #ifdef GFTIMER
  506.     rftimer();
  507. #endif /* GFTIMER */
  508.     winlo = 0;            /* Window back to 0, again. */
  509.     debug(F101,"<ssopkt>Y winlo","",winlo);
  510.     nakstate = 1;            /* Can send NAKs from here. */
  511.     BEGIN vstate;            /* Switch to desired state */
  512.     }
  513.     debug(F101,"CPCPRO <ssopkt>Y not changing state","",x);
  514. }
  515.     break;
  516. case 15:
  517.     {                /* Ignore Error reply to I packet */
  518.     int x = 0;
  519.     winlo = 0;                /* Set window-low back to zero */
  520.     debug(F101,"<ipkt>E winlo","",winlo);
  521.     if (vcmd) {                /* In case other Kermit doesn't */
  522.     if (tinit(0) < 0) return(-9);
  523.     x = scmd(vcmd,(CHAR *)cmarg);    /* understand I-packets. */
  524.     if (x >= 0) x = 0;        /* (because of O-Packet) */
  525.     vcmd = 0;            /* Otherwise act as above... */
  526.     } else if (vstate == get) x = srinit(reget, retrieve, opkt);
  527.     if (x < 0) {            /* If command was too long */
  528.     errpkt((CHAR *)srimsg);        /* cancel both sides. */
  529.     success = 0;
  530.     RESUME;
  531.     } else if (x > 0) {            /* Need to send more O-Packets */
  532.     BEGIN ssopkt;
  533.     } else {
  534.     winlo = 0;            /* Back to packet 0 again. */
  535.     debug(F101,"<ipkt>E winlo","",winlo);
  536.     freerpkt(winlo);        /* Discard the Error packet. */
  537.     nakstate = 1;            /* Can send NAKs from here. */
  538.     BEGIN vstate;
  539.     }
  540. }
  541.     break;
  542. case 16:
  543.     {        /* Resend of previous I-pkt ACK, same seq number! */
  544.     srinit(reget, retrieve, opkt);    /* Send the GET packet again. */
  545. }
  546.     break;
  547. case 17:
  548.     {                /* Get I-packet */
  549. #ifndef NOSERVER
  550.     spar(rdatap);            /* Set parameters from it */
  551.     ack1(rpar());            /* Respond with our own parameters */
  552. #ifdef COMMENT
  553.     pktinit();                /* Reinitialize packet numbers */
  554. #else
  555. #ifdef COMMENT
  556.     /* This can't be right - it undoes the stuff we just negotiated */
  557.     x = justone;
  558.     tinit(1);                /* Reinitialize EVERYTHING */
  559.     justone = x;            /* But this... */
  560. #else
  561.     tinit(0);                /* Initialize most things */
  562. #endif /* COMMENT */
  563. #endif /* COMMENT */
  564. #endif /* NOSERVER */
  565. }
  566.     break;
  567. case 18:
  568.     {                /* GET */
  569. #ifndef NOSERVER
  570.     if (x_login && !x_logged) {
  571.     errpkt((CHAR *)"Login required");
  572.     SERVE;
  573.     } else if (sgetinit(0,0) < 0) {
  574.     RESUME;
  575.     } else {
  576. #ifdef CKSYSLOG
  577.     if (ckxsyslog >= SYSLG_PR && ckxlogging)
  578.       cksyslog(SYSLG_PR, 1, "server", "GET", (char *)srvcmd);
  579. #endif /* CKSYSLOG */
  580.     BEGIN ssinit;
  581.     }
  582. #endif /* NOSERVER */
  583. }
  584.     break;
  585. case 19:
  586.     {                /* GET /DELETE (RETRIEVE) */
  587. #ifndef NOSERVER
  588.     if (x_login && !x_logged) {
  589.     errpkt((CHAR *)"Login required");
  590.     RESUME;
  591.     } else if (!ENABLED(en_del)) {
  592.     errpkt((CHAR *)"Deleting files is disabled");
  593.     RESUME;
  594.     } else if (sgetinit(0,0) < 0) {
  595.     RESUME;
  596.     } else {
  597.     moving = 1;
  598. #ifdef CKSYSLOG
  599.     if (ckxsyslog >= SYSLG_PR && ckxlogging)
  600.       cksyslog(SYSLG_PR, 1, "server", "GET /DELETE", (char *)srvcmd);
  601. #endif /* CKSYSLOG */
  602.     BEGIN ssinit;
  603.     }
  604. #endif /* NOSERVER */
  605. }
  606.     break;
  607. case 20:
  608.     {                /* GET /RECURSIVE */
  609. #ifndef NOSERVER
  610.     recursive = 1;            /* Set these before sgetinit() */
  611.     if (fnspath == PATH_OFF)
  612.       fnspath = PATH_REL;        /* Don't worry, they will be */
  613.     if (x_login && !x_logged) {        /* reset next time through. */
  614.     errpkt((CHAR *)"Login required");
  615.     RESUME;
  616.     } else if (sgetinit(0,0) < 0) {
  617.     RESUME;
  618.     } else {
  619. #ifdef CKSYSLOG
  620.     if (ckxsyslog >= SYSLG_PR && ckxlogging)
  621.       cksyslog(SYSLG_PR, 1, "server", "GET /RECURSIVE", (char *)srvcmd);
  622. #endif /* CKSYSLOG */
  623.     BEGIN ssinit;
  624.     }
  625. #endif /* NOSERVER */
  626. }
  627.     break;
  628. case 21:
  629.     {                /* GET /RECURSIVE /DELETE */
  630. #ifndef NOSERVER
  631.     recursive = 1;            /* Set these before sgetinit() */
  632.     if (fnspath == PATH_OFF)
  633.       fnspath = PATH_REL;        /* Don't worry, they will be */
  634.     moving = 1;                /* reset next time through. */
  635.     if (x_login && !x_logged) {
  636.     errpkt((CHAR *)"Login required");
  637.     RESUME;
  638.     } else if (!ENABLED(en_del)) {
  639.     errpkt((CHAR *)"Deleting files is disabled");
  640.     RESUME;
  641.     } else if (sgetinit(0,0) < 0) {
  642.     RESUME;
  643.     } else {
  644. #ifdef CKSYSLOG
  645.     if (ckxsyslog >= SYSLG_PR && ckxlogging)
  646.       cksyslog(SYSLG_PR,1,"server",
  647.            "GET /RECURSIVE /DELETE",(char *)srvcmd);
  648. #endif /* CKSYSLOG */
  649.     BEGIN ssinit;
  650.     }
  651. #endif /* NOSERVER */
  652. }
  653.     break;
  654. case 22:
  655.     {                /* GET /RECOVER (REGET) */
  656. #ifndef NOSERVER
  657.     if (x_login && !x_logged) {
  658.     errpkt((CHAR *)"Login required");
  659.     SERVE;
  660.     } else if (sgetinit(1,0) < 0) {
  661.     RESUME;
  662.     } else {
  663. #ifdef CKSYSLOG
  664.     if (ckxsyslog >= SYSLG_PR && ckxlogging)
  665.       cksyslog(SYSLG_PR, 1, "server", "GET /RECOVER", (char *)srvcmd);
  666. #endif /* CKSYSLOG */
  667.     BEGIN ssinit;
  668.     }
  669. #endif /* NOSERVER */
  670. }
  671.     break;
  672. case 23:
  673.     {                /* Extended GET */
  674. #ifndef NOSERVER
  675.     if (x_login && !x_logged) {        /* (any combination of options) */
  676.     errpkt((CHAR *)"Login required");
  677.     SERVE;
  678.     } else if ((x = sgetinit(0,1)) < 0) {
  679.     debug(F101,"CKCPRO <serve>O sgetinit fail","",x);
  680.     RESUME;
  681.     } else if (x == 0) {
  682.     debug(F101,"CKCPRO <serve>O sgetinit done","",x);
  683. #ifdef CKSYSLOG
  684.     if (ckxsyslog >= SYSLG_PR && ckxlogging)
  685.       cksyslog(SYSLG_PR, 1, "server", "EXTENDED GET", (char *)srvcmd);
  686. #endif /* CKSYSLOG */
  687.     BEGIN ssinit;
  688.     } else {                /* Otherwise stay in this state */
  689.     debug(F101,"CKCPRO <serve>O sgetinit TBC","",x);
  690.     ack();
  691.     BEGIN ropkt;
  692.     }
  693. #endif /* NOSERVER */
  694. }
  695.     break;
  696. case 24:
  697.     {
  698. #ifndef NOSERVER
  699.     if (x_login && !x_logged) {        /* (any combination of options) */
  700.     errpkt((CHAR *)"Login required");
  701.     SERVE;
  702.     } else if ((x = sgetinit(0,1)) < 0) {
  703.     debug(F101,"CKCPRO <ropkt>O sgetinit fail","",x);
  704.     RESUME;
  705.     } else if (x == 0) {
  706.     debug(F101,"CKCPRO <ropkt>O sgetinit done","",x);
  707. #ifdef CKSYSLOG
  708.     if (ckxsyslog >= SYSLG_PR && ckxlogging)
  709.       cksyslog(SYSLG_PR, 1, "server", "EXTENDED GET", (char *)srvcmd);
  710. #endif /* CKSYSLOG */
  711.     BEGIN ssinit;
  712.     } else {                /* Otherwise stay in this state */
  713.     debug(F101,"CKCPRO <ropkt>O sgetinit TBC","",x);
  714.     ack();
  715.     }
  716. #endif /* NOSERVER */
  717. }
  718.     break;
  719. case 25:
  720.     {                /* Generic server command */
  721. #ifndef NOSERVER
  722.     srvptr = srvcmd;            /* Point to command buffer */
  723.     decode(rdatap,putsrv,0);        /* Decode packet data into it */
  724.     putsrv(NUL);            /* Insert a couple nulls */
  725.     putsrv(NUL);            /* for termination */
  726.     if (srvcmd[0]) {
  727.     sstate = srvcmd[0];        /* Set requested start state */
  728.     if (x_login && !x_logged &&    /* Login required? */
  729.         /* Login, Logout, and Help are allowed when not logged in */
  730.         sstate != 'I' && sstate != 'L' && sstate != 'H') {
  731.         errpkt((CHAR *)"Login required");
  732.         SERVE;
  733.     } else {
  734.         nakstate = 0;        /* Now I'm the sender. */
  735.         what = W_REMO;        /* Doing a REMOTE command. */
  736. #ifdef STREAMING
  737.         if (!streaming)
  738. #endif /* STREAMING */
  739.           if (timint < 1)
  740.         timint = chktimo(rtimo,timef); /* Switch to per-packet timer */
  741.         binary = XYFT_T;        /* Switch to text mode */
  742.         BEGIN generic;        /* Switch to generic command state */
  743.     }
  744.     } else {
  745.     errpkt((CHAR *)"Badly formed server command"); /* report error */
  746.     RESUME;            /* & go back to server command wait */
  747.     }
  748. #endif /* NOSERVER */
  749. }
  750.     break;
  751. case 26:
  752.     {                /* Receive Host command */
  753. #ifndef NOSERVER
  754.     if (x_login && !x_logged) {
  755.     errpkt((CHAR *)"Login required");
  756.     SERVE;
  757.     } else if (!ENABLED(en_hos)) {
  758.     errpkt((CHAR *)"REMOTE HOST disabled");
  759.     RESUME;
  760.     } else if (nopush) {
  761.     errpkt((CHAR *)"HOST commands not available");
  762.     RESUME;
  763.     } else {
  764.     srvptr = srvcmd;        /* Point to command buffer */
  765.     decode(rdatap,putsrv,0);    /* Decode command packet into it */
  766.     putsrv(NUL);            /* Null-terminate */
  767.     nakstate = 0;            /* Now sending, not receiving */
  768.     binary = XYFT_T;        /* Switch to text mode */
  769.     if (syscmd((char *)srvcmd,"")) { /* Try to execute the command */
  770.         what = W_REMO;        /* Doing a REMOTE command. */
  771. #ifdef STREAMING
  772.         if (!streaming)
  773. #endif /* STREAMING */
  774.           if (timint < 1)
  775.         timint = chktimo(rtimo,timef); /* Switch to per-packet timer */
  776. #ifdef CKSYSLOG
  777.         if (ckxsyslog >= SYSLG_PR && ckxlogging)
  778.           cksyslog(SYSLG_PR, 1, "server", "REMOTE HOST", (char *)srvcmd);
  779. #endif /* CKSYSLOG */
  780.         BEGIN ssinit;        /* If OK, send back its output */
  781.     } else {            /* Otherwise */
  782.         errpkt((CHAR *)"Can't do system command"); /* report error */
  783.         RESUME;            /* & go back to server command wait */
  784.     }
  785.     }
  786. #endif /* NOSERVER */
  787. }
  788.     break;
  789. case 27:
  790.     {                /* Interrupted or connection lost */
  791.     rc = srv_timeout();
  792.     debug(F101,"srv_timeout","",rc);
  793.     if (rc > -1) return(rc);        /* (see below) */
  794. }
  795.     break;
  796. case 28:
  797.     {                /* Server got a NAK in command-wait */
  798. #ifndef NOSERVER
  799.     errpkt((CHAR *)"Did you say RECEIVE instead of GET?");
  800.     RESUME;
  801. #endif /* NOSERVER */
  802. }
  803.     break;
  804. case 29:
  805.     {                /* Any other command in this state */
  806. #ifndef NOSERVER
  807.     if (c != ('E' - SP) && c != ('Y' - SP)) /* except E and Y packets. */
  808.       errpkt((CHAR *)"Unimplemented server function");
  809.     /* If we answer an E with an E, we get an infinite loop. */
  810.     /* A Y (ACK) can show up here if we sent back a short-form reply to */
  811.     /* a G packet and it was echoed.  ACKs can be safely ignored here. */
  812.     RESUME;                /* Go back to server command wait. */
  813. #endif /* NOSERVER */
  814. }
  815.     break;
  816. case 30:
  817.     {                /* Login/Out */
  818.     rc = srv_login();
  819.     debug(F101,"<generic>I srv_login","",rc);
  820.     if (rc > -1) return(rc);        /* (see below) */
  821. }
  822.     break;
  823. case 31:
  824.     {                /* Got REMOTE CD command */
  825. #ifndef NOSERVER
  826. #ifdef CKSYSLOG
  827.     if (ckxsyslog >= SYSLG_PR && ckxlogging)
  828.       cksyslog(SYSLG_PR, 1, "server", "REMOTE CD", (char *)srvcmd);
  829. #endif /* CKSYSLOG */
  830.     if (!ENABLED(en_cwd)) {
  831.     errpkt((CHAR *)"REMOTE CD disabled");
  832.     RESUME;
  833.     } else {
  834.     char * p = NULL;
  835.     x = cwd((char *)(srvcmd+1));    /* Try to change directory */
  836. #ifdef IKSDB
  837.     if (ikdbopen) slotstate(what,"REMOTE CD", (char *)(srvcmd+2), "");
  838. #endif /* IKSDB */
  839.     if (!x) {            /* Failed */
  840.         errpkt((CHAR *)"Can't change directory");
  841.         RESUME;            /* Back to server command wait */
  842.     } else if (x == 2) {        /* User wants message */
  843.         if (!ENABLED(en_typ)) {    /* Messages (REMOTE TYPE) disabled? */
  844.         errpkt((CHAR *)"REMOTE TYPE disabled");
  845.         RESUME;
  846.         } else {            /* TYPE is enabled */
  847.         int i;
  848.         for (i = 0; i < 8; i++) {
  849.             if (zchki(cdmsgfile[i]) > -1) {
  850.             break;
  851.             }
  852.         }
  853.         binary = XYFT_T;    /* Use text mode for this. */
  854.         if (i < 8 && sndtype(cdmsgfile[i])) { /* Have readme file? */
  855.             BEGIN ssinit;    /* OK */
  856.         } else {        /* not OK */
  857.             p = zgtdir();
  858.             if (!p) p = "";
  859.             success = (*p) ? 1 : 0;
  860.             ack1((CHAR *)p);    /* ACK with new directory name */
  861.             success = 1;
  862.             RESUME;        /* wait for next server command */
  863.         }
  864.         }
  865.     } else {            /* User doesn't want message */
  866.         p =zgtdir();
  867.         if (!p) p = "";
  868.         success = (*p) ? 1 : 0;
  869.         ack1((CHAR *)p);
  870.         success = 1;
  871.         RESUME;            /* Wait for next server command */
  872.     }
  873.     }
  874. #endif /* NOSERVER */
  875. }
  876.     break;
  877. case 32:
  878.     {                /* Got REMOTE PWD command */
  879. #ifndef NOSERVER
  880. #ifdef CKSYSLOG
  881.     if (ckxsyslog >= SYSLG_PR && ckxlogging)
  882.       cksyslog(SYSLG_PR, 1, "server", "REMOTE PWD", NULL);
  883. #endif /* CKSYSLOG */
  884.     if (!ENABLED(en_cwd)) {
  885.     errpkt((CHAR *)"REMOTE CD disabled");
  886.     RESUME;
  887.     } else {
  888.     if (encstr((CHAR *)zgtdir()) > -1) { /* Encode current directory */
  889.         ack1(data);            /* If it fits, send it back in ACK */
  890.         success = 1;
  891.     } else {            /* Failed */
  892.         ack();            /* Send empty ACK */
  893.         success = 0;        /* and indicate failure locally */
  894.     }
  895.     RESUME;                /* Back to server command wait */
  896.     }
  897. #endif /* NOSERVER */
  898. }
  899.     break;
  900. case 33:
  901.     {                /* REMOTE DIRECTORY command */
  902. #ifndef NOSERVER
  903.     char *n2;
  904. #ifdef CKSYSLOG
  905.     if (ckxsyslog >= SYSLG_PR && ckxlogging)
  906.       cksyslog(SYSLG_PR, 1, "server", "REMOTE DIRECTORY", (char *)srvcmd);
  907. #endif /* CKSYSLOG */
  908.     if (!ENABLED(en_dir)) {        /* If DIR is disabled, */
  909.     errpkt((CHAR *)"REMOTE DIRECTORY disabled"); /* refuse. */
  910.     RESUME;
  911.     } else {                /* DIR is enabled. */
  912. #ifdef IKSDB
  913.     if (ikdbopen) slotstate(what,"REMOTE DIR", (char *)(srvcmd+2), "");
  914. #endif /* IKSDB */
  915.     if (!ENABLED(en_cwd)) {        /* But CWD is disabled */
  916.         zstrip((char *)(srvcmd+2),&n2); /* and they included a pathname, */
  917.         if (strcmp((char *)(srvcmd+2),n2)) { /* so refuse. */
  918.         errpkt((CHAR *)"Access denied");
  919.         RESUME;            /* Remember, this is not a goto! */
  920.         }
  921.     }
  922.     if (state == generic) {            /* It's OK to go ahead. */
  923. #ifdef COMMENT
  924.         n2 = (*(srvcmd+2)) ? DIRCMD : DIRCM2;
  925.         if (syscmd(n2,(char *)(srvcmd+2)))  /* If it can be done */
  926. #else
  927.         int x;
  928.         if ((x = snddir((char*)(srvcmd+2))) > 0)
  929. #endif /* COMMENT */
  930.         {
  931.         BEGIN ssinit;        /* send the results back; */
  932.         } else {            /* otherwise */
  933.         if (x < 0)
  934.           errpkt((CHAR *)"No files match");
  935.         else
  936.           errpkt((CHAR *)"Can't list directory");
  937.         RESUME;            /* return to server command wait */
  938.         }
  939.     }
  940.     }
  941. #endif /* NOSERVER */
  942. }
  943.     break;
  944. case 34:
  945.     {                /* REMOTE DELETE (Erase) */
  946. #ifndef NOSERVER
  947.     char *n2;
  948. #ifdef CKSYSLOG
  949.     if (ckxsyslog >= SYSLG_PR && ckxlogging)
  950.       cksyslog(SYSLG_PR, 1, "server", "REMOTE DELETE", (char *)srvcmd);
  951. #endif /* CKSYSLOG */
  952.     if (!ENABLED(en_del)) {
  953.     errpkt((CHAR *)"REMOTE DELETE disabled");
  954.     RESUME;
  955.     } else {                /* DELETE is enabled */
  956. #ifdef IKSDB
  957.     if (ikdbopen) slotstate(what,"REMOTE DELETE", (char *)(srvcmd+2), "");
  958. #endif /* IKSDB */
  959.     if (!ENABLED(en_cwd)) {        /* but CWD is disabled */
  960.         zstrip((char *)(srvcmd+2),&n2); /* and they included a pathname, */
  961.         if (strcmp((char *)(srvcmd+2),n2)) { /* so refuse. */
  962.         errpkt((CHAR *)"Access denied");
  963.         RESUME;            /* Remember, this is not a goto! */
  964.         }
  965.     } else if (isdir((char *)(srvcmd+2))) { /* A directory name? */
  966.         errpkt((CHAR *)"It's a directory");
  967.         RESUME;
  968.     }
  969.     if (state == generic) {        /* It's OK to go ahead. */
  970.         int x;
  971.         if ((x = snddel((char*)(srvcmd+2))) > 0) {
  972.         BEGIN ssinit;        /* If OK send results back */
  973.         } else {            /* otherwise */
  974.         if (x < 0)
  975.           errpkt((CHAR *)"File not found"); /* report failure */
  976.         else
  977.           errpkt((CHAR *)"DELETE failed");
  978.         RESUME;            /* & return to server command wait */
  979.         }
  980.     }
  981.     }
  982. #endif /* NOSERVER */
  983. }
  984.     break;
  985. case 35:
  986.     {                /* FINISH */
  987. #ifndef NOSERVER
  988. #ifdef CKSYSLOG
  989.     if (ckxsyslog >= SYSLG_PR && ckxlogging)
  990.       cksyslog(SYSLG_PR, 1, "server", "FINISH", NULL);
  991. #endif /* CKSYSLOG */
  992. #ifdef IKSDB
  993.     if (ikdbopen) slotstate(what,"SERVER FINISH", "", "");
  994. #endif /* IKSDB */
  995.     if (!ENABLED(en_fin)) {
  996.     errpkt((CHAR *)"FINISH disabled");
  997.     RESUME;
  998.     } else {
  999.     ack();                /* Acknowledge */
  1000.     xxscreen(SCR_TC,0,0L,"");    /* Display */
  1001.     success = 1;
  1002.     return(0);            /* Done */
  1003.     }
  1004. #endif /* NOSERVER */
  1005. }
  1006.     break;
  1007. case 36:
  1008.     {                /* EXIT */
  1009. #ifndef NOSERVER
  1010. #ifdef CKSYSLOG
  1011.     if (ckxsyslog >= SYSLG_PR && ckxlogging)
  1012.       cksyslog(SYSLG_PR, 1, "server", "REMOTE EXIT", NULL);
  1013. #endif /* CKSYSLOG */
  1014. #ifdef IKSDB
  1015.     if (ikdbopen) slotstate(what,"REMOTE EXIT", "", "");
  1016. #endif /* IKSDB */
  1017.     if (!ENABLED(en_xit)) {
  1018.     errpkt((CHAR *)"EXIT disabled");
  1019.     RESUME;
  1020.     } else {
  1021.     ack();                /* Acknowledge */
  1022.     xxscreen(SCR_TC,0,0L,"");    /* Display */
  1023.     doexit(GOOD_EXIT,xitsta);
  1024.     }
  1025. #endif /* NOSERVER */
  1026. }
  1027.     break;
  1028. case 37:
  1029.     {                /* BYE (Logout) */
  1030. #ifndef NOSERVER
  1031. #ifdef CKSYSLOG
  1032.     if (ckxsyslog >= SYSLG_PR && ckxlogging)
  1033.       cksyslog(SYSLG_PR, 1, "server", "BYE", NULL);
  1034. #endif /* CKSYSLOG */
  1035. #ifdef IKSDB
  1036.     if (ikdbopen) slotstate(what,"SERVER BYE", "", "");
  1037. #endif /* IKSDB */
  1038.     if (!ENABLED(en_bye)) {
  1039.     errpkt((CHAR *)"BYE disabled");
  1040.     RESUME;
  1041.     } else {
  1042.     ack();                /* Acknowledge */
  1043.     success = 1;
  1044.     msleep(750);            /* Give the ACK time to get out */
  1045.     if (local)
  1046.       ttres();            /* Reset the terminal */
  1047.     xxscreen(SCR_TC,0,0L,"");    /* Display */
  1048.     doclean(1);            /* Clean up files, etc */
  1049. #ifdef DEBUG
  1050.     debug(F100,"C-Kermit BYE - Loggin out...","",0);
  1051.     zclose(ZDFILE);
  1052. #endif /* DEBUG */
  1053. #ifdef IKSD
  1054. #ifdef CK_LOGIN
  1055.     if (inserver)
  1056.       ckxlogout();
  1057.     else
  1058. #endif /* CK_LOGIN */
  1059. #endif /* IKSD */
  1060. #ifdef TCPSOCKET
  1061. #ifndef NOLISTEN
  1062.       if (network && tcpsrfd > 0 && !inserver)
  1063.         doexit(GOOD_EXIT,xitsta);
  1064.     else
  1065. #endif /* NOLISTEN */
  1066. #endif /* TCPSOCKET */
  1067.       return(zkself());        /* Try to log self out */
  1068.     }
  1069. #endif /* NOSERVER */
  1070. }
  1071.     break;
  1072. case 38:
  1073.     {                /* REMOTE HELP */
  1074. #ifdef CKSYSLOG
  1075.     if (ckxsyslog >= SYSLG_PR && ckxlogging)
  1076.       cksyslog(SYSLG_PR, 1, "server", "REMOTE HELP", NULL);
  1077. #endif /* CKSYSLOG */
  1078. #ifdef IKSDB
  1079.     if (ikdbopen) slotstate(what,"REMOTE HELP", "", "");
  1080. #endif /* IKSDB */
  1081. #ifndef NOSERVER
  1082.     if (sndhlp(NULL)) {
  1083.     BEGIN ssinit;            /* try to send it */
  1084.     } else {                /* If not ok, */
  1085.     errpkt((CHAR *)"Can't send help"); /* send error message instead */
  1086.     RESUME;                /* and return to server command wait */
  1087.     }
  1088. #endif /* NOSERVER */
  1089. }
  1090.     break;
  1091. case 39:
  1092.     {                            /* REMOTE RENAME */
  1093.     rc = srv_rename();
  1094.     debug(F101,"srv_rename","",rc);
  1095.     if (rc > -1) return(rc);        /* (see below) */
  1096. }
  1097.     break;
  1098. case 40:
  1099.     {                            /* REMOTE COPY */
  1100.     rc = srv_copy();
  1101.     debug(F101,"srv_copy","",rc);
  1102.     if (rc > -1) return(rc);        /* (see below) */
  1103. }
  1104.     break;
  1105. case 41:
  1106.     {                /* REMOTE SET */
  1107. #ifdef CKSYSLOG
  1108.     if (ckxsyslog >= SYSLG_PR && ckxlogging)
  1109.       cksyslog(SYSLG_PR, 1, "server", "REMOTE SET", (char *)srvcmd);
  1110. #endif /* CKSYSLOG */
  1111. #ifndef NOSERVER
  1112. #ifdef IKSDB
  1113.     if (ikdbopen) slotstate(what,"REMOTE SET", (char *)(srvcmd+1), "");
  1114. #endif /* IKSDB */
  1115.     if (!ENABLED(en_set)) {
  1116.     errpkt((CHAR *)"REMOTE SET disabled");
  1117.     RESUME;
  1118.     } else {
  1119.     if (remset((char *)(srvcmd+1))) { /* Try to do what they ask */
  1120.         success = 1;
  1121.         ack();            /* If OK, then acknowledge */
  1122.     } else                /* Otherwise */
  1123.       errpkt((CHAR *)"Unknown REMOTE SET parameter"); /* give error msg */
  1124.     RESUME;                /* Return to server command wait */
  1125.     }
  1126. #endif /* NOSERVER */
  1127. }
  1128.     break;
  1129. case 42:
  1130.     {                /* REMOTE TYPE */
  1131. #ifndef NOSERVER
  1132.     char *n2;
  1133. #ifdef CKSYSLOG
  1134.     if (ckxsyslog >= SYSLG_PR && ckxlogging)
  1135.       cksyslog(SYSLG_PR, 1, "server", "REMOTE TYPE", (char *)srvcmd);
  1136. #endif /* CKSYSLOG */
  1137.     if (!ENABLED(en_typ)) {
  1138.     errpkt((CHAR *)"REMOTE TYPE disabled");
  1139.     RESUME;
  1140.     } else {
  1141. #ifdef IKSDB
  1142.     if (ikdbopen) slotstate(what,"REMOTE TYPE", (char *)(srvcmd+2), "");
  1143. #endif /* IKSDB */
  1144.     if (!ENABLED(en_cwd)) {        /* If CWD disabled */
  1145.         zstrip((char *)(srvcmd+2),&n2); /* and they included a pathname, */
  1146.         if (strcmp((char *)(srvcmd+2),n2)) { /* refuse. */
  1147.         errpkt((CHAR *)"Access denied");
  1148.         RESUME;            /* Remember, this is not a goto! */
  1149.         }
  1150.     }
  1151.     if (state == generic) {        /* It's OK to go ahead. */
  1152.         binary = XYFT_T;        /* Use text mode for this. */
  1153.         if (            /* (RESUME didn't change state) */
  1154. #ifdef COMMENT
  1155.           syscmd(TYPCMD,(char *)(srvcmd+2))    /* Old way */
  1156. #else
  1157.           sndtype((char *)(srvcmd+2)) /* New way */
  1158. #endif /* COMMENT */
  1159.         )
  1160.           BEGIN ssinit;        /* OK */
  1161.         else {            /* not OK */
  1162.         errpkt((CHAR *)"Can't type file"); /* give error message */
  1163.         RESUME;            /* wait for next server command */
  1164.         }
  1165.     }
  1166.     }
  1167. #endif /* NOSERVER */
  1168. }
  1169.     break;
  1170. case 43:
  1171.     {                /* REMOTE MKDIR */
  1172. #ifndef NOSERVER
  1173. #ifdef CK_MKDIR
  1174. #ifdef CKSYSLOG
  1175.     if (ckxsyslog >= SYSLG_PR && ckxlogging)
  1176.       cksyslog(SYSLG_PR, 1, "server", "REMOTE MKDIR", (char *)srvcmd);
  1177. #endif /* CKSYSLOG */
  1178. #ifdef IKSDB
  1179.     if (ikdbopen) slotstate(what,"REMOTE MKDIR", (char *)(srvcmd+2), "");
  1180. #endif /* IKSDB */
  1181.     if (!ENABLED(en_mkd)) {
  1182.     errpkt((CHAR *)"REMOTE MKDIR disabled");
  1183.     RESUME;
  1184.     } else if (!ENABLED(en_cwd)) {    /* If CWD disabled */
  1185.     errpkt((CHAR *)"Directory access restricted");
  1186.     RESUME;                /* Remember, this is not a goto! */
  1187.     }
  1188.     if (state == generic) {        /* OK to go ahead. */
  1189.     char *p = NULL;
  1190.     x = ckmkdir(0,(char *)(srvcmd+2),&p,0,1); /* Make the directory */
  1191.     if (!p) p = "";
  1192.     if (x > -1) {
  1193.         encstr((CHAR *)p);        /* OK - encode the name */
  1194.         ack1(data);            /* Send short-form response */
  1195.         success = 1;
  1196.         RESUME;
  1197.     } else {            /* not OK */
  1198.         if (!*p) p = "Directory creation failure";
  1199.         errpkt((CHAR *)p);        /* give error message */
  1200.         RESUME;            /* Wait for next server command */
  1201.     }
  1202.     }
  1203. #else
  1204.     errpkt((CHAR *)"REMOTE MKDIR not available");
  1205.     RESUME;
  1206. #endif /* CK_MKDIR */
  1207. #endif /* NOSERVER */
  1208. }
  1209.     break;
  1210. case 44:
  1211.     {                /* REMOTE RMDIR */
  1212. #ifndef NOSERVER
  1213. #ifdef CK_MKDIR
  1214. #ifdef CKSYSLOG
  1215.     if (ckxsyslog >= SYSLG_PR && ckxlogging)
  1216.       cksyslog(SYSLG_PR, 1, "server", "REMOTE RMDIR", (char *)srvcmd);
  1217. #endif /* CKSYSLOG */
  1218. #ifdef IKSDB
  1219.     if (ikdbopen) slotstate(what,"REMOTE RMDIR", (char *)(srvcmd+2), "");
  1220. #endif /* IKSDB */
  1221.     if (!ENABLED(en_rmd)) {
  1222.     errpkt((CHAR *)"REMOTE RMDIR disabled");
  1223.     RESUME;
  1224.     } else if (!ENABLED(en_cwd)) {    /* If CWD disabled */
  1225.     errpkt((CHAR *)"Directory access restricted");
  1226.     RESUME;                /* Remember, this is not a goto! */
  1227.     }
  1228.     if (state == generic) {        /* OK to go ahead. */
  1229.     char *p = NULL;
  1230.     x = ckmkdir(1,(char *)(srvcmd+2),&p,0,1);
  1231.     if (!p) p = "";
  1232.     if (x > -1) {
  1233.         encstr((CHAR *)p);        /* OK - encode the name */
  1234.         ack1(data);            /* Send short-form response */
  1235.         success = 1;
  1236.         RESUME;
  1237.     } else {            /* not OK */
  1238.         if (!*p) p = "Directory removal failure";
  1239.         errpkt((CHAR *)p);        /* give error message */
  1240.         RESUME;            /* Wait for next server command */
  1241.     }
  1242.     }
  1243. #else
  1244.     errpkt((CHAR *)"REMOTE RMDIR not available");
  1245.     RESUME;
  1246. #endif /* CK_MKDIR */
  1247. #endif /* NOSERVER */
  1248. }
  1249.     break;
  1250. case 45:
  1251.     {                /* REMOTE SPACE */
  1252. #ifndef NOSERVER
  1253. #ifdef CKSYSLOG
  1254.     if (ckxsyslog >= SYSLG_PR && ckxlogging)
  1255.       cksyslog(SYSLG_PR, 1, "server", "REMOTE SPACE", (char *)srvcmd);
  1256. #endif /* CKSYSLOG */
  1257.     if (!ENABLED(en_spa)) {
  1258.     errpkt((CHAR *)"REMOTE SPACE disabled");
  1259.     RESUME;
  1260.     } else {
  1261.     x = srvcmd[1];            /* Get area to check */
  1262.     x = ((x == NUL) || (x == SP)
  1263. #ifdef OS2
  1264.          || (x == '!') || (srvcmd[3] == ':')
  1265. #endif /* OS2 */
  1266.          );
  1267. #ifdef IKSDB
  1268.     if (ikdbopen) slotstate(what,
  1269.                   "REMOTE SPACE",
  1270.                   (x ? "" : (char *)srvcmd),
  1271.                   ""
  1272.                   );
  1273. #endif /* IKSDB */
  1274.     if (!x && !ENABLED(en_cwd)) {    /* CWD disabled */
  1275.         errpkt((CHAR *)"Access denied"); /* and non-default area given, */
  1276.         RESUME;            /* refuse. */
  1277.     } else {
  1278. #ifdef OS2
  1279. _PROTOTYP(int sndspace,(int));
  1280.         if (sndspace(x ? toupper(srvcmd[2]) : 0)) {
  1281.         BEGIN ssinit;        /* send the report. */
  1282.         } else {            /* If not ok, */
  1283.         errpkt((CHAR *)"Can't send space"); /* send error message */
  1284.         RESUME;            /* and return to server command wait */
  1285.         }
  1286. #else
  1287.             if (nopush)
  1288.               x = 0;
  1289.             else
  1290.               x = (x ? syscmd(SPACMD,"") : syscmd(SPACM2,(char *)(srvcmd+2)));
  1291.         if (x) {            /* If we got the info */
  1292.         BEGIN ssinit;        /* send it */
  1293.         } else {            /* otherwise */
  1294.         errpkt((CHAR *)"Can't check space"); /* send error message */
  1295.         RESUME;            /* and await next server command */
  1296.         }
  1297. #endif /* OS2 */
  1298.     }
  1299.     }
  1300. #endif /* NOSERVER */
  1301. }
  1302.     break;
  1303. case 46:
  1304.     {                /* REMOTE WHO */
  1305. #ifndef NOSERVER
  1306. #ifdef CKSYSLOG
  1307.     if (ckxsyslog >= SYSLG_PR && ckxlogging)
  1308.       cksyslog(SYSLG_PR, 1, "server", "REMOTE WHO", (char *)srvcmd);
  1309. #endif /* CKSYSLOG */
  1310. #ifdef IKSDB
  1311.     if (ikdbopen) slotstate(what,"REMOTE WHO", (char *)(srvcmd+2), "");
  1312. #endif /* IKSDB */
  1313.     if (!ENABLED(en_who)) {
  1314.     errpkt((CHAR *)"REMOTE WHO disabled");
  1315.     RESUME;
  1316.     } else {
  1317. #ifdef OS2
  1318. _PROTOTYP(int sndwho,(char *));
  1319.         if (sndwho((char *)(srvcmd+2))) {
  1320.         BEGIN ssinit;        /* try to send it */
  1321.         } else {            /* If not ok, */
  1322.         errpkt((CHAR *)"Can't do who command"); /* send error msg */
  1323.         RESUME;            /* and return to server command wait */
  1324.         }
  1325. #else
  1326.     if (syscmd(WHOCMD,(char *)(srvcmd+2))) {
  1327.         BEGIN ssinit;
  1328.     } else {
  1329.         errpkt((CHAR *)"Can't do who command");
  1330.         RESUME;
  1331.     }
  1332. #endif /* OS2 */
  1333.     }
  1334. #endif /* NOSERVER */
  1335. }
  1336.     break;
  1337. case 47:
  1338.     {                /* Variable query or set */
  1339.     rc = srv_query();
  1340.     debug(F101,"srv_query","",rc);
  1341.     if (rc > -1) return(rc);
  1342. }
  1343.     break;
  1344. case 48:
  1345.     {                /* Interrupted or connection lost */
  1346. #ifndef NOSERVER
  1347.     if (fatalio) {            /* Connection lost */
  1348. #ifdef CKSYSLOG
  1349.     if (ckxsyslog >= SYSLG_PR && ckxlogging)
  1350.       cksyslog(SYSLG_PR, 1, "server", "Interrupted", NULL);
  1351. #endif /* CKSYSLOG */
  1352.     success = 0;
  1353.     xitsta |= what;
  1354.     QUIT;
  1355.     } else if (interrupted) {
  1356.     if (!ENABLED(en_fin)) {        /* Ctrl-C typed */
  1357.         errpkt((CHAR *)"QUIT disabled");
  1358.         RESUME;
  1359.     } else {
  1360. #ifdef CKSYSLOG
  1361.         if (ckxsyslog >= SYSLG_PR && ckxlogging)
  1362.           cksyslog(SYSLG_PR, 1, "server", "Interrupted", NULL);
  1363. #endif /* CKSYSLOG */
  1364.         success = 0;
  1365.         xitsta |= what;
  1366.         QUIT;
  1367.     }
  1368.     } else {                /* Shouldn't happen */
  1369.     debug(F100,"SERVER (generic) GOT UNEXPECTED 'q'","",0);
  1370.     QUIT;
  1371.     }
  1372. #endif /* NOSERVER */
  1373. }
  1374.     break;
  1375. case 49:
  1376.     {                /* Anything else in this state... */
  1377. #ifndef NOSERVER
  1378.     errpkt((CHAR *)"Unimplemented REMOTE command"); /* Complain */
  1379.     RESUME;                /* and return to server command wait */
  1380. #endif /* NOSERVER */
  1381. }
  1382.     break;
  1383. case 50:
  1384.     {                /* Sent BYE and connection broken */
  1385.     if (bye_active && ttchk() < 0) {
  1386.     msleep(500);
  1387.     bye_active = 0;
  1388.     ttclos(0);            /* Close our end of the connection */
  1389.     clsof(0);
  1390.     return(success = 1);
  1391.     } else {                /* Other generic command */
  1392.     return(success = 0);        /* or connection not broken */
  1393.     }
  1394. }
  1395.     break;
  1396. case 51:
  1397.     {                /* Short-Form reply */
  1398.     rc = rcv_shortreply();
  1399.     debug(F101,"<rgen>Y rcv_shortreply","",rc);
  1400.     if (rc > -1) return(rc);
  1401. }
  1402.     break;
  1403. case 52:
  1404.     {                /* File header */
  1405.     char *n2;
  1406.     extern int rsn;
  1407.     debug(F101,"<rfile>F winlo 1","",winlo);
  1408.     xflg = 0;                /* Not screen data */
  1409.     cancel = 0;                /* Reset cancellation counter */
  1410. #ifdef CALIBRATE
  1411.     if (dest == DEST_N)
  1412.       calibrate = 1;
  1413. #endif /* CALIBRATE */
  1414.     if (!rcvfil(filnam)) {        /* Figure out local filename */
  1415.     errpkt((CHAR *)rf_err);        /* Trouble */
  1416.     RESUME;
  1417.     } else {                /* Real file, OK to receive */
  1418.     char * fnp;
  1419.     debug(F111,"<rfile>F winlo 2",fspec,winlo);
  1420.     if (filcnt == 1)        /* rcvfil set this to 1 for 1st file */
  1421.       crc16 = 0L;            /* Clear file CRC */
  1422.     fnp = fspec;            /* This is the full path */
  1423.     if (server && !ENABLED(en_cwd) || /* if DISABLE CD */
  1424.         !fackpath              /* or F-ACK-PATH OFF */
  1425.         ) {
  1426.         zstrip(fspec,&fnp);        /* don't send back full path */
  1427.     }
  1428.     encstr((CHAR *)fnp);
  1429.     if (fackbug)
  1430.       ack();
  1431.     else
  1432.       ack1(data);            /* Send it back in ACK */
  1433.     initattr(&iattr);        /* Clear file attribute structure */
  1434.     streamon();
  1435.     if (window(wslotn) < 0) {    /* Allocate negotiated window slots */
  1436.         errpkt((CHAR *)"Can't open window");
  1437.         RESUME;
  1438.     }
  1439. #ifdef IKSDB
  1440.     if (ikdbopen) slotstate(what,
  1441.                   server ? "SERVER" : "",
  1442.                   "RECEIVE",
  1443.                   fspec
  1444.                   );
  1445. #endif /* IKSDB */
  1446.     BEGIN rattr;            /* Now expect Attribute packets */
  1447.     }
  1448. }
  1449.     break;
  1450. case 53:
  1451.     {                /* X-packet instead of file header */
  1452.     xflg = 1;                /* Screen data */
  1453.     cancel = 0;                /* Reset cancellation counter */
  1454.     ack();                /* Acknowledge the X-packet */
  1455.     initattr(&iattr);            /* Initialize attribute structure */
  1456.     streamon();
  1457.     if (window(wslotn) < 0) {        /* allocate negotiated window slots */
  1458.     errpkt((CHAR *)"Can't open window");
  1459.     RESUME;
  1460.     }
  1461. #ifndef NOSPL
  1462.     if (query) {            /* If this is the response to */
  1463.     qbufp = querybuf;        /* a query that we sent, initialize */
  1464.     qbufn = 0;            /* the response buffer */
  1465.     querybuf[0] = NUL;
  1466.     }
  1467. #endif /* NOSPL */
  1468.     what = W_REMO;            /* we're doing a REMOTE command */
  1469. #ifdef IKSDB
  1470.     if (ikdbopen) slotstate(what,
  1471.               server ? "SERVER" : "",
  1472.               "RECEIVE",
  1473.               fspec
  1474.               );
  1475. #endif /* IKSDB */
  1476.     BEGIN rattr;            /* Expect Attribute packets */
  1477. }
  1478.     break;
  1479. case 54:
  1480.     {                /* Attribute packet */
  1481.     if (gattr(rdatap,&iattr) == 0) {    /* Read into attribute structure */
  1482. #ifdef CK_RESEND
  1483.     ack1((CHAR *)iattr.reply.val);    /* Reply with data */
  1484. #else
  1485.     ack();                /* If OK, acknowledge */
  1486. #endif /* CK_RESEND */
  1487.     } else {                /* Otherwise */
  1488.     extern long fsize;
  1489.     char *r;
  1490.     r = getreason(iattr.reply.val);
  1491.     ack1((CHAR *)iattr.reply.val);    /* refuse to accept the file */
  1492.     xxscreen(SCR_ST,ST_REFU,0L,r);    /* reason */
  1493. #ifdef TLOG
  1494.     if (tralog && !tlogfmt)
  1495.       doxlog(what,filnam,fsize,binary,1,r);
  1496. #endif /* TLOG */
  1497.     }
  1498. }
  1499.     break;
  1500. case 55:
  1501.     {                /* First data packet */
  1502.     rc = rcv_firstdata();
  1503.     debug(F101,"srv_firstdata","",rc);
  1504.     if (rc > -1) return(rc);        /* (see below) */
  1505. }
  1506.     break;
  1507. case 56:
  1508.     {                /* EOT, no more files */
  1509.     ack();                /* Acknowledge the B packet */
  1510.     reot();                /* Do EOT things */
  1511. #ifdef CK_TMPDIR
  1512. /* If we were cd'd temporarily to another device or directory ... */
  1513.     if (f_tmpdir) {
  1514.     int x;
  1515.     x = zchdir((char *) savdir);    /* ... restore previous directory */
  1516.     f_tmpdir = 0;            /* and remember we did it. */
  1517.     debug(F111,"ckcpro.w B tmpdir restoring",savdir,x);
  1518.     }
  1519. #endif /* CK_TMPDIR */
  1520.     RESUME;                /* and quit */
  1521. }
  1522.     break;
  1523. case 57:
  1524.     {                /* Data packet */
  1525.     if (cxseen || discard) {        /* If file interrupt */
  1526. #ifdef STREAMING
  1527.     if (streaming) {
  1528.         if (cancel++ == 0)
  1529.           ack1((CHAR *)"X");    /* put "X" in ACK */
  1530.         else
  1531.           fastack();
  1532.     } else
  1533. #endif /* STREAMING */
  1534.         ack1((CHAR *)"X");        /* put "X" in ACK */
  1535.     } else if (czseen) {        /* If file-group interrupt */
  1536. #ifdef STREAMING
  1537.     if (streaming) {
  1538.         if (cancel++ == 0)
  1539.           ack1((CHAR *)"Z");    /* put "Z" in ACK */
  1540.         else
  1541.           fastack();
  1542.     } else
  1543. #endif /* STREAMING */
  1544.         ack1((CHAR *)"Z");        /* put "Z" in ACK */
  1545.     } else {
  1546.     int rc, qf;
  1547. #ifndef NOSPL
  1548.     qf = query;
  1549. #else
  1550.     qf = 0;
  1551. #endif /* NOSPL */
  1552. #ifdef CKTUNING
  1553.     rc = (binary && !parity) ?
  1554.       bdecode(rdatap,putfil):
  1555.         decode(rdatap, qf ? puttrm : putfil, 1);
  1556. #else
  1557.     rc = decode(rdatap, qf ? puttrm : putfil, 1);
  1558. #endif /* CKTUNING */
  1559.     if (rc < 0) {
  1560.         discard = (keep == 0 || (keep == SET_AUTO && binary != XYFT_T));
  1561.         errpkt((CHAR *)"Error writing data"); /* If failure, */
  1562.         RESUME;
  1563.     } else                /* Data written OK, send ACK */
  1564. #ifdef STREAMING
  1565.       if (streaming)
  1566.         fastack();
  1567.     else
  1568. #endif /* STREAMING */
  1569.       ack();
  1570.     }
  1571. }
  1572.     break;
  1573. case 58:
  1574.     {                /* EOF immediately after A-Packet. */
  1575.     rf_err = "Can't create file";
  1576.     timint = s_timint;
  1577.     if (discard) {            /* Discarding a real file... */
  1578.     x = 1;
  1579.     } else if (xflg) {            /* If screen data */
  1580.     if (remfile) {            /* redirected to file */
  1581.         if (rempipe)        /* or pipe */
  1582.           x = openc(ZOFILE,remdest); /* Pipe: start command */
  1583.         else
  1584.           x = opena(remdest,&iattr); /* File: open with attributes */
  1585.     } else {            /* otherwise */
  1586.         x = opent(&iattr);        /* "open" the screen */
  1587.     }
  1588. #ifdef CALIBRATE
  1589.     } else if (calibrate) {        /* If calibration run */
  1590.     x = ckopenx(&iattr);        /* do this */
  1591. #endif /* CALIBRATE */
  1592.     } else {                /* otherwise */
  1593.     x = opena(filnam,&iattr);    /* open the file, with attributes */
  1594.     }
  1595.     if (!x || reof(filnam, &iattr) < 0) { /* Now close & dispose of the file */
  1596.     errpkt((CHAR *) rf_err);    /* If problem, send error msg */
  1597.     RESUME;                /* and quit */
  1598.     } else {                /* otherwise */
  1599.     ack();                /* acknowledge the EOF packet */
  1600.     BEGIN rfile;            /* and await another file */
  1601.     }
  1602. }
  1603.     break;
  1604. case 59:
  1605.     {                  /* Ctrl-C or connection loss. */
  1606.     timint = s_timint;
  1607.     window(1);                /* Set window size back to 1... */
  1608.     cxseen = 1;
  1609.     x = clsof(1);            /* Close file */
  1610.     return(success = 0);        /* Failed */
  1611. }
  1612.     break;
  1613. case 60:
  1614.     {                /* End Of File (EOF) Packet */
  1615. /*  wslots = 1;    */            /* (don't set) Window size back to 1 */
  1616. #ifndef COHERENT /* Coherent compiler blows up on this switch() statement. */
  1617.     x = reof(filnam, &iattr);        /* Handle the EOF packet */
  1618.     switch (x) {            /* reof() sets the success flag */
  1619.       case -3:                /* If problem, send error msg */
  1620.     errpkt((CHAR *)"Can't print file"); /* Fatal */
  1621.     RESUME;
  1622.     break;
  1623.       case -2:
  1624.     errpkt((CHAR *)"Can't mail file"); /* Fatal */
  1625.     RESUME;
  1626.     break;
  1627.       case 2:
  1628.       case 3:
  1629.     xxscreen(SCR_EM,0,0L,"Can't delete temp file"); /* Not fatal */
  1630.     RESUME;
  1631.     break;
  1632.       default:
  1633.     if (x < 0) {            /* Fatal */
  1634.         errpkt((CHAR *)"Can't close file");
  1635.         RESUME;
  1636.     } else {            /* Success */
  1637. #ifndef NOSPL
  1638.         if (query)            /* Query reponses generally */
  1639.           conoll("");        /* don't have line terminators */
  1640. #endif /* NOSPL */
  1641.         ack();            /* Acknowledge the EOF packet */
  1642.         BEGIN rfile;        /* and await another file */
  1643.     }
  1644.     }
  1645. #else
  1646.     if (reof(filnam, &iattr) < 0) {    /* Close the file */
  1647.     errpkt((CHAR *)"Error at end of file");
  1648.     RESUME;
  1649.     } else {                /* reof() sets success flag */
  1650.     ack();
  1651.     BEGIN rfile;
  1652.     }
  1653. #endif /* COHERENT */
  1654. }
  1655.     break;
  1656. case 61:
  1657.     {                /* ACK for Send-Init */
  1658.     spar(rdatap);            /* set parameters from it */
  1659.     bctu = bctr;            /* switch to agreed-upon block check */
  1660.     bctl = (bctu == 4) ? 2 : bctu;    /* Set block-check length */
  1661. #ifdef CK_RESEND
  1662.     if ((sendmode == SM_RESEND) && (!atcapu || !rscapu)) { /* RESEND */
  1663.     errpkt((CHAR *) "RESEND capabilities not negotiated");
  1664.     RESUME;
  1665.     } else {
  1666. #endif /* CK_RESEND */
  1667.     what = W_SEND;            /* Remember we're sending */
  1668.     lastxfer = W_SEND;
  1669.     x = sfile(xflg);        /* Send X or F header packet */
  1670.     cancel = 0;            /* Reset cancellation counter */
  1671.     if (x) {            /* If the packet was sent OK */
  1672.         if (!xflg && filcnt == 1)    /* and it's a real file */
  1673.           crc16 = 0L;        /* Clear the file CRC */
  1674.         resetc();            /* reset per-transaction counters */
  1675.         rtimer();            /* reset timers */
  1676. #ifdef GFTIMER
  1677.         rftimer();
  1678. #endif /* GFTIMER */
  1679.         streamon();            /* turn on streaming */
  1680. #ifdef IKSDB
  1681.         if (ikdbopen) slotstate(what,
  1682.                   (server ? "SERVER" : ""),
  1683.                   "SEND",
  1684.                   filnam,
  1685.                   "");
  1686. #endif /* IKSDB */
  1687.         BEGIN ssfile;        /* and switch to receive-file state */
  1688.     } else {            /* otherwise send error msg & quit */
  1689.         s = xflg ? "Can't execute command" : (char *)epktmsg;
  1690.         if (!*s) s = "Can't open file";
  1691.         errpkt((CHAR *)s);
  1692.         RESUME;
  1693.     }
  1694. #ifdef CK_RESEND
  1695.     }
  1696. #endif /* CK_RESEND */
  1697. }
  1698.     break;
  1699. case 62:
  1700.     {                /* R packet was retransmitted. */
  1701.     xsinit();                /* Resend packet 0 */
  1702. }
  1703.     break;
  1704. case 63:
  1705.     {                /* Same deal if G packet comes again */
  1706.     xsinit();
  1707. }
  1708.     break;
  1709. case 64:
  1710.     {                /* Same deal if C packet comes again */
  1711.     xsinit();
  1712. }
  1713.     break;
  1714. case 65:
  1715.     {                /* ACK for F or X packet */
  1716.     srvptr = srvcmd;            /* Point to string buffer */
  1717.     decode(rdatap,putsrv,0);        /* Decode data field, if any */
  1718.     putsrv(NUL);            /* Terminate with null */
  1719.     ffc = 0L;                /* Reset file byte counter */
  1720.     if (*srvcmd) {            /* If remote name was recorded */
  1721.         if (sendmode != SM_RESEND) {
  1722.         extern char * srfspec;
  1723.         if (fdispla == XYFD_C || fdispla == XYFD_S)
  1724.           xxscreen(SCR_AN,0,0L,(char *)srvcmd);
  1725.         tlog(F110," remote name:",(char *) srvcmd,0L);
  1726.         makestr(&srfspec,(char *)srvcmd);
  1727.         }
  1728.     }
  1729.     if (atcapu) {            /* If attributes are to be used */
  1730.     if (sattr(xflg | stdinf, 1) < 0) { /* send them */
  1731.         errpkt((CHAR *)"Can't send attributes"); /* if problem, say so */
  1732.         RESUME;            /* and quit */
  1733.     } else BEGIN ssattr;        /* if ok, switch to attribute state */
  1734.     } else {                /* Attributes not negotiated */
  1735.     if (window(wslotn) < 0) {    /* Open window */
  1736.         errpkt((CHAR *)"Can't open window");
  1737.         RESUME;
  1738.     }
  1739.     if ((x = sdata()) == -2) {    /* Send first data packet data */
  1740.         window(1);            /* Failed, put window size back to 1 */
  1741.         x = clsif();        /* Close input file */
  1742.         return(success = 0);    /* Return failure */
  1743.     } else if (x == -9) {        /* User interrupted */
  1744.         errpkt((CHAR *)"User cancelled"); /* Send Error packet */
  1745.         window(1);            /* Set window size back to 1... */
  1746.         timint = s_timint;        /* Restore timeout */
  1747.         return(success = 0);    /* Failed */
  1748.     } else if (x == -1) {        /* EOF (empty file) */
  1749.         window(1);            /* put window size back to 1, */
  1750.         debug(F101,"<ssfile>Y cxseen","",cxseen);
  1751.         x = clsif();        /* If not ok, close input file, */
  1752.         if (x < 0)            /* treating failure as interruption */
  1753.           cxseen = 1;        /* Send EOF packet */
  1754.         seof(cxseen||czseen);
  1755.         BEGIN sseof;        /* and switch to EOF state. */
  1756.     } else {            /* First data sent OK */
  1757.         BEGIN ssdata;        /* All ok, switch to send-data state */
  1758.     }
  1759.     }
  1760. }
  1761.     break;
  1762. case 66:
  1763.     {                /* Got ACK to A packet */
  1764.     ffc = 0L;                /* Reset file byte counter */
  1765.     if (rsattr(rdatap) < 0) {        /* Was the file refused? */
  1766.     discard = 1;            /* Set the discard flag */
  1767.     clsif();            /* Close the file */
  1768.     sxeof(1);            /* send EOF with "discard" code */
  1769.     BEGIN sseof;            /* switch to send-EOF state */
  1770.     } else if ((x = sattr(xflg | stdinf, 0)) < 0) { /* Send more? */
  1771.     errpkt((CHAR *)"Can't send attributes"); /* Trouble... */
  1772.     RESUME;
  1773.     } else if (x == 0) {        /* No more to send so now the data */
  1774.     if (window(wslotn) < 0) {    /* Allocate negotiated window slots */
  1775.         errpkt((CHAR *)"Can't open window");
  1776.         RESUME;
  1777.     }
  1778.     if ((x = sdata()) == -2) {    /* File accepted, send first data */
  1779.         return(success = 0);    /* Failed */
  1780.     } else if (x == -9) {        /* User interrupted */
  1781.         errpkt((CHAR *)"User cancelled"); /* Send Error packet */
  1782.         window(1);            /* Set window size back to 1... */
  1783.         timint = s_timint;        /* Restore timeout */
  1784.         return(success = 0);    /* Failed */
  1785.     } else if (x == -1) {        /* EOF */
  1786.         window(1);            /* put window size back to 1, */
  1787.         debug(F101,"<ssattr>Y cxseen","",cxseen);
  1788.         if (clsif() < 0)        /* Close input file */
  1789.           cxseen = 1;        /* Send EOF packet */
  1790.         seof(cxseen||czseen);
  1791.         BEGIN sseof;        /* and switch to EOF state. */
  1792.     } else {
  1793.         BEGIN ssdata;        /* All ok, switch to send-data state */
  1794.     }
  1795.     }
  1796. }
  1797.     break;
  1798. case 67:
  1799.     {                  /* Ctrl-C or connection loss. */
  1800.     window(1);                /* Set window size back to 1... */
  1801.     cxseen = 1;                /* To indicate interruption */
  1802.     x = clsif();            /* Close file */
  1803.     return(success = 0);        /* Failed */
  1804. }
  1805.     break;
  1806. case 68:
  1807.     {                /* Got ACK to Data packet */
  1808.     canned(rdatap);            /* Check if file transfer cancelled */
  1809.     if ((x = sdata()) == -2) {        /* Try to send next data */
  1810.     window(1);            /* Set window size back to 1... */
  1811.     x = clsif();            /* Close file */
  1812.     return(success = 0);        /* Failed */
  1813.     } else if (x == -9) {        /* User interrupted */
  1814.     errpkt((CHAR *)"User cancelled"); /* Send Error packet */
  1815.     window(1);            /* Set window size back to 1... */
  1816.     timint = s_timint;        /* Restore original timeout */
  1817.     return(success = 0);        /* Failed */
  1818.     } else if (x == -1) {        /* EOF - finished sending data */
  1819.     debug(F101,"<ssdata>Y cxseen","",cxseen);
  1820.     window(1);            /* Set window size back to 1... */
  1821.     if (clsif() < 0)        /* Close input file */
  1822.       cxseen = 1;            /* Send EOF packet*/
  1823.     debug(F101,"<ssdata>Y CALLING SEOF()","",cxseen);
  1824.     seof(cxseen||czseen);
  1825.     BEGIN sseof;            /* and enter send-eof state */
  1826.     }
  1827. }
  1828.     break;
  1829. case 69:
  1830.     {                /* Got ACK to EOF */
  1831.     int g;
  1832.     success = (cxseen == 0 && czseen == 0); /* Transfer status... */
  1833.     if (success && rejection > 0)        /* If rejected, succeed if */
  1834.       if (rejection != '#' &&            /* reason was date */
  1835.       rejection != 1 && rejection != '?') /* or name; */
  1836.     success = 0;                /* fail otherwise. */
  1837.     cxseen = 0;                /* This goes back to zero. */
  1838.     if (success) {            /* Only if transfer succeeded... */
  1839.     if (moving) {            /* If MOVE'ing */
  1840.         tlog(F110," deleting",filnam,0); /* delete the file */
  1841.         zdelet(filnam);
  1842.     } else if (snd_move) {        /* Or move it */
  1843.         int x;
  1844.         tlog(F110," moving source to",snd_move,0);
  1845.         x = zrename(filnam,snd_move);
  1846.         debug(F111,"send MOVE zrename",snd_move,x);
  1847.     } else if (snd_rename) {    /* Or rename it */
  1848.         char *s = snd_rename;    /* Renaming string */
  1849. #ifndef NOSPL
  1850.         int y;            /* Pass it thru the evaluator */
  1851.         extern int cmd_quoting;    /* for \v(filename) */
  1852.         if (cmd_quoting) {        /* But only if cmd_quoting is on */
  1853.         y = MAXRP;
  1854.         s = (char *)srvcmd;
  1855.         zzstring(snd_rename,&s,&y);
  1856.         s = (char *)srvcmd;
  1857.         }
  1858. #endif /* NOSPL */
  1859.         if (s) if (*s) {
  1860.         int x;
  1861.         x = zrename(filnam,s);
  1862.         debug(F111,"send RENAME zrename",snd_rename,x);
  1863.         if (x > -1)
  1864.           tlog(F110," renaming source to",s,0);
  1865. #ifdef COMMENT
  1866.         *s = NUL;
  1867. #endif /* COMMENT */
  1868.         }
  1869.     }
  1870.     }
  1871.     g = gnfile();
  1872.     debug(F111,"<seof>Y gnfile",filnam,g);
  1873.     if (g > 0) {            /* Any more files to send? */
  1874.     if (sfile(xflg))        /* Yes, try to send next file header */
  1875.       BEGIN ssfile;            /* if ok, enter send-file state */
  1876.     else {                /* otherwise */
  1877.         s = xflg ? "Can't execute command" : (char *)epktmsg;
  1878.         if (!*s) s = "Can't open file";
  1879.         errpkt((CHAR *)s);        /* send error message */
  1880.         RESUME;            /* and quit */
  1881.     }
  1882.     } else {                /* No next file */
  1883.     tsecs = gtimer();        /* get statistics timers */
  1884. #ifdef GFTIMER
  1885.     fptsecs = gftimer();
  1886. #endif /* GFTIMER */
  1887.     seot();                /* send EOT packet */
  1888.     BEGIN sseot;            /* enter send-eot state */
  1889.     }
  1890. }
  1891.     break;
  1892. case 70:
  1893.     {                /* Got ACK to EOT */
  1894.     debug(F101,"sseot justone","",justone);
  1895.     RESUME;                /* All done, just quit */
  1896. }
  1897.     break;
  1898. case 71:
  1899.     {                    /* Got Error packet, in any state */
  1900.     char *s = "";
  1901.     window(1);                /* Close window */
  1902.     timint = s_timint;            /* Restore original timeout */
  1903.     if (*epktmsg)            /* Message from Error packet */
  1904.       s = (char *)epktmsg;
  1905.     if (!*s) {                /* If not there then maybe here */
  1906.     s = (char *)rdatap;
  1907.     ckstrncpy((char *)epktmsg,(char *)rdatap,PKTMSGLEN);
  1908.     }
  1909.     if (!*s)                /* Hopefully we'll never see this. */
  1910.       s = "Unknown error";
  1911.     success = 0;            /* For IF SUCCESS/FAIL. */
  1912.     debug(F101,"ckcpro.w justone at E pkt","",justone);
  1913.     x = quiet; quiet = 1;        /* Close files silently, */
  1914.     epktrcvd = 1;            /* Prevent messages from clsof() */
  1915.     clsif(); clsof(1);             /* discarding any output file. */
  1916.     success = 0;            /* Transfer failed */
  1917.     xferstat = success;            /* Remember transfer status */
  1918.     ermsg(s);                /* Issue the message (calls screen). */
  1919.     tstats();                /* Get stats */
  1920.     quiet = x;                /* Restore quiet state */
  1921. /*
  1922.   If we are executing commands from a command file or macro, let the command
  1923.   file or macro decide whether to exit, based on SET { TAKE, MACRO } ERROR.
  1924. */
  1925.     if (
  1926. #ifndef NOICP
  1927.     !cmdsrc() &&
  1928. #endif /* NOICP */
  1929.     backgrd && !server)
  1930.       fatal("Protocol error");
  1931.     xitsta |= what;            /* Save this for doexit(). */
  1932. #ifdef CK_TMPDIR
  1933. /* If we were cd'd temporarily to another device or directory ... */
  1934.     if (f_tmpdir) {
  1935.     int x;
  1936.     x = zchdir((char *) savdir);    /* ... restore previous directory */
  1937.     f_tmpdir = 0;            /* and remember we did it. */
  1938.     debug(F111,"ckcpro.w E tmpdir restored",savdir,x);
  1939.     }
  1940. #endif /* CK_TMPDIR */
  1941. #ifdef IKSDB
  1942.     if (ikdbopen) slotstate(what,"ERROR", (char *)epktmsg, "");
  1943. #endif /* IKSDB */
  1944.     RESUME;
  1945. }
  1946.     break;
  1947. case 72:
  1948.     { success = 0; QUIT; }
  1949.     break;
  1950. case 73:
  1951.     {                    /* Anything not accounted for above */
  1952.     errpkt((CHAR *)"Unexpected packet type"); /* Give error message */
  1953.     window(1);
  1954.     xitsta |= what;            /* Save this for doexit(). */
  1955.     RESUME;                /* and quit */
  1956. }
  1957.     break;
  1958.  
  1959.         }
  1960.     }
  1961. }
  1962.  
  1963. char tbl[] = {
  1964.  -1, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
  1965.  73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
  1966.  73, 73, 73, 73, 73, 71, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
  1967.  73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
  1968.  73, 11, 73,  7, 73, 73, 73,  9,  4, 73,  5,  8, 73, 73, 73,  6,
  1969.  73, 72,  3,  1, 73, 73,  2, 73, 10, 73, 73, 73, 73, 73, 73, 73,
  1970.  -1, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
  1971.  73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
  1972.  73, 73, 73, 73, 73, 15, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
  1973.  73, 73, 73, 73, 73, 73, 73, 73, 73, 13, 73, 73, 73, 73, 73, 73,
  1974.  73, 11, 73,  7, 73, 73, 73,  9,  4, 73,  5,  8, 73, 73, 73,  6,
  1975.  73, 72,  3,  1, 73, 73,  2, 73, 10, 73, 73, 73, 73, 73, 73, 73,
  1976.  -1, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
  1977.  73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
  1978.  73, 73, 56, 73, 73, 71, 52, 73, 73, 73, 73, 73, 73, 73, 73, 73,
  1979.  73, 73, 73, 73, 73, 73, 73, 73, 53, 73, 73, 73, 73, 73, 73, 73,
  1980.  73, 11, 73,  7, 73, 73, 73,  9,  4, 73,  5,  8, 73, 73, 73,  6,
  1981.  73, 72,  3,  1, 73, 73,  2, 73, 10, 73, 73, 73, 73, 73, 73, 73,
  1982.  -1, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
  1983.  73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
  1984.  73, 54, 73, 73, 55, 71, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
  1985.  73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 58, 73, 73, 73, 73, 73,
  1986.  73, 11, 73,  7, 73, 73, 73,  9,  4, 73,  5,  8, 73, 73, 73,  6,
  1987.  73, 72,  3,  1, 73, 73,  2, 73, 10, 73, 73, 73, 73, 73, 73, 73,
  1988.  -1, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
  1989.  73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
  1990.  73, 73, 73, 73, 57, 71, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
  1991.  73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 60, 73, 73, 73, 73, 73,
  1992.  73, 11, 73,  7, 73, 73, 73,  9,  4, 73,  5,  8, 73, 73, 73,  6,
  1993.  73, 59,  3,  1, 73, 73,  2, 73, 10, 73, 73, 73, 73, 73, 73, 73,
  1994.  -1, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
  1995.  73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
  1996.  73, 73, 73, 64, 73, 71, 73, 63, 73, 73, 73, 73, 73, 73, 73, 73,
  1997.  73, 73, 62, 73, 73, 73, 73, 73, 73, 61, 73, 73, 73, 73, 73, 73,
  1998.  73, 11, 73,  7, 73, 73, 73,  9,  4, 73,  5,  8, 73, 73, 73,  6,
  1999.  73, 72,  3,  1, 73, 73,  2, 73, 10, 73, 73, 73, 73, 73, 73, 73,
  2000.  -1, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
  2001.  73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
  2002.  73, 73, 73, 73, 73, 71, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
  2003.  73, 73, 73, 73, 73, 73, 73, 73, 73, 65, 73, 73, 73, 73, 73, 73,
  2004.  73, 11, 73,  7, 73, 73, 73,  9,  4, 73,  5,  8, 73, 73, 73,  6,
  2005.  73, 72,  3,  1, 73, 73,  2, 73, 10, 73, 73, 73, 73, 73, 73, 73,
  2006.  -1, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
  2007.  73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
  2008.  73, 73, 73, 73, 73, 71, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
  2009.  73, 73, 73, 73, 73, 73, 73, 73, 73, 66, 73, 73, 73, 73, 73, 73,
  2010.  73, 11, 73,  7, 73, 73, 73,  9,  4, 73,  5,  8, 73, 73, 73,  6,
  2011.  73, 72,  3,  1, 73, 73,  2, 73, 10, 73, 73, 73, 73, 73, 73, 73,
  2012.  -1, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
  2013.  73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
  2014.  73, 73, 73, 73, 73, 71, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
  2015.  73, 73, 73, 73, 73, 73, 73, 73, 73, 68, 73, 73, 73, 73, 73, 73,
  2016.  73, 11, 73,  7, 73, 73, 73,  9,  4, 73,  5,  8, 73, 73, 73,  6,
  2017.  73, 67,  3,  1, 73, 73,  2, 73, 10, 73, 73, 73, 73, 73, 73, 73,
  2018.  -1, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
  2019.  73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
  2020.  73, 73, 73, 73, 73, 71, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
  2021.  73, 73, 73, 73, 73, 73, 73, 73, 73, 69, 73, 73, 73, 73, 73, 73,
  2022.  73, 11, 73,  7, 73, 73, 73,  9,  4, 73,  5,  8, 73, 73, 73,  6,
  2023.  73, 72,  3,  1, 73, 73,  2, 73, 10, 73, 73, 73, 73, 73, 73, 73,
  2024.  -1, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
  2025.  73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
  2026.  73, 73, 73, 73, 73, 71, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
  2027.  73, 73, 73, 73, 73, 73, 73, 73, 73, 70, 73, 73, 73, 73, 73, 73,
  2028.  73, 11, 73,  7, 73, 73, 73,  9,  4, 73,  5,  8, 73, 73, 73,  6,
  2029.  73, 72,  3,  1, 73, 73,  2, 73, 10, 73, 73, 73, 73, 73, 73, 73,
  2030.  -1, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  2031.  29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  2032.  29, 29, 29, 26, 29, 29, 29, 25, 19, 17, 22, 29, 29, 29, 28, 23,
  2033.  29, 29, 18, 12, 29, 29, 20, 21, 29, 29, 29, 29, 29, 29, 29, 29,
  2034.  29, 11, 29,  7, 29, 29, 29,  9,  4, 29,  5,  8, 29, 29, 29,  6,
  2035.  29, 27,  3,  1, 29, 29,  2, 29, 10, 29, 29, 29, 29, 29, 29, 29,
  2036.  -1, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
  2037.  49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
  2038.  49, 32, 49, 31, 33, 34, 35, 49, 38, 30, 49, 40, 37, 49, 49, 49,
  2039.  49, 49, 39, 41, 42, 45, 47, 46, 36, 49, 49, 49, 49, 49, 49, 49,
  2040.  49, 11, 49,  7, 44, 49, 49,  9,  4, 49,  5,  8, 49, 43, 49,  6,
  2041.  49, 48,  3,  1, 49, 49,  2, 49, 10, 49, 49, 49, 49, 49, 49, 49,
  2042.  -1, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
  2043.  73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
  2044.  73, 73, 73, 73, 73, 71, 73, 73, 73, 17, 73, 73, 73, 73, 73, 73,
  2045.  73, 73, 73, 12, 73, 73, 73, 73, 73, 16, 73, 73, 73, 73, 73, 73,
  2046.  73, 11, 73,  7, 73, 73, 73,  9,  4, 73,  5,  8, 73, 73, 73,  6,
  2047.  73, 72,  3,  1, 73, 73,  2, 73, 10, 73, 73, 73, 73, 73, 73, 73,
  2048.  -1, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
  2049.  73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
  2050.  73, 73, 73, 73, 73, 71, 52, 73, 73, 73, 73, 73, 73, 73, 73, 73,
  2051.  73, 73, 73, 12, 73, 73, 73, 73, 53, 51, 73, 73, 73, 73, 73, 73,
  2052.  73, 11, 73,  7, 73, 73, 73,  9,  4, 73,  5,  8, 73, 73, 73,  6,
  2053.  73, 50,  3,  1, 73, 73,  2, 73, 10, 73, 73, 73, 73, 73, 73, 73,
  2054.  -1, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
  2055.  73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
  2056.  73, 73, 73, 73, 73, 71, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
  2057.  73, 73, 73, 73, 73, 73, 73, 73, 73, 14, 73, 73, 73, 73, 73, 73,
  2058.  73, 11, 73,  7, 73, 73, 73,  9,  4, 73,  5,  8, 73, 73, 73,  6,
  2059.  73, 72,  3,  1, 73, 73,  2, 73, 10, 73, 73, 73, 73, 73, 73, 73,
  2060.   0, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
  2061.  73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
  2062.  73, 73, 73, 73, 73, 71, 73, 73, 73, 73, 73, 73, 73, 73, 73, 24,
  2063.  73, 73, 73, 12, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
  2064.  73, 11, 73,  7, 73, 73, 73,  9,  4, 73,  5,  8, 73, 73, 73,  6,
  2065.  73, 72,  3,  1, 73, 73,  2, 73, 10, 73, 73, 73, 73, 73, 73,73
  2066. };
  2067.  
  2068.  
  2069. /*
  2070.   From here down to proto() are routines that were moved out of the state
  2071.   table switcher because the resulting switch() had become too large.
  2072.   To move the contents of a state-table case to a routine:
  2073.     1. Add a prototype to the list above the state table switcher.
  2074.     2. Make a routine with an appropriate name, returning int.
  2075.     3. Move the code into it.
  2076.     4. Put a call to the new routine in the former spot:
  2077.          rc = name_of_routine();
  2078.          if (rc > -1) return(rc);
  2079.     5. Add "return(-1);" after every RESUME, SERVE, or BEGIN macro and
  2080.        at the end if the code is open-ended.
  2081. */
  2082. static int
  2083. rcv_firstdata() {
  2084.     if (discard) {            /* if we're discarding the file */
  2085.     ack1((CHAR *)"X");        /* just ack the data like this. */
  2086.     cancel++;            /* and count it */
  2087.     BEGIN rdpkt;            /* and wait for more data packets. */
  2088.     return(-1);
  2089.     } else {                /* Not discarding. */
  2090.     rf_err = "Can't open file";
  2091.     if (xflg) {            /* If screen data */
  2092.         if (remfile) {        /* redirected to file */
  2093.         if (rempipe)        /* or pipe */
  2094.           x = openc(ZOFILE,remdest); /* Pipe: start command */
  2095.         else
  2096.           x = opena(remdest,&iattr); /* File: open with attributes */
  2097.         } else {            /* otherwise */
  2098.         x = opent(&iattr);    /* "open" the screen */
  2099.         }
  2100.     } else {            /* otherwise */
  2101. #ifdef CALIBRATE
  2102.         if (calibrate) {        /* If calibration run */
  2103.         x = ckopenx(&iattr);    /* open nothing */
  2104. #ifdef STREAMING
  2105.         if (streaming)        /* Streaming */
  2106.           fastack();        /* ACK without ACKing. */
  2107.         else
  2108. #endif /* STREAMING */
  2109.           ack();        /* Send real ACK */
  2110.         BEGIN rdpkt;        /* Proceed to next state */
  2111.         return(-1);
  2112.         } else
  2113. #endif /* CALIBRATE */
  2114. #ifdef UNIX
  2115. /*
  2116.   In UNIX we can pipe the file data into the mail program, which is to be
  2117.   preferred to writing it out to a temp file and then mailing it afterwards.
  2118.   This depends rather heavily on all UNIXes having a mail command that
  2119.   accepts '-s "subject"' on the command line.  MAILCMD (e.g. mail, Mail, mailx)
  2120.   is defined in ckufio.c.
  2121. */
  2122.         if (*(iattr.disp.val) == 'M') {
  2123.         char *s;
  2124.         char tmp[1024];
  2125.         extern char *MAILCMD;
  2126.         s = iattr.disp.val + 1;
  2127.         sprintf(tmp,"%s -s %c%s%c %s", MAILCMD, '"', ofn1, '"', s);
  2128.         x = openc(ZOFILE,(char *)tmp);
  2129.         } else if (*(iattr.disp.val) == 'P') { /* Ditto for print */
  2130.         char tmp[1024];
  2131.         extern char *PRINTCMD;
  2132.         sprintf(tmp,"%s %s", PRINTCMD, iattr.disp.val + 1);
  2133.         x = openc(ZOFILE,(char *)tmp);
  2134.         } else
  2135. #endif /* UNIX */
  2136.           x = opena(filnam,&iattr);    /* open the file, with attributes */
  2137.     }
  2138.     if (x) {            /* If file was opened ok */
  2139.         int rc, qf;
  2140. #ifndef NOSPL
  2141.         qf = query;
  2142. #else
  2143.         qf = 0;
  2144. #endif /* NOSPL */
  2145.  
  2146. #ifdef CKTUNING
  2147.         rc = (binary && !parity) ?
  2148.           bdecode(rdatap,putfil):
  2149.            decode(rdatap, qf ? puttrm : putfil, 1);
  2150. #else
  2151.         rc = decode(rdatap, qf ? puttrm : putfil, 1);
  2152. #endif /* CKTUNING */
  2153.         if (rc < 0) {
  2154.         errpkt((CHAR *)"Error writing data");
  2155.         RESUME;
  2156.         return(-1);
  2157.         }
  2158. #ifdef STREAMING
  2159.         if (streaming)        /* Streaming was negotiated */
  2160.           fastack();        /* ACK without ACKing. */
  2161.         else
  2162. #endif /* STREAMING */
  2163.           ack();            /* acknowledge it */
  2164.         BEGIN rdpkt;        /* and switch to receive-data state */
  2165.         return(-1);
  2166.     } else {            /* otherwise */
  2167.         errpkt((CHAR *) rf_err);    /* send error packet */
  2168.             RESUME;            /* and quit. */
  2169.         return(-1);
  2170.     }
  2171.     }
  2172. }
  2173.  
  2174. static int
  2175. rcv_shortreply() {
  2176. #ifdef PKTZEROHACK
  2177.     success = 0;
  2178.     debug(F111,"rcv_shortreply",rdatap,ipktlen);
  2179.     if (!strncmp(ipktack,(char *)rdatap,ipktlen)) {
  2180.     /* No it's the ACK to the I packet again */
  2181.     x = scmd(vcmd,(CHAR *)cmarg);    /* So send the REMOTE command again */
  2182.     /* Maybe this should be resend() */
  2183.     debug(F110,"IPKTZEROHACK",ipktack,x);
  2184.     if (x < 0) {
  2185.         errpkt((CHAR *)srimsg);
  2186.         RESUME;
  2187.         return(-1);
  2188.     }
  2189.     } else {
  2190.     ipktack[0] = NUL;
  2191. #endif /* PKTZEROHACK */
  2192.     urserver = 1;
  2193. #ifndef NOSERVER
  2194. #ifndef NOSPL
  2195.     if (query) {            /* If to query, */
  2196.         qbufp = querybuf;        /*  initialize query response buffer */
  2197.         qbufn = 0;
  2198.         querybuf[0] = NUL;
  2199.     }
  2200. #endif /* NOSPL */
  2201.     x = 1;
  2202.     if (remfile) {            /* Response redirected to file */
  2203.         rf_err = "Can't open file";
  2204.         if (rempipe)        /* or pipe */
  2205.           x =
  2206. #ifndef NOPUSH
  2207.         zxcmd(ZOFILE,remdest)    /* Pipe: Start command */
  2208. #else
  2209.         0
  2210. #endif /* NOPUSH */
  2211.         ;
  2212.         else
  2213.           x = opena(remdest,&iattr); /* File: Open with attributes */
  2214.         debug(F111,"rcv_shortreply remfile",remdest,x);
  2215.     } else {
  2216.         x = opent(&iattr);        /* "open" the screen */
  2217.     }
  2218.     if (x) {            /* If file was opened ok */
  2219.         if (decode(rdatap,
  2220. #ifndef NOSPL
  2221.                (query || !remfile) ? puttrm :
  2222. #else
  2223.                !remfile ? puttrm :
  2224. #endif /* NOSPL */
  2225.                zputfil, 1) < 0) { /* Note: zputfil, not putfil. */
  2226.         errpkt((CHAR *)"Error writing data");
  2227.         RESUME;
  2228.         return(-1);
  2229.         } else {
  2230.         if (rdatap)        /* If we had data */
  2231.           if (*rdatap)        /* add a line terminator */
  2232.             if (remfile) {    /* to file */
  2233.             zsoutl(ZOFILE,"");
  2234.             } else {        /* or to screen. */
  2235. #ifndef NOICP
  2236.             if (!query || !cmdsrc())
  2237. #endif /* NOICP */
  2238.               conoll("");
  2239.             }
  2240.         if (bye_active && network) { /* I sent BYE or REMOTE LOGOUT */
  2241.             msleep(500);    /* command and got the ACK... */
  2242.             bye_active = 0;
  2243.             ttclos(0);
  2244.         }
  2245.         clsof(0);
  2246.         if (!epktsent && !epktrcvd) /* If no error packet... */
  2247.           success = 1;        /* success. */
  2248.         RESUME;
  2249.         return(-1);
  2250.         }
  2251.     } else {            /* File not opened OK */
  2252.         errpkt((CHAR *) rf_err);    /* send error message */
  2253.         RESUME;            /* and quit. */
  2254.         return(-1);
  2255.     }
  2256. #endif /* NOSERVER */
  2257. #ifdef PKTZEROHACK
  2258.     }
  2259. #endif /* PKTZEROHACK */
  2260.     debug(F101,"rcv_shortreply fallthru","",success);
  2261.     return(-1);
  2262. }
  2263.  
  2264.  
  2265. static int
  2266. srv_query() {
  2267. #ifndef NOSERVER
  2268. #ifndef NOSPL
  2269.     char c;
  2270. #ifdef CKSYSLOG
  2271.     if (ckxsyslog >= SYSLG_PR && ckxlogging)
  2272.       cksyslog(SYSLG_PR, 1, "server", "REMOTE QUERY", (char *)srvcmd);
  2273. #endif /* CKSYSLOG */
  2274. #ifdef IKSDB
  2275.     if (ikdbopen) slotstate(what,"REMOTE QUERY", (char *)(srvcmd+2), "");
  2276. #endif /* IKSDB */
  2277.     c = *(srvcmd+2);            /* Q = Query, S = Set */
  2278.     if (c == 'Q') {            /* Query */
  2279.     if (!ENABLED(en_que)) { /* Security */
  2280.         errpkt((CHAR *)"REMOTE QUERY disabled");
  2281.         RESUME;
  2282.         return(-1);
  2283.     } else {            /* Query allowed */
  2284.         int n; char *p, *q;
  2285.         qbufp = querybuf;        /* Wipe out old stuff */
  2286.         qbufn = 0;
  2287.         querybuf[0] = NUL;
  2288.         p = (char *) srvcmd + 3;    /* Pointer for making wrapper */
  2289.         n = strlen((char *)srvcmd);    /* Position of end */
  2290.         c = *(srvcmd+4);        /* Which type of variable */
  2291.  
  2292.         if (*(srvcmd+6) == CMDQ) {    /* Starts with command quote? */
  2293.         p = (char *) srvcmd + 6; /* Take it literally */
  2294.         if (*p == CMDQ) p++;
  2295.         } else {            /* They played by the rules */
  2296.         if (c == 'K') {        /* Kermit variable */
  2297.             int k;
  2298.             k = (int) strlen(p);
  2299.             if (k > 0 && p[k-1] == ')') {
  2300.             p = (char *)(srvcmd + 4);
  2301.             *(srvcmd+4) = CMDQ;
  2302.             *(srvcmd+5) = 'f'; /* Function, so make it \f...() */
  2303.             } else {
  2304.             *(srvcmd+3) = CMDQ; /* Stuff wrapping into buffer */
  2305.             *(srvcmd+4) = 'v';  /* Variable, so make it \v(...) */
  2306.             *(srvcmd+5) = '(';  /* around variable name */
  2307.             *(srvcmd+n) = ')';
  2308.             *(srvcmd+n+1) = NUL;
  2309.             }
  2310.         } else {
  2311.             *(srvcmd+3) = CMDQ; /* Stuff wrapping into buffer */
  2312.             *(srvcmd+4) = 'v'; /*  Variable, so make it \v(...) */
  2313.             *(srvcmd+5) = '(';    /* around variable name */
  2314.             *(srvcmd+n) = ')';
  2315.             *(srvcmd+n+1) = NUL;
  2316.             if (c == 'S') {    /* System variable */
  2317.             *(srvcmd+4) = '$'; /*  so it's \$(...) */
  2318.             } else if (c == 'G') { /* Non-\ Global variable */
  2319.             *(srvcmd+4) = 'm'; /*  so wrap it in \m(...) */
  2320.             }
  2321.         }
  2322.         }                /* Now evaluate it */
  2323.         n = QBUFL;            /* Max length */
  2324.         q = querybuf;        /* Where to put it */
  2325.         if (zzstring(p,&q,&n) < 0) {
  2326.         errpkt((n > 0) ? (CHAR *)"Can't get value"
  2327.                        : (CHAR *)"Value too long"
  2328.                );
  2329.         RESUME;
  2330.         return(-1);
  2331.         } else {
  2332.         if (encstr((CHAR *)querybuf) > -1) { /* Encode it */
  2333.             ack1(data);        /* If it fits, send it back in ACK */
  2334.             success = 1;
  2335.             RESUME;
  2336.             return(-1);
  2337.         } else if (sndstring(querybuf)) { /* Long form response */
  2338.             BEGIN ssinit;
  2339.             return(-1);
  2340.         } else {        /* sndhlp() fails */
  2341.             errpkt((CHAR *)"Can't send value");
  2342.             RESUME;
  2343.             return(-1);
  2344.         }
  2345.         }
  2346.     }
  2347.     } else if (c == 'S') {        /* Set (assign) */
  2348.     if (!ENABLED(en_asg)) {        /* Security */
  2349.         errpkt((CHAR *)"REMOTE ASSIGN disabled");
  2350.         RESUME;
  2351.         return(-1);
  2352.     } else {            /* OK */
  2353.         int n;
  2354.         n = xunchar(*(srvcmd+3));    /* Length of name */
  2355.         n = 3 + n + 1;        /* Position of length of value */
  2356.         *(srvcmd+n) = NUL;        /* Don't need it */
  2357.         if (addmac((char *)(srvcmd+4),(char *)(srvcmd+n+1)) < 0)
  2358.           errpkt((CHAR *)"REMOTE ASSIGN failed");
  2359.         else {
  2360.         ack();
  2361.         success = 1;
  2362.         }
  2363.         RESUME;
  2364.         return(-1);
  2365.     }
  2366.     } else {
  2367.     errpkt((CHAR *)"Badly formed server command");
  2368.     RESUME;
  2369.     return(-1);
  2370.     }
  2371. #else
  2372.     errpkt((CHAR *)"Variable query/set not available");
  2373.     RESUME;
  2374.     return(-1);
  2375. #endif /* NOSPL */
  2376. #endif /* NOSERVER */
  2377. }
  2378.  
  2379. static int
  2380. srv_copy() {
  2381. #ifndef NOSERVER
  2382. #ifdef CKSYSLOG
  2383.     if (ckxsyslog >= SYSLG_PR && ckxlogging)
  2384.       cksyslog(SYSLG_PR, 1, "server", "REMOTE COPY", (char *)srvcmd);
  2385. #endif /* CKSYSLOG */
  2386. #ifdef ZCOPY
  2387.     if (!ENABLED(en_cpy)) {
  2388.     errpkt((CHAR *)"REMOTE COPY disabled");
  2389.     RESUME;
  2390.     return(-1);
  2391.     } else {
  2392.     char *str1, *str2, f1[256], f2[256];
  2393.     int  len1, len2;
  2394.         len1 = xunchar(srvcmd[1]);    /* Separate the parameters */
  2395.         len2 = xunchar(srvcmd[2+len1]);
  2396.         strncpy(f1,(char *)(srvcmd+2),len1);
  2397.         f1[len1] = NUL;
  2398.         strncpy(f2,(char *)(srvcmd+3+len1),len2);
  2399.         f2[len2] = NUL;
  2400. #ifdef IKSDB
  2401.     if (ikdbopen) slotstate(what,"REMOTE COPY", f1, f2);
  2402. #endif /* IKSDB */
  2403.     if (!ENABLED(en_cwd)) {        /* If CWD is disabled */
  2404.         zstrip(f1,&str1);        /* and they included a pathname, */
  2405.             zstrip(f2,&str2);
  2406.         if (strcmp(f1,str1) || strcmp(f2,str2)) { /* Refuse. */
  2407.         errpkt((CHAR *)"Access denied");
  2408.         RESUME;            /* Remember, this is not a goto! */
  2409.         return(-1);
  2410.         }
  2411.     }
  2412.     if (state == generic) {        /* It's OK to go ahead. */
  2413.             if (zcopy(f1,f2)) {        /* Try */
  2414.         errpkt((CHAR *)"Can't copy file"); /* give error message */
  2415.         } else {
  2416.         success = 1;
  2417.         ack();
  2418.         }
  2419.             RESUME;            /* wait for next server command */
  2420.         return(-1);
  2421.     }
  2422.     }
  2423.     return(-1);
  2424. #else /* no ZCOPY */
  2425.     errpkt((CHAR *)"REMOTE COPY not available"); /* give error message */
  2426.     RESUME;                /* wait for next server command */
  2427.     return(-1);
  2428. #endif /* ZCOPY */
  2429. #endif /* NOSERVER */
  2430. }
  2431.  
  2432. static int
  2433. srv_rename() {
  2434. #ifndef NOSERVER
  2435. #ifdef CKSYSLOG
  2436.     if (ckxsyslog >= SYSLG_PR && ckxlogging)
  2437.       cksyslog(SYSLG_PR, 1, "server", "REMOTE RENAME", (char *)srvcmd);
  2438. #endif /* CKSYSLOG */
  2439. #ifdef ZRENAME
  2440.     if (!ENABLED(en_ren)) {
  2441.     errpkt((CHAR *)"REMOTE RENAME disabled");
  2442.     RESUME;
  2443.     return(-1);
  2444.     } else {                /* RENAME is enabled */
  2445.     char *str1, *str2, f1[256], f2[256];
  2446.     int len1, len2;
  2447.     len1 = xunchar(srvcmd[1]);    /* Separate the parameters */
  2448.     len2 = xunchar(srvcmd[2+len1]);
  2449.     strncpy(f1,(char *)(srvcmd+2),len1);
  2450.     f1[len1] = NUL;
  2451.     strncpy(f2,(char *)(srvcmd+3+len1),len2);
  2452.     f2[len2] = NUL;
  2453.     len2 = xunchar(srvcmd[2+len1]);
  2454.     strncpy(f1,(char *)(srvcmd+2),len1);
  2455.     f1[len1] = NUL;
  2456.     strncpy(f2,(char *)(srvcmd+3+len1),len2);
  2457.     f2[len2] = NUL;
  2458. #ifdef IKSDB
  2459.     if (ikdbopen) slotstate(what,"REMOTE RENAME", f1, f2);
  2460. #endif /* IKSDB */
  2461.     if (!ENABLED(en_cwd)) {        /* If CWD is disabled */
  2462.         zstrip(f1,&str1);        /* and they included a pathname, */
  2463.         zstrip(f2,&str2);
  2464.         if ( strcmp(f1,str1) || strcmp(f2,str2) ) { /* refuse. */
  2465.         errpkt((CHAR *)"Access denied");
  2466.         RESUME;            /* Remember, this is not a goto! */
  2467.         return(-1);
  2468.         }
  2469.     }
  2470.     if (state == generic) {        /* It's OK to go ahead. */
  2471.         if (zrename(f1,f2)) {    /* Try */
  2472.         errpkt((CHAR *)"Can't rename file"); /* Give error msg */
  2473.         } else {
  2474.         success = 1;
  2475.         ack();
  2476.         }
  2477.         RESUME;            /* Wait for next server command */
  2478.         return(-1);
  2479.     }
  2480.     }
  2481.     return(-1);
  2482. #else /* no ZRENAME */
  2483.     /* Give error message */
  2484.     errpkt((CHAR *)"REMOTE RENAME not available");
  2485.     RESUME;                /* Wait for next server command */
  2486.     return(-1);
  2487. #endif /* ZRENAME */
  2488. #endif /* NOSERVER */
  2489. }
  2490.  
  2491. static int
  2492. srv_login() {
  2493. #ifndef NOSERVER
  2494.     char f1[LOGINLEN+1], f2[LOGINLEN+1], f3[LOGINLEN+1];
  2495.     CHAR *p;
  2496.     int len, i;
  2497.  
  2498.     debug(F101,"REMOTE LOGIN x_login","",x_login);
  2499.     debug(F101,"REMOTE LOGIN x_logged","",x_logged);
  2500.  
  2501.     f1[0] = NUL; f2[0] = NUL; f3[0] = NUL;
  2502.     len = 0;
  2503.     if (srvcmd[1])            /* First length field */
  2504.       len = xunchar(srvcmd[1]);        /* Separate the parameters */
  2505.  
  2506.     if (x_login) {            /* Login required */
  2507.     if (x_logged) {            /* And already logged in */
  2508.         if (len > 0) {        /* Logging in again */
  2509.         errpkt((CHAR *)"Already logged in.");
  2510.         } else {            /* Logging out */
  2511.         debug(F101,"REMOTE LOGOUT","",x_logged);
  2512. #ifdef CKSYSLOG
  2513.         if (ckxsyslog >= SYSLG_PR && ckxlogging)
  2514.           cksyslog(SYSLG_PR, 1, "server", "REMOTE LOGOUT", NULL);
  2515. #endif /* CKSYSLOG */
  2516. #ifdef IKSDB
  2517.         if (ikdbopen) slotstate(what,"REMOTE LOGOUT", "", "");
  2518. #endif /* IKSDB */
  2519.         tlog(F110,"Logged out",x_user,0);
  2520.         ack1((CHAR *)"Logged out");
  2521.         success = 1;
  2522.         msleep(500);
  2523. #ifdef CK_LOGIN
  2524.         x_logged = 0;
  2525. #ifdef IKSD
  2526.         if (inserver)
  2527.           ckxlogout();
  2528. #endif /* IKSD */
  2529. #endif /* CK_LOGIN */
  2530.         }
  2531.     } else {            /* Not logged in yet */
  2532.         debug(F101,"REMOTE LOGIN len","",len);
  2533.         if (len > 0) {        /* Have username */
  2534. #ifdef CKSYSLOG
  2535.         if (ckxsyslog >= SYSLG_PR && ckxlogging)
  2536.           cksyslog(SYSLG_PR, 1, "server", "REMOTE LOGIN", NULL);
  2537. #endif /* CKSYSLOG */
  2538.         if (len > LOGINLEN) {
  2539.             errpkt((CHAR *)"Username too long");
  2540.         }
  2541.         p = srvcmd + 2;        /* Point to it */
  2542.         for (i = 0; i < len; i++) /* Copy it */
  2543.           f1[i] = p[i];
  2544.         f1[len] = NUL;        /* Terminate it */
  2545.         p += len;        /* Point to next length field */
  2546.         if (*p) {        /* If we have one */
  2547.             len = xunchar(*p++); /* decode it */
  2548.             if (len > 0 && len <= LOGINLEN) {
  2549.             for (i = 0; i < len; i++) /* Same deal for password */
  2550.               f2[i] = p[i];
  2551.             f2[len] = NUL;
  2552.             p += len;    /* And account */
  2553.             if (*p) {
  2554.                 len = xunchar(*p++);
  2555.                 if (len > 0 && len <= LOGINLEN) {
  2556.                 for (i = 0; i < len; i++)
  2557.                   f3[i] = p[i];    /* Set but never used */
  2558.                 f3[len] = NUL; /* (because account not used) */
  2559.                 }
  2560.             }
  2561.             }
  2562.         }
  2563.         debug(F101,"REMOTE LOGIN 1","",x_logged);
  2564. #ifdef IKSD
  2565. #ifdef CK_LOGIN
  2566.         if (inserver) {        /* Log in to system for real */
  2567.             x_logged = ckxlogin((CHAR *)f1,(CHAR *)f2,NULL,0);
  2568.             debug(F101,"REMOTE LOGIN 2","",x_logged);
  2569.             if (x_logged) {    /* Count attempts */
  2570.             logtries = 0;
  2571.             justone = 1;
  2572.             } else {
  2573.             logtries++;
  2574.             sleep(logtries);
  2575.             }
  2576.         } else
  2577. #endif /* CK_LOGIN */
  2578. #endif /* IKSD */
  2579.           if (x_user && x_passwd) { /* User and password must match */
  2580.               if (!strcmp(x_user,f1)) /* SET SERVER LOGIN */
  2581.             if (!strcmp(x_passwd,f2))
  2582.               x_logged = 1;
  2583.               debug(F101,"REMOTE LOGIN 3","",x_logged);
  2584.           } else if (x_user) {    /* Only username given, no password */
  2585.               if (!strcmp(x_user,f1)) /* so only username must match */
  2586.             x_logged = 1;
  2587.               debug(F101,"REMOTE LOGIN 4","",x_logged);
  2588.           }
  2589.         if (x_logged) {        /* Logged in? */
  2590.             tlog(F110,"Logged in", x_user, 0);
  2591.             if (isguest)
  2592.               ack1((CHAR *)"Logged in as guest - restrictions apply");
  2593.             else
  2594.               ack1((CHAR *)"Logged in");
  2595.             success = 1;
  2596.         } else {
  2597.             tlog(F110,"Login failed", f1, 0);
  2598.             errpkt((CHAR *)"Access denied.");
  2599. #ifdef IKSD
  2600. #ifdef CK_LOGIN
  2601.             if (inserver && logtries > 2)
  2602.               ckxlogout();
  2603. #endif /* CK_LOGIN */
  2604. #endif /* IKSD */
  2605.         }
  2606.         } else {            /* LOGOUT */
  2607.         errpkt((CHAR *)"Logout ignored");
  2608.         }
  2609.     }
  2610.     } else {                /* Login not required */
  2611.     if (len > 0)
  2612.       errpkt((CHAR *)"Login ignored.");
  2613.     else
  2614.       errpkt((CHAR *)"Logout ignored.");
  2615.     }
  2616. #endif /* NOSERVER */
  2617.     RESUME;
  2618.     return(-1);
  2619. }
  2620.  
  2621. static int
  2622. srv_timeout() {
  2623. #ifndef OS2
  2624.     /* K95 does this its own way */
  2625.     if (idletmo) {
  2626. #ifdef IKSD
  2627.         if (inserver) {
  2628.            printf("\r\nIKSD IDLE TIMEOUT: %d sec\r\n", srvidl);
  2629.            doexit(GOOD_EXIT,xitsta);
  2630.         }
  2631. #endif /* IKSD */
  2632.     idletmo = 0;
  2633.     printf("\r\nSERVER IDLE TIMEOUT: %d sec\r\n", srvidl);
  2634.     xitsta |= what;
  2635.     QUIT;
  2636.     }
  2637. #endif /* OS2 */
  2638. #ifndef NOSERVER
  2639. #ifndef OS2
  2640.     else
  2641. #endif /* OS2 */
  2642.       if (fatalio) {            /* Connection lost */
  2643. #ifdef CKSYSLOG
  2644.       if (ckxsyslog >= SYSLG_PR && ckxlogging)
  2645.         cksyslog(SYSLG_PR, 1, "server", "Connection lost", NULL);
  2646. #endif /* CKSYSLOG */
  2647. #ifdef IKSDB
  2648.       if (ikdbopen) slotstate(what,"SERVER DISCONNECT",(char *)srvcmd, "");
  2649. #endif /* IKSDB */
  2650.     xitsta |= what;
  2651.     QUIT;
  2652.     } else if (interrupted) {        /* Interrupted by hand */
  2653.     if (!ENABLED(en_fin)) {
  2654.         errpkt((CHAR *)"QUIT disabled");
  2655.         RESUME;
  2656.         return(-1);
  2657.     } else {
  2658.         if (what == W_SEND || what == W_RECV || what == W_REMO) {
  2659.         success = 0;
  2660. #ifdef CKSYSLOG
  2661.         if (ckxsyslog >= SYSLG_PR && ckxlogging)
  2662.           cksyslog(SYSLG_PR, 1, "server", "Interrupted", NULL);
  2663. #endif /* CKSYSLOG */
  2664.         } else if (what == W_NOTHING && filcnt == 0) {
  2665.         success = 1;
  2666.         } /* Otherwise leave success alone */
  2667.         xitsta |= what;
  2668.         QUIT;
  2669.     }
  2670.     } else {                /* Shouldn't happen */
  2671.     debug(F100,"SERVER (top) GOT UNEXPECTED 'q'","",0);
  2672.     QUIT;
  2673.     }
  2674. #endif /* NOSERVER */
  2675. }
  2676.  
  2677. static int
  2678. rcv_s_pkt() {
  2679. #ifndef NOSERVER
  2680.     if (state == rgen)
  2681.       urserver = 1;
  2682.     if (/* state == serve && */ x_login && !x_logged) {
  2683.     errpkt((CHAR *)"Login required");
  2684.     SERVE;
  2685.     } else
  2686. #endif /* NOSERVER */
  2687.       if (state == serve && !ENABLED(en_sen)) { /* Not in server mode */
  2688.     errpkt((CHAR *)"SEND disabled"); /* when SEND is disabled. */
  2689.     RESUME;
  2690.     return(-1);
  2691.     } else {                /* OK to go ahead. */
  2692. #ifdef CK_TMPDIR
  2693.     if (dldir && !f_tmpdir) {    /* If they have a download directory */
  2694.         debug(F110,"receive download dir",dldir,0);
  2695.         if (s = zgtdir()) {        /* Get current directory */
  2696.         debug(F110,"receive current dir",s,0);
  2697.         if (zchdir(dldir)) {    /* Change to download directory */
  2698.             debug(F100,"receive zchdir ok","",0);
  2699.             ckstrncpy(savdir,s,TMPDIRLEN);
  2700.             f_tmpdir = 1;    /* Remember that we did this */
  2701.         } else
  2702.           debug(F100,"receive zchdir failed","",0);
  2703.         }
  2704.     }
  2705. #endif /* CK_TMPDIR */
  2706.     nakstate = 1;            /* Can send NAKs from here. */
  2707.     rinit(rdatap);            /* Set parameters */
  2708.     bctu = bctr;            /* Switch to agreed-upon block check */
  2709.     bctl = (bctu == 4) ? 2 : bctu;    /* Set block-check length */
  2710.     what = W_RECV;            /* Remember we're receiving */
  2711.     lastxfer = W_RECV;
  2712.     resetc();            /* Reset counters */
  2713.     rtimer();            /* Reset timer */
  2714. #ifdef GFTIMER
  2715.     rftimer();
  2716. #endif /* GFTIMER */
  2717.     streamon();
  2718.     BEGIN rfile;            /* Go into receive-file state */
  2719.     }
  2720.     return(-1);
  2721. }
  2722.  
  2723. /* END OF ROUTINES MOVED OUT OF STATE MACHINE */
  2724.  
  2725.  
  2726. /*  P R O T O  --  Protocol entry function  */
  2727.  
  2728. static int is_tn = 0;            /* It's a Telnet connection */
  2729.  
  2730. #ifdef CK_SPEED
  2731. int f_ctlp = 0;                /* Control-character prefix table */
  2732. #ifdef COMMENT
  2733. short s_ctlp[256];
  2734. #endif /* COMMENT */
  2735. #endif /* CK_SPEED */
  2736.  
  2737. /*
  2738.   This is simply a wrapper for the real protocol function just below,
  2739.   that saves any items that might be changed automatically by protocol
  2740.   negotiations and then restores them upon exit from protocol mode.
  2741. */
  2742. VOID
  2743. proto() {
  2744.     extern int b_save, f_save, c_save, ss_save, slostart, reliable, urclear;
  2745. #ifndef NOCSETS
  2746.     extern int fcharset, fcs_save, tcharset, tcs_save;
  2747. #endif /* NOCSETS */
  2748.  
  2749. #ifdef PIPESEND
  2750.     extern int pipesend;
  2751. #endif /* PIPESEND */
  2752. #ifdef OS2
  2753.     extern int cursorena[], cursor_save, term_io;
  2754.     extern BYTE vmode;
  2755.     extern int display_demo;
  2756.     int term_io_save;
  2757. #endif /* OS2 */
  2758. #ifdef TNCODE
  2759.     int _u_bin=0, _me_bin=0;
  2760. #ifdef IKS_OPTION
  2761.     int _u_start=0, _me_start=0;
  2762. #endif /* IKS_OPTION */
  2763. #endif /* TNCODE */
  2764. #ifdef PATTERNS
  2765.     extern int patterns;
  2766.     int pa_save;
  2767.     int i;
  2768. #endif /* PATTERNS */
  2769.  
  2770. #ifdef PATTERNS
  2771.     pa_save = patterns;
  2772. #endif /* PATTERNS */
  2773.  
  2774. #ifdef CK_LOGIN
  2775.     if (isguest) {            /* If user is anonymous */
  2776.     en_pri = 0;            /* disable printing */
  2777.     en_mai = 0;            /* and disable email */
  2778.     en_del = 0;            /* and file deletion */
  2779.     }
  2780. #endif /* CK_LOGIN */
  2781.  
  2782. #ifdef OS2
  2783.     cursor_save = cursorena[vmode];
  2784.     cursorena[vmode] = 0;
  2785.     term_io_save = term_io;
  2786.     term_io = 0;
  2787. #endif /* OS2 */
  2788.     b_save = binary;            /* SET FILE TYPE */
  2789.     f_save = fncnv;            /* SET FILE NAMES */
  2790.     c_save = bctr;
  2791.     p_save = fnspath;
  2792.     r_save = recursive;
  2793.     s_timint = timint;
  2794.     ss_save = slostart;
  2795. #ifndef NOCSETS
  2796.     fcs_save = fcharset;
  2797.     tcs_save = tcharset;
  2798. #endif /* NOCSETS */
  2799.  
  2800. #ifdef COMMENT
  2801. /* Don't do this because then user can never find out what happened. */
  2802. #ifdef CK_SPEED
  2803.     for (i = 0; i < 256; i++)
  2804.       s_ctlp[i] = ctlp[i];
  2805.     f_ctlp = 1;
  2806. #endif /* CK_SPEED */
  2807. #endif /* COMMENT */
  2808.     if (reliable == SET_ON)
  2809.       slostart = 0;
  2810.     is_tn = (!local && sstelnet)
  2811. #ifdef TNCODE
  2812.       || (local && network && ttnproto == NP_TELNET)
  2813. #endif /* TNCODE */
  2814.     ;
  2815. #ifdef TNCODE
  2816.     if (is_tn) {
  2817.         if (tn_b_xfer && !(sstelnet || inserver)) {
  2818.         /* Save the current state of Telnet Binary */
  2819.         _u_bin = TELOPT_U(TELOPT_BINARY);
  2820.         _me_bin = TELOPT_ME(TELOPT_BINARY);
  2821.  
  2822.         /* If either direction is not Binary attempt to negotiate it */
  2823.         if (!_u_bin && TELOPT_U_MODE(TELOPT_BINARY) != TN_NG_RF) {
  2824.         tn_sopt(DO,TELOPT_BINARY);
  2825.         TELOPT_UNANSWERED_DO(TELOPT_BINARY) = 1;
  2826.         }
  2827.         if (!_me_bin && TELOPT_ME_MODE(TELOPT_BINARY) != TN_NG_RF) {
  2828.         tn_sopt(WILL,TELOPT_BINARY);
  2829.         TELOPT_UNANSWERED_WILL(TELOPT_BINARY) = 1;
  2830.         }
  2831.         if (!(_me_bin && _u_bin))
  2832.           tn_wait("proto set binary mode");
  2833.         }
  2834. #ifdef IKS_OPTION
  2835.         if (sstate == 'x' || sstate == 'v') { /* Responding to a request */
  2836.             if (!inserver && TELOPT_U(TELOPT_KERMIT) &&
  2837.                 TELOPT_SB(TELOPT_KERMIT).kermit.u_start) {
  2838.                 iks_wait(KERMIT_REQ_STOP,0); /* Stop the other Server */
  2839.         _u_start = 1;
  2840.             }
  2841.             if (TELOPT_ME(TELOPT_KERMIT) &&
  2842.                 !TELOPT_SB(TELOPT_KERMIT).kermit.me_start) {
  2843.                 tn_siks(KERMIT_START);    /* Send Kermit-Server Start */
  2844.          TELOPT_SB(TELOPT_KERMIT).kermit.me_start = 1;
  2845.             }
  2846.         } else {            /* Initiating a request */
  2847.             if (TELOPT_ME(TELOPT_KERMIT) &&
  2848.                 TELOPT_SB(TELOPT_KERMIT).kermit.me_start) {
  2849.                 tn_siks(KERMIT_STOP);    /* I'm not servering */
  2850.          TELOPT_SB(TELOPT_KERMIT).kermit.me_start = 0;
  2851.         _me_start = 1;
  2852.             }
  2853.             if (TELOPT_U(TELOPT_KERMIT) &&
  2854.             !TELOPT_SB(TELOPT_KERMIT).kermit.u_start) {
  2855.         /* Send Req-Server-Start */
  2856.                 if (!iks_wait(KERMIT_REQ_START,0)) {
  2857.                     if (sstate != 's') {
  2858.             success = 0;    /* Other Kermit refused to serve */
  2859.             if (local)
  2860.               printf("A Kermit server is not available\r\n");
  2861.             debug(F110,"proto()",
  2862.                              "A Kermit Server is not available",0);
  2863.             tlog(F110,"IKS client/server failure",
  2864.                              "A Kermit Server is not available",0);
  2865.             goto xxprotox;
  2866.                     }
  2867.         }
  2868.             }
  2869.         }
  2870. #endif /* IKS_OPTION */
  2871. #ifdef CK_ENCRYPTION
  2872.         if (tn_no_encrypt_xfer && !(sstelnet || inserver)) {
  2873.             ck_tn_enc_stop();
  2874.         }
  2875. #endif /* CK_ENCRYPTION */
  2876.     }
  2877. #endif /* TNCODE */
  2878.  
  2879.     if (!xfrint) connoi();
  2880.     xxproto();                /* Call the real protocol function */
  2881.  
  2882. #ifdef IKS_OPTION
  2883.   xxprotox:
  2884. #endif /* IKS_OPTION */
  2885.     xferstat = success;            /* Remember transfer status */
  2886.     kactive = 0;
  2887.  
  2888. #ifdef TNCODE
  2889. #ifdef CK_ENCRYPTION
  2890.         if (tn_no_encrypt_xfer && !(sstelnet || inserver)) {
  2891.             ck_tn_enc_start();
  2892.         }
  2893. #endif /* CK_ENCRYPTION */
  2894. #ifdef IKS_OPTION
  2895.     if (TELOPT_ME(TELOPT_KERMIT) &&
  2896.         TELOPT_SB(TELOPT_KERMIT).kermit.me_start && !_me_start) {
  2897.         tn_siks(KERMIT_STOP);        /* Server is stopped */
  2898.      TELOPT_SB(TELOPT_KERMIT).kermit.me_start = 0;
  2899.     }
  2900. #endif /* IKS_OPTION */
  2901.     if (is_tn && tn_b_xfer && !(sstelnet || inserver)) {
  2902.         /* if we negotiated Binary mode try to reset it */
  2903.         if (!_u_bin) {
  2904.             /* Check to see if the state changed during the transfer */
  2905.         if (TELOPT_U(TELOPT_BINARY)) {
  2906.         tn_sopt(DONT,TELOPT_BINARY);
  2907.         TELOPT_UNANSWERED_DONT(TELOPT_BINARY) = 1;
  2908.         } else
  2909.           _u_bin = 1;        /* So we don't call tn_wait() */
  2910.         }
  2911.         if (!_me_bin) {
  2912.             /* Check to see if the state changed during the transfer */
  2913.         if (TELOPT_ME(TELOPT_BINARY)) {
  2914.         tn_sopt(WONT,TELOPT_BINARY);
  2915.         TELOPT_UNANSWERED_WONT(TELOPT_BINARY) = 1;
  2916.         } else
  2917.           _me_bin = 1;        /* So we don't call tn_wait() */
  2918.     }
  2919.     if (!(_me_bin && _u_bin))
  2920.       tn_wait("proto reset binary mode");
  2921.     }
  2922. #endif /* TNCODE */
  2923.  
  2924. #ifdef PATTERNS
  2925.     patterns = pa_save;
  2926. #endif /* PATTERNS */
  2927.  
  2928. #ifdef STREAMING
  2929.     streaming = 0;
  2930.     /* streamok = 0; */
  2931. #endif /* STREAMING */
  2932. #ifdef COMMENT
  2933. #ifdef CK_SPEED
  2934.     for (i = 0; i < 256; i++)
  2935.       ctlp[i] = s_ctlp[i];
  2936.     f_ctlp = 0;
  2937. #endif /* CK_SPEED */
  2938. #endif /* COMMENT */
  2939.     urclear = 0;
  2940.     if (!success) {
  2941.     xitsta |= what;
  2942.     tlog(F110," failed:",(char *)epktmsg,0);
  2943.     }
  2944.     debug(F111,"proto xferstat",epktmsg,xferstat);
  2945.     slostart = ss_save;
  2946.     if (s_timint > -1) {        /* Because of REMOTE SET */
  2947.     timint = s_timint;
  2948.     s_timint = -1;
  2949.     }
  2950.     recursive = r_save;
  2951.     fnspath = p_save;
  2952.     if (c_save > -1) {            /* Because of REMOTE SET */
  2953.     bctr = c_save;
  2954.     c_save = -1;
  2955.     }
  2956.     fncnv   = f_save;
  2957.     binary  = b_save;
  2958. #ifdef PIPESEND
  2959.     pipesend = 0;                /* Next time might not be pipesend */
  2960. #endif /* PIPESEND */
  2961. #ifdef OS2
  2962.     cursorena[vmode] = cursor_save;
  2963.     term_io = term_io_save;
  2964.     display_demo = 1;
  2965. #endif /* OS2 */
  2966. }
  2967.  
  2968. static VOID
  2969. xxproto() {
  2970.     int x;
  2971.     long lx;
  2972. #ifdef CK_XYZ
  2973. #ifdef XYZ_INTERNAL
  2974. _PROTOTYP( int pxyz, (int) );
  2975. #endif /* XYZ_INTERNAL */
  2976. #endif /* CK_XYZ */
  2977.  
  2978.     char xss[2];            /* String representation of sstate */
  2979.     xss[0] = sstate;
  2980.     xss[1] = NUL;
  2981.     s_timint = timint;
  2982.  
  2983.     debug(F101,"xxproto entry justone","",justone);
  2984.     success = 0;
  2985.  
  2986.     retrieve = 0;            /* Reset these ... */
  2987.     reget = 0;
  2988.     opkt = 0;
  2989.  
  2990.     if (local && ttchk() < 0) {        /* Giving BYE or FIN */
  2991.     if (bye_active) {        /* but there is no connection */
  2992.         ttclos(0);
  2993.         success = 1;
  2994.         return;
  2995.     }
  2996.     /* Ditto for any REMOTE command */
  2997.     if (sstate == 'g' && cmarg ) {
  2998.         if (*cmarg == 'L' || *cmarg == 'F' || *cmarg == 'X')
  2999.           success = 1;
  3000.         else
  3001.           printf("?No connection\r\n");
  3002.         return;
  3003.     }
  3004.     }
  3005.  
  3006. /* Set up the communication line for file transfer. */
  3007.  
  3008.     if (local && (speed < 0L) && (network == 0)) {
  3009.     xxscreen(SCR_EM,0,0L,"Sorry, you must 'set speed' first");
  3010.     return;
  3011.     }
  3012.     x = -1;
  3013.     if (ttopen(ttname,&x,mdmtyp,cdtimo) < 0) {
  3014.     debug(F111,"failed: proto ttopen local",ttname,local);
  3015.     xxscreen(SCR_EM,0,0L,"Can't open line");
  3016.     return;
  3017.     }
  3018.     if (x > -1) local = x;
  3019.     debug(F111,"proto ttopen local",ttname,local);
  3020.  
  3021.     lx = (local && !network) ? speed : -1;
  3022. #ifdef NETCONN
  3023. #ifdef CK_SPEED
  3024.     if (is_tn) {
  3025.     ctlp[(unsigned)255] = ctlp[CR] = 1;
  3026.     if (parity == 'e' || parity == 'm') ctlp[127] = 1;
  3027.     if (flow == FLO_XONX) {        /* Also watch out for Xon/Xoff */
  3028.         ctlp[17] = ctlp[19] = 1;
  3029.         ctlp[17+128] = ctlp[19+128] = 1;
  3030.     }
  3031.     }
  3032. #endif /* CK_SPEED */
  3033. #endif /* NETCONN */
  3034.     if (ttpkt(lx,flow,parity) < 0) {    /* Put line in packet mode, */
  3035.     xxscreen(SCR_EM,0,0L,"Can't condition line");
  3036.     return;
  3037.     }
  3038.     if (local && !network && carrier != CAR_OFF) {
  3039.     int x;                /* Serial connection */
  3040.     x = ttgmdm();            /* with carrier checking */
  3041.     if (x > -1) {
  3042.         if (!(x & BM_DCD)) {
  3043.         debug(F101,"proto ttgmdm","",0);
  3044.         xxscreen(SCR_EM,0,0L,"Carrier required but not detected");
  3045.         return;
  3046.         }
  3047.     }
  3048.     }
  3049.     /* Send remote side's "receive" or "server" startup string, if any */
  3050.     if (local && ckindex((char *)xss,"srgcjhk",0,0,1)) {
  3051.     char *s = NULL;
  3052.         if (
  3053. #ifdef IKS_OPTION
  3054.         /* Don't send auto-blah string if we know other side is serving */
  3055.         !TELOPT_U(TELOPT_KERMIT) ||
  3056.         !TELOPT_SB(TELOPT_KERMIT).kermit.u_start
  3057. #else
  3058.         1
  3059. #endif /* IKS_OPTION */
  3060.         ) {
  3061.         if (sstate == 's') {    /* Sending file(s) */
  3062.         s = binary ? ptab[protocol].h_b_init : ptab[protocol].h_t_init;
  3063.         } else if (protocol == PROTO_K) { /* Command for server */
  3064.         s = ptab[protocol].h_x_init;
  3065.         }
  3066.     }
  3067. #ifdef CK_SPEED
  3068. #ifndef UNPREFIXZERO
  3069.     if (protocol == PROTO_K)    /* Because of C-strings... */
  3070.       ctlp[0] = 1;
  3071. #endif /* UNPREFIXZERO */
  3072. #endif /* CK_SPEED */
  3073.     if (s) if (*s) {        /* If we have a command to send... */
  3074.         char tmpbuf[356];
  3075.         int stuff = -1, stuff2 = -1, len = 0;
  3076.         extern int tnlm;
  3077.         strcpy(tmpbuf,s);
  3078.         if (sstate == 's')        /* Sending file(s) */
  3079.           sprintf(tmpbuf, s, cmarg2[0] ? cmarg2 : cmarg); /* For XMODEM */
  3080.         else            /* Command for server */
  3081.           sprintf(tmpbuf, s);
  3082.         strcat(tmpbuf, "\015");
  3083.         if (tnlm)            /* TERMINAL NEWLINE ON */
  3084.           stuff = LF;        /* Stuff LF */
  3085. #ifdef TNCODE
  3086.         /* TELNET NEWLINE MODE */
  3087.         if (is_tn) {
  3088.         switch (TELOPT_ME(TELOPT_BINARY) ? tn_b_nlm : tn_nlm) {
  3089.           case TNL_CR:
  3090.             break;
  3091.           case TNL_CRNUL:
  3092.             break;
  3093.           case TNL_CRLF:
  3094.             stuff2 = stuff;
  3095.             stuff = LF;
  3096.             break;
  3097.         }
  3098.         }
  3099. #endif /* TNCODE */
  3100.  
  3101. #ifdef NETCONN
  3102. #ifdef TCPSOCKET
  3103. #ifdef RLOGCODE
  3104.         if (network && ttnproto == NP_RLOGIN) {
  3105.         switch (tn_b_nlm) { /* Always BINARY */
  3106.           case TNL_CR:
  3107.             break;
  3108.           case TNL_CRNUL:
  3109.             stuff2 = stuff;
  3110.             stuff  = NUL;
  3111.             break;
  3112.           case TNL_CRLF:
  3113.             stuff2 = stuff;
  3114.             stuff = LF;
  3115.             break;
  3116.         }
  3117.         }
  3118. #endif /* RLOGCODE */
  3119. #endif /* TCPSOCKET */
  3120. #endif /* NETCONN */
  3121.  
  3122.         len = strlen(tmpbuf);
  3123.         if (stuff >= 0) {
  3124.         tmpbuf[len++] = stuff;
  3125.         if (stuff2 >= 0)
  3126.           tmpbuf[len++] = stuff2;
  3127.         tmpbuf[len] = NUL;
  3128.         }
  3129.         ttol((CHAR *)tmpbuf,len);
  3130.         if (protocol == PROTO_K)    /* Give remote Kermit time to start */
  3131.           msleep(400);
  3132.     }
  3133.     }
  3134.  
  3135. #ifdef CK_XYZ
  3136.     if (protocol != PROTO_K) {        /* Non-Kermit protocol selected */
  3137.     char tmpbuf[356];
  3138.     char * s = "";
  3139. #ifdef XYZ_INTERNAL            /* Internal */
  3140.     success = !pxyz(sstate);
  3141. #else
  3142. #ifdef CK_REDIR                /* External */
  3143.     switch (sstate) {
  3144.       case 's':            /* 'Tis better to SEND... */
  3145.         s = binary ? ptab[protocol].p_b_scmd : ptab[protocol].p_t_scmd;
  3146.         break;
  3147.       case 'v':            /* ... than RECEIVE */
  3148.         s = binary ? ptab[protocol].p_b_rcmd : ptab[protocol].p_t_rcmd;
  3149.         break;
  3150.     }
  3151.     if (!s) s = "";
  3152.     if (*s) {
  3153.         sprintf(tmpbuf,s,(sstate == 's') ? fspec : cmarg2);
  3154.         debug(F110,"ckcpro ttruncmd",tmpbuf,0);
  3155.         success = ttruncmd(tmpbuf);
  3156.     } else {
  3157.         printf("?Sorry, no external protocol defined for %s\r\n",
  3158.            ptab[protocol].p_name
  3159.            );
  3160.     }
  3161. #else
  3162.     printf(
  3163. "Sorry, only Kermit protocol is supported in this version of Kermit\n"
  3164.            );
  3165. #endif /* CK_REDIR */
  3166. #endif /* XYZ_INTERNAL */
  3167.     return;
  3168.     }
  3169. #endif /* CK_XYZ */
  3170.  
  3171. #ifdef NTSIGX
  3172.     conraw();
  3173.     connoi();
  3174. #else
  3175.     if (!local)
  3176.       connoi();                /* No console interrupts if remote */
  3177. #endif /* NTSIG */
  3178.  
  3179.     kactive = 1;
  3180.     if (sstate == 'x') {        /* If entering server mode, */
  3181.     server = 1;            /* set flag, */
  3182.     debug(F101,"server backgrd","",backgrd);
  3183.     debug(F101,"server quiet","",quiet);
  3184.     debug(F100,"SHOULD NOT SEE THIS IF IN BACKGROUND!","",0);
  3185.     if (!local) {            /* and issue appropriate message. */
  3186.         if (!quiet && !backgrd
  3187. #ifdef IKS_OPTION
  3188.                 && !TELOPT_ME(TELOPT_KERMIT) /* User was told by negotiation */
  3189. #endif /* IKS_OPTION */
  3190.         ) {
  3191.         conoll(srvtxt);
  3192.         conoll("KERMIT READY TO SERVE...");
  3193.         }
  3194.     } else {
  3195.         conol("Entering server mode on ");
  3196.         conoll(ttname);
  3197.         conoll("Type Ctrl-C to quit.");
  3198.         if (srvdis) intmsg(-1L);
  3199. #ifdef TCPSOCKET
  3200. #ifndef NOLISTEN
  3201.         if (network && tcpsrfd > 0)
  3202.           ttol((CHAR *)"KERMIT READY TO SERVE...\015\012",26);
  3203. #endif /* NOLISTEN */
  3204. #endif /* TCPSOCKET */
  3205.     }
  3206.     } else
  3207.       server = 0;
  3208. #ifdef VMS
  3209.     if (!quiet && !backgrd)    /* So message doesn't overwrite prompt */
  3210.       conoll("");
  3211.     if (local) conres();       /* So Ctrl-C will work */
  3212. #endif /* VMS */
  3213. /*
  3214.   If in remote mode, not shushed, not in background, and at top command level,
  3215.   issue a helpful message telling what to do...
  3216. */
  3217.     if (!local && !quiet && !backgrd) {
  3218.     if (sstate == 'v') {
  3219.         conoll("Return to your local Kermit and give a SEND command.");
  3220.         conoll("");
  3221.         conoll("KERMIT READY TO RECEIVE...");
  3222.     } else if (sstate == 's') {
  3223.         conoll("Return to your local Kermit and give a RECEIVE command.");
  3224.         conoll("");
  3225.         conoll("KERMIT READY TO SEND...");
  3226.     } else if ( sstate == 'g' || sstate == 'r' || sstate == 'h' ||
  3227.             sstate == 'j' || sstate == 'c' ) {
  3228.         conoll("Return to your local Kermit and give a SERVER command.");
  3229.         conoll("");
  3230.         conoll((sstate == 'r' || sstate == 'j' || sstate == 'h') ?
  3231.            "KERMIT READY TO GET..." :
  3232.            "KERMIT READY TO SEND SERVER COMMAND...");
  3233.     }
  3234.     }
  3235. #ifdef COMMENT
  3236.     if (!local) sleep(1);
  3237. #endif /* COMMENT */
  3238. /*
  3239.   The 'wart()' function is generated by the wart program.  It gets a
  3240.   character from the input() routine and then based on that character and
  3241.   the current state, selects the appropriate action, according to the state
  3242.   table above, which is transformed by the wart program into a big case
  3243.   statement.  The function is active for one transaction.
  3244. */
  3245.     rtimer();                /* Reset elapsed-time timer */
  3246. #ifdef GFTIMER
  3247.     rftimer();
  3248. #endif /* GFTIMER */
  3249.     resetc();                /* & other per-transaction counters. */
  3250.  
  3251.     debug(F101,"proto calling wart, justone","",justone);
  3252.  
  3253.     wart();                /* Enter the state table switcher. */
  3254. /*
  3255.   Note: the following is necessary in case we have just done a remote-mode
  3256.   file transfer, in which case the controlling terminal modes have been
  3257.   changed by ttpkt().  In particular, special characters like Ctrl-C and
  3258.   Ctrl-\ might have been turned off (see ttpkt).  So this call to ttres() is
  3259.   essential.  IMPORTANT: restore interrupt handlers first, otherwise any
  3260.   terminal interrupts that occur before this is done in the normal place
  3261.   later will cause a crash.
  3262. */
  3263. #ifdef OS2
  3264.     ttres();                /* Reset the communication device */
  3265. #else
  3266.     if (!local) {
  3267.     setint();            /* Arm interrupt handlers FIRST */
  3268.     msleep(500);
  3269.     ttres();            /* Then restore terminal. */
  3270.     }
  3271. #endif /* OS2 */
  3272.     xxscreen(SCR_TC,0,0L,"");        /* Transaction complete */
  3273.     x = quiet;
  3274.     quiet=1;
  3275.     clsif();                /* Failsafe in case we missed */
  3276.     clsof(1);                /* a case in the state machine. */
  3277.     quiet = x;
  3278.  
  3279.     if (server) {            /* Back from packet protocol. */
  3280.         if (!quiet && !backgrd
  3281. #ifdef IKSD
  3282.         && !inserver
  3283. #endif /* IKSD */
  3284.         ) {                /* Give appropriate message */
  3285.         conoll("");
  3286.         conoll("C-Kermit server done");
  3287.         }
  3288.         server = 0;            /* Not a server any more */
  3289.     }
  3290. }
  3291.  
  3292. /*  S G E T I N I T  --  Handle incoming GET-Class packets  */
  3293.  
  3294. /*
  3295.   Returns:
  3296.    -1: On error
  3297.     0: GET packet processed OK - ready to Send.
  3298.     1: Extended GET processed OK - wait for another.
  3299. */
  3300. static int
  3301. sgetinit(reget,xget) int reget, xget; {    /* Server end of GET command */
  3302.     char * fs = NULL;            /* Pointer to filespec */
  3303.     int i, n, done = 0;
  3304. #ifdef PATTERNS
  3305.     extern int patterns;
  3306. #endif /* PATTERNS */
  3307. #ifdef PIPESEND
  3308.     extern int usepipes, pipesend;
  3309. #endif /* PIPESEND */
  3310.  
  3311.     if (!ENABLED(en_get)) {        /* Only if not disabled!  */
  3312.     errpkt((CHAR *)"GET disabled");
  3313.     return(-1);
  3314.     }
  3315.  
  3316.     /* OK to proceed */
  3317.  
  3318. #ifdef WHATAMI
  3319.     /* If they are alike this was already done in whoarewe() */
  3320.     debug(F101,"sgetinit whatru","",whatru);
  3321.     if (whatru & WMI_FLAG) {        /* Did we get WHATAMI info? */
  3322.     debug(F101,"sgetinit binary (1)","",binary);
  3323. #ifdef VMS
  3324.     if (binary != XYFT_I && binary != XYFT_L)
  3325. #else
  3326. #ifdef OS2
  3327.       if (binary != XYFT_L)
  3328. #endif /* OS2 */
  3329. #endif /* VMS */
  3330.         binary = (whatru & WMI_FMODE) ? /* Yes, set file type */
  3331.           XYFT_B : XYFT_T;    /* automatically */
  3332.     debug(F101,"sgetinit binary (2)","",binary);
  3333.     if (!wearealike)
  3334.       fncnv = (whatru & WMI_FNAME) ? 1 : 0; /* And name conversion */
  3335.     }
  3336. #endif /* WHATAMI */
  3337.  
  3338.     fs = (char *)srvcmd;
  3339.     srvptr = srvcmd;            /* Point to server command buffer */
  3340.     decode(rdatap,putsrv,0);        /* Decode the GET command into it */
  3341.     /* Accept multiple filespecs */
  3342.     cmarg2 = "";            /* Don't use cmarg2 */
  3343.     cmarg = "";                /* Don't use cmarg */
  3344.  
  3345.     done = 1;                /* Only 1 packet needed... */
  3346.     if (xget) {                /* Special decoding for Extended GET */
  3347.     char L, next, c;        /* PLV items */
  3348.     int len, val;            /* More PLV items */
  3349.     char * p = (char *)srvcmd;    /* String to decode */
  3350.  
  3351.     done = 0;            /* Maybe more packets needed */
  3352.     fs = NULL;            /* We don't know the filespec yet */
  3353.     c = *p++;            /* Get first parameter */
  3354.  
  3355.     while (c) {            /* For all parameters... */
  3356.         debug(F000,"sgetinit c","",c);
  3357.         L = *p++;            /* Get length */
  3358.         if (L >= SP)        /* Decode length */
  3359.           len = xunchar(L);
  3360.         else if (c == '@') {    /* Allow missing EOP length field */
  3361.         len = 0;
  3362.         } else {
  3363.         len = (xunchar(*p++) * 95);
  3364.         len += xunchar(*p++);
  3365.         }
  3366.         debug(F101,"sgetinit len","",len);
  3367.         next = *(p+len);        /* Get next parameter */
  3368.         *(p+len) = NUL;        /* Zero it out to terminal value */
  3369.         debug(F110,"sgetinit p",p,0);
  3370.         switch (c) {        /* Do the parameter */
  3371.           case 'O':            /* GET Options */
  3372.         val = atoi(p);        /* Convert to int */
  3373.         debug(F101,"sgetinit O val","",val);
  3374.         if (val & GOPT_DEL) moving = 1;
  3375.         if (val & GOPT_RES) reget = 1;
  3376.         if (val & GOPT_REC) {
  3377.             recursive = 1;
  3378.             if (fnspath == PATH_OFF)
  3379.               fnspath = PATH_REL;
  3380.         }
  3381.         break;
  3382.           case 'M':            /* Transfer Mode */
  3383.         val = atoi(p);
  3384.         debug(F101,"sgetinit M val","",val);
  3385.         if (val < 1)
  3386.           break;
  3387. #ifdef PATTERNS
  3388.         patterns = 0;        /* Takes precedence over patterns */
  3389. #endif /* PATTERNS */
  3390.         if (val == GMOD_TXT) binary = XYFT_T; /* Text */
  3391.         if (val == GMOD_BIN) binary = XYFT_B; /* Binary */
  3392.         if (val == GMOD_LBL) binary = XYFT_L; /* Labeled */
  3393.         break;
  3394.           case 'F':            /* Filename */
  3395.         fs = p;
  3396.         debug(F110,"sgetinit filename",fs,0);
  3397.         break;
  3398.           case '@':            /* End Of Parameters */
  3399.         done = 1;
  3400.         debug(F100,"sgetinit EOP","",0);
  3401.         break;
  3402.           default:
  3403.         errpkt((CHAR *)"Unknown GET Parameter");
  3404.         debug(F100,"sgetinit unknown parameter","",0);
  3405.         return(-1);
  3406.         }
  3407.         p += (len + 1);
  3408.         c = next;
  3409.     }
  3410.     }
  3411.     if (!fs) fs = "";            /* A filename is required */
  3412.     if (*fs) {
  3413.     havefs = 1;
  3414.     n = 0;                /* Check for quoted name */
  3415.     if ((n = strlen(fs)) > 1) {
  3416.         /* Note: this does not allow for multiple quoted names */
  3417.         if ((fs[0] == '{' && fs[n-1] == '}') ||
  3418.         (fs[0] == '"' && fs[n-1] == '"')) {
  3419.         fs[n-1] = '\0';
  3420.         fs++;
  3421.         debug(F111,"sgetinit unquoted filename",fs,n);
  3422.         } else
  3423.           n = 0;            /* This means no quoting */
  3424.     }
  3425.  
  3426. #ifdef PIPESEND
  3427.     debug(F111,"sgetinit",fs,usepipes);
  3428.     if (usepipes && ENABLED(en_hos) && *fs == '!') {
  3429.         cmarg = fs + 1;        /* Point past the bang */
  3430.         *fs = NUL;
  3431.         nfils = -1;
  3432.         pipesend = 1;
  3433.         debug(F111,"sgetinit pipesend",cmarg,pipesend);
  3434.     }
  3435.     if (!pipesend) {        /* If it's not a pipe */
  3436. #endif /* PIPESEND */
  3437.         if (n == 0) {        /* If the name was not quoted */
  3438. #ifndef NOMSEND
  3439.         nfils = fnparse(fs);    /* Allow it to be a list of names */
  3440.         } else {            /* If it was quoted */
  3441. #endif /* NOMSEND */
  3442.         nzxopts = 0;
  3443. #ifdef UNIXOROSK
  3444.         if (matchdot)  nzxopts |= ZX_MATCHDOT;
  3445. #endif /* UNIXOROSK */
  3446.         if (recursive) nzxopts |= ZX_RECURSE;
  3447.         /* Treat as a single filespec */
  3448.         nfils = 0 - nzxpand(fs,nzxopts);
  3449.         cmarg = fs;
  3450.         }
  3451. #ifdef PIPESEND
  3452.     }
  3453. #endif /* PIPESEND */
  3454.     }
  3455.     if (!done) {            /* Need more O packets... */
  3456.     debug(F100,"sgetinit O-Packet TBC","",0); /* To Be Continued */
  3457.     return(1);
  3458.     }
  3459.     debug(F100,"sgetinit O-Packet done - havefs","",havefs);
  3460.     if (!havefs) {            /* Done - make sure we have filename */
  3461.     errpkt((CHAR *)"GET without filename");
  3462.     return(-1);
  3463.     }
  3464.     freerpkt(winlo);
  3465.     winlo = 0;                /* Back to packet 0 again. */
  3466.     debug(F101,"sgetinit winlo","",winlo);
  3467.     nakstate = 0;            /* Now I'm the sender! */
  3468.     if (reget) sendmode = SM_RESEND;
  3469.     if (sinit() > 0) {            /* Send Send-Init */
  3470. #ifdef STREAMING
  3471.     if (!streaming)
  3472. #endif /* STREAMING */
  3473.       timint = chktimo(rtimo,timef); /* Switch to per-packet timer */
  3474.     return(0);            /* If successful, switch state */
  3475.     } else return(-1);            /* Else back to server command wait */
  3476. }
  3477.  
  3478. #else  /* NOXFER */
  3479.  
  3480. #include "ckcdeb.h"
  3481.  
  3482. VOID
  3483. proto() {
  3484.     extern int success;
  3485.     success = 0;
  3486. }
  3487. #endif /* NOXFER */
  3488.