forked from KermitProject/ckermit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ckuusy.c
4763 lines (4476 loc) · 131 KB
/
ckuusy.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
#include "ckcsym.h"
#define XFATAL fatal
/* C K U U S Y -- "User Interface" for C-Kermit Kermit, part Y */
/* Command-Line Argument Parser */
/*
Authors:
Frank da Cruz <[email protected]>,
The Kermit Project, New York City
Jeffrey E Altman <[email protected]>
Secure Endpoints Inc., New York City
Copyright (C) 1985, 2014,
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.
Most recent update:
Sun Feb 23 09:39:28 2014
*/
#include "ckcdeb.h"
char * bannerfile = NULL;
char * helpfile = NULL;
extern int xferlog, filepeek, nolinks;
extern char * xferfile;
extern int debtim;
#include "ckcasc.h"
#include "ckcker.h"
#include "ckucmd.h"
#include "ckcnet.h"
#include "ckuusr.h"
#include "ckcxla.h"
#ifdef CK_SSL
#include "ck_ssl.h"
#endif /* CK_SSL */
#include <signal.h>
#ifdef OS2
#include <io.h>
#ifdef KUI
#include "ikui.h"
extern struct _kui_init kui_init;
#endif /* KUI */
#endif /* OS2 */
extern int inserver, fncnv, f_save, xfermode;
#ifdef PATTERNS
extern int patterns;
#endif /* PATTERNS */
#ifndef NOICP
extern int cmdint;
#endif /* NOICP */
extern int xsuspend;
#ifdef NETCONN
#ifdef ANYX25
extern int revcall, closgr, cudata;
extern char udata[];
extern int x25fd;
#endif /* ANYX25 */
#ifndef VMS
#ifndef OS2
#ifndef OSK
extern
#endif /* OSK */
#endif /* OS2 */
#endif /* VMS */
int telnetfd;
extern struct keytab netcmd[];
extern int tn_exit;
#ifndef NOICP
#ifndef NODIAL
extern int nnets, nnetdir; /* Network services directory */
extern char *netdir[];
extern char *nh_p[]; /* Network directory entry pointers */
extern char *nh_p2[]; /* Network directory entry nettype */
extern char *nh_px[4][MAXDNUMS + 1];
#endif /* NODIAL */
extern int nhcount;
extern char * n_name; /* Network name pointer */
#endif /* NOICP */
#endif /* NETCONN */
#ifndef NOSPL
extern int nmac;
extern struct mtab *mactab;
#endif /* NOSPL */
extern char uidbuf[];
#ifdef CK_LOGIN
extern int logintimo;
#endif /* CK_LOGIN */
extern char * myname, * dftty;
extern int howcalled;
extern char *ckxsys, *ckzsys, **xargv, *xarg0, **cmlist, *clcmds;
extern int action, cflg, xargc, cnflg, local, quiet, escape, network, mdmtyp,
bgset, backgrd, xargs, binary, parity, turn, turnch, duplex, flow, clfils,
noinit, stayflg, nettype, cfilef, noherald, cmask, cmdmsk, exitonclose,
haveline, justone, cxtype, xfinish, ttnproto;
extern long speed;
extern char ttname[];
extern char * pipedata, cmdfil[];
#ifndef NOXFER
extern char *cmarg, *cmarg2;
extern int nfils, stdouf, stdinf, displa, maxrps, rpsiz, ckwarn, urpsiz,
wslotr, swcapr, ckdelay, recursive, reliable, xreliable, fnspath, fncact,
clearrq, setreliable;
#ifdef PIPESEND
extern int usepipes, pipesend;
#endif /* PIPESEND */
extern int protocol;
#endif /* NOXFER */
#ifndef NOPUSH
extern int nopush;
#endif /* NOPUSH */
#ifdef OS2
extern struct keytab os2devtab[];
extern int nos2dev;
extern int ttslip;
extern int tt_scroll, tt_escape;
#ifdef OS2PM
extern int os2pm;
#endif /* OS2PM */
#endif /* OS2 */
#ifdef CK_NETBIOS
extern unsigned char NetBiosAdapter;
#endif /* CK_NETBIOS */
#ifdef XFATAL
#undef XFATAL
#endif /* XFATAL */
#ifdef TNCODE
_PROTOTYP(static int dotnarg, (char x) );
#endif /* TNCODE */
#ifdef RLOGCODE
_PROTOTYP(static int dorlgarg, (char x) );
#endif /* RLOGCODE */
#ifdef SSHBUILTIN
_PROTOTYP(static int dossharg, (char x) );
#endif /* SSHBUILTIN */
int haveftpuid = 0; /* Have FTP user ID */
static int have_cx = 0; /* Have connection */
static char * failmsg = NULL; /* Failure message */
#ifdef NEWFTP
extern char * ftp_host;
#endif /* NEWFTP */
extern int what;
#ifndef NOICP
#ifndef NODIAL
extern int nmdm, telephony;
extern struct keytab mdmtab[];
extern int usermdm, dialudt;
#endif /* NODIAL */
_PROTOTYP(static int pmsg, (char *) );
_PROTOTYP(static int fmsg, (char *) );
static int pmsg(s) char *s; { printf("%s\n", s); return(0); }
static int fmsg(s) char *s; { fatal(s); return(0); }
#define XFATAL(s) return(what==W_COMMAND?pmsg(s):fmsg(s))
#else
#define XFATAL fatal
#endif /* NOICP */
#ifndef NOHTTP
#define HTTP_GET 1
#define HTTP_PUT 2
#define HTTP_HED 3
#endif /* NOHTTP */
#ifdef CK_URL
/* URLs we recognize */
#define URL_FTP 1
#define URL_HTTP 2
#define URL_HTTPS 3
#define URL_IKSD 4
#define URL_TELNET 5
#define URL_LOGIN 6
struct keytab urltab[] = {
#ifdef NEWFTP
"ftp", URL_FTP, 0,
#endif /* NEWFTP */
#ifndef NOHTTP
"http", URL_HTTP, 0,
"https", URL_HTTPS, 0,
#endif /* NOHTTP */
"iksd", URL_IKSD, 0,
"kermit", URL_IKSD, 0,
"telnet", URL_TELNET, 0,
"", 0, 0
};
int nurltab = sizeof(urltab)/sizeof(struct keytab) - 1;
#ifndef URLBUFLEN
#define URLBUFLEN 1024
#endif /* URLBUFLEN */
static char urlbuf[URLBUFLEN];
struct urldata g_url = {NULL,NULL,NULL,NULL,NULL,NULL,NULL};
/* u r l p a r s e -- Parse a possible URL */
/*
Returns 0 if the candidate does not seem to be a URL.
Returns 1 if it might be a URL, with the above pointers set to its pieces:
service : [ // ] [ user [ : password ] @ ] host [ : service ] [ / path ] -
[ ? name [ = value ]]
Example: ftp://ds.internic.net:21/rfc/rfc1234.txt
url.svc = [ftp]
url.usr = [(NULL)]
url.psw = [(NULL)]
url.hos = [ds.internic.net]
url.por = [21]
url.pth = [rfc/rfc1234.txt]
It might be a URL if it contains a possible service name followed by a
a colon (:). Thus "telnet:xyzcorp.com" is a minimal URL, whereas a
full-blown example would be:
ftp://olga:[email protected]/public/oofa.txt
The caller must verify the results, i.e. that the service string is a real
TCP service, etc. This routine just parses the fields.
struct urldata defined in ckcker.h
*/
int
urlparse(s,url) char *s; struct urldata * url; {
char * p = NULL, * urlbuf = NULL;
int x;
if (!s || !url)
return(0);
if (!*s)
return(0);
makestr(&urlbuf,s);
if (url->sav) { /* In case we were called before... */
free(url->sav);
url->sav = NULL;
}
if (url->svc) {
free(url->svc);
url->svc = NULL;
}
if (url->hos) {
free(url->hos);
url->hos = NULL;
}
if (url->por) {
free(url->por);
url->por = NULL;
}
if (url->usr) {
free(url->usr);
url->usr = NULL;
}
if (url->psw) {
free(url->psw);
url->psw = NULL;
}
if (url->pth) {
free(url->pth);
url->pth = NULL;
}
if (url->nopts) {
int i;
for (i = 0; i < url->nopts && i < MAX_URL_OPTS; i++ ) {
if (url->opt[i].nam) {
free(url->opt[i].nam);
url->opt[i].nam = NULL;
}
if (url->opt[i].val) {
free(url->opt[i].val);
url->opt[i].val = NULL;
}
}
url->nopts = 0;
}
p = urlbuf; /* Was a service requested? */
while (*p && *p != ':') /* Look for colon */
p++;
if (*p == ':') { /* Have a colon */
*p++ = NUL; /* Get service name or number */
if (*p == ':') /* a second colon */
*p++ = NUL; /* get rid of that one too */
while (*p == '/') *p++ = NUL; /* and slashes */
#ifdef COMMENT
/* Trailing slash is part of path - leave it - jaltman */
x = strlen(p); /* Length of remainder */
if (p[x-1] == '/') /* If there is a trailing slash */
p[x-1] = NUL; /* remove it. */
#endif /* COMMENT */
if (urlbuf[0]) { /* Anything left? */
char *q = p, *r = p, *w = p;
makestr(&url->svc,urlbuf);
while (*p != NUL && *p != '@') /* look for @ */
p++;
if (*p == '@') { /* Signifies user ID, maybe password */
*p++ = NUL;
url->hos = p;
while (*w != NUL && *w != ':')
w++;
if (*w == ':')
*w++ = NUL;
url->usr = r; /* Username */
if (*w)
url->psw = w; /* Password */
q = p;
} else { /* No username or password */
p = q;
url->hos = p;
}
#ifdef COMMENT
debug(F111,"urlparse url->usr",url->usr,url->usr);
debug(F111,"urlparse url->psw",url->usr,url->psw);
debug(F111,"urlparse url->hos",url->usr,url->hos);
#endif /* COMMENT */
while (*p != NUL && *p != ':' && *p != '/') /* Port? */
p++;
if (*p == ':') { /* TCP port */
*p++ = NUL;
r = p;
url->por = r;
while (*p != NUL && *p != '/')
p++;
/* '/' is part of path, leave it until we can copy */
if (*p == '/') {
makestr(&url->pth,p); /* Path */
*p = NUL;
}
} else { /* No port */
/* '/' is part of path, leave it */
if (*p == '/') {
makestr(&url->pth,p); /* Path */
*p = NUL;
}
}
}
/* Copy non-NULL result strings */
if (url->svc) if (*url->svc) {
p = url->svc;
url->svc = NULL;
makestr(&url->svc,p);
}
if (url->hos) if (*url->hos) {
p = url->hos;
url->hos = NULL;
makestr(&url->hos,p);
}
if (url->por) if (*url->por) {
p = url->por;
url->por = NULL;
makestr(&url->por,p);
}
/*
WARNING (Wed Oct 9 16:09:03 2002): We now allow the username and
password to be empty strings. These are treated differently from null
pointers: an empty string means the URL included username and/or password
fields that were empty, e.g. ftp://:@ftp.xyzcorp.com/somepath/somefile,
which causes the client to prompt for the username and/or password.
*/
if (url->usr) /* if (*url->usr) */ {
p = url->usr;
url->usr = NULL;
makestr(&url->usr,p);
}
if (url->psw) /* if (*url->psw) */ {
p = url->psw;
url->psw = NULL;
makestr(&url->psw,p);
}
/* Save a copy of the full url if one was found. */
if (url->svc)
makestr(&url->sav,s);
free(urlbuf);
return(url->svc ? 1 : 0);
}
return(0);
}
#endif /* CK_URL */
#ifndef NOCMDL
char *hlp1[] = {
#ifndef NOICP
" [filename] [-x arg [-x arg]...[-yyy]..] [ = text ] ]\n",
#else
"[-x arg [-x arg]...[-yyy]..]\n",
#endif /* NOICP */
"\n",
" -x is an option requiring an argument, -y an option with no argument.\n",
" If the first command-line argument is the name of a file, interactive-\n",
" mode commands are executed from the file. The '=' argument tells Kermit\n",
" not to parse the remainder of the command line, but to make the words\n",
" following '=' available as \\%1, \\%2, ... \\%9. The command file \
(if any)\n",
" is executed before the command-line options.\n",
"\n",
#ifndef NOICP
"If no action command is included, or -S is, then after the command line is\n",
"executed, Kermit issues its prompt and waits for you to type commands.\n",
#else
"Operation by command-line options only.\n",
#endif /* NOICP */
""
};
static
char *hlp2[] = {
" [option-list] host[:port] [port]\n",
" The option-list consists of zero, one, or more of:\n",
" -8 Negotiate Telnet Binary in both directions\n",
" -a Require use of Telnet authentication\n",
" -d Turn on debug mode\n",
" -E No escape character\n",
" -K Refuse use of authentication; do not send username\n",
" -l user Set username and request Telnet authentication\n",
" -L Negotiate Telnet Binary Output only\n",
" -x Require Encryption\n",
" -D Disable forward-X\n",
" -T cert=file Use certificate in file\n",
" -T key=file Use private key in file\n",
" -T crlfile=file Use CRL in file\n",
" -T crldir=dir Use CRLs in directory\n",
" -T cipher=string Use only ciphers in string\n",
" -f Forward credentials to host\n",
" -k realm Set default Kerberos realm\n",
""
};
static
char *hlp3[] = { /* rlogin */
" [option-list] host[:port] [port]\n",
" The option-list consists of zero, one, or more of:\n",
" -d Turn on debug mode\n",
" -l user Set username\n",
""
};
static
char *hlp4[] = { /* ssh */
" [option-list] host[:port] [port]\n",
" The option-list consists of zero, one, or more of:\n",
#ifdef OS2
" -# flags Kermit 95 Startup Flags\n",
" 1 turn off Win95 special fixes\n",
" 2 do not load optional network dlls\n",
" 4 do not load optional tapi dlls\n",
" 8 do not load optional kerberos dlls\n",
" 16 do not load optional zmodem dlls\n",
" 32 use stdin for input instead of the console\n",
" 64 use stdout for output instead of the console\n",
" 128 do not terminate process in response to Session Logoff\n",
#endif /* OS2 */
" -d Turn on debug mode\n",
" -Y Disable init file processing\n",
" -l user Set username\n",
""
};
/* Command-line option help lines. Update this when adding new options! */
char * opthlp[128]; /* Option help */
char * arghlp[128]; /* Argument for option */
int optact[128]; /* Action-option flag */
VOID
fatal2(msg1,msg2) char *msg1, *msg2; {
char buf[256];
if (!msg1) msg1 = "";
if (!msg2) msg2 = "";
ckmakmsg(buf,256,"\"",msg1,"\" - ",msg2);
#ifndef NOICP
if (what == W_COMMAND)
printf("%s\n",buf);
else
#endif /* NOICP */
fatal((char *)buf);
}
static SIGTYP
#ifdef CK_ANSI
cl_int(int dummy)
#else /* CK_ANSI */
cl_int(dummy) int dummy;
#endif /* CK_ANSI */
{ /* Command-line interrupt handler */
doexit(BAD_EXIT,1);
SIGRETURN;
}
#ifdef NEWFTP
extern int ftp_action, ftp_cmdlin;
static int
xx_ftp(host, port) char * host, * port; {
#ifdef CK_URL
extern int haveurl;
#endif /* CK_URL */
extern char * ftp_logname;
int use_tls = 0;
char * p;
if (port) if (!*port) port = NULL;
if (!host)
return(0);
if (!*host)
return(0);
debug(F111,"ftp xx_ftp host",ftp_host,haveftpuid);
debug(F111,"ftp xx_ftp uidbuf 1",uidbuf,haveftpuid);
ftp_cmdlin = 1; /* 1 = FTP started from command line */
if (nfils > 0)
ftp_cmdlin++; /* 2 = same plus file transfer */
#ifndef NOURL
/* debug(F111,"ftp xx_ftp g_url.usr",g_url.usr,g_url.usr); */
if (haveurl && g_url.usr) { /* Wed Oct 9 15:15:22 2002 */
if (!*(g_url.usr)) { /* Force username prompt if */
haveftpuid = 0; /* "ftp://:@host" given. */
uidbuf[0] = NUL;
makestr(&ftp_logname,NULL);
}
debug(F111,"ftp xx_ftp uidbuf 2",uidbuf,haveftpuid);
}
#endif /* NOURL */
debug(F111,"ftp xx_ftp uidbuf 3",uidbuf,haveftpuid);
if (haveftpuid) {
makestr(&ftp_logname,uidbuf);
debug(F111,"ftp_logname",ftp_logname,haveftpuid);
}
if (!port) {
if ((p = ckstrchr(ftp_host,':')))
*p++ = NUL;
port = p;
}
if (!port) {
#ifdef CK_URL
if (haveurl) {
if (g_url.por)
port = g_url.por;
else if (g_url.svc)
port = g_url.svc;
else
port = "ftp";
} else
#endif /* CK_URL */
port = "ftp";
}
#ifdef CK_SSL
if (haveurl && g_url.svc)
use_tls = !ckstrcmp("ftps",g_url.svc,-1,0);
#endif /* CK_SSL */
if (ftpopen(ftp_host,port,use_tls) < 1)
return(-1);
debug(F111,"ftp xx_ftp action",ckctoa((char)ftp_action),nfils);
if (nfils > 0) {
switch (ftp_action) {
case 'g':
return(cmdlinget(stayflg));
case 'p':
case 's':
return(cmdlinput(stayflg));
}
}
return(1);
}
#endif /* NEWFTP */
#ifndef NOHTTP
static
char * http_hlp[] = {
" -h This message.\n",
" -d Debug to debug.log.\n",
" -S Stay (issue command prompt when done).\n",
" -Y Do not execute Kermit initialization file.\n",
" -q Quiet (suppress most messages).\n",
" -u name Username.\n",
" -P password Password.\n",
" -g pathname Get remote pathname.\n",
" -p pathname Put remote pathname.\n",
" -H pathname Head remote pathname.\n",
" -l pathname Local path for -g, -p, and -H.\n",
#ifdef CK_SSL
" -z opt[=value] Security options...\n",
" cert=file Client certificate file\n",
" certsok Accept all certificates\n",
" key=file Client private key file\n",
" secure Use SSL\n",
" verify=n 0 = none, 1 = peer , 2 = certificate required\n",
#endif /* CK_SSL */
""
};
#define HT_CERTFI 0
#define HT_OKCERT 1
#define HT_KEY 2
#define HT_SECURE 3
#define HT_VERIFY 4
static struct keytab httpztab[] = {
{ "cert", HT_CERTFI, CM_ARG },
{ "certsok", HT_OKCERT, 0 },
{ "key", HT_KEY, CM_ARG },
{ "secure", HT_SECURE, 0 },
{ "verify", HT_VERIFY, CM_ARG },
{ "", 0, 0 }
};
static int nhttpztab = sizeof(httpztab) / sizeof(struct keytab) - 1;
#endif /* NOHTTP */
/* U S A G E */
VOID
usage() {
#ifdef MINIX
conol("Usage: ");
conol(xarg0);
conol(" [-x arg [-x arg]...[-yyy]..] ]\n");
#else
conol("Usage: ");
conol(xarg0);
if (howcalled == I_AM_KERMIT || howcalled == I_AM_IKSD ||
howcalled == I_AM_SSHSUB)
conola(hlp1);
else if (howcalled == I_AM_TELNET)
conola(hlp2);
else if (howcalled == I_AM_RLOGIN)
conola(hlp3);
else if (howcalled == I_AM_SSH)
conola(hlp4);
if (howcalled == I_AM_KERMIT || howcalled == I_AM_IKSD ||
howcalled == I_AM_SSHSUB) {
int c;
conoll("");
conoll("Complete listing of command-line options:");
conoll("");
for (c = 31; c < 128; c++) {
if (!opthlp[c])
continue;
if (arghlp[c]) {
printf(" -%c <arg>%s\n",
(char)c,
(optact[c] ? " (action option)" : "")
);
printf(" %s\n",opthlp[c]);
printf(" Argument: %s\n\n",arghlp[c]);
} else { /* Option without arg */
printf(" -%c %s%s\n",
(char)c, opthlp[c],
(optact[c]?" (action option)":"")
);
printf(" Argument: (none)\n\n");
}
}
#ifdef OS2ORUNIX
printf("To prevent this message from scrolling, use '%s -h | more'.\n",
xarg0);
#endif /* OS2ORUNIX */
printf("For a list of extended options use '%s --help'.\n",
xarg0);
}
#endif /* MINIX */
}
/* C M D L I N -- Get arguments from command line */
int
cmdlin() {
char x; /* Local general-purpose char */
extern int haveurl;
#ifdef NEWFTP
char * port = NULL;
#endif /* NEWFTP */
#ifndef NOXFER
cmarg = ""; /* Initialize globals */
cmarg2 = "";
#endif /* NOXFER */
action = 0;
cflg = 0;
signal(SIGINT,cl_int);
/* Here we handle different "Command Line Personalities" */
#ifdef TCPSOCKET
#ifndef NOHTTP
if (howcalled == I_AM_HTTP) { /* If I was called as HTTP... */
char rdns[128];
#ifdef OS2
char * agent = "Kermit 95";
#else
char * agent = "C-Kermit";
#endif /* OS2 */
debug(F100,"http personality","",0);
#ifdef CK_URL
if (haveurl) {
int type;
char * lfile;
type = lookup(urltab,g_url.svc,nurltab,NULL);
if (!(type == URL_HTTP || type == URL_HTTPS)) {
printf("?Internal Error: HTTP command line processing\n");
debug(F100,"Error: HTTP command line processing","",0);
doexit(BAD_EXIT,1);
}
rdns[0] = '\0';
lfile = "";
x = (http_open(g_url.hos,g_url.por ? g_url.por : g_url.svc,
type == URL_HTTPS, rdns,128,NULL) == 0);
if (x) {
#ifdef KUI
char asname[CKMAXPATH+1];
#endif /* KUI */
if (!quiet) {
if (rdns[0])
printf("Connected to %s [%s]\r\n",g_url.hos,rdns);
else
printf("Connected to %s\r\n",g_url.hos);
}
if (g_url.pth)
zstrip(g_url.pth,&lfile);
else
g_url.pth = "/";
if (!*lfile)
lfile = "index.html";
#ifdef KUI
if (uq_file(NULL, /* K95 GUI: Put up file box. */
NULL, /* (not tested...) */
4,
NULL,
lfile,
asname,
CKMAXPATH+1
) > 0)
lfile = asname;
#endif /* KUI */
x = http_get(agent,
NULL, /* hdrlist */
g_url.usr,
g_url.psw,
0,
lfile,
g_url.pth,
0 /* stdio */
);
x = (http_close() == 0);
} else {
if (!quiet)
printf("?HTTP Connection failed.\r\n");
}
doexit(x ? GOOD_EXIT : BAD_EXIT, -1);
} else
#endif /* CK_URL */
{
int http_action = 0;
char * host = NULL, * svc = NULL, * lpath = NULL;
char * user = NULL, * pswd = NULL, * path = NULL;
char * xp;
while (--xargc > 0) { /* Go through command line words */
xargv++;
debug(F111,"cmdlin http xargv",*xargv,xargc);
xp = *xargv+1;
if (**xargv == '-') { /* Got an option */
int xx;
x = *(*xargv+1); /* Get the option letter */
switch (x) {
case 'd': /* Debug */
#ifdef DEBUG
if (deblog) {
debtim = 1;
} else {
deblog = debopn("debug.log",0);
}
#endif /* DEBUG */
break;
case 'S': /* Stay */
case 'Y': /* No initialization file */
break; /* (already done in prescan) */
case 'q': /* Quiet */
quiet = 1;
break;
case 'u': /* Options that require arguments */
case 'P':
case 'g':
case 'p':
case 'H':
case 'l':
if (*(xp+1)) {
XFATAL("Invalid argument bundling");
}
xargv++, xargc--;
if ((xargc < 1) || (**xargv == '-')) {
XFATAL("Missing argument");
}
switch (x) {
case 'u':
user = *xargv;
break;
case 'P':
pswd = *xargv;
break;
case 'l':
if (http_action != HTTP_PUT)
lpath = *xargv;
break;
case 'g':
http_action = HTTP_GET;
path = *xargv;
debug(F111,"cmdlin http GET",path,http_action);
break;
case 'p':
http_action = HTTP_PUT;
path = *xargv;
break;
case 'H':
http_action = HTTP_HED;
path = *xargv;
}
break;
#ifdef CK_SSL
case 'z': {
/* *xargv contains a value of the form tag=value */
/* we need to lookup the tag and save the value */
int x,y,z;
char * p, * q;
makestr(&p,*xargv);
y = ckindex("=",p,0,0,1);
if (y > 0)
p[y-1] = '\0';
x = lookup(httpztab,p,nhttpztab,&z);
if (x < 0) {
printf("?Invalid security option: \"%s\"\n",p);
} else {
printf("Security option: \"%s",p);
if (httpztab[z].flgs & CM_ARG) {
q = &p[y];
if (!*q)
fatal("?Missing required value");
}
/* -z options w/args */
switch (httpztab[z].kwval) {
case HT_CERTFI:
makestr(&ssl_rsa_cert_file,q);
break;
case HT_OKCERT:
ssl_certsok_flag = 1;
break;
case HT_KEY:
makestr(&ssl_rsa_key_file,q);
break;
case HT_SECURE:
svc="https";
break;
case HT_VERIFY:
if (!rdigits(q))
printf("?Bad number: %s\n",q);
ssl_verify_flag = atoi(q);
break;
}
}
free(p);
break;
}
#endif /* CK_SSL */
case 'h': /* Help */
default:
printf("Usage: %s host [ options... ]\n",xarg0);
conola(http_hlp);
doexit(GOOD_EXIT,-1);
}
} else { /* No dash - must be hostname */
host = *xargv;
if (xargc > 1) {
svc = *(xargv+1);
if (svc) if (*svc == '-' || !*svc)
svc = NULL;
if (svc) {
xargv++;
xargc--;
}
}
}
}
if (!svc) svc = "";
if (!*svc) svc = "http";
if (!host) XFATAL("No http host given");
/* Check action args before opening the connection */
if (http_action) {
if (http_action == HTTP_PUT) {
if (!lpath)
XFATAL("No local path for http PUT");
}
if (!path)
XFATAL("No remote path for http action");
}
/* Now it's OK to open the connection */
rdns[0] = NUL;
x = (http_open(host,
svc,!ckstrcmp("https",svc,-1,0),rdns,128,NULL
) == 0);
if (!x) {
if (!quiet)
printf("?HTTP Connection failed.\r\n");
doexit(BAD_EXIT,-1);
}
if (!quiet) {
if (rdns[0])
printf("Connected to %s [%s]\r\n",host,rdns);
else
printf("Connected to %s\r\n",host);
}
if (http_action) {
int pcpy = 0;
if (http_action != HTTP_PUT) { /* Supply default */
if (!lpath) { /* local path... */
zstrip(path,&lpath);
if (!lpath)
lpath = "";
if (!*lpath)
lpath = "index.html";
}
}
if (*path != '/') {
char * p = (char *) malloc(strlen(path)+2);
if (!p) fatal("?Memory allocation error\n");
*p = '/';
strcpy(&p[1],path); /* safe */
path = p;
pcpy = 1;
}
switch (http_action) {
case HTTP_GET:
x = http_get(agent,NULL,user,pswd,0,lpath,path,0);
break;
case HTTP_PUT:
x = http_put(agent,NULL,"text/HTML",
user,pswd,0,lpath,path,NULL,0);
break;
case HTTP_HED:
x = http_head(agent,NULL,user,pswd,0,lpath,path,0);
break;
}
debug(F101,"cmdline http result","",x);
x = (http_close() == 0);
if (pcpy) free(path);
doexit(x ? GOOD_EXIT : BAD_EXIT, -1);
}
return(0);
}
} else
#endif /* NOHTTP */
#ifdef NEWFTP
if (howcalled == I_AM_FTP) { /* If I was called as FTP... */
debug(F100,"ftp personality","",0);
#ifdef CK_URL