config.c revision 4aebe4128dcba3416f9acc4c5d888178c45952de
234N/A/* ==================================================================== 234N/A * The Apache Software License, Version 1.1 234N/A * Copyright (c) 2000 The Apache Software Foundation. All rights 234N/A * Redistribution and use in source and binary forms, with or without 234N/A * modification, are permitted provided that the following conditions 234N/A * 1. Redistributions of source code must retain the above copyright 234N/A * notice, this list of conditions and the following disclaimer. 234N/A * 2. Redistributions in binary form must reproduce the above copyright 234N/A * notice, this list of conditions and the following disclaimer in 234N/A * the documentation and/or other materials provided with the 234N/A * 3. The end-user documentation included with the redistribution, 234N/A * if any, must include the following acknowledgment: 727N/A * "This product includes software developed by the 234N/A * Alternately, this acknowledgment may appear in the software itself, 234N/A * if and wherever such third-party acknowledgments normally appear. 234N/A * 4. The names "Apache" and "Apache Software Foundation" must 234N/A * not be used to endorse or promote products derived from this 234N/A * software without prior written permission. For written 618N/A * permission, please contact apache@apache.org. 234N/A * 5. Products derived from this software may not be called "Apache", 844N/A * nor may "Apache" appear in their name, without prior written 844N/A * permission of the Apache Software Foundation. 1258N/A * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 234N/A * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 234N/A * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 234N/A * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR 234N/A * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 234N/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 234N/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 234N/A * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 234N/A * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 234N/A * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 234N/A * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 234N/A * ==================================================================== 234N/A * This software consists of voluntary contributions made by many 234N/A * individuals on behalf of the Apache Software Foundation. For more 234N/A * 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... /* MIME type arguments */ --
p2;
/* strip trailing spaces */ * The simple case: a method hard-coded into Apache. * Some extension method we don't know implicitly. /* 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? * It doesn't appear to be * 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... if (*w ==
'\0' || *
args != 0)
if (*w ==
'\0' || *
w2 ==
'\0' || *
args != 0)
if (*w ==
'\0' || *
args != 0)
if (*w ==
'\0' || *
w2 ==
'\0' || *
w3 ==
'\0' || *
args != 0)
if (*w ==
'\0' || *
w2 ==
'\0' || *
args != 0)
" takes two or three arguments",
if (*w ==
'\0' || *
args != 0)
" takes one, two or three arguments",
if (*w ==
'\0' || (
w2 && *
w2 && !
w3) || *
args != 0)
" takes one or three arguments",
if (*w ==
'\0' || *
args == 0)
" requires at least two arguments",
" 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. /* Before walking *current to the end of the list, * set the head to *current. "> 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",
/* 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 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... {
NULL, 0, -
1,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL};
"', perhaps mis-spelled or defined by a module " "not included in the server configuration",
/* 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 apr_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) */ * here we want to check if the candidate file is really a * directory, and most definitely NOT a symlink (to prevent * horrible loops). If so, let's recurse and toss it back into * first course of business is to grok all the directory * entries here and store 'em away. Recall we need full pathnames /* strip out '.' and '..' */ * Now recurse these... we handle errors and subdirectories * via the recursion, which is nice /* GCC's initialization extensions are soooo nice here... */ "%s: could not open document config file %s",
"Syntax error on line %d of %s:",
"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 */ /* 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");