forked from KermitProject/ckermit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ckcpro.c
3886 lines (3761 loc) · 112 KB
/
ckcpro.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* WARNING -- This C source program generated by Wart preprocessor. */
/* Do not edit this file; edit the Wart-format source file instead, */
/* and then run it through Wart to produce a new C source file. */
/* Wart Version Info: */
char *wartv = "Wart Version 2.15, 18 September 2020 ";
char *protv = /* -*-C-*- */
"C-Kermit Protocol Module 10.0.166, 23 Sep 2022";
int kactive = 0; /* Kermit protocol is active */
#define PKTZEROHACK
/* C K C P R O -- C-Kermit Protocol Module, in Wart preprocessor notation. */
/*
Author: Frank da Cruz <fdc@columbia.edu>,
Columbia University Academic Information Systems, New York City.
Copyright (C) 1985, 2022
Trustees of Columbia University in the City of New York.
All rights reserved. See the C-Kermit COPYING.TXT file or the
copyright text in the ckcmai.c module for disclaimer and permissions.
*/
#ifndef NOXFER
#include "ckcsym.h"
#include "ckcdeb.h"
#include "ckcasc.h"
#include "ckcker.h"
#ifdef OS2
#ifndef NT
#define INCL_NOPM
#define INCL_VIO /* Needed for ckocon.h */
#include <os2.h>
#undef COMMENT
#endif /* NT */
#include "ckocon.h"
#endif /* OS2 */
#ifdef CK_AUTHENTICATION
#include "ckuath.h" /* fdc 2021-12-17 */
#endif /* CK_AUTHENTICATION */
/*
Note -- This file may also be preprocessed by the UNIX Lex program, but
you must indent the above #include statements before using Lex, and then
restore them to the left margin in the resulting C program before compilation.
Also, the invocation of the "wart()" function below must be replaced by an
invocation of the "yylex()" function. It might also be necessary to remove
comments in the (%)(%)...(%)(%) section.
*/
/* State definitions for Wart (or Lex) */
#define ipkt 1
#define rfile 2
#define rattr 3
#define rdpkt 4
#define ssinit 5
#define ssfile 6
#define ssattr 7
#define ssdata 8
#define sseof 9
#define sseot 10
#define serve 11
#define generic 12
#define get 13
#define rgen 14
#define ssopkt 15
#define ropkt 16
_PROTOTYP(static VOID xxproto,(void));
_PROTOTYP(static VOID wheremsg,(void));
_PROTOTYP(int wart,(void));
_PROTOTYP(static int sgetinit,(int,int));
_PROTOTYP(int sndspace,(int));
/* External C-Kermit variable declarations */
extern char *versio, *srvtxt, *cmarg, *cmarg2, **cmlist, *rf_err;
extern char * rfspec, * sfspec, * srfspec, * rrfspec;
extern char * prfspec, * psfspec, * psrfspec, * prrfspec;
extern char *cdmsgfile[];
extern char * snd_move, * snd_rename, * srimsg;
extern char filnam[], ofilnam[], fspec[], ttname[], ofn1[];
extern CHAR sstate, *srvptr, *data;
extern int timint, rtimo, nfils, hcflg, xflg, flow, mdmtyp, network;
extern int oopts, omode, oname, opath, nopush, isguest, xcmdsrc, rcdactive;
extern int rejection, moving, fncact, bye_active, urserver, fatalio;
extern int protocol, prefixing, carrier, fnspath, interrupted;
extern long filcnt;
extern int recursive, inserver, nzxopts, idletmo, srvidl, xfrint;
extern struct ck_p ptab[];
extern int remfile, rempipe, xferstat, filestatus, wearealike, fackpath;
extern int patterns, filepeek, gnferror;
extern char * remdest;
#ifdef PKTZEROHACK
#define PKTZEROLEN 32
static char ipktack[PKTZEROLEN];
static int ipktlen = 0;
#endif /* PKTZEROHACK */
static int s_timint = -1; /* For saving timeout value */
static int myjob = 0;
static int havefs = 0;
#ifdef CK_LOGIN
static int logtries = 0;
#endif /* CK_LOGIN */
static int cancel = 0;
int fackbug = 0;
#ifdef STREAMING
extern int streaming, streamok;
static VOID
streamon() {
if (streamok) {
debug(F100,"streamon","",0);
streaming = 1;
timint = 0; /* No timeouts while streaming. */
}
}
#ifdef COMMENT /* (not used) */
static VOID
streamoff() {
if (streaming) {
debug(F100,"streamoff","",0);
streaming = 0;
timint = s_timint; /* Restore timeout */
}
}
#endif /* COMMENT */
#else /* STREAMING */
#define streamon()
#define streamoff()
#endif /* STREAMING */
#ifndef NOSPL
_PROTOTYP( int addmac, (char *, char *) );
_PROTOTYP( int zzstring, (char *, char **, int *) );
#endif /* NOSPL */
#ifndef NOICP
_PROTOTYP( int cmdsrc, (void) );
#endif /* NOICP */
#ifndef NOSERVER
extern char * x_user, * x_passwd, * x_acct;
extern int x_login, x_logged;
#endif /* NOSERVER */
#include "ckcnet.h"
#ifdef TNCODE
extern int ttnproto; /* Network protocol */
#endif /* TNCODE */
#ifdef CK_SPEED
extern short ctlp[]; /* Control-character prefix table */
#endif /* CK_SPEED */
#ifdef TNCODE
extern int tn_b_nlm, tn_b_xfer, tn_nlm;
#ifdef CK_ENCRYPTION
extern int tn_no_encrypt_xfer;
#endif /* CK_ENCRYPTION */
#endif /* TNCODE */
#ifdef TCPSOCKET
#ifndef NOLISTEN
extern int tcpsrfd;
#endif /* NOLISTEN */
#endif /* TCPSOCKET */
extern int cxseen, czseen, server, srvdis, local, displa, bctu, bctr, bctl;
extern int bctf;
extern int quiet, tsecs, parity, backgrd, nakstate, atcapu, wslotn, winlo;
extern int wslots, success, xitsta, rprintf, discard, cdtimo, keep, fdispla;
extern int timef, stdinf, rscapu, sendmode, epktflg, epktrcvd, epktsent;
extern int binary, fncnv, dest;
extern long speed, crc16;
extern CK_OFF_T calibrate, ffc;
#ifdef COMMENT
extern char *TYPCMD, *DIRCMD, *DIRCM2;
#endif /* COMMENT */
#ifndef OS2
extern char *SPACMD, *SPACM2, *WHOCMD;
#endif /* OS2 */
extern CHAR *rdatap;
extern struct zattr iattr;
#ifdef VMS
extern int batch;
#endif /* VMS */
#ifdef GFTIMER
extern CKFLOAT fptsecs;
#endif /* GFTIMER */
extern CHAR *srvcmd;
extern CHAR *epktmsg;
#ifdef CK_TMPDIR
extern int f_tmpdir; /* Directory changed temporarily */
extern char savdir[]; /* For saving current directory */
extern char * dldir;
#endif /* CK_TMPDIR */
extern int query; /* Query-active flag */
#ifndef NOSPL
extern int cmdlvl;
char querybuf[QBUFL+1] = { NUL, NUL }; /* QUERY response buffer */
char *qbufp = querybuf; /* Pointer to it */
int qbufn = 0; /* Length of data in it */
#else
extern int tlevel;
#endif /* NOSPL */
#ifndef NOICP
extern int escape;
#endif /* NOICP */
/*
If the following flag is nonzero when the protocol module is entered,
then server mode persists for exactly one transaction, rather than
looping until BYE or FINISH is received.
*/
extern int justone;
static int r_save = -1;
static int p_save = -1;
/* Function to let remote-mode user know where their file(s) went */
int whereflg = 1; /* Unset with SET XFER REPORT */
static VOID
wheremsg() {
extern int quiet;
extern long filrej;
long n;
n = filcnt - filrej;
debug(F101,"wheremsg n","",n);
debug(F110,"wheremsg prfspec",prfspec,0);
debug(F110,"wheremsg rfspec",rfspec,0);
debug(F110,"wheremsg psfspec",psfspec,0);
debug(F110,"wheremsg sfspec",sfspec,0);
debug(F110,"wheremsg prrfspec",prrfspec,0);
debug(F110,"wheremsg rrfspec",rrfspec,0);
debug(F110,"wheremsg psrfspec",psrfspec,0);
debug(F110,"wheremsg srfspec",srfspec,0);
if (!quiet && !local) {
if (n == 1) {
switch (myjob) {
case 's':
if (sfspec) {
printf(" SENT: [%s]",sfspec);
if (srfspec)
printf(" To: [%s]",srfspec);
printf(" (%s)\r\n", success ? "OK" : "FAILED");
}
break;
case 'r':
case 'v':
if (rrfspec) {
printf(" RCVD: [%s]",rrfspec);
if (rfspec)
printf(" To: [%s]",rfspec);
printf(" (%s)\r\n", success ? "OK" : "FAILED");
}
}
} else if (n > 1) {
switch (myjob) {
case 's':
if (sfspec) {
printf(" SENT: (%ld files)",n);
if (srfspec)
printf(" Last: [%s]",srfspec);
printf(" (%s)\r\n", success ? "OK" : "FAILED");
}
break;
case 'r':
case 'v':
if (rrfspec) {
printf(" RCVD: (%ld files)",n);
if (rfspec)
printf(" Last: [%s]",rfspec);
printf(" (%s)\r\n", success ? "OK" : "FAILED");
}
}
} else if (n == 0) {
if (myjob == 's')
printf(" SENT: (0 files) \r\n");
else if (myjob == 'r' || myjob == 'v')
printf(" RCVD: (0 files) \r\n");
}
}
}
static VOID
rdebug() {
if (server)
debug(F111,"RESUME","server=1",justone);
else
debug(F111,"RESUME","server=0",justone);
}
/* Flags for the ENABLE and DISABLE commands */
extern int
en_cpy, en_cwd, en_del, en_dir, en_fin, en_get, en_bye, en_mai, en_pri,
en_hos, en_ren, en_sen, en_spa, en_set, en_typ, en_who, en_ret, en_xit,
en_mkd, en_rmd;
#ifndef NOSPL
extern int en_asg, en_que;
#endif /* NOSPL */
extern int what, lastxfer;
/* Global variables declared here */
int whatru = 0; /* What are you. */
int whatru2 = 0; /* What are you, cont'd. */
/* Local variables */
static char vstate = 0; /* Saved State */
static char vcmd = 0; /* Saved Command */
static int reget = 0; /* Flag for executing REGET */
static int retrieve = 0; /* Flag for executing RETRIEVE */
static int opkt = 0; /* Send Extended GET packet */
static int x; /* General-purpose integer */
static char *s; /* General-purpose string pointer */
/* Macros - Note, BEGIN is predefined by Wart (and Lex) as "state = ", */
/* BEGIN is NOT a GOTO! */
#define TINIT if (tinit(1) < 0) return(-9)
#define SERVE { TINIT; resetc(); nakstate=1; what=W_NOTHING; cmarg2=""; \
sendmode=SM_SEND; havefs=0; recursive=r_save; fnspath=p_save; BEGIN serve; }
#define RESUME { rdebug(); if (!server) { wheremsg(); return(0); } else \
if (justone) { justone=0; wheremsg(); return(0); } else { SERVE; } }
#ifdef GFTIMER
#define QUIT x=quiet; quiet=1; clsif(); clsof(1); tsecs=gtimer(); \
fptsecs=gftimer(); quiet=x; return(success)
#else
#define QUIT x=quiet; quiet=1; clsif(); clsof(1); tsecs=gtimer(); quiet=x; \
return(success)
#endif /* GFTIMER */
/*
By late 1999, the big switch() statement generated from the following state
table began choking even gcc, so here we extract the code from the larger
states into static routines to reduce the size of the cases and the
switch() overall. The routines follow the state table; the prototypes are
here. Each of these routines simply contains the text from the
corresponding case, but with return(-1) added in appropriate places; see
instructions after the state table switcher.
*/
static int rc; /* Return code for these routines */
static int rcv_s_pkt(); /* Received an S packet */
static int rcv_firstdata(); /* Received first Data packet */
static int rcv_shortreply(); /* Short reply to a REMOTE command */
static int srv_query(); /* Server answers an query */
static int srv_copy(); /* Server executes REMOTE COPY */
static int srv_rename(); /* Server executes REMOTE RENAME */
static int srv_login(); /* Server executes REMOTE LOGIN */
static int srv_timeout(); /* Server times out */
#define BEGIN state =
int state = 0;
int
wart()
{
int c,actno;
extern char tbl[];
while (1) {
c = input() - 32;
debug(F000,"PROTO input",ckitoa(state),c+32);
if (c < 0 || c > 95) c = 0;
if ((actno = tbl[c + state*96]) != -1)
switch(actno) {
case 1:
{ TINIT; /* Send file(s) */
if (sinit() > 0) BEGIN ssinit;
else RESUME; }
break;
case 2:
{ TINIT; nakstate = 1; BEGIN get; }
break;
case 3:
{ /* Client sends a GET command */
TINIT;
vstate = get;
reget = 0;
retrieve = 0;
opkt = 0;
vcmd = 0;
#ifdef PKTZEROHACK
ipktack[0] = NUL;
#endif /* PKTZEROHACK */
if (sipkt('I') >= 0)
BEGIN ipkt;
else
RESUME;
}
break;
case 4:
{ /* Client sends a RETRIEVE command */
TINIT;
vstate = get;
reget = 0;
retrieve = 1;
opkt = 0;
vcmd = 0;
if (sipkt('I') >= 0)
BEGIN ipkt;
else
RESUME;
}
break;
case 5:
{ /* Client sends a REGET command */
TINIT;
vstate = get;
reget = 1;
retrieve = 0;
opkt = 0;
vcmd = 0;
if (sipkt('I') >= 0)
BEGIN ipkt;
else
RESUME;
}
break;
case 6:
{ /* Client sends Extended GET Packet */
TINIT;
vstate = get;
reget = oopts & GOPT_RES;
retrieve = oopts & GOPT_DEL;
opkt = 1;
vcmd = 0;
if (sipkt('I') >= 0)
BEGIN ipkt;
else
RESUME;
}
break;
case 7:
{ /* Client sends a Host command */
TINIT;
vstate = rgen;
vcmd = 'C';
if (sipkt('I') >= 0)
BEGIN ipkt;
else
RESUME;
}
break;
case 8:
{ TINIT; /* Client sends a Kermit command */
vstate = rgen;
vcmd = 'K';
if (sipkt('I') >= 0)
BEGIN ipkt;
else
RESUME;
}
break;
case 9:
{ /* Client sends a REMOTE command */
TINIT;
vstate = rgen;
vcmd = 'G';
if (sipkt('I') >= 0)
BEGIN ipkt;
else
RESUME;
}
break;
case 10:
{ /* Enter server mode */
int x;
x = justone;
if (!ENABLED(en_del)) { /* If DELETE is disabled */
if (fncact == XYFX_B || /* undo any file collision action */
fncact == XYFX_U || /* that could result in deletion or */
fncact == XYFX_A || /* modification of existing files. */
fncact == XYFX_X) {
#ifndef NOICP
extern int g_fncact;
g_fncact = fncact; /* Save current setting */
#endif /* NOICP */
fncact = XYFX_R; /* Change to RENAME */
debug(F101,"server DELETE disabled so fncact RENAME","",fncact);
}
}
SERVE; /* tinit() clears justone... */
justone = x;
#ifdef IKSDB
if (ikdbopen) slotstate(what, "SERVER", "", "");
#endif /* IKSDB */
}
break;
case 11:
{
int b1 = 0, b2 = 0;
if (!data) TINIT; /* "ABEND" -- Tell other side. */
if (!bctf) { /* Block check 3 forced on all packets */
#ifndef pdp11
if (epktflg) { /* If because of E-PACKET command */
b1 = bctl; b2 = bctu; /* Save block check type */
bctl = bctu = 1; /* set it to 1 */
}
#endif /* pdp11 */
}
errpkt((CHAR *)"User cancelled"); /* Send the packet */
if (!bctf) { /* Block check 3 forced on all packets */
#ifndef pdp11
if (epktflg) { /* Restore the block check */
epktflg = 0;
bctl = b1; bctu = b2;
}
}
#endif /* pdp11 */
success = 0;
return(0); /* Return from protocol. */
}
break;
case 12:
{ /* Receive Send-Init packet. */
rc = rcv_s_pkt();
cancel = 0; /* Reset cancellation counter */
debug(F101,"rcv_s_pkt","",rc);
if (rc > -1) return(rc); /* (see below) */
}
break;
case 13:
{ /* Get ack for I-packet */
int x = 0;
#ifdef PKTZEROHACK
ckstrncpy(ipktack,(char *)rdatap,PKTZEROLEN); /* Save a copy of the ACK */
ipktlen = strlen(ipktack);
#endif /* PKTZEROHACK */
spar(rdatap); /* Set parameters */
cancel = 0;
winlo = 0; /* Set window-low back to zero */
debug(F101,"<ipkt>Y winlo","",winlo);
urserver = 1; /* So I know I'm talking to a server */
if (vcmd) { /* If sending a generic command */
if (tinit(0) < 0) return(-9); /* Initialize many things */
x = scmd(vcmd,(CHAR *)cmarg); /* Do that */
if (x >= 0) x = 0; /* (because of O-Packet) */
debug(F101,"proto G packet scmd","",x);
vcmd = 0; /* and then un-remember it. */
} else if (vstate == get) {
debug(F101,"REGET sstate","",sstate);
x = srinit(reget, retrieve, opkt); /* GET or REGET, etc */
}
if (x < 0) { /* If command was too long */
if (!srimsg)
srimsg = "Error sending string";
errpkt((CHAR *)srimsg); /* cancel both sides. */
success = 0;
RESUME;
} else if (x > 0) { /* Need to send more O-Packets */
BEGIN ssopkt;
} else {
rtimer(); /* Reset the elapsed seconds timer. */
#ifdef GFTIMER
rftimer();
#endif /* GFTIMER */
winlo = 0; /* Window back to 0, again. */
debug(F101,"<ipkt>Y vstate","",vstate);
nakstate = 1; /* Can send NAKs from here. */
BEGIN vstate; /* Switch to desired state */
}
}
break;
case 14:
{ /* Got ACK to O-Packet */
debug(F100,"CPCPRO <ssopkt>Y","",0);
x = sopkt();
debug(F101,"CPCPRO <ssopkt>Y x","",x);
if (x < 0) { /* If error */
errpkt((CHAR *)srimsg); /* cancel both sides. */
success = 0;
RESUME;
} else if (x == 0) { /* This was the last O-Packet */
rtimer(); /* Reset the elapsed seconds timer. */
#ifdef GFTIMER
rftimer();
#endif /* GFTIMER */
winlo = 0; /* Window back to 0, again. */
debug(F101,"<ssopkt>Y winlo","",winlo);
nakstate = 1; /* Can send NAKs from here. */
BEGIN vstate; /* Switch to desired state */
}
debug(F101,"CPCPRO <ssopkt>Y not changing state","",x);
}
break;
case 15:
{ /* Ignore Error reply to I packet */
int x = 0;
winlo = 0; /* Set window-low back to zero */
debug(F101,"<ipkt>E winlo","",winlo);
if (vcmd) { /* In case other Kermit doesn't */
if (tinit(0) < 0) return(-9);
x = scmd(vcmd,(CHAR *)cmarg); /* understand I-packets. */
if (x >= 0) x = 0; /* (because of O-Packet) */
vcmd = 0; /* Otherwise act as above... */
} else if (vstate == get) x = srinit(reget, retrieve, opkt);
if (x < 0) { /* If command was too long */
errpkt((CHAR *)srimsg); /* cancel both sides. */
success = 0;
RESUME;
} else if (x > 0) { /* Need to send more O-Packets */
BEGIN ssopkt;
} else {
freerpkt(winlo); /* Discard the Error packet. */
debug(F101,"<ipkt>E winlo","",winlo);
winlo = 0; /* Back to packet 0 again. */
nakstate = 1; /* Can send NAKs from here. */
BEGIN vstate;
}
}
break;
case 16:
{ /* Resend of previous I-pkt ACK, same seq number */
freerpkt(0); /* Free the ACK's receive buffer */
resend(0); /* Send the GET packet again. */
}
break;
case 17:
{ /* Get I-packet */
#ifndef NOSERVER
spar(rdatap); /* Set parameters from it */
ack1(rpar()); /* Respond with our own parameters */
#ifdef COMMENT
pktinit(); /* Reinitialize packet numbers */
#else
#ifdef COMMENT
/* This can't be right - it undoes the stuff we just negotiated */
x = justone;
tinit(1); /* Reinitialize EVERYTHING */
justone = x; /* But this... */
#else
tinit(0); /* Initialize most things */
#endif /* COMMENT */
#endif /* COMMENT */
#endif /* NOSERVER */
cancel = 0; /* Reset cancellation counter */
}
break;
case 18:
{ /* GET */
#ifndef NOSERVER
if (x_login && !x_logged) {
errpkt((CHAR *)"Login required");
SERVE;
} else if (sgetinit(0,0) < 0) {
RESUME;
} else {
#ifdef CKSYSLOG
if (ckxsyslog >= SYSLG_PR && ckxlogging)
cksyslog(SYSLG_PR, 1, "server", "GET", (char *)srvcmd);
#endif /* CKSYSLOG */
BEGIN ssinit;
}
#endif /* NOSERVER */
}
break;
case 19:
{ /* GET /DELETE (RETRIEVE) */
#ifndef NOSERVER
if (x_login && !x_logged) {
errpkt((CHAR *)"Login required");
RESUME;
} else if (!ENABLED(en_del)) {
errpkt((CHAR *)"Deleting files is disabled");
RESUME;
} else if (sgetinit(0,0) < 0) {
RESUME;
} else {
moving = 1;
#ifdef CKSYSLOG
if (ckxsyslog >= SYSLG_PR && ckxlogging)
cksyslog(SYSLG_PR, 1, "server", "GET /DELETE", (char *)srvcmd);
#endif /* CKSYSLOG */
BEGIN ssinit;
}
#endif /* NOSERVER */
}
break;
case 20:
{ /* GET /RECURSIVE */
#ifndef NOSERVER
recursive = 1; /* Set these before sgetinit() */
if (fnspath == PATH_OFF)
fnspath = PATH_REL; /* Don't worry, they will be */
if (x_login && !x_logged) { /* reset next time through. */
errpkt((CHAR *)"Login required");
RESUME;
} else if (sgetinit(0,0) < 0) {
RESUME;
} else {
#ifdef CKSYSLOG
if (ckxsyslog >= SYSLG_PR && ckxlogging)
cksyslog(SYSLG_PR, 1, "server", "GET /RECURSIVE", (char *)srvcmd);
#endif /* CKSYSLOG */
BEGIN ssinit;
}
#endif /* NOSERVER */
}
break;
case 21:
{ /* GET /RECURSIVE /DELETE */
#ifndef NOSERVER
recursive = 1; /* Set these before sgetinit() */
if (fnspath == PATH_OFF)
fnspath = PATH_REL; /* Don't worry, they will be */
moving = 1; /* reset next time through. */
if (x_login && !x_logged) {
errpkt((CHAR *)"Login required");
RESUME;
} else if (!ENABLED(en_del)) {
errpkt((CHAR *)"Deleting files is disabled");
RESUME;
} else if (sgetinit(0,0) < 0) {
RESUME;
} else {
#ifdef CKSYSLOG
if (ckxsyslog >= SYSLG_PR && ckxlogging)
cksyslog(SYSLG_PR,1,"server",
"GET /RECURSIVE /DELETE",(char *)srvcmd);
#endif /* CKSYSLOG */
BEGIN ssinit;
}
#endif /* NOSERVER */
}
break;
case 22:
{ /* GET /RECOVER (REGET) */
#ifndef NOSERVER
if (x_login && !x_logged) {
errpkt((CHAR *)"Login required");
SERVE;
} else if (sgetinit(1,0) < 0) {
RESUME;
} else {
#ifdef CKSYSLOG
if (ckxsyslog >= SYSLG_PR && ckxlogging)
cksyslog(SYSLG_PR, 1, "server", "GET /RECOVER", (char *)srvcmd);
#endif /* CKSYSLOG */
BEGIN ssinit;
}
#endif /* NOSERVER */
}
break;
case 23:
{ /* Extended GET */
#ifndef NOSERVER
if (x_login && !x_logged) { /* (any combination of options) */
errpkt((CHAR *)"Login required");
SERVE;
} else if ((x = sgetinit(0,1)) < 0) {
debug(F101,"CKCPRO <serve>O sgetinit fail","",x);
RESUME;
} else if (x == 0) {
debug(F101,"CKCPRO <serve>O sgetinit done","",x);
#ifdef CKSYSLOG
if (ckxsyslog >= SYSLG_PR && ckxlogging)
cksyslog(SYSLG_PR, 1, "server", "EXTENDED GET", (char *)srvcmd);
#endif /* CKSYSLOG */
BEGIN ssinit;
} else { /* Otherwise stay in this state */
debug(F101,"CKCPRO <serve>O sgetinit TBC","",x);
ack();
BEGIN ropkt;
}
#endif /* NOSERVER */
}
break;
case 24:
{
#ifndef NOSERVER
if (x_login && !x_logged) { /* (any combination of options) */
errpkt((CHAR *)"Login required");
SERVE;
} else if ((x = sgetinit(0,1)) < 0) {
debug(F101,"CKCPRO <ropkt>O sgetinit fail","",x);
RESUME;
} else if (x == 0) {
debug(F101,"CKCPRO <ropkt>O sgetinit done","",x);
#ifdef CKSYSLOG
if (ckxsyslog >= SYSLG_PR && ckxlogging)
cksyslog(SYSLG_PR, 1, "server", "EXTENDED GET", (char *)srvcmd);
#endif /* CKSYSLOG */
BEGIN ssinit;
} else { /* Otherwise stay in this state */
debug(F101,"CKCPRO <ropkt>O sgetinit TBC","",x);
ack();
}
#endif /* NOSERVER */
}
break;
case 25:
{ /* Generic server command */
#ifndef NOSERVER
srvptr = srvcmd; /* Point to command buffer */
decode(rdatap,putsrv,0); /* Decode packet data into it */
putsrv(NUL); /* Insert a couple nulls */
putsrv(NUL); /* for termination */
if (srvcmd[0]) {
sstate = srvcmd[0]; /* Set requested start state */
if (x_login && !x_logged && /* Login required? */
/* Login, Logout, and Help are allowed when not logged in */
sstate != 'I' && sstate != 'L' && sstate != 'H') {
errpkt((CHAR *)"Login required");
SERVE;
} else {
nakstate = 0; /* Now I'm the sender. */
what = W_REMO; /* Doing a REMOTE command. */
#ifdef STREAMING
if (!streaming)
#endif /* STREAMING */
if (timint < 1)
timint = chktimo(rtimo,timef); /* Switch to per-packet timer */
binary = XYFT_T; /* Switch to text mode */
BEGIN generic; /* Switch to generic command state */
}
} else {
errpkt((CHAR *)"Badly formed server command"); /* report error */
RESUME; /* & go back to server command wait */
}
#endif /* NOSERVER */
}
break;
case 26:
{ /* Receive Host command */
#ifndef NOSERVER
if (x_login && !x_logged) {
errpkt((CHAR *)"Login required");
SERVE;
} else if (!ENABLED(en_hos)) {
errpkt((CHAR *)"REMOTE HOST disabled");
RESUME;
} else if (nopush) {
errpkt((CHAR *)"HOST commands not available");
RESUME;
} else {
srvptr = srvcmd; /* Point to command buffer */
decode(rdatap,putsrv,0); /* Decode command packet into it */
putsrv(NUL); /* Null-terminate */
nakstate = 0; /* Now sending, not receiving */
binary = XYFT_T; /* Switch to text mode */
if (syscmd((char *)srvcmd,"")) { /* Try to execute the command */
what = W_REMO; /* Doing a REMOTE command. */
#ifdef STREAMING
if (!streaming)
#endif /* STREAMING */
if (timint < 1)
timint = chktimo(rtimo,timef); /* Switch to per-packet timer */
#ifdef CKSYSLOG
if (ckxsyslog >= SYSLG_PR && ckxlogging)
cksyslog(SYSLG_PR, 1, "server", "REMOTE HOST", (char *)srvcmd);
#endif /* CKSYSLOG */
BEGIN ssinit; /* If OK, send back its output */
} else { /* Otherwise */
errpkt((CHAR *)"Can't do system command"); /* report error */
RESUME; /* & go back to server command wait */
}
}
#endif /* NOSERVER */
}
break;
case 27:
{ /* Interrupted or connection lost */
rc = srv_timeout();
debug(F101,"srv_timeout","",rc);
if (rc > -1) return(rc); /* (see below) */
}
break;
case 28:
{ /* Server got a NAK in command-wait */
#ifndef NOSERVER
errpkt((CHAR *)"Did you say RECEIVE instead of GET?");
RESUME;
#endif /* NOSERVER */
}
break;
case 29:
{ /* Any other command in this state */
#ifndef NOSERVER
if (c != ('E' - SP) && c != ('Y' - SP)) /* except E and Y packets. */
errpkt((CHAR *)"Unimplemented server function");
/* If we answer an E with an E, we get an infinite loop. */
/* A Y (ACK) can show up here if we sent back a short-form reply to */
/* a G packet and it was echoed. ACKs can be safely ignored here. */
RESUME; /* Go back to server command wait. */
#endif /* NOSERVER */
}
break;
case 30:
{ /* Login/Out */
rc = srv_login();
debug(F101,"<generic>I srv_login","",rc);
if (rc > -1) return(rc); /* (see below) */
}
break;
case 31:
{ /* Got REMOTE CD command */
#ifndef NOSERVER
#ifdef CKSYSLOG
if (ckxsyslog >= SYSLG_PR && ckxlogging)
cksyslog(SYSLG_PR, 1, "server", "REMOTE CD", (char *)srvcmd);
#endif /* CKSYSLOG */
if (!ENABLED(en_cwd)) {
errpkt((CHAR *)"REMOTE CD disabled");
RESUME;
} else {
char * p = NULL;
x = cwd((char *)(srvcmd+1)); /* Try to change directory */
#ifdef IKSDB
if (ikdbopen) slotstate(what,"REMOTE CD", (char *)(srvcmd+2), "");
#endif /* IKSDB */
if (!x) { /* Failed */
errpkt((CHAR *)"Can't change directory");
RESUME; /* Back to server command wait */
} else if (x == 2) { /* User wants message */
if (!ENABLED(en_typ)) { /* Messages (REMOTE TYPE) disabled? */
errpkt((CHAR *)"REMOTE TYPE disabled");
RESUME;
} else { /* TYPE is enabled */
int i;
for (i = 0; i < 8; i++) {
if (zchki(cdmsgfile[i]) > -1) {
break;
}
}
binary = XYFT_T; /* Use text mode for this. */
if (i < 8 && sndtype(cdmsgfile[i])) { /* Have readme file? */
BEGIN ssinit; /* OK */
} else { /* not OK */
p = zgtdir();
if (!p) p = "";
success = (*p) ? 1 : 0;
ack1((CHAR *)p); /* ACK with new directory name */
success = 1;
RESUME; /* wait for next server command */
}
}
} else { /* User doesn't want message */
p = zgtdir();
if (!p) p = "";
success = (*p) ? 1 : 0;
ack1((CHAR *)p);
success = 1;
RESUME; /* Wait for next server command */
}
}
#endif /* NOSERVER */
}
break;
case 32:
{ /* Got REMOTE PWD command */
#ifndef NOSERVER
#ifdef CKSYSLOG
if (ckxsyslog >= SYSLG_PR && ckxlogging)
cksyslog(SYSLG_PR, 1, "server", "REMOTE PWD", NULL);
#endif /* CKSYSLOG */
if (!ENABLED(en_cwd)) {
errpkt((CHAR *)"REMOTE CD disabled");
RESUME;
} else {
if (encstr((CHAR *)zgtdir()) > -1) { /* Encode current directory */
ack1(data); /* If it fits, send it back in ACK */
success = 1;
} else { /* Failed */
ack(); /* Send empty ACK */
success = 0; /* and indicate failure locally */
}
RESUME; /* Back to server command wait */
}
#endif /* NOSERVER */
}
break;
case 33:
{ /* REMOTE DIRECTORY command */
#ifndef NOSERVER
char *n2;
#ifdef CKSYSLOG
if (ckxsyslog >= SYSLG_PR && ckxlogging)