1 /* Copyright 1999-2005 The Apache Software Foundation or its licensors, as
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * http_config.c: once was auxillary functions for reading httpd's config
19 * file and converting filenames into a namespace
23 * Wall-to-wall rewrite for Apache... commands which are part of the
24 * server core can now be found next door in "http_core.c". Now contains
25 * general command loop, and functions which do bookkeeping for the new
26 * Apache config stuff (modules and configuration vectors).
33 #include "apr_strings.h"
34 #include "apr_portable.h"
35 #include "apr_file_io.h"
36 #include "apr_fnmatch.h"
38 #define APR_WANT_STDIO
39 #define APR_WANT_STRFUNC
44 #include "ap_config.h"
46 #include "http_config.h"
47 #include "http_protocol.h"
48 #include "http_core.h"
49 #include "http_log.h" /* for errors in parse_htaccess */
50 #include "http_request.h" /* for default_handler (see invoke_handler) */
51 #include "http_main.h"
52 #include "http_vhost.h"
53 #include "util_cfgtree.h"
57 AP_DECLARE_DATA const char *ap_server_argv0 = NULL;
59 AP_DECLARE_DATA const char *ap_server_root = NULL;
61 AP_DECLARE_DATA apr_array_header_t *ap_server_pre_read_config = NULL;
62 AP_DECLARE_DATA apr_array_header_t *ap_server_post_read_config = NULL;
63 AP_DECLARE_DATA apr_array_header_t *ap_server_config_defines = NULL;
65 AP_DECLARE_DATA ap_directive_t *ap_conftree = NULL;
68 APR_HOOK_LINK(header_parser)
69 APR_HOOK_LINK(pre_config)
70 APR_HOOK_LINK(post_config)
71 APR_HOOK_LINK(open_logs)
72 APR_HOOK_LINK(child_init)
73 APR_HOOK_LINK(handler)
74 APR_HOOK_LINK(quick_handler)
75 APR_HOOK_LINK(optional_fn_retrieve)
76 APR_HOOK_LINK(test_config)
79 AP_IMPLEMENT_HOOK_RUN_ALL(int, header_parser,
80 (request_rec *r), (r), OK, DECLINED)
82 AP_IMPLEMENT_HOOK_RUN_ALL(int, pre_config,
83 (apr_pool_t *pconf, apr_pool_t *plog,
85 (pconf, plog, ptemp), OK, DECLINED)
87 AP_IMPLEMENT_HOOK_VOID(test_config,
88 (apr_pool_t *pconf, server_rec *s),
91 AP_IMPLEMENT_HOOK_RUN_ALL(int, post_config,
92 (apr_pool_t *pconf, apr_pool_t *plog,
93 apr_pool_t *ptemp, server_rec *s),
94 (pconf, plog, ptemp, s), OK, DECLINED)
96 /* During the course of debugging I expanded this macro out, so
97 * rather than remove all the useful information there is in the
98 * following lines, I'm going to leave it here in case anyone
99 * else finds it useful.
101 * Ben has looked at it and thinks it correct :)
103 AP_DECLARE(int) ap_hook_post_config(ap_HOOK_post_config_t *pf,
104 const char * const *aszPre,
105 const char * const *aszSucc,
108 ap_LINK_post_config_t *pHook;
110 if (!_hooks.link_post_config) {
111 _hooks.link_post_config = apr_array_make(apr_hook_global_pool, 1,
112 sizeof(ap_LINK_post_config_t));
113 apr_hook_sort_register("post_config", &_hooks.link_post_config);
116 pHook = apr_array_push(_hooks.link_post_config);
118 pHook->aszPredecessors = aszPre;
119 pHook->aszSuccessors = aszSucc;
120 pHook->nOrder = nOrder;
121 pHook->szName = apr_hook_debug_current;
123 if (apr_hook_debug_enabled)
124 apr_hook_debug_show("post_config", aszPre, aszSucc);
127 AP_DECLARE(apr_array_header_t *) ap_hook_get_post_config(void) {
128 return _hooks.link_post_config;
131 AP_DECLARE(int) ap_run_post_config(apr_pool_t *pconf,
136 ap_LINK_post_config_t *pHook;
139 if(!_hooks.link_post_config)
142 pHook = (ap_LINK_post_config_t *)_hooks.link_post_config->elts;
143 for (n = 0; n < _hooks.link_post_config->nelts; ++n)
144 pHook[n].pFunc (pconf, plog, ptemp, s);
148 AP_IMPLEMENT_HOOK_RUN_ALL(int, open_logs,
149 (apr_pool_t *pconf, apr_pool_t *plog,
150 apr_pool_t *ptemp, server_rec *s),
151 (pconf, plog, ptemp, s), OK, DECLINED)
153 AP_IMPLEMENT_HOOK_VOID(child_init,
154 (apr_pool_t *pchild, server_rec *s),
157 AP_IMPLEMENT_HOOK_RUN_FIRST(int, handler, (request_rec *r),
160 AP_IMPLEMENT_HOOK_RUN_FIRST(int, quick_handler, (request_rec *r, int lookup),
161 (r, lookup), DECLINED)
163 AP_IMPLEMENT_HOOK_VOID(optional_fn_retrieve, (void), ())
165 /****************************************************************
167 * We begin with the functions which deal with the linked list
168 * of modules which control just about all of the server operation.
171 /* total_modules is the number of modules that have been linked
174 static int total_modules = 0;
176 /* dynamic_modules is the number of modules that have been added
177 * after the pre-loaded ones have been set up. It shouldn't be larger
178 * than DYNAMIC_MODULE_LIMIT.
180 static int dynamic_modules = 0;
182 AP_DECLARE_DATA module *ap_top_module = NULL;
183 AP_DECLARE_DATA module **ap_loaded_modules=NULL;
185 typedef int (*handler_func)(request_rec *);
186 typedef void *(*dir_maker_func)(apr_pool_t *, char *);
187 typedef void *(*merger_func)(apr_pool_t *, void *, void *);
189 /* maximum nesting level for config directories */
190 #ifndef AP_MAX_INCLUDE_DIR_DEPTH
191 #define AP_MAX_INCLUDE_DIR_DEPTH (128)
194 /* Dealing with config vectors. These are associated with per-directory,
195 * per-server, and per-request configuration, and have a void* pointer for
196 * each modules. The nature of the structure pointed to is private to the
197 * module in question... the core doesn't (and can't) know. However, there
198 * are defined interfaces which allow it to create instances of its private
199 * per-directory and per-server structures, and to merge the per-directory
200 * structures of a directory and its subdirectory (producing a new one in
201 * which the defaults applying to the base directory have been properly
205 static ap_conf_vector_t *create_empty_config(apr_pool_t *p)
207 void *conf_vector = apr_pcalloc(p, sizeof(void *) *
208 (total_modules + DYNAMIC_MODULE_LIMIT));
212 static ap_conf_vector_t *create_default_per_dir_config(apr_pool_t *p)
214 void **conf_vector = apr_pcalloc(p, sizeof(void *) *
215 (total_modules + DYNAMIC_MODULE_LIMIT));
218 for (modp = ap_top_module; modp; modp = modp->next) {
219 dir_maker_func df = modp->create_dir_config;
222 conf_vector[modp->module_index] = (*df)(p, NULL);
225 return (ap_conf_vector_t *)conf_vector;
228 AP_CORE_DECLARE(ap_conf_vector_t *) ap_merge_per_dir_configs(apr_pool_t *p,
229 ap_conf_vector_t *base,
230 ap_conf_vector_t *new_conf)
232 void **conf_vector = apr_palloc(p, sizeof(void *) * total_modules);
233 void **base_vector = (void **)base;
234 void **new_vector = (void **)new_conf;
237 for (modp = ap_top_module; modp; modp = modp->next) {
238 int i = modp->module_index;
240 if (!new_vector[i]) {
241 conf_vector[i] = base_vector[i];
244 merger_func df = modp->merge_dir_config;
245 if (df && base_vector[i]) {
246 conf_vector[i] = (*df)(p, base_vector[i], new_vector[i]);
249 conf_vector[i] = new_vector[i];
253 return (ap_conf_vector_t *)conf_vector;
256 static ap_conf_vector_t *create_server_config(apr_pool_t *p, server_rec *s)
258 void **conf_vector = apr_pcalloc(p, sizeof(void *) *
259 (total_modules + DYNAMIC_MODULE_LIMIT));
262 for (modp = ap_top_module; modp; modp = modp->next) {
263 if (modp->create_server_config)
264 conf_vector[modp->module_index] = (*modp->create_server_config)(p, s);
267 return (ap_conf_vector_t *)conf_vector;
270 static void merge_server_configs(apr_pool_t *p, ap_conf_vector_t *base,
271 ap_conf_vector_t *virt)
273 /* Can reuse the 'virt' vector for the spine of it, since we don't
274 * have to deal with the moral equivalent of .htaccess files here...
277 void **base_vector = (void **)base;
278 void **virt_vector = (void **)virt;
281 for (modp = ap_top_module; modp; modp = modp->next) {
282 merger_func df = modp->merge_server_config;
283 int i = modp->module_index;
286 virt_vector[i] = base_vector[i];
288 virt_vector[i] = (*df)(p, base_vector[i], virt_vector[i]);
292 AP_CORE_DECLARE(ap_conf_vector_t *) ap_create_request_config(apr_pool_t *p)
294 return create_empty_config(p);
297 AP_CORE_DECLARE(ap_conf_vector_t *) ap_create_conn_config(apr_pool_t *p)
299 return create_empty_config(p);
302 AP_CORE_DECLARE(ap_conf_vector_t *) ap_create_per_dir_config(apr_pool_t *p)
304 return create_empty_config(p);
307 static int ap_invoke_filter_init(ap_filter_t *filters)
310 if (filters->frec->filter_init_func) {
311 int result = filters->frec->filter_init_func(filters);
316 filters = filters->next;
321 AP_CORE_DECLARE(int) ap_invoke_handler(request_rec *r)
326 const char *old_handler = r->handler;
329 * The new insert_filter stage makes the most sense here. We only use
330 * it when we are going to run the request, so we must insert filters
331 * if any are available. Since the goal of this phase is to allow all
332 * modules to insert a filter if they want to, this filter returns
333 * void. I just can't see any way that this filter can reasonably
334 * fail, either your modules inserts something or it doesn't. rbb
336 ap_run_insert_filter(r);
338 /* Before continuing, allow each filter that is in the two chains to
339 * run their init function to let them do any magic before we could
340 * start generating data.
342 result = ap_invoke_filter_init(r->input_filters);
346 result = ap_invoke_filter_init(r->output_filters);
352 handler = r->content_type ? r->content_type : ap_default_type(r);
353 if ((p=ap_strchr_c(handler, ';')) != NULL) {
354 char *new_handler = (char *)apr_pmemdup(r->pool, handler,
356 char *p2 = new_handler + (p - handler);
357 handler = new_handler;
359 /* MIME type arguments */
360 while (p2 > handler && p2[-1] == ' ')
361 --p2; /* strip trailing spaces */
366 r->handler = handler;
369 result = ap_run_handler(r);
371 r->handler = old_handler;
373 if (result == DECLINED && r->handler && r->filename) {
374 ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r,
375 "handler \"%s\" not found for: %s", r->handler, r->filename);
378 return result == DECLINED ? HTTP_INTERNAL_SERVER_ERROR : result;
381 AP_DECLARE(int) ap_method_is_limited(cmd_parms *cmd, const char *method)
385 methnum = ap_method_number_of(method);
388 * A method number either hardcoded into apache or
389 * added by a module and registered.
391 if (methnum != M_INVALID) {
392 return (cmd->limited & (AP_METHOD_BIT << methnum)) ? 1 : 0;
395 return 0; /* not found */
398 AP_DECLARE(void) ap_register_hooks(module *m, apr_pool_t *p)
400 if (m->register_hooks) {
401 if (getenv("SHOW_HOOKS")) {
402 printf("Registering hooks for %s\n", m->name);
403 apr_hook_debug_enabled = 1;
406 apr_hook_debug_current = m->name;
407 m->register_hooks(p);
411 /* One-time setup for precompiled modules --- NOT to be done on restart */
413 AP_DECLARE(const char *) ap_add_module(module *m, apr_pool_t *p)
415 /* This could be called from a LoadModule httpd.conf command,
416 * after the file has been linked and the module structure within it
420 if (m->version != MODULE_MAGIC_NUMBER_MAJOR) {
421 return apr_psprintf(p, "Module \"%s\" is not compatible with this "
422 "version of Apache (found %d, need %d). Please "
423 "contact the vendor for the correct version.",
424 m->name, m->version, MODULE_MAGIC_NUMBER_MAJOR);
427 if (m->next == NULL) {
428 m->next = ap_top_module;
432 if (m->module_index == -1) {
433 m->module_index = total_modules++;
436 if (dynamic_modules > DYNAMIC_MODULE_LIMIT) {
437 return apr_psprintf(p, "Module \"%s\" could not be loaded, "
438 "because the dynamic module limit was "
439 "reached. Please increase "
440 "DYNAMIC_MODULE_LIMIT and recompile.", m->name);
444 /* Some C compilers put a complete path into __FILE__, but we want
445 * only the filename (e.g. mod_includes.c). So check for path
446 * components (Unix and DOS), and remove them.
449 if (ap_strrchr_c(m->name, '/'))
450 m->name = 1 + ap_strrchr_c(m->name, '/');
452 if (ap_strrchr_c(m->name, '\\'))
453 m->name = 1 + ap_strrchr_c(m->name, '\\');
457 * "*POSIX(/home/martin/apache/src/modules/standard/mod_info.c)"
460 /* We cannot fix the string in-place, because it's const */
461 if (m->name[strlen(m->name)-1] == ')') {
462 char *tmp = strdup(m->name); /* FIXME: memory leak, albeit a small one */
463 tmp[strlen(tmp)-1] = '\0';
466 #endif /*_OSD_POSIX*/
468 /* FIXME: is this the right place to call this?
469 * It doesn't appear to be
471 ap_register_hooks(m, p);
477 * remove_module undoes what add_module did. There are some caveats:
478 * when the module is removed, its slot is lost so all the current
479 * per-dir and per-server configurations are invalid. So we should
480 * only ever call this function when you are invalidating almost
481 * all our current data. I.e. when doing a restart.
484 AP_DECLARE(void) ap_remove_module(module *m)
488 modp = ap_top_module;
490 /* We are the top module, special case */
491 ap_top_module = modp->next;
495 /* Not the top module, find use. When found modp will
496 * point to the module _before_ us in the list
499 while (modp && modp->next != m) {
504 /* Uh-oh, this module doesn't exist */
505 ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL,
506 "Cannot remove module %s: not found in module list",
511 /* Eliminate us from the module list */
512 modp->next = modp->next->next;
515 m->module_index = -1; /* simulate being unloaded, should
521 AP_DECLARE(const char *) ap_add_loaded_module(module *mod, apr_pool_t *p)
527 * Add module pointer to top of chained module list
529 error = ap_add_module(mod, p);
535 * And module pointer to list of loaded modules
537 * Notes: 1. ap_add_module() would already complain if no more space
538 * exists for adding a dynamically loaded module
539 * 2. ap_add_module() accepts double inclusion, so we have
540 * to accept this, too.
542 for (m = ap_loaded_modules; *m != NULL; m++)
550 AP_DECLARE(void) ap_remove_loaded_module(module *mod)
557 * Remove module pointer from chained module list
559 ap_remove_module(mod);
562 * Remove module pointer from list of loaded modules
564 * Note: 1. We cannot determine if the module was successfully
565 * removed by ap_remove_module().
566 * 2. We have not to complain explicity when the module
567 * is not found because ap_remove_module() did it
570 for (m = m2 = ap_loaded_modules, done = 0; *m2 != NULL; m2++) {
571 if (*m2 == mod && done == 0)
580 AP_DECLARE(const char *) ap_setup_prelinked_modules(process_rec *process)
586 apr_hook_global_pool=process->pconf;
589 * Initialise total_modules variable and module indices
592 for (m = ap_preloaded_modules; *m != NULL; m++)
593 (*m)->module_index = total_modules++;
596 * Initialise list of loaded modules
598 ap_loaded_modules = (module **)apr_palloc(process->pool,
599 sizeof(module *) * (total_modules + DYNAMIC_MODULE_LIMIT + 1));
601 if (ap_loaded_modules == NULL) {
602 return "Ouch! Out of memory in ap_setup_prelinked_modules()!";
605 for (m = ap_preloaded_modules, m2 = ap_loaded_modules; *m != NULL; )
611 * Initialize chain of linked (=activate) modules
613 for (m = ap_prelinked_modules; *m != NULL; m++) {
614 error = ap_add_module(*m, process->pconf);
625 AP_DECLARE(const char *) ap_find_module_name(module *m)
630 AP_DECLARE(module *) ap_find_linked_module(const char *name)
634 for (modp = ap_top_module; modp; modp = modp->next) {
635 if (strcmp(modp->name, name) == 0)
642 /*****************************************************************
644 * Resource, access, and .htaccess config files now parsed by a common
647 * Let's begin with the basics; parsing the line and
648 * invoking the function...
651 static const char *invoke_cmd(const command_rec *cmd, cmd_parms *parms,
652 void *mconfig, const char *args)
655 const char *errmsg = NULL;
657 if ((parms->override & cmd->req_override) == 0)
658 return apr_pstrcat(parms->pool, cmd->name, " not allowed here", NULL);
660 parms->info = cmd->cmd_data;
663 switch (cmd->args_how) {
665 #ifdef RESOLVE_ENV_PER_TOKEN
666 args = ap_resolve_env(parms->pool,args);
668 return cmd->AP_RAW_ARGS(parms, mconfig, args);
672 return apr_pstrcat(parms->pool, cmd->name, " takes no arguments",
675 return cmd->AP_NO_ARGS(parms, mconfig);
678 w = ap_getword_conf(parms->pool, &args);
680 if (*w == '\0' || *args != 0)
681 return apr_pstrcat(parms->pool, cmd->name, " takes one argument",
682 cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
684 return cmd->AP_TAKE1(parms, mconfig, w);
687 w = ap_getword_conf(parms->pool, &args);
688 w2 = ap_getword_conf(parms->pool, &args);
690 if (*w == '\0' || *w2 == '\0' || *args != 0)
691 return apr_pstrcat(parms->pool, cmd->name, " takes two arguments",
692 cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
694 return cmd->AP_TAKE2(parms, mconfig, w, w2);
697 w = ap_getword_conf(parms->pool, &args);
698 w2 = ap_getword_conf(parms->pool, &args);
700 if (*w == '\0' || *args != 0)
701 return apr_pstrcat(parms->pool, cmd->name, " takes 1-2 arguments",
702 cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
704 return cmd->AP_TAKE2(parms, mconfig, w, *w2 ? w2 : NULL);
707 w = ap_getword_conf(parms->pool, &args);
708 w2 = ap_getword_conf(parms->pool, &args);
709 w3 = ap_getword_conf(parms->pool, &args);
711 if (*w == '\0' || *w2 == '\0' || *w3 == '\0' || *args != 0)
712 return apr_pstrcat(parms->pool, cmd->name, " takes three arguments",
713 cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
715 return cmd->AP_TAKE3(parms, mconfig, w, w2, w3);
718 w = ap_getword_conf(parms->pool, &args);
719 w2 = ap_getword_conf(parms->pool, &args);
720 w3 = *args ? ap_getword_conf(parms->pool, &args) : NULL;
722 if (*w == '\0' || *w2 == '\0' || *args != 0)
723 return apr_pstrcat(parms->pool, cmd->name,
724 " takes two or three arguments",
725 cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
727 return cmd->AP_TAKE3(parms, mconfig, w, w2, w3);
730 w = ap_getword_conf(parms->pool, &args);
731 w2 = *args ? ap_getword_conf(parms->pool, &args) : NULL;
732 w3 = *args ? ap_getword_conf(parms->pool, &args) : NULL;
734 if (*w == '\0' || *args != 0)
735 return apr_pstrcat(parms->pool, cmd->name,
736 " takes one, two or three arguments",
737 cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
739 return cmd->AP_TAKE3(parms, mconfig, w, w2, w3);
742 w = ap_getword_conf(parms->pool, &args);
743 w2 = *args ? ap_getword_conf(parms->pool, &args) : NULL;
744 w3 = *args ? ap_getword_conf(parms->pool, &args) : NULL;
746 if (*w == '\0' || (w2 && *w2 && !w3) || *args != 0)
747 return apr_pstrcat(parms->pool, cmd->name,
748 " takes one or three arguments",
749 cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
751 return cmd->AP_TAKE3(parms, mconfig, w, w2, w3);
754 while (*(w = ap_getword_conf(parms->pool, &args)) != '\0') {
756 errmsg = cmd->AP_TAKE1(parms, mconfig, w);
758 if (errmsg && strcmp(errmsg, DECLINE_CMD) != 0)
765 w = ap_getword_conf(parms->pool, &args);
767 if (*w == '\0' || *args == 0)
768 return apr_pstrcat(parms->pool, cmd->name,
769 " requires at least two arguments",
770 cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
772 while (*(w2 = ap_getword_conf(parms->pool, &args)) != '\0') {
774 errmsg = cmd->AP_TAKE2(parms, mconfig, w, w2);
776 if (errmsg && strcmp(errmsg, DECLINE_CMD) != 0)
783 w = ap_getword_conf(parms->pool, &args);
785 if (*w == '\0' || (strcasecmp(w, "on") && strcasecmp(w, "off")))
786 return apr_pstrcat(parms->pool, cmd->name, " must be On or Off",
789 return cmd->AP_FLAG(parms, mconfig, strcasecmp(w, "off") != 0);
792 return apr_pstrcat(parms->pool, cmd->name,
793 " is improperly configured internally (server bug)",
798 AP_CORE_DECLARE(const command_rec *) ap_find_command(const char *name,
799 const command_rec *cmds)
802 if (!strcasecmp(name, cmds->name))
811 AP_CORE_DECLARE(const command_rec *) ap_find_command_in_modules(
812 const char *cmd_name, module **mod)
814 const command_rec *cmdp;
817 for (modp = *mod; modp; modp = modp->next) {
818 if (modp->cmds && (cmdp = ap_find_command(cmd_name, modp->cmds))) {
827 AP_CORE_DECLARE(void *) ap_set_config_vectors(server_rec *server,
828 ap_conf_vector_t *section_vector,
830 module *mod, apr_pool_t *pconf)
832 void *section_config = ap_get_module_config(section_vector, mod);
833 void *server_config = ap_get_module_config(server->module_config, mod);
835 if (!section_config && mod->create_dir_config) {
836 /* ### need to fix the create_dir_config functions' prototype... */
837 section_config = (*mod->create_dir_config)(pconf, (char *)section);
838 ap_set_module_config(section_vector, mod, section_config);
841 if (!server_config && mod->create_server_config) {
842 server_config = (*mod->create_server_config)(pconf, server);
843 ap_set_module_config(server->module_config, mod, server_config);
846 return section_config;
849 static const char *execute_now(char *cmd_line, const char *args,
851 apr_pool_t *p, apr_pool_t *ptemp,
852 ap_directive_t **sub_tree,
853 ap_directive_t *parent);
855 static const char *ap_build_config_sub(apr_pool_t *p, apr_pool_t *temp_pool,
856 const char *l, cmd_parms *parms,
857 ap_directive_t **current,
858 ap_directive_t **curr_parent,
859 ap_directive_t **conftree)
861 const char *retval = NULL;
864 ap_directive_t *newdir;
865 module *mod = ap_top_module;
866 const command_rec *cmd;
868 if (*l == '#' || *l == '\0')
871 #if RESOLVE_ENV_PER_TOKEN
874 args = ap_resolve_env(temp_pool, l);
877 cmd_name = ap_getword_conf(p, &args);
878 if (*cmd_name == '\0') {
879 /* Note: this branch should not occur. An empty line should have
880 * triggered the exit further above.
885 if (cmd_name[1] != '/') {
886 char *lastc = cmd_name + strlen(cmd_name) - 1;
890 if (cmd_name[0] == '<' && *args == '\0') {
895 newdir = apr_pcalloc(p, sizeof(ap_directive_t));
896 newdir->filename = parms->config_file->name;
897 newdir->line_num = parms->config_file->line_number;
898 newdir->directive = cmd_name;
899 newdir->args = apr_pstrdup(p, args);
901 if ((cmd = ap_find_command_in_modules(cmd_name, &mod)) != NULL) {
902 if (cmd->req_override & EXEC_ON_READ) {
903 ap_directive_t *sub_tree = NULL;
905 parms->err_directive = newdir;
906 retval = execute_now(cmd_name, args, parms, p, temp_pool,
907 &sub_tree, *curr_parent);
909 (*current)->next = sub_tree;
914 (*curr_parent)->first_child = (*current);
917 (*current)->parent = (*curr_parent);
922 /* Before walking *current to the end of the list,
923 * set the head to *current.
925 *conftree = *current;
927 while ((*current)->next != NULL) {
928 (*current) = (*current)->next;
929 (*current)->parent = (*curr_parent);
936 if (cmd_name[0] == '<') {
937 if (cmd_name[1] != '/') {
938 (*current) = ap_add_node(curr_parent, *current, newdir, 1);
940 else if (*curr_parent == NULL) {
941 parms->err_directive = newdir;
942 return apr_pstrcat(p, cmd_name,
943 " without matching <", cmd_name + 2,
947 char *bracket = cmd_name + strlen(cmd_name) - 1;
949 if (*bracket != '>') {
950 parms->err_directive = newdir;
951 return apr_pstrcat(p, cmd_name,
952 "> directive missing closing '>'", NULL);
957 if (strcasecmp(cmd_name + 2,
958 (*curr_parent)->directive + 1) != 0) {
959 parms->err_directive = newdir;
960 return apr_pstrcat(p, "Expected </",
961 (*curr_parent)->directive + 1, "> but saw ",
962 cmd_name, ">", NULL);
967 /* done with this section; move up a level */
968 *current = *curr_parent;
969 *curr_parent = (*current)->parent;
973 *current = ap_add_node(curr_parent, *current, newdir, 0);
979 AP_DECLARE(const char *) ap_build_cont_config(apr_pool_t *p,
980 apr_pool_t *temp_pool,
982 ap_directive_t **current,
983 ap_directive_t **curr_parent,
984 char *orig_directive)
989 ap_directive_t *sub_tree = NULL;
991 /* Since this function can be called recursively, allocate
992 * the temporary 8k string buffer from the temp_pool rather
993 * than the stack to avoid over-running a fixed length stack.
995 l = apr_palloc(temp_pool, MAX_STRING_LEN);
997 bracket = apr_pstrcat(p, orig_directive + 1, ">", NULL);
998 while (!(ap_cfg_getline(l, MAX_STRING_LEN, parms->config_file))) {
999 if (!memcmp(l, "</", 2)
1000 && (strcasecmp(l + 2, bracket) == 0)
1001 && (*curr_parent == NULL)) {
1004 retval = ap_build_config_sub(p, temp_pool, l, parms, current,
1005 curr_parent, &sub_tree);
1009 if (sub_tree == NULL && curr_parent != NULL) {
1010 sub_tree = *curr_parent;
1013 if (sub_tree == NULL && current != NULL) {
1014 sub_tree = *current;
1018 *current = sub_tree;
1022 static const char *ap_walk_config_sub(const ap_directive_t *current,
1024 ap_conf_vector_t *section_vector)
1026 module *mod = ap_top_module;
1029 const command_rec *cmd;
1031 if (!(cmd = ap_find_command_in_modules(current->directive, &mod))) {
1032 parms->err_directive = current;
1033 return apr_pstrcat(parms->pool, "Invalid command '",
1035 "', perhaps mis-spelled or defined by a module "
1036 "not included in the server configuration",
1040 void *dir_config = ap_set_config_vectors(parms->server,
1047 /* Once was enough? */
1048 if (cmd->req_override & EXEC_ON_READ) {
1052 retval = invoke_cmd(cmd, parms, dir_config, current->args);
1053 if (retval == NULL) {
1057 if (strcmp(retval, DECLINE_CMD) != 0) {
1058 /* If the directive in error has already been set, don't
1059 * replace it. Otherwise, an error inside a container
1060 * will be reported as occuring on the first line of the
1063 if (!parms->err_directive) {
1064 parms->err_directive = current;
1070 mod = mod->next; /* Next time around, skip this one */
1076 AP_DECLARE(const char *) ap_walk_config(ap_directive_t *current,
1078 ap_conf_vector_t *section_vector)
1080 ap_conf_vector_t *oldconfig = parms->context;
1082 parms->context = section_vector;
1084 /* scan through all directives, executing each one */
1085 for (; current != NULL; current = current->next) {
1088 parms->directive = current;
1090 /* actually parse the command and execute the correct function */
1091 errmsg = ap_walk_config_sub(current, parms, section_vector);
1092 if (errmsg != NULL) {
1093 /* restore the context (just in case) */
1094 parms->context = oldconfig;
1099 parms->context = oldconfig;
1103 AP_DECLARE(const char *) ap_build_config(cmd_parms *parms,
1104 apr_pool_t *p, apr_pool_t *temp_pool,
1105 ap_directive_t **conftree)
1107 ap_directive_t *current = *conftree;
1108 ap_directive_t *curr_parent = NULL;
1109 char *l = apr_palloc (temp_pool, MAX_STRING_LEN);
1112 if (current != NULL) {
1113 while (current->next) {
1114 current = current->next;
1118 while (!(ap_cfg_getline(l, MAX_STRING_LEN, parms->config_file))) {
1119 errmsg = ap_build_config_sub(p, temp_pool, l, parms,
1120 ¤t, &curr_parent, conftree);
1124 if (*conftree == NULL && curr_parent != NULL) {
1125 *conftree = curr_parent;
1128 if (*conftree == NULL && current != NULL) {
1129 *conftree = current;
1133 if (curr_parent != NULL) {
1136 while (curr_parent != NULL) {
1137 errmsg = apr_psprintf(p, "%s%s%s:%u: %s> was not closed.",
1139 *errmsg == '\0' ? "" : APR_EOL_STR,
1140 curr_parent->filename,
1141 curr_parent->line_num,
1142 curr_parent->directive);
1144 parms->err_directive = curr_parent;
1145 curr_parent = curr_parent->parent;
1155 * Generic command functions...
1158 AP_DECLARE_NONSTD(const char *) ap_set_string_slot(cmd_parms *cmd,
1162 int offset = (int)(long)cmd->info;
1164 *(const char **)((char *)struct_ptr + offset) = arg;
1169 AP_DECLARE_NONSTD(const char *) ap_set_int_slot(cmd_parms *cmd,
1174 char *error_str = NULL;
1175 int offset = (int)(long)cmd->info;
1177 *(int *)((char*)struct_ptr + offset) = strtol(arg, &endptr, 10);
1179 if ((*arg == '\0') || (*endptr != '\0')) {
1180 error_str = apr_psprintf(cmd->pool,
1181 "Invalid value for directive %s, expected integer",
1182 cmd->directive->directive);
1188 AP_DECLARE_NONSTD(const char *) ap_set_string_slot_lower(cmd_parms *cmd,
1192 char *arg = apr_pstrdup(cmd->pool,arg_);
1193 int offset = (int)(long)cmd->info;
1195 ap_str_tolower(arg);
1196 *(char **)((char *)struct_ptr + offset) = arg;
1201 AP_DECLARE_NONSTD(const char *) ap_set_flag_slot(cmd_parms *cmd,
1202 void *struct_ptr_v, int arg)
1204 int offset = (int)(long)cmd->info;
1205 char *struct_ptr = (char *)struct_ptr_v;
1207 *(int *)(struct_ptr + offset) = arg ? 1 : 0;
1212 AP_DECLARE_NONSTD(const char *) ap_set_file_slot(cmd_parms *cmd, void *struct_ptr,
1215 /* Prepend server_root to relative arg.
1216 * This allows most args to be independent of server_root,
1217 * so the server can be moved or mirrored with less pain.
1220 int offset = (int)(long)cmd->info;
1222 path = ap_server_root_relative(cmd->pool, arg);
1225 return apr_pstrcat(cmd->pool, "Invalid file path ",
1229 *(const char **) ((char*)struct_ptr + offset) = path;
1234 AP_DECLARE_NONSTD(const char *) ap_set_deprecated(cmd_parms *cmd,
1238 return cmd->cmd->errmsg;
1241 /*****************************************************************
1243 * Reading whole config files...
1246 static cmd_parms default_parms =
1247 {NULL, 0, -1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
1249 AP_DECLARE(char *) ap_server_root_relative(apr_pool_t *p, const char *file)
1251 char *newpath = NULL;
1253 rv = apr_filepath_merge(&newpath, ap_server_root, file,
1254 APR_FILEPATH_TRUENAME, p);
1255 if (newpath && (rv == APR_SUCCESS || APR_STATUS_IS_EPATHWILD(rv)
1256 || APR_STATUS_IS_ENOENT(rv)
1257 || APR_STATUS_IS_ENOTDIR(rv))) {
1265 AP_DECLARE(const char *) ap_soak_end_container(cmd_parms *cmd, char *directive)
1267 char l[MAX_STRING_LEN];
1271 while(!(ap_cfg_getline(l, MAX_STRING_LEN, cmd->config_file))) {
1272 #if RESOLVE_ENV_PER_TOKEN
1275 args = ap_resolve_env(cmd->temp_pool, l);
1278 cmd_name = ap_getword_conf(cmd->pool, &args);
1279 if (cmd_name[0] == '<') {
1280 if (cmd_name[1] == '/') {
1281 cmd_name[strlen(cmd_name) - 1] = '\0';
1283 if (strcasecmp(cmd_name + 2, directive + 1) != 0) {
1284 return apr_pstrcat(cmd->pool, "Expected </",
1285 directive + 1, "> but saw ",
1286 cmd_name, ">", NULL);
1289 return NULL; /* found end of container */
1294 if (*args == '\0' && cmd_name[strlen(cmd_name) - 1] == '>') {
1295 cmd_name[strlen(cmd_name) - 1] = '\0';
1298 if ((msg = ap_soak_end_container(cmd, cmd_name)) != NULL) {
1305 return apr_pstrcat(cmd->pool, "Expected </",
1306 directive + 1, "> before end of configuration",
1310 static const char *execute_now(char *cmd_line, const char *args,
1312 apr_pool_t *p, apr_pool_t *ptemp,
1313 ap_directive_t **sub_tree,
1314 ap_directive_t *parent)
1316 module *mod = ap_top_module;
1317 const command_rec *cmd;
1319 if (!(cmd = ap_find_command_in_modules(cmd_line, &mod))) {
1320 return apr_pstrcat(parms->pool, "Invalid command '",
1322 "', perhaps mis-spelled or defined by a module "
1323 "not included in the server configuration",
1327 return invoke_cmd(cmd, parms, sub_tree, args);
1331 /* This structure and the following functions are needed for the
1332 * table-based config file reading. They are passed to the
1333 * cfg_open_custom() routine.
1336 /* Structure to be passed to cfg_open_custom(): it contains an
1337 * index which is incremented from 0 to nelts on each call to
1338 * cfg_getline() (which in turn calls arr_elts_getstr())
1339 * and an apr_array_header_t pointer for the string array.
1342 apr_array_header_t *array;
1347 /* arr_elts_getstr() returns the next line from the string array. */
1348 static void *arr_elts_getstr(void *buf, size_t bufsiz, void *param)
1350 arr_elts_param_t *arr_param = (arr_elts_param_t *)param;
1352 /* End of array reached? */
1353 if (++arr_param->curr_idx > arr_param->array->nelts)
1356 /* return the line */
1358 ((char **)arr_param->array->elts)[arr_param->curr_idx - 1],
1365 /* arr_elts_close(): dummy close routine (makes sure no more lines can be read) */
1366 static int arr_elts_close(void *param)
1368 arr_elts_param_t *arr_param = (arr_elts_param_t *)param;
1370 arr_param->curr_idx = arr_param->array->nelts;
1375 static const char *process_command_config(server_rec *s,
1376 apr_array_header_t *arr,
1377 ap_directive_t **conftree,
1383 arr_elts_param_t arr_parms;
1385 arr_parms.curr_idx = 0;
1386 arr_parms.array = arr;
1388 parms = default_parms;
1390 parms.temp_pool = ptemp;
1392 parms.override = (RSRC_CONF | OR_ALL) & ~(OR_AUTHCFG | OR_LIMIT);
1393 parms.override_opts = OPT_ALL | OPT_INCNOEXEC | OPT_SYM_OWNER | OPT_MULTI;
1395 parms.config_file = ap_pcfg_open_custom(p, "-c/-C directives",
1397 arr_elts_getstr, arr_elts_close);
1399 errmsg = ap_build_config(&parms, p, ptemp, conftree);
1400 ap_cfg_closefile(parms.config_file);
1403 return apr_pstrcat(p, "Syntax error in -C/-c directive: ", errmsg,
1414 static int fname_alphasort(const void *fn1, const void *fn2)
1416 const fnames *f1 = fn1;
1417 const fnames *f2 = fn2;
1419 return strcmp(f1->fname,f2->fname);
1422 static const char *process_resource_config_nofnmatch(server_rec *s,
1424 ap_directive_t **conftree,
1430 ap_configfile_t *cfp;
1433 if (ap_is_directory(p, fname)) {
1437 apr_array_header_t *candidates = NULL;
1440 char *path = apr_pstrdup(p, fname);
1442 if (++depth > AP_MAX_INCLUDE_DIR_DEPTH) {
1443 return apr_psprintf(p, "Directory %s exceeds the maximum include "
1444 "directory nesting level of %u. You have "
1445 "probably a recursion somewhere.", path,
1446 AP_MAX_INCLUDE_DIR_DEPTH);
1450 * first course of business is to grok all the directory
1451 * entries here and store 'em away. Recall we need full pathnames
1454 rv = apr_dir_open(&dirp, path, p);
1455 if (rv != APR_SUCCESS) {
1457 return apr_psprintf(p, "Could not open config directory %s: %s",
1458 path, apr_strerror(rv, errmsg, sizeof errmsg));
1461 candidates = apr_array_make(p, 1, sizeof(fnames));
1462 while (apr_dir_read(&dirent, APR_FINFO_DIRENT, dirp) == APR_SUCCESS) {
1463 /* strip out '.' and '..' */
1464 if (strcmp(dirent.name, ".")
1465 && strcmp(dirent.name, "..")) {
1466 fnew = (fnames *) apr_array_push(candidates);
1467 fnew->fname = ap_make_full_path(p, path, dirent.name);
1471 apr_dir_close(dirp);
1472 if (candidates->nelts != 0) {
1473 qsort((void *) candidates->elts, candidates->nelts,
1474 sizeof(fnames), fname_alphasort);
1477 * Now recurse these... we handle errors and subdirectories
1478 * via the recursion, which is nice
1480 for (current = 0; current < candidates->nelts; ++current) {
1481 fnew = &((fnames *) candidates->elts)[current];
1482 error = process_resource_config_nofnmatch(s, fnew->fname,
1494 /* GCC's initialization extensions are soooo nice here... */
1495 parms = default_parms;
1497 parms.temp_pool = ptemp;
1499 parms.override = (RSRC_CONF | OR_ALL) & ~(OR_AUTHCFG | OR_LIMIT);
1500 parms.override_opts = OPT_ALL | OPT_INCNOEXEC | OPT_SYM_OWNER | OPT_MULTI;
1502 if (ap_pcfg_openfile(&cfp, p, fname) != APR_SUCCESS) {
1503 return apr_pstrcat(p, "Could not open document config file ",
1507 parms.config_file = cfp;
1508 error = ap_build_config(&parms, p, ptemp, conftree);
1509 ap_cfg_closefile(cfp);
1512 return apr_psprintf(p, "Syntax error on line %d of %s: %s",
1513 parms.err_directive->line_num,
1514 parms.err_directive->filename, error);
1520 AP_DECLARE(const char *) ap_process_resource_config(server_rec *s,
1522 ap_directive_t **conftree,
1526 /* XXX: lstat() won't work on the wildcard pattern...
1529 /* don't require conf/httpd.conf if we have a -C or -c switch */
1530 if ((ap_server_pre_read_config->nelts
1531 || ap_server_post_read_config->nelts)
1532 && !(strcmp(fname, ap_server_root_relative(p, SERVER_CONFIG_FILE)))) {
1535 if (apr_stat(&finfo, fname, APR_FINFO_LINK | APR_FINFO_TYPE, p) != APR_SUCCESS)
1539 if (!apr_fnmatch_test(fname)) {
1540 return process_resource_config_nofnmatch(s, fname, conftree, p, ptemp,
1547 apr_array_header_t *candidates = NULL;
1550 char *path = apr_pstrdup(p, fname), *pattern = NULL;
1552 pattern = ap_strrchr(path, '/');
1554 AP_DEBUG_ASSERT(pattern != NULL); /* path must be absolute. */
1558 if (apr_fnmatch_test(path)) {
1559 return apr_pstrcat(p, "Wildcard patterns not allowed in Include ",
1563 if (!ap_is_directory(p, path)){
1564 return apr_pstrcat(p, "Include directory '", path, "' not found",
1568 if (!apr_fnmatch_test(pattern)) {
1569 return apr_pstrcat(p, "Must include a wildcard pattern for "
1570 "Include ", fname, NULL);
1574 * first course of business is to grok all the directory
1575 * entries here and store 'em away. Recall we need full pathnames
1578 rv = apr_dir_open(&dirp, path, p);
1579 if (rv != APR_SUCCESS) {
1581 return apr_psprintf(p, "Could not open config directory %s: %s",
1582 path, apr_strerror(rv, errmsg, sizeof errmsg));
1585 candidates = apr_array_make(p, 1, sizeof(fnames));
1586 while (apr_dir_read(&dirent, APR_FINFO_DIRENT, dirp) == APR_SUCCESS) {
1587 /* strip out '.' and '..' */
1588 if (strcmp(dirent.name, ".")
1589 && strcmp(dirent.name, "..")
1590 && (apr_fnmatch(pattern, dirent.name,
1591 APR_FNM_PERIOD) == APR_SUCCESS)) {
1592 fnew = (fnames *) apr_array_push(candidates);
1593 fnew->fname = ap_make_full_path(p, path, dirent.name);
1597 apr_dir_close(dirp);
1598 if (candidates->nelts != 0) {
1601 qsort((void *) candidates->elts, candidates->nelts,
1602 sizeof(fnames), fname_alphasort);
1605 * Now recurse these... we handle errors and subdirectories
1606 * via the recursion, which is nice
1608 for (current = 0; current < candidates->nelts; ++current) {
1609 fnew = &((fnames *) candidates->elts)[current];
1610 error = process_resource_config_nofnmatch(s, fnew->fname,
1623 AP_DECLARE(int) ap_process_config_tree(server_rec *s,
1624 ap_directive_t *conftree,
1631 parms = default_parms;
1633 parms.temp_pool = ptemp;
1635 parms.override = (RSRC_CONF | OR_ALL) & ~(OR_AUTHCFG | OR_LIMIT);
1636 parms.override_opts = OPT_ALL | OPT_INCNOEXEC | OPT_SYM_OWNER | OPT_MULTI;
1639 errmsg = ap_walk_config(conftree, &parms, s->lookup_defaults);
1641 ap_log_perror(APLOG_MARK, APLOG_STARTUP, 0, p,
1642 "Syntax error on line %d of %s:",
1643 parms.err_directive->line_num,
1644 parms.err_directive->filename);
1645 ap_log_perror(APLOG_MARK, APLOG_STARTUP, 0, p,
1647 return HTTP_INTERNAL_SERVER_ERROR;
1653 AP_CORE_DECLARE(int) ap_parse_htaccess(ap_conf_vector_t **result,
1654 request_rec *r, int override,
1656 const char *d, const char *access_name)
1658 ap_configfile_t *f = NULL;
1660 char *filename = NULL;
1661 const struct htaccess_result *cache;
1662 struct htaccess_result *new;
1663 ap_conf_vector_t *dc = NULL;
1664 apr_status_t status;
1666 /* firstly, search cache */
1667 for (cache = r->htaccess; cache != NULL; cache = cache->next) {
1668 if (cache->override == override && strcmp(cache->dir, d) == 0) {
1669 *result = cache->htaccess;
1674 parms = default_parms;
1675 parms.override = override;
1676 parms.override_opts = override_opts;
1677 parms.pool = r->pool;
1678 parms.temp_pool = r->pool;
1679 parms.server = r->server;
1680 parms.path = apr_pstrdup(r->pool, d);
1682 /* loop through the access names and find the first one */
1683 while (access_name[0]) {
1684 /* AFAICT; there is no use of the actual 'filename' against
1685 * any canonicalization, so we will simply take the given
1686 * name, ignoring case sensitivity and aliases
1688 filename = ap_make_full_path(r->pool, d,
1689 ap_getword_conf(r->pool, &access_name));
1690 status = ap_pcfg_openfile(&f, r->pool, filename);
1692 if (status == APR_SUCCESS) {
1694 ap_directive_t *temptree = NULL;
1696 dc = ap_create_per_dir_config(r->pool);
1698 parms.config_file = f;
1699 errmsg = ap_build_config(&parms, r->pool, r->pool, &temptree);
1701 errmsg = ap_walk_config(temptree, &parms, dc);
1703 ap_cfg_closefile(f);
1706 ap_log_rerror(APLOG_MARK, APLOG_ALERT, 0, r,
1707 "%s: %s", filename, errmsg);
1708 return HTTP_INTERNAL_SERVER_ERROR;
1715 if (!APR_STATUS_IS_ENOENT(status)
1716 && !APR_STATUS_IS_ENOTDIR(status)) {
1717 ap_log_rerror(APLOG_MARK, APLOG_CRIT, status, r,
1718 "%s pcfg_openfile: unable to check htaccess file, "
1719 "ensure it is readable",
1721 apr_table_setn(r->notes, "error-notes",
1722 "Server unable to read htaccess file, denying "
1723 "access to be safe");
1724 return HTTP_FORBIDDEN;
1730 new = apr_palloc(r->pool, sizeof(struct htaccess_result));
1731 new->dir = parms.path;
1732 new->override = override;
1733 new->override_opts = override_opts;
1736 /* add to head of list */
1737 new->next = r->htaccess;
1743 AP_CORE_DECLARE(const char *) ap_init_virtual_host(apr_pool_t *p,
1744 const char *hostname,
1745 server_rec *main_server,
1748 server_rec *s = (server_rec *) apr_pcalloc(p, sizeof(server_rec));
1750 /* TODO: this crap belongs in http_core */
1751 s->process = main_server->process;
1752 s->server_admin = NULL;
1753 s->server_hostname = NULL;
1754 s->error_fname = NULL;
1756 s->keep_alive_timeout = 0;
1758 s->keep_alive_max = -1;
1759 s->error_log = main_server->error_log;
1760 s->loglevel = main_server->loglevel;
1761 /* useful default, otherwise we get a port of 0 on redirects */
1762 s->port = main_server->port;
1766 s->names = apr_array_make(p, 4, sizeof(char **));
1767 s->wild_names = apr_array_make(p, 4, sizeof(char **));
1769 s->module_config = create_empty_config(p);
1770 s->lookup_defaults = ap_create_per_dir_config(p);
1772 s->limit_req_line = main_server->limit_req_line;
1773 s->limit_req_fieldsize = main_server->limit_req_fieldsize;
1774 s->limit_req_fields = main_server->limit_req_fields;
1778 return ap_parse_vhost_addrs(p, hostname, s);
1782 AP_DECLARE(void) ap_fixup_virtual_hosts(apr_pool_t *p, server_rec *main_server)
1786 for (virt = main_server->next; virt; virt = virt->next) {
1787 merge_server_configs(p, main_server->module_config,
1788 virt->module_config);
1790 virt->lookup_defaults =
1791 ap_merge_per_dir_configs(p, main_server->lookup_defaults,
1792 virt->lookup_defaults);
1794 if (virt->server_admin == NULL)
1795 virt->server_admin = main_server->server_admin;
1797 if (virt->timeout == 0)
1798 virt->timeout = main_server->timeout;
1800 if (virt->keep_alive_timeout == 0)
1801 virt->keep_alive_timeout = main_server->keep_alive_timeout;
1803 if (virt->keep_alive == -1)
1804 virt->keep_alive = main_server->keep_alive;
1806 if (virt->keep_alive_max == -1)
1807 virt->keep_alive_max = main_server->keep_alive_max;
1809 /* XXX: this is really something that should be dealt with by a
1810 * post-config api phase
1812 ap_core_reorder_directories(p, virt);
1815 ap_core_reorder_directories(p, main_server);
1818 /*****************************************************************
1820 * Getting *everything* configured...
1823 static void init_config_globals(apr_pool_t *p)
1825 /* Global virtual host hash bucket pointers. Init to null. */
1826 ap_init_vhost_config(p);
1829 static server_rec *init_server_config(process_rec *process, apr_pool_t *p)
1832 server_rec *s = (server_rec *) apr_pcalloc(p, sizeof(server_rec));
1834 apr_file_open_stderr(&s->error_log, p);
1835 s->process = process;
1837 s->server_admin = DEFAULT_ADMIN;
1838 s->server_hostname = NULL;
1839 s->error_fname = DEFAULT_ERRORLOG;
1840 s->loglevel = DEFAULT_LOGLEVEL;
1841 s->limit_req_line = DEFAULT_LIMIT_REQUEST_LINE;
1842 s->limit_req_fieldsize = DEFAULT_LIMIT_REQUEST_FIELDSIZE;
1843 s->limit_req_fields = DEFAULT_LIMIT_REQUEST_FIELDS;
1844 s->timeout = apr_time_from_sec(DEFAULT_TIMEOUT);
1845 s->keep_alive_timeout = apr_time_from_sec(DEFAULT_KEEPALIVE_TIMEOUT);
1846 s->keep_alive_max = DEFAULT_KEEPALIVE;
1849 s->addrs = apr_pcalloc(p, sizeof(server_addr_rec));
1851 /* NOT virtual host; don't match any real network interface */
1852 rv = apr_sockaddr_info_get(&s->addrs->host_addr,
1853 NULL, APR_INET, 0, 0, p);
1854 ap_assert(rv == APR_SUCCESS); /* otherwise: bug or no storage */
1856 s->addrs->host_port = 0; /* matches any port */
1857 s->addrs->virthost = ""; /* must be non-NULL */
1858 s->names = s->wild_names = NULL;
1860 s->module_config = create_server_config(p, s);
1861 s->lookup_defaults = create_default_per_dir_config(p);
1867 AP_DECLARE(server_rec*) ap_read_config(process_rec *process, apr_pool_t *ptemp,
1868 const char *filename,
1869 ap_directive_t **conftree)
1871 const char *confname, *error;
1872 apr_pool_t *p = process->pconf;
1873 server_rec *s = init_server_config(process, p);
1875 init_config_globals(p);
1877 /* All server-wide config files now have the SAME syntax... */
1878 error = process_command_config(s, ap_server_pre_read_config, conftree,
1881 ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_CRIT, 0, NULL, "%s: %s",
1882 ap_server_argv0, error);
1886 /* process_command_config may change the ServerRoot so
1887 * compute this config file name afterwards.
1889 confname = ap_server_root_relative(p, filename);
1892 ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_CRIT,
1893 APR_EBADPATH, NULL, "Invalid config file path %s",
1898 error = ap_process_resource_config(s, confname, conftree, p, ptemp);
1900 ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_CRIT, 0, NULL,
1901 "%s: %s", ap_server_argv0, error);
1905 error = process_command_config(s, ap_server_post_read_config, conftree,
1909 ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_CRIT, 0, NULL, "%s: %s",
1910 ap_server_argv0, error);
1917 AP_DECLARE(void) ap_single_module_configure(apr_pool_t *p, server_rec *s,
1920 if (m->create_server_config)
1921 ap_set_module_config(s->module_config, m,
1922 (*m->create_server_config)(p, s));
1924 if (m->create_dir_config)
1925 ap_set_module_config(s->lookup_defaults, m,
1926 (*m->create_dir_config)(p, NULL));
1929 AP_DECLARE(void) ap_run_rewrite_args(process_rec *process)
1933 for (m = ap_top_module; m; m = m->next) {
1934 if (m->rewrite_args) {
1935 (*m->rewrite_args)(process);
1940 /********************************************************************
1941 * Configuration directives are restricted in terms of where they may
1942 * appear in the main configuration files and/or .htaccess files according
1943 * to the bitmask req_override in the command_rec structure.
1944 * If any of the overrides set in req_override are also allowed in the
1945 * context in which the command is read, then the command is allowed.
1946 * The context is determined as follows:
1948 * inside *.conf --> override = (RSRC_CONF|OR_ALL)&~(OR_AUTHCFG|OR_LIMIT);
1949 * within <Directory> or <Location> --> override = OR_ALL|ACCESS_CONF;
1950 * within .htaccess --> override = AllowOverride for current directory;
1952 * the result is, well, a rather confusing set of possibilities for when
1953 * a particular directive is allowed to be used. This procedure prints
1954 * in English where the given (pc) directive can be used.
1956 static void show_overrides(const command_rec *pc, module *pm)
1960 printf("\tAllowed in *.conf ");
1961 if ((pc->req_override & (OR_OPTIONS | OR_FILEINFO | OR_INDEXES))
1962 || ((pc->req_override & RSRC_CONF)
1963 && ((pc->req_override & (ACCESS_CONF | OR_AUTHCFG | OR_LIMIT))))) {
1966 else if (pc->req_override & RSRC_CONF) {
1967 printf("only outside <Directory>, <Files> or <Location>");
1970 printf("only inside <Directory>, <Files> or <Location>");
1973 /* Warn if the directive is allowed inside <Directory> or .htaccess
1974 * but module doesn't support per-dir configuration
1976 if ((pc->req_override & (OR_ALL | ACCESS_CONF)) && !pm->create_dir_config)
1977 printf(" [no per-dir config]");
1979 if (pc->req_override & OR_ALL) {
1980 printf(" and in .htaccess\n\twhen AllowOverride");
1982 if ((pc->req_override & OR_ALL) == OR_ALL) {
1983 printf(" isn't None");
1986 printf(" includes ");
1988 if (pc->req_override & OR_AUTHCFG) {
1992 printf("AuthConfig");
1995 if (pc->req_override & OR_LIMIT) {
2002 if (pc->req_override & OR_OPTIONS) {
2009 if (pc->req_override & OR_FILEINFO) {
2016 if (pc->req_override & OR_INDEXES) {
2028 /* Show the preloaded configuration directives, the help string explaining
2029 * the directive arguments, in what module they are handled, and in
2030 * what parts of the configuration they are allowed. Used for httpd -L.
2032 AP_DECLARE(void) ap_show_directives(void)
2034 const command_rec *pc;
2037 for (n = 0; ap_loaded_modules[n]; ++n) {
2038 for (pc = ap_loaded_modules[n]->cmds; pc && pc->name; ++pc) {
2039 printf("%s (%s)\n", pc->name, ap_loaded_modules[n]->name);
2042 printf("\t%s\n", pc->errmsg);
2044 show_overrides(pc, ap_loaded_modules[n]);
2049 /* Show the preloaded module names. Used for httpd -l. */
2050 AP_DECLARE(void) ap_show_modules(void)
2054 printf("Compiled in modules:\n");
2055 for (n = 0; ap_loaded_modules[n]; ++n)
2056 printf(" %s\n", ap_loaded_modules[n]->name);
2059 AP_DECLARE(const char *) ap_show_mpm(void)