config.c revision 2e123e8beedc9f921448c113e2d6823a92fd5261
* 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. All advertising materials mentioning features or use of this * software must display the following acknowledgment: * "This product includes software developed by the Apache Group * 4. The names "Apache Server" and "Apache Group" must not be used to * endorse or promote products derived from this software without * prior written permission. For written permission, please contact * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * 6. Redistributions of any form whatsoever must retain the following * "This product includes software developed by the Apache Group * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``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 GROUP 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 Group and was originally based * on public domain software written at the National Center for * Supercomputing Applications, University of Illinois, Urbana-Champaign. * For more information on the Apache Group and the Apache HTTP server * 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... /**************************************************************** * Dispatch through the modules to find handlers for various phases * of request handling. These are invoked by http_request.c to actually * do the dirty work of slogging through the module structures. * Optimized run_method routines. The observation here is that many modules * have NULL for most of the methods. So we build optimized lists of * everything. If you think about it, this is really just like a sparse array * implementation to avoid scanning the zero entries. * This is just one big array of method_ptrs. It's constructed such that, * for example, method_ptrs[ offsets_into_method_ptrs.logger ] is the first * logger function. You go one-by-one from there until you hit a NULL. * This structure was designed to hopefully maximize cache-coolness. /* routine to reconstruct all these shortcuts... called after every * XXX: this breaks if modules dink with their methods pointers /* free up any previous set of method_ptrs */ /* first we count how many functions we have */ fprintf(
stderr,
"Ouch! Out of memory in build_method_shortcuts()!\n");
/* XXX: This is an itsy bit presumptuous about the alignment * constraints on offsets_into_method_ptrs. I can't remember if * ANSI says this has to be true... -djg */ /* Auth stuff --- anything that defines one of these will presumably * want to define something for the other. Note that check_auth is * separate from check_access to make catching some config errors easier. * 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 fprintf(
stderr,
"Please contact the vendor for the correct version.\n");
"DYNAMIC_MODULE_LIMIT and recompile.\n");
/* 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 */ * 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 fprintf(
stderr,
"Ouch! Out of memory in ap_setup_prelinked_modules()!\n");
* 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[0] ==
'#') || (!l[0]))
"', perhaps mis-spelled or defined by a module " "not included in the server configuration",
NULL);
mod =
mod->
next;
/* Next time around, skip this one */ * 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 array_header 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) */ /* GCC's initialization extensions are soooo nice here... */ /* 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)");
/* 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... */ /******************************************************************** * 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");