X-Git-Url: https://granicus.if.org/sourcecode?a=blobdiff_plain;f=server%2Fconfig.c;h=be64dea05e5334d81e416196e4b12cdd279ef1db;hb=9d66007aa2676fad84ac1205cc5032e2561336b5;hp=bf094de25b0dddb3e45bccde245866747a863553;hpb=703d13f7c5ac6cddd0119b4663d69fd7c352e82b;p=apache diff --git a/server/config.c b/server/config.c index bf094de25b..be64dea05e 100644 --- a/server/config.c +++ b/server/config.c @@ -1,67 +1,24 @@ -/* ==================================================================== - * The Apache Software License, Version 1.1 +/* Copyright 1999-2004 The Apache Software Foundation * - * Copyright (c) 2000 The Apache Software Foundation. All rights - * reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * http://www.apache.org/licenses/LICENSE-2.0 * - * 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 - * 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. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ /* * http_config.c: once was auxillary functions for reading httpd's config * file and converting filenames into a namespace * - * Rob McCool - * + * 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 @@ -75,10 +32,11 @@ #include "apr_strings.h" #include "apr_portable.h" #include "apr_file_io.h" +#include "apr_fnmatch.h" -#if APR_HAVE_STDIO_H -#include -#endif +#define APR_WANT_STDIO +#define APR_WANT_STRFUNC +#include "apr_want.h" #define CORE_PRIVATE @@ -92,44 +50,111 @@ #include "http_main.h" #include "http_vhost.h" #include "util_cfgtree.h" -#ifdef HAVE_ARPA_INET_H -#include -#endif -#ifdef HAVE_STRINGS_H -#include -#endif +#include "mpm.h" + -AP_DECLARE_DATA const char *ap_server_argv0; +AP_DECLARE_DATA const char *ap_server_argv0 = NULL; -AP_DECLARE_DATA const char *ap_server_root; +AP_DECLARE_DATA const char *ap_server_root = NULL; -AP_DECLARE_DATA apr_array_header_t *ap_server_pre_read_config; -AP_DECLARE_DATA apr_array_header_t *ap_server_post_read_config; -AP_DECLARE_DATA apr_array_header_t *ap_server_config_defines; +AP_DECLARE_DATA apr_array_header_t *ap_server_pre_read_config = NULL; +AP_DECLARE_DATA apr_array_header_t *ap_server_post_read_config = NULL; +AP_DECLARE_DATA apr_array_header_t *ap_server_config_defines = NULL; -AP_DECLARE_DATA ap_directive_t *ap_conftree; +AP_DECLARE_DATA ap_directive_t *ap_conftree = NULL; -AP_HOOK_STRUCT( - AP_HOOK_LINK(header_parser) - AP_HOOK_LINK(pre_config) - AP_HOOK_LINK(post_config) - AP_HOOK_LINK(open_logs) - AP_HOOK_LINK(child_init) +APR_HOOK_STRUCT( + APR_HOOK_LINK(header_parser) + APR_HOOK_LINK(pre_config) + APR_HOOK_LINK(post_config) + APR_HOOK_LINK(open_logs) + APR_HOOK_LINK(child_init) + APR_HOOK_LINK(handler) + APR_HOOK_LINK(quick_handler) + APR_HOOK_LINK(optional_fn_retrieve) ) -AP_IMPLEMENT_HOOK_RUN_ALL(int,header_parser, - (request_rec *r),(r),OK,DECLINED) -AP_IMPLEMENT_HOOK_VOID(pre_config, - (apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp), - (pconf,plog,ptemp)) -AP_IMPLEMENT_HOOK_VOID(post_config, - (apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp, - server_rec *s),(pconf,plog,ptemp,s)) -AP_IMPLEMENT_HOOK_VOID(open_logs, - (apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp, - server_rec *s),(pconf,plog,ptemp,s)) +AP_IMPLEMENT_HOOK_RUN_ALL(int, header_parser, + (request_rec *r), (r), OK, DECLINED) + +AP_IMPLEMENT_HOOK_RUN_ALL(int, pre_config, + (apr_pool_t *pconf, apr_pool_t *plog, + apr_pool_t *ptemp), + (pconf, plog, ptemp), OK, DECLINED) + +AP_IMPLEMENT_HOOK_RUN_ALL(int, post_config, + (apr_pool_t *pconf, apr_pool_t *plog, + apr_pool_t *ptemp, server_rec *s), + (pconf, plog, ptemp, s), OK, DECLINED) + +/* During the course of debugging I expanded this macro out, so + * rather than remove all the useful information there is in the + * following lines, I'm going to leave it here in case anyone + * else finds it useful. + * + * Ben has looked at it and thinks it correct :) + * +AP_DECLARE(int) ap_hook_post_config(ap_HOOK_post_config_t *pf, + const char * const *aszPre, + const char * const *aszSucc, + int nOrder) +{ + ap_LINK_post_config_t *pHook; + + if (!_hooks.link_post_config) { + _hooks.link_post_config = apr_array_make(apr_hook_global_pool, 1, + sizeof(ap_LINK_post_config_t)); + apr_hook_sort_register("post_config", &_hooks.link_post_config); + } + + pHook = apr_array_push(_hooks.link_post_config); + pHook->pFunc = pf; + pHook->aszPredecessors = aszPre; + pHook->aszSuccessors = aszSucc; + pHook->nOrder = nOrder; + pHook->szName = apr_hook_debug_current; + + if (apr_hook_debug_enabled) + apr_hook_debug_show("post_config", aszPre, aszSucc); +} + +AP_DECLARE(apr_array_header_t *) ap_hook_get_post_config(void) { + return _hooks.link_post_config; +} + +AP_DECLARE(int) ap_run_post_config(apr_pool_t *pconf, + apr_pool_t *plog, + apr_pool_t *ptemp, + server_rec *s) +{ + ap_LINK_post_config_t *pHook; + int n; + + if(!_hooks.link_post_config) + return; + + pHook = (ap_LINK_post_config_t *)_hooks.link_post_config->elts; + for (n = 0; n < _hooks.link_post_config->nelts; ++n) + pHook[n].pFunc (pconf, plog, ptemp, s); +} + */ + +AP_IMPLEMENT_HOOK_RUN_ALL(int, open_logs, + (apr_pool_t *pconf, apr_pool_t *plog, + apr_pool_t *ptemp, server_rec *s), + (pconf, plog, ptemp, s), OK, DECLINED) + AP_IMPLEMENT_HOOK_VOID(child_init, - (apr_pool_t *pchild, server_rec *s),(pchild,s)) + (apr_pool_t *pchild, server_rec *s), + (pchild, s)) + +AP_IMPLEMENT_HOOK_RUN_FIRST(int, handler, (request_rec *r), + (r), DECLINED) + +AP_IMPLEMENT_HOOK_RUN_FIRST(int, quick_handler, (request_rec *r, int lookup), + (r, lookup), DECLINED) + +AP_IMPLEMENT_HOOK_VOID(optional_fn_retrieve, (void), ()) /**************************************************************** * @@ -141,17 +166,24 @@ AP_IMPLEMENT_HOOK_VOID(child_init, * 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; -AP_DECLARE_DATA module *top_module = NULL; + +AP_DECLARE_DATA module *ap_top_module = NULL; AP_DECLARE_DATA module **ap_loaded_modules=NULL; -typedef int (*handler_func) (request_rec *); -typedef void *(*dir_maker_func) (apr_pool_t *, char *); -typedef void *(*merger_func) (apr_pool_t *, void *, void *); +typedef int (*handler_func)(request_rec *); +typedef void *(*dir_maker_func)(apr_pool_t *, char *); +typedef void *(*merger_func)(apr_pool_t *, void *, void *); + +/* maximum nesting level for config directories */ +#ifndef AP_MAX_INCLUDE_DIR_DEPTH +#define AP_MAX_INCLUDE_DIR_DEPTH (128) +#endif /* Dealing with config vectors. These are associated with per-directory, * per-server, and per-request configuration, and have a void* pointer for @@ -164,305 +196,243 @@ typedef void *(*merger_func) (apr_pool_t *, void *, void *); * overridden). */ -#ifndef ap_get_module_config -AP_DECLARE(void *) ap_get_module_config(void *conf_vector, module *m) -{ - void **confv = (void **) conf_vector; - return confv[m->module_index]; -} -#endif - -#ifndef ap_set_module_config -AP_DECLARE(void) ap_set_module_config(void *conf_vector, module *m, void *val) -{ - void **confv = (void **) conf_vector; - confv[m->module_index] = val; -} -#endif - -static void *create_empty_config(apr_pool_t *p) +static ap_conf_vector_t *create_empty_config(apr_pool_t *p) { - void **conf_vector = (void **) apr_pcalloc(p, sizeof(void *) * - (total_modules + DYNAMIC_MODULE_LIMIT)); - return (void *) conf_vector; + void *conf_vector = apr_pcalloc(p, sizeof(void *) * + (total_modules + DYNAMIC_MODULE_LIMIT)); + return conf_vector; } -static void *create_default_per_dir_config(apr_pool_t *p) +static ap_conf_vector_t *create_default_per_dir_config(apr_pool_t *p) { - void **conf_vector = (void **) apr_pcalloc(p, sizeof(void *) * (total_modules + DYNAMIC_MODULE_LIMIT)); + void **conf_vector = apr_pcalloc(p, sizeof(void *) * + (total_modules + DYNAMIC_MODULE_LIMIT)); module *modp; - for (modp = top_module; modp; modp = modp->next) { - dir_maker_func df = modp->create_dir_config; + for (modp = ap_top_module; modp; modp = modp->next) { + dir_maker_func df = modp->create_dir_config; - if (df) - conf_vector[modp->module_index] = (*df) (p, NULL); + if (df) + conf_vector[modp->module_index] = (*df)(p, NULL); } - return (void *) conf_vector; + return (ap_conf_vector_t *)conf_vector; } -void * - ap_merge_per_dir_configs(apr_pool_t *p, void *base, void *new) +AP_CORE_DECLARE(ap_conf_vector_t *) ap_merge_per_dir_configs(apr_pool_t *p, + ap_conf_vector_t *base, + ap_conf_vector_t *new_conf) { - void **conf_vector = (void **) apr_palloc(p, sizeof(void *) * total_modules); - void **base_vector = (void **) base; - void **new_vector = (void **) new; + void **conf_vector = apr_palloc(p, sizeof(void *) * total_modules); + void **base_vector = (void **)base; + void **new_vector = (void **)new_conf; module *modp; - for (modp = top_module; modp; modp = modp->next) { - merger_func df = modp->merge_dir_config; - int i = modp->module_index; + for (modp = ap_top_module; modp; modp = modp->next) { + int i = modp->module_index; - if (df && new_vector[i]) - conf_vector[i] = (*df) (p, base_vector[i], new_vector[i]); - else - conf_vector[i] = new_vector[i] ? new_vector[i] : base_vector[i]; + if (!new_vector[i]) { + conf_vector[i] = base_vector[i]; + } + else { + merger_func df = modp->merge_dir_config; + if (df && base_vector[i]) { + conf_vector[i] = (*df)(p, base_vector[i], new_vector[i]); + } + else + conf_vector[i] = new_vector[i]; + } } - return (void *) conf_vector; + return (ap_conf_vector_t *)conf_vector; } -static void *create_server_config(apr_pool_t *p, server_rec *s) +static ap_conf_vector_t *create_server_config(apr_pool_t *p, server_rec *s) { - void **conf_vector = (void **) apr_pcalloc(p, sizeof(void *) * (total_modules + DYNAMIC_MODULE_LIMIT)); + void **conf_vector = apr_pcalloc(p, sizeof(void *) * + (total_modules + DYNAMIC_MODULE_LIMIT)); module *modp; - for (modp = top_module; modp; modp = modp->next) { - if (modp->create_server_config) - conf_vector[modp->module_index] = (*modp->create_server_config) (p, s); + for (modp = ap_top_module; modp; modp = modp->next) { + if (modp->create_server_config) + conf_vector[modp->module_index] = (*modp->create_server_config)(p, s); } - return (void *) conf_vector; + return (ap_conf_vector_t *)conf_vector; } -static void merge_server_configs(apr_pool_t *p, void *base, void *virt) +static void merge_server_configs(apr_pool_t *p, ap_conf_vector_t *base, + ap_conf_vector_t *virt) { /* 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; + void **base_vector = (void **)base; + void **virt_vector = (void **)virt; module *modp; - for (modp = top_module; modp; modp = modp->next) { - merger_func df = modp->merge_server_config; - int i = modp->module_index; + for (modp = ap_top_module; modp; modp = modp->next) { + merger_func df = modp->merge_server_config; + int i = modp->module_index; - if (!virt_vector[i]) - virt_vector[i] = base_vector[i]; - else if (df) - virt_vector[i] = (*df) (p, base_vector[i], virt_vector[i]); + if (!virt_vector[i]) + virt_vector[i] = base_vector[i]; + else if (df) + virt_vector[i] = (*df)(p, base_vector[i], virt_vector[i]); } } -void *ap_create_request_config(apr_pool_t *p) +AP_CORE_DECLARE(ap_conf_vector_t *) ap_create_request_config(apr_pool_t *p) { return create_empty_config(p); } -void *ap_create_conn_config(apr_pool_t *p) +AP_CORE_DECLARE(ap_conf_vector_t *) ap_create_conn_config(apr_pool_t *p) { return create_empty_config(p); } -AP_CORE_DECLARE(void *) ap_create_per_dir_config(apr_pool_t *p) +AP_CORE_DECLARE(ap_conf_vector_t *) ap_create_per_dir_config(apr_pool_t *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 { - handler_rec hr; - size_t len; -} fast_handler_rec; - -static fast_handler_rec *handlers; -static fast_handler_rec *wildhandlers; - -static void init_handlers(apr_pool_t *p) +static int ap_invoke_filter_init(ap_filter_t *filters) { - module *modp; - int nhandlers = 0; - int nwildhandlers = 0; - const handler_rec *handp; - fast_handler_rec *ph, *pw; - const char *starp; - - for (modp = top_module; modp; modp = modp->next) { - if (!modp->handlers) - continue; - for (handp = modp->handlers; handp->content_type; ++handp) { - if (ap_strchr_c(handp->content_type, '*')) { - nwildhandlers ++; - } else { - nhandlers ++; - } - } - } - ph = handlers = apr_palloc(p, sizeof(*ph)*(nhandlers + 1)); - pw = wildhandlers = apr_palloc(p, sizeof(*pw)*(nwildhandlers + 1)); - for (modp = top_module; modp; modp = modp->next) { - if (!modp->handlers) - continue; - for (handp = modp->handlers; handp->content_type; ++handp) { - if ((starp = ap_strchr_c(handp->content_type, '*'))) { - pw->hr.content_type = handp->content_type; - pw->hr.handler = handp->handler; - pw->len = starp - handp->content_type; - pw ++; - } else { - ph->hr.content_type = handp->content_type; - ph->hr.handler = handp->handler; - ph->len = strlen(handp->content_type); - ph ++; + while (filters) { + if (filters->frec->filter_init_func) { + int result = filters->frec->filter_init_func(filters); + if (result != OK) { + return result; } } - } - pw->hr.content_type = NULL; - pw->hr.handler = NULL; - ph->hr.content_type = NULL; - ph->hr.handler = NULL; + filters = filters->next; + } + return OK; } -int ap_invoke_handler(request_rec *r) +AP_CORE_DECLARE(int) ap_invoke_handler(request_rec *r) { - fast_handler_rec *handp; const char *handler; const char *p; - size_t handler_len; - int result = HTTP_INTERNAL_SERVER_ERROR; + int result; + const char *old_handler = r->handler; - if (r->handler) { - handler = r->handler; - handler_len = strlen(handler); + /* + * The new insert_filter stage makes the most sense here. We only use + * it when we are going to run the request, so we must insert filters + * if any are available. Since the goal of this phase is to allow all + * modules to insert a filter if they want to, this filter returns + * void. I just can't see any way that this filter can reasonably + * fail, either your modules inserts something or it doesn't. rbb + */ + ap_run_insert_filter(r); + + /* Before continuing, allow each filter that is in the two chains to + * run their init function to let them do any magic before we could + * start generating data. + */ + result = ap_invoke_filter_init(r->input_filters); + if (result != OK) { + return result; } - else { - handler = r->content_type ? r->content_type : ap_default_type(r); - if ((p = ap_strchr_c(handler, ';')) != NULL) { - /* MIME type arguments */ - while (p > handler && p[-1] == ' ') - --p; /* strip trailing spaces */ - handler_len = p - handler; - } - else { - handler_len = strlen(handler); - } + result = ap_invoke_filter_init(r->output_filters); + if (result != OK) { + return result; } - /* Pass one --- direct matches */ + if (!r->handler) { + handler = r->content_type ? r->content_type : ap_default_type(r); + if ((p=ap_strchr_c(handler, ';')) != NULL) { + char *new_handler = (char *)apr_pmemdup(r->pool, handler, + p - handler + 1); + char *p2 = new_handler + (p - handler); + handler = new_handler; - for (handp = handlers; handp->hr.content_type; ++handp) { - if (handler_len == handp->len - && !strncmp(handler, handp->hr.content_type, handler_len)) { - result = (*handp->hr.handler) (r); + /* MIME type arguments */ + while (p2 > handler && p2[-1] == ' ') + --p2; /* strip trailing spaces */ - if (result != DECLINED) - return result; + *p2='\0'; } - } - /* Pass two --- wildcard matches */ + r->handler = handler; + } - for (handp = wildhandlers; handp->hr.content_type; ++handp) { - if (handler_len >= handp->len - && !strncmp(handler, handp->hr.content_type, handp->len)) { - result = (*handp->hr.handler) (r); + result = ap_run_handler(r); - if (result != DECLINED) - return result; - } - } + r->handler = old_handler; - if (result == HTTP_INTERNAL_SERVER_ERROR && r->handler && r->filename) { - ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING, 0, r, + if (result == DECLINED && r->handler && r->filename) { + ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, "handler \"%s\" not found for: %s", r->handler, r->filename); } - return HTTP_INTERNAL_SERVER_ERROR; + + return result == DECLINED ? HTTP_INTERNAL_SERVER_ERROR : result; } -AP_DECLARE(int) ap_method_is_limited(cmd_parms *cmd, const char *method) { +AP_DECLARE(int) ap_method_is_limited(cmd_parms *cmd, const char *method) +{ int methnum; - int i; - char **xmethod; methnum = ap_method_number_of(method); + /* - * The simple case: a method hard-coded into Apache. + * A method number either hardcoded into apache or + * added by a module and registered. */ if (methnum != M_INVALID) { - return (methnum & cmd->limited); + return (cmd->limited & (AP_METHOD_BIT << methnum)) ? 1 : 0; } - /* - * Some extension method we don't know implicitly. - */ - if ((cmd->limited_xmethods == NULL) - || (cmd->limited_xmethods->nelts == 0)) { - return 0; - } - xmethod = (char **) cmd->limited_xmethods->elts; - for (i = 0; i < cmd->limited_xmethods->nelts; ++i) { - if (strcmp(method, xmethod[i]) == 0) { - return 1; - } - } - return 0; + + return 0; /* not found */ } -AP_DECLARE(void) ap_register_hooks(module *m) - { - if(m->register_hooks) - { - if(getenv("SHOW_HOOKS")) - { - printf("Registering hooks for %s\n",m->name); - ap_debug_module_hooks=1; - } - ap_debug_module_name=m->name; - m->register_hooks(); - } +AP_DECLARE(void) ap_register_hooks(module *m, apr_pool_t *p) +{ + if (m->register_hooks) { + if (getenv("SHOW_HOOKS")) { + printf("Registering hooks for %s\n", m->name); + apr_hook_debug_enabled = 1; + } + + apr_hook_debug_current = m->name; + m->register_hooks(p); } +} /* One-time setup for precompiled modules --- NOT to be done on restart */ -AP_DECLARE(void) ap_add_module(module *m) +AP_DECLARE(const char *) ap_add_module(module *m, apr_pool_t *p) { - /* This could be called from an AddModule httpd.conf command, + /* This could be called from a LoadModule httpd.conf command, * after the file has been linked and the module structure within it * teased out... */ if (m->version != MODULE_MAGIC_NUMBER_MAJOR) { - ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, - "%s: module \"%s\" is not compatible with this " - "version of Apache.", ap_server_argv0, m->name); - ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, "Please contact the vendor for the correct version."); - exit(1); + return apr_psprintf(p, "Module \"%s\" is not compatible with this " + "version of Apache (found %d, need %d). Please " + "contact the vendor for the correct version.", + m->name, m->version, MODULE_MAGIC_NUMBER_MAJOR); } if (m->next == NULL) { - m->next = top_module; - top_module = m; + m->next = ap_top_module; + ap_top_module = m; } - if (m->module_index == -1) { - m->module_index = total_modules++; - dynamic_modules++; - if (dynamic_modules > DYNAMIC_MODULE_LIMIT) { - ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, - "%s: module \"%s\" could not be loaded, because" - " the dynamic", ap_server_argv0, m->name); - ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, - "module limit was reached. Please increase " - "DYNAMIC_MODULE_LIMIT and recompile."); - exit(1); - } + if (m->module_index == -1) { + m->module_index = total_modules++; + dynamic_modules++; + + if (dynamic_modules > DYNAMIC_MODULE_LIMIT) { + return apr_psprintf(p, "Module \"%s\" could not be loaded, " + "because the dynamic module limit was " + "reached. Please increase " + "DYNAMIC_MODULE_LIMIT and recompile.", m->name); + } } /* Some C compilers put a complete path into __FILE__, but we want @@ -471,24 +441,33 @@ AP_DECLARE(void) ap_add_module(module *m) */ if (ap_strrchr_c(m->name, '/')) - m->name = 1 + ap_strrchr_c(m->name, '/'); + m->name = 1 + ap_strrchr_c(m->name, '/'); + if (ap_strrchr_c(m->name, '\\')) - m->name = 1 + ap_strrchr_c(m->name, '\\'); + m->name = 1 + ap_strrchr_c(m->name, '\\'); + +#ifdef _OSD_POSIX + /* __FILE__ = + * "*POSIX(/home/martin/apache/src/modules/standard/mod_info.c)" + */ -#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 */ - if (m->name[strlen(m->name)-1]==')') { - char *tmp = strdup(m->name); /* FIXME:memory leak, albeit a small one */ - tmp[strlen(tmp)-1] = '\0'; - m->name = tmp; + if (m->name[strlen(m->name)-1] == ')') { + char *tmp = strdup(m->name); /* FIXME: memory leak, albeit a small one */ + tmp[strlen(tmp)-1] = '\0'; + m->name = tmp; } #endif /*_OSD_POSIX*/ - /* FIXME: is this the right place to call this? */ - ap_register_hooks(m); + /* FIXME: is this the right place to call this? + * It doesn't appear to be + */ + ap_register_hooks(m, p); + + return NULL; } -/* +/* * 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 @@ -500,48 +479,54 @@ AP_DECLARE(void) ap_remove_module(module *m) { module *modp; - modp = top_module; + modp = ap_top_module; if (modp == m) { - /* We are the top module, special case */ - top_module = modp->next; - m->next = NULL; + /* We are the top module, special case */ + ap_top_module = modp->next; + m->next = NULL; } else { - /* Not the top module, find use. When found modp will - * point to the module _before_ us in the list - */ - - while (modp && modp->next != m) { - modp = modp->next; - } - if (!modp) { - /* Uh-oh, this module doesn't exist */ - ap_log_error(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, NULL, - "Cannot remove module %s: not found in module list", - m->name); - return; - } - /* Eliminate us from the module list */ - modp->next = modp->next->next; - } - - m->module_index = -1; /* simulate being unloaded, should - * be unnecessary */ + /* Not the top module, find use. When found modp will + * point to the module _before_ us in the list + */ + + while (modp && modp->next != m) { + modp = modp->next; + } + + if (!modp) { + /* Uh-oh, this module doesn't exist */ + ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL, + "Cannot remove module %s: not found in module list", + m->name); + return; + } + + /* Eliminate us from the module list */ + modp->next = modp->next->next; + } + + m->module_index = -1; /* simulate being unloaded, should + * be unnecessary */ dynamic_modules--; total_modules--; } -AP_DECLARE(void) ap_add_loaded_module(module *mod) +AP_DECLARE(const char *) ap_add_loaded_module(module *mod, apr_pool_t *p) { module **m; + const char *error; - /* - * Add module pointer to top of chained module list + /* + * Add module pointer to top of chained module list */ - ap_add_module(mod); + error = ap_add_module(mod, p); + if (error) { + return error; + } - /* - * And module pointer to list of loaded modules + /* + * 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 @@ -552,6 +537,8 @@ AP_DECLARE(void) ap_add_loaded_module(module *mod) ; *m++ = mod; *m = NULL; + + return NULL; } AP_DECLARE(void) ap_remove_loaded_module(module *mod) @@ -560,12 +547,12 @@ AP_DECLARE(void) ap_remove_loaded_module(module *mod) module **m2; int done; - /* - * Remove module pointer from chained module list + /* + * Remove module pointer from chained module list */ ap_remove_module(mod); - /* + /* * Remove module pointer from list of loaded modules * * Note: 1. We cannot determine if the module was successfully @@ -580,15 +567,17 @@ AP_DECLARE(void) ap_remove_loaded_module(module *mod) else *m++ = *m2; } + *m = NULL; } -AP_DECLARE(void) ap_setup_prelinked_modules(process_rec *process) +AP_DECLARE(const char *) ap_setup_prelinked_modules(process_rec *process) { module **m; module **m2; + const char *error; - ap_global_hook_pool=process->pconf; + apr_hook_global_pool=process->pconf; /* * Initialise total_modules variable and module indices @@ -597,26 +586,34 @@ AP_DECLARE(void) ap_setup_prelinked_modules(process_rec *process) for (m = ap_preloaded_modules; *m != NULL; m++) (*m)->module_index = total_modules++; - /* + /* * Initialise list of loaded modules */ ap_loaded_modules = (module **)apr_palloc(process->pool, - sizeof(module *)*(total_modules+DYNAMIC_MODULE_LIMIT+1)); + sizeof(module *) * (total_modules + DYNAMIC_MODULE_LIMIT + 1)); + if (ap_loaded_modules == NULL) { - ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, - "Ouch! Out of memory in ap_setup_prelinked_modules()!"); + return "Ouch! Out of memory in ap_setup_prelinked_modules()!"; } + for (m = ap_preloaded_modules, m2 = ap_loaded_modules; *m != NULL; ) *m2++ = *m++; + *m2 = NULL; /* * Initialize chain of linked (=activate) modules */ - for (m = ap_prelinked_modules; *m != NULL; m++) - ap_add_module(*m); + for (m = ap_prelinked_modules; *m != NULL; m++) { + error = ap_add_module(*m, process->pconf); + if (error) { + return error; + } + } + + apr_hook_sort_all(); - ap_sort_hooks(); + return NULL; } AP_DECLARE(const char *) ap_find_module_name(module *m) @@ -628,46 +625,12 @@ AP_DECLARE(module *) ap_find_linked_module(const char *name) { module *modp; - for (modp = top_module; modp; modp = modp->next) { - if (strcmp(modp->name, name) == 0) - return modp; + for (modp = ap_top_module; modp; modp = modp->next) { + if (strcmp(modp->name, name) == 0) + return modp; } - return NULL; -} - -/* Add a named module. Returns 1 if module found, 0 otherwise. */ -AP_DECLARE(int) ap_add_named_module(const char *name) -{ - module *modp; - int i = 0; - for (modp = ap_loaded_modules[i]; modp; modp = ap_loaded_modules[++i]) { - if (strcmp(modp->name, name) == 0) { - /* Only add modules that are not already enabled. */ - if (modp->next == NULL) { - ap_add_module(modp); - } - return 1; - } - } - - return 0; -} - -/* Clear the internal list of modules, in preparation for starting over. */ -AP_DECLARE(void) ap_clear_module_list() -{ - module **m = &top_module; - module **next_m; - - while (*m) { - next_m = &((*m)->next); - *m = NULL; - m = next_m; - } - - /* This is required; so we add it always. */ - ap_add_named_module("http_core.c"); + return NULL; } /***************************************************************** @@ -680,13 +643,13 @@ AP_DECLARE(void) ap_clear_module_list() */ static const char *invoke_cmd(const command_rec *cmd, cmd_parms *parms, - void *mconfig, const char *args) + void *mconfig, const char *args) { char *w, *w2, *w3; - const char *errmsg; + const char *errmsg = NULL; if ((parms->override & cmd->req_override) == 0) - return apr_pstrcat(parms->pool, cmd->name, " not allowed here", NULL); + return apr_pstrcat(parms->pool, cmd->name, " not allowed here", NULL); parms->info = cmd->cmd_data; parms->cmd = cmd; @@ -694,215 +657,233 @@ static const char *invoke_cmd(const command_rec *cmd, cmd_parms *parms, switch (cmd->args_how) { case RAW_ARGS: #ifdef RESOLVE_ENV_PER_TOKEN - args = ap_resolve_env(parms->pool,args); + args = ap_resolve_env(parms->pool,args); #endif - return cmd->AP_RAW_ARGS(parms, mconfig, args); + return cmd->AP_RAW_ARGS(parms, mconfig, args); case NO_ARGS: - if (*args != 0) - return apr_pstrcat(parms->pool, cmd->name, " takes no arguments", - NULL); + if (*args != 0) + return apr_pstrcat(parms->pool, cmd->name, " takes no arguments", + NULL); - return cmd->AP_NO_ARGS(parms, mconfig); + return cmd->AP_NO_ARGS(parms, mconfig); case TAKE1: - w = ap_getword_conf(parms->pool, &args); + w = ap_getword_conf(parms->pool, &args); - if (*w == '\0' || *args != 0) - return apr_pstrcat(parms->pool, cmd->name, " takes one argument", - cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL); + if (*w == '\0' || *args != 0) + return apr_pstrcat(parms->pool, cmd->name, " takes one argument", + cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL); - return cmd->AP_TAKE1(parms, mconfig, w); + return cmd->AP_TAKE1(parms, mconfig, w); case TAKE2: - w = ap_getword_conf(parms->pool, &args); - w2 = ap_getword_conf(parms->pool, &args); + w = ap_getword_conf(parms->pool, &args); + w2 = ap_getword_conf(parms->pool, &args); - if (*w == '\0' || *w2 == '\0' || *args != 0) - return apr_pstrcat(parms->pool, cmd->name, " takes two arguments", - cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL); + if (*w == '\0' || *w2 == '\0' || *args != 0) + return apr_pstrcat(parms->pool, cmd->name, " takes two arguments", + cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL); - return cmd->AP_TAKE2(parms, mconfig, w, w2); + return cmd->AP_TAKE2(parms, mconfig, w, w2); case TAKE12: + w = ap_getword_conf(parms->pool, &args); + w2 = ap_getword_conf(parms->pool, &args); - w = ap_getword_conf(parms->pool, &args); - w2 = ap_getword_conf(parms->pool, &args); + if (*w == '\0' || *args != 0) + return apr_pstrcat(parms->pool, cmd->name, " takes 1-2 arguments", + cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL); - if (*w == '\0' || *args != 0) - return apr_pstrcat(parms->pool, cmd->name, " takes 1-2 arguments", - cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL); - - return cmd->AP_TAKE2(parms, mconfig, w, *w2 ? w2 : NULL); + return cmd->AP_TAKE2(parms, mconfig, w, *w2 ? w2 : NULL); case TAKE3: + w = ap_getword_conf(parms->pool, &args); + w2 = ap_getword_conf(parms->pool, &args); + w3 = ap_getword_conf(parms->pool, &args); - w = ap_getword_conf(parms->pool, &args); - w2 = ap_getword_conf(parms->pool, &args); - w3 = ap_getword_conf(parms->pool, &args); - - if (*w == '\0' || *w2 == '\0' || *w3 == '\0' || *args != 0) - return apr_pstrcat(parms->pool, cmd->name, " takes three arguments", - cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL); + if (*w == '\0' || *w2 == '\0' || *w3 == '\0' || *args != 0) + return apr_pstrcat(parms->pool, cmd->name, " takes three arguments", + cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL); - return cmd->AP_TAKE3(parms, mconfig, w, w2, w3); + return cmd->AP_TAKE3(parms, mconfig, w, w2, w3); case TAKE23: + w = ap_getword_conf(parms->pool, &args); + w2 = ap_getword_conf(parms->pool, &args); + w3 = *args ? ap_getword_conf(parms->pool, &args) : NULL; - w = ap_getword_conf(parms->pool, &args); - w2 = ap_getword_conf(parms->pool, &args); - w3 = *args ? ap_getword_conf(parms->pool, &args) : NULL; - - if (*w == '\0' || *w2 == '\0' || *args != 0) - return apr_pstrcat(parms->pool, cmd->name, - " takes two or three arguments", - cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL); + if (*w == '\0' || *w2 == '\0' || *args != 0) + return apr_pstrcat(parms->pool, cmd->name, + " takes two or three arguments", + cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL); - return cmd->AP_TAKE3(parms, mconfig, w, w2, w3); + return cmd->AP_TAKE3(parms, mconfig, w, w2, w3); case TAKE123: + w = ap_getword_conf(parms->pool, &args); + w2 = *args ? ap_getword_conf(parms->pool, &args) : NULL; + w3 = *args ? ap_getword_conf(parms->pool, &args) : NULL; - w = ap_getword_conf(parms->pool, &args); - w2 = *args ? ap_getword_conf(parms->pool, &args) : NULL; - w3 = *args ? ap_getword_conf(parms->pool, &args) : NULL; + if (*w == '\0' || *args != 0) + return apr_pstrcat(parms->pool, cmd->name, + " takes one, two or three arguments", + cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL); - if (*w == '\0' || *args != 0) - return apr_pstrcat(parms->pool, cmd->name, - " takes one, two or three arguments", - cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL); - - return cmd->AP_TAKE3(parms, mconfig, w, w2, w3); + return cmd->AP_TAKE3(parms, mconfig, w, w2, w3); case TAKE13: + w = ap_getword_conf(parms->pool, &args); + w2 = *args ? ap_getword_conf(parms->pool, &args) : NULL; + w3 = *args ? ap_getword_conf(parms->pool, &args) : NULL; - w = ap_getword_conf(parms->pool, &args); - w2 = *args ? ap_getword_conf(parms->pool, &args) : NULL; - w3 = *args ? ap_getword_conf(parms->pool, &args) : NULL; - - if (*w == '\0' || (w2 && *w2 && !w3) || *args != 0) - return apr_pstrcat(parms->pool, cmd->name, - " takes one or three arguments", - cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL); + if (*w == '\0' || (w2 && *w2 && !w3) || *args != 0) + return apr_pstrcat(parms->pool, cmd->name, + " takes one or three arguments", + cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL); - return cmd->AP_TAKE3(parms, mconfig, w, w2, w3); + return cmd->AP_TAKE3(parms, mconfig, w, w2, w3); case ITERATE: + while (*(w = ap_getword_conf(parms->pool, &args)) != '\0') { + + errmsg = cmd->AP_TAKE1(parms, mconfig, w); - while (*(w = ap_getword_conf(parms->pool, &args)) != '\0') - { - if ((errmsg = cmd->AP_TAKE1(parms, mconfig, w))) - return errmsg; - } + if (errmsg && strcmp(errmsg, DECLINE_CMD) != 0) + return errmsg; + } - return NULL; + return errmsg; case ITERATE2: + w = ap_getword_conf(parms->pool, &args); - w = ap_getword_conf(parms->pool, &args); + if (*w == '\0' || *args == 0) + return apr_pstrcat(parms->pool, cmd->name, + " requires at least two arguments", + cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL); - if (*w == '\0' || *args == 0) - return apr_pstrcat(parms->pool, cmd->name, - " requires at least two arguments", - cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL); + while (*(w2 = ap_getword_conf(parms->pool, &args)) != '\0') { - while (*(w2 = ap_getword_conf(parms->pool, &args)) != '\0') - { - if ((errmsg = cmd->AP_TAKE2(parms, mconfig, w, w2))) - return errmsg; - } + errmsg = cmd->AP_TAKE2(parms, mconfig, w, w2); - return NULL; + if (errmsg && strcmp(errmsg, DECLINE_CMD) != 0) + return errmsg; + } - case FLAG: + return errmsg; - w = ap_getword_conf(parms->pool, &args); + case FLAG: + w = ap_getword_conf(parms->pool, &args); - if (*w == '\0' || (strcasecmp(w, "on") && strcasecmp(w, "off"))) - return apr_pstrcat(parms->pool, cmd->name, " must be On or Off", - NULL); + if (*w == '\0' || (strcasecmp(w, "on") && strcasecmp(w, "off"))) + return apr_pstrcat(parms->pool, cmd->name, " must be On or Off", + NULL); - return cmd->AP_FLAG(parms, mconfig, strcasecmp(w, "off") != 0); + return cmd->AP_FLAG(parms, mconfig, strcasecmp(w, "off") != 0); default: - - return apr_pstrcat(parms->pool, cmd->name, - " is improperly configured internally (server bug)", - NULL); + return apr_pstrcat(parms->pool, cmd->name, + " is improperly configured internally (server bug)", + NULL); } } -AP_CORE_DECLARE(const command_rec *) ap_find_command(const char *name, const command_rec *cmds) +AP_CORE_DECLARE(const command_rec *) ap_find_command(const char *name, + const command_rec *cmds) { - while (cmds->name) - if (!strcasecmp(name, cmds->name)) - return cmds; - else - ++cmds; + while (cmds->name) { + if (!strcasecmp(name, cmds->name)) + return cmds; + + ++cmds; + } return NULL; } -AP_CORE_DECLARE(const command_rec *) ap_find_command_in_modules(const char *cmd_name, module **mod) +AP_CORE_DECLARE(const command_rec *) ap_find_command_in_modules( + const char *cmd_name, module **mod) { const command_rec *cmdp; module *modp; - for (modp = *mod; modp; modp = modp->next) - if (modp->cmds && (cmdp = ap_find_command(cmd_name, modp->cmds))) { - *mod = modp; - return cmdp; - } + for (modp = *mod; modp; modp = modp->next) { + if (modp->cmds && (cmdp = ap_find_command(cmd_name, modp->cmds))) { + *mod = modp; + return cmdp; + } + } return NULL; } -AP_CORE_DECLARE(void *) ap_set_config_vectors(cmd_parms *parms, void *config, module *mod) +AP_CORE_DECLARE(void *) ap_set_config_vectors(server_rec *server, + ap_conf_vector_t *section_vector, + const char *section, + module *mod, apr_pool_t *pconf) { - void *mconfig = ap_get_module_config(config, mod); - void *sconfig = ap_get_module_config(parms->server->module_config, mod); + void *section_config = ap_get_module_config(section_vector, mod); + void *server_config = ap_get_module_config(server->module_config, mod); - if (!mconfig && mod->create_dir_config) { - mconfig = (*mod->create_dir_config) (parms->pool, parms->path); - ap_set_module_config(config, mod, mconfig); + if (!section_config && mod->create_dir_config) { + /* ### need to fix the create_dir_config functions' prototype... */ + section_config = (*mod->create_dir_config)(pconf, (char *)section); + ap_set_module_config(section_vector, mod, section_config); } - if (!sconfig && mod->create_server_config) { - sconfig = (*mod->create_server_config) (parms->pool, parms->server); - ap_set_module_config(parms->server->module_config, mod, sconfig); + if (!server_config && mod->create_server_config) { + server_config = (*mod->create_server_config)(pconf, server); + ap_set_module_config(server->module_config, mod, server_config); } - return mconfig; + + return section_config; } -static const char *execute_now(char *cmd_line, const char *args, cmd_parms *parms, - apr_pool_t *p, apr_pool_t *ptemp, - ap_directive_t **sub_tree, ap_directive_t *parent); +static const char *execute_now(char *cmd_line, const char *args, + cmd_parms *parms, + apr_pool_t *p, apr_pool_t *ptemp, + ap_directive_t **sub_tree, + ap_directive_t *parent); -static const char * ap_build_config_sub(apr_pool_t *p, apr_pool_t *temp_pool, - const char *l, cmd_parms *parms, - ap_directive_t **current, - ap_directive_t **curr_parent, - ap_directive_t **conftree) +static const char *ap_build_config_sub(apr_pool_t *p, apr_pool_t *temp_pool, + const char *l, cmd_parms *parms, + ap_directive_t **current, + ap_directive_t **curr_parent, + ap_directive_t **conftree) { + const char *retval = NULL; const char *args; char *cmd_name; ap_directive_t *newdir; - module *mod = top_module; + module *mod = ap_top_module; const command_rec *cmd; if (*l == '#' || *l == '\0') - return NULL; + return NULL; #if RESOLVE_ENV_PER_TOKEN args = l; #else - args = ap_resolve_env(temp_pool, l); + args = ap_resolve_env(temp_pool, l); #endif + cmd_name = ap_getword_conf(p, &args); if (*cmd_name == '\0') { - /* Note: this branch should not occur. An empty line should have - * triggered the exit further above. - */ - return NULL; + /* Note: this branch should not occur. An empty line should have + * triggered the exit further above. + */ + return NULL; + } + + if (cmd_name[1] != '/') { + char *lastc = cmd_name + strlen(cmd_name) - 1; + if (*lastc == '>') { + *lastc = '\0' ; + } + if (cmd_name[0] == '<' && *args == '\0') { + args = ">"; + } } newdir = apr_pcalloc(p, sizeof(ap_directive_t)); @@ -913,17 +894,16 @@ static const char * ap_build_config_sub(apr_pool_t *p, apr_pool_t *temp_pool, if ((cmd = ap_find_command_in_modules(cmd_name, &mod)) != NULL) { if (cmd->req_override & EXEC_ON_READ) { - const char *retval; ap_directive_t *sub_tree = NULL; parms->err_directive = newdir; - retval = execute_now(cmd_name, args, parms, p, temp_pool, + retval = execute_now(cmd_name, args, parms, p, temp_pool, &sub_tree, *curr_parent); if (*current) { (*current)->next = sub_tree; } else { - (*current) = sub_tree; + *current = sub_tree; if (*curr_parent) { (*curr_parent)->first_child = (*current); } @@ -951,29 +931,34 @@ static const char * ap_build_config_sub(apr_pool_t *p, apr_pool_t *temp_pool, if (cmd_name[1] != '/') { (*current) = ap_add_node(curr_parent, *current, newdir, 1); } - else if (*curr_parent == NULL) { + else if (*curr_parent == NULL) { parms->err_directive = newdir; - return apr_pstrcat(p, cmd_name, - " without matching <", cmd_name + 2, - " section", NULL); - } - else { - char *bracket = cmd_name + strlen(cmd_name) - 1; - - if (*bracket != '>') { - return apr_pstrcat(p, cmd_name, - "> directive missing closing '>'", NULL); - } - *bracket = '\0'; - if (strcasecmp(cmd_name + 2, - (*curr_parent)->directive + 1) != 0) { - return apr_pstrcat(p, "Expected directive + 1, "> but saw ", - cmd_name, ">", NULL); - } - *bracket = '>'; - - /* done with this section; move up a level */ + return apr_pstrcat(p, cmd_name, + " without matching <", cmd_name + 2, + " section", NULL); + } + else { + char *bracket = cmd_name + strlen(cmd_name) - 1; + + if (*bracket != '>') { + parms->err_directive = newdir; + return apr_pstrcat(p, cmd_name, + "> directive missing closing '>'", NULL); + } + + *bracket = '\0'; + + if (strcasecmp(cmd_name + 2, + (*curr_parent)->directive + 1) != 0) { + parms->err_directive = newdir; + return apr_pstrcat(p, "Expected directive + 1, "> but saw ", + cmd_name, ">", NULL); + } + + *bracket = '>'; + + /* done with this section; move up a level */ *current = *curr_parent; *curr_parent = (*current)->parent; } @@ -982,66 +967,87 @@ static const char * ap_build_config_sub(apr_pool_t *p, apr_pool_t *temp_pool, *current = ap_add_node(curr_parent, *current, newdir, 0); } - return NULL; + return retval; } -const char *ap_build_cont_config(apr_pool_t *p, apr_pool_t *temp_pool, - cmd_parms *parms, - ap_directive_t **current, - ap_directive_t **curr_parent, - char *orig_directive) +AP_DECLARE(const char *) ap_build_cont_config(apr_pool_t *p, + apr_pool_t *temp_pool, + cmd_parms *parms, + ap_directive_t **current, + ap_directive_t **curr_parent, + char *orig_directive) { - char l[MAX_STRING_LEN]; + char *l; char *bracket; const char *retval; ap_directive_t *sub_tree = NULL; + /* Since this function can be called recursively, allocate + * the temporary 8k string buffer from the temp_pool rather + * than the stack to avoid over-running a fixed length stack. + */ + l = apr_palloc(temp_pool, MAX_STRING_LEN); + bracket = apr_pstrcat(p, orig_directive + 1, ">", NULL); while (!(ap_cfg_getline(l, MAX_STRING_LEN, parms->config_file))) { - if (!memcmp(l, "directive, &mod))) { + if (!(cmd = ap_find_command_in_modules(current->directive, &mod))) { parms->err_directive = current; - return apr_pstrcat(parms->pool, "Invalid command '", - current->directive, - "', perhaps mis-spelled or defined by a module " - "not included in the server configuration", - NULL); - } - else { - void *mconfig = ap_set_config_vectors(parms,config, mod); - const char *retval; - - retval = invoke_cmd(cmd, parms, mconfig, current->args); - if (retval == NULL) { + return apr_pstrcat(parms->pool, "Invalid command '", + current->directive, + "', perhaps mis-spelled or defined by a module " + "not included in the server configuration", + NULL); + } + else { + void *dir_config = ap_set_config_vectors(parms->server, + section_vector, + parms->path, + mod, + parms->pool); + const char *retval; + + /* Once was enough? */ + if (cmd->req_override & EXEC_ON_READ) { return NULL; } + + retval = invoke_cmd(cmd, parms, dir_config, current->args); + if (retval == NULL) { + return NULL; + } + if (strcmp(retval, DECLINE_CMD) != 0) { /* If the directive in error has already been set, don't * replace it. Otherwise, an error inside a container @@ -1051,45 +1057,46 @@ static const char *ap_walk_config_sub(const ap_directive_t *current, if (!parms->err_directive) { parms->err_directive = current; } - return retval; + + return retval; } - mod = mod->next; /* Next time around, skip this one */ - } + mod = mod->next; /* Next time around, skip this one */ + } } /* NOTREACHED */ } AP_DECLARE(const char *) ap_walk_config(ap_directive_t *current, - cmd_parms *parms, void *config) + cmd_parms *parms, + ap_conf_vector_t *section_vector) { - void *oldconfig = parms->context; + ap_conf_vector_t *oldconfig = parms->context; - parms->context = config; + parms->context = section_vector; /* scan through all directives, executing each one */ for (; current != NULL; current = current->next) { - const char *errmsg; + const char *errmsg; - parms->directive = current; + parms->directive = current; /* actually parse the command and execute the correct function */ - errmsg = ap_walk_config_sub(current, parms, config); - if (errmsg != NULL) { - /* restore the context (just in case) */ - parms->context = oldconfig; - return errmsg; - } + errmsg = ap_walk_config_sub(current, parms, section_vector); + if (errmsg != NULL) { + /* restore the context (just in case) */ + parms->context = oldconfig; + return errmsg; + } } parms->context = oldconfig; return NULL; } - AP_DECLARE(const char *) ap_build_config(cmd_parms *parms, - apr_pool_t *p, apr_pool_t *temp_pool, - ap_directive_t **conftree) + apr_pool_t *p, apr_pool_t *temp_pool, + ap_directive_t **conftree) { ap_directive_t *current = *conftree; ap_directive_t *curr_parent = NULL; @@ -1103,32 +1110,36 @@ AP_DECLARE(const char *) ap_build_config(cmd_parms *parms, } while (!(ap_cfg_getline(l, MAX_STRING_LEN, parms->config_file))) { + errmsg = ap_build_config_sub(p, temp_pool, l, parms, + ¤t, &curr_parent, conftree); + if (errmsg != NULL) + return errmsg; - errmsg = ap_build_config_sub(p, temp_pool, l, parms, - ¤t, &curr_parent, conftree); - if (errmsg != NULL) - return errmsg; - - if (*conftree == NULL && curr_parent != NULL) { + if (*conftree == NULL && curr_parent != NULL) { *conftree = curr_parent; } + if (*conftree == NULL && current != NULL) { *conftree = current; } } if (curr_parent != NULL) { - errmsg = ""; - while (curr_parent != NULL) { - errmsg = apr_psprintf(p, "%s%s%s:%u: %s> was not closed.", - errmsg, - *errmsg == '\0' ? "" : APR_EOL_STR, - curr_parent->filename, - curr_parent->line_num, - curr_parent->directive); - curr_parent = curr_parent->parent; - } - return errmsg; + errmsg = ""; + + while (curr_parent != NULL) { + errmsg = apr_psprintf(p, "%s%s%s:%u: %s> was not closed.", + errmsg, + *errmsg == '\0' ? "" : APR_EOL_STR, + curr_parent->filename, + curr_parent->line_num, + curr_parent->directive); + + parms->err_directive = curr_parent; + curr_parent = curr_parent->parent; + } + + return errmsg; } return NULL; @@ -1139,59 +1150,88 @@ AP_DECLARE(const char *) ap_build_config(cmd_parms *parms, */ AP_DECLARE_NONSTD(const char *) ap_set_string_slot(cmd_parms *cmd, - void *struct_ptr, - const char *arg) + void *struct_ptr, + const char *arg) { - /* This one's pretty generic... */ + int offset = (int)(long)cmd->info; + + *(const char **)((char *)struct_ptr + offset) = arg; - int offset = (int) (long) cmd->info; - *(const char **) ((char *)struct_ptr + offset) = arg; return NULL; } +AP_DECLARE_NONSTD(const char *) ap_set_int_slot(cmd_parms *cmd, + void *struct_ptr, + const char *arg) +{ + char *endptr; + char *error_str = NULL; + int offset = (int)(long)cmd->info; + + *(int *)((char*)struct_ptr + offset) = strtol(arg, &endptr, 10); + + if ((*arg == '\0') || (*endptr != '\0')) { + error_str = apr_psprintf(cmd->pool, + "Invalid value for directive %s, expected integer", + cmd->directive->directive); + } + + return error_str; +} + AP_DECLARE_NONSTD(const char *) ap_set_string_slot_lower(cmd_parms *cmd, - void *struct_ptr, - const char *arg_) + void *struct_ptr, + const char *arg_) { - /* This one's pretty generic... */ - char *arg=apr_pstrdup(cmd->pool,arg_); + char *arg = apr_pstrdup(cmd->pool,arg_); + int offset = (int)(long)cmd->info; - int offset = (int) (long) cmd->info; ap_str_tolower(arg); - *(char **) ((char *)struct_ptr + offset) = arg; + *(char **)((char *)struct_ptr + offset) = arg; + return NULL; } AP_DECLARE_NONSTD(const char *) ap_set_flag_slot(cmd_parms *cmd, void *struct_ptr_v, int arg) { - /* This one's pretty generic too... */ - - int offset = (int) (long) cmd->info; + int offset = (int)(long)cmd->info; char *struct_ptr = (char *)struct_ptr_v; - *(int *) (struct_ptr + offset) = arg ? 1 : 0; + + *(int *)(struct_ptr + offset) = arg ? 1 : 0; + return NULL; } -AP_DECLARE_NONSTD(const char *) ap_set_file_slot(cmd_parms *cmd, void *struct_ptr, +AP_DECLARE_NONSTD(const char *) ap_set_file_slot(cmd_parms *cmd, void *struct_ptr, const char *arg) { /* 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; - int offset = (int) (long) cmd->info; -#ifndef OS2 - arg = ap_os_canonical_filename(cmd->pool, arg); -#endif - if (ap_os_is_path_absolute(arg)) - p = apr_pstrdup(cmd->pool, arg); - else - p = ap_make_full_path(cmd->pool, ap_server_root, arg); - *(char **) ((char*)struct_ptr + offset) = p; + * This allows most args to be independent of server_root, + * so the server can be moved or mirrored with less pain. + */ + const char *path; + int offset = (int)(long)cmd->info; + + path = ap_server_root_relative(cmd->pool, arg); + + if (!path) { + return apr_pstrcat(cmd->pool, "Invalid file path ", + arg, NULL); + } + + *(const char **) ((char*)struct_ptr + offset) = path; + return NULL; } +AP_DECLARE_NONSTD(const char *) ap_set_deprecated(cmd_parms *cmd, + void *struct_ptr, + const char *arg) +{ + return cmd->cmd->errmsg; +} + /***************************************************************** * * Reading whole config files... @@ -1200,14 +1240,20 @@ AP_DECLARE_NONSTD(const char *) ap_set_file_slot(cmd_parms *cmd, void *struct_pt static cmd_parms default_parms = {NULL, 0, -1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; -AP_DECLARE(const char *) ap_server_root_relative(apr_pool_t *p, const char *file) +AP_DECLARE(char *) ap_server_root_relative(apr_pool_t *p, const char *file) { -#ifndef OS2 - file = ap_os_canonical_filename(p, file); -#endif - if(ap_os_is_path_absolute(file)) - return file; - return ap_make_full_path(p, ap_server_root, file); + char *newpath = NULL; + apr_status_t rv; + rv = apr_filepath_merge(&newpath, ap_server_root, file, + APR_FILEPATH_TRUENAME, p); + if (newpath && (rv == APR_SUCCESS || APR_STATUS_IS_EPATHWILD(rv) + || APR_STATUS_IS_ENOENT(rv) + || APR_STATUS_IS_ENOTDIR(rv))) { + return newpath; + } + else { + return NULL; + } } AP_DECLARE(const char *) ap_soak_end_container(cmd_parms *cmd, char *directive) @@ -1222,38 +1268,54 @@ AP_DECLARE(const char *) ap_soak_end_container(cmd_parms *cmd, char *directive) #else args = ap_resolve_env(cmd->temp_pool, l); #endif + cmd_name = ap_getword_conf(cmd->pool, &args); if (cmd_name[0] == '<') { if (cmd_name[1] == '/') { cmd_name[strlen(cmd_name) - 1] = '\0'; + if (strcasecmp(cmd_name + 2, directive + 1) != 0) { return apr_pstrcat(cmd->pool, "Expected but saw ", - cmd_name, ">", NULL); + directive + 1, "> but saw ", + cmd_name, ">", NULL); } - break; + + return NULL; /* found end of container */ } else { - ap_soak_end_container(cmd, cmd_name); + const char *msg; + + if (*args == '\0' && cmd_name[strlen(cmd_name) - 1] == '>') { + cmd_name[strlen(cmd_name) - 1] = '\0'; + } + + if ((msg = ap_soak_end_container(cmd, cmd_name)) != NULL) { + return msg; + } } } } - return NULL; + + return apr_pstrcat(cmd->pool, "Expected before end of configuration", + NULL); } -static const char *execute_now(char *cmd_line, const char *args, cmd_parms *parms, - apr_pool_t *p, apr_pool_t *ptemp, - ap_directive_t **sub_tree, ap_directive_t *parent) +static const char *execute_now(char *cmd_line, const char *args, + cmd_parms *parms, + apr_pool_t *p, apr_pool_t *ptemp, + ap_directive_t **sub_tree, + ap_directive_t *parent) { - module *mod = top_module; + module *mod = ap_top_module; const command_rec *cmd; if (!(cmd = ap_find_command_in_modules(cmd_line, &mod))) { - return apr_pstrcat(parms->pool, "Invalid command '", - cmd_line, - "', perhaps mis-spelled or defined by a module " - "not included in the server configuration", - NULL); + return apr_pstrcat(parms->pool, "Invalid command '", + cmd_line, + "', perhaps mis-spelled or defined by a module " + "not included in the server configuration", + NULL); } else { return invoke_cmd(cmd, parms, sub_tree, args); @@ -1279,14 +1341,16 @@ typedef struct { /* arr_elts_getstr() returns the next line from the string array. */ static void *arr_elts_getstr(void *buf, size_t bufsiz, void *param) { - arr_elts_param_t *arr_param = (arr_elts_param_t *) param; + arr_elts_param_t *arr_param = (arr_elts_param_t *)param; /* End of array reached? */ if (++arr_param->curr_idx > arr_param->array->nelts) return NULL; /* return the line */ - apr_cpystrn(buf, ((char **) arr_param->array->elts)[arr_param->curr_idx - 1], bufsiz); + apr_cpystrn(buf, + ((char **)arr_param->array->elts)[arr_param->curr_idx - 1], + bufsiz); return buf; } @@ -1295,14 +1359,18 @@ static void *arr_elts_getstr(void *buf, size_t bufsiz, void *param) /* arr_elts_close(): dummy close routine (makes sure no more lines can be read) */ static int arr_elts_close(void *param) { - arr_elts_param_t *arr_param = (arr_elts_param_t *) param; + arr_elts_param_t *arr_param = (arr_elts_param_t *)param; + arr_param->curr_idx = arr_param->array->nelts; + return 0; } -static void process_command_config(server_rec *s, apr_array_header_t *arr, - ap_directive_t **conftree, apr_pool_t *p, - apr_pool_t *ptemp) +static const char *process_command_config(server_rec *s, + apr_array_header_t *arr, + ap_directive_t **conftree, + apr_pool_t *p, + apr_pool_t *ptemp) { const char *errmsg; cmd_parms parms; @@ -1316,20 +1384,21 @@ static void process_command_config(server_rec *s, apr_array_header_t *arr, parms.temp_pool = ptemp; parms.server = s; parms.override = (RSRC_CONF | OR_ALL) & ~(OR_AUTHCFG | OR_LIMIT); + parms.override_opts = OPT_ALL | OPT_INCNOEXEC | OPT_SYM_OWNER | OPT_MULTI; parms.config_file = ap_pcfg_open_custom(p, "-c/-C directives", - &arr_parms, NULL, - arr_elts_getstr, arr_elts_close); + &arr_parms, NULL, + arr_elts_getstr, arr_elts_close); errmsg = ap_build_config(&parms, p, ptemp, conftree); + ap_cfg_closefile(parms.config_file); + if (errmsg) { - ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, - "Syntax error in -C/-c directive:" APR_EOL_STR "%s", - errmsg); - exit(1); + return apr_pstrcat(p, "Syntax error in -C/-c directive: ", errmsg, + NULL); } - ap_cfg_closefile(parms.config_file); + return NULL; } typedef struct { @@ -1344,111 +1413,211 @@ static int fname_alphasort(const void *fn1, const void *fn2) return strcmp(f1->fname,f2->fname); } -void ap_process_resource_config(server_rec *s, const char *fname, - ap_directive_t **conftree, apr_pool_t *p, - apr_pool_t *ptemp) +static const char *process_resource_config_nofnmatch(server_rec *s, + const char *fname, + ap_directive_t **conftree, + apr_pool_t *p, + apr_pool_t *ptemp, + unsigned depth) { cmd_parms parms; - apr_finfo_t finfo; - const char *errmsg; - configfile_t *cfp; + ap_configfile_t *cfp; + const char *error; - fname = ap_server_root_relative(p, fname); + if (ap_is_directory(p, fname)) { + apr_dir_t *dirp; + apr_finfo_t dirent; + int current; + apr_array_header_t *candidates = NULL; + fnames *fnew; + apr_status_t rv; + char *path = apr_pstrdup(p, fname); + + if (++depth > AP_MAX_INCLUDE_DIR_DEPTH) { + return apr_psprintf(p, "Directory %s exceeds the maximum include " + "directory nesting level of %u. You have " + "probably a recursion somewhere.", path, + AP_MAX_INCLUDE_DIR_DEPTH); + } - /* don't require conf/httpd.conf if we have a -C or -c switch */ - if ((ap_server_pre_read_config->nelts - || ap_server_post_read_config->nelts) - && !(strcmp(fname, ap_server_root_relative(p, SERVER_CONFIG_FILE)))) { - if (apr_stat(&finfo, fname, p) != APR_SUCCESS) - return; - } + /* + * first course of business is to grok all the directory + * entries here and store 'em away. Recall we need full pathnames + * for this. + */ + rv = apr_dir_open(&dirp, path, p); + if (rv != APR_SUCCESS) { + char errmsg[120]; + return apr_psprintf(p, "Could not open config directory %s: %s", + path, apr_strerror(rv, errmsg, sizeof errmsg)); + } - /* - * 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 - * the function. - */ - if (ap_is_rdirectory(fname)) { - apr_dir_t *dirp; - int current; - apr_array_header_t *candidates = NULL; - fnames *fnew; - - /* - * first course of business is to grok all the directory - * entries here and store 'em away. Recall we need full pathnames - * for this. - */ - fprintf(stderr, "Processing config directory: %s\n", fname); - if (apr_dir_open(&dirp, fname, p) != APR_SUCCESS) { - perror("fopen"); - fprintf(stderr, "%s: could not open config directory %s\n", - ap_server_argv0, fname); - exit(1); - } - candidates = apr_make_array(p, 1, sizeof(fnames)); - while (apr_readdir(dirp) == APR_SUCCESS) { - char *d_name; - apr_get_dir_filename(&d_name, dirp); - /* strip out '.' and '..' */ - if (strcmp(d_name, ".") && - strcmp(d_name, "..")) { - fnew = (fnames *) apr_push_array(candidates); - fnew->fname = ap_make_full_path(p, fname, d_name); - } - } - apr_closedir(dirp); - if (candidates->nelts != 0) { + candidates = apr_array_make(p, 1, sizeof(fnames)); + while (apr_dir_read(&dirent, APR_FINFO_DIRENT, dirp) == APR_SUCCESS) { + /* strip out '.' and '..' */ + if (strcmp(dirent.name, ".") + && strcmp(dirent.name, "..")) { + fnew = (fnames *) apr_array_push(candidates); + fnew->fname = ap_make_full_path(p, path, dirent.name); + } + } + + apr_dir_close(dirp); + if (candidates->nelts != 0) { qsort((void *) candidates->elts, candidates->nelts, - sizeof(fnames), fname_alphasort); - /* - * Now recurse these... we handle errors and subdirectories - * via the recursion, which is nice - */ - for (current = 0; current < candidates->nelts; ++current) { - fnew = &((fnames *) candidates->elts)[current]; - fprintf(stderr, " Processing config file: %s\n", fnew->fname); - ap_process_resource_config(s, fnew->fname, conftree, p, ptemp); - } - } - return; - } - - /* GCC's initialization extensions are soooo nice here... */ + sizeof(fnames), fname_alphasort); + + /* + * Now recurse these... we handle errors and subdirectories + * via the recursion, which is nice + */ + for (current = 0; current < candidates->nelts; ++current) { + fnew = &((fnames *) candidates->elts)[current]; + error = process_resource_config_nofnmatch(s, fnew->fname, + conftree, p, ptemp, + depth); + if (error) { + return error; + } + } + } + + return NULL; + } + /* GCC's initialization extensions are soooo nice here... */ parms = default_parms; parms.pool = p; parms.temp_pool = ptemp; parms.server = s; parms.override = (RSRC_CONF | OR_ALL) & ~(OR_AUTHCFG | OR_LIMIT); + parms.override_opts = OPT_ALL | OPT_INCNOEXEC | OPT_SYM_OWNER | OPT_MULTI; if (ap_pcfg_openfile(&cfp, p, fname) != APR_SUCCESS) { - ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, - "%s: could not open document config file %s", - ap_server_argv0, fname); - exit(1); + return apr_pstrcat(p, "Could not open document config file ", + fname, NULL); } parms.config_file = cfp; + error = ap_build_config(&parms, p, ptemp, conftree); + ap_cfg_closefile(cfp); - errmsg = ap_build_config(&parms, p, ptemp, conftree); + if (error) { + return apr_psprintf(p, "Syntax error on line %d of %s: %s", + parms.err_directive->line_num, + parms.err_directive->filename, error); + } - if (errmsg != NULL) { - ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, - "Syntax error on line %d of %s:", - parms.err_directive->line_num, - parms.err_directive->filename); - ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, - "%s", errmsg); - exit(1); + return NULL; +} + +AP_DECLARE(const char *) ap_process_resource_config(server_rec *s, + const char *fname, + ap_directive_t **conftree, + apr_pool_t *p, + apr_pool_t *ptemp) +{ + /* XXX: lstat() won't work on the wildcard pattern... + */ + + /* don't require conf/httpd.conf if we have a -C or -c switch */ + if ((ap_server_pre_read_config->nelts + || ap_server_post_read_config->nelts) + && !(strcmp(fname, ap_server_root_relative(p, SERVER_CONFIG_FILE)))) { + apr_finfo_t finfo; + + if (apr_stat(&finfo, fname, APR_FINFO_LINK | APR_FINFO_TYPE, p) != APR_SUCCESS) + return NULL; } - ap_cfg_closefile(cfp); + if (!apr_fnmatch_test(fname)) { + return process_resource_config_nofnmatch(s, fname, conftree, p, ptemp, + 0); + } + else { + apr_dir_t *dirp; + apr_finfo_t dirent; + int current; + apr_array_header_t *candidates = NULL; + fnames *fnew; + apr_status_t rv; + char *path = apr_pstrdup(p, fname), *pattern = NULL; + + pattern = ap_strrchr(path, '/'); + + AP_DEBUG_ASSERT(pattern != NULL); /* path must be absolute. */ + + *pattern++ = '\0'; + + if (apr_fnmatch_test(path)) { + return apr_pstrcat(p, "Wildcard patterns not allowed in Include ", + fname, NULL); + } + + if (!ap_is_directory(p, path)){ + return apr_pstrcat(p, "Include directory '", path, "' not found", + NULL); + } + + if (!apr_fnmatch_test(pattern)) { + return apr_pstrcat(p, "Must include a wildcard pattern for " + "Include ", fname, NULL); + } + + /* + * first course of business is to grok all the directory + * entries here and store 'em away. Recall we need full pathnames + * for this. + */ + rv = apr_dir_open(&dirp, path, p); + if (rv != APR_SUCCESS) { + char errmsg[120]; + return apr_psprintf(p, "Could not open config directory %s: %s", + path, apr_strerror(rv, errmsg, sizeof errmsg)); + } + + candidates = apr_array_make(p, 1, sizeof(fnames)); + while (apr_dir_read(&dirent, APR_FINFO_DIRENT, dirp) == APR_SUCCESS) { + /* strip out '.' and '..' */ + if (strcmp(dirent.name, ".") + && strcmp(dirent.name, "..") + && (apr_fnmatch(pattern, dirent.name, + APR_FNM_PERIOD) == APR_SUCCESS)) { + fnew = (fnames *) apr_array_push(candidates); + fnew->fname = ap_make_full_path(p, path, dirent.name); + } + } + + apr_dir_close(dirp); + if (candidates->nelts != 0) { + const char *error; + + qsort((void *) candidates->elts, candidates->nelts, + sizeof(fnames), fname_alphasort); + + /* + * Now recurse these... we handle errors and subdirectories + * via the recursion, which is nice + */ + for (current = 0; current < candidates->nelts; ++current) { + fnew = &((fnames *) candidates->elts)[current]; + error = process_resource_config_nofnmatch(s, fnew->fname, + conftree, p, + ptemp, 0); + if (error) { + return error; + } + } + } + } + + return NULL; } -AP_DECLARE(void)ap_process_config_tree(server_rec *s, ap_directive_t *conftree, - apr_pool_t *p, apr_pool_t *ptemp) +AP_DECLARE(int) ap_process_config_tree(server_rec *s, + ap_directive_t *conftree, + apr_pool_t *p, + apr_pool_t *ptemp) { const char *errmsg; cmd_parms parms; @@ -1458,100 +1627,117 @@ AP_DECLARE(void)ap_process_config_tree(server_rec *s, ap_directive_t *conftree, parms.temp_pool = ptemp; parms.server = s; parms.override = (RSRC_CONF | OR_ALL) & ~(OR_AUTHCFG | OR_LIMIT); + parms.override_opts = OPT_ALL | OPT_INCNOEXEC | OPT_SYM_OWNER | OPT_MULTI; parms.limited = -1; errmsg = ap_walk_config(conftree, &parms, s->lookup_defaults); if (errmsg) { - ap_log_perror(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, p, + ap_log_perror(APLOG_MARK, APLOG_STARTUP, 0, p, "Syntax error on line %d of %s:", parms.err_directive->line_num, parms.err_directive->filename); - ap_log_perror(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, p, + ap_log_perror(APLOG_MARK, APLOG_STARTUP, 0, p, "%s", errmsg); - exit(1); + return HTTP_INTERNAL_SERVER_ERROR; } + + return OK; } -int ap_parse_htaccess(void **result, request_rec *r, int override, - const char *d, const char *access_name) { - configfile_t *f = NULL; +AP_CORE_DECLARE(int) ap_parse_htaccess(ap_conf_vector_t **result, + request_rec *r, int override, + int override_opts, + const char *d, const char *access_name) +{ + ap_configfile_t *f = NULL; cmd_parms parms; char *filename = NULL; const struct htaccess_result *cache; struct htaccess_result *new; - void *dc = NULL; + ap_conf_vector_t *dc = NULL; apr_status_t status; -/* firstly, search cache */ - for (cache = r->htaccess; cache != NULL; cache = cache->next) - if (cache->override == override && strcmp(cache->dir, d) == 0) { - if (cache->htaccess != NULL) - *result = cache->htaccess; - return OK; - } + /* firstly, search cache */ + for (cache = r->htaccess; cache != NULL; cache = cache->next) { + if (cache->override == override && strcmp(cache->dir, d) == 0) { + *result = cache->htaccess; + return OK; + } + } parms = default_parms; parms.override = override; + parms.override_opts = override_opts; parms.pool = r->pool; parms.temp_pool = r->pool; parms.server = r->server; parms.path = apr_pstrdup(r->pool, d); /* loop through the access names and find the first one */ - while (access_name[0]) { + /* AFAICT; there is no use of the actual 'filename' against + * any canonicalization, so we will simply take the given + * name, ignoring case sensitivity and aliases + */ filename = ap_make_full_path(r->pool, d, ap_getword_conf(r->pool, &access_name)); status = ap_pcfg_openfile(&f, r->pool, filename); if (status == APR_SUCCESS) { - const char *errmsg; - ap_directive_t *temptree = NULL; + const char *errmsg; + ap_directive_t *temptree = NULL; dc = ap_create_per_dir_config(r->pool); parms.config_file = f; errmsg = ap_build_config(&parms, r->pool, r->pool, &temptree); - if (errmsg == NULL) - errmsg = ap_walk_config(temptree, &parms, dc); + if (errmsg == NULL) + errmsg = ap_walk_config(temptree, &parms, dc); ap_cfg_closefile(f); if (errmsg) { - ap_log_rerror(APLOG_MARK, APLOG_ALERT|APLOG_NOERRNO, 0, r, + ap_log_rerror(APLOG_MARK, APLOG_ALERT, 0, r, "%s: %s", filename, errmsg); return HTTP_INTERNAL_SERVER_ERROR; } + *result = dc; break; - } else { - if (!APR_STATUS_IS_ENOENT(status) && !APR_STATUS_IS_ENOTDIR(status)) { - ap_log_rerror(APLOG_MARK, APLOG_CRIT, status, r, - "%s pcfg_openfile: unable to check htaccess file, " - "ensure it is readable", - filename); - apr_table_setn(r->notes, "error-notes", - "Server unable to read htaccess file, denying " - "access to be safe"); - return HTTP_FORBIDDEN; - } + } + else { + if (!APR_STATUS_IS_ENOENT(status) + && !APR_STATUS_IS_ENOTDIR(status)) { + ap_log_rerror(APLOG_MARK, APLOG_CRIT, status, r, + "%s pcfg_openfile: unable to check htaccess file, " + "ensure it is readable", + filename); + apr_table_setn(r->notes, "error-notes", + "Server unable to read htaccess file, denying " + "access to be safe"); + return HTTP_FORBIDDEN; + } } } -/* cache it */ + /* cache it */ new = apr_palloc(r->pool, sizeof(struct htaccess_result)); new->dir = parms.path; new->override = override; + new->override_opts = override_opts; new->htaccess = dc; -/* add to head of list */ + + /* add to head of list */ new->next = r->htaccess; r->htaccess = new; return OK; } -AP_CORE_DECLARE(const char *) ap_init_virtual_host(apr_pool_t *p, const char *hostname, - server_rec *main_server, server_rec **ps) +AP_CORE_DECLARE(const char *) ap_init_virtual_host(apr_pool_t *p, + const char *hostname, + server_rec *main_server, + server_rec **ps) { server_rec *s = (server_rec *) apr_pcalloc(p, sizeof(server_rec)); @@ -1571,8 +1757,8 @@ AP_CORE_DECLARE(const char *) ap_init_virtual_host(apr_pool_t *p, const char *ho s->next = NULL; s->is_virtual = 1; - s->names = apr_make_array(p, 4, sizeof(char **)); - s->wild_names = apr_make_array(p, 4, sizeof(char **)); + s->names = apr_array_make(p, 4, sizeof(char **)); + s->wild_names = apr_array_make(p, 4, sizeof(char **)); s->module_config = create_empty_config(p); s->lookup_defaults = ap_create_per_dir_config(p); @@ -1592,38 +1778,40 @@ AP_DECLARE(void) ap_fixup_virtual_hosts(apr_pool_t *p, server_rec *main_server) server_rec *virt; for (virt = main_server->next; virt; virt = virt->next) { - merge_server_configs(p, main_server->module_config, - virt->module_config); + merge_server_configs(p, main_server->module_config, + virt->module_config); - virt->lookup_defaults = - ap_merge_per_dir_configs(p, main_server->lookup_defaults, - virt->lookup_defaults); + virt->lookup_defaults = + ap_merge_per_dir_configs(p, main_server->lookup_defaults, + virt->lookup_defaults); - if (virt->server_admin == NULL) - virt->server_admin = main_server->server_admin; + if (virt->server_admin == NULL) + virt->server_admin = main_server->server_admin; - if (virt->timeout == 0) - virt->timeout = main_server->timeout; + if (virt->timeout == 0) + virt->timeout = main_server->timeout; - if (virt->keep_alive_timeout == 0) - virt->keep_alive_timeout = main_server->keep_alive_timeout; + if (virt->keep_alive_timeout == 0) + virt->keep_alive_timeout = main_server->keep_alive_timeout; - if (virt->keep_alive == -1) - virt->keep_alive = main_server->keep_alive; + if (virt->keep_alive == -1) + virt->keep_alive = main_server->keep_alive; - if (virt->keep_alive_max == -1) - virt->keep_alive_max = main_server->keep_alive_max; + if (virt->keep_alive_max == -1) + virt->keep_alive_max = main_server->keep_alive_max; - /* XXX: this is really something that should be dealt with by a - * post-config api phase */ - ap_core_reorder_directories(p, virt); + /* XXX: this is really something that should be dealt with by a + * post-config api phase + */ + ap_core_reorder_directories(p, virt); } + ap_core_reorder_directories(p, main_server); } /***************************************************************** * - * Getting *everything* configured... + * Getting *everything* configured... */ static void init_config_globals(apr_pool_t *p) @@ -1637,7 +1825,7 @@ static server_rec *init_server_config(process_rec *process, apr_pool_t *p) apr_status_t rv; server_rec *s = (server_rec *) apr_pcalloc(p, sizeof(server_rec)); - apr_open_stderr(&s->error_log, p); + apr_file_open_stderr(&s->error_log, p); s->process = process; s->port = 0; s->server_admin = DEFAULT_ADMIN; @@ -1647,18 +1835,20 @@ static server_rec *init_server_config(process_rec *process, apr_pool_t *p) s->limit_req_line = DEFAULT_LIMIT_REQUEST_LINE; s->limit_req_fieldsize = DEFAULT_LIMIT_REQUEST_FIELDSIZE; s->limit_req_fields = DEFAULT_LIMIT_REQUEST_FIELDS; - s->timeout = DEFAULT_TIMEOUT; - s->keep_alive_timeout = DEFAULT_KEEPALIVE_TIMEOUT; + s->timeout = apr_time_from_sec(DEFAULT_TIMEOUT); + s->keep_alive_timeout = apr_time_from_sec(DEFAULT_KEEPALIVE_TIMEOUT); s->keep_alive_max = DEFAULT_KEEPALIVE; s->keep_alive = 1; s->next = NULL; s->addrs = apr_pcalloc(p, sizeof(server_addr_rec)); + /* NOT virtual host; don't match any real network interface */ - rv = apr_getaddrinfo(&s->addrs->host_addr, - NULL, APR_INET, 0, 0, p); + rv = apr_sockaddr_info_get(&s->addrs->host_addr, + NULL, APR_INET, 0, 0, p); ap_assert(rv == APR_SUCCESS); /* otherwise: bug or no storage */ - s->addrs->host_port = 0; /* matches any port */ - s->addrs->virthost = ""; /* must be non-NULL */ + + s->addrs->host_port = 0; /* matches any port */ + s->addrs->virthost = ""; /* must be non-NULL */ s->names = s->wild_names = NULL; s->module_config = create_server_config(p, s); @@ -1669,32 +1859,62 @@ static server_rec *init_server_config(process_rec *process, apr_pool_t *p) AP_DECLARE(server_rec*) ap_read_config(process_rec *process, apr_pool_t *ptemp, - const char *confname, + const char *filename, ap_directive_t **conftree) { + const char *confname, *error; apr_pool_t *p = process->pconf; server_rec *s = init_server_config(process, p); init_config_globals(p); /* All server-wide config files now have the SAME syntax... */ + error = process_command_config(s, ap_server_pre_read_config, conftree, + p, ptemp); + if (error) { + ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_CRIT, 0, NULL, "%s: %s", + ap_server_argv0, error); + return NULL; + } - process_command_config(s, ap_server_pre_read_config, conftree, - p, ptemp); + /* process_command_config may change the ServerRoot so + * compute this config file name afterwards. + */ + confname = ap_server_root_relative(p, filename); - ap_process_resource_config(s, confname, conftree, p, ptemp); + if (!confname) { + ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_CRIT, + APR_EBADPATH, NULL, "Invalid config file path %s", + filename); + return NULL; + } + + error = ap_process_resource_config(s, confname, conftree, p, ptemp); + if (error) { + ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_CRIT, 0, NULL, + "%s: %s", ap_server_argv0, error); + return NULL; + } - process_command_config(s, ap_server_post_read_config, conftree, - p, ptemp); + error = process_command_config(s, ap_server_post_read_config, conftree, + p, ptemp); + + if (error) { + ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_CRIT, 0, NULL, "%s: %s", + ap_server_argv0, error); + return NULL; + } return s; } -void ap_single_module_configure(apr_pool_t *p, server_rec *s, module *m) +AP_DECLARE(void) ap_single_module_configure(apr_pool_t *p, server_rec *s, + module *m) { if (m->create_server_config) ap_set_module_config(s->module_config, m, (*m->create_server_config)(p, s)); + if (m->create_dir_config) ap_set_module_config(s->lookup_defaults, m, (*m->create_dir_config)(p, NULL)); @@ -1704,23 +1924,11 @@ AP_DECLARE(void) ap_run_rewrite_args(process_rec *process) { module *m; - for (m = top_module; m; m = m->next) - if (m->rewrite_args) - (*m->rewrite_args) (process); -} - -AP_DECLARE(void) ap_post_config_hook(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s) -{ - ap_run_post_config(pconf,plog,ptemp,s); - init_handlers(pconf); -} - -void ap_child_init_hook(apr_pool_t *pchild, server_rec *s) -{ - /* TODO: uh this seems ugly, is there a better way? */ - /*ap_child_init_alloc(); PUT THIS BACK IN XXXXX */ - - ap_run_child_init(pchild,s); + for (m = ap_top_module; m; m = m->next) { + if (m->rewrite_args) { + (*m->rewrite_args)(process); + } + } } /******************************************************************** @@ -1744,84 +1952,105 @@ static void show_overrides(const command_rec *pc, module *pm) int n = 0; printf("\tAllowed in *.conf "); - if ((pc->req_override & (OR_OPTIONS | OR_FILEINFO | OR_INDEXES)) || - ((pc->req_override & RSRC_CONF) && - ((pc->req_override & (ACCESS_CONF | OR_AUTHCFG | OR_LIMIT))))) - printf("anywhere"); - else if (pc->req_override & RSRC_CONF) - printf("only outside , or "); - else - printf("only inside , or "); + if ((pc->req_override & (OR_OPTIONS | OR_FILEINFO | OR_INDEXES)) + || ((pc->req_override & RSRC_CONF) + && ((pc->req_override & (ACCESS_CONF | OR_AUTHCFG | OR_LIMIT))))) { + printf("anywhere"); + } + else if (pc->req_override & RSRC_CONF) { + printf("only outside , or "); + } + else { + printf("only inside , or "); + } /* Warn if the directive is allowed inside or .htaccess - * but module doesn't support per-dir configuration */ - + * but module doesn't support per-dir configuration + */ if ((pc->req_override & (OR_ALL | ACCESS_CONF)) && !pm->create_dir_config) - printf(" [no per-dir config]"); + printf(" [no per-dir config]"); if (pc->req_override & OR_ALL) { - printf(" and in .htaccess\n\twhen AllowOverride"); - - if ((pc->req_override & OR_ALL) == OR_ALL) - printf(" isn't None"); - else { - printf(" includes "); - - if (pc->req_override & OR_AUTHCFG) { - if (n++) - printf(" or "); - printf("AuthConfig"); - } - if (pc->req_override & OR_LIMIT) { - if (n++) - printf(" or "); - printf("Limit"); - } - if (pc->req_override & OR_OPTIONS) { - if (n++) - printf(" or "); - printf("Options"); - } - if (pc->req_override & OR_FILEINFO) { - if (n++) - printf(" or "); - printf("FileInfo"); - } - if (pc->req_override & OR_INDEXES) { - if (n++) - printf(" or "); - printf("Indexes"); - } - } + printf(" and in .htaccess\n\twhen AllowOverride"); + + if ((pc->req_override & OR_ALL) == OR_ALL) { + printf(" isn't None"); + } + else { + printf(" includes "); + + if (pc->req_override & OR_AUTHCFG) { + if (n++) + printf(" or "); + + printf("AuthConfig"); + } + + if (pc->req_override & OR_LIMIT) { + if (n++) + printf(" or "); + + printf("Limit"); + } + + if (pc->req_override & OR_OPTIONS) { + if (n++) + printf(" or "); + + printf("Options"); + } + + if (pc->req_override & OR_FILEINFO) { + if (n++) + printf(" or "); + + printf("FileInfo"); + } + + if (pc->req_override & OR_INDEXES) { + 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. + * what parts of the configuration they are allowed. Used for httpd -L. */ -AP_DECLARE(void) ap_show_directives() +AP_DECLARE(void) ap_show_directives(void) { const command_rec *pc; int n; - for (n = 0; ap_loaded_modules[n]; ++n) - for (pc = ap_loaded_modules[n]->cmds; pc && pc->name; ++pc) { - printf("%s (%s)\n", pc->name, ap_loaded_modules[n]->name); - if (pc->errmsg) - printf("\t%s\n", pc->errmsg); - show_overrides(pc, ap_loaded_modules[n]); - } + for (n = 0; ap_loaded_modules[n]; ++n) { + for (pc = ap_loaded_modules[n]->cmds; pc && pc->name; ++pc) { + printf("%s (%s)\n", pc->name, ap_loaded_modules[n]->name); + + if (pc->errmsg) + printf("\t%s\n", pc->errmsg); + + show_overrides(pc, ap_loaded_modules[n]); + } + } } /* Show the preloaded module names. Used for httpd -l. */ -AP_DECLARE(void) ap_show_modules() +AP_DECLARE(void) ap_show_modules(void) { int n; printf("Compiled in modules:\n"); for (n = 0; ap_loaded_modules[n]; ++n) - printf(" %s\n", ap_loaded_modules[n]->name); + printf(" %s\n", ap_loaded_modules[n]->name); } +AP_DECLARE(const char *) ap_show_mpm(void) +{ + return MPM_NAME; +}