config.c revision 23923c878b8e2ade4ca9cb67d240fc744661a7a3
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein/* ====================================================================
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * Copyright (c) 1995-2000 The Apache Software Foundation. All rights reserved.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * Redistribution and use in source and binary forms, with or without
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * modification, are permitted provided that the following conditions
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * 1. Redistributions of source code must retain the above copyright
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * notice, this list of conditions and the following disclaimer.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * 2. Redistributions in binary form must reproduce the above copyright
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * notice, this list of conditions and the following disclaimer in
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * the documentation and/or other materials provided with the
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * distribution.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * 3. All advertising materials mentioning features or use of this
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * software must display the following acknowledgment:
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * "This product includes software developed by the Apache Software Foundation
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * for use in the Apache HTTP server project (http://www.apache.org/)."
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * 4. The names "Apache Server" and "Apache Software Foundation" must not be used to
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * endorse or promote products derived from this software without
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * prior written permission. For written permission, please contact
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * apache@apache.org.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * 5. Products derived from this software may not be called "Apache"
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * nor may "Apache" appear in their names without prior written
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * permission of the Apache Software Foundation.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * 6. Redistributions of any form whatsoever must retain the following
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * acknowledgment:
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * "This product includes software developed by the Apache Software Foundation
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * for use in the Apache HTTP server project (http://www.apache.org/)."
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * THIS SOFTWARE IS PROVIDED BY THE Apache Software Foundation ``AS IS'' AND ANY
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE Apache Software Foundation OR
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * OF THE POSSIBILITY OF SUCH DAMAGE.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * ====================================================================
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * This software consists of voluntary contributions made by many
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * individuals on behalf of the Apache Software Foundation and was originally based
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * on public domain software written at the National Center for
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * Supercomputing Applications, University of Illinois, Urbana-Champaign.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * For more information on the Apache Software Foundation and the Apache HTTP server
f4c310fd2555c6faca1f980f00b161eadb089023gstein * project, please see <http://www.apache.org/>.
f4c310fd2555c6faca1f980f00b161eadb089023gstein * http_config.c: once was auxillary functions for reading httpd's config
f4c310fd2555c6faca1f980f00b161eadb089023gstein * file and converting filenames into a namespace
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Rob McCool
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Wall-to-wall rewrite for Apache... commands which are part of the
f4c310fd2555c6faca1f980f00b161eadb089023gstein * server core can now be found next door in "http_core.c". Now contains
f4c310fd2555c6faca1f980f00b161eadb089023gstein * general command loop, and functions which do bookkeeping for the new
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Apache config stuff (modules and configuration vectors).
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "http_log.h" /* for errors in parse_htaccess */
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "http_request.h" /* for default_handler (see invoke_handler) */
f4c310fd2555c6faca1f980f00b161eadb089023gsteinIMPLEMENT_HOOK_RUN_ALL(int,header_parser,(request_rec *r),(r),OK,DECLINED)
f4c310fd2555c6faca1f980f00b161eadb089023gsteinIMPLEMENT_HOOK_VOID(pre_config,(ap_context_t *pconf,ap_context_t *plog,ap_context_t *ptemp),
000397350b42c6266351bd618fa07df929fa7c79gstein (ap_context_t *pconf, ap_context_t *plog, ap_context_t *ptemp, server_rec *s),
f4c310fd2555c6faca1f980f00b161eadb089023gstein (ap_context_t *pconf, ap_context_t *plog, ap_context_t *ptemp, server_rec *s),
f4c310fd2555c6faca1f980f00b161eadb089023gsteinIMPLEMENT_HOOK_VOID(child_init,(ap_context_t *pchild, server_rec *s),(pchild,s))
f4c310fd2555c6faca1f980f00b161eadb089023gstein/****************************************************************
9f18c80269be35c0b5653e84b0db0a24044722c4gstein * We begin with the functions which deal with the linked list
9f18c80269be35c0b5653e84b0db0a24044722c4gstein * of modules which control just about all of the server operation.
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* total_modules is the number of modules that have been linked
f4c310fd2555c6faca1f980f00b161eadb089023gstein * into the server.
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic int total_modules = 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* dynamic_modules is the number of modules that have been added
f4c310fd2555c6faca1f980f00b161eadb089023gstein * after the pre-loaded ones have been set up. It shouldn't be larger
f4c310fd2555c6faca1f980f00b161eadb089023gstein * than DYNAMIC_MODULE_LIMIT.
b47464a901075041e800be2de098a603923fa4f9gsteinstatic int dynamic_modules = 0;
f4c310fd2555c6faca1f980f00b161eadb089023gsteintypedef void *(*dir_maker_func) (ap_context_t *, char *);
f4c310fd2555c6faca1f980f00b161eadb089023gsteintypedef void *(*merger_func) (ap_context_t *, void *, void *);
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* Dealing with config vectors. These are associated with per-directory,
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe * per-server, and per-request configuration, and have a void* pointer for
f4c310fd2555c6faca1f980f00b161eadb089023gstein * each modules. The nature of the structure pointed to is private to the
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * module in question... the core doesn't (and can't) know. However, there
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein * are defined interfaces which allow it to create instances of its private
f4c310fd2555c6faca1f980f00b161eadb089023gstein * per-directory and per-server structures, and to merge the per-directory
f4c310fd2555c6faca1f980f00b161eadb089023gstein * structures of a directory and its subdirectory (producing a new one in
f4c310fd2555c6faca1f980f00b161eadb089023gstein * which the defaults applying to the base directory have been properly
9f18c80269be35c0b5653e84b0db0a24044722c4gstein * overridden).
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAPI_EXPORT(void *) ap_get_module_config(void *conf_vector, module *m)
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAPI_EXPORT(void) ap_set_module_config(void *conf_vector, module *m, void *val)
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm void **conf_vector = (void **) ap_pcalloc(p, sizeof(void *) *
b47464a901075041e800be2de098a603923fa4f9gstein return (void *) conf_vector;
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic void *create_default_per_dir_config(ap_context_t *p)
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm void **conf_vector = (void **) ap_pcalloc(p, sizeof(void *) * (total_modules + DYNAMIC_MODULE_LIMIT));
de18a9e85398b9c79c422f578633ed56c2747bbbgstein return (void *) conf_vector;
de18a9e85398b9c79c422f578633ed56c2747bbbgstein ap_merge_per_dir_configs(ap_context_t *p, void *base, void *new)
de18a9e85398b9c79c422f578633ed56c2747bbbgstein void **conf_vector = (void **) ap_palloc(p, sizeof(void *) * total_modules);
f4c310fd2555c6faca1f980f00b161eadb089023gstein conf_vector[i] = (*df) (p, base_vector[i], new_vector[i]);
f4c310fd2555c6faca1f980f00b161eadb089023gstein conf_vector[i] = new_vector[i] ? new_vector[i] : base_vector[i];
f4c310fd2555c6faca1f980f00b161eadb089023gstein return (void *) conf_vector;
de18a9e85398b9c79c422f578633ed56c2747bbbgsteinstatic void *create_server_config(ap_context_t *p, server_rec *s)
9f18c80269be35c0b5653e84b0db0a24044722c4gstein void **conf_vector = (void **) ap_pcalloc(p, sizeof(void *) * (total_modules + DYNAMIC_MODULE_LIMIT));
000397350b42c6266351bd618fa07df929fa7c79gstein conf_vector[modp->module_index] = (*modp->create_server_config) (p, s);
000397350b42c6266351bd618fa07df929fa7c79gstein return (void *) conf_vector;
000397350b42c6266351bd618fa07df929fa7c79gsteinstatic void merge_server_configs(ap_context_t *p, void *base, void *virt)
000397350b42c6266351bd618fa07df929fa7c79gstein /* Can reuse the 'virt' vector for the spine of it, since we don't
f4c310fd2555c6faca1f980f00b161eadb089023gstein * have to deal with the moral equivalent of .htaccess files here...
f4c310fd2555c6faca1f980f00b161eadb089023gstein virt_vector[i] = (*df) (p, base_vector[i], virt_vector[i]);
9f18c80269be35c0b5653e84b0db0a24044722c4gsteinCORE_EXPORT(void *) ap_create_per_dir_config(ap_context_t *p)
709df1e1c2e1710570f8cb4209497e88662829c3gstein * For speed/efficiency we generate a compact list of all the handlers
eb2abb2d3f87f28e99bcb282b91e432822b4d9b4gstein * and wildcard handlers. This means we won't have to scan the entire
eb2abb2d3f87f28e99bcb282b91e432822b4d9b4gstein * module list looking for handlers... where we'll find a whole whack
f4c310fd2555c6faca1f980f00b161eadb089023gstein * of NULLs.
eb2abb2d3f87f28e99bcb282b91e432822b4d9b4gsteintypedef struct {
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (handp = modp->handlers; handp->content_type; ++handp) {
000397350b42c6266351bd618fa07df929fa7c79gstein ph = handlers = ap_palloc(p, sizeof(*ph)*(nhandlers + 1));
9f18c80269be35c0b5653e84b0db0a24044722c4gstein pw = wildhandlers = ap_palloc(p, sizeof(*pw)*(nwildhandlers + 1));
9f18c80269be35c0b5653e84b0db0a24044722c4gstein for (handp = modp->handlers; handp->content_type; ++handp) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *handler;
f4c310fd2555c6faca1f980f00b161eadb089023gstein handler = r->content_type ? r->content_type : ap_default_type(r);
26250b0077972bf21b6d8a8d23772a4cf53f9477gstein if ((p = strchr(handler, ';')) != NULL) { /* MIME type arguments */
f4c310fd2555c6faca1f980f00b161eadb089023gstein --p; /* strip trailing spaces */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Pass one --- direct matches */
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (handp = handlers; handp->hr.content_type; ++handp) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein && !strncmp(handler, handp->hr.content_type, handler_len)) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Pass two --- wildcard matches */
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (handp = wildhandlers; handp->hr.content_type; ++handp) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein && !strncmp(handler, handp->hr.content_type, handp->len)) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (result == HTTP_INTERNAL_SERVER_ERROR && r->handler && r->filename) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING, 0, r,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "handler \"%s\" not found for: %s", r->handler, r->filename);
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* One-time setup for precompiled modules --- NOT to be done on restart */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* This could be called from an AddModule httpd.conf command,
f4c310fd2555c6faca1f980f00b161eadb089023gstein * after the file has been linked and the module structure within it
f4c310fd2555c6faca1f980f00b161eadb089023gstein * teased out...
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "%s: module \"%s\" is not compatible with this "
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, "Please contact the vendor for the correct version.");
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "%s: module \"%s\" could not be loaded, because"
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "module limit was reached. Please increase "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "DYNAMIC_MODULE_LIMIT and recompile.");
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Some C compilers put a complete path into __FILE__, but we want
f4c310fd2555c6faca1f980f00b161eadb089023gstein * only the filename (e.g. mod_includes.c). So check for path
f4c310fd2555c6faca1f980f00b161eadb089023gstein * components (Unix and DOS), and remove them.
252e2478cb56afb5ca8585b50bc2ffb780d2efb6gstein#ifdef _OSD_POSIX /* __FILE__="*POSIX(/home/martin/apache/src/modules/standard/mod_info.c)" */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* We cannot fix the string in-place, because it's const */
f4c310fd2555c6faca1f980f00b161eadb089023gstein char *tmp = strdup(m->name); /* FIXME:memory leak, albeit a small one */
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif /*_OSD_POSIX*/
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* FIXME: is this the right place to call this? */
f4c310fd2555c6faca1f980f00b161eadb089023gstein * remove_module undoes what add_module did. There are some caveats:
f4c310fd2555c6faca1f980f00b161eadb089023gstein * when the module is removed, its slot is lost so all the current
f4c310fd2555c6faca1f980f00b161eadb089023gstein * per-dir and per-server configurations are invalid. So we should
f4c310fd2555c6faca1f980f00b161eadb089023gstein * only ever call this function when you are invalidating almost
f4c310fd2555c6faca1f980f00b161eadb089023gstein * all our current data. I.e. when doing a restart.
d839a9822ee53ce00da24c15f2d9fe054233d342gstein if (modp == m) {
d839a9822ee53ce00da24c15f2d9fe054233d342gstein /* We are the top module, special case */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Not the top module, find use. When found modp will
f4c310fd2555c6faca1f980f00b161eadb089023gstein * point to the module _before_ us in the list
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Uh-oh, this module doesn't exist */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, NULL,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Cannot remove module %s: not found in module list",
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Eliminate us from the module list */
f4c310fd2555c6faca1f980f00b161eadb089023gstein m->module_index = -1; /* simulate being unloaded, should
f4c310fd2555c6faca1f980f00b161eadb089023gstein * be unnecessary */
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Add module pointer to top of chained module list
f4c310fd2555c6faca1f980f00b161eadb089023gstein * And module pointer to list of loaded modules
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Notes: 1. ap_add_module() would already complain if no more space
f4c310fd2555c6faca1f980f00b161eadb089023gstein * exists for adding a dynamically loaded module
f4c310fd2555c6faca1f980f00b161eadb089023gstein * 2. ap_add_module() accepts double inclusion, so we have
f4c310fd2555c6faca1f980f00b161eadb089023gstein * to accept this, too.
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Remove module pointer from chained module list
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Remove module pointer from list of loaded modules
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Note: 1. We cannot determine if the module was successfully
f4c310fd2555c6faca1f980f00b161eadb089023gstein * removed by ap_remove_module().
f4c310fd2555c6faca1f980f00b161eadb089023gstein * 2. We have not to complain explicity when the module
f4c310fd2555c6faca1f980f00b161eadb089023gstein * is not found because ap_remove_module() did it
f4c310fd2555c6faca1f980f00b161eadb089023gstein * for us already.
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (m = m2 = ap_loaded_modules, done = 0; *m2 != NULL; m2++) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Initialise total_modules variable and module indices
50bd75672ef114fb839dd9643c192b432fdf344cgstein * Initialise list of loaded modules
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_loaded_modules = (module **)ap_palloc(process->pool,
f4c310fd2555c6faca1f980f00b161eadb089023gstein sizeof(module *)*(total_modules+DYNAMIC_MODULE_LIMIT+1));
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Ouch! Out of memory in ap_setup_prelinked_modules()!");
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (m = ap_preloaded_modules, m2 = ap_loaded_modules; *m != NULL; )
f4c310fd2555c6faca1f980f00b161eadb089023gstein *m2++ = *m++;
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein * Initialize chain of linked (=activate) modules
50bd75672ef114fb839dd9643c192b432fdf344cgsteinAPI_EXPORT(const char *) ap_find_module_name(module *m)
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAPI_EXPORT(module *) ap_find_linked_module(const char *name)
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* Add a named module. Returns 1 if module found, 0 otherwise. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (modp = ap_loaded_modules[i]; modp; modp = ap_loaded_modules[++i]) {
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein /* Only add modules that are not already enabled. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* Clear the internal list of modules, in preparation for starting over. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein while (*m) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* This is required; so we add it always. */
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein/*****************************************************************
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein * Resource, access, and .htaccess config files now parsed by a common
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein * command loop.
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein * Let's begin with the basics; parsing the line and
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein * invoking the function...
5a47cad1aef57039cd47eb34ebbc2959c610f326gsteinstatic const char *invoke_cmd(const command_rec *cmd, cmd_parms *parms,
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *errmsg;
5a47cad1aef57039cd47eb34ebbc2959c610f326gstein return ap_pstrcat(parms->pool, cmd->name, " not allowed here", NULL);
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein return ((const char *(*)(cmd_parms *, void *, const char *))
9f18c80269be35c0b5653e84b0db0a24044722c4gstein return ap_pstrcat(parms->pool, cmd->name, " takes no arguments",
9f18c80269be35c0b5653e84b0db0a24044722c4gstein return ((const char *(*)(cmd_parms *, void *))
5a47cad1aef57039cd47eb34ebbc2959c610f326gstein return ap_pstrcat(parms->pool, cmd->name, " takes one argument",
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein return ((const char *(*)(cmd_parms *, void *, const char *))
f4c310fd2555c6faca1f980f00b161eadb089023gstein return ap_pstrcat(parms->pool, cmd->name, " takes two arguments",
f4c310fd2555c6faca1f980f00b161eadb089023gstein return ((const char *(*)(cmd_parms *, void *, const char *,
f4c310fd2555c6faca1f980f00b161eadb089023gstein return ap_pstrcat(parms->pool, cmd->name, " takes 1-2 arguments",
26250b0077972bf21b6d8a8d23772a4cf53f9477gstein return ((const char *(*)(cmd_parms *, void *, const char *,
26250b0077972bf21b6d8a8d23772a4cf53f9477gstein if (*w == '\0' || *w2 == '\0' || *w3 == '\0' || *args != 0)
26250b0077972bf21b6d8a8d23772a4cf53f9477gstein return ap_pstrcat(parms->pool, cmd->name, " takes three arguments",
f4c310fd2555c6faca1f980f00b161eadb089023gstein return ((const char *(*)(cmd_parms *, void *, const char *,
f4c310fd2555c6faca1f980f00b161eadb089023gstein w3 = *args ? ap_getword_conf(parms->pool, &args) : NULL;
f4c310fd2555c6faca1f980f00b161eadb089023gstein " takes two or three arguments",
f4c310fd2555c6faca1f980f00b161eadb089023gstein return ((const char *(*)(cmd_parms *, void *, const char *,
f4c310fd2555c6faca1f980f00b161eadb089023gstein w2 = *args ? ap_getword_conf(parms->pool, &args) : NULL;
f4c310fd2555c6faca1f980f00b161eadb089023gstein w3 = *args ? ap_getword_conf(parms->pool, &args) : NULL;
f4c310fd2555c6faca1f980f00b161eadb089023gstein " takes one, two or three arguments",
f4c310fd2555c6faca1f980f00b161eadb089023gstein return ((const char *(*)(cmd_parms *, void *, const char *,
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein w2 = *args ? ap_getword_conf(parms->pool, &args) : NULL;
f4c310fd2555c6faca1f980f00b161eadb089023gstein w3 = *args ? ap_getword_conf(parms->pool, &args) : NULL;
f4c310fd2555c6faca1f980f00b161eadb089023gstein " takes one or three arguments",
f4c310fd2555c6faca1f980f00b161eadb089023gstein return ((const char *(*)(cmd_parms *, void *, const char *,
f4c310fd2555c6faca1f980f00b161eadb089023gstein while (*(w = ap_getword_conf(parms->pool, &args)) != '\0')
f4c310fd2555c6faca1f980f00b161eadb089023gstein " requires at least two arguments",
f4c310fd2555c6faca1f980f00b161eadb089023gstein while (*(w2 = ap_getword_conf(parms->pool, &args)) != '\0')
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (*w == '\0' || (strcasecmp(w, "on") && strcasecmp(w, "off")))
f4c310fd2555c6faca1f980f00b161eadb089023gstein return ap_pstrcat(parms->pool, cmd->name, " must be On or Off",
f4c310fd2555c6faca1f980f00b161eadb089023gstein return ((const char *(*)(cmd_parms *, void *, int))
f4c310fd2555c6faca1f980f00b161eadb089023gstein (cmd->func)) (parms, mconfig, strcasecmp(w, "off") != 0);
f4c310fd2555c6faca1f980f00b161eadb089023gstein " is improperly configured internally (server bug)",
f4c310fd2555c6faca1f980f00b161eadb089023gsteinCORE_EXPORT(const command_rec *) ap_find_command(const char *name, const command_rec *cmds)
f4c310fd2555c6faca1f980f00b161eadb089023gsteinCORE_EXPORT(const command_rec *) ap_find_command_in_modules(const char *cmd_name, module **mod)
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (modp->cmds && (cmdp = ap_find_command(cmd_name, modp->cmds))) {
f4c310fd2555c6faca1f980f00b161eadb089023gsteinCORE_EXPORT(void *) ap_set_config_vectors(cmd_parms *parms, void *config, module *mod)
f4c310fd2555c6faca1f980f00b161eadb089023gstein void *sconfig = ap_get_module_config(parms->server->module_config, mod);
f4c310fd2555c6faca1f980f00b161eadb089023gstein mconfig = (*mod->create_dir_config) (parms->pool, parms->path);
f4c310fd2555c6faca1f980f00b161eadb089023gstein sconfig = (*mod->create_server_config) (parms->pool, parms->server);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_set_module_config(parms->server->module_config, mod, sconfig);
f4c310fd2555c6faca1f980f00b161eadb089023gsteinCORE_EXPORT(const char *) ap_handle_command(cmd_parms *parms, void *config, const char *l)
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((l[0] == '#') || (!l[0]))
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!(cmd = ap_find_command_in_modules(cmd_name, &mod))) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein return ap_pstrcat(parms->pool, "Invalid command '", cmd_name,
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm "', perhaps mis-spelled or defined by a module "
f4c310fd2555c6faca1f980f00b161eadb089023gstein void *mconfig = ap_set_config_vectors(parms,config, mod);
f4c310fd2555c6faca1f980f00b161eadb089023gstein mod = mod->next; /* Next time around, skip this one */
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAPI_EXPORT(const char *) ap_srm_command_loop(cmd_parms *parms, void *config)
f4c310fd2555c6faca1f980f00b161eadb089023gstein while (!(ap_cfg_getline(l, MAX_STRING_LEN, parms->config_file))) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *errmsg = ap_handle_command(parms, config, l);
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Generic command functions...
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAPI_EXPORT_NONSTD(const char *) ap_set_string_slot(cmd_parms *cmd,
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* This one's pretty generic... */
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAPI_EXPORT_NONSTD(const char *) ap_set_string_slot_lower(cmd_parms *cmd,
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* This one's pretty generic... */
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAPI_EXPORT_NONSTD(const char *) ap_set_flag_slot(cmd_parms *cmd,
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein /* This one's pretty generic too... */
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAPI_EXPORT_NONSTD(const char *) ap_set_file_slot(cmd_parms *cmd, char *struct_ptr, char *arg)
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Prepend server_root to relative arg.
f4c310fd2555c6faca1f980f00b161eadb089023gstein This allows .htaccess to be independent of server_root,
f4c310fd2555c6faca1f980f00b161eadb089023gstein so the server can be moved or mirrored with less pain. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein p = ap_make_full_path(cmd->pool, ap_server_root, arg);
f4c310fd2555c6faca1f980f00b161eadb089023gstein/*****************************************************************
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Reading whole config files...
f4c310fd2555c6faca1f980f00b161eadb089023gstein{NULL, 0, -1, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAPI_EXPORT(const char *) ap_server_root_relative(ap_context_t *p, const char *file)
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein/* This structure and the following functions are needed for the
f4c310fd2555c6faca1f980f00b161eadb089023gstein * table-based config file reading. They are passed to the
f4c310fd2555c6faca1f980f00b161eadb089023gstein * cfg_open_custom() routine.
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* Structure to be passed to cfg_open_custom(): it contains an
f4c310fd2555c6faca1f980f00b161eadb089023gstein * index which is incremented from 0 to nelts on each call to
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * cfg_getline() (which in turn calls arr_elts_getstr())
f4c310fd2555c6faca1f980f00b161eadb089023gstein * and an ap_array_header_t pointer for the string array.
f4c310fd2555c6faca1f980f00b161eadb089023gsteintypedef struct {
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* arr_elts_getstr() returns the next line from the string array. */
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic void *arr_elts_getstr(void *buf, size_t bufsiz, void *param)
f4c310fd2555c6faca1f980f00b161eadb089023gstein arr_elts_param_t *arr_param = (arr_elts_param_t *) param;
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* End of array reached? */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* return the line */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_cpystrn(buf, ((char **) arr_param->array->elts)[arr_param->curr_idx - 1], bufsiz);
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* arr_elts_close(): dummy close routine (makes sure no more lines can be read) */
f4c310fd2555c6faca1f980f00b161eadb089023gstein arr_elts_param_t *arr_param = (arr_elts_param_t *) param;
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic void process_command_config(server_rec *s, ap_array_header_t *arr, ap_context_t *p,
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *errmsg;
f4c310fd2555c6faca1f980f00b161eadb089023gstein parms.override = (RSRC_CONF | OR_ALL) & ~(OR_AUTHCFG | OR_LIMIT);
f4c310fd2555c6faca1f980f00b161eadb089023gstein parms.config_file = ap_pcfg_open_custom(p, "-c/-C directives",
f4c310fd2555c6faca1f980f00b161eadb089023gstein errmsg = ap_srm_command_loop(&parms, s->lookup_defaults);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
f4c310fd2555c6faca1f980f00b161eadb089023gsteinvoid ap_process_resource_config(server_rec *s, const char *fname, ap_context_t *p, ap_context_t *ptemp)
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *errmsg;
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!(strcmp(fname, ap_server_root_relative(p, RESOURCE_CONFIG_FILE))) ||
f4c310fd2555c6faca1f980f00b161eadb089023gstein !(strcmp(fname, ap_server_root_relative(p, ACCESS_CONFIG_FILE)))) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* don't require conf/httpd.conf if we have a -C or -c switch */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if((ap_server_pre_read_config->nelts || ap_server_post_read_config->nelts) &&
f4c310fd2555c6faca1f980f00b161eadb089023gstein !(strcmp(fname, ap_server_root_relative(p, SERVER_CONFIG_FILE)))) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* GCC's initialization extensions are soooo nice here... */
f4c310fd2555c6faca1f980f00b161eadb089023gstein parms.override = (RSRC_CONF | OR_ALL) & ~(OR_AUTHCFG | OR_LIMIT);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (ap_pcfg_openfile(&parms.config_file, p, fname) != APR_SUCCESS) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "%s: could not open document config file %s",
f4c310fd2555c6faca1f980f00b161eadb089023gstein errmsg = ap_srm_command_loop(&parms, s->lookup_defaults);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Syntax error on line %d of %s:",
f4c310fd2555c6faca1f980f00b161eadb089023gstein parms.config_file->line_number, parms.config_file->name);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
f4c310fd2555c6faca1f980f00b161eadb089023gsteinint ap_parse_htaccess(void **result, request_rec *r, int override,
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *d, const char *access_name)
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein const char *errmsg;
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* firstly, search cache */
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (cache = r->htaccess; cache != NULL; cache = cache->next)
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (cache->override == override && strcmp(cache->dir, d) == 0) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* loop through the access names and find the first one */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_rerror(APLOG_MARK, APLOG_ALERT|APLOG_NOERRNO, 0, r,
f4c310fd2555c6faca1f980f00b161eadb089023gstein else if (status != APR_ENOENT && status != APR_ENOTDIR) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein "%s pcfg_openfile: unable to check htaccess file, "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "ensure it is readable",
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Server unable to read htaccess file, denying "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "access to be safe");
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* cache it */
f4c310fd2555c6faca1f980f00b161eadb089023gstein new = ap_palloc(r->pool, sizeof(struct htaccess_result));
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* add to head of list */
f4c310fd2555c6faca1f980f00b161eadb089023gsteinCORE_EXPORT(const char *) ap_init_virtual_host(ap_context_t *p, const char *hostname,
f4c310fd2555c6faca1f980f00b161eadb089023gstein server_rec *s = (server_rec *) ap_pcalloc(p, sizeof(server_rec));
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Cannot exceed hard limit for open files");
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* TODO: this crap belongs in http_core */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* useful default, otherwise we get a port of 0 on redirects */
f4c310fd2555c6faca1f980f00b161eadb089023gstein s->wild_names = ap_make_array(p, 4, sizeof(char **));
f4c310fd2555c6faca1f980f00b161eadb089023gstein s->limit_req_fieldsize = main_server->limit_req_fieldsize;
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic void fixup_virtual_hosts(ap_context_t *p, server_rec *main_server)
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (virt = main_server->next; virt; virt = virt->next) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_merge_per_dir_configs(p, main_server->lookup_defaults,
f4c310fd2555c6faca1f980f00b161eadb089023gstein virt->access_confname = main_server->access_confname;
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein virt->keep_alive_timeout = main_server->keep_alive_timeout;
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* XXX: this is really something that should be dealt with by a
f4c310fd2555c6faca1f980f00b161eadb089023gstein * post-config api phase */
f4c310fd2555c6faca1f980f00b161eadb089023gstein/*****************************************************************
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Getting *everything* configured...
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Global virtual host hash bucket pointers. Init to null. */
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic server_rec *init_server_config(process_rec *process, ap_context_t *p)
f4c310fd2555c6faca1f980f00b161eadb089023gstein server_rec *s = (server_rec *) ap_pcalloc(p, sizeof(server_rec));
6b745319b1099edacf401e8911efa480440f999agstein s->limit_req_fieldsize = DEFAULT_LIMIT_REQUEST_FIELDSIZE;
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* NOT virtual host; don't match any real network interface */
f4c310fd2555c6faca1f980f00b161eadb089023gstein s->lookup_defaults = create_default_per_dir_config(p);
f4c310fd2555c6faca1f980f00b161eadb089023gsteinserver_rec *ap_read_config(process_rec *process, ap_context_t *ptemp, const char *confname)
6b745319b1099edacf401e8911efa480440f999agstein /* All server-wide config files now have the SAME syntax... */
6b745319b1099edacf401e8911efa480440f999agstein process_command_config(s, ap_server_pre_read_config, p, ptemp);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm ap_process_resource_config(s, s->srm_confname, p, ptemp);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_process_resource_config(s, s->access_confname, p, ptemp);
f4c310fd2555c6faca1f980f00b161eadb089023gstein process_command_config(s, ap_server_post_read_config, p, ptemp);
f4c310fd2555c6faca1f980f00b161eadb089023gsteinvoid ap_single_module_configure(ap_context_t *p, server_rec *s, module *m)
f4c310fd2555c6faca1f980f00b161eadb089023gsteinvoid ap_post_config_hook(ap_context_t *pconf, ap_context_t *plog, ap_context_t *ptemp, server_rec *s)
f4c310fd2555c6faca1f980f00b161eadb089023gsteinvoid ap_child_init_hook(ap_context_t *pchild, server_rec *s)
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm /* TODO: uh this seems ugly, is there a better way? */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /*ap_child_init_alloc(); PUT THIS BACK IN XXXXX */
f4c310fd2555c6faca1f980f00b161eadb089023gstein/********************************************************************
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Configuration directives are restricted in terms of where they may
f4c310fd2555c6faca1f980f00b161eadb089023gstein * appear in the main configuration files and/or .htaccess files according
f4c310fd2555c6faca1f980f00b161eadb089023gstein * to the bitmask req_override in the command_rec structure.
f4c310fd2555c6faca1f980f00b161eadb089023gstein * If any of the overrides set in req_override are also allowed in the
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * context in which the command is read, then the command is allowed.
f4c310fd2555c6faca1f980f00b161eadb089023gstein * The context is determined as follows:
f4c310fd2555c6faca1f980f00b161eadb089023gstein * inside *.conf --> override = (RSRC_CONF|OR_ALL)&~(OR_AUTHCFG|OR_LIMIT);
f4c310fd2555c6faca1f980f00b161eadb089023gstein * within <Directory> or <Location> --> override = OR_ALL|ACCESS_CONF;
f4c310fd2555c6faca1f980f00b161eadb089023gstein * within .htaccess --> override = AllowOverride for current directory;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * the result is, well, a rather confusing set of possibilities for when
f4c310fd2555c6faca1f980f00b161eadb089023gstein * a particular directive is allowed to be used. This procedure prints
f4c310fd2555c6faca1f980f00b161eadb089023gstein * in English where the given (pc) directive can be used.
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic void show_overrides(const command_rec *pc, module *pm)
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((pc->req_override & (OR_OPTIONS | OR_FILEINFO | OR_INDEXES)) ||
f4c310fd2555c6faca1f980f00b161eadb089023gstein ((pc->req_override & (ACCESS_CONF | OR_AUTHCFG | OR_LIMIT)))))
f4c310fd2555c6faca1f980f00b161eadb089023gstein printf("only outside <Directory>, <Files> or <Location>");
7281ea331999debdc337b02ce37a3169e0e033a2gstein printf("only inside <Directory>, <Files> or <Location>");
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* Warn if the directive is allowed inside <Directory> or .htaccess
7281ea331999debdc337b02ce37a3169e0e033a2gstein * but module doesn't support per-dir configuration */
7281ea331999debdc337b02ce37a3169e0e033a2gstein if ((pc->req_override & (OR_ALL | ACCESS_CONF)) && !pm->create_dir_config)
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* Show the preloaded configuration directives, the help string explaining
f4c310fd2555c6faca1f980f00b161eadb089023gstein * the directive arguments, in what module they are handled, and in
f4c310fd2555c6faca1f980f00b161eadb089023gstein * what parts of the configuration they are allowed. Used for httpd -h.
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (n = 0; ap_loaded_modules[n]; ++n)
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (pc = ap_loaded_modules[n]->cmds; pc && pc->name; ++pc) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein printf("%s (%s)\n", pc->name, ap_loaded_modules[n]->name);
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* Show the preloaded module names. Used for httpd -l. */
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein for (n = 0; ap_loaded_modules[n]; ++n)