forked from JasonAlt/UberFTP
-
Notifications
You must be signed in to change notification settings - Fork 2
/
cmds.c
3842 lines (3319 loc) · 88.3 KB
/
cmds.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
/*
* University of Illinois/NCSA Open Source License
*
* Copyright (c) 2003-2012 NCSA. All rights reserved.
*
* Developed by:
*
* Storage Enabling Technologies (SET)
*
* Nation Center for Supercomputing Applications (NCSA)
*
* http://dims.ncsa.uiuc.edu/set/uberftp
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the .Software.),
* to deal with the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* + Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimers.
*
* + Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimers in the
* documentation and/or other materials provided with the distribution.
*
* + Neither the names of SET, NCSA
* nor the names of its contributors may be used to endorse or promote
* products derived from this Software without specific prior written
* permission.
*
* THE SOFTWARE IS PROVIDED .AS IS., WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS WITH THE SOFTWARE.
*/
#include "config.h"
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/time.h>
#include <termios.h>
#include <string.h>
#include <dirent.h>
#include <libgen.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <time.h>
#include <pwd.h>
#include "linterface.h"
#include "filetree.h"
#include "settings.h"
#include "logical.h"
#include "output.h"
#include "cmds.h"
#include "misc.h"
#include "unix.h"
#include "ml.h"
#include "nc.h"
#ifdef SYSLOG_PERF
#include "perf.h"
#endif /* SYSLOG_PERF */
#ifdef DMALLOC
#include "dmalloc.h"
#endif /* DMALLOC */
#define C_RETRY(ec,cmd) \
{ \
int retcnt = s_retry(); \
ec = EC_SUCCESS; \
do \
{ \
ec_destroy(ec); \
ec = cmd; \
if (!ec_retry(ec)) \
break; \
} while (retcnt-- > 0 || !s_retry()); \
}
#define C_A_CMD 0x00
#define C_A_NOARGS 0x01
#define C_A_OINT 0x02 /* Optional 32bit integer. */
#define C_A_STRINGS 0x03 /* Expect 1 string, then optional strings. */
#define C_A_OSTRINGS 0x04 /* Optional strings. */
#define C_A_STRING 0x05 /* Expect 1 string. */
#define C_A_2STRINGS 0x06 /* Expect 2 strings. */
#define C_A_STRINGPLUS 0x07 /* Expect 1 string, possibly 2. */
#define C_A_OSTRING 0x08 /* Possibly 1 string. */
#define C_A_OCHAR 0x09
#define C_A_2OFF 0x0A
#define C_A_OFF 0x0B
#define C_A_PERMS 0x0C
#define C_A_INT_STRINGS 0x0D /* Int followed by 1 or more strings. */
#define C_A_OCH_OSTRING 0x0E
#define C_A_2STRINGPLUS 0x0F /* Expect 2 strings, possibly more. */
#define C_A_2OSTRINGS 0x10 /* Possibly 2 strings. */
#define C_A_OLONG 0x11 /* Optional 64bit integer. */
#define C_A_OPT_P 0x020
#define C_A_OPT_p 0x040
#define C_A_OPT_u 0x080
#define C_A_OPT_r 0x100
#define C_A_OPT_d 0x200
#define C_A_RCH_1 0x1000
#define C_A_LCH_1 0x2000
#define C_A_RCH_2 0x4000
#define C_A_LCH_2 0x8000
#define C_A_OPT_MASK 0xFFE0
#define C_ISDIR(x) ((x) == 0 || (x) == S_IFDIR)
#define C_ISREG(x) ((x) == 0 || (x) == S_IFREG)
/* Connection Handle. */
typedef struct {
lh_t lh;
} ch_t;
typedef struct cmd {
void * func;
char * name;
int ctype;
char * desc;
char * syntax;
char * options;
} cmd_t;
ch_t glch; /* Local connection handle. */
ch_t grch; /* Remote connection handle. */
static cmdret_t _c_lex(char * token);
static cmd_t * _c_lookup(char * cmd);
static cmdret_t _c_active();
static cmdret_t _c_ascii();
static cmdret_t _c_binary();
static cmdret_t _c_blksize(long long size);
static cmdret_t _c_bugs();
static cmdret_t _c_cat(ch_t *, char ** files);
static cmdret_t _c_cdup(ch_t *);
static cmdret_t _c_chdir(ch_t *, char * path);
static cmdret_t _c_chgrp(ch_t *, int rflag, char * group, char ** files);
static cmdret_t _c_chmod(ch_t *, int rflag, int perms, char ** files);
static cmdret_t _c_close(ch_t *);
static cmdret_t _c_cksum(char * val);
static cmdret_t _c_cos(char * cos);
static cmdret_t _c_dcau(char mode, char * subject);
static cmdret_t _c_debug(int lvl);
static cmdret_t _c_glob(char * val);
static cmdret_t _c_family(char * family);
static cmdret_t _c_get(ch_t *, ch_t *, int, char *, char *);
static cmdret_t _c_hash();
static cmdret_t _c_help(char * cmd);
static cmdret_t _c_keepalive(int seconds);
static cmdret_t _c_list(ch_t *, int rflag, char * path, char * ofile);
static cmdret_t _c_lscos(ch_t *);
static cmdret_t _c_lsfam(ch_t *);
static cmdret_t _c_mkdir(ch_t *, char ** dirs);
static cmdret_t _c_mode(char mode);
static cmdret_t _c_mget(ch_t *, ch_t *, int rflag, char ** files);
#ifdef MSSFTP
static cmdret_t _c_open(ch_t *);
#else /* MSSFTP */
static cmdret_t _c_open(ch_t *, char *, char *, char *, int);
#endif /* MSSFTP */
static cmdret_t _c_order(char * order);
static cmdret_t _c_parallel(int count);
static cmdret_t _c_passive();
static cmdret_t _c_pbsz(long long length);
static cmdret_t _c_prot(char);
static cmdret_t _c_pget(ch_t*, ch_t*,globus_off_t, globus_off_t, char*, char*);
static cmdret_t _c_pwd(ch_t *);
static cmdret_t _c_quit(ch_t *, ch_t *);
static cmdret_t _c_quote(ch_t *, char ** words);
static cmdret_t _c_rename(ch_t *, char * sfile, char * dfile);
static cmdret_t _c_retry(int cnt);
static cmdret_t _c_resume(int dflag, char * resume);
static cmdret_t _c_rm(ch_t *, int rflag, char ** files);
static cmdret_t _c_rmdir(ch_t *, char ** dirs);
static cmdret_t _c_runique();
static cmdret_t _c_shell(char ** args);
static cmdret_t _c_size(ch_t *, char ** files);
static cmdret_t _c_stage(ch_t *, int rflag, int t, char ** files);
static cmdret_t _c_sunique();
static cmdret_t _c_tcpbuf(long long size);
#ifdef MSSFTP
static cmdret_t _c_type(char *);
#endif /* MSSFTP */
static cmdret_t _c_versions();
static cmdret_t _c_wait();
static cmdret_t _c_link(ch_t *, char * oldfile, char * newfile);
static cmdret_t _c_symlink(ch_t *, char * oldfile, char * newfile);
static errcode_t _c_get_ml(ch_t * ch, char * target, int type, ml_t ** mlp);
static cmdret_t _c_xfer(ch_t * sch,
ch_t * dch,
int rflag,
char * sfile,
char * dfile,
int unique,
globus_off_t soff,
globus_off_t slen);
static cmdret_t
_c_xfer_file(ch_t * sch,
ch_t * dch,
char * src,
char * dst,
int unique,
globus_off_t soff,
globus_off_t slen);
static cmdret_t
_c_list_normal(ch_t * ch, char * path, char * ofile);
static cmdret_t
_c_list_mlsx(ch_t * ch, char * path, char * ofile, int rflag);
static cmd_t gcmdlist [] = {
{ _c_shell, "!", C_A_OSTRINGS,
"Run the command using a shell on the local machine. If no command is given,\n"
"invoke an interactive shell.\n",
"! [command]\n", NULL},
{ _c_help, "?", C_A_OSTRING,
"If [command] is given, print a (hopefully) helpful blurb about [command].\n"
"Otherwise, list all commands.\n",
"? [command]\n", NULL},
{ _c_active, "active", C_A_NOARGS,
"Change to ACTIVE mode which causes the server to initiate the data\n"
"connection. The default is PASSIVE mode unless the variable\n"
"UBERFTP_ACTIVE_MODE is set in the environment. If you are behind a\n"
"firewall you must use PASSIVE mode.\n",
"active\n", NULL},
{ _c_ascii, "ascii", C_A_NOARGS,
"Change the data transfer type to ASCII which causes the server to do some\n"
"simple transformations to the file being transferred. This is mostly useful\n"
"for changing EOL (end of line) in text files when moving between platforms.\n"
"This option is almost never necessary today. The default is BINARY mode\n"
"also known as IMAGE mode.\n",
"ascii\n", NULL},
{ _c_binary, "binary", C_A_NOARGS,
"Change the data transfer type to BINARY (aka IMAGE) which causes the server\n"
"to not perform transformations to the file being transferred. This is the\n"
"default and is faster than an ASCII transfer.\n",
"binary\n", NULL},
{ _c_blksize, "blksize", C_A_OLONG,
"Change the size of the memory buffer used to read and write data to disks\n"
"to <size> bytes. The default block size is 1024*1024 (1048576) bytes. The\n"
"block size can be increased to improve file transfer performance. This is\n"
"not related to the extended block mode block size used to determine the\n"
"ratio of data to header for data transferred on the data channel.\n",
"blksize [size]\n", NULL},
{ _c_bugs, "bugs", C_A_NOARGS,
"Prints information regarding bug reporting and feature requests.\n",
"bugs\n", NULL},
{ _c_quit, "bye", C_A_RCH_1|C_A_LCH_2|C_A_NOARGS,
"Close all control and data connections and exit.\n",
"bye\n", NULL},
{ _c_cat, "cat", C_A_RCH_1|C_A_STRINGS,
"Print the contents of the remote file(s) to stdout.\n"
"See CAT BEHAVIOUR in uberftp(1) for details about the behaviour of this\n"
"functionality.\n",
"cat file1 [file2 ... filen]\n", NULL},
{ _c_chdir, "cd", C_A_RCH_1|C_A_OSTRING,
"Change the remote working directory to [dir]. If [dir] is not given,\n"
"the client will make every attempt to change to the user's home directory.\n"
"'~' expansion and '-' previous directory are supported.\n",
"cd [dir]\n", NULL},
{ _c_cdup, "cdup", C_A_RCH_1|C_A_NOARGS,
"Change the remote working directory up one level.\n",
"cdup\n", NULL},
{ _c_chgrp, "chgrp", C_A_RCH_1|C_A_OPT_r|C_A_2STRINGPLUS,
"Change group ownership on the remote object(s).\n",
"chgrp [-r] group object [object2 ... objectn]\n",
"-r Recursively chgrp everything in the given directory.\n"},
{ _c_chmod, "chmod", C_A_RCH_1|C_A_OPT_r|C_A_PERMS,
"Change permissions on the remote object(s).\n",
"chmod [-r] perms object [object2 ... objectn]\n",
"-r Recursively chmod everything in the given directory.\n"},
{ _c_cksum, "cksum", C_A_OSTRING,
"Enable file cksum comparison after each file transfer. This only works with\n"
"NCSA's mass storage system.\n",
"cksum [on|off]\n",
"on Enable checksum comparison\n"
"off Disable checksum comparison\n"},
{ _c_cos, "cos", C_A_OSTRING,
"Sets the class of service to [name] on the FTP service if the service\n"
"supports it. If [name] is omitted, the current class of service is printed.\n",
"cos [name]\n", NULL},
{ _c_close, "close", C_A_RCH_1|C_A_NOARGS,
"Close the control connection to the remote host.\n",
"close\n", NULL},
{ _c_dcau, "dcau", C_A_OCH_OSTRING,
"Change the data channel authentication settings. If the service does not\n"
"support DCAU, these settings are ignored.\n",
"dcau [N|A|S <subject>]\n",
"N Disabled dcau.\n"
"A Expect the remote identity to be mine. (Default)\n"
"S <subject> Expect the remote identity to be <subject>.\n"},
{ _c_debug, "debug", C_A_OINT,
"Turn debug statements on/off. If no value is given, this command will\n"
"toggle between debug(2) and non debug(1) mode. Otherwise the debug level\n"
"is set to the given level.\n",
"debug [0-3]\n",
"0 Only errors are printed\n"
"1 Default. Errors and some helpful messages are printed\n"
"2 Print useful control channel information\n"
"3 Print all information\n"},
#ifdef MSSFTP
{ _c_rm, "delete", C_A_RCH_1|C_A_OPT_r|C_A_STRINGS,
"Alias for rm. This command has been deprecated.\n",
"delete [-r] object1 [object1...objectn]\n",
"-r Recursively remove the given directory.\n"},
#endif /* MSSFTP */
{ _c_list, "dir", C_A_RCH_1|C_A_OPT_r|C_A_2OSTRINGS,
"List the contents of the remote target directory. If [target] is not given,\n"
"then the current working directory is used.\n",
"dir [-r] [target [file]]\n",
"-r Recursively list [target].\n"
"target Directory or file to list. '.' is used by default.\n"
"file Write listing to [file].\n"},
#ifdef MSSFTP
{ _c_close, "disconnect", C_A_RCH_1|C_A_NOARGS,
"Alias for close. This command has been deprecated.\n",
"disconnect\n", NULL},
#endif /* MSSFTP */
{ _c_family, "family", C_A_OSTRING,
"Sets the tape family to [name] on the FTP service if the service\n"
"supports it. If [name] is omitted, the current family is printed.\n",
"family [name]\n", NULL},
{ _c_get, "get", C_A_RCH_1|C_A_LCH_2|C_A_OPT_r|C_A_STRINGPLUS,
"Retreive file(s) from the remote service. If <source> implies multiple\n"
"transfers, either through regular expressions or by using the recursive\n"
"feature, then [destination] must be a directory. If [destination] is not\n"
"specified, <source> is used.\n",
"get [-r] <source> [destination]\n",
"-r Recursively transfer the given directory.\n"},
{ _c_glob, "glob", C_A_OSTRING,
"Enable or disable filename globbing. If no option is given, this command\n"
"will toggle the current setting.\n",
"glob [on|off]\n",
"on Enable filename globbing\n"
"off Disable filename globbing\n"},
{ _c_hash, "hash", C_A_NOARGS,
"Print hash marks during data transfers. This does not work during third\n"
"party transfers.\n",
"hash\n", NULL},
{ _c_help, "help", C_A_OSTRING,
"If [command] is given, print a (hopefully) helpful blurb about [command].\n"
"Otherwise, list all commands.\n",
"help [command]\n", NULL},
{ _c_keepalive, "keepalive", C_A_OINT,
"Attempts to keep the control channel from being blocked by firewalls during\n"
"long data channel operations. UberFTP sends a NOOP command to the service\n"
"at intervals equal to the specified number of seconds. Setting it to zero\n"
"will disable keepalive. If seconds are not given, the current timeout is\n"
"displayed. This feature is disabled by default.\n",
"keepalive [seconds]\n",
"seconds number of seconds between NOOPs. Disabled if zero.\n"},
{ _c_cat, "lcat", C_A_LCH_1|C_A_STRINGS,
"Print the contents of the local file(s) to stdout.\n"
"See CAT BEHAVIOUR in uberftp(1) for details about the behaviour of this\n"
"functionality.\n",
"lcat file1 [file2 ... filen]\n", NULL},
{ _c_chdir, "lcd", C_A_LCH_1|C_A_OSTRING,
"Change the local working directory to [dir]. If [dir] is not given,\n"
"the client will make every attempt to change to the user's home directory.\n"
"'~' expansion and '-' previous directory are supported.\n",
"lcd [dir]\n", NULL},
{ _c_cdup, "lcdup", C_A_LCH_1|C_A_NOARGS,
"Change the local working directory up one level.\n",
"lcdup\n", NULL},
{ _c_chgrp, "lchgrp", C_A_LCH_1|C_A_OPT_r|C_A_2STRINGPLUS,
"Change group ownership on the local object(s).\n",
"lchgrp [-r] group object [object2 ... objectn]\n",
"-r Recursively chgrp everything in the given directory.\n"},
{ _c_chmod, "lchmod", C_A_LCH_1|C_A_OPT_r|C_A_PERMS,
"Change permissions on the local object(s).\n",
"lchmod [-r] perms object [object2 ... objectn]\n",
"-r Recursively chmod everything in the given directory.\n"},
#ifndef MSSFTP
{ _c_close, "lclose", C_A_LCH_1|C_A_NOARGS,
"Close the control connection to the local host.\n",
"lclose\n", NULL},
#endif /* !MSSFTP */
#ifdef MSSFTP
{ _c_rm, "ldelete", C_A_LCH_1|C_A_OPT_r|C_A_STRINGS,
"Alias for lrm. This command has been deprecated.\n",
"ldelete [-r] object1 [object1...objectn]\n",
"-r Recursively remove the given directory.\n"},
#endif /* MSSFTP */
{ _c_list, "ldir", C_A_LCH_1|C_A_OPT_r|C_A_2OSTRINGS,
"List the contents of the local target directory. If [target] is not given,\n"
"then the current working directory is used.\n",
"ldir [-r] [target [file]]\n",
"-r Recursively list [target].\n"
"target Directory or file to list. '.' is used by default.\n"
"file Write listing to [file].\n"},
{ _c_link, "link", C_A_RCH_1|C_A_2STRINGS,
"Creates a hardlink to 'oldfile' on the remote service.\n",
"link oldfile newfile\n", NULL},
{ _c_link, "llink", C_A_LCH_1|C_A_2STRINGS,
"Creates a hardlink to 'oldfile' on the local service.\n",
"llink oldfile newfile\n", NULL},
{ _c_list, "lls", C_A_LCH_1|C_A_OPT_r|C_A_2OSTRINGS,
"List the contents of the local target directory. If [target] is not given,\n"
"then the current working directory is used.\n",
"lls [-r] [target [file]]\n",
"-r Recursively list [target].\n"
"target Directory or file to list. '.' is used by default.\n"
"file Write listing to [file].\n"},
{ _c_lscos, "llscos", C_A_LCH_1|C_A_NOARGS,
"List the available COS on the local server (if supported).\n",
"llscos\n", NULL},
{ _c_lsfam, "llsfam", C_A_LCH_1|C_A_NOARGS,
"List the available families on the local server (if supported).\n",
"llsfam\n", NULL},
#ifdef MSSFTP
{ _c_rm, "lmdelete", C_A_LCH_1|C_A_OPT_r|C_A_STRINGS,
"Alias for lrm. This command has been deprecated.\n",
"lmdelete [-r] object1 [object1...objectn]\n",
"-r Recursively remove the given directory.\n"},
#endif /* MSSFTP */
{ _c_mkdir, "lmkdir", C_A_LCH_1|C_A_STRINGS,
"Create the local directory(ies).\n",
"lmkdir dir1 [dir2 ... dirn]\n", NULL},
#ifndef MSSFTP
{ _c_open, "lopen", C_A_LCH_1|C_A_OPT_u|C_A_OPT_p|C_A_OPT_P|C_A_STRING,
"Opens a control channel to <host> and that host becomes the 'local' machine.\n"
"After using lopen, all local (l*) commands perform their respective\n"
"operations on <host> rather than the local machine. This is how third\n"
"party transfers are accomplished. GSI authentication is used unless the\n"
"-p option is used.\n",
"lopen [-P port] [-u user] [-p pass | X] <host>\n",
"-P port Connect to port (Default 2811 for GSI, 21 for password).\n"
"-u user Connect as alternate user.\n"
"-p pass | X\n"
" Use password 'pass' when authenticating with 'host'.\n"
" If 'pass' equals 'X', read the password from STDIN with\n"
" character echoing turned off.\n"
"host Connect to host.\n"},
#endif /* !MSSFTP */
{ _c_pwd, "lpwd", C_A_LCH_1|C_A_NOARGS,
"Prints the current local working directory.\n",
"lpwd\n", NULL},
{ _c_quote, "lquote", C_A_LCH_1|C_A_STRINGS,
"Pass <cmd> to the local FTP service. This allows the user to use\n"
"server-specific commands that are not available through the uberftp\n"
"interface.\n",
"lquote <cmd>\n", NULL},
{ _c_rename, "lrename", C_A_LCH_1|C_A_2STRINGS,
"Rename the local object <src> to <dst>.\n",
"lrename <src> <dst>\n", NULL},
{ _c_rm, "lrm", C_A_LCH_1|C_A_OPT_r|C_A_STRINGS,
"Removes the local file system object(s).\n",
"lrm [-r] object1 [object1...objectn]\n",
"-r Recursively remove the given directory.\n"},
{ _c_rmdir, "lrmdir", C_A_LCH_1|C_A_STRINGS,
"Removes the given directories from the local service.\n",
"lrmdir dir1 [dir2...dirn]\n", NULL},
{ _c_list, "ls", C_A_RCH_1|C_A_OPT_r|C_A_2OSTRINGS,
"List the contents of the remote target directory. If [target] is not given,\n"
"then the current working directory is used.\n",
"ls [-r] [target [file]]\n",
"-r Recursively list [target].\n"
"target Directory or file to list. '.' is used by default.\n"
"file Write listing to [file].\n"},
{ _c_lscos, "lscos", C_A_RCH_1|C_A_NOARGS,
"List the available COS on the remote server (if supported).\n",
"lscos\n", NULL},
{ _c_lsfam, "lsfam", C_A_RCH_1|C_A_NOARGS,
"List the available families on the remote server (if supported).\n",
"lsfam\n", NULL},
{ _c_size, "lsize", C_A_LCH_1|C_A_STRINGS,
"Prints the size of the given object(s).\n",
"lsize file1 [file2...filen]\n", NULL },
{ _c_stage, "lstage", C_A_LCH_1|C_A_OPT_r|C_A_INT_STRINGS,
"Attempt to stage all matching files within the given number of seconds\n"
"on the local service.\n",
"lstage [-r] seconds object1 [object2...objectn]\n",
"seconds number of seconds to attempt staging\n"
"-r Recursively stage all files in the given subdirectory.\n"},
{ _c_symlink, "lsymlink", C_A_LCH_1|C_A_2STRINGS,
"Creates a symlink to 'oldfile' on the local service.\n",
"lsymlink oldfile newfile\n", NULL},
#ifdef MSSFTP
{ _c_rm, "mdelete", C_A_RCH_1|C_A_OPT_r|C_A_STRINGS,
"Alias for rm. This command has been deprecated.\n",
"mdelete [-r] object1 [object1...objectn]\n",
"-r Recursively remove the given directory.\n"},
#endif /* MSSFTP */
{ _c_mget, "mget", C_A_RCH_1|C_A_LCH_2|C_A_OPT_r|C_A_STRINGS,
"Retrieve file(s) from the remote service. This is similiar to making\n"
"multiple calls to get without specifying a destination.\n",
"mget [-r] object1 [object2...objectn]\n",
"-r Recursively transfer the given directory.\n"},
{ _c_mkdir, "mkdir", C_A_RCH_1|C_A_STRINGS,
"Create the remote directory.\n",
"mkdir <dir>\n", NULL},
{ _c_mode, "mode", C_A_OCHAR,
"Toggle the data transfer mode between Streams mode and Extended Block\n"
"mode. The default is Streams mode. If no option is given, it will\n"
"display the current mode.\n",
"mode [E|S]\n",
"E Extended block mode\n"
"S Streams mode\n"},
{ _c_mget, "mput", C_A_LCH_1|C_A_RCH_2|C_A_OPT_r|C_A_STRINGS,
"Store file(s) to the remote service. This is similiar to making\n"
"multiple calls to put without specifying a destination.\n",
"mput [-r] object1 [object2...objectn]\n",
"-r Recursively transfer the given directory.\n"},
#ifndef MSSFTP
{ _c_open, "open", C_A_RCH_1|C_A_OPT_u|C_A_OPT_p|C_A_OPT_P|C_A_STRING,
"Opens a control channel to <host> and that host becomes the 'remote'\n"
"machine. GSI authentication is used unless the -p option is used.\n",
"open [-P port] [-u user] [-p pass | X] <host>\n",
"-P port Connect to port (Default 2811 for GSI, 21 for password).\n"
"-u user Connect as alternate user.\n"
"-p pass | X\n"
" Use password 'pass' when authenticating with 'host'.\n"
" If 'pass' equals 'X', read the password from STDIN with\n"
" character echoing turned off.\n"
"host Connect to host.\n"},
#else /* !MSSFTP */
{ _c_open, "open", C_A_RCH_1|C_A_NOARGS,
"Opens a control channel to MSS and that host becomes the 'remote'\n"
"machine. GSI authentication is used.\n",
"open\n", NULL},
#endif /* !MSSFTP */
{ _c_order, "order", C_A_OSTRING,
"Changes the order of lists returned from ls and lls to the given scheme.\n"
"If <type> is not given, the current order is displayed.\n",
"order <type>\n",
"type Ordering scheme to use. Value options are:\n"
" none Do not order listings\n"
" name Order listings by name\n"
" size Order listings by size\n"
" type Order listings by type\n"},
{ _c_parallel, "parallel", C_A_OINT,
"Set the number of parallel data connections to <number>. This is only\n"
"useful for extended block mode transfers. The default number of data\n"
"connections is one. If no number is given, the current setting for the\n"
"number of parallel connects is printed.\n",
"parallel [number]\n", NULL},
{ _c_passive, "passive", C_A_NOARGS,
"Change to PASSIVE mode which causes the client to initiate the data\n"
"connection. This is the default mode unless the variable\n"
"UBERFTP_ACTIVE_MODE is set in the environment. If you are behind a\n"
"firewall you must use PASSIVE mode.\n",
"passive\n", NULL},
{ _c_pbsz, "pbsz", C_A_OLONG,
"Change the length of the protection buffer. The protection buffer is used\n"
"to encrypt data on the data channel. The length of the protection buffer\n"
"represents the largest encoded message that is allowed on the data channel.\n"
"By default, the protection buffer is grown to match the internal buffer\n"
"used. For efficient transfers, pbsz should be sufficiently larger than\n"
"blksize so that the wrapped buffer fits within the protection buffer.\n"
"Otherwise, the blksize buffer is broken into multiple pieces so that each\n"
"write is less than pbsz when wrapped. If [size] is not given, the current\n"
"size is displayed.\n",
"pbsz [size]\n",
"size length of protection buffer. 0 will set it to its default.\n"},
{ _c_pget, "pget", C_A_RCH_1|C_A_LCH_2|C_A_2OFF,
"Retrieve only the specified portion of the file(s). If srcfile is a regular\n"
"expression and expands to multiple files, and destination is given,\n"
"destination must refer to a directory.\n",
"pget offset size srcfile [destfile]\n",
"offset Offset within the file\n"
"size Amount of data to retrieve\n"
"srcfile Name of remote file\n"
"destfile Name of local file. srcfile is used if destfile\n"
" is not specified\n"},
{ _c_pget, "pput", C_A_LCH_1|C_A_RCH_2|C_A_2OFF,
"Store only the specified portion of the file(s). If srcfile is a regular\n"
"expression and expands to multiple files, and destination is given,\n"
"destination must refer to a directory.\n",
"pput offset size srcfile [destfile]\n",
"offset Offset within the file\n"
"size Amount of data to retrieve\n"
"srcfile Name of remote file\n"
"destfile Name of local file. srcfile is used if destfile\n"
" is not specified\n"},
{ _c_prot, "prot", C_A_OCHAR,
"This command configures the level of security on the data channel after\n"
"data channel authentication has completed. Clear means that the data will\n"
"not be protected. Safe means that the data will be integrity protected\n"
"meaning that altered data will be detected. Confidential means that the data\n"
"will be unreadable to third parties. Private mode means the data will be\n"
"confidential and safe.\n",
"prot [C|S|E|P]\n",
"C Set protection level to clear.\n"
"S Set protection level to safe.\n"
"E Set protection level to confidential.\n"
"P Set protection level to private.\n"},
{ _c_get, "put", C_A_LCH_1|C_A_RCH_2|C_A_OPT_r|C_A_STRINGPLUS,
"Store file(s) to the remote service. If <source> implies multiple\n"
"transfers, either through regular expressions or by using the recursive\n"
"feature, then [destination] must be a directory. If [destination] is not\n"
"specified, <source> is used.\n",
"put [-r] <source> [destination]\n",
"-r Recursively transfer the given directory.\n"},
{ _c_pwd, "pwd", C_A_RCH_1|C_A_NOARGS,
"Prints the current working directory.\n",
"pwd\n", NULL},
{ _c_quit, "quit", C_A_RCH_1|C_A_LCH_2|C_A_NOARGS,
"Close all control and data connections and exit.\n",
"quit\n", NULL},
{ _c_quote, "quote", C_A_RCH_1|C_A_STRINGS,
"Pass <cmd> to the remote FTP service. This allows the user to use\n"
"server-specific commands that are not available through the uberftp\n"
"interface.\n",
"quote <cmd>\n", NULL},
#ifdef MSSFTP
{ _c_get, "recv", C_A_RCH_1|C_A_LCH_2|C_A_OPT_r|C_A_STRINGPLUS,
"Alias for get. This command has been deprecated.\n",
"recv [-r] <source> [destination]\n",
"-r Recursively transfer the given directory.\n"},
#endif /* MSSFTP */
{ _c_rename, "rename", C_A_RCH_1|C_A_2STRINGS,
"Rename the remote object <src> to <dst>.\n",
"rename <src> <dst>\n", NULL},
{ _c_resume, "resume", C_A_OPT_d|C_A_OSTRING,
"Sets a restart point for recursive transfers. If a long recursive transfer\n"
"fails, you can set resume to the path that failed and UberFTP will skip\n"
"all file and directory creations up to the given path.\n",
"resume [-d] [path]\n",
"path Path to resume transfer at. If path is not given, print the current\n"
" resume target.\n"
"-d Remove the current resume path.\n"},
{ _c_retry, "retry", C_A_OINT,
"Configures retry on failed commands that have transient errors. cnt\n"
"represents the number of times a failed command is retried. A value of\n"
"zero effectively disables retry. Zero is the default. If no value is given\n"
"the current setting is displayed.\n",
"retry [cnt]\n",
"cnt Number of times a failed command is retried.\n"},
{ _c_rm, "rm", C_A_RCH_1|C_A_OPT_r|C_A_STRINGS,
"Removes the remote file system object(s).\n",
"rm [-r] object1 [object1...objectn]\n",
"-r Recursively remove the given directory.\n"},
{ _c_rmdir, "rmdir", C_A_RCH_1|C_A_STRINGS,
"Removes the given directories from the remote service.\n",
"rmdir dir1 [dir2...dirn]\n", NULL},
{ _c_runique, "runique", C_A_NOARGS,
"Toggles the client to store files using unique names during get operations.\n",
"runique\n", NULL},
#ifdef MSSFTP
{ _c_get, "send", C_A_LCH_1|C_A_RCH_2|C_A_OPT_r|C_A_STRINGPLUS,
"Alias for put. This command has been deprecated.\n",
"send [-r] <source> [destination]\n",
"-r Recursively transfer the given directory.\n"},
#endif /* MSSFTP */
{ _c_size, "size", C_A_RCH_1|C_A_STRINGS,
"Prints the size of the given object(s).\n",
"size file1 [file2...filen]\n", NULL },
{ _c_stage, "stage", C_A_RCH_1|C_A_OPT_r|C_A_INT_STRINGS,
"Attempt to stage all matching files within the given number of seconds\n"
"on the remote service.\n",
"stage [-r] seconds object1 [object2...objectn]\n",
"seconds number of seconds to attempt staging\n"
"-r Recursively stage all files in the given subdirectory.\n"},
{ _c_sunique, "sunique", C_A_NOARGS,
"Toggles the client to store files using unique names during put operations.\n",
"sunique\n", NULL},
{ _c_symlink, "symlink", C_A_RCH_1|C_A_2STRINGS,
"Creates a symlink to 'oldfile' on the remote service.\n",
"symlink oldfile newfile\n", NULL},
{ _c_tcpbuf, "tcpbuf", C_A_OLONG,
"Set the data channel TCP buffer size to [size] bytes. If [size] is not\n"
"given, the current TCP buffer size will be printed.\n",
"tcpbuf [size]\n", NULL},
#ifdef MSSFTP
{ _c_type, "type", C_A_OSTRING,
"Sets the transfer type. If no type is given, it reports the current type.\n",
"type [ascii|binary]\n", NULL},
{ _c_debug, "verbose", C_A_OINT,
"Alias for debug. This command has been deprecated.\n",
"verbose [0-3]\n",
"0 Only errors are printed\n"
"1 Default. Errors and some helpful messages are printed\n"
"2 Print useful control channel information\n"
"3 Print all information\n"},
#endif /* MSSFTP */
{ _c_versions, "versions", C_A_NOARGS,
"Prints the versions of all Globus modules being used.\n",
"versions\n", NULL},
{ _c_wait, "wait", C_A_NOARGS,
"Toggles whether the client should wait for files to stage before attempting\n"
"to retrieve them.\n",
"wait\n", NULL},
{ NULL, NULL}
};
void
cmd_init()
{
glch.lh = l_init(UnixInterface); /* Local connection handle. */
grch.lh = l_init(NcInterface); /* Remote connection handle. */
}
cmdret_t
cmd_intrptr(char * cmd)
{
cmdret_t cr = CMD_SUCCESS;
char * token = NULL;
char * nxttok = NULL;
char * sc = NULL;
char * buf = NULL;
buf = cmd = Strdup(cmd);
for (; cmd && *cmd && cr == CMD_SUCCESS; cmd = (sc ? sc+1 : NULL))
{
sc = StrchrEsc(cmd, ";,");
if (sc)
*sc = '\0';
nxttok = cmd;
do
{
token = StrtokEsc(nxttok, ' ', &nxttok);
cmd = NULL;
cr = _c_lex(token);
} while (token && cr == CMD_SUCCESS);
}
FREE(buf);
return cr;
}
static cmdret_t
_c_lex(char * token)
{
static int state = C_A_CMD;
static int dflag = 0;
static int rflag = 0;
static int rparg = 0;
static int rParg = 0;
static int ruarg = 0;
static cmd_t * cmd = NULL;
static char * parg = NULL;
static char * uarg = NULL;
static char ** strs = NULL;
static char * str = NULL;
static char chr;
static int perms = 0;
static int Parg = -1;
static int scnt = 0;
static int ival = -1;
static globus_off_t lval1 = -1;
static globus_off_t lval2 = -1;
cmdret_t cr = CMD_SUCCESS;
if ((ruarg || rParg || rparg) && !token)
{
fprintf(stderr, "Illegal syntax.\n");
goto error;
}
if (ruarg)
{
ruarg = 0;
uarg = Strdup(token);
return CMD_SUCCESS;
}
if (rparg)
{
rparg = 0;
parg = Strdup(token);
return CMD_SUCCESS;
}
if (rParg)
{
if (!IsInt(token))
{
fprintf(stderr, "%s must be an integer.\n", token);
goto error;
}
rParg = 0;
Parg = strtol(token, NULL, 0);
return CMD_SUCCESS;
}
if (!token)
{
switch (state & ~C_A_OPT_MASK)
{
case C_A_CMD:
return CMD_SUCCESS;
case C_A_OCH_OSTRING:
case C_A_OCHAR:
case C_A_NOARGS:
case C_A_OINT:
case C_A_OLONG:
case C_A_OSTRINGS:
case C_A_OSTRING:
case C_A_2OSTRINGS:
switch(cmd->ctype)
{
case C_A_NOARGS:
cr = ((cmdret_t (*)())cmd->func)();
break;
case C_A_OINT:
cr = ((cmdret_t (*)(int))cmd->func)(ival);
break;
case C_A_OLONG:
cr = ((cmdret_t (*)(long long))cmd->func)(lval1);
break;
case C_A_OPT_d|C_A_OSTRING:
cr = ((cmdret_t (*)(int, char *))cmd->func)(dflag,
strs?strs[0]:NULL);
break;
case C_A_STRING:
cr = ((cmdret_t (*)(char*))cmd->func)(strs[0]);
break;
case C_A_OSTRING:
cr = ((cmdret_t (*)(char*))cmd->func)(strs?strs[0]:NULL);
break;
case C_A_OCHAR:
cr = ((cmdret_t (*)(char))cmd->func)(chr);
break;
case C_A_OCH_OSTRING:
cr = ((cmdret_t (*)(char, char *))cmd->func)
(chr, strs?strs[0]:NULL);
break;
case C_A_OSTRINGS:
cr = ((cmdret_t (*)(char**))cmd->func)(strs);
break;
case C_A_RCH_1|C_A_NOARGS:
cr = ((cmdret_t (*)(ch_t*))cmd->func)(&grch);
break;
case C_A_RCH_1|C_A_STRING:
cr = ((cmdret_t (*)(ch_t*,char*))cmd->func)(&grch,strs[0]);
break;
case C_A_RCH_1|C_A_OSTRING:
cr = ((cmdret_t (*)(ch_t*,char*))cmd->func)
(&grch,strs?strs[0]:NULL);
break;
case C_A_RCH_1|C_A_STRINGS:
cr = ((cmdret_t (*)(ch_t*,char**))cmd->func)(&grch,strs);
break;
case C_A_RCH_1|C_A_2STRINGS:
cr = ((cmdret_t (*)(ch_t*,char*,char*))cmd->func)
(&grch,strs[0],strs[1]);
break;
case C_A_RCH_1|C_A_OPT_r|C_A_STRINGS:
cr = ((cmdret_t (*)(ch_t*,int,char**))cmd->func)
(&grch,rflag,strs);
break;
case C_A_RCH_1|C_A_OPT_r|C_A_2STRINGPLUS:
cr = ((cmdret_t (*)(ch_t*,int,char*,char**))cmd->func)
(&grch,rflag,str,strs);
break;
case C_A_RCH_1|C_A_OPT_r|C_A_PERMS:
cr = ((cmdret_t (*)(ch_t*,int,int,char**))cmd->func)
(&grch,rflag,perms,strs);
break;
case C_A_RCH_1|C_A_OPT_r|C_A_INT_STRINGS:
cr = ((cmdret_t (*)(ch_t*,int,int,char**))cmd->func)
(&grch,rflag,ival,strs);
break;
case C_A_RCH_1|C_A_OPT_r|C_A_OSTRING:
cr = ((cmdret_t (*)(ch_t*,int,char*))cmd->func)
(&grch,rflag,strs?strs[0]:NULL);
break;
case C_A_RCH_1|C_A_OPT_r|C_A_2OSTRINGS:
cr = ((cmdret_t (*)(ch_t*,int,char*,char*))cmd->func)
(&grch,rflag,strs?strs[0]:NULL,strs?strs[1]:NULL);
break;
case C_A_RCH_1|C_A_OPT_u|C_A_OPT_p|C_A_OPT_P|C_A_STRING:
cr = ((cmdret_t (*)(ch_t*,char*,char*,char*,int))cmd->func)
(&grch,uarg,parg,strs[0],Parg);
break;
case C_A_LCH_1|C_A_NOARGS:
cr = ((cmdret_t (*)(ch_t*))cmd->func)(&glch);
break;
case C_A_LCH_1|C_A_OSTRING:
cr = ((cmdret_t (*)(ch_t*,char*))cmd->func)
(&glch,strs?strs[0]:NULL);
break;
case C_A_LCH_1|C_A_STRINGS:
cr = ((cmdret_t (*)(ch_t*,char**))cmd->func)(&glch,strs);
break;
case C_A_LCH_1|C_A_2STRINGS:
cr = ((cmdret_t (*)(ch_t*,char*,char*))cmd->func)
(&glch,strs[0],strs[1]);
break;