1 /* Copyright 1999-2004 The Apache Software Foundation
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
17 * http_config.c: once was auxillary functions for reading httpd's config
18 * file and converting filenames into a namespace
22 * Wall-to-wall rewrite for Apache... commands which are part of the
23 * server core can now be found next door in "http_core.c". Now contains
24 * general command loop, and functions which do bookkeeping for the new
25 * Apache config stuff (modules and configuration vectors).
32 #include "apr_strings.h"
33 #include "apr_portable.h"
34 #include "apr_file_io.h"
35 #include "apr_fnmatch.h"
37 #define APR_WANT_STDIO
38 #define APR_WANT_STRFUNC
43 #include "ap_config.h"
45 #include "http_config.h"
46 #include "http_protocol.h"
47 #include "http_core.h"
48 #include "http_log.h" /* for errors in parse_htaccess */
49 #include "http_request.h" /* for default_handler (see invoke_handler) */
50 #include "http_main.h"
51 #include "http_vhost.h"
52 #include "util_cfgtree.h"
56 AP_DECLARE_DATA const char *ap_server_argv0 = NULL;
58 AP_DECLARE_DATA const char *ap_server_root = NULL;
60 AP_DECLARE_DATA apr_array_header_t *ap_server_pre_read_config = NULL;
61 AP_DECLARE_DATA apr_array_header_t *ap_server_post_read_config = NULL;
62 AP_DECLARE_DATA apr_array_header_t *ap_server_config_defines = NULL;
64 AP_DECLARE_DATA ap_directive_t *ap_conftree = NULL;
67 APR_HOOK_LINK(header_parser)
68 APR_HOOK_LINK(pre_config)
69 APR_HOOK_LINK(post_config)
70 APR_HOOK_LINK(open_logs)
71 APR_HOOK_LINK(child_init)
72 APR_HOOK_LINK(handler)
73 APR_HOOK_LINK(quick_handler)
74 APR_HOOK_LINK(optional_fn_retrieve)
77 AP_IMPLEMENT_HOOK_RUN_ALL(int, header_parser,
78 (request_rec *r), (r), OK, DECLINED)
80 AP_IMPLEMENT_HOOK_RUN_ALL(int, pre_config,
81 (apr_pool_t *pconf, apr_pool_t *plog,
83 (pconf, plog, ptemp), OK, DECLINED)
85 AP_IMPLEMENT_HOOK_RUN_ALL(int, post_config,
86 (apr_pool_t *pconf, apr_pool_t *plog,
87 apr_pool_t *ptemp, server_rec *s),
88 (pconf, plog, ptemp, s), OK, DECLINED)
90 /* During the course of debugging I expanded this macro out, so
91 * rather than remove all the useful information there is in the
92 * following lines, I'm going to leave it here in case anyone
93 * else finds it useful.
95 * Ben has looked at it and thinks it correct :)
97 AP_DECLARE(int) ap_hook_post_config(ap_HOOK_post_config_t *pf,
98 const char * const *aszPre,
99 const char * const *aszSucc,
102 ap_LINK_post_config_t *pHook;
104 if (!_hooks.link_post_config) {
105 _hooks.link_post_config = apr_array_make(apr_hook_global_pool, 1,
106 sizeof(ap_LINK_post_config_t));
107 apr_hook_sort_register("post_config", &_hooks.link_post_config);
110 pHook = apr_array_push(_hooks.link_post_config);
112 pHook->aszPredecessors = aszPre;
113 pHook->aszSuccessors = aszSucc;
114 pHook->nOrder = nOrder;
115 pHook->szName = apr_hook_debug_current;
117 if (apr_hook_debug_enabled)
118 apr_hook_debug_show("post_config", aszPre, aszSucc);
121 AP_DECLARE(apr_array_header_t *) ap_hook_get_post_config(void) {
122 return _hooks.link_post_config;
125 AP_DECLARE(int) ap_run_post_config(apr_pool_t *pconf,
130 ap_LINK_post_config_t *pHook;
133 if(!_hooks.link_post_config)
136 pHook = (ap_LINK_post_config_t *)_hooks.link_post_config->elts;
137 for (n = 0; n < _hooks.link_post_config->nelts; ++n)
138 pHook[n].pFunc (pconf, plog, ptemp, s);
142 AP_IMPLEMENT_HOOK_RUN_ALL(int, open_logs,
143 (apr_pool_t *pconf, apr_pool_t *plog,
144 apr_pool_t *ptemp, server_rec *s),
145 (pconf, plog, ptemp, s), OK, DECLINED)
147 AP_IMPLEMENT_HOOK_VOID(child_init,
148 (apr_pool_t *pchild, server_rec *s),
151 AP_IMPLEMENT_HOOK_RUN_FIRST(int, handler, (request_rec *r),
154 AP_IMPLEMENT_HOOK_RUN_FIRST(int, quick_handler, (request_rec *r, int lookup),
155 (r, lookup), DECLINED)
157 AP_IMPLEMENT_HOOK_VOID(optional_fn_retrieve, (void), ())
159 /****************************************************************
161 * We begin with the functions which deal with the linked list
162 * of modules which control just about all of the server operation.
165 /* total_modules is the number of modules that have been linked
168 static int total_modules = 0;
170 /* dynamic_modules is the number of modules that have been added
171 * after the pre-loaded ones have been set up. It shouldn't be larger
172 * than DYNAMIC_MODULE_LIMIT.
174 static int dynamic_modules = 0;
176 AP_DECLARE_DATA module *ap_top_module = NULL;
177 AP_DECLARE_DATA module **ap_loaded_modules=NULL;
179 typedef int (*handler_func)(request_rec *);
180 typedef void *(*dir_maker_func)(apr_pool_t *, char *);
181 typedef void *(*merger_func)(apr_pool_t *, void *, void *);
183 /* maximum nesting level for config directories */
184 #ifndef AP_MAX_INCLUDE_DIR_DEPTH
185 #define AP_MAX_INCLUDE_DIR_DEPTH (128)
188 /* Dealing with config vectors. These are associated with per-directory,
189 * per-server, and per-request configuration, and have a void* pointer for
190 * each modules. The nature of the structure pointed to is private to the
191 * module in question... the core doesn't (and can't) know. However, there
192 * are defined interfaces which allow it to create instances of its private
193 * per-directory and per-server structures, and to merge the per-directory
194 * structures of a directory and its subdirectory (producing a new one in
195 * which the defaults applying to the base directory have been properly
199 static ap_conf_vector_t *create_empty_config(apr_pool_t *p)
201 void *conf_vector = apr_pcalloc(p, sizeof(void *) *
202 (total_modules + DYNAMIC_MODULE_LIMIT));
206 static ap_conf_vector_t *create_default_per_dir_config(apr_pool_t *p)
208 void **conf_vector = apr_pcalloc(p, sizeof(void *) *
209 (total_modules + DYNAMIC_MODULE_LIMIT));
212 for (modp = ap_top_module; modp; modp = modp->next) {
213 dir_maker_func df = modp->create_dir_config;
216 conf_vector[modp->module_index] = (*df)(p, NULL);
219 return (ap_conf_vector_t *)conf_vector;
222 AP_CORE_DECLARE(ap_conf_vector_t *) ap_merge_per_dir_configs(apr_pool_t *p,
223 ap_conf_vector_t *base,
224 ap_conf_vector_t *new_conf)
226 void **conf_vector = apr_palloc(p, sizeof(void *) * total_modules);
227 void **base_vector = (void **)base;
228 void **new_vector = (void **)new_conf;
231 for (modp = ap_top_module; modp; modp = modp->next) {
232 int i = modp->module_index;
234 if (!new_vector[i]) {
235 conf_vector[i] = base_vector[i];
238 merger_func df = modp->merge_dir_config;
239 if (df && base_vector[i]) {
240 conf_vector[i] = (*df)(p, base_vector[i], new_vector[i]);
243 conf_vector[i] = new_vector[i];
247 return (ap_conf_vector_t *)conf_vector;
250 static ap_conf_vector_t *create_server_config(apr_pool_t *p, server_rec *s)
252 void **conf_vector = apr_pcalloc(p, sizeof(void *) *
253 (total_modules + DYNAMIC_MODULE_LIMIT));
256 for (modp = ap_top_module; modp; modp = modp->next) {
257 if (modp->create_server_config)
258 conf_vector[modp->module_index] = (*modp->create_server_config)(p, s);
261 return (ap_conf_vector_t *)conf_vector;
264 static void merge_server_configs(apr_pool_t *p, ap_conf_vector_t *base,
265 ap_conf_vector_t *virt)
267 /* Can reuse the 'virt' vector for the spine of it, since we don't
268 * have to deal with the moral equivalent of .htaccess files here...
271 void **base_vector = (void **)base;
272 void **virt_vector = (void **)virt;
275 for (modp = ap_top_module; modp; modp = modp->next) {
276 merger_func df = modp->merge_server_config;
277 int i = modp->module_index;
280 virt_vector[i] = base_vector[i];
282 virt_vector[i] = (*df)(p, base_vector[i], virt_vector[i]);
286 AP_CORE_DECLARE(ap_conf_vector_t *) ap_create_request_config(apr_pool_t *p)
288 return create_empty_config(p);
291 AP_CORE_DECLARE(ap_conf_vector_t *) ap_create_conn_config(apr_pool_t *p)
293 return create_empty_config(p);
296 AP_CORE_DECLARE(ap_conf_vector_t *) ap_create_per_dir_config(apr_pool_t *p)
298 return create_empty_config(p);
301 static int ap_invoke_filter_init(ap_filter_t *filters)
304 if (filters->frec->filter_init_func) {
305 int result = filters->frec->filter_init_func(filters);
310 filters = filters->next;
315 AP_CORE_DECLARE(int) ap_invoke_handler(request_rec *r)
320 const char *old_handler = r->handler;
323 * The new insert_filter stage makes the most sense here. We only use
324 * it when we are going to run the request, so we must insert filters
325 * if any are available. Since the goal of this phase is to allow all
326 * modules to insert a filter if they want to, this filter returns
327 * void. I just can't see any way that this filter can reasonably
328 * fail, either your modules inserts something or it doesn't. rbb
330 ap_run_insert_filter(r);
332 /* Before continuing, allow each filter that is in the two chains to
333 * run their init function to let them do any magic before we could
334 * start generating data.
336 result = ap_invoke_filter_init(r->input_filters);
340 result = ap_invoke_filter_init(r->output_filters);
346 handler = r->content_type ? r->content_type : ap_default_type(r);
347 if ((p=ap_strchr_c(handler, ';')) != NULL) {
348 char *new_handler = (char *)apr_pmemdup(r->pool, handler,
350 char *p2 = new_handler + (p - handler);
351 handler = new_handler;
353 /* MIME type arguments */
354 while (p2 > handler && p2[-1] == ' ')
355 --p2; /* strip trailing spaces */
360 r->handler = handler;
363 result = ap_run_handler(r);
365 r->handler = old_handler;
367 if (result == DECLINED && r->handler && r->filename) {
368 ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r,
369 "handler \"%s\" not found for: %s", r->handler, r->filename);
372 return result == DECLINED ? HTTP_INTERNAL_SERVER_ERROR : result;
375 AP_DECLARE(int) ap_method_is_limited(cmd_parms *cmd, const char *method)
379 methnum = ap_method_number_of(method);
382 * A method number either hardcoded into apache or
383 * added by a module and registered.
385 if (methnum != M_INVALID) {
386 return (cmd->limited & (AP_METHOD_BIT << methnum)) ? 1 : 0;
389 return 0; /* not found */
392 AP_DECLARE(void) ap_register_hooks(module *m, apr_pool_t *p)
394 if (m->register_hooks) {
395 if (getenv("SHOW_HOOKS")) {
396 printf("Registering hooks for %s\n", m->name);
397 apr_hook_debug_enabled = 1;
400 apr_hook_debug_current = m->name;
401 m->register_hooks(p);
405 /* One-time setup for precompiled modules --- NOT to be done on restart */
407 AP_DECLARE(const char *) ap_add_module(module *m, apr_pool_t *p)
409 /* This could be called from a LoadModule httpd.conf command,
410 * after the file has been linked and the module structure within it
414 if (m->version != MODULE_MAGIC_NUMBER_MAJOR) {
415 return apr_psprintf(p, "Module \"%s\" is not compatible with this "
416 "version of Apache (found %d, need %d). Please "
417 "contact the vendor for the correct version.",
418 m->name, m->version, MODULE_MAGIC_NUMBER_MAJOR);
421 if (m->next == NULL) {
422 m->next = ap_top_module;
426 if (m->module_index == -1) {
427 m->module_index = total_modules++;
430 if (dynamic_modules > DYNAMIC_MODULE_LIMIT) {
431 return apr_psprintf(p, "Module \"%s\" could not be loaded, "
432 "because the dynamic module limit was "
433 "reached. Please increase "
434 "DYNAMIC_MODULE_LIMIT and recompile.", m->name);
438 /* Some C compilers put a complete path into __FILE__, but we want
439 * only the filename (e.g. mod_includes.c). So check for path
440 * components (Unix and DOS), and remove them.
443 if (ap_strrchr_c(m->name, '/'))
444 m->name = 1 + ap_strrchr_c(m->name, '/');
446 if (ap_strrchr_c(m->name, '\\'))
447 m->name = 1 + ap_strrchr_c(m->name, '\\');
451 * "*POSIX(/home/martin/apache/src/modules/standard/mod_info.c)"
454 /* We cannot fix the string in-place, because it's const */
455 if (m->name[strlen(m->name)-1] == ')') {
456 char *tmp = strdup(m->name); /* FIXME: memory leak, albeit a small one */
457 tmp[strlen(tmp)-1] = '\0';
460 #endif /*_OSD_POSIX*/
462 /* FIXME: is this the right place to call this?
463 * It doesn't appear to be
465 ap_register_hooks(m, p);
471 * remove_module undoes what add_module did. There are some caveats:
472 * when the module is removed, its slot is lost so all the current
473 * per-dir and per-server configurations are invalid. So we should
474 * only ever call this function when you are invalidating almost
475 * all our current data. I.e. when doing a restart.
478 AP_DECLARE(void) ap_remove_module(module *m)
482 modp = ap_top_module;
484 /* We are the top module, special case */
485 ap_top_module = modp->next;
489 /* Not the top module, find use. When found modp will
490 * point to the module _before_ us in the list
493 while (modp && modp->next != m) {
498 /* Uh-oh, this module doesn't exist */
499 ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL,
500 "Cannot remove module %s: not found in module list",
505 /* Eliminate us from the module list */
506 modp->next = modp->next->next;
509 m->module_index = -1; /* simulate being unloaded, should
515 AP_DECLARE(const char *) ap_add_loaded_module(module *mod, apr_pool_t *p)
521 * Add module pointer to top of chained module list
523 error = ap_add_module(mod, p);
529 * And module pointer to list of loaded modules
531 * Notes: 1. ap_add_module() would already complain if no more space
532 * exists for adding a dynamically loaded module
533 * 2. ap_add_module() accepts double inclusion, so we have
534 * to accept this, too.
536 for (m = ap_loaded_modules; *m != NULL; m++)
544 AP_DECLARE(void) ap_remove_loaded_module(module *mod)
551 * Remove module pointer from chained module list
553 ap_remove_module(mod);
556 * Remove module pointer from list of loaded modules
558 * Note: 1. We cannot determine if the module was successfully
559 * removed by ap_remove_module().
560 * 2. We have not to complain explicity when the module
561 * is not found because ap_remove_module() did it
564 for (m = m2 = ap_loaded_modules, done = 0; *m2 != NULL; m2++) {
565 if (*m2 == mod && done == 0)
574 AP_DECLARE(const char *) ap_setup_prelinked_modules(process_rec *process)
580 apr_hook_global_pool=process->pconf;
583 * Initialise total_modules variable and module indices
586 for (m = ap_preloaded_modules; *m != NULL; m++)
587 (*m)->module_index = total_modules++;
590 * Initialise list of loaded modules
592 ap_loaded_modules = (module **)apr_palloc(process->pool,
593 sizeof(module *) * (total_modules + DYNAMIC_MODULE_LIMIT + 1));
595 if (ap_loaded_modules == NULL) {
596 return "Ouch! Out of memory in ap_setup_prelinked_modules()!";
599 for (m = ap_preloaded_modules, m2 = ap_loaded_modules; *m != NULL; )
605 * Initialize chain of linked (=activate) modules
607 for (m = ap_prelinked_modules; *m != NULL; m++) {
608 error = ap_add_module(*m, process->pconf);
619 AP_DECLARE(const char *) ap_find_module_name(module *m)
624 AP_DECLARE(module *) ap_find_linked_module(const char *name)
628 for (modp = ap_top_module; modp; modp = modp->next) {
629 if (strcmp(modp->name, name) == 0)
636 /*****************************************************************
638 * Resource, access, and .htaccess config files now parsed by a common
641 * Let's begin with the basics; parsing the line and
642 * invoking the function...
645 static const char *invoke_cmd(const command_rec *cmd, cmd_parms *parms,
646 void *mconfig, const char *args)
649 const char *errmsg = NULL;
651 if ((parms->override & cmd->req_override) == 0)
652 return apr_pstrcat(parms->pool, cmd->name, " not allowed here", NULL);
654 parms->info = cmd->cmd_data;
657 switch (cmd->args_how) {
659 #ifdef RESOLVE_ENV_PER_TOKEN
660 args = ap_resolve_env(parms->pool,args);
662 return cmd->AP_RAW_ARGS(parms, mconfig, args);
666 return apr_pstrcat(parms->pool, cmd->name, " takes no arguments",
669 return cmd->AP_NO_ARGS(parms, mconfig);
672 w = ap_getword_conf(parms->pool, &args);
674 if (*w == '\0' || *args != 0)
675 return apr_pstrcat(parms->pool, cmd->name, " takes one argument",
676 cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
678 return cmd->AP_TAKE1(parms, mconfig, w);
681 w = ap_getword_conf(parms->pool, &args);
682 w2 = ap_getword_conf(parms->pool, &args);
684 if (*w == '\0' || *w2 == '\0' || *args != 0)
685 return apr_pstrcat(parms->pool, cmd->name, " takes two arguments",
686 cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
688 return cmd->AP_TAKE2(parms, mconfig, w, w2);
691 w = ap_getword_conf(parms->pool, &args);
692 w2 = ap_getword_conf(parms->pool, &args);
694 if (*w == '\0' || *args != 0)
695 return apr_pstrcat(parms->pool, cmd->name, " takes 1-2 arguments",
696 cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
698 return cmd->AP_TAKE2(parms, mconfig, w, *w2 ? w2 : NULL);
701 w = ap_getword_conf(parms->pool, &args);
702 w2 = ap_getword_conf(parms->pool, &args);
703 w3 = ap_getword_conf(parms->pool, &args);
705 if (*w == '\0' || *w2 == '\0' || *w3 == '\0' || *args != 0)
706 return apr_pstrcat(parms->pool, cmd->name, " takes three arguments",
707 cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
709 return cmd->AP_TAKE3(parms, mconfig, w, w2, w3);
712 w = ap_getword_conf(parms->pool, &args);
713 w2 = ap_getword_conf(parms->pool, &args);
714 w3 = *args ? ap_getword_conf(parms->pool, &args) : NULL;
716 if (*w == '\0' || *w2 == '\0' || *args != 0)
717 return apr_pstrcat(parms->pool, cmd->name,
718 " takes two or three arguments",
719 cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
721 return cmd->AP_TAKE3(parms, mconfig, w, w2, w3);
724 w = ap_getword_conf(parms->pool, &args);
725 w2 = *args ? ap_getword_conf(parms->pool, &args) : NULL;
726 w3 = *args ? ap_getword_conf(parms->pool, &args) : NULL;
728 if (*w == '\0' || *args != 0)
729 return apr_pstrcat(parms->pool, cmd->name,
730 " takes one, two or three arguments",
731 cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
733 return cmd->AP_TAKE3(parms, mconfig, w, w2, w3);
736 w = ap_getword_conf(parms->pool, &args);
737 w2 = *args ? ap_getword_conf(parms->pool, &args) : NULL;
738 w3 = *args ? ap_getword_conf(parms->pool, &args) : NULL;
740 if (*w == '\0' || (w2 && *w2 && !w3) || *args != 0)
741 return apr_pstrcat(parms->pool, cmd->name,
742 " takes one or three arguments",
743 cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
745 return cmd->AP_TAKE3(parms, mconfig, w, w2, w3);
748 while (*(w = ap_getword_conf(parms->pool, &args)) != '\0') {
750 errmsg = cmd->AP_TAKE1(parms, mconfig, w);
752 if (errmsg && strcmp(errmsg, DECLINE_CMD) != 0)
759 w = ap_getword_conf(parms->pool, &args);
761 if (*w == '\0' || *args == 0)
762 return apr_pstrcat(parms->pool, cmd->name,
763 " requires at least two arguments",
764 cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
766 while (*(w2 = ap_getword_conf(parms->pool, &args)) != '\0') {
768 errmsg = cmd->AP_TAKE2(parms, mconfig, w, w2);
770 if (errmsg && strcmp(errmsg, DECLINE_CMD) != 0)
777 w = ap_getword_conf(parms->pool, &args);
779 if (*w == '\0' || (strcasecmp(w, "on") && strcasecmp(w, "off")))
780 return apr_pstrcat(parms->pool, cmd->name, " must be On or Off",
783 return cmd->AP_FLAG(parms, mconfig, strcasecmp(w, "off") != 0);
786 return apr_pstrcat(parms->pool, cmd->name,
787 " is improperly configured internally (server bug)",
792 AP_CORE_DECLARE(const command_rec *) ap_find_command(const char *name,
793 const command_rec *cmds)
796 if (!strcasecmp(name, cmds->name))
805 AP_CORE_DECLARE(const command_rec *) ap_find_command_in_modules(
806 const char *cmd_name, module **mod)
808 const command_rec *cmdp;
811 for (modp = *mod; modp; modp = modp->next) {
812 if (modp->cmds && (cmdp = ap_find_command(cmd_name, modp->cmds))) {
821 AP_CORE_DECLARE(void *) ap_set_config_vectors(server_rec *server,
822 ap_conf_vector_t *section_vector,
824 module *mod, apr_pool_t *pconf)
826 void *section_config = ap_get_module_config(section_vector, mod);
827 void *server_config = ap_get_module_config(server->module_config, mod);
829 if (!section_config && mod->create_dir_config) {
830 /* ### need to fix the create_dir_config functions' prototype... */
831 section_config = (*mod->create_dir_config)(pconf, (char *)section);
832 ap_set_module_config(section_vector, mod, section_config);
835 if (!server_config && mod->create_server_config) {
836 server_config = (*mod->create_server_config)(pconf, server);
837 ap_set_module_config(server->module_config, mod, server_config);
840 return section_config;
843 static const char *execute_now(char *cmd_line, const char *args,
845 apr_pool_t *p, apr_pool_t *ptemp,
846 ap_directive_t **sub_tree,
847 ap_directive_t *parent);
849 static const char *ap_build_config_sub(apr_pool_t *p, apr_pool_t *temp_pool,
850 const char *l, cmd_parms *parms,
851 ap_directive_t **current,
852 ap_directive_t **curr_parent,
853 ap_directive_t **conftree)
855 const char *retval = NULL;
858 ap_directive_t *newdir;
859 module *mod = ap_top_module;
860 const command_rec *cmd;
862 if (*l == '#' || *l == '\0')
865 #if RESOLVE_ENV_PER_TOKEN
868 args = ap_resolve_env(temp_pool, l);
871 cmd_name = ap_getword_conf(p, &args);
872 if (*cmd_name == '\0') {
873 /* Note: this branch should not occur. An empty line should have
874 * triggered the exit further above.
879 if (cmd_name[1] != '/') {
880 char *lastc = cmd_name + strlen(cmd_name) - 1;
884 if (cmd_name[0] == '<' && *args == '\0') {
889 newdir = apr_pcalloc(p, sizeof(ap_directive_t));
890 newdir->filename = parms->config_file->name;
891 newdir->line_num = parms->config_file->line_number;
892 newdir->directive = cmd_name;
893 newdir->args = apr_pstrdup(p, args);
895 if ((cmd = ap_find_command_in_modules(cmd_name, &mod)) != NULL) {
896 if (cmd->req_override & EXEC_ON_READ) {
897 ap_directive_t *sub_tree = NULL;
899 parms->err_directive = newdir;
900 retval = execute_now(cmd_name, args, parms, p, temp_pool,
901 &sub_tree, *curr_parent);
903 (*current)->next = sub_tree;
908 (*curr_parent)->first_child = (*current);
911 (*current)->parent = (*curr_parent);
916 /* Before walking *current to the end of the list,
917 * set the head to *current.
919 *conftree = *current;
921 while ((*current)->next != NULL) {
922 (*current) = (*current)->next;
923 (*current)->parent = (*curr_parent);
930 if (cmd_name[0] == '<') {
931 if (cmd_name[1] != '/') {
932 (*current) = ap_add_node(curr_parent, *current, newdir, 1);
934 else if (*curr_parent == NULL) {
935 parms->err_directive = newdir;
936 return apr_pstrcat(p, cmd_name,
937 " without matching <", cmd_name + 2,
941 char *bracket = cmd_name + strlen(cmd_name) - 1;
943 if (*bracket != '>') {
944 parms->err_directive = newdir;
945 return apr_pstrcat(p, cmd_name,
946 "> directive missing closing '>'", NULL);
951 if (strcasecmp(cmd_name + 2,
952 (*curr_parent)->directive + 1) != 0) {
953 parms->err_directive = newdir;
954 return apr_pstrcat(p, "Expected </",
955 (*curr_parent)->directive + 1, "> but saw ",
956 cmd_name, ">", NULL);
961 /* done with this section; move up a level */
962 *current = *curr_parent;
963 *curr_parent = (*current)->parent;
967 *current = ap_add_node(curr_parent, *current, newdir, 0);
973 AP_DECLARE(const char *) ap_build_cont_config(apr_pool_t *p,
974 apr_pool_t *temp_pool,
976 ap_directive_t **current,
977 ap_directive_t **curr_parent,
978 char *orig_directive)
983 ap_directive_t *sub_tree = NULL;
985 /* Since this function can be called recursively, allocate
986 * the temporary 8k string buffer from the temp_pool rather
987 * than the stack to avoid over-running a fixed length stack.
989 l = apr_palloc(temp_pool, MAX_STRING_LEN);
991 bracket = apr_pstrcat(p, orig_directive + 1, ">", NULL);
992 while (!(ap_cfg_getline(l, MAX_STRING_LEN, parms->config_file))) {
993 if (!memcmp(l, "</", 2)
994 && (strcasecmp(l + 2, bracket) == 0)
995 && (*curr_parent == NULL)) {
998 retval = ap_build_config_sub(p, temp_pool, l, parms, current,
999 curr_parent, &sub_tree);
1003 if (sub_tree == NULL && curr_parent != NULL) {
1004 sub_tree = *curr_parent;
1007 if (sub_tree == NULL && current != NULL) {
1008 sub_tree = *current;
1012 *current = sub_tree;
1016 static const char *ap_walk_config_sub(const ap_directive_t *current,
1018 ap_conf_vector_t *section_vector)
1020 module *mod = ap_top_module;
1023 const command_rec *cmd;
1025 if (!(cmd = ap_find_command_in_modules(current->directive, &mod))) {
1026 parms->err_directive = current;
1027 return apr_pstrcat(parms->pool, "Invalid command '",
1029 "', perhaps mis-spelled or defined by a module "
1030 "not included in the server configuration",
1034 void *dir_config = ap_set_config_vectors(parms->server,
1041 /* Once was enough? */
1042 if (cmd->req_override & EXEC_ON_READ) {
1046 retval = invoke_cmd(cmd, parms, dir_config, current->args);
1047 if (retval == NULL) {
1051 if (strcmp(retval, DECLINE_CMD) != 0) {
1052 /* If the directive in error has already been set, don't
1053 * replace it. Otherwise, an error inside a container
1054 * will be reported as occuring on the first line of the
1057 if (!parms->err_directive) {
1058 parms->err_directive = current;
1064 mod = mod->next; /* Next time around, skip this one */
1070 AP_DECLARE(const char *) ap_walk_config(ap_directive_t *current,
1072 ap_conf_vector_t *section_vector)
1074 ap_conf_vector_t *oldconfig = parms->context;
1076 parms->context = section_vector;
1078 /* scan through all directives, executing each one */
1079 for (; current != NULL; current = current->next) {
1082 parms->directive = current;
1084 /* actually parse the command and execute the correct function */
1085 errmsg = ap_walk_config_sub(current, parms, section_vector);
1086 if (errmsg != NULL) {
1087 /* restore the context (just in case) */
1088 parms->context = oldconfig;
1093 parms->context = oldconfig;
1097 AP_DECLARE(const char *) ap_build_config(cmd_parms *parms,
1098 apr_pool_t *p, apr_pool_t *temp_pool,
1099 ap_directive_t **conftree)
1101 ap_directive_t *current = *conftree;
1102 ap_directive_t *curr_parent = NULL;
1103 char *l = apr_palloc (temp_pool, MAX_STRING_LEN);
1106 if (current != NULL) {
1107 while (current->next) {
1108 current = current->next;
1112 while (!(ap_cfg_getline(l, MAX_STRING_LEN, parms->config_file))) {
1113 errmsg = ap_build_config_sub(p, temp_pool, l, parms,
1114 ¤t, &curr_parent, conftree);
1118 if (*conftree == NULL && curr_parent != NULL) {
1119 *conftree = curr_parent;
1122 if (*conftree == NULL && current != NULL) {
1123 *conftree = current;
1127 if (curr_parent != NULL) {
1130 while (curr_parent != NULL) {
1131 errmsg = apr_psprintf(p, "%s%s%s:%u: %s> was not closed.",
1133 *errmsg == '\0' ? "" : APR_EOL_STR,
1134 curr_parent->filename,
1135 curr_parent->line_num,
1136 curr_parent->directive);
1138 parms->err_directive = curr_parent;
1139 curr_parent = curr_parent->parent;
1149 * Generic command functions...
1152 AP_DECLARE_NONSTD(const char *) ap_set_string_slot(cmd_parms *cmd,
1156 int offset = (int)(long)cmd->info;
1158 *(const char **)((char *)struct_ptr + offset) = arg;
1163 AP_DECLARE_NONSTD(const char *) ap_set_int_slot(cmd_parms *cmd,
1168 char *error_str = NULL;
1169 int offset = (int)(long)cmd->info;
1171 *(int *)((char*)struct_ptr + offset) = strtol(arg, &endptr, 10);
1173 if ((*arg == '\0') || (*endptr != '\0')) {
1174 error_str = apr_psprintf(cmd->pool,
1175 "Invalid value for directive %s, expected integer",
1176 cmd->directive->directive);
1182 AP_DECLARE_NONSTD(const char *) ap_set_string_slot_lower(cmd_parms *cmd,
1186 char *arg = apr_pstrdup(cmd->pool,arg_);
1187 int offset = (int)(long)cmd->info;
1189 ap_str_tolower(arg);
1190 *(char **)((char *)struct_ptr + offset) = arg;
1195 AP_DECLARE_NONSTD(const char *) ap_set_flag_slot(cmd_parms *cmd,
1196 void *struct_ptr_v, int arg)
1198 int offset = (int)(long)cmd->info;
1199 char *struct_ptr = (char *)struct_ptr_v;
1201 *(int *)(struct_ptr + offset) = arg ? 1 : 0;
1206 AP_DECLARE_NONSTD(const char *) ap_set_file_slot(cmd_parms *cmd, void *struct_ptr,
1209 /* Prepend server_root to relative arg.
1210 * This allows most args to be independent of server_root,
1211 * so the server can be moved or mirrored with less pain.
1214 int offset = (int)(long)cmd->info;
1216 path = ap_server_root_relative(cmd->pool, arg);
1219 return apr_pstrcat(cmd->pool, "Invalid file path ",
1223 *(const char **) ((char*)struct_ptr + offset) = path;
1228 AP_DECLARE_NONSTD(const char *) ap_set_deprecated(cmd_parms *cmd,
1232 return cmd->cmd->errmsg;
1235 /*****************************************************************
1237 * Reading whole config files...
1240 static cmd_parms default_parms =
1241 {NULL, 0, -1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
1243 AP_DECLARE(char *) ap_server_root_relative(apr_pool_t *p, const char *file)
1245 char *newpath = NULL;
1247 rv = apr_filepath_merge(&newpath, ap_server_root, file,
1248 APR_FILEPATH_TRUENAME, p);
1249 if (newpath && (rv == APR_SUCCESS || APR_STATUS_IS_EPATHWILD(rv)
1250 || APR_STATUS_IS_ENOENT(rv)
1251 || APR_STATUS_IS_ENOTDIR(rv))) {
1259 AP_DECLARE(const char *) ap_soak_end_container(cmd_parms *cmd, char *directive)
1261 char l[MAX_STRING_LEN];
1265 while(!(ap_cfg_getline(l, MAX_STRING_LEN, cmd->config_file))) {
1266 #if RESOLVE_ENV_PER_TOKEN
1269 args = ap_resolve_env(cmd->temp_pool, l);
1272 cmd_name = ap_getword_conf(cmd->pool, &args);
1273 if (cmd_name[0] == '<') {
1274 if (cmd_name[1] == '/') {
1275 cmd_name[strlen(cmd_name) - 1] = '\0';
1277 if (strcasecmp(cmd_name + 2, directive + 1) != 0) {
1278 return apr_pstrcat(cmd->pool, "Expected </",
1279 directive + 1, "> but saw ",
1280 cmd_name, ">", NULL);
1283 return NULL; /* found end of container */
1288 if (*args == '\0' && cmd_name[strlen(cmd_name) - 1] == '>') {
1289 cmd_name[strlen(cmd_name) - 1] = '\0';
1292 if ((msg = ap_soak_end_container(cmd, cmd_name)) != NULL) {
1299 return apr_pstrcat(cmd->pool, "Expected </",
1300 directive + 1, "> before end of configuration",
1304 static const char *execute_now(char *cmd_line, const char *args,
1306 apr_pool_t *p, apr_pool_t *ptemp,
1307 ap_directive_t **sub_tree,
1308 ap_directive_t *parent)
1310 module *mod = ap_top_module;
1311 const command_rec *cmd;
1313 if (!(cmd = ap_find_command_in_modules(cmd_line, &mod))) {
1314 return apr_pstrcat(parms->pool, "Invalid command '",
1316 "', perhaps mis-spelled or defined by a module "
1317 "not included in the server configuration",
1321 return invoke_cmd(cmd, parms, sub_tree, args);
1325 /* This structure and the following functions are needed for the
1326 * table-based config file reading. They are passed to the
1327 * cfg_open_custom() routine.
1330 /* Structure to be passed to cfg_open_custom(): it contains an
1331 * index which is incremented from 0 to nelts on each call to
1332 * cfg_getline() (which in turn calls arr_elts_getstr())
1333 * and an apr_array_header_t pointer for the string array.
1336 apr_array_header_t *array;
1341 /* arr_elts_getstr() returns the next line from the string array. */
1342 static void *arr_elts_getstr(void *buf, size_t bufsiz, void *param)
1344 arr_elts_param_t *arr_param = (arr_elts_param_t *)param;
1346 /* End of array reached? */
1347 if (++arr_param->curr_idx > arr_param->array->nelts)
1350 /* return the line */
1352 ((char **)arr_param->array->elts)[arr_param->curr_idx - 1],
1359 /* arr_elts_close(): dummy close routine (makes sure no more lines can be read) */
1360 static int arr_elts_close(void *param)
1362 arr_elts_param_t *arr_param = (arr_elts_param_t *)param;
1364 arr_param->curr_idx = arr_param->array->nelts;
1369 static const char *process_command_config(server_rec *s,
1370 apr_array_header_t *arr,
1371 ap_directive_t **conftree,
1377 arr_elts_param_t arr_parms;
1379 arr_parms.curr_idx = 0;
1380 arr_parms.array = arr;
1382 parms = default_parms;
1384 parms.temp_pool = ptemp;
1386 parms.override = (RSRC_CONF | OR_ALL) & ~(OR_AUTHCFG | OR_LIMIT);
1387 parms.override_opts = OPT_ALL | OPT_INCNOEXEC | OPT_SYM_OWNER | OPT_MULTI;
1389 parms.config_file = ap_pcfg_open_custom(p, "-c/-C directives",
1391 arr_elts_getstr, arr_elts_close);
1393 errmsg = ap_build_config(&parms, p, ptemp, conftree);
1394 ap_cfg_closefile(parms.config_file);
1397 return apr_pstrcat(p, "Syntax error in -C/-c directive: ", errmsg,
1408 static int fname_alphasort(const void *fn1, const void *fn2)
1410 const fnames *f1 = fn1;
1411 const fnames *f2 = fn2;
1413 return strcmp(f1->fname,f2->fname);
1416 static const char *process_resource_config_nofnmatch(server_rec *s,
1418 ap_directive_t **conftree,
1424 ap_configfile_t *cfp;
1427 if (ap_is_directory(p, fname)) {
1431 apr_array_header_t *candidates = NULL;
1434 char *path = apr_pstrdup(p, fname);
1436 if (++depth > AP_MAX_INCLUDE_DIR_DEPTH) {
1437 return apr_psprintf(p, "Directory %s exceeds the maximum include "
1438 "directory nesting level of %u. You have "
1439 "probably a recursion somewhere.", path,
1440 AP_MAX_INCLUDE_DIR_DEPTH);
1444 * first course of business is to grok all the directory
1445 * entries here and store 'em away. Recall we need full pathnames
1448 rv = apr_dir_open(&dirp, path, p);
1449 if (rv != APR_SUCCESS) {
1451 return apr_psprintf(p, "Could not open config directory %s: %s",
1452 path, apr_strerror(rv, errmsg, sizeof errmsg));
1455 candidates = apr_array_make(p, 1, sizeof(fnames));
1456 while (apr_dir_read(&dirent, APR_FINFO_DIRENT, dirp) == APR_SUCCESS) {
1457 /* strip out '.' and '..' */
1458 if (strcmp(dirent.name, ".")
1459 && strcmp(dirent.name, "..")) {
1460 fnew = (fnames *) apr_array_push(candidates);
1461 fnew->fname = ap_make_full_path(p, path, dirent.name);
1465 apr_dir_close(dirp);
1466 if (candidates->nelts != 0) {
1467 qsort((void *) candidates->elts, candidates->nelts,
1468 sizeof(fnames), fname_alphasort);
1471 * Now recurse these... we handle errors and subdirectories
1472 * via the recursion, which is nice
1474 for (current = 0; current < candidates->nelts; ++current) {
1475 fnew = &((fnames *) candidates->elts)[current];
1476 error = process_resource_config_nofnmatch(s, fnew->fname,
1488 /* GCC's initialization extensions are soooo nice here... */
1489 parms = default_parms;
1491 parms.temp_pool = ptemp;
1493 parms.override = (RSRC_CONF | OR_ALL) & ~(OR_AUTHCFG | OR_LIMIT);
1494 parms.override_opts = OPT_ALL | OPT_INCNOEXEC | OPT_SYM_OWNER | OPT_MULTI;
1496 if (ap_pcfg_openfile(&cfp, p, fname) != APR_SUCCESS) {
1497 return apr_pstrcat(p, "Could not open document config file ",
1501 parms.config_file = cfp;
1502 error = ap_build_config(&parms, p, ptemp, conftree);
1503 ap_cfg_closefile(cfp);
1506 return apr_psprintf(p, "Syntax error on line %d of %s: %s",
1507 parms.err_directive->line_num,
1508 parms.err_directive->filename, error);
1514 AP_DECLARE(const char *) ap_process_resource_config(server_rec *s,
1516 ap_directive_t **conftree,
1520 /* XXX: lstat() won't work on the wildcard pattern...
1523 /* don't require conf/httpd.conf if we have a -C or -c switch */
1524 if ((ap_server_pre_read_config->nelts
1525 || ap_server_post_read_config->nelts)
1526 && !(strcmp(fname, ap_server_root_relative(p, SERVER_CONFIG_FILE)))) {
1529 if (apr_stat(&finfo, fname, APR_FINFO_LINK | APR_FINFO_TYPE, p) != APR_SUCCESS)
1533 if (!apr_fnmatch_test(fname)) {
1534 return process_resource_config_nofnmatch(s, fname, conftree, p, ptemp,
1541 apr_array_header_t *candidates = NULL;
1544 char *path = apr_pstrdup(p, fname), *pattern = NULL;
1546 pattern = ap_strrchr(path, '/');
1548 AP_DEBUG_ASSERT(pattern != NULL); /* path must be absolute. */
1552 if (apr_fnmatch_test(path)) {
1553 return apr_pstrcat(p, "Wildcard patterns not allowed in Include ",
1557 if (!ap_is_directory(p, path)){
1558 return apr_pstrcat(p, "Include directory '", path, "' not found",
1562 if (!apr_fnmatch_test(pattern)) {
1563 return apr_pstrcat(p, "Must include a wildcard pattern for "
1564 "Include ", fname, NULL);
1568 * first course of business is to grok all the directory
1569 * entries here and store 'em away. Recall we need full pathnames
1572 rv = apr_dir_open(&dirp, path, p);
1573 if (rv != APR_SUCCESS) {
1575 return apr_psprintf(p, "Could not open config directory %s: %s",
1576 path, apr_strerror(rv, errmsg, sizeof errmsg));
1579 candidates = apr_array_make(p, 1, sizeof(fnames));
1580 while (apr_dir_read(&dirent, APR_FINFO_DIRENT, dirp) == APR_SUCCESS) {
1581 /* strip out '.' and '..' */
1582 if (strcmp(dirent.name, ".")
1583 && strcmp(dirent.name, "..")
1584 && (apr_fnmatch(pattern, dirent.name,
1585 APR_FNM_PERIOD) == APR_SUCCESS)) {
1586 fnew = (fnames *) apr_array_push(candidates);
1587 fnew->fname = ap_make_full_path(p, path, dirent.name);
1591 apr_dir_close(dirp);
1592 if (candidates->nelts != 0) {
1595 qsort((void *) candidates->elts, candidates->nelts,
1596 sizeof(fnames), fname_alphasort);
1599 * Now recurse these... we handle errors and subdirectories
1600 * via the recursion, which is nice
1602 for (current = 0; current < candidates->nelts; ++current) {
1603 fnew = &((fnames *) candidates->elts)[current];
1604 error = process_resource_config_nofnmatch(s, fnew->fname,
1617 AP_DECLARE(int) ap_process_config_tree(server_rec *s,
1618 ap_directive_t *conftree,
1625 parms = default_parms;
1627 parms.temp_pool = ptemp;
1629 parms.override = (RSRC_CONF | OR_ALL) & ~(OR_AUTHCFG | OR_LIMIT);
1630 parms.override_opts = OPT_ALL | OPT_INCNOEXEC | OPT_SYM_OWNER | OPT_MULTI;
1633 errmsg = ap_walk_config(conftree, &parms, s->lookup_defaults);
1635 ap_log_perror(APLOG_MARK, APLOG_STARTUP, 0, p,
1636 "Syntax error on line %d of %s:",
1637 parms.err_directive->line_num,
1638 parms.err_directive->filename);
1639 ap_log_perror(APLOG_MARK, APLOG_STARTUP, 0, p,
1641 return HTTP_INTERNAL_SERVER_ERROR;
1647 AP_CORE_DECLARE(int) ap_parse_htaccess(ap_conf_vector_t **result,
1648 request_rec *r, int override,
1650 const char *d, const char *access_name)
1652 ap_configfile_t *f = NULL;
1654 char *filename = NULL;
1655 const struct htaccess_result *cache;
1656 struct htaccess_result *new;
1657 ap_conf_vector_t *dc = NULL;
1658 apr_status_t status;
1660 /* firstly, search cache */
1661 for (cache = r->htaccess; cache != NULL; cache = cache->next) {
1662 if (cache->override == override && strcmp(cache->dir, d) == 0) {
1663 *result = cache->htaccess;
1668 parms = default_parms;
1669 parms.override = override;
1670 parms.override_opts = override_opts;
1671 parms.pool = r->pool;
1672 parms.temp_pool = r->pool;
1673 parms.server = r->server;
1674 parms.path = apr_pstrdup(r->pool, d);
1676 /* loop through the access names and find the first one */
1677 while (access_name[0]) {
1678 /* AFAICT; there is no use of the actual 'filename' against
1679 * any canonicalization, so we will simply take the given
1680 * name, ignoring case sensitivity and aliases
1682 filename = ap_make_full_path(r->pool, d,
1683 ap_getword_conf(r->pool, &access_name));
1684 status = ap_pcfg_openfile(&f, r->pool, filename);
1686 if (status == APR_SUCCESS) {
1688 ap_directive_t *temptree = NULL;
1690 dc = ap_create_per_dir_config(r->pool);
1692 parms.config_file = f;
1693 errmsg = ap_build_config(&parms, r->pool, r->pool, &temptree);
1695 errmsg = ap_walk_config(temptree, &parms, dc);
1697 ap_cfg_closefile(f);
1700 ap_log_rerror(APLOG_MARK, APLOG_ALERT, 0, r,
1701 "%s: %s", filename, errmsg);
1702 return HTTP_INTERNAL_SERVER_ERROR;
1709 if (!APR_STATUS_IS_ENOENT(status)
1710 && !APR_STATUS_IS_ENOTDIR(status)) {
1711 ap_log_rerror(APLOG_MARK, APLOG_CRIT, status, r,
1712 "%s pcfg_openfile: unable to check htaccess file, "
1713 "ensure it is readable",
1715 apr_table_setn(r->notes, "error-notes",
1716 "Server unable to read htaccess file, denying "
1717 "access to be safe");
1718 return HTTP_FORBIDDEN;
1724 new = apr_palloc(r->pool, sizeof(struct htaccess_result));
1725 new->dir = parms.path;
1726 new->override = override;
1727 new->override_opts = override_opts;
1730 /* add to head of list */
1731 new->next = r->htaccess;
1737 AP_CORE_DECLARE(const char *) ap_init_virtual_host(apr_pool_t *p,
1738 const char *hostname,
1739 server_rec *main_server,
1742 server_rec *s = (server_rec *) apr_pcalloc(p, sizeof(server_rec));
1744 /* TODO: this crap belongs in http_core */
1745 s->process = main_server->process;
1746 s->server_admin = NULL;
1747 s->server_hostname = NULL;
1748 s->error_fname = NULL;
1750 s->keep_alive_timeout = 0;
1752 s->keep_alive_max = -1;
1753 s->error_log = main_server->error_log;
1754 s->loglevel = main_server->loglevel;
1755 /* useful default, otherwise we get a port of 0 on redirects */
1756 s->port = main_server->port;
1760 s->names = apr_array_make(p, 4, sizeof(char **));
1761 s->wild_names = apr_array_make(p, 4, sizeof(char **));
1763 s->module_config = create_empty_config(p);
1764 s->lookup_defaults = ap_create_per_dir_config(p);
1766 s->limit_req_line = main_server->limit_req_line;
1767 s->limit_req_fieldsize = main_server->limit_req_fieldsize;
1768 s->limit_req_fields = main_server->limit_req_fields;
1772 return ap_parse_vhost_addrs(p, hostname, s);
1776 AP_DECLARE(void) ap_fixup_virtual_hosts(apr_pool_t *p, server_rec *main_server)
1780 for (virt = main_server->next; virt; virt = virt->next) {
1781 merge_server_configs(p, main_server->module_config,
1782 virt->module_config);
1784 virt->lookup_defaults =
1785 ap_merge_per_dir_configs(p, main_server->lookup_defaults,
1786 virt->lookup_defaults);
1788 if (virt->server_admin == NULL)
1789 virt->server_admin = main_server->server_admin;
1791 if (virt->timeout == 0)
1792 virt->timeout = main_server->timeout;
1794 if (virt->keep_alive_timeout == 0)
1795 virt->keep_alive_timeout = main_server->keep_alive_timeout;
1797 if (virt->keep_alive == -1)
1798 virt->keep_alive = main_server->keep_alive;
1800 if (virt->keep_alive_max == -1)
1801 virt->keep_alive_max = main_server->keep_alive_max;
1803 /* XXX: this is really something that should be dealt with by a
1804 * post-config api phase
1806 ap_core_reorder_directories(p, virt);
1809 ap_core_reorder_directories(p, main_server);
1812 /*****************************************************************
1814 * Getting *everything* configured...
1817 static void init_config_globals(apr_pool_t *p)
1819 /* Global virtual host hash bucket pointers. Init to null. */
1820 ap_init_vhost_config(p);
1823 static server_rec *init_server_config(process_rec *process, apr_pool_t *p)
1826 server_rec *s = (server_rec *) apr_pcalloc(p, sizeof(server_rec));
1828 apr_file_open_stderr(&s->error_log, p);
1829 s->process = process;
1831 s->server_admin = DEFAULT_ADMIN;
1832 s->server_hostname = NULL;
1833 s->error_fname = DEFAULT_ERRORLOG;
1834 s->loglevel = DEFAULT_LOGLEVEL;
1835 s->limit_req_line = DEFAULT_LIMIT_REQUEST_LINE;
1836 s->limit_req_fieldsize = DEFAULT_LIMIT_REQUEST_FIELDSIZE;
1837 s->limit_req_fields = DEFAULT_LIMIT_REQUEST_FIELDS;
1838 s->timeout = apr_time_from_sec(DEFAULT_TIMEOUT);
1839 s->keep_alive_timeout = apr_time_from_sec(DEFAULT_KEEPALIVE_TIMEOUT);
1840 s->keep_alive_max = DEFAULT_KEEPALIVE;
1843 s->addrs = apr_pcalloc(p, sizeof(server_addr_rec));
1845 /* NOT virtual host; don't match any real network interface */
1846 rv = apr_sockaddr_info_get(&s->addrs->host_addr,
1847 NULL, APR_INET, 0, 0, p);
1848 ap_assert(rv == APR_SUCCESS); /* otherwise: bug or no storage */
1850 s->addrs->host_port = 0; /* matches any port */
1851 s->addrs->virthost = ""; /* must be non-NULL */
1852 s->names = s->wild_names = NULL;
1854 s->module_config = create_server_config(p, s);
1855 s->lookup_defaults = create_default_per_dir_config(p);
1861 AP_DECLARE(server_rec*) ap_read_config(process_rec *process, apr_pool_t *ptemp,
1862 const char *filename,
1863 ap_directive_t **conftree)
1865 const char *confname, *error;
1866 apr_pool_t *p = process->pconf;
1867 server_rec *s = init_server_config(process, p);
1869 init_config_globals(p);
1871 /* All server-wide config files now have the SAME syntax... */
1872 error = process_command_config(s, ap_server_pre_read_config, conftree,
1875 ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_CRIT, 0, NULL, "%s: %s",
1876 ap_server_argv0, error);
1880 /* process_command_config may change the ServerRoot so
1881 * compute this config file name afterwards.
1883 confname = ap_server_root_relative(p, filename);
1886 ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_CRIT,
1887 APR_EBADPATH, NULL, "Invalid config file path %s",
1892 error = ap_process_resource_config(s, confname, conftree, p, ptemp);
1894 ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_CRIT, 0, NULL,
1895 "%s: %s", ap_server_argv0, error);
1899 error = process_command_config(s, ap_server_post_read_config, conftree,
1903 ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_CRIT, 0, NULL, "%s: %s",
1904 ap_server_argv0, error);
1911 AP_DECLARE(void) ap_single_module_configure(apr_pool_t *p, server_rec *s,
1914 if (m->create_server_config)
1915 ap_set_module_config(s->module_config, m,
1916 (*m->create_server_config)(p, s));
1918 if (m->create_dir_config)
1919 ap_set_module_config(s->lookup_defaults, m,
1920 (*m->create_dir_config)(p, NULL));
1923 AP_DECLARE(void) ap_run_rewrite_args(process_rec *process)
1927 for (m = ap_top_module; m; m = m->next) {
1928 if (m->rewrite_args) {
1929 (*m->rewrite_args)(process);
1934 /********************************************************************
1935 * Configuration directives are restricted in terms of where they may
1936 * appear in the main configuration files and/or .htaccess files according
1937 * to the bitmask req_override in the command_rec structure.
1938 * If any of the overrides set in req_override are also allowed in the
1939 * context in which the command is read, then the command is allowed.
1940 * The context is determined as follows:
1942 * inside *.conf --> override = (RSRC_CONF|OR_ALL)&~(OR_AUTHCFG|OR_LIMIT);
1943 * within <Directory> or <Location> --> override = OR_ALL|ACCESS_CONF;
1944 * within .htaccess --> override = AllowOverride for current directory;
1946 * the result is, well, a rather confusing set of possibilities for when
1947 * a particular directive is allowed to be used. This procedure prints
1948 * in English where the given (pc) directive can be used.
1950 static void show_overrides(const command_rec *pc, module *pm)
1954 printf("\tAllowed in *.conf ");
1955 if ((pc->req_override & (OR_OPTIONS | OR_FILEINFO | OR_INDEXES))
1956 || ((pc->req_override & RSRC_CONF)
1957 && ((pc->req_override & (ACCESS_CONF | OR_AUTHCFG | OR_LIMIT))))) {
1960 else if (pc->req_override & RSRC_CONF) {
1961 printf("only outside <Directory>, <Files> or <Location>");
1964 printf("only inside <Directory>, <Files> or <Location>");
1967 /* Warn if the directive is allowed inside <Directory> or .htaccess
1968 * but module doesn't support per-dir configuration
1970 if ((pc->req_override & (OR_ALL | ACCESS_CONF)) && !pm->create_dir_config)
1971 printf(" [no per-dir config]");
1973 if (pc->req_override & OR_ALL) {
1974 printf(" and in .htaccess\n\twhen AllowOverride");
1976 if ((pc->req_override & OR_ALL) == OR_ALL) {
1977 printf(" isn't None");
1980 printf(" includes ");
1982 if (pc->req_override & OR_AUTHCFG) {
1986 printf("AuthConfig");
1989 if (pc->req_override & OR_LIMIT) {
1996 if (pc->req_override & OR_OPTIONS) {
2003 if (pc->req_override & OR_FILEINFO) {
2010 if (pc->req_override & OR_INDEXES) {
2022 /* Show the preloaded configuration directives, the help string explaining
2023 * the directive arguments, in what module they are handled, and in
2024 * what parts of the configuration they are allowed. Used for httpd -L.
2026 AP_DECLARE(void) ap_show_directives(void)
2028 const command_rec *pc;
2031 for (n = 0; ap_loaded_modules[n]; ++n) {
2032 for (pc = ap_loaded_modules[n]->cmds; pc && pc->name; ++pc) {
2033 printf("%s (%s)\n", pc->name, ap_loaded_modules[n]->name);
2036 printf("\t%s\n", pc->errmsg);
2038 show_overrides(pc, ap_loaded_modules[n]);
2043 /* Show the preloaded module names. Used for httpd -l. */
2044 AP_DECLARE(void) ap_show_modules(void)
2048 printf("Compiled in modules:\n");
2049 for (n = 0; ap_loaded_modules[n]; ++n)
2050 printf(" %s\n", ap_loaded_modules[n]->name);
2053 AP_DECLARE(const char *) ap_show_mpm(void)