/
mod_core.c
7239 lines (5731 loc) · 201 KB
/
mod_core.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
/*
* ProFTPD - FTP server daemon
* Copyright (c) 1997, 1998 Public Flood Software
* Copyright (c) 1999, 2000 MacGyver aka Habeeb J. Dihu <macgyver@tos.net>
* Copyright (c) 2001-2021 The ProFTPD Project team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
*
* As a special exemption, Public Flood Software/MacGyver aka Habeeb J. Dihu
* and other respective copyright holders give permission to link this program
* with OpenSSL, and distribute the resulting executable, without including
* the source code for OpenSSL in the source distribution.
*/
/* Core FTPD module */
#include "conf.h"
#include "privs.h"
#include "error.h"
#include <ctype.h>
extern module *loaded_modules;
extern module site_module;
extern xaset_t *server_list;
/* From src/main.c */
extern unsigned long max_connects;
extern unsigned int max_connect_interval;
/* From modules/mod_site.c */
extern modret_t *site_dispatch(cmd_rec*);
/* For bytes-retrieving directives */
#define PR_BYTES_BAD_UNITS -1
#define PR_BYTES_BAD_FORMAT -2
/* Maximum number of parameters for OPTS commands (see Bug#3870). */
#define PR_OPTS_MAX_PARAM_COUNT 8
module core_module;
char AddressCollisionCheck = TRUE;
static int core_scrub_timer_id = -1;
static pr_fh_t *displayquit_fh = NULL;
#ifdef PR_USE_TRACE
static const char *trace_log = NULL;
#endif /* PR_USE_TRACE */
/* Necessary prototypes. */
static void core_exit_ev(const void *, void *);
static int core_sess_init(void);
static void reset_server_auth_order(void);
/* These are for handling any configured MaxCommandRate. */
static unsigned long core_cmd_count = 0UL;
static unsigned long core_max_cmds = 0UL;
static unsigned int core_max_cmd_interval = 1;
static time_t core_max_cmd_ts = 0;
static unsigned long core_exceeded_cmd_rate(cmd_rec *cmd) {
unsigned long res = 0;
long over = 0;
time_t now;
if (core_max_cmds == 0) {
return 0;
}
core_cmd_count++;
over = core_cmd_count - core_max_cmds;
if (over > 0) {
/* Determine the delay, in ms.
*
* The value for this delay must be a value which will cause the command
* rate to not be exceeded. For example, if the config is:
*
* MaxCommandRate 200 1
*
* it means a maximum of 200 commands a sec. This works out to a command
* every 5 ms, maximum:
*
* 1 sec * 1000 ms / 200 cmds per sec = 5 ms
*
* That 5 ms, then, would be the delay to use. For each command over the
* maximum number of commands per interval, we add this delay factor.
* This means that the more over the limit the session is, the longer the
* delay.
*/
res = (unsigned long) (((core_max_cmd_interval * 1000) / core_max_cmds) * over);
}
now = time(NULL);
if (core_max_cmd_ts > 0) {
if ((now - core_max_cmd_ts) > core_max_cmd_interval) {
/* If it's been longer than the MaxCommandRate interval, reset the
* command counter.
*/
core_cmd_count = 0;
core_max_cmd_ts = now;
}
} else {
core_max_cmd_ts = now;
}
return res;
}
static int core_idle_timeout_cb(CALLBACK_FRAME) {
int timeout;
timeout = pr_data_get_timeout(PR_DATA_TIMEOUT_IDLE);
/* We don't want to quit in the middle of a transfer */
if (session.sf_flags & SF_XFER) {
pr_trace_msg("timer", 4,
"TimeoutIdle (%d %s) reached, but data transfer in progress, ignoring",
timeout, timeout != 1 ? "seconds" : "second");
/* Restart the timer. */
return 1;
}
pr_event_generate("core.timeout-idle", NULL);
pr_response_send_async(R_421,
_("Idle timeout (%d seconds): closing control connection"), timeout);
pr_timer_remove(PR_TIMER_LOGIN, ANY_MODULE);
pr_timer_remove(PR_TIMER_NOXFER, ANY_MODULE);
pr_log_pri(PR_LOG_INFO, "%s", "Client session idle timeout, disconnected");
pr_session_disconnect(&core_module, PR_SESS_DISCONNECT_TIMEOUT,
"TimeoutIdle");
return 0;
}
/* If the environment variable being set/unset is locale-related, then we need
* to call setlocale(3) again.
*
* Note: We deliberately set LC_NUMERIC to "C", regardless of configuration.
* Failure to do so will cause problems with formatting of e.g. floats in
* SQL query strings.
*/
static void core_handle_locale_env(const char *env_name) {
#if defined(PR_USE_NLS) && defined(HAVE_LOCALE_H)
register unsigned int i;
const char *locale_envs[] = {
"LC_ALL",
"LC_COLLATE",
"LC_CTYPE",
"LC_MESSAGES",
"LC_MONETARY",
"LC_NUMERIC",
"LC_TIME",
"LANG",
NULL
};
for (i = 0; locale_envs[i] != NULL; i++) {
if (strcmp(env_name, locale_envs[i]) == 0) {
if (setlocale(LC_ALL, "") != NULL) {
setlocale(LC_NUMERIC, "C");
}
}
}
#endif /* PR_USE_NLS and HAVE_LOCALE_H */
}
static int core_scrub_scoreboard_cb(CALLBACK_FRAME) {
/* Always return 1 when leaving this function, to make sure the timer
* gets called again.
*/
pr_scoreboard_scrub();
return 1;
}
MODRET start_ifdefine(cmd_rec *cmd) {
unsigned int ifdefine_ctx_count = 1;
unsigned char not_define = FALSE, defined = FALSE;
char buf[PR_TUNABLE_BUFFER_SIZE] = {'\0'}, *config_line = NULL, *ptr;
CHECK_ARGS(cmd, 1);
ptr = cmd->argv[1];
if (*ptr == '!') {
not_define = TRUE;
ptr++;
}
defined = pr_define_exists(ptr);
/* Return now if we don't need to consume the <IfDefine> section
* configuration lines.
*/
if ((!not_define && defined) ||
(not_define && !defined)) {
pr_log_debug(DEBUG3, "%s: using '%s%s' section at line %u",
(char *) cmd->argv[0], not_define ? "!" : "", (char *) cmd->argv[1],
pr_parser_get_lineno());
return PR_HANDLED(cmd);
}
pr_log_debug(DEBUG3, "%s: skipping '%s%s' section at line %u",
(char *) cmd->argv[0], not_define ? "!" : "", (char *) cmd->argv[1],
pr_parser_get_lineno());
/* Rather than communicating with parse_config_file() via some global
* variable/flag the need to skip configuration lines, if the requested
* module condition is not TRUE, read in the lines here (effectively
* preventing them from being parsed) up to and including the closing
* directive.
*/
while (ifdefine_ctx_count && (config_line = pr_parser_read_line(buf,
sizeof(buf))) != NULL) {
if (strncasecmp(config_line, "<IfDefine", 9) == 0) {
ifdefine_ctx_count++;
} else if (strcasecmp(config_line, "</IfDefine>") == 0) {
ifdefine_ctx_count--;
}
}
/* If there are still unclosed <IfDefine> sections, signal an error.
*/
if (ifdefine_ctx_count) {
CONF_ERROR(cmd, "unclosed <IfDefine> context");
}
return PR_HANDLED(cmd);
}
/* As with Apache, there is no way of cleanly checking whether an
* <IfDefine> section is properly closed. Extra </IfDefine> directives
* will be silently ignored.
*/
MODRET end_ifdefine(cmd_rec *cmd) {
return PR_HANDLED(cmd);
}
MODRET start_ifmodule(cmd_rec *cmd) {
unsigned int ifmodule_ctx_count = 1;
unsigned char not_module = FALSE, found_module = FALSE;
char buf[PR_TUNABLE_BUFFER_SIZE] = {'\0'}, *config_line = NULL, *ptr;
CHECK_ARGS(cmd, 1);
ptr = cmd->argv[1];
if (*ptr == '!') {
not_module = TRUE;
ptr++;
}
found_module = pr_module_exists(ptr);
/* Return now if we don't need to consume the <IfModule> section
* configuration lines.
*/
if ((!not_module && found_module) ||
(not_module && !found_module)) {
pr_log_debug(DEBUG3, "%s: using '%s%s' section at line %u",
(char *) cmd->argv[0], not_module ? "!" : "", (char *) cmd->argv[1],
pr_parser_get_lineno());
return PR_HANDLED(cmd);
}
pr_log_debug(DEBUG3, "%s: skipping '%s%s' section at line %u",
(char *) cmd->argv[0], not_module ? "!" : "", (char *) cmd->argv[1],
pr_parser_get_lineno());
/* Rather than communicating with parse_config_file() via some global
* variable/flag the need to skip configuration lines, if the requested
* module condition is not TRUE, read in the lines here (effectively
* preventing them from being parsed) up to and including the closing
* directive.
*/
while (ifmodule_ctx_count && (config_line = pr_parser_read_line(buf,
sizeof(buf))) != NULL) {
char *bufp;
pr_signals_handle();
/* Advance past any leading whitespace. */
for (bufp = config_line; *bufp && PR_ISSPACE(*bufp); bufp++) {
}
if (strncasecmp(bufp, "<IfModule", 9) == 0) {
ifmodule_ctx_count++;
} else if (strcasecmp(bufp, "</IfModule>") == 0) {
ifmodule_ctx_count--;
}
}
/* If there are still unclosed <IfModule> sections, signal an error. */
if (ifmodule_ctx_count) {
CONF_ERROR(cmd, "unclosed <IfModule> context");
}
return PR_HANDLED(cmd);
}
/* As with Apache, there is no way of cleanly checking whether an
* <IfModule> section is properly closed. Extra </IfModule> directives
* will be silently ignored.
*/
MODRET end_ifmodule(cmd_rec *cmd) {
return PR_HANDLED(cmd);
}
/* Syntax: Define parameter
*
* Configuration file equivalent of the -D command-line option for
* specifying an <IfDefine> value.
*
* It is suggested the RLimitMemory (a good idea to use anyway) be
* used if this directive is present, to prevent Defines was being
* used by a malicious local user in a .ftpaccess file.
*/
MODRET set_define(cmd_rec *cmd) {
/* Make sure there's at least one parameter; any others are ignored */
CHECK_ARGS(cmd, 1);
/* This directive can occur in any context, so no need for the
* CHECK_CONF macro.
*/
pr_define_add(cmd->argv[1], FALSE);
return PR_HANDLED(cmd);
}
/* usage: Include path|pattern */
MODRET set_include(cmd_rec *cmd) {
int allowed_ctxs, parent_ctx, res, xerrno;
CHECK_ARGS(cmd, 1);
/* If we are not currently in a .ftpaccess context, then we allow Include
* in a <Limit> section. Otherwise, a .ftpaccess file could contain a
* <Limit>, and that <Limit> could include e.g. itself, leading to a loop.
*/
allowed_ctxs = CONF_ROOT|CONF_VIRTUAL|CONF_ANON|CONF_GLOBAL|CONF_DIR;
parent_ctx = CONF_ROOT;
if (cmd->config != NULL &&
cmd->config->parent != NULL) {
parent_ctx = cmd->config->parent->config_type;
}
if (parent_ctx != CONF_DYNDIR) {
allowed_ctxs |= CONF_LIMIT;
}
CHECK_CONF(cmd, allowed_ctxs);
/* Make sure the given path is a valid path. */
PRIVS_ROOT
res = pr_fs_valid_path(cmd->argv[1]);
PRIVS_RELINQUISH
if (res < 0) {
CONF_ERROR(cmd, pstrcat(cmd->tmp_pool,
"unable to use path for configuration file '", cmd->argv[1], "'", NULL));
}
PRIVS_ROOT
res = parse_config_path(cmd->tmp_pool, cmd->argv[1]);
xerrno = errno;
PRIVS_RELINQUISH
if (res < 0) {
if (xerrno != EINVAL) {
pr_log_pri(PR_LOG_WARNING, "warning: unable to include '%s': %s",
(char *) cmd->argv[1], strerror(xerrno));
} else {
CONF_ERROR(cmd, pstrcat(cmd->tmp_pool, "error including '",
(char *) cmd->argv[1], "': ", strerror(xerrno), NULL));
}
}
return PR_HANDLED(cmd);
}
/* usage: IncludeOptions opt1 ... */
MODRET set_includeoptions(cmd_rec *cmd) {
register unsigned int i;
unsigned long opts = 0UL;
if (cmd->argc-1 == 0) {
CONF_ERROR(cmd, "wrong number of parameters");
}
CHECK_CONF(cmd, CONF_ROOT);
for (i = 1; i < cmd->argc; i++) {
if (strcmp(cmd->argv[i], "AllowSymlinks") == 0) {
opts |= PR_PARSER_INCLUDE_OPT_ALLOW_SYMLINKS;
} else if (strcmp(cmd->argv[i], "IgnoreTempFiles") == 0) {
opts |= PR_PARSER_INCLUDE_OPT_IGNORE_TMP_FILES;
} else if (strcmp(cmd->argv[i], "IgnoreWildcards") == 0) {
opts |= PR_PARSER_INCLUDE_OPT_IGNORE_WILDCARDS;
} else {
CONF_ERROR(cmd, pstrcat(cmd->tmp_pool, "unknown IncludeOption '",
cmd->argv[i], "'", NULL));
}
}
(void) pr_parser_set_include_opts(opts);
return PR_HANDLED(cmd);
}
MODRET set_debuglevel(cmd_rec *cmd) {
config_rec *c = NULL;
int debuglevel = -1;
char *endp = NULL;
CHECK_ARGS(cmd, 1);
CHECK_CONF(cmd, CONF_ROOT|CONF_VIRTUAL|CONF_GLOBAL);
/* Make sure the parameter is a valid number. */
debuglevel = strtol(cmd->argv[1], &endp, 10);
if (endp && *endp)
CONF_ERROR(cmd, "not a valid number");
/* Make sure the number is within the valid debug level range. */
if (debuglevel < 0 || debuglevel > 10)
CONF_ERROR(cmd, "invalid debug level configured");
c = add_config_param(cmd->argv[0], 1, NULL);
c->argv[0] = pcalloc(c->pool, sizeof(int));
*((int *) c->argv[0]) = debuglevel;
return PR_HANDLED(cmd);
}
MODRET set_defaultaddress(cmd_rec *cmd) {
const char *name, *main_ipstr;
const pr_netaddr_t *main_addr = NULL;
array_header *addrs = NULL;
unsigned int addr_flags = PR_NETADDR_GET_ADDR_FL_INCL_DEVICE;
if (cmd->argc-1 < 1) {
CONF_ERROR(cmd, "wrong number of parameters");
}
CHECK_CONF(cmd, CONF_ROOT);
name = cmd->argv[1];
main_addr = pr_netaddr_get_addr2(main_server->pool, name, &addrs, addr_flags);
if (main_addr == NULL) {
CONF_ERROR(cmd, pstrcat(cmd->tmp_pool, "unable to resolve '", name, "'",
NULL));
}
/* If the given name is a DNS name, automatically add a ServerAlias
* directive.
*/
if (pr_netaddr_is_v4(name) == FALSE &&
pr_netaddr_is_v6(name) == FALSE) {
add_config_param_str("ServerAlias", 1, name);
}
main_server->ServerAddress = main_ipstr = pr_netaddr_get_ipstr(main_addr);
main_server->addr = main_addr;
if (addrs != NULL) {
register unsigned int i;
pr_netaddr_t **elts = addrs->elts;
/* For every additional address, implicitly add a bind record. */
for (i = 0; i < addrs->nelts; i++) {
const char *ipstr;
ipstr = pr_netaddr_get_ipstr(elts[i]);
/* Skip duplicate addresses. */
if (strcmp(main_ipstr, ipstr) == 0) {
continue;
}
#if defined(PR_USE_IPV6)
if (pr_netaddr_use_ipv6()) {
char *ipbuf;
ipbuf = pcalloc(cmd->tmp_pool, INET6_ADDRSTRLEN + 1);
if (pr_netaddr_get_family(elts[i]) == AF_INET) {
/* Create the bind record using the IPv4-mapped IPv6 version of
* this address.
*/
pr_snprintf(ipbuf, INET6_ADDRSTRLEN, "::ffff:%s", ipstr);
ipstr = ipbuf;
}
}
#endif /* PR_USE_IPV6 */
add_config_param_str("_bind_", 1, ipstr);
}
}
/* Handle multiple addresses in a DefaultAddress directive. We do
* this by adding bind directives to the server_rec created for the
* first address.
*/
if (cmd->argc-1 > 1) {
register unsigned int i;
char *addrs_str = (char *) pr_netaddr_get_ipstr(main_addr);
for (i = 2; i < cmd->argc; i++) {
const char *addr_ipstr;
const pr_netaddr_t *addr;
addrs = NULL;
addr = pr_netaddr_get_addr2(cmd->tmp_pool, cmd->argv[i], &addrs,
addr_flags|PR_NETADDR_GET_ADDR_FL_EXCL_CACHE);
if (addr == NULL) {
CONF_ERROR(cmd, pstrcat(cmd->tmp_pool, "error resolving '",
cmd->argv[i], "': ", strerror(errno), NULL));
}
addr_ipstr = pr_netaddr_get_ipstr(addr);
add_config_param_str("_bind_", 1, addr_ipstr);
/* If the given name is a DNS name, automatically add a ServerAlias
* directive.
*/
if (pr_netaddr_is_v4(cmd->argv[i]) == FALSE &&
pr_netaddr_is_v6(cmd->argv[i]) == FALSE) {
add_config_param_str("ServerAlias", 1, cmd->argv[i]);
}
addrs_str = pstrcat(cmd->tmp_pool, addrs_str, ", ", addr_ipstr, NULL);
if (addrs != NULL) {
register unsigned int j;
pr_netaddr_t **elts = addrs->elts;
/* For every additional address, implicitly add a bind record. */
for (j = 0; j < addrs->nelts; j++) {
const char *ipstr;
ipstr = pr_netaddr_get_ipstr(elts[j]);
/* Skip duplicate addresses. */
if (strcmp(addr_ipstr, ipstr) == 0) {
continue;
}
add_config_param_str("_bind_", 1, ipstr);
}
}
}
pr_log_debug(DEBUG3, "setting default addresses to %s", addrs_str);
} else {
pr_log_debug(DEBUG3, "setting default address to %s", main_ipstr);
}
return PR_HANDLED(cmd);
}
MODRET set_servername(cmd_rec *cmd) {
server_rec *s = cmd->server;
CHECK_ARGS(cmd, 1);
CHECK_CONF(cmd, CONF_ROOT|CONF_VIRTUAL);
s->ServerName = pstrdup(s->pool, cmd->argv[1]);
return PR_HANDLED(cmd);
}
MODRET set_servertype(cmd_rec *cmd) {
CHECK_ARGS(cmd, 1);
CHECK_CONF(cmd, CONF_ROOT);
if (strcasecmp(cmd->argv[1], "inetd") == 0) {
ServerType = SERVER_INETD;
} else if (strcasecmp(cmd->argv[1], "standalone") == 0) {
ServerType = SERVER_STANDALONE;
} else {
CONF_ERROR(cmd,"type must be either 'inetd' or 'standalone'");
}
return PR_HANDLED(cmd);
}
MODRET set_setenv(cmd_rec *cmd) {
int ctxt_type;
CHECK_ARGS(cmd, 2);
CHECK_CONF(cmd, CONF_ROOT|CONF_VIRTUAL|CONF_GLOBAL);
add_config_param_str(cmd->argv[0], 2, cmd->argv[1], cmd->argv[2]);
/* In addition, if this is the "server config" context, set the
* environment variable now. If there was a <Daemon> context, that would
* be a more appropriate place for configuring parse-time environ
* variables.
*/
ctxt_type = (cmd->config && cmd->config->config_type != CONF_PARAM ?
cmd->config->config_type : cmd->server->config_type ?
cmd->server->config_type : CONF_ROOT);
if (ctxt_type == CONF_ROOT) {
if (pr_env_set(cmd->server->pool, cmd->argv[1], cmd->argv[2]) < 0) {
pr_log_debug(DEBUG1, "%s: unable to set environment variable '%s': %s",
(char *) cmd->argv[0], (char *) cmd->argv[1], strerror(errno));
} else {
core_handle_locale_env(cmd->argv[1]);
}
}
return PR_HANDLED(cmd);
}
MODRET add_transferlog(cmd_rec *cmd) {
config_rec *c = NULL;
CHECK_ARGS(cmd, 1);
CHECK_CONF(cmd, CONF_ROOT|CONF_VIRTUAL|CONF_GLOBAL|CONF_ANON);
c = add_config_param_str(cmd->argv[0], 1, cmd->argv[1]);
c->flags |= CF_MERGEDOWN;
return PR_HANDLED(cmd);
}
MODRET set_serveradmin(cmd_rec *cmd) {
server_rec *s = cmd->server;
CHECK_ARGS(cmd, 1);
CHECK_CONF(cmd, CONF_ROOT|CONF_VIRTUAL);
s->ServerAdmin = pstrdup(s->pool, cmd->argv[1]);
return PR_HANDLED(cmd);
}
/* usage: UseIPv6 on|off */
MODRET set_useipv6(cmd_rec *cmd) {
#ifdef PR_USE_IPV6
int bool = -1;
CHECK_ARGS(cmd, 1);
CHECK_CONF(cmd, CONF_ROOT);
bool = get_boolean(cmd, 1);
if (bool == -1)
CONF_ERROR(cmd, "expected Boolean parameter");
if (bool == 0) {
pr_log_debug(DEBUG2, "disabling runtime support for IPv6 connections");
pr_netaddr_disable_ipv6();
} else {
pr_netaddr_enable_ipv6();
}
return PR_HANDLED(cmd);
#else
CONF_ERROR(cmd,
"Use of the UseIPv6 directive requires IPv6 support (--enable-ipv6)");
#endif /* PR_USE_IPV6 */
}
MODRET set_usereversedns(cmd_rec *cmd) {
int bool = -1;
CHECK_ARGS(cmd, 1);
CHECK_CONF(cmd, CONF_ROOT);
bool = get_boolean(cmd, 1);
if (bool == -1)
CONF_ERROR(cmd, "expected Boolean parameter");
ServerUseReverseDNS = bool;
pr_netaddr_set_reverse_dns(bool);
return PR_HANDLED(cmd);
}
MODRET set_satisfy(cmd_rec *cmd) {
int satisfy = -1;
CHECK_ARGS(cmd, 1);
CHECK_CONF(cmd, CONF_CLASS);
if (strcasecmp(cmd->argv[1], "any") == 0) {
satisfy = PR_CLASS_SATISFY_ANY;
} else if (strcasecmp(cmd->argv[1], "all") == 0) {
satisfy = PR_CLASS_SATISFY_ALL;
} else {
CONF_ERROR(cmd, pstrcat(cmd->tmp_pool, "invalid parameter: '",
cmd->argv[1], "'", NULL));
}
if (pr_class_set_satisfy(satisfy) < 0) {
CONF_ERROR(cmd, pstrcat(cmd->tmp_pool, "error setting Satisfy: ",
strerror(errno), NULL));
}
return PR_HANDLED(cmd);
}
/* usage: ScoreboardFile path */
MODRET set_scoreboardfile(cmd_rec *cmd) {
CHECK_ARGS(cmd, 1);
CHECK_CONF(cmd, CONF_ROOT);
if (pr_set_scoreboard(cmd->argv[1]) < 0) {
CONF_ERROR(cmd, pstrcat(cmd->tmp_pool, "unable to use '", cmd->argv[1],
"': ", strerror(errno), NULL));
}
return PR_HANDLED(cmd);
}
/* usage: ScoreboardMutex path */
MODRET set_scoreboardmutex(cmd_rec *cmd) {
CHECK_ARGS(cmd, 1);
CHECK_CONF(cmd, CONF_ROOT);
if (pr_set_scoreboard_mutex(cmd->argv[1]) < 0) {
CONF_ERROR(cmd, pstrcat(cmd->tmp_pool, "unable to use '", cmd->argv[1],
"': ", strerror(errno), NULL));
}
return PR_HANDLED(cmd);
}
/* usage: ScoreboardScrub "on"|"off"|secs */
MODRET set_scoreboardscrub(cmd_rec *cmd) {
int bool = -1, nsecs = 0;
config_rec *c;
CHECK_ARGS(cmd, 1);
CHECK_CONF(cmd, CONF_ROOT);
bool = get_boolean(cmd, 1);
if (bool == -1) {
/* If this is the case, try handling the parameter as the number of
* seconds, as the scrub frequency.
*/
nsecs = atoi(cmd->argv[1]);
if (nsecs <= 0) {
CONF_ERROR(cmd, "number must be greater than zero");
}
}
if (nsecs > 0) {
c = add_config_param(cmd->argv[0], 2, NULL, NULL);
c->argv[0] = pcalloc(c->pool, sizeof(int));
*((int *) c->argv[0]) = TRUE;
c->argv[1] = pcalloc(c->pool, sizeof(int));
*((int *) c->argv[1]) = nsecs;
} else {
c = add_config_param(cmd->argv[0], 1, NULL);
c->argv[0] = pcalloc(c->pool, sizeof(int));
*((int *) c->argv[0]) = bool;
}
return PR_HANDLED(cmd);
}
MODRET set_serverport(cmd_rec *cmd) {
server_rec *s = cmd->server;
int port;
CHECK_ARGS(cmd, 1);
CHECK_CONF(cmd, CONF_ROOT|CONF_VIRTUAL);
port = atoi(cmd->argv[1]);
if (port < 0 ||
port > 65535) {
CONF_ERROR(cmd, "value must be between 0 and 65535");
}
s->ServerPort = port;
return PR_HANDLED(cmd);
}
MODRET set_pidfile(cmd_rec *cmd) {
CHECK_ARGS(cmd, 1);
CHECK_CONF(cmd, CONF_ROOT);
if (pr_pidfile_set(cmd->argv[1]) < 0) {
CONF_ERROR(cmd, pstrcat(cmd->tmp_pool, "unable to set PidFile '",
cmd->argv[1], "': ", strerror(errno), NULL));
}
return PR_HANDLED(cmd);
}
MODRET set_sysloglevel(cmd_rec *cmd) {
config_rec *c = NULL;
int level = 0;
CHECK_ARGS(cmd, 1);
CHECK_CONF(cmd, CONF_ROOT|CONF_VIRTUAL|CONF_GLOBAL);
level = pr_log_str2sysloglevel(cmd->argv[1]);
if (level < 0) {
CONF_ERROR(cmd, "SyslogLevel requires level keyword: one of "
"emerg/alert/crit/error/warn/notice/info/debug");
}
c = add_config_param(cmd->argv[0], 1, NULL);
c->argv[0] = pcalloc(c->pool, sizeof(int));
*((int *) c->argv[0]) = level;
return PR_HANDLED(cmd);
}
/* usage: ServerAlias hostname [hostname ...] */
MODRET set_serveralias(cmd_rec *cmd) {
register unsigned int i;
if (cmd->argc < 2) {
CONF_ERROR(cmd, "wrong number of parameters");
}
CHECK_CONF(cmd, CONF_ROOT|CONF_VIRTUAL);
for (i = 1; i < cmd->argc; i++) {
add_config_param_str(cmd->argv[0], 1, cmd->argv[i]);
}
return PR_HANDLED(cmd);
}
/* usage: ServerIdent off|on [name] */
MODRET set_serverident(cmd_rec *cmd) {
int ident_on = -1;
config_rec *c = NULL;
if (cmd->argc < 2 ||
cmd->argc > 3) {
CONF_ERROR(cmd, "wrong number of parameters");
}
CHECK_CONF(cmd, CONF_ROOT|CONF_VIRTUAL|CONF_GLOBAL);
ident_on = get_boolean(cmd, 1);
if (ident_on == -1) {
CONF_ERROR(cmd, "expected Boolean parameter");
}
if (ident_on == TRUE &&
cmd->argc == 3) {
c = add_config_param(cmd->argv[0], 2, NULL, NULL);
c->argv[0] = pcalloc(c->pool, sizeof(unsigned char));
*((unsigned char *) c->argv[0]) = ident_on;
c->argv[1] = pstrdup(c->pool, cmd->argv[2]);
} else {
c = add_config_param(cmd->argv[0], 1, NULL);
c->argv[0] = pcalloc(c->pool, sizeof(unsigned char));
*((unsigned char *) c->argv[0]) = ident_on;
}
return PR_HANDLED(cmd);
}
MODRET set_defaultserver(cmd_rec *cmd) {
int bool = -1;
server_rec *s = NULL;
config_rec *c = NULL;
CHECK_ARGS(cmd, 1);
CHECK_CONF(cmd, CONF_ROOT|CONF_VIRTUAL);
bool = get_boolean(cmd, 1);
if (bool == -1) {
CONF_ERROR(cmd, "expected Boolean parameter");
}
if (!bool) {
return PR_HANDLED(cmd);
}
/* DefaultServer is not allowed if already set somewhere */
for (s = (server_rec *) server_list->xas_list; s; s = s->next) {
if (find_config(s->conf, CONF_PARAM, cmd->argv[0], FALSE)) {
CONF_ERROR(cmd, "DefaultServer has already been set");
}
}
c = add_config_param(cmd->argv[0], 1, NULL);
c->argv[0] = pcalloc(c->pool, sizeof(unsigned char));
*((unsigned char *) c->argv[0]) = bool;
return PR_HANDLED(cmd);
}
MODRET set_masqueradeaddress(cmd_rec *cmd) {
config_rec *c = NULL;
const char *name;
size_t namelen;
const pr_netaddr_t *masq_addr = NULL;
unsigned int addr_flags = PR_NETADDR_GET_ADDR_FL_INCL_DEVICE;
CHECK_ARGS(cmd, 1);
CHECK_CONF(cmd, CONF_ROOT|CONF_VIRTUAL|CONF_GLOBAL);
/* We can only masquerade as one address, so we don't need to know if the
* given name might map to multiple addresses.
*/
name = cmd->argv[1];
namelen = strlen(name);
if (namelen == 0) {
/* Guard against empty names here. */
CONF_ERROR(cmd, "missing required name parameter");
}
masq_addr = pr_netaddr_get_addr2(cmd->server->pool, name, NULL, addr_flags);
if (masq_addr == NULL) {
/* If the requested name cannot be resolved because it is not known AT
* THIS TIME, then do not fail to start the server. We will simply try
* again later (Bug#4104).
*/
if (errno != ENOENT) {
CONF_ERROR(cmd, pstrcat(cmd->tmp_pool, "unable to resolve '", name, "'",
NULL));
}
}
c = add_config_param(cmd->argv[0], 2, (void *) masq_addr, NULL);
c->argv[1] = pstrdup(c->pool, cmd->argv[1]);
return PR_HANDLED(cmd);
}
MODRET set_maxinstances(cmd_rec *cmd) {
long max_instances;
char *endp;
CHECK_ARGS(cmd, 1);
CHECK_CONF(cmd, CONF_ROOT);
if (strcasecmp(cmd->argv[1], "none") == 0) {
max_instances = 0UL;
} else {
max_instances = strtol(cmd->argv[1], &endp, 10);
if ((endp && *endp) ||
max_instances < 1) {
CONF_ERROR(cmd, "argument must be 'none' or a number greater than 0");
}
}
ServerMaxInstances = max_instances;
return PR_HANDLED(cmd);
}
/* usage: MaxCommandRate rate [interval] */
MODRET set_maxcommandrate(cmd_rec *cmd) {
config_rec *c;
long cmd_max = 0L;
unsigned int max_cmd_interval = 1;
char *endp = NULL;
if (cmd->argc-1 < 1 ||
cmd->argc-1 > 2) {
CONF_ERROR(cmd, "wrong number of parameters");
}
CHECK_CONF(cmd, CONF_ROOT|CONF_VIRTUAL|CONF_GLOBAL);