ckcpro.w 105 KB

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