config.c revision 6b11d948596dbe78c9b4fd0201c5391086305b76
* Copyright (c) 2000 The Apache Software Foundation. All rights * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * 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 * the documentation and/or other materials provided with the * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * 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 * ==================================================================== * 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 * 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). #
include "http_log.h" /* for errors in parse_htaccess */#
include "http_request.h" /* for default_handler (see invoke_handler) *//**************************************************************** * 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 /* 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. /* 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 /* 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... * 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 while (p >
handler && p[-
1] ==
' ')
--p;
/* strip trailing spaces */ /* Pass one --- direct matches */ /* Pass two --- wildcard matches */ /* 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 "%s: module \"%s\" is not compatible with this " "%s: module \"%s\" could not be loaded, because" "module limit was reached. Please increase " "DYNAMIC_MODULE_LIMIT and recompile.");
/* Some C compilers put a complete path into __FILE__, but we want * components (Unix and DOS), and remove them. /* We cannot fix the string in-place, because it's const */ char *
tmp =
strdup(m->
name);
/* FIXME:memory leak, albeit a small one */ /* 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. /* We are the top module, special case */ /* Not the top module, find use. When found modp will * point to the module _before_ us in the list /* Uh-oh, this module doesn't exist */ "Cannot remove module %s: not found in module list",
/* Eliminate us from the module list */ * 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 * 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 * Initialise total_modules variable and module indices * Initialise list of loaded modules "Ouch! Out of memory in ap_setup_prelinked_modules()!");
* Initialize chain of linked (=activate) modules /* Add a named module. Returns 1 if module found, 0 otherwise. */ /* Only add modules that are not already enabled. */ /* Clear the internal list of modules, in preparation for starting over. */ /* This is required; so we add it always. */ /***************************************************************** * Resource, access, and .htaccess config files now parsed by a common * Let's begin with the basics; parsing the line and * invoking the function... return ((
const char *(*)(
cmd_parms *,
void *,
const char *))
return ((
const char *(*)(
cmd_parms *,
void *))
if (*w ==
'\0' || *
args != 0)
return ((
const char *(*)(
cmd_parms *,
void *,
const char *))
if (*w ==
'\0' || *
w2 ==
'\0' || *
args != 0)
return ((
const char *(*)(
cmd_parms *,
void *,
const char *,
if (*w ==
'\0' || *
args != 0)
return ((
const char *(*)(
cmd_parms *,
void *,
const char *,
if (*w ==
'\0' || *
w2 ==
'\0' || *
w3 ==
'\0' || *
args != 0)
return ((
const char *(*)(
cmd_parms *,
void *,
const char *,
if (*w ==
'\0' || *
w2 ==
'\0' || *
args != 0)
" takes two or three arguments",
return ((
const char *(*)(
cmd_parms *,
void *,
const char *,
if (*w ==
'\0' || *
args != 0)
" takes one, two or three arguments",
return ((
const char *(*)(
cmd_parms *,
void *,
const char *,
if (*w ==
'\0' || (*
w2 && !
w3) || *
args != 0)
" takes one or three arguments",
return ((
const char *(*)(
cmd_parms *,
void *,
const char *,
if (*w ==
'\0' || *
args == 0)
" requires at least two arguments",
return ((
const char *(*)(
cmd_parms *,
void *,
int))
" is improperly configured internally (server bug)",
if (*l ==
'#' || *l ==
'\0')
/* Note: this branch should not occur. An empty line should have * triggered the exit further above. "> directive missing closing '>'",
NULL);
/* done with this section; move up a level */ "', perhaps mis-spelled or defined by a module " "not included in the server configuration",
mod =
mod->
next;
/* Next time around, skip this one */ /* scan through all directives, executing each one */ /* actually parse the command and execute the correct function */ /* restore the context (just in case) */ * Generic command functions... /* This one's pretty generic... */ /* This one's pretty generic... */ /* This one's pretty generic too... */ /* 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. */ /***************************************************************** * Reading whole config files... /* 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. /* arr_elts_getstr() returns the next line from the string array. */ /* End of array reached? */ /* arr_elts_close(): dummy close routine (makes sure no more lines can be read) */ "Syntax error in -C/-c directive:\n%s",
errmsg);
/* GCC's initialization extensions are soooo nice here... */ "%s: could not open document config file %s",
/* ### wrong line number. need to pull from ap_directive_t */ "Syntax error on line %d of %s:",
/* firstly, search cache */ /* loop through the access names and find the first one */ "%s pcfg_openfile: unable to check htaccess file, " "Server unable to read htaccess file, denying " /* add to head of list */ perror(
"setrlimit(RLIMIT_NOFILE)");
"Cannot exceed hard limit for open files");
/* TODO: this crap belongs in http_core */ /* useful default, otherwise we get a port of 0 on redirects */ /* XXX: this is really something that should be dealt with by a * post-config api phase */ /***************************************************************** * Getting *everything* configured... /* Global virtual host hash bucket pointers. Init to null. */ /* NOT virtual host; don't match any real network interface */ /* All server-wide config files now have the SAME syntax... */ /* 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 * appear in the main configuration files and/or .htaccess files according * 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. printf(
"\tAllowed in *.conf ");
printf(
"only outside <Directory>, <Files> or <Location>");
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");
/* 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. /* Show the preloaded module names. Used for httpd -l. */ printf(
"Compiled in modules:\n");