config.c revision 30e3e9b782c701f885583b7d13d8e46c37d7e1dd
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes/* ====================================================================
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * The Apache Software License, Version 1.1
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * Copyright (c) 2000-2001 The Apache Software Foundation. All rights
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * Redistribution and use in source and binary forms, with or without
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * modification, are permitted provided that the following conditions
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * 1. Redistributions of source code must retain the above copyright
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * notice, this list of conditions and the following disclaimer.
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * 2. Redistributions in binary form must reproduce the above copyright
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * notice, this list of conditions and the following disclaimer in
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * the documentation and/or other materials provided with the
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * distribution.
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * 3. The end-user documentation included with the redistribution,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * if any, must include the following acknowledgment:
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * "This product includes software developed by the
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * Apache Software Foundation (http://www.apache.org/)."
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * Alternately, this acknowledgment may appear in the software itself,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * if and wherever such third-party acknowledgments normally appear.
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * 4. The names "Apache" and "Apache Software Foundation" must
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * not be used to endorse or promote products derived from this
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * software without prior written permission. For written
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * permission, please contact apache@apache.org.
70953fb44a7140fe206c3a5f011e24209c8c5c6abnicholes * 5. Products derived from this software may not be called "Apache",
70953fb44a7140fe206c3a5f011e24209c8c5c6abnicholes * nor may "Apache" appear in their name, without prior written
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * permission of the Apache Software Foundation.
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * SUCH DAMAGE.
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * ====================================================================
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * This software consists of voluntary contributions made by many
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * individuals on behalf of the Apache Software Foundation. For more
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * information on the Apache Software Foundation, please see
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * Portions of this software are based upon public domain software
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * originally written at the National Center for Supercomputing Applications,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * University of Illinois, Urbana-Champaign.
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * http_config.c: once was auxillary functions for reading httpd's config
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * file and converting filenames into a namespace
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * Rob McCool
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * Wall-to-wall rewrite for Apache... commands which are part of the
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * server core can now be found next door in "http_core.c". Now contains
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * general command loop, and functions which do bookkeeping for the new
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * Apache config stuff (modules and configuration vectors).
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes#include "http_log.h" /* for errors in parse_htaccess */
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes#include "http_request.h" /* for default_handler (see invoke_handler) */
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesAP_DECLARE_DATA apr_array_header_t *ap_server_pre_read_config;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesAP_DECLARE_DATA apr_array_header_t *ap_server_post_read_config;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesAP_DECLARE_DATA apr_array_header_t *ap_server_config_defines;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes (apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp),
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes (apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes (apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp,
41022996c916eb4ab2ec3204eb491b64779eb100bnicholesAP_IMPLEMENT_HOOK_RUN_FIRST(int,handler,(request_rec *r),
41022996c916eb4ab2ec3204eb491b64779eb100bnicholesAP_IMPLEMENT_HOOK_VOID(optional_fn_retrieve,(void),())
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes/****************************************************************
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * We begin with the functions which deal with the linked list
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * of modules which control just about all of the server operation.
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes/* total_modules is the number of modules that have been linked
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * into the server.
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesstatic int total_modules = 0;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes/* dynamic_modules is the number of modules that have been added
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * after the pre-loaded ones have been set up. It shouldn't be larger
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * than DYNAMIC_MODULE_LIMIT.
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesstatic int dynamic_modules = 0;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholestypedef void *(*dir_maker_func) (apr_pool_t *, char *);
bb2b38cd44b032118359afbc743efbea12f48e61bnicholestypedef void *(*merger_func) (apr_pool_t *, void *, void *);
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes/* Dealing with config vectors. These are associated with per-directory,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * per-server, and per-request configuration, and have a void* pointer for
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * each modules. The nature of the structure pointed to is private to the
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * module in question... the core doesn't (and can't) know. However, there
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * are defined interfaces which allow it to create instances of its private
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * per-directory and per-server structures, and to merge the per-directory
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * structures of a directory and its subdirectory (producing a new one in
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * which the defaults applying to the base directory have been properly
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * overridden).
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesstatic ap_conf_vector_t *create_empty_config(apr_pool_t *p)
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes void *conf_vector = apr_pcalloc(p, sizeof(void *) *
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesstatic ap_conf_vector_t *create_default_per_dir_config(apr_pool_t *p)
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes void **conf_vector = apr_pcalloc(p, sizeof(void *) *
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes for (modp = top_module; modp; modp = modp->next) {
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes conf_vector[modp->module_index] = (*df) (p, NULL);
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesap_conf_vector_t *ap_merge_per_dir_configs(apr_pool_t *p,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes void **conf_vector = apr_palloc(p, sizeof(void *) * total_modules);
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes for (modp = top_module; modp; modp = modp->next) {
56ab8639aed4d3b2f031d9c1160c5f40af01bdebjerenkrantz conf_vector[i] = (*df) (p, base_vector[i], new_vector[i]);
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes conf_vector[i] = new_vector[i] ? new_vector[i] : base_vector[i];
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesstatic ap_conf_vector_t *create_server_config(apr_pool_t *p, server_rec *s)
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes void **conf_vector = apr_pcalloc(p, sizeof(void *) *
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes for (modp = top_module; modp; modp = modp->next) {
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes conf_vector[modp->module_index] = (*modp->create_server_config) (p, s);
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesstatic void merge_server_configs(apr_pool_t *p, ap_conf_vector_t *base,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes /* Can reuse the 'virt' vector for the spine of it, since we don't
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * have to deal with the moral equivalent of .htaccess files here...
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes for (modp = top_module; modp; modp = modp->next) {
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes virt_vector[i] = (*df) (p, base_vector[i], virt_vector[i]);
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesap_conf_vector_t *ap_create_request_config(apr_pool_t *p)
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesap_conf_vector_t *ap_create_conn_config(apr_pool_t *p)
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesAP_CORE_DECLARE(ap_conf_vector_t *) ap_create_per_dir_config(apr_pool_t *p)
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes const char *handler;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes const char *p;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes handler = r->content_type ? r->content_type : ap_default_type(r);
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes /* MIME type arguments */
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes if (result == DECLINED && r->handler && r->filename) {
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING, 0, r,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes "handler \"%s\" not found for: %s", r->handler, r->filename);
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes return result == DECLINED ? HTTP_INTERNAL_SERVER_ERROR : result;
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesAP_DECLARE(int) ap_method_is_limited(cmd_parms *cmd, const char *method) {
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * The simple case: a method hard-coded into Apache.
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * Some extension method we don't know implicitly.
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes for (i = 0; i < cmd->limited_xmethods->nelts; ++i) {
084aee5bd4093a1b5e9b51d1ccfafc3948fa4109bnicholesAP_DECLARE(void) ap_register_hooks(module *m, apr_pool_t *p)
0f7cc4b1d3c42262bcdced99f682778963e83ea7bnicholes/* One-time setup for precompiled modules --- NOT to be done on restart */
bb2b38cd44b032118359afbc743efbea12f48e61bnicholesAP_DECLARE(void) ap_add_module(module *m, apr_pool_t *p)
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes /* This could be called from an AddModule httpd.conf command,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * after the file has been linked and the module structure within it
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes * teased out...
a0209387ac93aa84037cf3a48096e75c6c8ce17ebnicholes ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes "%s: module \"%s\" is not compatible with this "
273e1eccdc9e5b94f1e3e13e3ffca7360b6f461fbnicholes ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, "Please contact the vendor for the correct version.");
8410c53aaf5e0372a19d5f4d2bc696b9c609ce3cbnicholes ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
8410c53aaf5e0372a19d5f4d2bc696b9c609ce3cbnicholes "%s: module \"%s\" could not be loaded, because"
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes "module limit was reached. Please increase "
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes "DYNAMIC_MODULE_LIMIT and recompile.");
bb2b38cd44b032118359afbc743efbea12f48e61bnicholes /* Some C compilers put a complete path into __FILE__, but we want
* only the filename (e.g. mod_includes.c). So check for path
ap_register_hooks(m, p);
if (modp == m) {
if (!modp) {
m->name);
module **m;
*m++ = mod;
*m = NULL;
module **m;
int done;
*m++ = *m2;
*m = NULL;
module **m;
total_modules = 0;
*m2++ = *m++;
return m->name;
return modp;
return NULL;
const char *errmsg;
case RAW_ARGS:
#ifdef RESOLVE_ENV_PER_TOKEN
case NO_ARGS:
if (*args != 0)
NULL);
case TAKE1:
case TAKE2:
case TAKE12:
case TAKE3:
case TAKE23:
case TAKE123:
case TAKE13:
case ITERATE:
return errmsg;
return NULL;
case ITERATE2:
return errmsg;
return NULL;
case FLAG:
NULL);
NULL);
return cmds;
++cmds;
return NULL;
return cmdp;
return NULL;
const char *section,
return section_config;
const char *args;
char *cmd_name;
return NULL;
args = l;
return NULL;
const char *retval;
if (*current) {
if (*curr_parent) {
if (*current) {
if (*current) {
if (!*conftree) {
return retval;
return NULL;
char *orig_directive)
char l[MAX_STRING_LEN];
char *bracket;
const char *retval;
return retval;
return NULL;
NULL);
mod,
const char *retval;
return NULL;
return retval;
const char *errmsg;
return errmsg;
return NULL;
char l[MAX_STRING_LEN];
const char *errmsg;
return errmsg;
return errmsg;
return NULL;
void *struct_ptr,
const char *arg)
return NULL;
void *struct_ptr,
const char *arg_)
return NULL;
return NULL;
const char *arg)
#ifndef OS2
return NULL;
#ifndef OS2
return file;
char l[MAX_STRING_LEN];
const char *args;
char *cmd_name;
args = l;
const char *msg;
return msg;
NULL);
NULL);
int curr_idx;
return NULL;
return buf;
const char *errmsg;
if (errmsg) {
errmsg);
char *fname;
} fnames;
const char *errmsg;
/* don't require conf/httpd.conf if we have a -C or -c switch */
int current;
const char *errmsg;
if (errmsg) {
const char *d, const char *access_name)
return OK;
while (access_name[0]) {
const char *errmsg;
ap_cfg_closefile(f);
if (errmsg) {
return HTTP_INTERNAL_SERVER_ERROR;
filename);
return HTTP_FORBIDDEN;
return OK;
const char *hostname,
s->timeout = 0;
s->keep_alive_timeout = 0;
*ps = s;
s->port = 0;
const char *confname,
p, ptemp);
p, ptemp);
module *m)
if (m->create_server_config)
(*m->create_server_config)(p, s));
if (m->create_dir_config)
module *m;
if (m->rewrite_args)
for (n = 0; ap_loaded_modules[n]; ++n)
for (n = 0; ap_loaded_modules[n]; ++n)