1 /* ====================================================================
2 * The Apache Software License, Version 1.1
4 * Copyright (c) 2000 The Apache Software Foundation. All rights
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
19 * 3. The end-user documentation included with the redistribution,
20 * if any, must include the following acknowledgment:
21 * "This product includes software developed by the
22 * Apache Software Foundation (http://www.apache.org/)."
23 * Alternately, this acknowledgment may appear in the software itself,
24 * if and wherever such third-party acknowledgments normally appear.
26 * 4. The names "Apache" and "Apache Software Foundation" must
27 * not be used to endorse or promote products derived from this
28 * software without prior written permission. For written
29 * permission, please contact apache@apache.org.
31 * 5. Products derived from this software may not be called "Apache",
32 * nor may "Apache" appear in their name, without prior written
33 * permission of the Apache Software Foundation.
35 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
36 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
42 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
43 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
45 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47 * ====================================================================
49 * This software consists of voluntary contributions made by many
50 * individuals on behalf of the Apache Software Foundation. For more
51 * information on the Apache Software Foundation, please see
52 * <http://www.apache.org/>.
54 * Portions of this software are based upon public domain software
55 * originally written at the National Center for Supercomputing Applications,
56 * University of Illinois, Urbana-Champaign.
60 * http_config.c: once was auxillary functions for reading httpd's config
61 * file and converting filenames into a namespace
65 * Wall-to-wall rewrite for Apache... commands which are part of the
66 * server core can now be found next door in "http_core.c". Now contains
67 * general command loop, and functions which do bookkeeping for the new
68 * Apache config stuff (modules and configuration vectors).
75 #include "apr_strings.h"
76 #include "apr_portable.h"
77 #include "apr_file_io.h"
85 #include "ap_config.h"
87 #include "http_config.h"
88 #include "http_protocol.h"
89 #include "http_core.h"
90 #include "http_log.h" /* for errors in parse_htaccess */
91 #include "http_request.h" /* for default_handler (see invoke_handler) */
92 #include "http_main.h"
93 #include "http_vhost.h"
94 #include "util_cfgtree.h"
95 #ifdef HAVE_ARPA_INET_H
96 #include <arpa/inet.h>
102 AP_DECLARE_DATA const char *ap_server_argv0;
104 AP_DECLARE_DATA const char *ap_server_root;
106 AP_DECLARE_DATA apr_array_header_t *ap_server_pre_read_config;
107 AP_DECLARE_DATA apr_array_header_t *ap_server_post_read_config;
108 AP_DECLARE_DATA apr_array_header_t *ap_server_config_defines;
110 AP_DECLARE_DATA ap_directive_t *ap_conftree;
113 APR_HOOK_LINK(header_parser)
114 APR_HOOK_LINK(pre_config)
115 APR_HOOK_LINK(post_config)
116 APR_HOOK_LINK(open_logs)
117 APR_HOOK_LINK(child_init)
118 APR_HOOK_LINK(handler)
119 APR_HOOK_LINK(optional_fn_retrieve)
122 AP_IMPLEMENT_HOOK_RUN_ALL(int,header_parser,
123 (request_rec *r),(r),OK,DECLINED)
124 AP_IMPLEMENT_HOOK_VOID(pre_config,
125 (apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp),
127 AP_IMPLEMENT_HOOK_VOID(post_config,
128 (apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp,
129 server_rec *s),(pconf,plog,ptemp,s))
130 AP_IMPLEMENT_HOOK_VOID(open_logs,
131 (apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp,
132 server_rec *s),(pconf,plog,ptemp,s))
133 AP_IMPLEMENT_HOOK_VOID(child_init,
134 (apr_pool_t *pchild, server_rec *s),(pchild,s))
136 AP_IMPLEMENT_HOOK_RUN_FIRST(int,handler,(request_rec *r),
139 AP_IMPLEMENT_HOOK_VOID(optional_fn_retrieve,(void),())
141 /****************************************************************
143 * We begin with the functions which deal with the linked list
144 * of modules which control just about all of the server operation.
147 /* total_modules is the number of modules that have been linked
150 static int total_modules = 0;
151 /* dynamic_modules is the number of modules that have been added
152 * after the pre-loaded ones have been set up. It shouldn't be larger
153 * than DYNAMIC_MODULE_LIMIT.
155 static int dynamic_modules = 0;
156 AP_DECLARE_DATA module *top_module = NULL;
157 AP_DECLARE_DATA module **ap_loaded_modules=NULL;
159 typedef int (*handler_func) (request_rec *);
160 typedef void *(*dir_maker_func) (apr_pool_t *, char *);
161 typedef void *(*merger_func) (apr_pool_t *, void *, void *);
163 /* Dealing with config vectors. These are associated with per-directory,
164 * per-server, and per-request configuration, and have a void* pointer for
165 * each modules. The nature of the structure pointed to is private to the
166 * module in question... the core doesn't (and can't) know. However, there
167 * are defined interfaces which allow it to create instances of its private
168 * per-directory and per-server structures, and to merge the per-directory
169 * structures of a directory and its subdirectory (producing a new one in
170 * which the defaults applying to the base directory have been properly
174 #ifndef ap_get_module_config
175 AP_DECLARE(void *) ap_get_module_config(void *conf_vector, module *m)
177 void **confv = (void **) conf_vector;
178 return confv[m->module_index];
182 #ifndef ap_set_module_config
183 AP_DECLARE(void) ap_set_module_config(void *conf_vector, module *m, void *val)
185 void **confv = (void **) conf_vector;
186 confv[m->module_index] = val;
190 static void *create_empty_config(apr_pool_t *p)
192 void **conf_vector = (void **) apr_pcalloc(p, sizeof(void *) *
193 (total_modules + DYNAMIC_MODULE_LIMIT));
194 return (void *) conf_vector;
197 static void *create_default_per_dir_config(apr_pool_t *p)
199 void **conf_vector = (void **) apr_pcalloc(p, sizeof(void *) * (total_modules + DYNAMIC_MODULE_LIMIT));
202 for (modp = top_module; modp; modp = modp->next) {
203 dir_maker_func df = modp->create_dir_config;
206 conf_vector[modp->module_index] = (*df) (p, NULL);
209 return (void *) conf_vector;
213 ap_merge_per_dir_configs(apr_pool_t *p, void *base, void *new)
215 void **conf_vector = (void **) apr_palloc(p, sizeof(void *) * total_modules);
216 void **base_vector = (void **) base;
217 void **new_vector = (void **) new;
220 for (modp = top_module; modp; modp = modp->next) {
221 merger_func df = modp->merge_dir_config;
222 int i = modp->module_index;
224 if (df && new_vector[i])
225 conf_vector[i] = (*df) (p, base_vector[i], new_vector[i]);
227 conf_vector[i] = new_vector[i] ? new_vector[i] : base_vector[i];
230 return (void *) conf_vector;
233 static void *create_server_config(apr_pool_t *p, server_rec *s)
235 void **conf_vector = (void **) apr_pcalloc(p, sizeof(void *) * (total_modules + DYNAMIC_MODULE_LIMIT));
238 for (modp = top_module; modp; modp = modp->next) {
239 if (modp->create_server_config)
240 conf_vector[modp->module_index] = (*modp->create_server_config) (p, s);
243 return (void *) conf_vector;
246 static void merge_server_configs(apr_pool_t *p, void *base, void *virt)
248 /* Can reuse the 'virt' vector for the spine of it, since we don't
249 * have to deal with the moral equivalent of .htaccess files here...
252 void **base_vector = (void **) base;
253 void **virt_vector = (void **) virt;
256 for (modp = top_module; modp; modp = modp->next) {
257 merger_func df = modp->merge_server_config;
258 int i = modp->module_index;
261 virt_vector[i] = base_vector[i];
263 virt_vector[i] = (*df) (p, base_vector[i], virt_vector[i]);
267 void *ap_create_request_config(apr_pool_t *p)
269 return create_empty_config(p);
272 void *ap_create_conn_config(apr_pool_t *p)
274 return create_empty_config(p);
277 AP_CORE_DECLARE(void *) ap_create_per_dir_config(apr_pool_t *p)
279 return create_empty_config(p);
282 int ap_invoke_handler(request_rec *r)
288 char hbuf[MAX_STRING_LEN];
289 const char *old_handler = r->handler;
292 handler = r->content_type ? r->content_type : ap_default_type(r);
293 if ((p=ap_strchr_c(handler, ';')) != NULL) {
294 apr_cpystrn(hbuf, handler, sizeof hbuf);
295 p2 = hbuf+(handler-p);
297 /* MIME type arguments */
298 while (p2 > handler && p2[-1] == ' ')
299 --p2; /* strip trailing spaces */
302 r->handler = handler;
305 result = ap_run_handler(r);
307 r->handler = old_handler;
309 if (result == DECLINED && r->handler && r->filename) {
310 ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING, 0, r,
311 "handler \"%s\" not found for: %s", r->handler, r->filename);
313 return result == DECLINED ? HTTP_INTERNAL_SERVER_ERROR : result;
316 AP_DECLARE(int) ap_method_is_limited(cmd_parms *cmd, const char *method) {
321 methnum = ap_method_number_of(method);
323 * The simple case: a method hard-coded into Apache.
325 if (methnum != M_INVALID) {
326 return (methnum & cmd->limited);
329 * Some extension method we don't know implicitly.
331 if ((cmd->limited_xmethods == NULL)
332 || (cmd->limited_xmethods->nelts == 0)) {
335 xmethod = (char **) cmd->limited_xmethods->elts;
336 for (i = 0; i < cmd->limited_xmethods->nelts; ++i) {
337 if (strcmp(method, xmethod[i]) == 0) {
344 AP_DECLARE(void) ap_register_hooks(module *m, apr_pool_t *p)
346 if(m->register_hooks)
348 if(getenv("SHOW_HOOKS"))
350 printf("Registering hooks for %s\n",m->name);
351 apr_debug_module_hooks=1;
353 apr_current_hooking_module=m->name;
354 m->register_hooks(p);
358 /* One-time setup for precompiled modules --- NOT to be done on restart */
360 AP_DECLARE(void) ap_add_module(module *m, apr_pool_t *p)
362 /* This could be called from an AddModule httpd.conf command,
363 * after the file has been linked and the module structure within it
367 if (m->version != MODULE_MAGIC_NUMBER_MAJOR) {
368 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
369 "%s: module \"%s\" is not compatible with this "
370 "version of Apache.", ap_server_argv0, m->name);
371 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, "Please contact the vendor for the correct version.");
375 if (m->next == NULL) {
376 m->next = top_module;
379 if (m->module_index == -1) {
380 m->module_index = total_modules++;
383 if (dynamic_modules > DYNAMIC_MODULE_LIMIT) {
384 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
385 "%s: module \"%s\" could not be loaded, because"
386 " the dynamic", ap_server_argv0, m->name);
387 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
388 "module limit was reached. Please increase "
389 "DYNAMIC_MODULE_LIMIT and recompile.");
394 /* Some C compilers put a complete path into __FILE__, but we want
395 * only the filename (e.g. mod_includes.c). So check for path
396 * components (Unix and DOS), and remove them.
399 if (ap_strrchr_c(m->name, '/'))
400 m->name = 1 + ap_strrchr_c(m->name, '/');
401 if (ap_strrchr_c(m->name, '\\'))
402 m->name = 1 + ap_strrchr_c(m->name, '\\');
404 #ifdef _OSD_POSIX /* __FILE__="*POSIX(/home/martin/apache/src/modules/standard/mod_info.c)" */
405 /* We cannot fix the string in-place, because it's const */
406 if (m->name[strlen(m->name)-1]==')') {
407 char *tmp = strdup(m->name); /* FIXME:memory leak, albeit a small one */
408 tmp[strlen(tmp)-1] = '\0';
411 #endif /*_OSD_POSIX*/
413 /* FIXME: is this the right place to call this?
414 * It doesn't appear to be
416 ap_register_hooks(m, p);
420 * remove_module undoes what add_module did. There are some caveats:
421 * when the module is removed, its slot is lost so all the current
422 * per-dir and per-server configurations are invalid. So we should
423 * only ever call this function when you are invalidating almost
424 * all our current data. I.e. when doing a restart.
427 AP_DECLARE(void) ap_remove_module(module *m)
433 /* We are the top module, special case */
434 top_module = modp->next;
438 /* Not the top module, find use. When found modp will
439 * point to the module _before_ us in the list
442 while (modp && modp->next != m) {
446 /* Uh-oh, this module doesn't exist */
447 ap_log_error(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, NULL,
448 "Cannot remove module %s: not found in module list",
452 /* Eliminate us from the module list */
453 modp->next = modp->next->next;
456 m->module_index = -1; /* simulate being unloaded, should
462 AP_DECLARE(void) ap_add_loaded_module(module *mod, apr_pool_t *p)
467 * Add module pointer to top of chained module list
469 ap_add_module(mod, p);
472 * And module pointer to list of loaded modules
474 * Notes: 1. ap_add_module() would already complain if no more space
475 * exists for adding a dynamically loaded module
476 * 2. ap_add_module() accepts double inclusion, so we have
477 * to accept this, too.
479 for (m = ap_loaded_modules; *m != NULL; m++)
485 AP_DECLARE(void) ap_remove_loaded_module(module *mod)
492 * Remove module pointer from chained module list
494 ap_remove_module(mod);
497 * Remove module pointer from list of loaded modules
499 * Note: 1. We cannot determine if the module was successfully
500 * removed by ap_remove_module().
501 * 2. We have not to complain explicity when the module
502 * is not found because ap_remove_module() did it
505 for (m = m2 = ap_loaded_modules, done = 0; *m2 != NULL; m2++) {
506 if (*m2 == mod && done == 0)
514 AP_DECLARE(void) ap_setup_prelinked_modules(process_rec *process)
519 apr_global_hook_pool=process->pconf;
522 * Initialise total_modules variable and module indices
525 for (m = ap_preloaded_modules; *m != NULL; m++)
526 (*m)->module_index = total_modules++;
529 * Initialise list of loaded modules
531 ap_loaded_modules = (module **)apr_palloc(process->pool,
532 sizeof(module *)*(total_modules+DYNAMIC_MODULE_LIMIT+1));
533 if (ap_loaded_modules == NULL) {
534 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
535 "Ouch! Out of memory in ap_setup_prelinked_modules()!");
537 for (m = ap_preloaded_modules, m2 = ap_loaded_modules; *m != NULL; )
542 * Initialize chain of linked (=activate) modules
544 for (m = ap_prelinked_modules; *m != NULL; m++)
545 ap_add_module(*m, process->pconf);
550 AP_DECLARE(const char *) ap_find_module_name(module *m)
555 AP_DECLARE(module *) ap_find_linked_module(const char *name)
559 for (modp = top_module; modp; modp = modp->next) {
560 if (strcmp(modp->name, name) == 0)
566 /* Add a named module. Returns 1 if module found, 0 otherwise. */
567 AP_DECLARE(int) ap_add_named_module(const char *name, apr_pool_t *p)
572 for (modp = ap_loaded_modules[i]; modp; modp = ap_loaded_modules[++i]) {
573 if (strcmp(modp->name, name) == 0) {
574 /* Only add modules that are not already enabled. */
575 if (modp->next == NULL) {
576 ap_add_module(modp, p);
585 /*****************************************************************
587 * Resource, access, and .htaccess config files now parsed by a common
590 * Let's begin with the basics; parsing the line and
591 * invoking the function...
594 static const char *invoke_cmd(const command_rec *cmd, cmd_parms *parms,
595 void *mconfig, const char *args)
600 if ((parms->override & cmd->req_override) == 0)
601 return apr_pstrcat(parms->pool, cmd->name, " not allowed here", NULL);
603 parms->info = cmd->cmd_data;
606 switch (cmd->args_how) {
608 #ifdef RESOLVE_ENV_PER_TOKEN
609 args = ap_resolve_env(parms->pool,args);
611 return cmd->AP_RAW_ARGS(parms, mconfig, args);
615 return apr_pstrcat(parms->pool, cmd->name, " takes no arguments",
618 return cmd->AP_NO_ARGS(parms, mconfig);
621 w = ap_getword_conf(parms->pool, &args);
623 if (*w == '\0' || *args != 0)
624 return apr_pstrcat(parms->pool, cmd->name, " takes one argument",
625 cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
627 return cmd->AP_TAKE1(parms, mconfig, w);
630 w = ap_getword_conf(parms->pool, &args);
631 w2 = ap_getword_conf(parms->pool, &args);
633 if (*w == '\0' || *w2 == '\0' || *args != 0)
634 return apr_pstrcat(parms->pool, cmd->name, " takes two arguments",
635 cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
637 return cmd->AP_TAKE2(parms, mconfig, w, w2);
641 w = ap_getword_conf(parms->pool, &args);
642 w2 = ap_getword_conf(parms->pool, &args);
644 if (*w == '\0' || *args != 0)
645 return apr_pstrcat(parms->pool, cmd->name, " takes 1-2 arguments",
646 cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
648 return cmd->AP_TAKE2(parms, mconfig, w, *w2 ? w2 : NULL);
652 w = ap_getword_conf(parms->pool, &args);
653 w2 = ap_getword_conf(parms->pool, &args);
654 w3 = ap_getword_conf(parms->pool, &args);
656 if (*w == '\0' || *w2 == '\0' || *w3 == '\0' || *args != 0)
657 return apr_pstrcat(parms->pool, cmd->name, " takes three arguments",
658 cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
660 return cmd->AP_TAKE3(parms, mconfig, w, w2, w3);
664 w = ap_getword_conf(parms->pool, &args);
665 w2 = ap_getword_conf(parms->pool, &args);
666 w3 = *args ? ap_getword_conf(parms->pool, &args) : NULL;
668 if (*w == '\0' || *w2 == '\0' || *args != 0)
669 return apr_pstrcat(parms->pool, cmd->name,
670 " takes two or three arguments",
671 cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
673 return cmd->AP_TAKE3(parms, mconfig, w, w2, w3);
677 w = ap_getword_conf(parms->pool, &args);
678 w2 = *args ? ap_getword_conf(parms->pool, &args) : NULL;
679 w3 = *args ? ap_getword_conf(parms->pool, &args) : NULL;
681 if (*w == '\0' || *args != 0)
682 return apr_pstrcat(parms->pool, cmd->name,
683 " takes one, two or three arguments",
684 cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
686 return cmd->AP_TAKE3(parms, mconfig, w, w2, w3);
690 w = ap_getword_conf(parms->pool, &args);
691 w2 = *args ? ap_getword_conf(parms->pool, &args) : NULL;
692 w3 = *args ? ap_getword_conf(parms->pool, &args) : NULL;
694 if (*w == '\0' || (w2 && *w2 && !w3) || *args != 0)
695 return apr_pstrcat(parms->pool, cmd->name,
696 " takes one or three arguments",
697 cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
699 return cmd->AP_TAKE3(parms, mconfig, w, w2, w3);
703 while (*(w = ap_getword_conf(parms->pool, &args)) != '\0')
705 if ((errmsg = cmd->AP_TAKE1(parms, mconfig, w)))
713 w = ap_getword_conf(parms->pool, &args);
715 if (*w == '\0' || *args == 0)
716 return apr_pstrcat(parms->pool, cmd->name,
717 " requires at least two arguments",
718 cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
720 while (*(w2 = ap_getword_conf(parms->pool, &args)) != '\0')
722 if ((errmsg = cmd->AP_TAKE2(parms, mconfig, w, w2)))
730 w = ap_getword_conf(parms->pool, &args);
732 if (*w == '\0' || (strcasecmp(w, "on") && strcasecmp(w, "off")))
733 return apr_pstrcat(parms->pool, cmd->name, " must be On or Off",
736 return cmd->AP_FLAG(parms, mconfig, strcasecmp(w, "off") != 0);
740 return apr_pstrcat(parms->pool, cmd->name,
741 " is improperly configured internally (server bug)",
746 AP_CORE_DECLARE(const command_rec *) ap_find_command(const char *name, const command_rec *cmds)
749 if (!strcasecmp(name, cmds->name))
757 AP_CORE_DECLARE(const command_rec *) ap_find_command_in_modules(const char *cmd_name, module **mod)
759 const command_rec *cmdp;
762 for (modp = *mod; modp; modp = modp->next)
763 if (modp->cmds && (cmdp = ap_find_command(cmd_name, modp->cmds))) {
771 AP_CORE_DECLARE(void *) ap_set_config_vectors(cmd_parms *parms, void *config, module *mod)
773 void *mconfig = ap_get_module_config(config, mod);
774 void *sconfig = ap_get_module_config(parms->server->module_config, mod);
776 if (!mconfig && mod->create_dir_config) {
777 mconfig = (*mod->create_dir_config) (parms->pool, parms->path);
778 ap_set_module_config(config, mod, mconfig);
781 if (!sconfig && mod->create_server_config) {
782 sconfig = (*mod->create_server_config) (parms->pool, parms->server);
783 ap_set_module_config(parms->server->module_config, mod, sconfig);
788 static const char *execute_now(char *cmd_line, const char *args, cmd_parms *parms,
789 apr_pool_t *p, apr_pool_t *ptemp,
790 ap_directive_t **sub_tree, ap_directive_t *parent);
792 static const char * ap_build_config_sub(apr_pool_t *p, apr_pool_t *temp_pool,
793 const char *l, cmd_parms *parms,
794 ap_directive_t **current,
795 ap_directive_t **curr_parent,
796 ap_directive_t **conftree)
800 ap_directive_t *newdir;
801 module *mod = top_module;
802 const command_rec *cmd;
804 if (*l == '#' || *l == '\0')
807 #if RESOLVE_ENV_PER_TOKEN
810 args = ap_resolve_env(temp_pool, l);
812 cmd_name = ap_getword_conf(p, &args);
813 if (*cmd_name == '\0') {
814 /* Note: this branch should not occur. An empty line should have
815 * triggered the exit further above.
820 newdir = apr_pcalloc(p, sizeof(ap_directive_t));
821 newdir->filename = parms->config_file->name;
822 newdir->line_num = parms->config_file->line_number;
823 newdir->directive = cmd_name;
824 newdir->args = apr_pstrdup(p, args);
826 if ((cmd = ap_find_command_in_modules(cmd_name, &mod)) != NULL) {
827 if (cmd->req_override & EXEC_ON_READ) {
829 ap_directive_t *sub_tree = NULL;
831 parms->err_directive = newdir;
832 retval = execute_now(cmd_name, args, parms, p, temp_pool,
833 &sub_tree, *curr_parent);
835 (*current)->next = sub_tree;
838 (*current) = sub_tree;
840 (*curr_parent)->first_child = (*current);
843 (*current)->parent = (*curr_parent);
848 /* Before walking *current to the end of the list,
849 * set the head to *current.
851 *conftree = *current;
853 while ((*current)->next != NULL) {
854 (*current) = (*current)->next;
855 (*current)->parent = (*curr_parent);
862 if (cmd_name[0] == '<') {
863 if (cmd_name[1] != '/') {
864 (*current) = ap_add_node(curr_parent, *current, newdir, 1);
866 else if (*curr_parent == NULL) {
867 parms->err_directive = newdir;
868 return apr_pstrcat(p, cmd_name,
869 " without matching <", cmd_name + 2,
873 char *bracket = cmd_name + strlen(cmd_name) - 1;
875 if (*bracket != '>') {
876 return apr_pstrcat(p, cmd_name,
877 "> directive missing closing '>'", NULL);
880 if (strcasecmp(cmd_name + 2,
881 (*curr_parent)->directive + 1) != 0) {
882 return apr_pstrcat(p, "Expected </",
883 (*curr_parent)->directive + 1, "> but saw ",
884 cmd_name, ">", NULL);
888 /* done with this section; move up a level */
889 *current = *curr_parent;
890 *curr_parent = (*current)->parent;
894 *current = ap_add_node(curr_parent, *current, newdir, 0);
900 const char *ap_build_cont_config(apr_pool_t *p, apr_pool_t *temp_pool,
902 ap_directive_t **current,
903 ap_directive_t **curr_parent,
904 char *orig_directive)
906 char l[MAX_STRING_LEN];
909 ap_directive_t *sub_tree = NULL;
911 bracket = apr_pstrcat(p, orig_directive + 1, ">", NULL);
912 while (!(ap_cfg_getline(l, MAX_STRING_LEN, parms->config_file))) {
913 if (!memcmp(l, "</", 2) &&
914 (strcasecmp(l + 2, bracket) == 0) &&
915 (*curr_parent == NULL)) {
918 retval = ap_build_config_sub(p, temp_pool, l, parms, current,
919 curr_parent, &sub_tree);
922 if (sub_tree == NULL && curr_parent != NULL) {
923 sub_tree = *curr_parent;
925 if (sub_tree == NULL && current != NULL) {
933 static const char *ap_walk_config_sub(const ap_directive_t *current,
934 cmd_parms *parms, void *config)
936 module *mod = top_module;
939 const command_rec *cmd;
941 if (!(cmd = ap_find_command_in_modules(current->directive, &mod))) {
942 parms->err_directive = current;
943 return apr_pstrcat(parms->pool, "Invalid command '",
945 "', perhaps mis-spelled or defined by a module "
946 "not included in the server configuration",
950 void *mconfig = ap_set_config_vectors(parms,config, mod);
953 retval = invoke_cmd(cmd, parms, mconfig, current->args);
954 if (retval == NULL) {
957 if (strcmp(retval, DECLINE_CMD) != 0) {
958 /* If the directive in error has already been set, don't
959 * replace it. Otherwise, an error inside a container
960 * will be reported as occuring on the first line of the
963 if (!parms->err_directive) {
964 parms->err_directive = current;
969 mod = mod->next; /* Next time around, skip this one */
975 AP_DECLARE(const char *) ap_walk_config(ap_directive_t *current,
976 cmd_parms *parms, void *config)
978 void *oldconfig = parms->context;
980 parms->context = config;
982 /* scan through all directives, executing each one */
983 for (; current != NULL; current = current->next) {
986 parms->directive = current;
988 /* actually parse the command and execute the correct function */
989 errmsg = ap_walk_config_sub(current, parms, config);
990 if (errmsg != NULL) {
991 /* restore the context (just in case) */
992 parms->context = oldconfig;
997 parms->context = oldconfig;
1002 AP_DECLARE(const char *) ap_build_config(cmd_parms *parms,
1003 apr_pool_t *p, apr_pool_t *temp_pool,
1004 ap_directive_t **conftree)
1006 ap_directive_t *current = *conftree;
1007 ap_directive_t *curr_parent = NULL;
1008 char l[MAX_STRING_LEN];
1011 if (current != NULL) {
1012 while (current->next) {
1013 current = current->next;
1017 while (!(ap_cfg_getline(l, MAX_STRING_LEN, parms->config_file))) {
1019 errmsg = ap_build_config_sub(p, temp_pool, l, parms,
1020 ¤t, &curr_parent, conftree);
1024 if (*conftree == NULL && curr_parent != NULL) {
1025 *conftree = curr_parent;
1027 if (*conftree == NULL && current != NULL) {
1028 *conftree = current;
1032 if (curr_parent != NULL) {
1034 while (curr_parent != NULL) {
1035 errmsg = apr_psprintf(p, "%s%s%s:%u: %s> was not closed.",
1037 *errmsg == '\0' ? "" : APR_EOL_STR,
1038 curr_parent->filename,
1039 curr_parent->line_num,
1040 curr_parent->directive);
1041 curr_parent = curr_parent->parent;
1050 * Generic command functions...
1053 AP_DECLARE_NONSTD(const char *) ap_set_string_slot(cmd_parms *cmd,
1057 /* This one's pretty generic... */
1059 int offset = (int) (long) cmd->info;
1060 *(const char **) ((char *)struct_ptr + offset) = arg;
1064 AP_DECLARE_NONSTD(const char *) ap_set_string_slot_lower(cmd_parms *cmd,
1068 /* This one's pretty generic... */
1069 char *arg=apr_pstrdup(cmd->pool,arg_);
1071 int offset = (int) (long) cmd->info;
1072 ap_str_tolower(arg);
1073 *(char **) ((char *)struct_ptr + offset) = arg;
1077 AP_DECLARE_NONSTD(const char *) ap_set_flag_slot(cmd_parms *cmd,
1078 void *struct_ptr_v, int arg)
1080 /* This one's pretty generic too... */
1082 int offset = (int) (long) cmd->info;
1083 char *struct_ptr = (char *)struct_ptr_v;
1084 *(int *) (struct_ptr + offset) = arg ? 1 : 0;
1088 AP_DECLARE_NONSTD(const char *) ap_set_file_slot(cmd_parms *cmd, void *struct_ptr,
1091 /* Prepend server_root to relative arg.
1092 This allows .htaccess to be independent of server_root,
1093 so the server can be moved or mirrored with less pain. */
1095 int offset = (int) (long) cmd->info;
1097 arg = ap_os_canonical_filename(cmd->pool, arg);
1099 if (ap_os_is_path_absolute(arg))
1100 p = apr_pstrdup(cmd->pool, arg);
1102 p = ap_make_full_path(cmd->pool, ap_server_root, arg);
1103 *(char **) ((char*)struct_ptr + offset) = p;
1107 /*****************************************************************
1109 * Reading whole config files...
1112 static cmd_parms default_parms =
1113 {NULL, 0, -1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
1115 AP_DECLARE(const char *) ap_server_root_relative(apr_pool_t *p, const char *file)
1118 file = ap_os_canonical_filename(p, file);
1120 if(ap_os_is_path_absolute(file))
1122 return ap_make_full_path(p, ap_server_root, file);
1125 AP_DECLARE(const char *) ap_soak_end_container(cmd_parms *cmd, char *directive)
1127 char l[MAX_STRING_LEN];
1131 while(!(ap_cfg_getline(l, MAX_STRING_LEN, cmd->config_file))) {
1132 #if RESOLVE_ENV_PER_TOKEN
1135 args = ap_resolve_env(cmd->temp_pool, l);
1137 cmd_name = ap_getword_conf(cmd->pool, &args);
1138 if (cmd_name[0] == '<') {
1139 if (cmd_name[1] == '/') {
1140 cmd_name[strlen(cmd_name) - 1] = '\0';
1141 if (strcasecmp(cmd_name + 2, directive + 1) != 0) {
1142 return apr_pstrcat(cmd->pool, "Expected </",
1143 directive + 1, "> but saw ",
1144 cmd_name, ">", NULL);
1149 ap_soak_end_container(cmd, cmd_name);
1156 static const char *execute_now(char *cmd_line, const char *args, cmd_parms *parms,
1157 apr_pool_t *p, apr_pool_t *ptemp,
1158 ap_directive_t **sub_tree, ap_directive_t *parent)
1160 module *mod = top_module;
1161 const command_rec *cmd;
1163 if (!(cmd = ap_find_command_in_modules(cmd_line, &mod))) {
1164 return apr_pstrcat(parms->pool, "Invalid command '",
1166 "', perhaps mis-spelled or defined by a module "
1167 "not included in the server configuration",
1171 return invoke_cmd(cmd, parms, sub_tree, args);
1175 /* This structure and the following functions are needed for the
1176 * table-based config file reading. They are passed to the
1177 * cfg_open_custom() routine.
1180 /* Structure to be passed to cfg_open_custom(): it contains an
1181 * index which is incremented from 0 to nelts on each call to
1182 * cfg_getline() (which in turn calls arr_elts_getstr())
1183 * and an apr_array_header_t pointer for the string array.
1186 apr_array_header_t *array;
1191 /* arr_elts_getstr() returns the next line from the string array. */
1192 static void *arr_elts_getstr(void *buf, size_t bufsiz, void *param)
1194 arr_elts_param_t *arr_param = (arr_elts_param_t *) param;
1196 /* End of array reached? */
1197 if (++arr_param->curr_idx > arr_param->array->nelts)
1200 /* return the line */
1201 apr_cpystrn(buf, ((char **) arr_param->array->elts)[arr_param->curr_idx - 1], bufsiz);
1207 /* arr_elts_close(): dummy close routine (makes sure no more lines can be read) */
1208 static int arr_elts_close(void *param)
1210 arr_elts_param_t *arr_param = (arr_elts_param_t *) param;
1211 arr_param->curr_idx = arr_param->array->nelts;
1215 static void process_command_config(server_rec *s, apr_array_header_t *arr,
1216 ap_directive_t **conftree, apr_pool_t *p,
1221 arr_elts_param_t arr_parms;
1223 arr_parms.curr_idx = 0;
1224 arr_parms.array = arr;
1226 parms = default_parms;
1228 parms.temp_pool = ptemp;
1230 parms.override = (RSRC_CONF | OR_ALL) & ~(OR_AUTHCFG | OR_LIMIT);
1232 parms.config_file = ap_pcfg_open_custom(p, "-c/-C directives",
1234 arr_elts_getstr, arr_elts_close);
1236 errmsg = ap_build_config(&parms, p, ptemp, conftree);
1238 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
1239 "Syntax error in -C/-c directive:" APR_EOL_STR "%s",
1244 ap_cfg_closefile(parms.config_file);
1251 static int fname_alphasort(const void *fn1, const void *fn2)
1253 const fnames *f1 = fn1;
1254 const fnames *f2 = fn2;
1256 return strcmp(f1->fname,f2->fname);
1259 void ap_process_resource_config(server_rec *s, const char *fname,
1260 ap_directive_t **conftree, apr_pool_t *p,
1268 fname = ap_server_root_relative(p, fname);
1270 /* don't require conf/httpd.conf if we have a -C or -c switch */
1271 if ((ap_server_pre_read_config->nelts
1272 || ap_server_post_read_config->nelts)
1273 && !(strcmp(fname, ap_server_root_relative(p, SERVER_CONFIG_FILE)))) {
1274 if (apr_stat(&finfo, fname, APR_FINFO_NORM, p) != APR_SUCCESS)
1279 * here we want to check if the candidate file is really a
1280 * directory, and most definitely NOT a symlink (to prevent
1281 * horrible loops). If so, let's recurse and toss it back into
1284 if (ap_is_rdirectory(ptemp, fname)) {
1288 apr_array_header_t *candidates = NULL;
1294 * first course of business is to grok all the directory
1295 * entries here and store 'em away. Recall we need full pathnames
1298 fprintf(stderr, "Processing config directory: %s\n", fname);
1299 rv = apr_dir_open(&dirp, fname, p);
1300 if (rv != APR_SUCCESS) {
1301 fprintf(stderr, "%s: could not open config directory %s: %s\n",
1302 ap_server_argv0, fname,
1303 apr_strerror(rv, errmsg, sizeof errmsg));
1306 candidates = apr_make_array(p, 1, sizeof(fnames));
1307 while (apr_dir_read(&dirent, APR_FINFO_DIRENT, dirp) == APR_SUCCESS) {
1308 /* strip out '.' and '..' */
1309 if (strcmp(dirent.name, ".") &&
1310 strcmp(dirent.name, "..")) {
1311 fnew = (fnames *) apr_push_array(candidates);
1312 fnew->fname = ap_make_full_path(p, fname, dirent.name);
1315 apr_dir_close(dirp);
1316 if (candidates->nelts != 0) {
1317 qsort((void *) candidates->elts, candidates->nelts,
1318 sizeof(fnames), fname_alphasort);
1320 * Now recurse these... we handle errors and subdirectories
1321 * via the recursion, which is nice
1323 for (current = 0; current < candidates->nelts; ++current) {
1324 fnew = &((fnames *) candidates->elts)[current];
1325 fprintf(stderr, " Processing config file: %s\n", fnew->fname);
1326 ap_process_resource_config(s, fnew->fname, conftree, p, ptemp);
1332 /* GCC's initialization extensions are soooo nice here... */
1334 parms = default_parms;
1336 parms.temp_pool = ptemp;
1338 parms.override = (RSRC_CONF | OR_ALL) & ~(OR_AUTHCFG | OR_LIMIT);
1340 if (ap_pcfg_openfile(&cfp, p, fname) != APR_SUCCESS) {
1341 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
1342 "%s: could not open document config file %s",
1343 ap_server_argv0, fname);
1347 parms.config_file = cfp;
1349 errmsg = ap_build_config(&parms, p, ptemp, conftree);
1351 if (errmsg != NULL) {
1352 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
1353 "Syntax error on line %d of %s:",
1354 parms.err_directive->line_num,
1355 parms.err_directive->filename);
1356 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
1361 ap_cfg_closefile(cfp);
1364 AP_DECLARE(void)ap_process_config_tree(server_rec *s, ap_directive_t *conftree,
1365 apr_pool_t *p, apr_pool_t *ptemp)
1370 parms = default_parms;
1372 parms.temp_pool = ptemp;
1374 parms.override = (RSRC_CONF | OR_ALL) & ~(OR_AUTHCFG | OR_LIMIT);
1377 errmsg = ap_walk_config(conftree, &parms, s->lookup_defaults);
1379 ap_log_perror(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, p,
1380 "Syntax error on line %d of %s:",
1381 parms.err_directive->line_num,
1382 parms.err_directive->filename);
1383 ap_log_perror(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, p,
1389 int ap_parse_htaccess(void **result, request_rec *r, int override,
1390 const char *d, const char *access_name) {
1391 configfile_t *f = NULL;
1393 char *filename = NULL;
1394 const struct htaccess_result *cache;
1395 struct htaccess_result *new;
1397 apr_status_t status;
1399 /* firstly, search cache */
1400 for (cache = r->htaccess; cache != NULL; cache = cache->next)
1401 if (cache->override == override && strcmp(cache->dir, d) == 0) {
1402 if (cache->htaccess != NULL)
1403 *result = cache->htaccess;
1407 parms = default_parms;
1408 parms.override = override;
1409 parms.pool = r->pool;
1410 parms.temp_pool = r->pool;
1411 parms.server = r->server;
1412 parms.path = apr_pstrdup(r->pool, d);
1414 /* loop through the access names and find the first one */
1416 while (access_name[0]) {
1417 filename = ap_make_full_path(r->pool, d,
1418 ap_getword_conf(r->pool, &access_name));
1419 status = ap_pcfg_openfile(&f, r->pool, filename);
1421 if (status == APR_SUCCESS) {
1423 ap_directive_t *temptree = NULL;
1425 dc = ap_create_per_dir_config(r->pool);
1427 parms.config_file = f;
1428 errmsg = ap_build_config(&parms, r->pool, r->pool, &temptree);
1430 errmsg = ap_walk_config(temptree, &parms, dc);
1432 ap_cfg_closefile(f);
1435 ap_log_rerror(APLOG_MARK, APLOG_ALERT|APLOG_NOERRNO, 0, r,
1436 "%s: %s", filename, errmsg);
1437 return HTTP_INTERNAL_SERVER_ERROR;
1442 if (!APR_STATUS_IS_ENOENT(status) && !APR_STATUS_IS_ENOTDIR(status)) {
1443 ap_log_rerror(APLOG_MARK, APLOG_CRIT, status, r,
1444 "%s pcfg_openfile: unable to check htaccess file, "
1445 "ensure it is readable",
1447 apr_table_setn(r->notes, "error-notes",
1448 "Server unable to read htaccess file, denying "
1449 "access to be safe");
1450 return HTTP_FORBIDDEN;
1456 new = apr_palloc(r->pool, sizeof(struct htaccess_result));
1457 new->dir = parms.path;
1458 new->override = override;
1460 /* add to head of list */
1461 new->next = r->htaccess;
1467 AP_CORE_DECLARE(const char *) ap_init_virtual_host(apr_pool_t *p, const char *hostname,
1468 server_rec *main_server, server_rec **ps)
1470 server_rec *s = (server_rec *) apr_pcalloc(p, sizeof(server_rec));
1472 /* TODO: this crap belongs in http_core */
1473 s->process = main_server->process;
1474 s->server_admin = NULL;
1475 s->server_hostname = NULL;
1476 s->error_fname = NULL;
1478 s->keep_alive_timeout = 0;
1480 s->keep_alive_max = -1;
1481 s->error_log = main_server->error_log;
1482 s->loglevel = main_server->loglevel;
1483 /* useful default, otherwise we get a port of 0 on redirects */
1484 s->port = main_server->port;
1488 s->names = apr_make_array(p, 4, sizeof(char **));
1489 s->wild_names = apr_make_array(p, 4, sizeof(char **));
1491 s->module_config = create_empty_config(p);
1492 s->lookup_defaults = ap_create_per_dir_config(p);
1494 s->limit_req_line = main_server->limit_req_line;
1495 s->limit_req_fieldsize = main_server->limit_req_fieldsize;
1496 s->limit_req_fields = main_server->limit_req_fields;
1500 return ap_parse_vhost_addrs(p, hostname, s);
1504 AP_DECLARE(void) ap_fixup_virtual_hosts(apr_pool_t *p, server_rec *main_server)
1508 for (virt = main_server->next; virt; virt = virt->next) {
1509 merge_server_configs(p, main_server->module_config,
1510 virt->module_config);
1512 virt->lookup_defaults =
1513 ap_merge_per_dir_configs(p, main_server->lookup_defaults,
1514 virt->lookup_defaults);
1516 if (virt->server_admin == NULL)
1517 virt->server_admin = main_server->server_admin;
1519 if (virt->timeout == 0)
1520 virt->timeout = main_server->timeout;
1522 if (virt->keep_alive_timeout == 0)
1523 virt->keep_alive_timeout = main_server->keep_alive_timeout;
1525 if (virt->keep_alive == -1)
1526 virt->keep_alive = main_server->keep_alive;
1528 if (virt->keep_alive_max == -1)
1529 virt->keep_alive_max = main_server->keep_alive_max;
1531 /* XXX: this is really something that should be dealt with by a
1532 * post-config api phase */
1533 ap_core_reorder_directories(p, virt);
1535 ap_core_reorder_directories(p, main_server);
1538 /*****************************************************************
1540 * Getting *everything* configured...
1543 static void init_config_globals(apr_pool_t *p)
1545 /* Global virtual host hash bucket pointers. Init to null. */
1546 ap_init_vhost_config(p);
1549 static server_rec *init_server_config(process_rec *process, apr_pool_t *p)
1552 server_rec *s = (server_rec *) apr_pcalloc(p, sizeof(server_rec));
1554 apr_open_stderr(&s->error_log, p);
1555 s->process = process;
1557 s->server_admin = DEFAULT_ADMIN;
1558 s->server_hostname = NULL;
1559 s->error_fname = DEFAULT_ERRORLOG;
1560 s->loglevel = DEFAULT_LOGLEVEL;
1561 s->limit_req_line = DEFAULT_LIMIT_REQUEST_LINE;
1562 s->limit_req_fieldsize = DEFAULT_LIMIT_REQUEST_FIELDSIZE;
1563 s->limit_req_fields = DEFAULT_LIMIT_REQUEST_FIELDS;
1564 s->timeout = DEFAULT_TIMEOUT;
1565 s->keep_alive_timeout = DEFAULT_KEEPALIVE_TIMEOUT;
1566 s->keep_alive_max = DEFAULT_KEEPALIVE;
1569 s->addrs = apr_pcalloc(p, sizeof(server_addr_rec));
1570 /* NOT virtual host; don't match any real network interface */
1571 rv = apr_getaddrinfo(&s->addrs->host_addr,
1572 NULL, APR_INET, 0, 0, p);
1573 ap_assert(rv == APR_SUCCESS); /* otherwise: bug or no storage */
1574 s->addrs->host_port = 0; /* matches any port */
1575 s->addrs->virthost = ""; /* must be non-NULL */
1576 s->names = s->wild_names = NULL;
1578 s->module_config = create_server_config(p, s);
1579 s->lookup_defaults = create_default_per_dir_config(p);
1585 AP_DECLARE(server_rec*) ap_read_config(process_rec *process, apr_pool_t *ptemp,
1586 const char *confname,
1587 ap_directive_t **conftree)
1589 apr_pool_t *p = process->pconf;
1590 server_rec *s = init_server_config(process, p);
1592 init_config_globals(p);
1594 /* All server-wide config files now have the SAME syntax... */
1596 process_command_config(s, ap_server_pre_read_config, conftree,
1599 ap_process_resource_config(s, confname, conftree, p, ptemp);
1601 process_command_config(s, ap_server_post_read_config, conftree,
1607 AP_DECLARE(void) ap_single_module_configure(apr_pool_t *p, server_rec *s,
1610 if (m->create_server_config)
1611 ap_set_module_config(s->module_config, m,
1612 (*m->create_server_config)(p, s));
1613 if (m->create_dir_config)
1614 ap_set_module_config(s->lookup_defaults, m,
1615 (*m->create_dir_config)(p, NULL));
1618 AP_DECLARE(void) ap_run_rewrite_args(process_rec *process)
1622 for (m = top_module; m; m = m->next)
1623 if (m->rewrite_args)
1624 (*m->rewrite_args) (process);
1627 AP_DECLARE(void) ap_post_config_hook(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s)
1629 ap_run_post_config(pconf,plog,ptemp,s);
1632 void ap_child_init_hook(apr_pool_t *pchild, server_rec *s)
1634 /* TODO: uh this seems ugly, is there a better way? */
1635 /*ap_child_init_alloc(); PUT THIS BACK IN XXXXX */
1637 ap_run_child_init(pchild,s);
1640 /********************************************************************
1641 * Configuration directives are restricted in terms of where they may
1642 * appear in the main configuration files and/or .htaccess files according
1643 * to the bitmask req_override in the command_rec structure.
1644 * If any of the overrides set in req_override are also allowed in the
1645 * context in which the command is read, then the command is allowed.
1646 * The context is determined as follows:
1648 * inside *.conf --> override = (RSRC_CONF|OR_ALL)&~(OR_AUTHCFG|OR_LIMIT);
1649 * within <Directory> or <Location> --> override = OR_ALL|ACCESS_CONF;
1650 * within .htaccess --> override = AllowOverride for current directory;
1652 * the result is, well, a rather confusing set of possibilities for when
1653 * a particular directive is allowed to be used. This procedure prints
1654 * in English where the given (pc) directive can be used.
1656 static void show_overrides(const command_rec *pc, module *pm)
1660 printf("\tAllowed in *.conf ");
1661 if ((pc->req_override & (OR_OPTIONS | OR_FILEINFO | OR_INDEXES)) ||
1662 ((pc->req_override & RSRC_CONF) &&
1663 ((pc->req_override & (ACCESS_CONF | OR_AUTHCFG | OR_LIMIT)))))
1665 else if (pc->req_override & RSRC_CONF)
1666 printf("only outside <Directory>, <Files> or <Location>");
1668 printf("only inside <Directory>, <Files> or <Location>");
1670 /* Warn if the directive is allowed inside <Directory> or .htaccess
1671 * but module doesn't support per-dir configuration */
1673 if ((pc->req_override & (OR_ALL | ACCESS_CONF)) && !pm->create_dir_config)
1674 printf(" [no per-dir config]");
1676 if (pc->req_override & OR_ALL) {
1677 printf(" and in .htaccess\n\twhen AllowOverride");
1679 if ((pc->req_override & OR_ALL) == OR_ALL)
1680 printf(" isn't None");
1682 printf(" includes ");
1684 if (pc->req_override & OR_AUTHCFG) {
1687 printf("AuthConfig");
1689 if (pc->req_override & OR_LIMIT) {
1694 if (pc->req_override & OR_OPTIONS) {
1699 if (pc->req_override & OR_FILEINFO) {
1704 if (pc->req_override & OR_INDEXES) {
1714 /* Show the preloaded configuration directives, the help string explaining
1715 * the directive arguments, in what module they are handled, and in
1716 * what parts of the configuration they are allowed. Used for httpd -h.
1718 AP_DECLARE(void) ap_show_directives()
1720 const command_rec *pc;
1723 for (n = 0; ap_loaded_modules[n]; ++n)
1724 for (pc = ap_loaded_modules[n]->cmds; pc && pc->name; ++pc) {
1725 printf("%s (%s)\n", pc->name, ap_loaded_modules[n]->name);
1727 printf("\t%s\n", pc->errmsg);
1728 show_overrides(pc, ap_loaded_modules[n]);
1732 /* Show the preloaded module names. Used for httpd -l. */
1733 AP_DECLARE(void) ap_show_modules()
1737 printf("Compiled in modules:\n");
1738 for (n = 0; ap_loaded_modules[n]; ++n)
1739 printf(" %s\n", ap_loaded_modules[n]->name);