-
Notifications
You must be signed in to change notification settings - Fork 0
/
ckcftp.c
17681 lines (16456 loc) · 555 KB
/
ckcftp.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
#define FTP_TIMEOUT
/* C K C F T P -- FTP Client for C-Kermit */
char *ckftpv = "FTP Client, 9.0.264, 24 Dec 2015";
/*
Authors:
Jeffrey E Altman <jaltman@secure-endpoints.com>
Secure Endpoints Inc., New York City
Frank da Cruz <fdc@columbia.edu>,
The Kermit Project, Columbia University.
Copyright (C) 2000, 2015,
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.
Portions of conditionally included code Copyright Regents of the
University of California and The Stanford SRP Authentication Project;
see notices below.
*/
/*
Pending...
. Implement recursive NLST downloads by trying to CD to each filename.
If it works, it's a directory; if not, it's a file -- GET it. But
that won't work with servers like wu-ftpd that don't send directory
names. Recursion with MLSD is done.
. Make syslog entries for session? Files?
. Messages are printed to stdout and stderr in random fashion. We should
either print everything to stdout, or else be systematic about when
to use stderr.
. Implement mail (MAIL, MLFL, MSOM, etc) if any servers support it.
. Adapt to VMS. Big job because of its record-oriented file system.
RMS programmer required. There are probably also some VMS TCP/IP
product-specific wrinkles, e.g. attribute preservation in VMS-to-VMS
transfers using special options for Multinet or other FTP servers
(find out about STRU VMS).
*/
/*
Quick FTP command reference:
RFC765 (1980) and earlier:
MODE S(tream), B(lock), C(ompressed)
STRU F(ILE), R(ECORD), P(AGE)
TYPE A(SCII) <format>, E(BCDIC) <format>, I(MAGE), L(OCAL) <bytesize>
PORT - Port
PASV - Passive mode
USER - User
PASS - Password
ACCT - Account
CWD - Change Working Directory
REIN - Logout but not disconnect
QUIT - Bye
RETR - Retreive
STOR - Store
APPE - Append
ALLO - Allocate
REST - Restart
RNFR - Rename from
RNTO - Rename to
ABOR - Cancel
DELE - Delete
LIST - Directory
NLST - Name List
SITE - Site parameters or commands
STAT - Status
HELP - Help
NOOP - Noop
RFC959 (1985):
CDUP - Change to Parent Directory
SMNT - Structure Mount
STOU - Store Unique
RMD - Remove Directory
MKD - Make Directory
PWD - Print Directory
SYST - System
RFC2389 (1998):
FEAT - List Features (done)
OPTS - Send options (done)
RFC2640 (1999):
LANG - Specify language for messages (not done)
Pending (Internet Drafts):
SIZE - File size (done)
MDTM - File modification date-time (done)
MLST - File name and attribute list (single file) (not done)
MLSD - File list with attributes (multiple files) (done)
MAIL, MLFL, MSOM - mail delivery (not done)
Alphabetical syntax list:
ABOR <CRLF>
ACCT <SP> <account-information> <CRLF>
ALLO <SP> <decimal-integer> [<SP> R <SP> <decimal-integer>] <CRLF>
APPE <SP> <pathname> <CRLF>
CDUP <CRLF>
CWD <SP> <pathname> <CRLF>
DELE <SP> <pathname> <CRLF>
FEAT <CRLF>
HELP [<SP> <string>] <CRLF>
LANG [<SP> <language-tag> ] <CRLF>
LIST [<SP> <pathname>] <CRLF>
MKD <SP> <pathname> <CRLF>
MLSD [<SP> <pathname>] <CRLF>
MLST [<SP> <pathname>] <CRLF>
MODE <SP> <mode-code> <CRLF>
NLST [<SP> <pathname-or-wildcard>] <CRLF>
NOOP <CRLF>
OPTS <SP> <commandname> [ <SP> <command-options> ] <CRLF>
PASS <SP> <password> <CRLF>
PASV <CRLF>
PORT <SP> <host-port> <CRLF>
PWD <CRLF>
QUIT <CRLF>
REIN <CRLF>
REST <SP> <marker> <CRLF>
RETR <SP> <pathname> <CRLF>
RMD <SP> <pathname> <CRLF>
RNFR <SP> <pathname> <CRLF>
RNTO <SP> <pathname> <CRLF>
SITE <SP> <string> <CRLF>
SIZE <SP> <pathname> <CRLF>
SMNT <SP> <pathname> <CRLF>
STAT [<SP> <pathname>] <CRLF>
STOR <SP> <pathname> <CRLF>
STOU <CRLF>
STRU <SP> <structure-code> <CRLF>
SYST <CRLF>
TYPE <SP> <type-code> <CRLF>
USER <SP> <username> <CRLF>
*/
#include "ckcsym.h" /* Standard includes */
#include "ckcdeb.h"
#ifndef NOFTP /* NOFTP = no FTP */
#ifndef SYSFTP /* SYSFTP = use external ftp client */
#ifdef TCPSOCKET /* Build only if TCP/IP included */
#define CKCFTP_C
/* Note: much of the following duplicates what was done in ckcdeb.h */
/* but let's not mess with it unless it causes trouble. */
#ifdef CK_ANSIC
#include <stdarg.h>
#else /* CK_ANSIC */
#include <varargs.h>
#endif /* CK_ANSIC */
#include <signal.h>
#ifdef OS2
#ifdef OS2ONLY
#include <os2.h>
#endif /* OS2ONLY */
#include "ckowin.h"
#include "ckocon.h"
#endif /* OS2 */
#ifndef ZILOG
#ifdef NT
#include <setjmpex.h>
#ifdef NTSIG
extern int TlsIndex;
#endif /* NTSIG */
#else /* NT */
#include <setjmp.h>
#endif /* NT */
#else
#include <setret.h>
#endif /* ZILOG */
#include "ckcsig.h"
#ifdef VMS
/* 2010-03-09 SMS. VAX C needs help to find "sys". It's easier not to try. */
#include <stat.h>
#else /* def VMS */
#include <sys/stat.h>
#endif /* def VMS [else] */
#include <ctype.h>
#ifndef HPUXPRE65
#include <errno.h> /* Error number symbols */
#else
#ifndef ERRNO_INCLUDED
#include <errno.h> /* Error number symbols */
#endif /* ERRNO_INCLUDED */
#endif /* HPUXPRE65 */
#ifndef NOTIMEH
#include <time.h>
#endif /* NOTIMEH */
#ifndef EPIPE
#define EPIPE 32 /* Broken pipe error */
#endif /* EPIPE */
/* Kermit includes */
#include "ckcasc.h"
#include "ckcker.h"
#include "ckucmd.h"
#include "ckuusr.h"
#include "ckcnet.h" /* Includes ckctel.h */
#include "ckctel.h" /* (then why include it again?) */
#include "ckcxla.h"
#ifdef CK_SSL
#include "ckuath.h" /* SMS 2007/02/15 */
#endif /* def CK_SSL */
/*
How to get the struct timeval definition so we can call select(). The
xxTIMEH symbols are defined in ckcdeb.h, overridden in various makefile
targets. The problem is: maybe we have already included some header file
that defined struct timeval, and maybe we didn't. If we did, we don't want
to include another header file that defines it again or the compilation will
fail. If we didn't, we have to include the header file where it's defined.
But in some cases even that won't work because of strict POSIX constraints
or somesuch, or because this introduces other conflicts (e.g. struct tm
multiply defined), in which case we have to define it ourselves, but this
can work only if we didn't already encounter a definition.
*/
#ifndef DCLTIMEVAL
#ifdef SV68R3V6
#define DCLTIMEVAL
#else
#ifdef SCO234
#define DCLTIMEVAL
#endif /* SCO234 */
#endif /* SV68R3V6 */
#endif /* DCLTIMEVAL */
#ifdef DCLTIMEVAL
/* Also maybe in some places the elements must be unsigned... */
struct timeval {
long tv_sec;
long tv_usec;
};
#ifdef COMMENT
/* Currently we don't use this... */
struct timezone {
int tz_minuteswest;
int tz_dsttime;
};
#endif /* COMMENT */
#else /* !DCLTIMEVAL */
#ifndef NOSYSTIMEH
#ifdef SYSTIMEH
#include <sys/time.h>
#endif /* SYSTIMEH */
#endif /* NOSYSTIMEH */
#ifndef NOSYSTIMEBH
#ifdef SYSTIMEBH
#include <sys/timeb.h>
#endif /* SYSTIMEBH */
#endif /* NOSYSTIMEBH */
#endif /* DCLTIMEVAL */
/* 2010-03-09 SMS. VAX C needs help to find "sys". It's easier not to try. */
#ifdef VMS
#include <types.h>
#else /* def VMS */
#include <sys/types.h>
#endif /* def VMS [else] */
#include <stdio.h>
#include <string.h>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif /* HAVE_STDLIB_H */
#ifndef NOSETTIME
#ifdef COMMENT
/* This section moved to ckcdeb.h */
#ifdef POSIX
#define UTIMEH
#else
#ifdef HPUX9
#define UTIMEH
#else
#ifdef OS2
#define SYSUTIMEH
#endif /* OS2 */
#endif /* HPUX9 */
#endif /* POSIX */
#endif /* COMMENT */
#ifdef VMS /* SMS 2007/02/15 */
#include "ckvrtl.h" /* for utime() */
#else /* def VMS */
#ifdef SYSUTIMEH
#include <sys/utime.h>
#else
#ifdef UTIMEH
#include <utime.h>
#define SYSUTIMEH
#endif /* UTIMEH */
#endif /* SYSUTIMEH */
#endif /* def VMS */
#endif /* NOSETTIME */
#ifndef SCO_OSR504
#ifdef SELECT_H
#include <sys/select.h>
#endif /* SELECT_H */
#endif /* SCO_OSR504 */
#ifndef INADDR_NONE /* 2010-03-29 */
#define INADDR_NONE -1
#endif /* INADDR_NONE */
/* select() dialects... */
#ifdef UNIX
#define BSDSELECT /* BSD select() syntax/semantics */
#ifndef FD_SETSIZE
#define FD_SETSIZE 128
#endif /* FD_SETSIZE */
#ifdef HPUX6 /* For HP-UX 6.5 circa 1989 */
typedef long fd_mask;
#define NFDBITS (sizeof(fd_mask) * NBBY) /* bits per mask */
#ifndef howmany
#define howmany(x, y) (((x)+((y)-1))/(y))
#endif /* howmany */
#define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
#define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
#define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
#define FD_COPY(f, t) bcopy(f, t, sizeof(*(f)))
#define FD_ZERO(p) bzero(p, sizeof(*(p)))
#endif /* HPUX6 */
#else
#ifdef OS2 /* OS/2 or Win32 */
#ifdef NT
#define BSDSELECT
#else /* NT */
#define IBMSELECT
#endif /* NT */
#endif /* OS2 */
#endif /* UNIX */
#ifdef VMS
#define BSDSELECT /* SMS 2007/02/15 */
#endif /* def VMS */
/* Other select() peculiarities */
#ifdef HPUX
#ifndef HPUX10 /* HP-UX 9.xx and earlier */
#ifndef HPUX1100
/* The three interior args to select() are (int *) rather than (fd_set *) */
#ifndef INTSELECT
#define INTSELECT
#endif /* INTSELECT */
#endif /* HPUX1100 */
#endif /* HPUX10 */
#endif /* HPUX */
#ifdef CK_SOCKS /* SOCKS Internet relay package */
#ifdef CK_SOCKS5 /* SOCKS 5 */
#define accept SOCKSaccept
#define bind SOCKSbind
#define connect SOCKSconnect
#define getsockname SOCKSgetsockname
#define listen SOCKSlisten
#else /* Not SOCKS 5 */
#define accept Raccept
#define bind Rbind
#define connect Rconnect
#define getsockname Rgetsockname
#define listen Rlisten
#endif /* CK_SOCKS5 */
#endif /* CK_SOCKS */
#ifndef NOHTTP
extern char * tcp_http_proxy; /* Name[:port] of http proxy server */
extern int tcp_http_proxy_errno;
extern char * tcp_http_proxy_user;
extern char * tcp_http_proxy_pwd;
extern char * tcp_http_proxy_agent;
#define HTTPCPYL 1024
static char proxyhost[HTTPCPYL];
#endif /* NOHTTP */
int ssl_ftp_proxy = 0; /* FTP over SSL/TLS Proxy Server */
/* Feature selection */
#ifndef USE_SHUTDOWN
/*
We don't use shutdown() because (a) we always call it just before close()
so it's redundant and unnecessary, and (b) it introduces a long pause on
some platforms like SV/68 R3.
*/
/* #define USE_SHUTDOWN */
#endif /* USE_SHUTDOWN */
#ifndef NORESEND
#ifndef NORESTART /* Restart / recover */
#ifndef FTP_RESTART
#define FTP_RESTART
#endif /* FTP_RESTART */
#endif /* NORESTART */
#endif /* NORESEND */
#ifndef NOUPDATE /* Update mode */
#ifndef DOUPDATE
#define DOUPDATE
#endif /* DOUPDATE */
#endif /* NOUPDATE */
#ifndef UNICODE /* Unicode required */
#ifndef NOCSETS /* for charset translation */
#define NOCSETS
#endif /* NOCSETS */
#endif /* UNICODE */
#ifndef OS2
#ifndef HAVE_MSECS /* Millisecond timer */
#ifdef UNIX
#ifdef GFTIMER
#define HAVE_MSECS
#endif /* GFTIMER */
#endif /* UNIX */
#endif /* HAVE_MSECS */
#endif /* OS2 */
#ifdef PIPESEND /* PUT from pipe */
#ifndef PUTPIPE
#define PUTPIPE
#endif /* PUTPIPE */
#endif /* PIPESEND */
#ifndef NOSPL /* PUT from array */
#ifndef PUTARRAY
#define PUTARRAY
#endif /* PUTARRAY */
#endif /* NOSPL */
/* Security... */
#ifdef CK_SRP
#define FTP_SRP
#endif /* CK_SRP */
#ifdef CK_KERBEROS
#ifdef KRB4
/*
There is a conflict between the Key Schedule formats used internally
within the standalone MIT KRB4 library and that used by Eric Young
in OpenSSL and his standalone DES library. Therefore, KRB4 FTP AUTH
cannot be supported when either of those two packages are used.
*/
#ifdef KRB524
#define FTP_KRB4
#else /* KRB524 */
#ifndef CK_SSL
#ifndef LIBDES
#define FTP_KRB4
#endif /* LIBDES */
#endif /* CK_SSL */
#endif /* KRB524 */
#endif /* KRB4 */
#ifdef KRB5
#ifndef HEIMDAL
#ifndef NOFTP_GSSAPI /* 299 */
#define FTP_GSSAPI
#endif /* NOFTP_GSSAPI */
#endif /* HEIMDAL */
#endif /* KRB5 */
#endif /* CK_KERBEROS */
/* FTP_SECURITY is defined if any of the above is selected */
#ifndef FTP_SECURITY
#ifdef FTP_GSSAPI
#define FTP_SECURITY
#else
#ifdef FTP_KRB4
#define FTP_SECURITY
#else
#ifdef FTP_SRP
#define FTP_SECURITY
#else
#ifdef CK_SSL
#define FTP_SECURITY
#endif /* CK_SSL */
#endif /* FTP_SRP */
#endif /* FTP_KRB4 */
#endif /* FTP_GSSAPI */
#endif /* FTP_SECURITY */
#ifdef CK_DES
#ifdef CK_SSL
#ifndef LIBDES
#define LIBDES
#endif /* LIBDES */
#endif /* CK_SSL */
#endif /* CK_DES */
#ifdef CRYPT_DLL
#ifndef LIBDES
#define LIBDES
#endif /* LIBDES */
#endif /* CRYPT_DLL */
#ifdef FTP_KRB4
#define des_cblock Block
#define des_key_schedule Schedule
#ifdef KRB524
#ifdef NT
#define _WINDOWS
#endif /* NT */
#include "kerberosIV/krb.h"
#else /* KRB524 */
#ifdef SOLARIS
#ifndef sun
/* For some reason lost in history the Makefile Solaris targets have -Usun */
#define sun
#endif /* sun */
#endif /* SOLARIS */
#include "krb.h"
#define krb_get_err_text_entry krb_get_err_text
#endif /* KRB524 */
#endif /* FTP_KRB4 */
#ifdef CK_SSL
#ifdef FTP_KRB4
#ifndef HEADER_DES_H
#define HEADER_DES_H
#endif /* HEADER_DES_H */
#endif /* FTP_KRB4 */
#include "ck_ssl.h"
#endif /* CK_SSL */
#ifdef FTP_SRP
#ifdef HAVE_PWD_H
#include "pwd.h"
#endif /* HAVE_PWD_H */
#include "t_pwd.h"
#include "t_client.h"
#include "krypto.h"
#endif /* FTP_SRP */
#ifdef FTP_GSSAPI
#include <gssapi/gssapi.h>
/*
Need to include the krb5 file, because we're doing manual fallback
from the v2 mech to the v1 mech. Once there's real negotiation,
we can be generic again.
*/
#include <gssapi/gssapi_generic.h>
#include <gssapi/gssapi_krb5.h>
static gss_ctx_id_t gcontext;
#ifdef MACOSX
/** exported constants defined in gssapi_krb5{,_nx}.h **/
/* these are bogus, but will compile */
/*
* The OID of the draft krb5 mechanism, assigned by IETF, is:
* iso(1) org(3) dod(5) internet(1) security(5)
* kerberosv5(2) = 1.3.5.1.5.2
* The OID of the krb5_name type is:
* iso(1) member-body(2) US(840) mit(113554) infosys(1) gssapi(2)
* krb5(2) krb5_name(1) = 1.2.840.113554.1.2.2.1
* The OID of the krb5_principal type is:
* iso(1) member-body(2) US(840) mit(113554) infosys(1) gssapi(2)
* krb5(2) krb5_principal(2) = 1.2.840.113554.1.2.2.2
* The OID of the proposed standard krb5 mechanism is:
* iso(1) member-body(2) US(840) mit(113554) infosys(1) gssapi(2)
* krb5(2) = 1.2.840.113554.1.2.2
* The OID of the proposed standard krb5 v2 mechanism is:
* iso(1) member-body(2) US(840) mit(113554) infosys(1) gssapi(2)
* krb5v2(3) = 1.2.840.113554.1.2.3
*
*/
/*
* Encoding rules: The first two values are encoded in one byte as 40
* * value1 + value2. Subsequent values are encoded base 128, most
* significant digit first, with the high bit (\200) set on all octets
* except the last in each value's encoding.
*/
static CONST gss_OID_desc
ck_krb5_gss_oid_array[] = {
/* this is the official, rfc-specified OID */
{9, "\052\206\110\206\367\022\001\002\002"},
/* this is the unofficial, wrong OID */
{5, "\053\005\001\005\002"},
/* this is the v2 assigned OID */
{9, "\052\206\110\206\367\022\001\002\003"},
/* these two are name type OID's */
{10, "\052\206\110\206\367\022\001\002\002\001"},
{10, "\052\206\110\206\367\022\001\002\002\002"},
{ 0, 0 }
};
static
CONST gss_OID_desc * CONST gss_mech_krb5_v2 = ck_krb5_gss_oid_array+2;
#ifdef MACOSX103
static
CONST gss_OID_desc * CONST gss_mech_krb5 = ck_krb5_gss_oid_array+0;
#endif /* MACOSX103 */
#ifndef MACOSX
static
CONST gss_OID_desc * CONST gss_mech_krb5 = ck_krb5_gss_oid_array+0;
static
CONST gss_OID_desc * CONST gss_mech_krb5_old = ck_krb5_gss_oid_array+1;
static
CONST gss_OID_desc * CONST gss_nt_krb5_name = ck_krb5_gss_oid_array+3;
static
CONST gss_OID_desc * CONST gss_nt_krb5_principal = ck_krb5_gss_oid_array+4;
#endif /* MACOSX */
/*
* See krb5/gssapi_krb5.c for a description of the algorithm for
* encoding an object identifier.
*/
/*
* The OID of user_name is:
* iso(1) member-body(2) US(840) mit(113554) infosys(1) gssapi(2)
* generic(1) user_name(1) = 1.2.840.113554.1.2.1.1
* machine_uid_name:
* iso(1) member-body(2) US(840) mit(113554) infosys(1) gssapi(2)
* generic(1) machine_uid_name(2) = 1.2.840.113554.1.2.1.2
* string_uid_name:
* iso(1) member-body(2) US(840) mit(113554) infosys(1) gssapi(2)
* generic(1) string_uid_name(3) = 1.2.840.113554.1.2.1.3
* service_name:
* iso(1) member-body(2) US(840) mit(113554) infosys(1) gssapi(2)
* generic(1) service_name(4) = 1.2.840.113554.1.2.1.4
* exported_name:
* 1(iso), 3(org), 6(dod), 1(internet), 5(security), 6(nametypes),
* 4(gss-api-exported-name)
* host_based_service_name (v2):
* iso (1) org (3), dod (6), internet (1), security (5), nametypes(6),
* gss-host-based-services(2)
*/
static gss_OID_desc ck_oids[] = {
{10, "\052\206\110\206\367\022\001\002\001\001"},
{10, "\052\206\110\206\367\022\001\002\001\002"},
{10, "\052\206\110\206\367\022\001\002\001\003"},
{10, "\052\206\110\206\367\022\001\002\001\004"},
{ 6, "\053\006\001\005\006\004"},
{ 6, "\053\006\001\005\006\002"},
};
static gss_OID ck_gss_nt_user_name = ck_oids+0;
static gss_OID ck_gss_nt_machine_uid_name = ck_oids+1;
static gss_OID ck_gss_nt_string_uid_name = ck_oids+2;
static gss_OID ck_gss_nt_service_name = ck_oids+3;
static gss_OID ck_gss_nt_exported_name = ck_oids+4;
static gss_OID ck_gss_nt_service_name_v2 = ck_oids+5;
#endif /* MACOSX */
#endif /* FTP_GSSAPI */
#ifdef OS2
#ifdef FTP_SRP
#define MAP_KRYPTO
#ifdef SRPDLL
#define MAP_SRP
#endif /* SRPDLL */
#endif /* FTP_SRP */
#ifdef FTP_KRB4
#define MAP_KRB4
#ifdef CK_ENCRYPTION
#define MAP_DES
#endif /* CK_ENCRYPTION */
#endif /* FTP_KRB4 */
#ifdef FTP_GSSAPI
#define MAP_GSSAPI
#define GSS_OIDS
#endif /* FTP_GSSAPI */
#include "ckoath.h"
extern int k95stdout, wherex[], wherey[];
extern unsigned char colorcmd;
#endif /* OS2 */
#ifdef FTP_KRB4
static char ftp_realm[REALM_SZ + 1];
static KTEXT_ST ftp_tkt;
#ifdef OS2
static LEASH_CREDENTIALS ftp_cred;
#else /* OS2 */
static CREDENTIALS ftp_cred;
#endif /* OS2 */
static MSG_DAT ftp_msg_data;
static des_key_schedule ftp_sched;
static int foo[4] = {99,99,99,99};
#endif /* FTP_KRB4 */
/* getreply() function codes */
#define GRF_AUTH 1 /* Reply to AUTH command */
#define GRF_FEAT 2 /* Reply to FEAT command */
/* Operational definitions */
#define DEF_VBM 0 /* Default verbose mode */
/* #define SETVBM */ /* (see getreply) */
#define URL_ONEFILE /* GET, not MGET, for FTP URL */
#define FTP_BUFSIZ 10240 /* Max size for FTP cmds & replies */
#define SRVNAMLEN 32 /* Max length for server type name */
#define PWDSIZ 256
#define PASSBUFSIZ 256
#define PROMPTSIZ 256
#ifndef MGETMAX /* Max operands for MGET command */
#define MGETMAX 1000
#endif /* MGETMAX */
#ifdef FTP_SRP
#define FUDGE_FACTOR 100
#endif /* FTP_SRP */
/*
Amount of growth from cleartext to ciphertext. krb_mk_priv adds this
number bytes. Must be defined for each auth type.
GSSAPI appears to add 52 bytes, but I'm not sure it is a constant--hartmans
3DES requires 56 bytes. Lets use 96 just to be sure.
*/
#ifdef FTP_GSSAPI
#ifndef FUDGE_FACTOR
#define FUDGE_FACTOR 96
#endif /* FUDGE_FACTOR */
#endif /* FTP_GSSAPI */
#ifdef FTP_KRB4
#ifndef FUDGE_FACTOR
#define FUDGE_FACTOR 32
#endif /* FUDGE_FACTOR */
#endif /* FTP_KRB4 */
#ifndef FUDGE_FACTOR /* In case no auth types define it */
#define FUDGE_FACTOR 0
#endif /* FUDGE_FACTOR */
#ifndef MAXHOSTNAMELEN
#define MAXHOSTNAMELEN 64
#endif /* MAXHOSTNAMELEN */
#define MAX_DNS_NAMELEN (15*(MAXHOSTNAMELEN + 1)+1)
/* Fascist compiler toadying */
#ifndef SENDARG2TYPE
#ifdef COMMENT /* Might be needed here and there */
#define SENDARG2TYPE const char *
#else
#define SENDARG2TYPE char *
#endif /* COMMENT */
#endif /* SENDARG2TYPE */
/* Common text messages */
static char *nocx = "?No FTP control connection\n";
static char *fncnam[] = {
"rename", "overwrite", "backup", "append", "discard", "ask", "update",
"dates-differ", ""
};
/* Macro definitions */
/* Used to speed up text-mode PUTs */
#define zzout(fd,c) \
((fd<0)?(-1):((nout>=ucbufsiz)?(zzsend(fd,c)):(ucbuf[nout++]=c)))
#define CHECKCONN() if(!connected){printf(nocx);return(-9);}
/* Externals */
#ifdef CK_URL
extern struct urldata g_url;
#endif /* CK_URL */
#ifdef DYNAMIC
extern char *zinbuffer, *zoutbuffer; /* Regular Kermit file i/o */
#else
extern char zinbuffer[], zoutbuffer[];
#endif /* DYNAMIC */
extern char *zinptr, *zoutptr;
extern int zincnt, zoutcnt, zobufsize, fncact;
#ifdef CK_TMPDIR
extern int f_tmpdir; /* Directory changed temporarily */
extern char savdir[]; /* For saving current directory */
extern char * dldir;
#endif /* CK_TMPDIR */
extern char * rfspec, * sfspec, * srfspec, * rrfspec; /* For WHERE command */
extern xx_strp xxstring;
extern struct keytab onoff[], txtbin[], rpathtab[];
extern int nrpathtab, xfiletype, patterns, gnferror, moving, what, pktnum;
extern int success, nfils, sndsrc, quiet, nopush, recursive, inserver, binary;
extern int filepeek, nscanfile, fsecs, xferstat, xfermode, lastxfer, tsecs;
extern int backgrd, spackets, rpackets, spktl, rpktl, xaskmore, cmd_rows;
extern int nolinks, msgflg, keep;
extern CK_OFF_T fsize, ffc, tfc, sendstart, sndsmaller, sndlarger, rs_len;
extern long filcnt, xfsecs, tfcps, cps, oldcps;
#ifdef FTP_TIMEOUT
int ftp_timed_out = 0;
long ftp_timeout = 0;
#endif /* FTP_TIMEOUT */
#ifdef GFTIMER
extern CKFLOAT fptsecs, fpfsecs, fpxfsecs;
#else
extern long xfsecs;
#endif /* GFTIMER */
extern char filnam[], * filefile, myhost[];
extern char * snd_move, * rcv_move, * snd_rename, * rcv_rename;
extern int g_skipbup, skipbup, sendmode;
extern int g_displa, fdispla, displa;
#ifdef LOCUS
extern int locus, autolocus;
#endif /* LOCUS */
#ifndef NOCSETS
extern int nfilc, dcset7, dcset8, fileorder;
extern struct csinfo fcsinfo[];
extern struct keytab fcstab[];
extern int fcharset;
#endif /* NOCSETS */
extern char sndbefore[], sndafter[], *sndexcept[]; /* Selection criteria */
extern char sndnbefore[], sndnafter[], *rcvexcept[];
extern CHAR feol;
extern char * remdest;
extern int remfile, remappd, rempipe;
#ifndef NOSPL
extern int cmd_quoting;
#ifdef PUTARRAY
extern int sndxlo, sndxhi, sndxin;
extern char sndxnam[];
extern char **a_ptr[]; /* Array pointers */
extern int a_dim[]; /* Array dimensions */
#endif /* PUTARRAY */
#endif /* NOSPL */
#ifndef NOMSEND /* MPUT and ADD SEND-LIST lists */
extern char *msfiles[];
extern int filesinlist;
extern struct filelist * filehead;
extern struct filelist * filetail;
extern struct filelist * filenext;
extern int addlist;
extern char fspec[]; /* Most recent filespec */
extern int fspeclen; /* Length of fspec[] buffer */
#endif /* NOMSEND */
extern int pipesend;
#ifdef PIPESEND
extern char * sndfilter, * rcvfilter;
#endif /* PIPESEND */
#ifdef CKROOT
extern int ckrooterr;
#endif /* CKROOT */
#ifdef KRB4
extern int krb4_autoget;
_PROTOTYP(char * ck_krb4_realmofhost,(char *));
#endif /* KRB4 */
#ifdef KRB5
extern int krb5_autoget;
extern int krb5_d_no_addresses;
_PROTOTYP(char * ck_krb5_realmofhost,(char *));
#endif /* KRB5 */
#ifdef DCMDBUF
extern char *atmbuf; /* Atom buffer (malloc'd) */
extern char *cmdbuf; /* Command buffer (malloc'd) */
extern char *line; /* Big string buffer #1 */
extern char *tmpbuf; /* Big string buffer #2 */
#else
extern char atmbuf[]; /* The same, but static */
extern char cmdbuf[];
extern char line[];
extern char tmpbuf[];
#endif /* DCMDBUF */
extern char * cmarg, * cmarg2, ** cmlist; /* For setting up file lists */
/* Public variables declared here */
#ifdef NOXFER
int ftpget = 1; /* GET/PUT/REMOTE orientation FTP */
#else
int ftpget = 2; /* GET/PUT/REMOTE orientation AUTO */
#endif /* NOXFER */
int ftpcode = -1; /* Last FTP response code */
int ftp_cmdlin = 0; /* FTP invoked from command line */
int ftp_fai = 0; /* FTP failure count */
int ftp_deb = 0; /* FTP debugging */
int ftp_dis = -1; /* FTP display style */
int ftp_log = 1; /* FTP Auto-login */
int sav_log = -1;
int ftp_action = 0; /* FTP action from command line */
int ftp_dates = 1; /* Set file dates from server */
int ftp_xfermode = XMODE_A; /* FTP-specific transfer mode */
char ftp_reply_str[FTP_BUFSIZ] = ""; /* Last line of previous reply */
char ftp_srvtyp[SRVNAMLEN] = { NUL, NUL }; /* Server's system type */
char ftp_user_host[MAX_DNS_NAMELEN]= ""; /* FTP hostname specified by user */
char * ftp_host = NULL; /* FTP hostname */
char * ftp_logname = NULL; /* FTP username */
char * ftp_rdir = NULL; /* Remote directory from cmdline */
char * ftp_apw = NULL; /* Anonymous password */
/* Definitions and typedefs needed for prototypes */
#define sig_t my_sig_t
#define sigtype SIGTYP
typedef sigtype (*sig_t)();
/* Static global variables */
static char ftpsndbuf[FTP_BUFSIZ+64];
static char * fts_sto = NULL;
static int ftpsndret = 0;
static struct _ftpsnd {
sig_t oldintr, oldintp;
int reply;
int incs,
outcs;
char * cmd, * local, * remote;
int bytes;
int restart;
int xlate;
char * lmode;
} ftpsnd;
/*
This is just a first stab -- these strings should match how the
corresponding FTP servers identify themselves.
*/
#ifdef UNIX
static char * myostype = "UNIX";
#else
#ifdef VMS
/* not yet... */
static char * myostype = "VMS";
#else
#ifdef OS2
#ifdef NT
static char * myostype = "WIN32";
#else
static char * myostype = "OS/2";
#endif /* NT */
#else
static char * myostype = "UNSUPPORTED";
#endif /* OS2 */
#endif /* VMS */
#endif /* UNIX */
static int noinit = 0; /* Don't send REST, STRU, MODE */
static int alike = 0; /* Client/server like platforms */
static int local = 1; /* Shadows Kermit global 'local' */
static int dout = -1; /* Data connection file descriptor */
static int dpyactive = 0; /* Data transfer is active */
static int globaldin = -1; /* Data connection f.d. */
static int out2screen = 0; /* GET output is to screen */
static int forcetype = 0; /* Force text or binary mode */
static int cancelfile = 0; /* File canceled */
static int cancelgroup = 0; /* Group canceled */
static int anonymous = 0; /* Logging in as anonymous */
static int loggedin = 0; /* Logged in (or not) */
static int puterror = 0; /* What to do on PUT error */
static int geterror = 0; /* What to do on GET error */
static int rfrc = 0; /* remote_files() return code */
static int okrestart = 0; /* Server understands REST */
static int printlines = 0; /* getreply()should print data lines */
static int haveurl = 0; /* Invoked by command-line FTP URL */
static int mdtmok = 1; /* Server supports MDTM */
static int sizeok = 1;
static int featok = 1;
static int mlstok = 1;
static int stouarg = 1;
static int typesent = 0;