forked from apache/httpd
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.c
More file actions
2083 lines (1704 loc) · 65.1 KB
/
config.c
File metadata and controls
2083 lines (1704 loc) · 65.1 KB
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
/* Copyright 1999-2005 The Apache Software Foundation or its licensors, as
* applicable.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* http_config.c: once was auxillary functions for reading httpd's config
* file and converting filenames into a namespace
*
* Rob McCool
*
* Wall-to-wall rewrite for Apache... commands which are part of the
* server core can now be found next door in "http_core.c". Now contains
* general command loop, and functions which do bookkeeping for the new
* Apache config stuff (modules and configuration vectors).
*
* rst
*
*/
#include "apr.h"
#include "apr_strings.h"
#include "apr_portable.h"
#include "apr_file_io.h"
#include "apr_fnmatch.h"
#define APR_WANT_STDIO
#define APR_WANT_STRFUNC
#include "apr_want.h"
#define CORE_PRIVATE
#include "ap_config.h"
#include "httpd.h"
#include "http_config.h"
#include "http_protocol.h"
#include "http_core.h"
#include "http_log.h" /* for errors in parse_htaccess */
#include "http_request.h" /* for default_handler (see invoke_handler) */
#include "http_main.h"
#include "http_vhost.h"
#include "util_cfgtree.h"
#include "mpm.h"
AP_DECLARE_DATA const char *ap_server_argv0 = NULL;
AP_DECLARE_DATA const char *ap_server_root = NULL;
AP_DECLARE_DATA apr_array_header_t *ap_server_pre_read_config = NULL;
AP_DECLARE_DATA apr_array_header_t *ap_server_post_read_config = NULL;
AP_DECLARE_DATA apr_array_header_t *ap_server_config_defines = NULL;
AP_DECLARE_DATA ap_directive_t *ap_conftree = NULL;
APR_HOOK_STRUCT(
APR_HOOK_LINK(header_parser)
APR_HOOK_LINK(pre_config)
APR_HOOK_LINK(post_config)
APR_HOOK_LINK(open_logs)
APR_HOOK_LINK(child_init)
APR_HOOK_LINK(handler)
APR_HOOK_LINK(quick_handler)
APR_HOOK_LINK(optional_fn_retrieve)
APR_HOOK_LINK(test_config)
)
AP_IMPLEMENT_HOOK_RUN_ALL(int, header_parser,
(request_rec *r), (r), OK, DECLINED)
AP_IMPLEMENT_HOOK_RUN_ALL(int, pre_config,
(apr_pool_t *pconf, apr_pool_t *plog,
apr_pool_t *ptemp),
(pconf, plog, ptemp), OK, DECLINED)
AP_IMPLEMENT_HOOK_VOID(test_config,
(apr_pool_t *pconf, server_rec *s),
(pconf, s))
AP_IMPLEMENT_HOOK_RUN_ALL(int, post_config,
(apr_pool_t *pconf, apr_pool_t *plog,
apr_pool_t *ptemp, server_rec *s),
(pconf, plog, ptemp, s), OK, DECLINED)
/* During the course of debugging I expanded this macro out, so
* rather than remove all the useful information there is in the
* following lines, I'm going to leave it here in case anyone
* else finds it useful.
*
* Ben has looked at it and thinks it correct :)
*
AP_DECLARE(int) ap_hook_post_config(ap_HOOK_post_config_t *pf,
const char * const *aszPre,
const char * const *aszSucc,
int nOrder)
{
ap_LINK_post_config_t *pHook;
if (!_hooks.link_post_config) {
_hooks.link_post_config = apr_array_make(apr_hook_global_pool, 1,
sizeof(ap_LINK_post_config_t));
apr_hook_sort_register("post_config", &_hooks.link_post_config);
}
pHook = apr_array_push(_hooks.link_post_config);
pHook->pFunc = pf;
pHook->aszPredecessors = aszPre;
pHook->aszSuccessors = aszSucc;
pHook->nOrder = nOrder;
pHook->szName = apr_hook_debug_current;
if (apr_hook_debug_enabled)
apr_hook_debug_show("post_config", aszPre, aszSucc);
}
AP_DECLARE(apr_array_header_t *) ap_hook_get_post_config(void) {
return _hooks.link_post_config;
}
AP_DECLARE(int) ap_run_post_config(apr_pool_t *pconf,
apr_pool_t *plog,
apr_pool_t *ptemp,
server_rec *s)
{
ap_LINK_post_config_t *pHook;
int n;
if(!_hooks.link_post_config)
return;
pHook = (ap_LINK_post_config_t *)_hooks.link_post_config->elts;
for (n = 0; n < _hooks.link_post_config->nelts; ++n)
pHook[n].pFunc (pconf, plog, ptemp, s);
}
*/
AP_IMPLEMENT_HOOK_RUN_ALL(int, open_logs,
(apr_pool_t *pconf, apr_pool_t *plog,
apr_pool_t *ptemp, server_rec *s),
(pconf, plog, ptemp, s), OK, DECLINED)
AP_IMPLEMENT_HOOK_VOID(child_init,
(apr_pool_t *pchild, server_rec *s),
(pchild, s))
AP_IMPLEMENT_HOOK_RUN_FIRST(int, handler, (request_rec *r),
(r), DECLINED)
AP_IMPLEMENT_HOOK_RUN_FIRST(int, quick_handler, (request_rec *r, int lookup),
(r, lookup), DECLINED)
AP_IMPLEMENT_HOOK_VOID(optional_fn_retrieve, (void), ())
/****************************************************************
*
* We begin with the functions which deal with the linked list
* of modules which control just about all of the server operation.
*/
/* total_modules is the number of modules that have been linked
* into the server.
*/
static int total_modules = 0;
/* dynamic_modules is the number of modules that have been added
* after the pre-loaded ones have been set up. It shouldn't be larger
* than DYNAMIC_MODULE_LIMIT.
*/
static int dynamic_modules = 0;
AP_DECLARE_DATA module *ap_top_module = NULL;
AP_DECLARE_DATA module **ap_loaded_modules=NULL;
typedef int (*handler_func)(request_rec *);
typedef void *(*dir_maker_func)(apr_pool_t *, char *);
typedef void *(*merger_func)(apr_pool_t *, void *, void *);
/* maximum nesting level for config directories */
#ifndef AP_MAX_INCLUDE_DIR_DEPTH
#define AP_MAX_INCLUDE_DIR_DEPTH (128)
#endif
/* Dealing with config vectors. These are associated with per-directory,
* per-server, and per-request configuration, and have a void* pointer for
* each modules. The nature of the structure pointed to is private to the
* module in question... the core doesn't (and can't) know. However, there
* are defined interfaces which allow it to create instances of its private
* per-directory and per-server structures, and to merge the per-directory
* structures of a directory and its subdirectory (producing a new one in
* which the defaults applying to the base directory have been properly
* overridden).
*/
static ap_conf_vector_t *create_empty_config(apr_pool_t *p)
{
void *conf_vector = apr_pcalloc(p, sizeof(void *) *
(total_modules + DYNAMIC_MODULE_LIMIT));
return conf_vector;
}
static ap_conf_vector_t *create_default_per_dir_config(apr_pool_t *p)
{
void **conf_vector = apr_pcalloc(p, sizeof(void *) *
(total_modules + DYNAMIC_MODULE_LIMIT));
module *modp;
for (modp = ap_top_module; modp; modp = modp->next) {
dir_maker_func df = modp->create_dir_config;
if (df)
conf_vector[modp->module_index] = (*df)(p, NULL);
}
return (ap_conf_vector_t *)conf_vector;
}
AP_CORE_DECLARE(ap_conf_vector_t *) ap_merge_per_dir_configs(apr_pool_t *p,
ap_conf_vector_t *base,
ap_conf_vector_t *new_conf)
{
void **conf_vector = apr_palloc(p, sizeof(void *) * total_modules);
void **base_vector = (void **)base;
void **new_vector = (void **)new_conf;
module *modp;
for (modp = ap_top_module; modp; modp = modp->next) {
int i = modp->module_index;
if (!new_vector[i]) {
conf_vector[i] = base_vector[i];
}
else {
merger_func df = modp->merge_dir_config;
if (df && base_vector[i]) {
conf_vector[i] = (*df)(p, base_vector[i], new_vector[i]);
}
else
conf_vector[i] = new_vector[i];
}
}
return (ap_conf_vector_t *)conf_vector;
}
static ap_conf_vector_t *create_server_config(apr_pool_t *p, server_rec *s)
{
void **conf_vector = apr_pcalloc(p, sizeof(void *) *
(total_modules + DYNAMIC_MODULE_LIMIT));
module *modp;
for (modp = ap_top_module; modp; modp = modp->next) {
if (modp->create_server_config)
conf_vector[modp->module_index] = (*modp->create_server_config)(p, s);
}
return (ap_conf_vector_t *)conf_vector;
}
static void merge_server_configs(apr_pool_t *p, ap_conf_vector_t *base,
ap_conf_vector_t *virt)
{
/* Can reuse the 'virt' vector for the spine of it, since we don't
* have to deal with the moral equivalent of .htaccess files here...
*/
void **base_vector = (void **)base;
void **virt_vector = (void **)virt;
module *modp;
for (modp = ap_top_module; modp; modp = modp->next) {
merger_func df = modp->merge_server_config;
int i = modp->module_index;
if (!virt_vector[i])
virt_vector[i] = base_vector[i];
else if (df)
virt_vector[i] = (*df)(p, base_vector[i], virt_vector[i]);
}
}
AP_CORE_DECLARE(ap_conf_vector_t *) ap_create_request_config(apr_pool_t *p)
{
return create_empty_config(p);
}
AP_CORE_DECLARE(ap_conf_vector_t *) ap_create_conn_config(apr_pool_t *p)
{
return create_empty_config(p);
}
AP_CORE_DECLARE(ap_conf_vector_t *) ap_create_per_dir_config(apr_pool_t *p)
{
return create_empty_config(p);
}
static int ap_invoke_filter_init(ap_filter_t *filters)
{
while (filters) {
if (filters->frec->filter_init_func) {
int result = filters->frec->filter_init_func(filters);
if (result != OK) {
return result;
}
}
filters = filters->next;
}
return OK;
}
AP_CORE_DECLARE(int) ap_invoke_handler(request_rec *r)
{
const char *handler;
const char *p;
int result;
const char *old_handler = r->handler;
/*
* The new insert_filter stage makes the most sense here. We only use
* it when we are going to run the request, so we must insert filters
* if any are available. Since the goal of this phase is to allow all
* modules to insert a filter if they want to, this filter returns
* void. I just can't see any way that this filter can reasonably
* fail, either your modules inserts something or it doesn't. rbb
*/
ap_run_insert_filter(r);
/* Before continuing, allow each filter that is in the two chains to
* run their init function to let them do any magic before we could
* start generating data.
*/
result = ap_invoke_filter_init(r->input_filters);
if (result != OK) {
return result;
}
result = ap_invoke_filter_init(r->output_filters);
if (result != OK) {
return result;
}
if (!r->handler) {
handler = r->content_type ? r->content_type : ap_default_type(r);
if ((p=ap_strchr_c(handler, ';')) != NULL) {
char *new_handler = (char *)apr_pmemdup(r->pool, handler,
p - handler + 1);
char *p2 = new_handler + (p - handler);
handler = new_handler;
/* MIME type arguments */
while (p2 > handler && p2[-1] == ' ')
--p2; /* strip trailing spaces */
*p2='\0';
}
r->handler = handler;
}
result = ap_run_handler(r);
r->handler = old_handler;
if (result == DECLINED && r->handler && r->filename) {
ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r,
"handler \"%s\" not found for: %s", r->handler, r->filename);
}
return result == DECLINED ? HTTP_INTERNAL_SERVER_ERROR : result;
}
AP_DECLARE(int) ap_method_is_limited(cmd_parms *cmd, const char *method)
{
int methnum;
methnum = ap_method_number_of(method);
/*
* A method number either hardcoded into apache or
* added by a module and registered.
*/
if (methnum != M_INVALID) {
return (cmd->limited & (AP_METHOD_BIT << methnum)) ? 1 : 0;
}
return 0; /* not found */
}
AP_DECLARE(void) ap_register_hooks(module *m, apr_pool_t *p)
{
if (m->register_hooks) {
if (getenv("SHOW_HOOKS")) {
printf("Registering hooks for %s\n", m->name);
apr_hook_debug_enabled = 1;
}
apr_hook_debug_current = m->name;
m->register_hooks(p);
}
}
/* One-time setup for precompiled modules --- NOT to be done on restart */
AP_DECLARE(const char *) ap_add_module(module *m, apr_pool_t *p)
{
/* This could be called from a LoadModule httpd.conf command,
* after the file has been linked and the module structure within it
* teased out...
*/
if (m->version != MODULE_MAGIC_NUMBER_MAJOR) {
return apr_psprintf(p, "Module \"%s\" is not compatible with this "
"version of Apache (found %d, need %d). Please "
"contact the vendor for the correct version.",
m->name, m->version, MODULE_MAGIC_NUMBER_MAJOR);
}
if (m->next == NULL) {
m->next = ap_top_module;
ap_top_module = m;
}
if (m->module_index == -1) {
m->module_index = total_modules++;
dynamic_modules++;
if (dynamic_modules > DYNAMIC_MODULE_LIMIT) {
return apr_psprintf(p, "Module \"%s\" could not be loaded, "
"because the dynamic module limit was "
"reached. Please increase "
"DYNAMIC_MODULE_LIMIT and recompile.", m->name);
}
}
/* Some C compilers put a complete path into __FILE__, but we want
* only the filename (e.g. mod_includes.c). So check for path
* components (Unix and DOS), and remove them.
*/
if (ap_strrchr_c(m->name, '/'))
m->name = 1 + ap_strrchr_c(m->name, '/');
if (ap_strrchr_c(m->name, '\\'))
m->name = 1 + ap_strrchr_c(m->name, '\\');
#ifdef _OSD_POSIX
/* __FILE__ =
* "*POSIX(/home/martin/apache/src/modules/standard/mod_info.c)"
*/
/* We cannot fix the string in-place, because it's const */
if (m->name[strlen(m->name)-1] == ')') {
char *tmp = strdup(m->name); /* FIXME: memory leak, albeit a small one */
tmp[strlen(tmp)-1] = '\0';
m->name = tmp;
}
#endif /*_OSD_POSIX*/
/* FIXME: is this the right place to call this?
* It doesn't appear to be
*/
ap_register_hooks(m, p);
return NULL;
}
/*
* remove_module undoes what add_module did. There are some caveats:
* when the module is removed, its slot is lost so all the current
* per-dir and per-server configurations are invalid. So we should
* only ever call this function when you are invalidating almost
* all our current data. I.e. when doing a restart.
*/
AP_DECLARE(void) ap_remove_module(module *m)
{
module *modp;
modp = ap_top_module;
if (modp == m) {
/* We are the top module, special case */
ap_top_module = modp->next;
m->next = NULL;
}
else {
/* Not the top module, find use. When found modp will
* point to the module _before_ us in the list
*/
while (modp && modp->next != m) {
modp = modp->next;
}
if (!modp) {
/* Uh-oh, this module doesn't exist */
ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL,
"Cannot remove module %s: not found in module list",
m->name);
return;
}
/* Eliminate us from the module list */
modp->next = modp->next->next;
}
m->module_index = -1; /* simulate being unloaded, should
* be unnecessary */
dynamic_modules--;
total_modules--;
}
AP_DECLARE(const char *) ap_add_loaded_module(module *mod, apr_pool_t *p)
{
module **m;
const char *error;
/*
* Add module pointer to top of chained module list
*/
error = ap_add_module(mod, p);
if (error) {
return error;
}
/*
* And module pointer to list of loaded modules
*
* Notes: 1. ap_add_module() would already complain if no more space
* exists for adding a dynamically loaded module
* 2. ap_add_module() accepts double inclusion, so we have
* to accept this, too.
*/
for (m = ap_loaded_modules; *m != NULL; m++)
;
*m++ = mod;
*m = NULL;
return NULL;
}
AP_DECLARE(void) ap_remove_loaded_module(module *mod)
{
module **m;
module **m2;
int done;
/*
* Remove module pointer from chained module list
*/
ap_remove_module(mod);
/*
* Remove module pointer from list of loaded modules
*
* Note: 1. We cannot determine if the module was successfully
* removed by ap_remove_module().
* 2. We have not to complain explicity when the module
* is not found because ap_remove_module() did it
* for us already.
*/
for (m = m2 = ap_loaded_modules, done = 0; *m2 != NULL; m2++) {
if (*m2 == mod && done == 0)
done = 1;
else
*m++ = *m2;
}
*m = NULL;
}
AP_DECLARE(const char *) ap_setup_prelinked_modules(process_rec *process)
{
module **m;
module **m2;
const char *error;
apr_hook_global_pool=process->pconf;
/*
* Initialise total_modules variable and module indices
*/
total_modules = 0;
for (m = ap_preloaded_modules; *m != NULL; m++)
(*m)->module_index = total_modules++;
/*
* Initialise list of loaded modules
*/
ap_loaded_modules = (module **)apr_palloc(process->pool,
sizeof(module *) * (total_modules + DYNAMIC_MODULE_LIMIT + 1));
if (ap_loaded_modules == NULL) {
return "Ouch! Out of memory in ap_setup_prelinked_modules()!";
}
for (m = ap_preloaded_modules, m2 = ap_loaded_modules; *m != NULL; )
*m2++ = *m++;
*m2 = NULL;
/*
* Initialize chain of linked (=activate) modules
*/
for (m = ap_prelinked_modules; *m != NULL; m++) {
error = ap_add_module(*m, process->pconf);
if (error) {
return error;
}
}
apr_hook_sort_all();
return NULL;
}
AP_DECLARE(const char *) ap_find_module_name(module *m)
{
return m->name;
}
AP_DECLARE(module *) ap_find_linked_module(const char *name)
{
module *modp;
for (modp = ap_top_module; modp; modp = modp->next) {
if (strcmp(modp->name, name) == 0)
return modp;
}
return NULL;
}
/*****************************************************************
*
* Resource, access, and .htaccess config files now parsed by a common
* command loop.
*
* Let's begin with the basics; parsing the line and
* invoking the function...
*/
#define AP_MAX_ARGC 64
static const char *invoke_cmd(const command_rec *cmd, cmd_parms *parms,
void *mconfig, const char *args)
{
char *w, *w2, *w3;
const char *errmsg = NULL;
if ((parms->override & cmd->req_override) == 0)
return apr_pstrcat(parms->pool, cmd->name, " not allowed here", NULL);
parms->info = cmd->cmd_data;
parms->cmd = cmd;
switch (cmd->args_how) {
case RAW_ARGS:
#ifdef RESOLVE_ENV_PER_TOKEN
args = ap_resolve_env(parms->pool,args);
#endif
return cmd->AP_RAW_ARGS(parms, mconfig, args);
case TAKE_ARGV:
{
char *argv[AP_MAX_ARGC];
int argc = 0;
do {
w = ap_getword_conf(parms->pool, &args);
if (*w == '\0' && *args == '\0') {
break;
}
argv[argc] = w;
argc++;
} while (argc < AP_MAX_ARGC && *args != '\0');
return cmd->AP_TAKE_ARGV(parms, mconfig, argc, argv);
}
case NO_ARGS:
if (*args != 0)
return apr_pstrcat(parms->pool, cmd->name, " takes no arguments",
NULL);
return cmd->AP_NO_ARGS(parms, mconfig);
case TAKE1:
w = ap_getword_conf(parms->pool, &args);
if (*w == '\0' || *args != 0)
return apr_pstrcat(parms->pool, cmd->name, " takes one argument",
cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
return cmd->AP_TAKE1(parms, mconfig, w);
case TAKE2:
w = ap_getword_conf(parms->pool, &args);
w2 = ap_getword_conf(parms->pool, &args);
if (*w == '\0' || *w2 == '\0' || *args != 0)
return apr_pstrcat(parms->pool, cmd->name, " takes two arguments",
cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
return cmd->AP_TAKE2(parms, mconfig, w, w2);
case TAKE12:
w = ap_getword_conf(parms->pool, &args);
w2 = ap_getword_conf(parms->pool, &args);
if (*w == '\0' || *args != 0)
return apr_pstrcat(parms->pool, cmd->name, " takes 1-2 arguments",
cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
return cmd->AP_TAKE2(parms, mconfig, w, *w2 ? w2 : NULL);
case TAKE3:
w = ap_getword_conf(parms->pool, &args);
w2 = ap_getword_conf(parms->pool, &args);
w3 = ap_getword_conf(parms->pool, &args);
if (*w == '\0' || *w2 == '\0' || *w3 == '\0' || *args != 0)
return apr_pstrcat(parms->pool, cmd->name, " takes three arguments",
cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
return cmd->AP_TAKE3(parms, mconfig, w, w2, w3);
case TAKE23:
w = ap_getword_conf(parms->pool, &args);
w2 = ap_getword_conf(parms->pool, &args);
w3 = *args ? ap_getword_conf(parms->pool, &args) : NULL;
if (*w == '\0' || *w2 == '\0' || *args != 0)
return apr_pstrcat(parms->pool, cmd->name,
" takes two or three arguments",
cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
return cmd->AP_TAKE3(parms, mconfig, w, w2, w3);
case TAKE123:
w = ap_getword_conf(parms->pool, &args);
w2 = *args ? ap_getword_conf(parms->pool, &args) : NULL;
w3 = *args ? ap_getword_conf(parms->pool, &args) : NULL;
if (*w == '\0' || *args != 0)
return apr_pstrcat(parms->pool, cmd->name,
" takes one, two or three arguments",
cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
return cmd->AP_TAKE3(parms, mconfig, w, w2, w3);
case TAKE13:
w = ap_getword_conf(parms->pool, &args);
w2 = *args ? ap_getword_conf(parms->pool, &args) : NULL;
w3 = *args ? ap_getword_conf(parms->pool, &args) : NULL;
if (*w == '\0' || (w2 && *w2 && !w3) || *args != 0)
return apr_pstrcat(parms->pool, cmd->name,
" takes one or three arguments",
cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
return cmd->AP_TAKE3(parms, mconfig, w, w2, w3);
case ITERATE:
while (*(w = ap_getword_conf(parms->pool, &args)) != '\0') {
errmsg = cmd->AP_TAKE1(parms, mconfig, w);
if (errmsg && strcmp(errmsg, DECLINE_CMD) != 0)
return errmsg;
}
return errmsg;
case ITERATE2:
w = ap_getword_conf(parms->pool, &args);
if (*w == '\0' || *args == 0)
return apr_pstrcat(parms->pool, cmd->name,
" requires at least two arguments",
cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
while (*(w2 = ap_getword_conf(parms->pool, &args)) != '\0') {
errmsg = cmd->AP_TAKE2(parms, mconfig, w, w2);
if (errmsg && strcmp(errmsg, DECLINE_CMD) != 0)
return errmsg;
}
return errmsg;
case FLAG:
w = ap_getword_conf(parms->pool, &args);
if (*w == '\0' || (strcasecmp(w, "on") && strcasecmp(w, "off")))
return apr_pstrcat(parms->pool, cmd->name, " must be On or Off",
NULL);
return cmd->AP_FLAG(parms, mconfig, strcasecmp(w, "off") != 0);
default:
return apr_pstrcat(parms->pool, cmd->name,
" is improperly configured internally (server bug)",
NULL);
}
}
AP_CORE_DECLARE(const command_rec *) ap_find_command(const char *name,
const command_rec *cmds)
{
while (cmds->name) {
if (!strcasecmp(name, cmds->name))
return cmds;
++cmds;
}
return NULL;
}
AP_CORE_DECLARE(const command_rec *) ap_find_command_in_modules(
const char *cmd_name, module **mod)
{
const command_rec *cmdp;
module *modp;
for (modp = *mod; modp; modp = modp->next) {
if (modp->cmds && (cmdp = ap_find_command(cmd_name, modp->cmds))) {
*mod = modp;
return cmdp;
}
}
return NULL;
}
AP_CORE_DECLARE(void *) ap_set_config_vectors(server_rec *server,
ap_conf_vector_t *section_vector,
const char *section,
module *mod, apr_pool_t *pconf)
{
void *section_config = ap_get_module_config(section_vector, mod);
void *server_config = ap_get_module_config(server->module_config, mod);
if (!section_config && mod->create_dir_config) {
/* ### need to fix the create_dir_config functions' prototype... */
section_config = (*mod->create_dir_config)(pconf, (char *)section);
ap_set_module_config(section_vector, mod, section_config);
}
if (!server_config && mod->create_server_config) {
server_config = (*mod->create_server_config)(pconf, server);
ap_set_module_config(server->module_config, mod, server_config);
}
return section_config;
}
static const char *execute_now(char *cmd_line, const char *args,
cmd_parms *parms,
apr_pool_t *p, apr_pool_t *ptemp,
ap_directive_t **sub_tree,
ap_directive_t *parent);
static const char *ap_build_config_sub(apr_pool_t *p, apr_pool_t *temp_pool,
const char *l, cmd_parms *parms,
ap_directive_t **current,
ap_directive_t **curr_parent,
ap_directive_t **conftree)
{
const char *retval = NULL;
const char *args;
char *cmd_name;
ap_directive_t *newdir;
module *mod = ap_top_module;
const command_rec *cmd;
if (*l == '#' || *l == '\0')
return NULL;
#if RESOLVE_ENV_PER_TOKEN
args = l;
#else
args = ap_resolve_env(temp_pool, l);
#endif
cmd_name = ap_getword_conf(p, &args);
if (*cmd_name == '\0') {
/* Note: this branch should not occur. An empty line should have
* triggered the exit further above.
*/
return NULL;
}
if (cmd_name[1] != '/') {
char *lastc = cmd_name + strlen(cmd_name) - 1;
if (*lastc == '>') {
*lastc = '\0' ;
}
if (cmd_name[0] == '<' && *args == '\0') {
args = ">";
}
}
newdir = apr_pcalloc(p, sizeof(ap_directive_t));
newdir->filename = parms->config_file->name;
newdir->line_num = parms->config_file->line_number;
newdir->directive = cmd_name;
newdir->args = apr_pstrdup(p, args);
if ((cmd = ap_find_command_in_modules(cmd_name, &mod)) != NULL) {
if (cmd->req_override & EXEC_ON_READ) {
ap_directive_t *sub_tree = NULL;
parms->err_directive = newdir;
retval = execute_now(cmd_name, args, parms, p, temp_pool,
&sub_tree, *curr_parent);
if (*current) {
(*current)->next = sub_tree;
}
else {
*current = sub_tree;
if (*curr_parent) {
(*curr_parent)->first_child = (*current);
}
if (*current) {
(*current)->parent = (*curr_parent);
}
}
if (*current) {
if (!*conftree) {
/* Before walking *current to the end of the list,
* set the head to *current.
*/
*conftree = *current;
}
while ((*current)->next != NULL) {
(*current) = (*current)->next;
(*current)->parent = (*curr_parent);
}
}
return retval;
}
}
if (cmd_name[0] == '<') {
if (cmd_name[1] != '/') {
(*current) = ap_add_node(curr_parent, *current, newdir, 1);
}
else if (*curr_parent == NULL) {
parms->err_directive = newdir;
return apr_pstrcat(p, cmd_name,
" without matching <", cmd_name + 2,
" section", NULL);
}
else {
char *bracket = cmd_name + strlen(cmd_name) - 1;
if (*bracket != '>') {
parms->err_directive = newdir;
return apr_pstrcat(p, cmd_name,
"> directive missing closing '>'", NULL);
}
*bracket = '\0';
if (strcasecmp(cmd_name + 2,
(*curr_parent)->directive + 1) != 0) {
parms->err_directive = newdir;
return apr_pstrcat(p, "Expected </",
(*curr_parent)->directive + 1, "> but saw ",
cmd_name, ">", NULL);
}
*bracket = '>';
/* done with this section; move up a level */
*current = *curr_parent;
*curr_parent = (*current)->parent;
}
}
else {
*current = ap_add_node(curr_parent, *current, newdir, 0);
}
return retval;
}
AP_DECLARE(const char *) ap_build_cont_config(apr_pool_t *p,
apr_pool_t *temp_pool,
cmd_parms *parms,