This repository has been archived by the owner on Apr 20, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
settings.c
501 lines (435 loc) · 7.22 KB
/
settings.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
/*
* University of Illinois/NCSA Open Source License
*
* Copyright © 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 <stdlib.h>
#include <stdio.h>
#include "settings.h"
#include "output.h"
#include "config.h"
#include "misc.h"
#ifdef DMALLOC
#include "dmalloc.h"
#endif /* DMALLOC */
/* These are the defaults. */
static int binary = 1;
static int cksum = 0;
static int dcau = 1; /* 0 none, 1 self, 2 subject */
static int debug = DEBUG_ERRS_ONLY;
static int debug_set = 0;
static int hash = 0;
static int globon = 1;
static int keepalive = 0;
static unsigned short min_port = 0; /* TCP_PORT_RANGE min */
static unsigned short max_port = 0; /* TCP_PORT_RANGE max */
static unsigned short min_src = 0; /* TCP_SOURCE_RANGE min */
static unsigned short max_src = 0; /* TCP_SOURCE_RANGE max */
static int order = ORDER_BY_NONE;
static int parallel = 1;
static int prot = 0; /* 0 clear, 1 safe, 2 confidential, 3 private */
static int retry = 0;
static int runique = 0;
static int stream = 1;
static int sunique = 0;
static int waiton = 0;
static long long pbsz = 0; /* Default, determined on the fly */
static long long tcpbuf = DEFAULT_TCP_BUFFER_SIZE;
static long long blocksize = DEFAULT_BLKSIZE;
static char * dcau_subject = NULL;
static char * cos = NULL;
static char * family = NULL;
static char * resume = NULL;
#ifdef MSSFTP
static int passive = 0;
#else /* MSSFTP */
static int passive = 1;
#endif /* MSSFTP */
void
s_init()
{
int rv = 0;
char * cval = NULL;
unsigned short min = 0;
unsigned short max = 0;
if (getenv("UBERFTP_ACTIVE_MODE"))
passive = 0;
/* GLOBUS_TCP_PORT_RANGE for backwards compatibility */
cval = getenv("GLOBUS_TCP_PORT_RANGE");
if (cval)
{
rv = sscanf(cval, "%hu,%hu", &min, &max);
if (rv != 2)
rv = sscanf(cval, "%hu %hu", &min, &max);
if (rv == 2 && min <= max)
{
min_port = min;
max_port = max;
}
}
/* UBERFTP_TCP_PORT_RANGE for forwards compatibility */
/* Overrides GLOBUS_* */
cval = getenv("UBERFTP_TCP_PORT_RANGE");
if (cval)
{
rv = sscanf(cval, "%hu,%hu", &min, &max);
if (rv != 2)
rv = sscanf(cval, "%hu %hu", &min, &max);
if (rv == 2 && min <= max)
{
min_port = min;
max_port = max;
}
}
/* GLOBUS_TCP_SOURCE_RANGE for backwards compatibility */
cval = getenv("GLOBUS_TCP_SOURCE_RANGE");
if (cval)
{
rv = sscanf(cval, "%hu,%hu", &min, &max);
if (rv != 2)
rv = sscanf(cval, "%hu %hu", &min, &max);
if (rv == 2 && min <= max)
{
min_src = min;
max_src = max;
}
}
/* UBERFTP_TCP_SOURCE_RANGE for forwards compatibility */
/* Overrides GLOBUS_* */
cval = getenv("UBERFTP_TCP_SOURCE_RANGE");
if (cval)
{
rv = sscanf(cval, "%hu,%hu", &min, &max);
if (rv != 2)
rv = sscanf(cval, "%hu %hu", &min, &max);
if (rv == 2 && min <= max)
{
min_src = min;
max_src = max;
}
}
}
void
s_setactive()
{
passive = 0;
}
void
s_setascii()
{
binary = 0;
}
void
s_setbinary()
{
binary = 1;
}
void
s_setblocksize(long long size)
{
blocksize = size;
if (size == 0)
blocksize = DEFAULT_BLKSIZE;
}
void
s_setcksum(int on)
{
cksum = on ? 1 : 0;
}
void
s_setcos(char * Cos)
{
FREE(cos);
if (strcasecmp(Cos, "default") != 0)
cos = Strdup(Cos);
}
void
s_setdcau(int lvl, char * subject)
{
dcau = lvl;
if (dcau_subject)
FREE(dcau_subject);
dcau_subject = Strdup(subject);
}
void
s_setdebug(int lvl)
{
if (lvl < DEBUG_MIN)
debug = DEBUG_MIN;
else if (lvl > DEBUG_MAX)
debug = DEBUG_MAX;
else
debug = lvl;
debug_set = 1;
}
void
s_setglob(int on)
{
globon = on;
}
void
s_setfamily(char * fam)
{
FREE(family);
if (strcasecmp(fam, "default") != 0)
family = Strdup(fam);
}
void
s_seteb()
{
stream = 0;
}
void
s_sethash()
{
hash = !hash;
}
void
s_setkeepalive(int seconds)
{
keepalive = seconds;
}
void
s_setorder(int o)
{
order = o;
}
void
s_setparallel(int cnt)
{
parallel = cnt;
if (parallel < 1)
parallel = 1;
}
void
s_setpbsz(long long length)
{
pbsz = length;
if (pbsz == 0)
pbsz = 0;
}
void
s_setpassive()
{
passive = 1;
}
void
s_setprot(int lvl)
{
prot = lvl;
}
void
s_setretry(int cnt)
{
retry = cnt;
if (retry < 0)
retry = 0;
}
void
s_setresume(char * path)
{
FREE(resume);
resume = Strdup(path);
}
void
s_setrunique()
{
runique = !runique;
}
void
s_setstream()
{
stream = 1;
}
void
s_setsunique()
{
sunique = !sunique;
}
void
s_settcpbuf(long long size)
{
tcpbuf = size;
if (size == 0)
tcpbuf = 0;
}
void
s_setwait()
{
waiton = !waiton;
}
int
s_ascii()
{
return !binary;
}
long long
s_blocksize()
{
return blocksize;
}
int
s_cksum()
{
return cksum;
}
char *
s_cos()
{
return cos;
}
int
s_dcau()
{
return dcau;
}
char *
s_dcau_subject()
{
return Strdup(dcau_subject);
}
int
s_debug()
{
return debug;
}
int
s_debug_set()
{
return debug_set;
}
int
s_glob()
{
return globon;
}
char *
s_family()
{
return family;
}
int
s_hash()
{
return hash;
}
int
s_keepalive()
{
return keepalive;
}
unsigned short
s_maxsrc(void)
{
return max_src;
}
unsigned short
s_maxport(void)
{
return max_port;
}
unsigned short
s_minsrc(void)
{
return min_src;
}
unsigned short
s_minport(void)
{
return min_port;
}
int
s_order()
{
return order;
}
int
s_parallel()
{
return parallel;
}
long long
s_pbsz()
{
return pbsz;
}
int
s_passive()
{
return passive;
}
int
s_prot()
{
return prot;
}
int
s_retry()
{
return retry;
}
char *
s_resume()
{
return resume;
}
int
s_runique()
{
return runique;
}
int
s_stream()
{
return stream;
}
int
s_sunique()
{
return sunique;
}
long long
s_tcpbuf()
{
return tcpbuf;
}
int
s_wait()
{
return waiton;
}