config.c revision 543d682d2aedf7342a519ea303f9f32463fbef80
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
*
* Portions of this software are based upon public domain software
* originally written at the National Center for Supercomputing Applications,
* University of Illinois, Urbana-Champaign.
*/
/*
* http_config.c: once was auxillary functions for reading httpd's config
* file and converting filenames into a namespace
*
* Rob McCool
*
* Wall-to-wall rewrite for Apache... commands which are part of the
* server core can now be found next door in "http_core.c". Now contains
* general command loop, and functions which do bookkeeping for the new
* Apache config stuff (modules and configuration vectors).
*
* rst
*
*/
#define CORE_PRIVATE
#include "ap_config.h"
#include "apr_portable.h"
#include "apr_file_io.h"
#include "httpd.h"
#include "http_config.h"
#include "http_core.h"
#include "http_log.h" /* for errors in parse_htaccess */
#include "http_request.h" /* for default_handler (see invoke_handler) */
#include "http_main.h"
#include "http_vhost.h"
#include "util_cfgtree.h"
API_VAR_EXPORT const char *ap_server_argv0;
API_VAR_EXPORT const char *ap_server_root;
)
/****************************************************************
*
* We begin with the functions which deal with the linked list
* of modules which control just about all of the server operation.
*/
/* total_modules is the number of modules that have been linked
* into the server.
*/
static int total_modules = 0;
/* dynamic_modules is the number of modules that have been added
* after the pre-loaded ones have been set up. It shouldn't be larger
* than DYNAMIC_MODULE_LIMIT.
*/
static int dynamic_modules = 0;
typedef int (*handler_func) (request_rec *);
typedef void *(*dir_maker_func) (ap_pool_t *, char *);
typedef void *(*merger_func) (ap_pool_t *, void *, void *);
/* Dealing with config vectors. These are associated with per-directory,
* per-server, and per-request configuration, and have a void* pointer for
* each modules. The nature of the structure pointed to is private to the
* module in question... the core doesn't (and can't) know. However, there
* are defined interfaces which allow it to create instances of its private
* per-directory and per-server structures, and to merge the per-directory
* structures of a directory and its subdirectory (producing a new one in
* which the defaults applying to the base directory have been properly
* overridden).
*/
#ifndef ap_get_module_config
{
void **confv = (void **) conf_vector;
return confv[m->module_index];
}
#endif
#ifndef ap_set_module_config
{
void **confv = (void **) conf_vector;
}
#endif
static void *create_empty_config(ap_pool_t *p)
{
void **conf_vector = (void **) ap_pcalloc(p, sizeof(void *) *
return (void *) conf_vector;
}
static void *create_default_per_dir_config(ap_pool_t *p)
{
void **conf_vector = (void **) ap_pcalloc(p, sizeof(void *) * (total_modules + DYNAMIC_MODULE_LIMIT));
if (df)
}
return (void *) conf_vector;
}
void *
{
void **base_vector = (void **) base;
void **new_vector = (void **) new;
int i = modp->module_index;
if (df && new_vector[i])
else
}
return (void *) conf_vector;
}
{
void **conf_vector = (void **) ap_pcalloc(p, sizeof(void *) * (total_modules + DYNAMIC_MODULE_LIMIT));
if (modp->create_server_config)
}
return (void *) conf_vector;
}
{
/* Can reuse the 'virt' vector for the spine of it, since we don't
* have to deal with the moral equivalent of .htaccess files here...
*/
void **base_vector = (void **) base;
void **virt_vector = (void **) virt;
int i = modp->module_index;
if (!virt_vector[i])
virt_vector[i] = base_vector[i];
else if (df)
}
}
void *ap_create_request_config(ap_pool_t *p)
{
return create_empty_config(p);
}
void *ap_create_conn_config(ap_pool_t *p)
{
return create_empty_config(p);
}
{
return create_empty_config(p);
}
/*
* For speed/efficiency we generate a compact list of all the handlers
* and wildcard handlers. This means we won't have to scan the entire
* module list looking for handlers... where we'll find a whole whack
* of NULLs.
*/
typedef struct {
static fast_handler_rec *handlers;
static fast_handler_rec *wildhandlers;
static void init_handlers(ap_pool_t *p)
{
int nhandlers = 0;
int nwildhandlers = 0;
const handler_rec *handp;
char *starp;
continue;
nwildhandlers ++;
} else {
nhandlers ++;
}
}
}
continue;
pw ++;
} else {
ph ++;
}
}
}
}
int ap_invoke_handler(request_rec *r)
{
const char *handler;
char *p;
int result = HTTP_INTERNAL_SERVER_ERROR;
if (r->handler) {
}
else {
--p; /* strip trailing spaces */
handler_len = p - handler;
}
else {
}
}
/* Pass one --- direct matches */
return result;
}
}
/* Pass two --- wildcard matches */
return result;
}
}
}
return HTTP_INTERNAL_SERVER_ERROR;
}
{
if(m->register_hooks)
{
if(getenv("SHOW_HOOKS"))
{
}
m->register_hooks();
}
}
/* One-time setup for precompiled modules --- NOT to be done on restart */
{
/* This could be called from an AddModule httpd.conf command,
* after the file has been linked and the module structure within it
* teased out...
*/
if (m->version != MODULE_MAGIC_NUMBER_MAJOR) {
"%s: module \"%s\" is not compatible with this "
ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, "Please contact the vendor for the correct version.");
exit(1);
}
m->next = top_module;
top_module = m;
}
if (m->module_index == -1) {
m->module_index = total_modules++;
if (dynamic_modules > DYNAMIC_MODULE_LIMIT) {
"%s: module \"%s\" could not be loaded, because"
"module limit was reached. Please increase "
"DYNAMIC_MODULE_LIMIT and recompile.");
exit(1);
}
}
/* Some C compilers put a complete path into __FILE__, but we want
* only the filename (e.g. mod_includes.c). So check for path
* components (Unix and DOS), and remove them.
*/
#ifdef _OSD_POSIX /* __FILE__="*POSIX(/home/martin/apache/src/modules/standard/mod_info.c)" */
/* We cannot fix the string in-place, because it's const */
}
#endif /*_OSD_POSIX*/
/* FIXME: is this the right place to call this? */
}
/*
* remove_module undoes what add_module did. There are some caveats:
* when the module is removed, its slot is lost so all the current
* per-dir and per-server configurations are invalid. So we should
* only ever call this function when you are invalidating almost
* all our current data. I.e. when doing a restart.
*/
{
modp = top_module;
if (modp == m) {
/* We are the top module, special case */
}
else {
/* Not the top module, find use. When found modp will
* point to the module _before_ us in the list
*/
}
if (!modp) {
/* Uh-oh, this module doesn't exist */
"Cannot remove module %s: not found in module list",
m->name);
return;
}
/* Eliminate us from the module list */
}
* be unnecessary */
}
{
module **m;
/*
* Add module pointer to top of chained module list
*/
/*
* And module pointer to list of loaded modules
*
* Notes: 1. ap_add_module() would already complain if no more space
* exists for adding a dynamically loaded module
* 2. ap_add_module() accepts double inclusion, so we have
* to accept this, too.
*/
for (m = ap_loaded_modules; *m != NULL; m++)
;
*m++ = mod;
*m = NULL;
}
{
module **m;
int done;
/*
* Remove module pointer from chained module list
*/
/*
* Remove module pointer from list of loaded modules
*
* Note: 1. We cannot determine if the module was successfully
* removed by ap_remove_module().
* 2. We have not to complain explicity when the module
* is not found because ap_remove_module() did it
* for us already.
*/
done = 1;
else
*m++ = *m2;
}
*m = NULL;
}
{
module **m;
/*
* Initialise total_modules variable and module indices
*/
total_modules = 0;
for (m = ap_preloaded_modules; *m != NULL; m++)
(*m)->module_index = total_modules++;
/*
* Initialise list of loaded modules
*/
if (ap_loaded_modules == NULL) {
"Ouch! Out of memory in ap_setup_prelinked_modules()!");
}
*m2++ = *m++;
/*
* Initialize chain of linked (=activate) modules
*/
for (m = ap_prelinked_modules; *m != NULL; m++)
ap_add_module(*m);
}
{
return m->name;
}
{
return modp;
}
return NULL;
}
/* Add a named module. Returns 1 if module found, 0 otherwise. */
{
int i = 0;
/* Only add modules that are not already enabled. */
}
return 1;
}
}
return 0;
}
/* Clear the internal list of modules, in preparation for starting over. */
API_EXPORT(void) ap_clear_module_list()
{
module **m = &top_module;
while (*m) {
*m = NULL;
m = next_m;
}
/* This is required; so we add it always. */
}
/*****************************************************************
*
* Resource, access, and .htaccess config files now parsed by a common
* command loop.
*
* Let's begin with the basics; parsing the line and
* invoking the function...
*/
{
const char *errmsg;
case RAW_ARGS:
#ifdef RESOLVE_ENV_PER_TOKEN
#endif
return ((const char *(*)(cmd_parms *, void *, const char *))
case NO_ARGS:
if (*args != 0)
NULL);
return ((const char *(*)(cmd_parms *, void *))
case TAKE1:
if (*w == '\0' || *args != 0)
return ((const char *(*)(cmd_parms *, void *, const char *))
case TAKE2:
return ((const char *(*)(cmd_parms *, void *, const char *,
case TAKE12:
if (*w == '\0' || *args != 0)
return ((const char *(*)(cmd_parms *, void *, const char *,
case TAKE3:
return ((const char *(*)(cmd_parms *, void *, const char *,
case TAKE23:
" takes two or three arguments",
return ((const char *(*)(cmd_parms *, void *, const char *,
case TAKE123:
if (*w == '\0' || *args != 0)
" takes one, two or three arguments",
return ((const char *(*)(cmd_parms *, void *, const char *,
case TAKE13:
" takes one or three arguments",
return ((const char *(*)(cmd_parms *, void *, const char *,
case ITERATE:
return errmsg;
return NULL;
case ITERATE2:
if (*w == '\0' || *args == 0)
" requires at least two arguments",
return errmsg;
return NULL;
case FLAG:
NULL);
return ((const char *(*)(cmd_parms *, void *, int))
default:
" is improperly configured internally (server bug)",
NULL);
}
}
{
return cmds;
else
++cmds;
return NULL;
}
{
const command_rec *cmdp;
return cmdp;
}
return NULL;
}
{
}
}
return mconfig;
}
{
const char *args;
char *cmd_name;
const command_rec *cmd;
if (*l == '#' || *l == '\0')
return NULL;
args = l;
#else
#endif
if (*cmd_name == '\0') {
/* Note: this branch should not occur. An empty line should have
* triggered the exit further above.
*/
return NULL;
}
const char *retval;
&sub_tree, *curr_parent);
if (*current) {
}
else {
if (*curr_parent) {
}
if (*current) {
}
}
if (*current) {
}
}
return retval;
}
}
if (cmd_name[0] == '<') {
}
else if (*curr_parent == NULL) {
return ap_pstrcat(p, cmd_name,
" section", NULL);
}
else {
if (*bracket != '>') {
return ap_pstrcat(p, cmd_name,
"> directive missing closing '>'", NULL);
}
*bracket = '\0';
return ap_pstrcat(p, "Expected </",
}
*bracket = '>';
/* done with this section; move up a level */
*current = *curr_parent;
}
}
else {
}
return NULL;
}
char *orig_directive)
{
char l[MAX_STRING_LEN];
char *bracket;
const char *retval;
(*curr_parent == NULL)) {
break;
}
return retval;
conftree = *curr_parent;
}
}
}
return NULL;
}
{
while (1) {
const command_rec *cmd;
"', perhaps mis-spelled or defined by a module "
"not included in the server configuration",
NULL);
}
else {
const char *retval;
return NULL;
}
/* If the directive in error has already been set, don't
* replace it. Otherwise, an error inside a container
* will be reported as occuring on the first line of the
* container.
*/
if (!parms->err_directive) {
}
return retval;
}
}
}
/* NOTREACHED */
}
{
/* scan through all directives, executing each one */
const char *errmsg;
/* actually parse the command and execute the correct function */
/* restore the context (just in case) */
return errmsg;
}
}
return NULL;
}
{
char l[MAX_STRING_LEN];
const char *errmsg;
}
}
¤t, &curr_parent);
return errmsg;
*conftree = curr_parent;
}
}
}
if (curr_parent != NULL) {
errmsg = "";
while (curr_parent != NULL) {
}
return errmsg;
}
return NULL;
}
/*
* Generic command functions...
*/
char *struct_ptr, char *arg)
{
/* This one's pretty generic... */
return NULL;
}
char *struct_ptr, char *arg)
{
/* This one's pretty generic... */
return NULL;
}
char *struct_ptr, int arg)
{
/* This one's pretty generic too... */
return NULL;
}
{
/* Prepend server_root to relative arg.
This allows .htaccess to be independent of server_root,
so the server can be moved or mirrored with less pain. */
char *p;
if (ap_os_is_path_absolute(arg))
p = arg;
else
*(char **) (struct_ptr + offset) = p;
return NULL;
}
/*****************************************************************
*
* Reading whole config files...
*/
static cmd_parms default_parms =
{
return file;
}
{
char l[MAX_STRING_LEN];
const char *args;
char *cmd_name;
args = l;
#else
#endif
if (cmd_name[0] == '<') {
}
break;
}
else {
}
}
}
return NULL;
}
{
const command_rec *cmd;
"', perhaps mis-spelled or defined by a module "
"not included in the server configuration",
NULL);
}
else {
}
}
/* This structure and the following functions are needed for the
* table-based config file reading. They are passed to the
* cfg_open_custom() routine.
*/
/* Structure to be passed to cfg_open_custom(): it contains an
* index which is incremented from 0 to nelts on each call to
* cfg_getline() (which in turn calls arr_elts_getstr())
* and an ap_array_header_t pointer for the string array.
*/
typedef struct {
int curr_idx;
/* arr_elts_getstr() returns the next line from the string array. */
{
/* End of array reached? */
return NULL;
/* return the line */
return buf;
}
/* arr_elts_close(): dummy close routine (makes sure no more lines can be read) */
static int arr_elts_close(void *param)
{
return 0;
}
{
const char *errmsg;
if (errmsg) {
"Syntax error in -C/-c directive:\n%s", errmsg);
exit(1);
}
}
{
const char *errmsg;
/* don't require conf/httpd.conf if we have a -C or -c switch */
return;
}
/* GCC's initialization extensions are soooo nice here... */
"%s: could not open document config file %s",
exit(1);
}
"Syntax error on line %d of %s:",
"%s", errmsg);
exit(1);
}
}
{
const char *errmsg;
if (errmsg) {
"Syntax error on line %d of %s:",
"%s", errmsg);
exit(1);
}
}
const char *d, const char *access_name)
{
configfile_t *f = NULL;
const struct htaccess_result *cache;
struct htaccess_result *new;
/* firstly, search cache */
return OK;
}
/* loop through the access names and find the first one */
while (access_name[0]) {
if (status == APR_SUCCESS) {
const char *errmsg;
parms.config_file = f;
ap_cfg_closefile(f);
if (errmsg) {
return HTTP_INTERNAL_SERVER_ERROR;
}
break;
} else {
"%s pcfg_openfile: unable to check htaccess file, "
"ensure it is readable",
filename);
"Server unable to read htaccess file, denying "
"access to be safe");
return HTTP_FORBIDDEN;
}
}
}
/* cache it */
/* add to head of list */
return OK;
}
{
#ifdef RLIMIT_NOFILE
perror("setrlimit(RLIMIT_NOFILE)");
"Cannot exceed hard limit for open files");
}
}
#endif
/* TODO: this crap belongs in http_core */
s->server_admin = NULL;
s->server_hostname = NULL;
s->error_fname = NULL;
s->timeout = 0;
s->keep_alive_timeout = 0;
s->keep_alive = -1;
s->keep_alive_max = -1;
/* useful default, otherwise we get a port of 0 on redirects */
s->is_virtual = 1;
s->module_config = create_empty_config(p);
s->lookup_defaults = ap_create_per_dir_config(p);
#if 0
s->server_uid = ap_user_id;
s->server_gid = ap_group_id;
#endif
*ps = s;
return ap_parse_vhost_addrs(p, hostname, s);
}
{
if (virt->keep_alive_timeout == 0)
/* XXX: this is really something that should be dealt with by a
* post-config api phase */
}
}
/*****************************************************************
*
* Getting *everything* configured...
*/
static void init_config_globals(ap_pool_t *p)
{
/* Global virtual host hash bucket pointers. Init to null. */
}
{
ap_open_stderr(&s->error_log, p);
s->port = 0;
s->server_admin = DEFAULT_ADMIN;
s->server_hostname = NULL;
s->error_fname = DEFAULT_ERRORLOG;
s->loglevel = DEFAULT_LOGLEVEL;
s->timeout = DEFAULT_TIMEOUT;
s->keep_alive = 1;
/* NOT virtual host; don't match any real network interface */
s->module_config = create_server_config(p, s);
return s;
}
const char *confname,
{
/* All server-wide config files now have the SAME syntax... */
p, ptemp);
p, ptemp);
fixup_virtual_hosts(p, s);
ap_fini_vhost_config(p, s);
return s;
}
{
if (m->create_server_config)
(*m->create_server_config)(p, s));
if (m->create_dir_config)
(*m->create_dir_config)(p, NULL));
}
{
module *m;
for (m = top_module; m; m = m->next)
if (m->rewrite_args)
(*m->rewrite_args) (process);
}
API_EXPORT(void) ap_post_config_hook(ap_pool_t *pconf, ap_pool_t *plog, ap_pool_t *ptemp, server_rec *s)
{
}
{
/* TODO: uh this seems ugly, is there a better way? */
/*ap_child_init_alloc(); PUT THIS BACK IN XXXXX */
}
/********************************************************************
* Configuration directives are restricted in terms of where they may
* to the bitmask req_override in the command_rec structure.
* If any of the overrides set in req_override are also allowed in the
* context in which the command is read, then the command is allowed.
* The context is determined as follows:
*
* inside *.conf --> override = (RSRC_CONF|OR_ALL)&~(OR_AUTHCFG|OR_LIMIT);
* within <Directory> or <Location> --> override = OR_ALL|ACCESS_CONF;
* within .htaccess --> override = AllowOverride for current directory;
*
* the result is, well, a rather confusing set of possibilities for when
* a particular directive is allowed to be used. This procedure prints
* in English where the given (pc) directive can be used.
*/
{
int n = 0;
printf("\tAllowed in *.conf ");
printf("anywhere");
printf("only outside <Directory>, <Files> or <Location>");
else
printf("only inside <Directory>, <Files> or <Location>");
/* Warn if the directive is allowed inside <Directory> or .htaccess
* but module doesn't support per-dir configuration */
printf(" [no per-dir config]");
printf(" and in .htaccess\n\twhen AllowOverride");
printf(" isn't None");
else {
printf(" includes ");
if (n++)
printf(" or ");
printf("AuthConfig");
}
if (n++)
printf(" or ");
printf("Limit");
}
if (n++)
printf(" or ");
printf("Options");
}
if (n++)
printf(" or ");
printf("FileInfo");
}
if (n++)
printf(" or ");
printf("Indexes");
}
}
}
printf("\n");
}
/* Show the preloaded configuration directives, the help string explaining
* the directive arguments, in what module they are handled, and in
* what parts of the configuration they are allowed. Used for httpd -h.
*/
API_EXPORT(void) ap_show_directives()
{
const command_rec *pc;
int n;
for (n = 0; ap_loaded_modules[n]; ++n)
}
}
/* Show the preloaded module names. Used for httpd -l. */
API_EXPORT(void) ap_show_modules()
{
int n;
printf("Compiled in modules:\n");
for (n = 0; ap_loaded_modules[n]; ++n)
}