|
Packit |
90a5c9 |
/* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
Packit |
90a5c9 |
* contributor license agreements. See the NOTICE file distributed with
|
|
Packit |
90a5c9 |
* this work for additional information regarding copyright ownership.
|
|
Packit |
90a5c9 |
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
Packit |
90a5c9 |
* (the "License"); you may not use this file except in compliance with
|
|
Packit |
90a5c9 |
* the License. You may obtain a copy of the License at
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* Unless required by applicable law or agreed to in writing, software
|
|
Packit |
90a5c9 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
Packit |
90a5c9 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
Packit |
90a5c9 |
* See the License for the specific language governing permissions and
|
|
Packit |
90a5c9 |
* limitations under the License.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* http_config.c: once was auxiliary functions for reading httpd's config
|
|
Packit |
90a5c9 |
* file and converting filenames into a namespace
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* Rob McCool
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* Wall-to-wall rewrite for Apache... commands which are part of the
|
|
Packit |
90a5c9 |
* server core can now be found next door in "http_core.c". Now contains
|
|
Packit |
90a5c9 |
* general command loop, and functions which do bookkeeping for the new
|
|
Packit |
90a5c9 |
* Apache config stuff (modules and configuration vectors).
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* rst
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#include "apr.h"
|
|
Packit |
90a5c9 |
#include "apr_strings.h"
|
|
Packit |
90a5c9 |
#include "apr_portable.h"
|
|
Packit |
90a5c9 |
#include "apr_file_io.h"
|
|
Packit |
90a5c9 |
#include "apr_fnmatch.h"
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#define APR_WANT_STDIO
|
|
Packit |
90a5c9 |
#define APR_WANT_STRFUNC
|
|
Packit |
90a5c9 |
#include "apr_want.h"
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#include "ap_config.h"
|
|
Packit |
90a5c9 |
#include "httpd.h"
|
|
Packit |
90a5c9 |
#include "http_config.h"
|
|
Packit |
90a5c9 |
#include "http_protocol.h"
|
|
Packit |
90a5c9 |
#include "http_core.h"
|
|
Packit |
90a5c9 |
#include "http_log.h" /* for errors in parse_htaccess */
|
|
Packit |
90a5c9 |
#include "http_request.h" /* for default_handler (see invoke_handler) */
|
|
Packit |
90a5c9 |
#include "http_main.h"
|
|
Packit |
90a5c9 |
#include "http_vhost.h"
|
|
Packit |
90a5c9 |
#include "util_cfgtree.h"
|
|
Packit |
90a5c9 |
#include "util_varbuf.h"
|
|
Packit |
90a5c9 |
#include "mpm_common.h"
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#define APLOG_UNSET (APLOG_NO_MODULE - 1)
|
|
Packit |
90a5c9 |
/* we know core's module_index is 0 */
|
|
Packit |
90a5c9 |
#undef APLOG_MODULE_INDEX
|
|
Packit |
90a5c9 |
#define APLOG_MODULE_INDEX AP_CORE_MODULE_INDEX
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_DECLARE_DATA const char *ap_server_argv0 = NULL;
|
|
Packit |
90a5c9 |
AP_DECLARE_DATA const char *ap_server_root = NULL;
|
|
Packit |
90a5c9 |
AP_DECLARE_DATA const char *ap_runtime_dir = NULL;
|
|
Packit |
90a5c9 |
AP_DECLARE_DATA server_rec *ap_server_conf = NULL;
|
|
Packit |
90a5c9 |
AP_DECLARE_DATA apr_pool_t *ap_pglobal = NULL;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_DECLARE_DATA apr_array_header_t *ap_server_pre_read_config = NULL;
|
|
Packit |
90a5c9 |
AP_DECLARE_DATA apr_array_header_t *ap_server_post_read_config = NULL;
|
|
Packit |
90a5c9 |
AP_DECLARE_DATA apr_array_header_t *ap_server_config_defines = NULL;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_DECLARE_DATA ap_directive_t *ap_conftree = NULL;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
APR_HOOK_STRUCT(
|
|
Packit |
90a5c9 |
APR_HOOK_LINK(header_parser)
|
|
Packit |
90a5c9 |
APR_HOOK_LINK(pre_config)
|
|
Packit |
90a5c9 |
APR_HOOK_LINK(check_config)
|
|
Packit |
90a5c9 |
APR_HOOK_LINK(post_config)
|
|
Packit |
90a5c9 |
APR_HOOK_LINK(open_logs)
|
|
Packit |
90a5c9 |
APR_HOOK_LINK(child_init)
|
|
Packit |
90a5c9 |
APR_HOOK_LINK(handler)
|
|
Packit |
90a5c9 |
APR_HOOK_LINK(quick_handler)
|
|
Packit |
90a5c9 |
APR_HOOK_LINK(optional_fn_retrieve)
|
|
Packit |
90a5c9 |
APR_HOOK_LINK(test_config)
|
|
Packit |
90a5c9 |
APR_HOOK_LINK(open_htaccess)
|
|
Packit |
90a5c9 |
)
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_IMPLEMENT_HOOK_RUN_ALL(int, header_parser,
|
|
Packit |
90a5c9 |
(request_rec *r), (r), OK, DECLINED)
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_IMPLEMENT_HOOK_RUN_ALL(int, pre_config,
|
|
Packit |
90a5c9 |
(apr_pool_t *pconf, apr_pool_t *plog,
|
|
Packit |
90a5c9 |
apr_pool_t *ptemp),
|
|
Packit |
90a5c9 |
(pconf, plog, ptemp), OK, DECLINED)
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_IMPLEMENT_HOOK_RUN_ALL(int, check_config,
|
|
Packit |
90a5c9 |
(apr_pool_t *pconf, apr_pool_t *plog,
|
|
Packit |
90a5c9 |
apr_pool_t *ptemp, server_rec *s),
|
|
Packit |
90a5c9 |
(pconf, plog, ptemp, s), OK, DECLINED)
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_IMPLEMENT_HOOK_VOID(test_config,
|
|
Packit |
90a5c9 |
(apr_pool_t *pconf, server_rec *s),
|
|
Packit |
90a5c9 |
(pconf, s))
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_IMPLEMENT_HOOK_RUN_ALL(int, post_config,
|
|
Packit |
90a5c9 |
(apr_pool_t *pconf, apr_pool_t *plog,
|
|
Packit |
90a5c9 |
apr_pool_t *ptemp, server_rec *s),
|
|
Packit |
90a5c9 |
(pconf, plog, ptemp, s), OK, DECLINED)
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* During the course of debugging I expanded this macro out, so
|
|
Packit |
90a5c9 |
* rather than remove all the useful information there is in the
|
|
Packit |
90a5c9 |
* following lines, I'm going to leave it here in case anyone
|
|
Packit |
90a5c9 |
* else finds it useful.
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* Ben has looked at it and thinks it correct :)
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
AP_DECLARE(int) ap_hook_post_config(ap_HOOK_post_config_t *pf,
|
|
Packit |
90a5c9 |
const char * const *aszPre,
|
|
Packit |
90a5c9 |
const char * const *aszSucc,
|
|
Packit |
90a5c9 |
int nOrder)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
ap_LINK_post_config_t *pHook;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!_hooks.link_post_config) {
|
|
Packit |
90a5c9 |
_hooks.link_post_config = apr_array_make(apr_hook_global_pool, 1,
|
|
Packit |
90a5c9 |
sizeof(ap_LINK_post_config_t));
|
|
Packit |
90a5c9 |
apr_hook_sort_register("post_config", &_hooks.link_post_config);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
pHook = apr_array_push(_hooks.link_post_config);
|
|
Packit |
90a5c9 |
pHook->pFunc = pf;
|
|
Packit |
90a5c9 |
pHook->aszPredecessors = aszPre;
|
|
Packit |
90a5c9 |
pHook->aszSuccessors = aszSucc;
|
|
Packit |
90a5c9 |
pHook->nOrder = nOrder;
|
|
Packit |
90a5c9 |
pHook->szName = apr_hook_debug_current;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (apr_hook_debug_enabled)
|
|
Packit |
90a5c9 |
apr_hook_debug_show("post_config", aszPre, aszSucc);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_DECLARE(apr_array_header_t *) ap_hook_get_post_config(void)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
return _hooks.link_post_config;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_DECLARE(int) ap_run_post_config(apr_pool_t *pconf,
|
|
Packit |
90a5c9 |
apr_pool_t *plog,
|
|
Packit |
90a5c9 |
apr_pool_t *ptemp,
|
|
Packit |
90a5c9 |
server_rec *s)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
ap_LINK_post_config_t *pHook;
|
|
Packit |
90a5c9 |
int n;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!_hooks.link_post_config)
|
|
Packit |
90a5c9 |
return;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
pHook = (ap_LINK_post_config_t *)_hooks.link_post_config->elts;
|
|
Packit |
90a5c9 |
for (n = 0; n < _hooks.link_post_config->nelts; ++n)
|
|
Packit |
90a5c9 |
pHook[n].pFunc (pconf, plog, ptemp, s);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_IMPLEMENT_HOOK_RUN_ALL(int, open_logs,
|
|
Packit |
90a5c9 |
(apr_pool_t *pconf, apr_pool_t *plog,
|
|
Packit |
90a5c9 |
apr_pool_t *ptemp, server_rec *s),
|
|
Packit |
90a5c9 |
(pconf, plog, ptemp, s), OK, DECLINED)
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_IMPLEMENT_HOOK_VOID(child_init,
|
|
Packit |
90a5c9 |
(apr_pool_t *pchild, server_rec *s),
|
|
Packit |
90a5c9 |
(pchild, s))
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_IMPLEMENT_HOOK_RUN_FIRST(int, handler, (request_rec *r),
|
|
Packit |
90a5c9 |
(r), DECLINED)
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_IMPLEMENT_HOOK_RUN_FIRST(int, quick_handler, (request_rec *r, int lookup),
|
|
Packit |
90a5c9 |
(r, lookup), DECLINED)
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_IMPLEMENT_HOOK_RUN_FIRST(apr_status_t, open_htaccess,
|
|
Packit |
90a5c9 |
(request_rec *r, const char *dir_name, const char *access_name,
|
|
Packit |
90a5c9 |
ap_configfile_t **conffile, const char **full_name),
|
|
Packit |
90a5c9 |
(r, dir_name, access_name, conffile, full_name),
|
|
Packit |
90a5c9 |
AP_DECLINED)
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* hooks with no args are implemented last, after disabling APR hook probes */
|
|
Packit |
90a5c9 |
#if defined(APR_HOOK_PROBES_ENABLED)
|
|
Packit |
90a5c9 |
#undef APR_HOOK_PROBES_ENABLED
|
|
Packit |
90a5c9 |
#undef APR_HOOK_PROBE_ENTRY
|
|
Packit |
90a5c9 |
#define APR_HOOK_PROBE_ENTRY(ud,ns,name,args)
|
|
Packit |
90a5c9 |
#undef APR_HOOK_PROBE_RETURN
|
|
Packit |
90a5c9 |
#define APR_HOOK_PROBE_RETURN(ud,ns,name,rv,args)
|
|
Packit |
90a5c9 |
#undef APR_HOOK_PROBE_INVOKE
|
|
Packit |
90a5c9 |
#define APR_HOOK_PROBE_INVOKE(ud,ns,name,src,args)
|
|
Packit |
90a5c9 |
#undef APR_HOOK_PROBE_COMPLETE
|
|
Packit |
90a5c9 |
#define APR_HOOK_PROBE_COMPLETE(ud,ns,name,src,rv,args)
|
|
Packit |
90a5c9 |
#undef APR_HOOK_INT_DCL_UD
|
|
Packit |
90a5c9 |
#define APR_HOOK_INT_DCL_UD
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
AP_IMPLEMENT_HOOK_VOID(optional_fn_retrieve, (void), ())
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/****************************************************************
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* We begin with the functions which deal with the linked list
|
|
Packit |
90a5c9 |
* of modules which control just about all of the server operation.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* total_modules is the number of modules that have been linked
|
|
Packit |
90a5c9 |
* into the server.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
static int total_modules = 0;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* dynamic_modules is the number of modules that have been added
|
|
Packit |
90a5c9 |
* after the pre-loaded ones have been set up. It shouldn't be larger
|
|
Packit |
90a5c9 |
* than DYNAMIC_MODULE_LIMIT.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
static int dynamic_modules = 0;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* The maximum possible value for total_modules, i.e. number of static
|
|
Packit |
90a5c9 |
* modules plus DYNAMIC_MODULE_LIMIT.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
static int max_modules = 0;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* The number of elements we need to alloc for config vectors. Before loading
|
|
Packit |
90a5c9 |
* of dynamic modules, we must be liberal and set this to max_modules. After
|
|
Packit |
90a5c9 |
* loading of dynamic modules, we can trim it down to total_modules. On
|
|
Packit |
90a5c9 |
* restart, reset to max_modules.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
static int conf_vector_length = 0;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static int reserved_module_slots = 0;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_DECLARE_DATA module *ap_top_module = NULL;
|
|
Packit |
90a5c9 |
AP_DECLARE_DATA module **ap_loaded_modules=NULL;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static apr_hash_t *ap_config_hash = NULL;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* a list of the module symbol names with the trailing "_module"removed */
|
|
Packit |
90a5c9 |
static char **ap_module_short_names = NULL;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
typedef int (*handler_func)(request_rec *);
|
|
Packit |
90a5c9 |
typedef void *(*dir_maker_func)(apr_pool_t *, char *);
|
|
Packit |
90a5c9 |
typedef void *(*merger_func)(apr_pool_t *, void *, void *);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* A list of the merge_dir_config functions of all loaded modules, sorted
|
|
Packit |
90a5c9 |
* by module_index.
|
|
Packit |
90a5c9 |
* Using this list in ap_merge_per_dir_configs() is faster than following
|
|
Packit |
90a5c9 |
* the module->next linked list because of better memory locality (resulting
|
|
Packit |
90a5c9 |
* in better cache usage).
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
static merger_func *merger_func_cache;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* maximum nesting level for config directories */
|
|
Packit |
90a5c9 |
#ifndef AP_MAX_INCLUDE_DIR_DEPTH
|
|
Packit |
90a5c9 |
#define AP_MAX_INCLUDE_DIR_DEPTH (128)
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Dealing with config vectors. These are associated with per-directory,
|
|
Packit |
90a5c9 |
* per-server, and per-request configuration, and have a void* pointer for
|
|
Packit |
90a5c9 |
* each modules. The nature of the structure pointed to is private to the
|
|
Packit |
90a5c9 |
* module in question... the core doesn't (and can't) know. However, there
|
|
Packit |
90a5c9 |
* are defined interfaces which allow it to create instances of its private
|
|
Packit |
90a5c9 |
* per-directory and per-server structures, and to merge the per-directory
|
|
Packit |
90a5c9 |
* structures of a directory and its subdirectory (producing a new one in
|
|
Packit |
90a5c9 |
* which the defaults applying to the base directory have been properly
|
|
Packit |
90a5c9 |
* overridden).
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static ap_conf_vector_t *create_empty_config(apr_pool_t *p)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
void *conf_vector = apr_pcalloc(p, sizeof(void *) * conf_vector_length);
|
|
Packit |
90a5c9 |
return conf_vector;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static ap_conf_vector_t *create_default_per_dir_config(apr_pool_t *p)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
void **conf_vector = apr_pcalloc(p, sizeof(void *) * conf_vector_length);
|
|
Packit |
90a5c9 |
module *modp;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
for (modp = ap_top_module; modp; modp = modp->next) {
|
|
Packit |
90a5c9 |
dir_maker_func df = modp->create_dir_config;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (df)
|
|
Packit |
90a5c9 |
conf_vector[modp->module_index] = (*df)(p, NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return (ap_conf_vector_t *)conf_vector;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_CORE_DECLARE(ap_conf_vector_t *) ap_merge_per_dir_configs(apr_pool_t *p,
|
|
Packit |
90a5c9 |
ap_conf_vector_t *base,
|
|
Packit |
90a5c9 |
ap_conf_vector_t *new_conf)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
void **conf_vector = apr_palloc(p, sizeof(void *) * conf_vector_length);
|
|
Packit |
90a5c9 |
void **base_vector = (void **)base;
|
|
Packit |
90a5c9 |
void **new_vector = (void **)new_conf;
|
|
Packit |
90a5c9 |
int i;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
for (i = 0; i < total_modules; i++) {
|
|
Packit |
90a5c9 |
if (!new_vector[i]) {
|
|
Packit |
90a5c9 |
conf_vector[i] = base_vector[i];
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
const merger_func df = merger_func_cache[i];
|
|
Packit |
90a5c9 |
if (df && base_vector[i]) {
|
|
Packit |
90a5c9 |
conf_vector[i] = (*df)(p, base_vector[i], new_vector[i]);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else
|
|
Packit |
90a5c9 |
conf_vector[i] = new_vector[i];
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return (ap_conf_vector_t *)conf_vector;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static ap_conf_vector_t *create_server_config(apr_pool_t *p, server_rec *s)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
void **conf_vector = apr_pcalloc(p, sizeof(void *) * conf_vector_length);
|
|
Packit |
90a5c9 |
module *modp;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
for (modp = ap_top_module; modp; modp = modp->next) {
|
|
Packit |
90a5c9 |
if (modp->create_server_config)
|
|
Packit |
90a5c9 |
conf_vector[modp->module_index] = (*modp->create_server_config)(p, s);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return (ap_conf_vector_t *)conf_vector;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void merge_server_configs(apr_pool_t *p, ap_conf_vector_t *base,
|
|
Packit |
90a5c9 |
server_rec *virt)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
/* Can reuse the 'virt' vector for the spine of it, since we don't
|
|
Packit |
90a5c9 |
* have to deal with the moral equivalent of .htaccess files here...
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
void **base_vector = (void **)base;
|
|
Packit |
90a5c9 |
void **virt_vector = (void **)virt->module_config;
|
|
Packit |
90a5c9 |
module *modp;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
for (modp = ap_top_module; modp; modp = modp->next) {
|
|
Packit |
90a5c9 |
merger_func df = modp->merge_server_config;
|
|
Packit |
90a5c9 |
int i = modp->module_index;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!virt_vector[i]) {
|
|
Packit |
90a5c9 |
if (df && modp->create_server_config
|
|
Packit |
90a5c9 |
&& (ap_get_module_flags(modp) &
|
|
Packit |
90a5c9 |
AP_MODULE_FLAG_ALWAYS_MERGE)) {
|
|
Packit |
90a5c9 |
virt_vector[i] = (*modp->create_server_config)(p, virt);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
virt_vector[i] = base_vector[i];
|
|
Packit |
90a5c9 |
df = NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (df) {
|
|
Packit |
90a5c9 |
virt_vector[i] = (*df)(p, base_vector[i], virt_vector[i]);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_CORE_DECLARE(ap_conf_vector_t *) ap_create_request_config(apr_pool_t *p)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
return create_empty_config(p);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_CORE_DECLARE(ap_conf_vector_t *) ap_create_conn_config(apr_pool_t *p)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
return create_empty_config(p);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_CORE_DECLARE(ap_conf_vector_t *) ap_create_per_dir_config(apr_pool_t *p)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
return create_empty_config(p);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Invoke the filter_init_func for all filters with FILTERS where f->r
|
|
Packit |
90a5c9 |
* matches R. Restricting to a matching R avoids re-running init
|
|
Packit |
90a5c9 |
* functions for filters configured for r->main where r is a
|
|
Packit |
90a5c9 |
* subrequest. */
|
|
Packit |
90a5c9 |
static int invoke_filter_init(request_rec *r, ap_filter_t *filters)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
while (filters) {
|
|
Packit |
90a5c9 |
if (filters->frec->filter_init_func && filters->r == r) {
|
|
Packit |
90a5c9 |
int result = filters->frec->filter_init_func(filters);
|
|
Packit |
90a5c9 |
if (result != OK) {
|
|
Packit |
90a5c9 |
return result;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
filters = filters->next;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return OK;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_CORE_DECLARE(int) ap_invoke_handler(request_rec *r)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
const char *handler;
|
|
Packit |
90a5c9 |
const char *p;
|
|
Packit |
90a5c9 |
int result;
|
|
Packit |
90a5c9 |
const char *old_handler = r->handler;
|
|
Packit |
90a5c9 |
const char *ignore;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* The new insert_filter stage makes the most sense here. We only use
|
|
Packit |
90a5c9 |
* it when we are going to run the request, so we must insert filters
|
|
Packit |
90a5c9 |
* if any are available. Since the goal of this phase is to allow all
|
|
Packit |
90a5c9 |
* modules to insert a filter if they want to, this filter returns
|
|
Packit |
90a5c9 |
* void. I just can't see any way that this filter can reasonably
|
|
Packit |
90a5c9 |
* fail, either your modules inserts something or it doesn't. rbb
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
ap_run_insert_filter(r);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Before continuing, allow each filter that is in the two chains to
|
|
Packit |
90a5c9 |
* run their init function to let them do any magic before we could
|
|
Packit |
90a5c9 |
* start generating data.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
result = invoke_filter_init(r, r->input_filters);
|
|
Packit |
90a5c9 |
if (result != OK) {
|
|
Packit |
90a5c9 |
return result;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
result = invoke_filter_init(r, r->output_filters);
|
|
Packit |
90a5c9 |
if (result != OK) {
|
|
Packit |
90a5c9 |
return result;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!r->handler) {
|
|
Packit |
90a5c9 |
if (r->content_type) {
|
|
Packit |
90a5c9 |
handler = r->content_type;
|
|
Packit |
90a5c9 |
if ((p=ap_strchr_c(handler, ';')) != NULL) {
|
|
Packit |
90a5c9 |
char *new_handler = (char *)apr_pmemdup(r->pool, handler,
|
|
Packit |
90a5c9 |
p - handler + 1);
|
|
Packit |
90a5c9 |
char *p2 = new_handler + (p - handler);
|
|
Packit |
90a5c9 |
handler = new_handler;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* exclude media type arguments */
|
|
Packit |
90a5c9 |
while (p2 > handler && p2[-1] == ' ')
|
|
Packit |
90a5c9 |
--p2; /* strip trailing spaces */
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
*p2='\0';
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
handler = AP_DEFAULT_HANDLER_NAME;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
r->handler = handler;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
result = ap_run_handler(r);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
r->handler = old_handler;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (result == DECLINED && r->handler && r->filename) {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, APLOGNO(00523)
|
|
Packit |
90a5c9 |
"handler \"%s\" not found for: %s", r->handler, r->filename);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if ((result != OK) && (result != DONE) && (result != DECLINED) && (result != SUSPENDED)
|
|
Packit |
90a5c9 |
&& (result != AP_FILTER_ERROR) /* ap_die() knows about this specifically */
|
|
Packit |
90a5c9 |
&& !ap_is_HTTP_VALID_RESPONSE(result)) {
|
|
Packit |
90a5c9 |
/* If a module is deliberately returning something else
|
|
Packit |
90a5c9 |
* (request_rec in non-HTTP or proprietary extension?)
|
|
Packit |
90a5c9 |
* let it set a note to allow it explicitly.
|
|
Packit |
90a5c9 |
* Otherwise, a return code that is neither reserved nor HTTP
|
|
Packit |
90a5c9 |
* is a bug, as in PR#31759.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
ignore = apr_table_get(r->notes, "HTTP_IGNORE_RANGE");
|
|
Packit |
90a5c9 |
if (!ignore) {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00524)
|
|
Packit |
90a5c9 |
"Handler for %s returned invalid result code %d",
|
|
Packit |
90a5c9 |
r->handler, result);
|
|
Packit |
90a5c9 |
result = HTTP_INTERNAL_SERVER_ERROR;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return result == DECLINED ? HTTP_INTERNAL_SERVER_ERROR : result;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_DECLARE(int) ap_method_is_limited(cmd_parms *cmd, const char *method)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
int methnum;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
methnum = ap_method_number_of(method);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* A method number either hardcoded into apache or
|
|
Packit |
90a5c9 |
* added by a module and registered.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (methnum != M_INVALID) {
|
|
Packit |
90a5c9 |
return (cmd->limited & (AP_METHOD_BIT << methnum)) ? 1 : 0;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return 0; /* not found */
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_DECLARE(void) ap_register_hooks(module *m, apr_pool_t *p)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
if (m->register_hooks) {
|
|
Packit |
90a5c9 |
if (getenv("SHOW_HOOKS")) {
|
|
Packit |
90a5c9 |
printf("Registering hooks for %s\n", m->name);
|
|
Packit |
90a5c9 |
apr_hook_debug_enabled = 1;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
apr_hook_debug_current = m->name;
|
|
Packit |
90a5c9 |
m->register_hooks(p);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void ap_add_module_commands(module *m, apr_pool_t *p);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
typedef struct ap_mod_list_struct ap_mod_list;
|
|
Packit |
90a5c9 |
struct ap_mod_list_struct {
|
|
Packit |
90a5c9 |
struct ap_mod_list_struct *next;
|
|
Packit |
90a5c9 |
module *m;
|
|
Packit |
90a5c9 |
const command_rec *cmd;
|
|
Packit |
90a5c9 |
};
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void rebuild_conf_hash(apr_pool_t *p, int add_prelinked)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
module **m;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ap_config_hash = apr_hash_make(p);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
apr_pool_cleanup_register(p, &ap_config_hash, ap_pool_cleanup_set_null,
|
|
Packit |
90a5c9 |
apr_pool_cleanup_null);
|
|
Packit |
90a5c9 |
if (add_prelinked) {
|
|
Packit |
90a5c9 |
for (m = ap_prelinked_modules; *m != NULL; m++) {
|
|
Packit |
90a5c9 |
ap_add_module_commands(*m, p);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void ap_add_module_commands(module *m, apr_pool_t *p)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
apr_pool_t *tpool;
|
|
Packit |
90a5c9 |
ap_mod_list *mln;
|
|
Packit |
90a5c9 |
const command_rec *cmd;
|
|
Packit |
90a5c9 |
char *dir;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
cmd = m->cmds;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (ap_config_hash == NULL) {
|
|
Packit |
90a5c9 |
rebuild_conf_hash(p, 0);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
tpool = apr_hash_pool_get(ap_config_hash);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
while (cmd && cmd->name) {
|
|
Packit |
90a5c9 |
mln = apr_palloc(tpool, sizeof(ap_mod_list));
|
|
Packit |
90a5c9 |
mln->cmd = cmd;
|
|
Packit |
90a5c9 |
mln->m = m;
|
|
Packit |
90a5c9 |
dir = apr_pstrdup(tpool, cmd->name);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ap_str_tolower(dir);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
mln->next = apr_hash_get(ap_config_hash, dir, APR_HASH_KEY_STRING);
|
|
Packit |
90a5c9 |
apr_hash_set(ap_config_hash, dir, APR_HASH_KEY_STRING, mln);
|
|
Packit |
90a5c9 |
++cmd;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* One-time setup for precompiled modules --- NOT to be done on restart */
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_DECLARE(const char *) ap_add_module(module *m, apr_pool_t *p,
|
|
Packit |
90a5c9 |
const char *sym_name)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
ap_module_symbol_t *sym = ap_prelinked_module_symbols;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* This could be called from a LoadModule httpd.conf command,
|
|
Packit |
90a5c9 |
* after the file has been linked and the module structure within it
|
|
Packit |
90a5c9 |
* teased out...
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (m->version != MODULE_MAGIC_NUMBER_MAJOR) {
|
|
Packit |
90a5c9 |
return apr_psprintf(p, "Module \"%s\" is not compatible with this "
|
|
Packit |
90a5c9 |
"version of Apache (found %d, need %d). Please "
|
|
Packit |
90a5c9 |
"contact the vendor for the correct version.",
|
|
Packit |
90a5c9 |
m->name, m->version, MODULE_MAGIC_NUMBER_MAJOR);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (m->module_index == -1) {
|
|
Packit |
90a5c9 |
if (dynamic_modules >= DYNAMIC_MODULE_LIMIT) {
|
|
Packit |
90a5c9 |
return apr_psprintf(p, "Module \"%s\" could not be loaded, "
|
|
Packit |
90a5c9 |
"because the dynamic module limit was "
|
|
Packit |
90a5c9 |
"reached. Please increase "
|
|
Packit |
90a5c9 |
"DYNAMIC_MODULE_LIMIT and recompile.", m->name);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* If this fails some module forgot to call ap_reserve_module_slots*.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
ap_assert(total_modules < conf_vector_length);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
m->module_index = total_modules++;
|
|
Packit |
90a5c9 |
dynamic_modules++;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (!sym_name) {
|
|
Packit |
90a5c9 |
while (sym->modp != NULL) {
|
|
Packit |
90a5c9 |
if (sym->modp == m) {
|
|
Packit |
90a5c9 |
sym_name = sym->name;
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
sym++;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (m->next == NULL) {
|
|
Packit |
90a5c9 |
m->next = ap_top_module;
|
|
Packit |
90a5c9 |
ap_top_module = m;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (sym_name) {
|
|
Packit |
90a5c9 |
int len = strlen(sym_name);
|
|
Packit |
90a5c9 |
int slen = strlen("_module");
|
|
Packit |
90a5c9 |
if (len > slen && !strcmp(sym_name + len - slen, "_module")) {
|
|
Packit |
90a5c9 |
len -= slen;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ap_module_short_names[m->module_index] = ap_malloc(len + 1);
|
|
Packit |
90a5c9 |
memcpy(ap_module_short_names[m->module_index], sym_name, len);
|
|
Packit |
90a5c9 |
ap_module_short_names[m->module_index][len] = '\0';
|
|
Packit |
90a5c9 |
merger_func_cache[m->module_index] = m->merge_dir_config;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Some C compilers put a complete path into __FILE__, but we want
|
|
Packit |
90a5c9 |
* only the filename (e.g. mod_includes.c). So check for path
|
|
Packit |
90a5c9 |
* components (Unix and DOS), and remove them.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (ap_strrchr_c(m->name, '/'))
|
|
Packit |
90a5c9 |
m->name = 1 + ap_strrchr_c(m->name, '/');
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (ap_strrchr_c(m->name, '\\'))
|
|
Packit |
90a5c9 |
m->name = 1 + ap_strrchr_c(m->name, '\\');
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#ifdef _OSD_POSIX
|
|
Packit |
90a5c9 |
/* __FILE__ =
|
|
Packit |
90a5c9 |
* "*POSIX(/home/martin/apache/src/modules/standard/mod_info.c)"
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* We cannot fix the string in-place, because it's const */
|
|
Packit |
90a5c9 |
if (m->name[strlen(m->name)-1] == ')') {
|
|
Packit |
90a5c9 |
char *tmp = ap_malloc(strlen(m->name)); /* FIXME: memory leak, albeit a small one */
|
|
Packit |
90a5c9 |
memcpy(tmp, m->name, strlen(m->name)-1);
|
|
Packit |
90a5c9 |
tmp[strlen(m->name)-1] = '\0';
|
|
Packit |
90a5c9 |
m->name = tmp;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#endif /*_OSD_POSIX*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ap_add_module_commands(m, p);
|
|
Packit |
90a5c9 |
/* FIXME: is this the right place to call this?
|
|
Packit |
90a5c9 |
* It doesn't appear to be
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
ap_register_hooks(m, p);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* remove_module undoes what add_module did. There are some caveats:
|
|
Packit |
90a5c9 |
* when the module is removed, its slot is lost so all the current
|
|
Packit |
90a5c9 |
* per-dir and per-server configurations are invalid. So we should
|
|
Packit |
90a5c9 |
* only ever call this function when you are invalidating almost
|
|
Packit |
90a5c9 |
* all our current data. I.e. when doing a restart.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_DECLARE(void) ap_remove_module(module *m)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
module *modp;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
modp = ap_top_module;
|
|
Packit |
90a5c9 |
if (modp == m) {
|
|
Packit |
90a5c9 |
/* We are the top module, special case */
|
|
Packit |
90a5c9 |
ap_top_module = modp->next;
|
|
Packit |
90a5c9 |
m->next = NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
/* Not the top module, find use. When found modp will
|
|
Packit |
90a5c9 |
* point to the module _before_ us in the list
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
while (modp && modp->next != m) {
|
|
Packit |
90a5c9 |
modp = modp->next;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!modp) {
|
|
Packit |
90a5c9 |
/* Uh-oh, this module doesn't exist */
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL, APLOGNO(00525)
|
|
Packit |
90a5c9 |
"Cannot remove module %s: not found in module list",
|
|
Packit |
90a5c9 |
m->name);
|
|
Packit |
90a5c9 |
return;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Eliminate us from the module list */
|
|
Packit |
90a5c9 |
modp->next = modp->next->next;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
free(ap_module_short_names[m->module_index]);
|
|
Packit |
90a5c9 |
ap_module_short_names[m->module_index] = NULL;
|
|
Packit |
90a5c9 |
merger_func_cache[m->module_index] = NULL;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
m->module_index = -1; /* simulate being unloaded, should
|
|
Packit |
90a5c9 |
* be unnecessary */
|
|
Packit |
90a5c9 |
dynamic_modules--;
|
|
Packit |
90a5c9 |
total_modules--;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_DECLARE(const char *) ap_add_loaded_module(module *mod, apr_pool_t *p,
|
|
Packit |
90a5c9 |
const char *short_name)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
module **m;
|
|
Packit |
90a5c9 |
const char *error;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Add module pointer to top of chained module list
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
error = ap_add_module(mod, p, short_name);
|
|
Packit |
90a5c9 |
if (error) {
|
|
Packit |
90a5c9 |
return error;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* And module pointer to list of loaded modules
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* Notes: 1. ap_add_module() would already complain if no more space
|
|
Packit |
90a5c9 |
* exists for adding a dynamically loaded module
|
|
Packit |
90a5c9 |
* 2. ap_add_module() accepts double inclusion, so we have
|
|
Packit |
90a5c9 |
* to accept this, too.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
for (m = ap_loaded_modules; *m != NULL; m++)
|
|
Packit |
90a5c9 |
;
|
|
Packit |
90a5c9 |
*m++ = mod;
|
|
Packit |
90a5c9 |
*m = NULL;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_DECLARE(void) ap_remove_loaded_module(module *mod)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
module **m;
|
|
Packit |
90a5c9 |
module **m2;
|
|
Packit |
90a5c9 |
int done;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Remove module pointer from chained module list
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
ap_remove_module(mod);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Remove module pointer from list of loaded modules
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* Note: 1. We cannot determine if the module was successfully
|
|
Packit |
90a5c9 |
* removed by ap_remove_module().
|
|
Packit |
90a5c9 |
* 2. We have not to complain explicitly when the module
|
|
Packit |
90a5c9 |
* is not found because ap_remove_module() did it
|
|
Packit |
90a5c9 |
* for us already.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
for (m = m2 = ap_loaded_modules, done = 0; *m2 != NULL; m2++) {
|
|
Packit |
90a5c9 |
if (*m2 == mod && done == 0)
|
|
Packit |
90a5c9 |
done = 1;
|
|
Packit |
90a5c9 |
else
|
|
Packit |
90a5c9 |
*m++ = *m2;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
*m = NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_DECLARE(const char *) ap_setup_prelinked_modules(process_rec *process)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
module **m;
|
|
Packit |
90a5c9 |
module **m2;
|
|
Packit |
90a5c9 |
const char *error;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
apr_hook_global_pool=process->pconf;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
rebuild_conf_hash(process->pconf, 0);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Initialise total_modules variable and module indices
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
total_modules = 0;
|
|
Packit |
90a5c9 |
for (m = ap_preloaded_modules; *m != NULL; m++)
|
|
Packit |
90a5c9 |
(*m)->module_index = total_modules++;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
max_modules = total_modules + DYNAMIC_MODULE_LIMIT + 1;
|
|
Packit |
90a5c9 |
conf_vector_length = max_modules;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Initialise list of loaded modules and short names
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
ap_loaded_modules = (module **)apr_palloc(process->pool,
|
|
Packit |
90a5c9 |
sizeof(module *) * conf_vector_length);
|
|
Packit |
90a5c9 |
if (!ap_module_short_names)
|
|
Packit |
90a5c9 |
ap_module_short_names = ap_calloc(sizeof(char *), conf_vector_length);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!merger_func_cache)
|
|
Packit |
90a5c9 |
merger_func_cache = ap_calloc(sizeof(merger_func), conf_vector_length);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (ap_loaded_modules == NULL || ap_module_short_names == NULL
|
|
Packit |
90a5c9 |
|| merger_func_cache == NULL)
|
|
Packit |
90a5c9 |
return "Ouch! Out of memory in ap_setup_prelinked_modules()!";
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
for (m = ap_preloaded_modules, m2 = ap_loaded_modules; *m != NULL; )
|
|
Packit |
90a5c9 |
*m2++ = *m++;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
*m2 = NULL;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Initialize chain of linked (=activate) modules
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
for (m = ap_prelinked_modules; *m != NULL; m++) {
|
|
Packit |
90a5c9 |
error = ap_add_module(*m, process->pconf, NULL);
|
|
Packit |
90a5c9 |
if (error) {
|
|
Packit |
90a5c9 |
return error;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
apr_hook_sort_all();
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_DECLARE(const char *) ap_find_module_name(module *m)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
return m->name;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_DECLARE(const char *) ap_find_module_short_name(int module_index)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
if (module_index < 0 || module_index >= conf_vector_length)
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
return ap_module_short_names[module_index];
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_DECLARE(module *) ap_find_linked_module(const char *name)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
module *modp;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
for (modp = ap_top_module; modp; modp = modp->next) {
|
|
Packit |
90a5c9 |
if (strcmp(modp->name, name) == 0)
|
|
Packit |
90a5c9 |
return modp;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*****************************************************************
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* Resource, access, and .htaccess config files now parsed by a common
|
|
Packit |
90a5c9 |
* command loop.
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* Let's begin with the basics; parsing the line and
|
|
Packit |
90a5c9 |
* invoking the function...
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#define AP_MAX_ARGC 64
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static const char *invoke_cmd(const command_rec *cmd, cmd_parms *parms,
|
|
Packit |
90a5c9 |
void *mconfig, const char *args)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
int override_list_ok = 0;
|
|
Packit |
90a5c9 |
char *w, *w2, *w3;
|
|
Packit |
90a5c9 |
const char *errmsg = NULL;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Have we been provided a list of acceptable directives? */
|
|
Packit |
90a5c9 |
if (parms->override_list != NULL) {
|
|
Packit |
90a5c9 |
if (apr_table_get(parms->override_list, cmd->name) != NULL) {
|
|
Packit |
90a5c9 |
override_list_ok = 1;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if ((parms->override & cmd->req_override) == 0 && !override_list_ok) {
|
|
Packit |
90a5c9 |
if (parms->override & NONFATAL_OVERRIDE) {
|
|
Packit |
90a5c9 |
ap_log_perror(APLOG_MARK, APLOG_WARNING, 0, parms->temp_pool,
|
|
Packit |
90a5c9 |
APLOGNO(02295)
|
|
Packit |
90a5c9 |
"%s in .htaccess forbidden by AllowOverride",
|
|
Packit |
90a5c9 |
cmd->name);
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (parms->directive && parms->directive->parent) {
|
|
Packit |
90a5c9 |
return apr_pstrcat(parms->pool, cmd->name, " not allowed in ",
|
|
Packit |
90a5c9 |
parms->directive->parent->directive, ">",
|
|
Packit |
90a5c9 |
" context", NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
return apr_pstrcat(parms->pool, cmd->name,
|
|
Packit |
90a5c9 |
" not allowed here", NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
parms->info = cmd->cmd_data;
|
|
Packit |
90a5c9 |
parms->cmd = cmd;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
switch (cmd->args_how) {
|
|
Packit |
90a5c9 |
case RAW_ARGS:
|
|
Packit |
90a5c9 |
#ifdef RESOLVE_ENV_PER_TOKEN
|
|
Packit |
90a5c9 |
args = ap_resolve_env(parms->pool,args);
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
return cmd->AP_RAW_ARGS(parms, mconfig, args);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
case TAKE_ARGV:
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
char *argv[AP_MAX_ARGC];
|
|
Packit |
90a5c9 |
int argc = 0;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
do {
|
|
Packit |
90a5c9 |
w = ap_getword_conf(parms->pool, &args);
|
|
Packit |
90a5c9 |
if (*w == '\0' && *args == '\0') {
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
argv[argc] = w;
|
|
Packit |
90a5c9 |
argc++;
|
|
Packit |
90a5c9 |
} while (argc < AP_MAX_ARGC && *args != '\0');
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return cmd->AP_TAKE_ARGV(parms, mconfig, argc, argv);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
case NO_ARGS:
|
|
Packit |
90a5c9 |
if (*args != 0)
|
|
Packit |
90a5c9 |
return apr_pstrcat(parms->pool, cmd->name, " takes no arguments",
|
|
Packit |
90a5c9 |
NULL);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return cmd->AP_NO_ARGS(parms, mconfig);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
case TAKE1:
|
|
Packit |
90a5c9 |
w = ap_getword_conf(parms->pool, &args);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (*w == '\0' || *args != 0)
|
|
Packit |
90a5c9 |
return apr_pstrcat(parms->pool, cmd->name, " takes one argument",
|
|
Packit |
90a5c9 |
cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return cmd->AP_TAKE1(parms, mconfig, w);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
case TAKE2:
|
|
Packit |
90a5c9 |
w = ap_getword_conf(parms->pool, &args);
|
|
Packit |
90a5c9 |
w2 = ap_getword_conf(parms->pool, &args);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (*w == '\0' || *w2 == '\0' || *args != 0)
|
|
Packit |
90a5c9 |
return apr_pstrcat(parms->pool, cmd->name, " takes two arguments",
|
|
Packit |
90a5c9 |
cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return cmd->AP_TAKE2(parms, mconfig, w, w2);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
case TAKE12:
|
|
Packit |
90a5c9 |
w = ap_getword_conf(parms->pool, &args);
|
|
Packit |
90a5c9 |
w2 = ap_getword_conf(parms->pool, &args);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (*w == '\0' || *args != 0)
|
|
Packit |
90a5c9 |
return apr_pstrcat(parms->pool, cmd->name, " takes 1-2 arguments",
|
|
Packit |
90a5c9 |
cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return cmd->AP_TAKE2(parms, mconfig, w, *w2 ? w2 : NULL);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
case TAKE3:
|
|
Packit |
90a5c9 |
w = ap_getword_conf(parms->pool, &args);
|
|
Packit |
90a5c9 |
w2 = ap_getword_conf(parms->pool, &args);
|
|
Packit |
90a5c9 |
w3 = ap_getword_conf(parms->pool, &args);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (*w == '\0' || *w2 == '\0' || *w3 == '\0' || *args != 0)
|
|
Packit |
90a5c9 |
return apr_pstrcat(parms->pool, cmd->name, " takes three arguments",
|
|
Packit |
90a5c9 |
cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return cmd->AP_TAKE3(parms, mconfig, w, w2, w3);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
case TAKE23:
|
|
Packit |
90a5c9 |
w = ap_getword_conf(parms->pool, &args);
|
|
Packit |
90a5c9 |
w2 = ap_getword_conf(parms->pool, &args);
|
|
Packit |
90a5c9 |
w3 = *args ? ap_getword_conf(parms->pool, &args) : NULL;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (*w == '\0' || *w2 == '\0' || *args != 0)
|
|
Packit |
90a5c9 |
return apr_pstrcat(parms->pool, cmd->name,
|
|
Packit |
90a5c9 |
" takes two or three arguments",
|
|
Packit |
90a5c9 |
cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return cmd->AP_TAKE3(parms, mconfig, w, w2, w3);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
case TAKE123:
|
|
Packit |
90a5c9 |
w = ap_getword_conf(parms->pool, &args);
|
|
Packit |
90a5c9 |
w2 = *args ? ap_getword_conf(parms->pool, &args) : NULL;
|
|
Packit |
90a5c9 |
w3 = *args ? ap_getword_conf(parms->pool, &args) : NULL;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (*w == '\0' || *args != 0)
|
|
Packit |
90a5c9 |
return apr_pstrcat(parms->pool, cmd->name,
|
|
Packit |
90a5c9 |
" takes one, two or three arguments",
|
|
Packit |
90a5c9 |
cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return cmd->AP_TAKE3(parms, mconfig, w, w2, w3);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
case TAKE13:
|
|
Packit |
90a5c9 |
w = ap_getword_conf(parms->pool, &args);
|
|
Packit |
90a5c9 |
w2 = *args ? ap_getword_conf(parms->pool, &args) : NULL;
|
|
Packit |
90a5c9 |
w3 = *args ? ap_getword_conf(parms->pool, &args) : NULL;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (*w == '\0' || (w2 && *w2 && !w3) || *args != 0)
|
|
Packit |
90a5c9 |
return apr_pstrcat(parms->pool, cmd->name,
|
|
Packit |
90a5c9 |
" takes one or three arguments",
|
|
Packit |
90a5c9 |
cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return cmd->AP_TAKE3(parms, mconfig, w, w2, w3);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
case ITERATE:
|
|
Packit |
90a5c9 |
w = ap_getword_conf(parms->pool, &args);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (*w == '\0')
|
|
Packit |
90a5c9 |
return apr_pstrcat(parms->pool, cmd->name,
|
|
Packit |
90a5c9 |
" requires at least one argument",
|
|
Packit |
90a5c9 |
cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
while (*w != '\0') {
|
|
Packit |
90a5c9 |
errmsg = cmd->AP_TAKE1(parms, mconfig, w);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (errmsg && strcmp(errmsg, DECLINE_CMD) != 0)
|
|
Packit |
90a5c9 |
return errmsg;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
w = ap_getword_conf(parms->pool, &args);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return errmsg;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
case ITERATE2:
|
|
Packit |
90a5c9 |
w = ap_getword_conf(parms->pool, &args);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (*w == '\0' || *args == 0)
|
|
Packit |
90a5c9 |
return apr_pstrcat(parms->pool, cmd->name,
|
|
Packit |
90a5c9 |
" requires at least two arguments",
|
|
Packit |
90a5c9 |
cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
while (*(w2 = ap_getword_conf(parms->pool, &args)) != '\0') {
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
errmsg = cmd->AP_TAKE2(parms, mconfig, w, w2);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (errmsg && strcmp(errmsg, DECLINE_CMD) != 0)
|
|
Packit |
90a5c9 |
return errmsg;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return errmsg;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
case FLAG:
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* This is safe to use temp_pool here, because the 'flag' itself is not
|
|
Packit |
90a5c9 |
* forwarded as-is
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
w = ap_getword_conf(parms->temp_pool, &args);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (*w == '\0' || (strcasecmp(w, "on") && strcasecmp(w, "off")))
|
|
Packit |
90a5c9 |
return apr_pstrcat(parms->pool, cmd->name, " must be On or Off",
|
|
Packit |
90a5c9 |
NULL);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return cmd->AP_FLAG(parms, mconfig, strcasecmp(w, "off") != 0);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
default:
|
|
Packit |
90a5c9 |
return apr_pstrcat(parms->pool, cmd->name,
|
|
Packit |
90a5c9 |
" is improperly configured internally (server bug)",
|
|
Packit |
90a5c9 |
NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_CORE_DECLARE(const command_rec *) ap_find_command(const char *name,
|
|
Packit |
90a5c9 |
const command_rec *cmds)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
while (cmds->name) {
|
|
Packit |
90a5c9 |
if (!strcasecmp(name, cmds->name))
|
|
Packit |
90a5c9 |
return cmds;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
++cmds;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_CORE_DECLARE(const command_rec *) ap_find_command_in_modules(
|
|
Packit |
90a5c9 |
const char *cmd_name, module **mod)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
const command_rec *cmdp;
|
|
Packit |
90a5c9 |
module *modp;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
for (modp = *mod; modp; modp = modp->next) {
|
|
Packit |
90a5c9 |
if (modp->cmds && (cmdp = ap_find_command(cmd_name, modp->cmds))) {
|
|
Packit |
90a5c9 |
*mod = modp;
|
|
Packit |
90a5c9 |
return cmdp;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_CORE_DECLARE(void *) ap_set_config_vectors(server_rec *server,
|
|
Packit |
90a5c9 |
ap_conf_vector_t *section_vector,
|
|
Packit |
90a5c9 |
const char *section,
|
|
Packit |
90a5c9 |
module *mod, apr_pool_t *pconf)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
void *section_config = ap_get_module_config(section_vector, mod);
|
|
Packit |
90a5c9 |
void *server_config = ap_get_module_config(server->module_config, mod);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!section_config && mod->create_dir_config) {
|
|
Packit |
90a5c9 |
/* ### need to fix the create_dir_config functions' prototype... */
|
|
Packit |
90a5c9 |
section_config = (*mod->create_dir_config)(pconf, (char *)section);
|
|
Packit |
90a5c9 |
ap_set_module_config(section_vector, mod, section_config);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!server_config && mod->create_server_config) {
|
|
Packit |
90a5c9 |
server_config = (*mod->create_server_config)(pconf, server);
|
|
Packit |
90a5c9 |
ap_set_module_config(server->module_config, mod, server_config);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return section_config;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static const char *execute_now(char *cmd_line, const char *args,
|
|
Packit |
90a5c9 |
cmd_parms *parms,
|
|
Packit |
90a5c9 |
apr_pool_t *p, apr_pool_t *ptemp,
|
|
Packit |
90a5c9 |
ap_directive_t **sub_tree,
|
|
Packit |
90a5c9 |
ap_directive_t *parent);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static const char *ap_build_config_sub(apr_pool_t *p, apr_pool_t *temp_pool,
|
|
Packit |
90a5c9 |
const char *l, cmd_parms *parms,
|
|
Packit |
90a5c9 |
ap_directive_t **current,
|
|
Packit |
90a5c9 |
ap_directive_t **curr_parent,
|
|
Packit |
90a5c9 |
ap_directive_t **conftree)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
const char *retval = NULL;
|
|
Packit |
90a5c9 |
const char *args;
|
|
Packit |
90a5c9 |
char *cmd_name;
|
|
Packit |
90a5c9 |
ap_directive_t *newdir;
|
|
Packit |
90a5c9 |
module *mod = ap_top_module;
|
|
Packit |
90a5c9 |
const command_rec *cmd;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (*l == '#' || *l == '\0')
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#if RESOLVE_ENV_PER_TOKEN
|
|
Packit |
90a5c9 |
args = l;
|
|
Packit |
90a5c9 |
#else
|
|
Packit |
90a5c9 |
args = ap_resolve_env(temp_pool, l);
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* The first word is the name of a directive. We can safely use the
|
|
Packit |
90a5c9 |
* 'temp_pool' for it. If it matches the name of a known directive, we
|
|
Packit |
90a5c9 |
* can reference the string within the module if needed. Otherwise, we
|
|
Packit |
90a5c9 |
* can still make a copy in the 'p' pool. */
|
|
Packit |
90a5c9 |
cmd_name = ap_getword_conf(temp_pool, &args);
|
|
Packit |
90a5c9 |
if (*cmd_name == '\0') {
|
|
Packit |
90a5c9 |
/* Note: this branch should not occur. An empty line should have
|
|
Packit |
90a5c9 |
* triggered the exit further above.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (cmd_name[1] != '/') {
|
|
Packit |
90a5c9 |
char *lastc = cmd_name + strlen(cmd_name) - 1;
|
|
Packit |
90a5c9 |
if (*lastc == '>') {
|
|
Packit |
90a5c9 |
*lastc = '\0' ;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (cmd_name[0] == '<' && *args == '\0') {
|
|
Packit |
90a5c9 |
args = ">";
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
newdir = apr_pcalloc(p, sizeof(ap_directive_t));
|
|
Packit |
90a5c9 |
newdir->filename = parms->config_file->name;
|
|
Packit |
90a5c9 |
newdir->line_num = parms->config_file->line_number;
|
|
Packit |
90a5c9 |
newdir->args = apr_pstrdup(p, args);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if ((cmd = ap_find_command_in_modules(cmd_name, &mod)) != NULL) {
|
|
Packit |
90a5c9 |
newdir->directive = cmd->name;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (cmd->req_override & EXEC_ON_READ) {
|
|
Packit |
90a5c9 |
ap_directive_t *sub_tree = NULL;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
parms->err_directive = newdir;
|
|
Packit |
90a5c9 |
retval = execute_now(cmd_name, args, parms, p, temp_pool,
|
|
Packit |
90a5c9 |
&sub_tree, *curr_parent);
|
|
Packit |
90a5c9 |
if (*current) {
|
|
Packit |
90a5c9 |
(*current)->next = sub_tree;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
*current = sub_tree;
|
|
Packit |
90a5c9 |
if (*curr_parent) {
|
|
Packit |
90a5c9 |
(*curr_parent)->first_child = (*current);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (*current) {
|
|
Packit |
90a5c9 |
(*current)->parent = (*curr_parent);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (*current) {
|
|
Packit |
90a5c9 |
if (!*conftree) {
|
|
Packit |
90a5c9 |
/* Before walking *current to the end of the list,
|
|
Packit |
90a5c9 |
* set the head to *current.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
*conftree = *current;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
while ((*current)->next != NULL) {
|
|
Packit |
90a5c9 |
(*current) = (*current)->next;
|
|
Packit |
90a5c9 |
(*current)->parent = (*curr_parent);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return retval;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
/* No known directive found? Make a copy of what we have parsed. */
|
|
Packit |
90a5c9 |
newdir->directive = apr_pstrdup(p, cmd_name);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (cmd_name[0] == '<') {
|
|
Packit |
90a5c9 |
if (cmd_name[1] != '/') {
|
|
Packit |
90a5c9 |
(*current) = ap_add_node(curr_parent, *current, newdir, 1);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (*curr_parent == NULL) {
|
|
Packit |
90a5c9 |
parms->err_directive = newdir;
|
|
Packit |
90a5c9 |
return apr_pstrcat(p, cmd_name,
|
|
Packit |
90a5c9 |
" without matching <", cmd_name + 2,
|
|
Packit |
90a5c9 |
" section", NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
char *bracket = cmd_name + strlen(cmd_name) - 1;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (*bracket != '>') {
|
|
Packit |
90a5c9 |
parms->err_directive = newdir;
|
|
Packit |
90a5c9 |
return apr_pstrcat(p, cmd_name,
|
|
Packit |
90a5c9 |
"> directive missing closing '>'", NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
*bracket = '\0';
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (strcasecmp(cmd_name + 2,
|
|
Packit |
90a5c9 |
(*curr_parent)->directive + 1) != 0) {
|
|
Packit |
90a5c9 |
parms->err_directive = newdir;
|
|
Packit |
90a5c9 |
return apr_pstrcat(p, "Expected </",
|
|
Packit |
90a5c9 |
(*curr_parent)->directive + 1, "> but saw ",
|
|
Packit |
90a5c9 |
cmd_name, ">", NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
*bracket = '>';
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* done with this section; move up a level */
|
|
Packit |
90a5c9 |
*current = *curr_parent;
|
|
Packit |
90a5c9 |
*curr_parent = (*current)->parent;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
*current = ap_add_node(curr_parent, *current, newdir, 0);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return retval;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#define VARBUF_INIT_LEN 200
|
|
Packit |
90a5c9 |
#define VARBUF_MAX_LEN (16*1024*1024)
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_DECLARE(const char *) ap_build_cont_config(apr_pool_t *p,
|
|
Packit |
90a5c9 |
apr_pool_t *temp_pool,
|
|
Packit |
90a5c9 |
cmd_parms *parms,
|
|
Packit |
90a5c9 |
ap_directive_t **current,
|
|
Packit |
90a5c9 |
ap_directive_t **curr_parent,
|
|
Packit |
90a5c9 |
char *orig_directive)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
char *bracket;
|
|
Packit |
90a5c9 |
const char *retval;
|
|
Packit |
90a5c9 |
ap_directive_t *sub_tree = NULL;
|
|
Packit |
90a5c9 |
apr_status_t rc;
|
|
Packit |
90a5c9 |
struct ap_varbuf vb;
|
|
Packit |
90a5c9 |
apr_size_t max_len = VARBUF_MAX_LEN;
|
|
Packit |
90a5c9 |
if (p == temp_pool)
|
|
Packit |
90a5c9 |
max_len = HUGE_STRING_LEN; /* lower limit for .htaccess */
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
bracket = apr_pstrcat(temp_pool, orig_directive + 1, ">", NULL);
|
|
Packit |
90a5c9 |
ap_varbuf_init(temp_pool, &vb, VARBUF_INIT_LEN);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
while ((rc = ap_varbuf_cfg_getline(&vb, parms->config_file, max_len))
|
|
Packit |
90a5c9 |
== APR_SUCCESS) {
|
|
Packit |
90a5c9 |
if (!memcmp(vb.buf, "</", 2)
|
|
Packit |
90a5c9 |
&& (strcasecmp(vb.buf + 2, bracket) == 0)
|
|
Packit |
90a5c9 |
&& (*curr_parent == NULL)) {
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
retval = ap_build_config_sub(p, temp_pool, vb.buf, parms, current,
|
|
Packit |
90a5c9 |
curr_parent, &sub_tree);
|
|
Packit |
90a5c9 |
if (retval != NULL)
|
|
Packit |
90a5c9 |
return retval;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (sub_tree == NULL) {
|
|
Packit |
90a5c9 |
sub_tree = *curr_parent;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (sub_tree == NULL) {
|
|
Packit |
90a5c9 |
sub_tree = *current;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
ap_varbuf_free(&vb;;
|
|
Packit |
90a5c9 |
if (rc != APR_EOF && rc != APR_SUCCESS)
|
|
Packit |
90a5c9 |
return ap_pcfg_strerror(temp_pool, parms->config_file, rc);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
*current = sub_tree;
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static const char *ap_walk_config_sub(const ap_directive_t *current,
|
|
Packit |
90a5c9 |
cmd_parms *parms,
|
|
Packit |
90a5c9 |
ap_conf_vector_t *section_vector)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
const command_rec *cmd;
|
|
Packit |
90a5c9 |
ap_mod_list *ml;
|
|
Packit |
90a5c9 |
char *dir = apr_pstrdup(parms->temp_pool, current->directive);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ap_str_tolower(dir);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ml = apr_hash_get(ap_config_hash, dir, APR_HASH_KEY_STRING);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (ml == NULL) {
|
|
Packit |
90a5c9 |
parms->err_directive = current;
|
|
Packit |
90a5c9 |
if (parms->override & NONFATAL_UNKNOWN) {
|
|
Packit |
90a5c9 |
ap_log_perror(APLOG_MARK, APLOG_WARNING, 0, parms->temp_pool,
|
|
Packit |
90a5c9 |
APLOGNO(02296) "Unknown directive %s "
|
|
Packit |
90a5c9 |
"perhaps misspelled or defined by a module "
|
|
Packit |
90a5c9 |
"not included in the server configuration", dir);
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
return apr_pstrcat(parms->pool, "Invalid command '",
|
|
Packit |
90a5c9 |
current->directive,
|
|
Packit |
90a5c9 |
"', perhaps misspelled or defined by a module "
|
|
Packit |
90a5c9 |
"not included in the server configuration",
|
|
Packit |
90a5c9 |
NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
for ( ; ml != NULL; ml = ml->next) {
|
|
Packit |
90a5c9 |
void *dir_config = ap_set_config_vectors(parms->server,
|
|
Packit |
90a5c9 |
section_vector,
|
|
Packit |
90a5c9 |
parms->path,
|
|
Packit |
90a5c9 |
ml->m,
|
|
Packit |
90a5c9 |
parms->pool);
|
|
Packit |
90a5c9 |
const char *retval;
|
|
Packit |
90a5c9 |
cmd = ml->cmd;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Once was enough? */
|
|
Packit |
90a5c9 |
if (cmd->req_override & EXEC_ON_READ) {
|
|
Packit |
90a5c9 |
continue;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
retval = invoke_cmd(cmd, parms, dir_config, current->args);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (retval != NULL && strcmp(retval, DECLINE_CMD) != 0) {
|
|
Packit |
90a5c9 |
/* If the directive in error has already been set, don't
|
|
Packit |
90a5c9 |
* replace it. Otherwise, an error inside a container
|
|
Packit |
90a5c9 |
* will be reported as occurring on the first line of the
|
|
Packit |
90a5c9 |
* container.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (!parms->err_directive) {
|
|
Packit |
90a5c9 |
parms->err_directive = current;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return retval;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_DECLARE(const char *) ap_walk_config(ap_directive_t *current,
|
|
Packit |
90a5c9 |
cmd_parms *parms,
|
|
Packit |
90a5c9 |
ap_conf_vector_t *section_vector)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
ap_conf_vector_t *oldconfig = parms->context;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
parms->context = section_vector;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* scan through all directives, executing each one */
|
|
Packit |
90a5c9 |
for (; current != NULL; current = current->next) {
|
|
Packit |
90a5c9 |
const char *errmsg;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
parms->directive = current;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* actually parse the command and execute the correct function */
|
|
Packit |
90a5c9 |
errmsg = ap_walk_config_sub(current, parms, section_vector);
|
|
Packit |
90a5c9 |
if (errmsg != NULL) {
|
|
Packit |
90a5c9 |
/* restore the context (just in case) */
|
|
Packit |
90a5c9 |
parms->context = oldconfig;
|
|
Packit |
90a5c9 |
return errmsg;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
parms->context = oldconfig;
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_DECLARE(const char *) ap_build_config(cmd_parms *parms,
|
|
Packit |
90a5c9 |
apr_pool_t *p, apr_pool_t *temp_pool,
|
|
Packit |
90a5c9 |
ap_directive_t **conftree)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
ap_directive_t *current = *conftree;
|
|
Packit |
90a5c9 |
ap_directive_t *curr_parent = NULL;
|
|
Packit |
90a5c9 |
const char *errmsg;
|
|
Packit |
90a5c9 |
ap_directive_t **last_ptr = NULL;
|
|
Packit |
90a5c9 |
apr_status_t rc;
|
|
Packit |
90a5c9 |
struct ap_varbuf vb;
|
|
Packit |
90a5c9 |
apr_size_t max_len = VARBUF_MAX_LEN;
|
|
Packit |
90a5c9 |
if (p == temp_pool)
|
|
Packit |
90a5c9 |
max_len = HUGE_STRING_LEN; /* lower limit for .htaccess */
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ap_varbuf_init(temp_pool, &vb, VARBUF_INIT_LEN);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (current != NULL) {
|
|
Packit |
90a5c9 |
/* If we have to traverse the whole tree again for every included
|
|
Packit |
90a5c9 |
* config file, the required time grows as O(n^2) with the number of
|
|
Packit |
90a5c9 |
* files. This can be a significant delay for large configurations.
|
|
Packit |
90a5c9 |
* Therefore we cache a pointer to the last node.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
last_ptr = &(current->last);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (last_ptr && *last_ptr) {
|
|
Packit |
90a5c9 |
current = *last_ptr;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
while (current->next) {
|
|
Packit |
90a5c9 |
current = current->next;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (last_ptr) {
|
|
Packit |
90a5c9 |
/* update cached pointer to last node */
|
|
Packit |
90a5c9 |
*last_ptr = current;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
while ((rc = ap_varbuf_cfg_getline(&vb, parms->config_file, max_len))
|
|
Packit |
90a5c9 |
== APR_SUCCESS) {
|
|
Packit |
90a5c9 |
errmsg = ap_build_config_sub(p, temp_pool, vb.buf, parms,
|
|
Packit |
90a5c9 |
¤t, &curr_parent, conftree);
|
|
Packit |
90a5c9 |
if (errmsg != NULL)
|
|
Packit |
90a5c9 |
return errmsg;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (*conftree == NULL && curr_parent != NULL) {
|
|
Packit |
90a5c9 |
*conftree = curr_parent;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (*conftree == NULL && current != NULL) {
|
|
Packit |
90a5c9 |
*conftree = current;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
ap_varbuf_free(&vb;;
|
|
Packit |
90a5c9 |
if (rc != APR_EOF && rc != APR_SUCCESS)
|
|
Packit |
90a5c9 |
return ap_pcfg_strerror(temp_pool, parms->config_file, rc);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (curr_parent != NULL) {
|
|
Packit |
90a5c9 |
errmsg = "";
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
while (curr_parent != NULL) {
|
|
Packit |
90a5c9 |
errmsg = apr_psprintf(p, "%s%s%s:%u: %s> was not closed.",
|
|
Packit |
90a5c9 |
errmsg,
|
|
Packit |
90a5c9 |
*errmsg == '\0' ? "" : APR_EOL_STR,
|
|
Packit |
90a5c9 |
curr_parent->filename,
|
|
Packit |
90a5c9 |
curr_parent->line_num,
|
|
Packit |
90a5c9 |
curr_parent->directive);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
parms->err_directive = curr_parent;
|
|
Packit |
90a5c9 |
curr_parent = curr_parent->parent;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return errmsg;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Generic command functions...
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_DECLARE_NONSTD(const char *) ap_set_string_slot(cmd_parms *cmd,
|
|
Packit |
90a5c9 |
void *struct_ptr,
|
|
Packit |
90a5c9 |
const char *arg)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
int offset = (int)(long)cmd->info;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
*(const char **)((char *)struct_ptr + offset) = arg;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_DECLARE_NONSTD(const char *) ap_set_int_slot(cmd_parms *cmd,
|
|
Packit |
90a5c9 |
void *struct_ptr,
|
|
Packit |
90a5c9 |
const char *arg)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
char *endptr;
|
|
Packit |
90a5c9 |
char *error_str = NULL;
|
|
Packit |
90a5c9 |
int offset = (int)(long)cmd->info;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
*(int *)((char*)struct_ptr + offset) = strtol(arg, &endptr, 10);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if ((*arg == '\0') || (*endptr != '\0')) {
|
|
Packit |
90a5c9 |
error_str = apr_psprintf(cmd->pool,
|
|
Packit |
90a5c9 |
"Invalid value for directive %s, expected integer",
|
|
Packit |
90a5c9 |
cmd->directive->directive);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return error_str;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_DECLARE_NONSTD(const char *) ap_set_string_slot_lower(cmd_parms *cmd,
|
|
Packit |
90a5c9 |
void *struct_ptr,
|
|
Packit |
90a5c9 |
const char *arg_)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
char *arg = apr_pstrdup(cmd->pool,arg_);
|
|
Packit |
90a5c9 |
int offset = (int)(long)cmd->info;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ap_str_tolower(arg);
|
|
Packit |
90a5c9 |
*(char **)((char *)struct_ptr + offset) = arg;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_DECLARE_NONSTD(const char *) ap_set_flag_slot(cmd_parms *cmd,
|
|
Packit |
90a5c9 |
void *struct_ptr_v, int arg)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
int offset = (int)(long)cmd->info;
|
|
Packit |
90a5c9 |
char *struct_ptr = (char *)struct_ptr_v;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
*(int *)(struct_ptr + offset) = arg ? 1 : 0;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_DECLARE_NONSTD(const char *) ap_set_flag_slot_char(cmd_parms *cmd,
|
|
Packit |
90a5c9 |
void *struct_ptr_v, int arg)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
int offset = (int)(long)cmd->info;
|
|
Packit |
90a5c9 |
char *struct_ptr = (char *)struct_ptr_v;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
*(struct_ptr + offset) = arg ? 1 : 0;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_DECLARE_NONSTD(const char *) ap_set_file_slot(cmd_parms *cmd, void *struct_ptr,
|
|
Packit |
90a5c9 |
const char *arg)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
/* Prepend server_root to relative arg.
|
|
Packit |
90a5c9 |
* This allows most args to be independent of server_root,
|
|
Packit |
90a5c9 |
* so the server can be moved or mirrored with less pain.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
const char *path;
|
|
Packit |
90a5c9 |
int offset = (int)(long)cmd->info;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
path = ap_server_root_relative(cmd->pool, arg);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!path) {
|
|
Packit |
90a5c9 |
return apr_pstrcat(cmd->pool, "Invalid file path ",
|
|
Packit |
90a5c9 |
arg, NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
*(const char **) ((char*)struct_ptr + offset) = path;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_DECLARE_NONSTD(const char *) ap_set_deprecated(cmd_parms *cmd,
|
|
Packit |
90a5c9 |
void *struct_ptr,
|
|
Packit |
90a5c9 |
const char *arg)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
return cmd->cmd->errmsg;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_DECLARE(void) ap_reset_module_loglevels(struct ap_logconf *l, int val)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
if (l->module_levels)
|
|
Packit |
90a5c9 |
memset(l->module_levels, val, conf_vector_length);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_DECLARE(void) ap_set_module_loglevel(apr_pool_t *pool, struct ap_logconf *l,
|
|
Packit |
90a5c9 |
int index, int level)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
if (!l->module_levels) {
|
|
Packit |
90a5c9 |
l->module_levels = apr_palloc(pool, conf_vector_length);
|
|
Packit |
90a5c9 |
if (l->level == APLOG_UNSET) {
|
|
Packit |
90a5c9 |
ap_reset_module_loglevels(l, APLOG_UNSET);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
ap_reset_module_loglevels(l, APLOG_NO_MODULE);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
l->module_levels[index] = level;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*****************************************************************
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* Reading whole config files...
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static cmd_parms default_parms =
|
|
Packit |
90a5c9 |
{NULL, 0, 0, NULL, -1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_DECLARE(char *) ap_server_root_relative(apr_pool_t *p, const char *file)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
char *newpath = NULL;
|
|
Packit |
90a5c9 |
apr_status_t rv;
|
|
Packit |
90a5c9 |
rv = apr_filepath_merge(&newpath, ap_server_root, file,
|
|
Packit |
90a5c9 |
APR_FILEPATH_TRUENAME, p);
|
|
Packit |
90a5c9 |
if (newpath && (rv == APR_SUCCESS || APR_STATUS_IS_EPATHWILD(rv)
|
|
Packit |
90a5c9 |
|| APR_STATUS_IS_ENOENT(rv)
|
|
Packit |
90a5c9 |
|| APR_STATUS_IS_ENOTDIR(rv))) {
|
|
Packit |
90a5c9 |
return newpath;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_DECLARE(char *) ap_runtime_dir_relative(apr_pool_t *p, const char *file)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
char *newpath = NULL;
|
|
Packit |
90a5c9 |
apr_status_t rv;
|
|
Packit |
90a5c9 |
const char *runtime_dir = ap_runtime_dir ? ap_runtime_dir : ap_server_root_relative(p, DEFAULT_REL_RUNTIMEDIR);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
rv = apr_filepath_merge(&newpath, runtime_dir, file,
|
|
Packit |
90a5c9 |
APR_FILEPATH_TRUENAME, p);
|
|
Packit |
90a5c9 |
if (newpath && (rv == APR_SUCCESS || APR_STATUS_IS_EPATHWILD(rv)
|
|
Packit |
90a5c9 |
|| APR_STATUS_IS_ENOENT(rv)
|
|
Packit |
90a5c9 |
|| APR_STATUS_IS_ENOTDIR(rv))) {
|
|
Packit |
90a5c9 |
return newpath;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_DECLARE(const char *) ap_soak_end_container(cmd_parms *cmd, char *directive)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
struct ap_varbuf vb;
|
|
Packit |
90a5c9 |
const char *args;
|
|
Packit |
90a5c9 |
char *cmd_name;
|
|
Packit |
90a5c9 |
apr_status_t rc;
|
|
Packit |
90a5c9 |
apr_size_t max_len = VARBUF_MAX_LEN;
|
|
Packit |
90a5c9 |
if (cmd->pool == cmd->temp_pool)
|
|
Packit |
90a5c9 |
max_len = HUGE_STRING_LEN; /* lower limit for .htaccess */
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ap_varbuf_init(cmd->temp_pool, &vb, VARBUF_INIT_LEN);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
while ((rc = ap_varbuf_cfg_getline(&vb, cmd->config_file, max_len))
|
|
Packit |
90a5c9 |
== APR_SUCCESS) {
|
|
Packit |
90a5c9 |
args = vb.buf;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
cmd_name = ap_getword_conf(cmd->temp_pool, &args);
|
|
Packit |
90a5c9 |
if (cmd_name[0] == '<') {
|
|
Packit |
90a5c9 |
if (cmd_name[1] == '/') {
|
|
Packit |
90a5c9 |
cmd_name[strlen(cmd_name) - 1] = '\0';
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (strcasecmp(cmd_name + 2, directive + 1) != 0) {
|
|
Packit |
90a5c9 |
return apr_pstrcat(cmd->pool, "Expected </",
|
|
Packit |
90a5c9 |
directive + 1, "> but saw ",
|
|
Packit |
90a5c9 |
cmd_name, ">", NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ap_varbuf_free(&vb;;
|
|
Packit |
90a5c9 |
return NULL; /* found end of container */
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
const char *msg;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (*args == '\0' && cmd_name[strlen(cmd_name) - 1] == '>') {
|
|
Packit |
90a5c9 |
cmd_name[strlen(cmd_name) - 1] = '\0';
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if ((msg = ap_soak_end_container(cmd, cmd_name)) != NULL) {
|
|
Packit |
90a5c9 |
return msg;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (rc != APR_EOF && rc != APR_SUCCESS)
|
|
Packit |
90a5c9 |
return ap_pcfg_strerror(cmd->temp_pool, cmd->config_file, rc);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return apr_pstrcat(cmd->pool, "Expected </",
|
|
Packit |
90a5c9 |
directive + 1, "> before end of configuration",
|
|
Packit |
90a5c9 |
NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static const char *execute_now(char *cmd_line, const char *args,
|
|
Packit |
90a5c9 |
cmd_parms *parms,
|
|
Packit |
90a5c9 |
apr_pool_t *p, apr_pool_t *ptemp,
|
|
Packit |
90a5c9 |
ap_directive_t **sub_tree,
|
|
Packit |
90a5c9 |
ap_directive_t *parent)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
const command_rec *cmd;
|
|
Packit |
90a5c9 |
ap_mod_list *ml;
|
|
Packit |
90a5c9 |
char *dir = apr_pstrdup(parms->temp_pool, cmd_line);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ap_str_tolower(dir);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ml = apr_hash_get(ap_config_hash, dir, APR_HASH_KEY_STRING);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (ml == NULL) {
|
|
Packit |
90a5c9 |
return apr_pstrcat(parms->pool, "Invalid command '",
|
|
Packit |
90a5c9 |
cmd_line,
|
|
Packit |
90a5c9 |
"', perhaps misspelled or defined by a module "
|
|
Packit |
90a5c9 |
"not included in the server configuration",
|
|
Packit |
90a5c9 |
NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
for ( ; ml != NULL; ml = ml->next) {
|
|
Packit |
90a5c9 |
const char *retval;
|
|
Packit |
90a5c9 |
cmd = ml->cmd;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
retval = invoke_cmd(cmd, parms, sub_tree, args);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (retval != NULL) {
|
|
Packit |
90a5c9 |
return retval;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* This structure and the following functions are needed for the
|
|
Packit |
90a5c9 |
* table-based config file reading. They are passed to the
|
|
Packit |
90a5c9 |
* cfg_open_custom() routine.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Structure to be passed to cfg_open_custom(): it contains an
|
|
Packit |
90a5c9 |
* index which is incremented from 0 to nelts on each call to
|
|
Packit |
90a5c9 |
* cfg_getline() (which in turn calls arr_elts_getstr())
|
|
Packit |
90a5c9 |
* and an apr_array_header_t pointer for the string array.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
typedef struct {
|
|
Packit |
90a5c9 |
apr_array_header_t *array;
|
|
Packit |
90a5c9 |
int curr_idx;
|
|
Packit |
90a5c9 |
} arr_elts_param_t;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* arr_elts_getstr() returns the next line from the string array. */
|
|
Packit |
90a5c9 |
static apr_status_t arr_elts_getstr(void *buf, apr_size_t bufsiz, void *param)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
arr_elts_param_t *arr_param = (arr_elts_param_t *)param;
|
|
Packit |
90a5c9 |
const char *elt;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* End of array reached? */
|
|
Packit |
90a5c9 |
if (++arr_param->curr_idx > arr_param->array->nelts)
|
|
Packit |
90a5c9 |
return APR_EOF;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* return the line */
|
|
Packit |
90a5c9 |
elt = ((const char **)arr_param->array->elts)[arr_param->curr_idx - 1];
|
|
Packit |
90a5c9 |
if (apr_cpystrn(buf, elt, bufsiz) - (char *)buf >= bufsiz - 1)
|
|
Packit |
90a5c9 |
return APR_ENOSPC;
|
|
Packit |
90a5c9 |
return APR_SUCCESS;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* arr_elts_close(): dummy close routine (makes sure no more lines can be read) */
|
|
Packit |
90a5c9 |
static apr_status_t arr_elts_close(void *param)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
arr_elts_param_t *arr_param = (arr_elts_param_t *)param;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
arr_param->curr_idx = arr_param->array->nelts;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return APR_SUCCESS;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static const char *process_command_config(server_rec *s,
|
|
Packit |
90a5c9 |
apr_array_header_t *arr,
|
|
Packit |
90a5c9 |
ap_directive_t **conftree,
|
|
Packit |
90a5c9 |
apr_pool_t *p,
|
|
Packit |
90a5c9 |
apr_pool_t *ptemp)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
const char *errmsg;
|
|
Packit |
90a5c9 |
cmd_parms parms;
|
|
Packit |
90a5c9 |
arr_elts_param_t arr_parms;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
arr_parms.curr_idx = 0;
|
|
Packit |
90a5c9 |
arr_parms.array = arr;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (ap_config_hash == NULL) {
|
|
Packit |
90a5c9 |
rebuild_conf_hash(s->process->pconf, 1);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
parms = default_parms;
|
|
Packit |
90a5c9 |
parms.pool = p;
|
|
Packit |
90a5c9 |
parms.temp_pool = ptemp;
|
|
Packit |
90a5c9 |
parms.server = s;
|
|
Packit |
90a5c9 |
parms.override = (RSRC_CONF | OR_ALL) & ~(OR_AUTHCFG | OR_LIMIT);
|
|
Packit |
90a5c9 |
parms.override_opts = OPT_ALL | OPT_SYM_OWNER | OPT_MULTI;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
parms.config_file = ap_pcfg_open_custom(p, "-c/-C directives",
|
|
Packit |
90a5c9 |
&arr_parms, NULL,
|
|
Packit |
90a5c9 |
arr_elts_getstr, arr_elts_close);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
errmsg = ap_build_config(&parms, p, ptemp, conftree);
|
|
Packit |
90a5c9 |
ap_cfg_closefile(parms.config_file);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (errmsg) {
|
|
Packit |
90a5c9 |
return apr_pstrcat(p, "Syntax error in -C/-c directive: ", errmsg,
|
|
Packit |
90a5c9 |
NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
typedef struct {
|
|
Packit |
90a5c9 |
const char *fname;
|
|
Packit |
90a5c9 |
} fnames;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static int fname_alphasort(const void *fn1, const void *fn2)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
const fnames *f1 = fn1;
|
|
Packit |
90a5c9 |
const fnames *f2 = fn2;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return strcmp(f1->fname,f2->fname);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/**
|
|
Packit |
90a5c9 |
* Used by -D DUMP_INCLUDES to output the config file "tree".
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
static void dump_config_name(const char *fname, apr_pool_t *p)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
unsigned i, recursion, line_number;
|
|
Packit |
90a5c9 |
void *data;
|
|
Packit |
90a5c9 |
apr_file_t *out = NULL;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
apr_file_open_stdout(&out, p);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* ap_include_sentinel is defined by the core Include directive; use it to
|
|
Packit |
90a5c9 |
* figure out how deep in the stack we are.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
apr_pool_userdata_get(&data, "ap_include_sentinel", p);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (data) {
|
|
Packit |
90a5c9 |
recursion = *(unsigned *)data;
|
|
Packit |
90a5c9 |
} else {
|
|
Packit |
90a5c9 |
recursion = 0;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Indent once for each level. */
|
|
Packit |
90a5c9 |
for (i = 0; i < (recursion + 1); ++i) {
|
|
Packit |
90a5c9 |
apr_file_printf(out, " ");
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* ap_include_lineno is similarly defined to tell us where in the last
|
|
Packit |
90a5c9 |
* config file we were.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
apr_pool_userdata_get(&data, "ap_include_lineno", p);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (data) {
|
|
Packit |
90a5c9 |
line_number = *(unsigned *)data;
|
|
Packit |
90a5c9 |
} else {
|
|
Packit |
90a5c9 |
line_number = 0;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Print the line number and the name of the parsed file. */
|
|
Packit |
90a5c9 |
if (line_number > 0) {
|
|
Packit |
90a5c9 |
apr_file_printf(out, "(%u)", line_number);
|
|
Packit |
90a5c9 |
} else {
|
|
Packit |
90a5c9 |
apr_file_printf(out, "(*)");
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
apr_file_printf(out, " %s\n", fname);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_DECLARE(const char *) ap_process_resource_config(server_rec *s,
|
|
Packit |
90a5c9 |
const char *fname,
|
|
Packit |
90a5c9 |
ap_directive_t **conftree,
|
|
Packit |
90a5c9 |
apr_pool_t *p,
|
|
Packit |
90a5c9 |
apr_pool_t *ptemp)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
ap_configfile_t *cfp;
|
|
Packit |
90a5c9 |
cmd_parms parms;
|
|
Packit |
90a5c9 |
apr_status_t rv;
|
|
Packit |
90a5c9 |
const char *error;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
parms = default_parms;
|
|
Packit |
90a5c9 |
parms.pool = p;
|
|
Packit |
90a5c9 |
parms.temp_pool = ptemp;
|
|
Packit |
90a5c9 |
parms.server = s;
|
|
Packit |
90a5c9 |
parms.override = (RSRC_CONF | OR_ALL) & ~(OR_AUTHCFG | OR_LIMIT);
|
|
Packit |
90a5c9 |
parms.override_opts = OPT_ALL | OPT_SYM_OWNER | OPT_MULTI;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
rv = ap_pcfg_openfile(&cfp, p, fname);
|
|
Packit |
90a5c9 |
if (rv != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
return apr_psprintf(p, "Could not open configuration file %s: %pm",
|
|
Packit |
90a5c9 |
fname, &rv;;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (ap_exists_config_define("DUMP_INCLUDES")) {
|
|
Packit |
90a5c9 |
dump_config_name(fname, p);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
parms.config_file = cfp;
|
|
Packit |
90a5c9 |
error = ap_build_config(&parms, p, ptemp, conftree);
|
|
Packit |
90a5c9 |
ap_cfg_closefile(cfp);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (error) {
|
|
Packit |
90a5c9 |
if (parms.err_directive)
|
|
Packit |
90a5c9 |
return apr_psprintf(p, "Syntax error on line %d of %s: %s",
|
|
Packit |
90a5c9 |
parms.err_directive->line_num,
|
|
Packit |
90a5c9 |
parms.err_directive->filename, error);
|
|
Packit |
90a5c9 |
else
|
|
Packit |
90a5c9 |
return error;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static const char *process_resource_config_nofnmatch(server_rec *s,
|
|
Packit |
90a5c9 |
const char *fname,
|
|
Packit |
90a5c9 |
ap_directive_t **conftree,
|
|
Packit |
90a5c9 |
apr_pool_t *p,
|
|
Packit |
90a5c9 |
apr_pool_t *ptemp,
|
|
Packit |
90a5c9 |
unsigned depth,
|
|
Packit |
90a5c9 |
int optional)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
const char *error;
|
|
Packit |
90a5c9 |
apr_status_t rv;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (ap_is_directory(ptemp, fname)) {
|
|
Packit |
90a5c9 |
apr_dir_t *dirp;
|
|
Packit |
90a5c9 |
apr_finfo_t dirent;
|
|
Packit |
90a5c9 |
int current;
|
|
Packit |
90a5c9 |
apr_array_header_t *candidates = NULL;
|
|
Packit |
90a5c9 |
fnames *fnew;
|
|
Packit |
90a5c9 |
char *path = apr_pstrdup(ptemp, fname);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (++depth > AP_MAX_INCLUDE_DIR_DEPTH) {
|
|
Packit |
90a5c9 |
return apr_psprintf(p, "Directory %s exceeds the maximum include "
|
|
Packit |
90a5c9 |
"directory nesting level of %u. You have "
|
|
Packit |
90a5c9 |
"probably a recursion somewhere.", path,
|
|
Packit |
90a5c9 |
AP_MAX_INCLUDE_DIR_DEPTH);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* first course of business is to grok all the directory
|
|
Packit |
90a5c9 |
* entries here and store 'em away. Recall we need full pathnames
|
|
Packit |
90a5c9 |
* for this.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
rv = apr_dir_open(&dirp, path, ptemp);
|
|
Packit |
90a5c9 |
if (rv != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
return apr_psprintf(p, "Could not open config directory %s: %pm",
|
|
Packit |
90a5c9 |
path, &rv;;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
candidates = apr_array_make(ptemp, 1, sizeof(fnames));
|
|
Packit |
90a5c9 |
while (apr_dir_read(&dirent, APR_FINFO_DIRENT, dirp) == APR_SUCCESS) {
|
|
Packit |
90a5c9 |
/* strip out '.' and '..' */
|
|
Packit |
90a5c9 |
if (strcmp(dirent.name, ".")
|
|
Packit |
90a5c9 |
&& strcmp(dirent.name, "..")) {
|
|
Packit |
90a5c9 |
fnew = (fnames *) apr_array_push(candidates);
|
|
Packit |
90a5c9 |
fnew->fname = ap_make_full_path(ptemp, path, dirent.name);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
apr_dir_close(dirp);
|
|
Packit |
90a5c9 |
if (candidates->nelts != 0) {
|
|
Packit |
90a5c9 |
qsort((void *) candidates->elts, candidates->nelts,
|
|
Packit |
90a5c9 |
sizeof(fnames), fname_alphasort);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Now recurse these... we handle errors and subdirectories
|
|
Packit |
90a5c9 |
* via the recursion, which is nice
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
for (current = 0; current < candidates->nelts; ++current) {
|
|
Packit |
90a5c9 |
fnew = &((fnames *) candidates->elts)[current];
|
|
Packit |
90a5c9 |
error = process_resource_config_nofnmatch(s, fnew->fname,
|
|
Packit |
90a5c9 |
conftree, p, ptemp,
|
|
Packit |
90a5c9 |
depth, optional);
|
|
Packit |
90a5c9 |
if (error) {
|
|
Packit |
90a5c9 |
return error;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (optional) {
|
|
Packit |
90a5c9 |
/* If the optinal flag is set (like for IncludeOptional) we can
|
|
Packit |
90a5c9 |
* tolerate that no file or directory is present and bail out.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
apr_finfo_t finfo;
|
|
Packit |
90a5c9 |
if (apr_stat(&finfo, fname, APR_FINFO_TYPE, ptemp) != APR_SUCCESS
|
|
Packit |
90a5c9 |
|| finfo.filetype == APR_NOFILE)
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return ap_process_resource_config(s, fname, conftree, p, ptemp);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static const char *process_resource_config_fnmatch(server_rec *s,
|
|
Packit |
90a5c9 |
const char *path,
|
|
Packit |
90a5c9 |
const char *fname,
|
|
Packit |
90a5c9 |
ap_directive_t **conftree,
|
|
Packit |
90a5c9 |
apr_pool_t *p,
|
|
Packit |
90a5c9 |
apr_pool_t *ptemp,
|
|
Packit |
90a5c9 |
unsigned depth,
|
|
Packit |
90a5c9 |
int optional)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
const char *rest;
|
|
Packit |
90a5c9 |
apr_status_t rv;
|
|
Packit |
90a5c9 |
apr_dir_t *dirp;
|
|
Packit |
90a5c9 |
apr_finfo_t dirent;
|
|
Packit |
90a5c9 |
apr_array_header_t *candidates = NULL;
|
|
Packit |
90a5c9 |
fnames *fnew;
|
|
Packit |
90a5c9 |
int current;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* find the first part of the filename */
|
|
Packit |
90a5c9 |
rest = ap_strchr_c(fname, '/');
|
|
Packit |
90a5c9 |
if (rest) {
|
|
Packit |
90a5c9 |
fname = apr_pstrmemdup(ptemp, fname, rest - fname);
|
|
Packit |
90a5c9 |
rest++;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* optimisation - if the filename isn't a wildcard, process it directly */
|
|
Packit |
90a5c9 |
if (!apr_fnmatch_test(fname)) {
|
|
Packit |
90a5c9 |
path = ap_make_full_path(ptemp, path, fname);
|
|
Packit |
90a5c9 |
if (!rest) {
|
|
Packit |
90a5c9 |
return process_resource_config_nofnmatch(s, path,
|
|
Packit |
90a5c9 |
conftree, p,
|
|
Packit |
90a5c9 |
ptemp, 0, optional);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
return process_resource_config_fnmatch(s, path, rest,
|
|
Packit |
90a5c9 |
conftree, p,
|
|
Packit |
90a5c9 |
ptemp, 0, optional);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* first course of business is to grok all the directory
|
|
Packit |
90a5c9 |
* entries here and store 'em away. Recall we need full pathnames
|
|
Packit |
90a5c9 |
* for this.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
rv = apr_dir_open(&dirp, path, ptemp);
|
|
Packit |
90a5c9 |
if (rv != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
/* If the directory doesn't exist and the optional flag is set
|
|
Packit |
90a5c9 |
* there is no need to return an error.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (rv == APR_ENOENT && optional) {
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return apr_psprintf(p, "Could not open config directory %s: %pm",
|
|
Packit |
90a5c9 |
path, &rv;;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
candidates = apr_array_make(ptemp, 1, sizeof(fnames));
|
|
Packit |
90a5c9 |
while (apr_dir_read(&dirent, APR_FINFO_DIRENT | APR_FINFO_TYPE, dirp) == APR_SUCCESS) {
|
|
Packit |
90a5c9 |
/* strip out '.' and '..' */
|
|
Packit |
90a5c9 |
if (strcmp(dirent.name, ".")
|
|
Packit |
90a5c9 |
&& strcmp(dirent.name, "..")
|
|
Packit |
90a5c9 |
&& (apr_fnmatch(fname, dirent.name,
|
|
Packit |
90a5c9 |
APR_FNM_PERIOD) == APR_SUCCESS)) {
|
|
Packit |
90a5c9 |
const char *full_path = ap_make_full_path(ptemp, path, dirent.name);
|
|
Packit |
90a5c9 |
/* If matching internal to path, and we happen to match something
|
|
Packit |
90a5c9 |
* other than a directory, skip it
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (rest && (dirent.filetype != APR_DIR)) {
|
|
Packit |
90a5c9 |
continue;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
fnew = (fnames *) apr_array_push(candidates);
|
|
Packit |
90a5c9 |
fnew->fname = full_path;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
apr_dir_close(dirp);
|
|
Packit |
90a5c9 |
if (candidates->nelts != 0) {
|
|
Packit |
90a5c9 |
const char *error;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
qsort((void *) candidates->elts, candidates->nelts,
|
|
Packit |
90a5c9 |
sizeof(fnames), fname_alphasort);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Now recurse these... we handle errors and subdirectories
|
|
Packit |
90a5c9 |
* via the recursion, which is nice
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
for (current = 0; current < candidates->nelts; ++current) {
|
|
Packit |
90a5c9 |
fnew = &((fnames *) candidates->elts)[current];
|
|
Packit |
90a5c9 |
if (!rest) {
|
|
Packit |
90a5c9 |
error = process_resource_config_nofnmatch(s, fnew->fname,
|
|
Packit |
90a5c9 |
conftree, p,
|
|
Packit |
90a5c9 |
ptemp, 0, optional);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
error = process_resource_config_fnmatch(s, fnew->fname, rest,
|
|
Packit |
90a5c9 |
conftree, p,
|
|
Packit |
90a5c9 |
ptemp, 0, optional);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (error) {
|
|
Packit |
90a5c9 |
return error;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!optional) {
|
|
Packit |
90a5c9 |
return apr_psprintf(p, "No matches for the wildcard '%s' in '%s', failing "
|
|
Packit |
90a5c9 |
"(use IncludeOptional if required)", fname, path);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_DECLARE(const char *) ap_process_fnmatch_configs(server_rec *s,
|
|
Packit |
90a5c9 |
const char *fname,
|
|
Packit |
90a5c9 |
ap_directive_t **conftree,
|
|
Packit |
90a5c9 |
apr_pool_t *p,
|
|
Packit |
90a5c9 |
apr_pool_t *ptemp,
|
|
Packit |
90a5c9 |
int optional)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
/* XXX: lstat() won't work on the wildcard pattern...
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* don't require conf/httpd.conf if we have a -C or -c switch */
|
|
Packit |
90a5c9 |
if ((ap_server_pre_read_config->nelts
|
|
Packit |
90a5c9 |
|| ap_server_post_read_config->nelts)
|
|
Packit |
90a5c9 |
&& !(strcmp(fname, ap_server_root_relative(ptemp, SERVER_CONFIG_FILE)))) {
|
|
Packit |
90a5c9 |
apr_finfo_t finfo;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (apr_stat(&finfo, fname, APR_FINFO_LINK | APR_FINFO_TYPE, ptemp) != APR_SUCCESS)
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!apr_fnmatch_test(fname)) {
|
|
Packit |
90a5c9 |
return process_resource_config_nofnmatch(s, fname, conftree, p, ptemp, 0, optional);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
apr_status_t status;
|
|
Packit |
90a5c9 |
const char *rootpath, *filepath = fname;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* locate the start of the directories proper */
|
|
Packit |
90a5c9 |
status = apr_filepath_root(&rootpath, &filepath, APR_FILEPATH_TRUENAME, ptemp);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* we allow APR_SUCCESS and APR_EINCOMPLETE */
|
|
Packit |
90a5c9 |
if (APR_ERELATIVE == status) {
|
|
Packit |
90a5c9 |
return apr_pstrcat(p, "Include must have an absolute path, ", fname, NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (APR_EBADPATH == status) {
|
|
Packit |
90a5c9 |
return apr_pstrcat(p, "Include has a bad path, ", fname, NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* walk the filepath */
|
|
Packit |
90a5c9 |
return process_resource_config_fnmatch(s, rootpath, filepath, conftree, p, ptemp,
|
|
Packit |
90a5c9 |
0, optional);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_DECLARE(int) ap_process_config_tree(server_rec *s,
|
|
Packit |
90a5c9 |
ap_directive_t *conftree,
|
|
Packit |
90a5c9 |
apr_pool_t *p,
|
|
Packit |
90a5c9 |
apr_pool_t *ptemp)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
const char *errmsg;
|
|
Packit |
90a5c9 |
cmd_parms parms;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
parms = default_parms;
|
|
Packit |
90a5c9 |
parms.pool = p;
|
|
Packit |
90a5c9 |
parms.temp_pool = ptemp;
|
|
Packit |
90a5c9 |
parms.server = s;
|
|
Packit |
90a5c9 |
parms.override = (RSRC_CONF | OR_ALL) & ~(OR_AUTHCFG | OR_LIMIT);
|
|
Packit |
90a5c9 |
parms.override_opts = OPT_ALL | OPT_SYM_OWNER | OPT_MULTI;
|
|
Packit |
90a5c9 |
parms.limited = -1;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
errmsg = ap_walk_config(conftree, &parms, s->lookup_defaults);
|
|
Packit |
90a5c9 |
if (errmsg) {
|
|
Packit |
90a5c9 |
if (parms.err_directive)
|
|
Packit |
90a5c9 |
ap_log_perror(APLOG_MARK, APLOG_STARTUP, 0, p, APLOGNO(00526)
|
|
Packit |
90a5c9 |
"Syntax error on line %d of %s:",
|
|
Packit |
90a5c9 |
parms.err_directive->line_num,
|
|
Packit |
90a5c9 |
parms.err_directive->filename);
|
|
Packit |
90a5c9 |
ap_log_perror(APLOG_MARK, APLOG_STARTUP, 0, p, "%s", errmsg);
|
|
Packit |
90a5c9 |
return HTTP_INTERNAL_SERVER_ERROR;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return OK;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
apr_status_t ap_open_htaccess(request_rec *r, const char *dir_name,
|
|
Packit |
90a5c9 |
const char *access_name,
|
|
Packit |
90a5c9 |
ap_configfile_t **conffile,
|
|
Packit |
90a5c9 |
const char **full_name)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
*full_name = ap_make_full_path(r->pool, dir_name, access_name);
|
|
Packit |
90a5c9 |
return ap_pcfg_openfile(conffile, r->pool, *full_name);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_CORE_DECLARE(int) ap_parse_htaccess(ap_conf_vector_t **result,
|
|
Packit |
90a5c9 |
request_rec *r, int override,
|
|
Packit |
90a5c9 |
int override_opts, apr_table_t *override_list,
|
|
Packit |
90a5c9 |
const char *d, const char *access_names)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
ap_configfile_t *f = NULL;
|
|
Packit |
90a5c9 |
cmd_parms parms;
|
|
Packit |
90a5c9 |
const char *filename;
|
|
Packit |
90a5c9 |
const struct htaccess_result *cache;
|
|
Packit |
90a5c9 |
struct htaccess_result *new;
|
|
Packit |
90a5c9 |
ap_conf_vector_t *dc = NULL;
|
|
Packit |
90a5c9 |
apr_status_t status;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* firstly, search cache */
|
|
Packit |
90a5c9 |
for (cache = r->htaccess; cache != NULL; cache = cache->next) {
|
|
Packit |
90a5c9 |
if (cache->override == override && strcmp(cache->dir, d) == 0) {
|
|
Packit |
90a5c9 |
*result = cache->htaccess;
|
|
Packit |
90a5c9 |
return OK;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
parms = default_parms;
|
|
Packit |
90a5c9 |
parms.override = override;
|
|
Packit |
90a5c9 |
parms.override_opts = override_opts;
|
|
Packit |
90a5c9 |
parms.override_list = override_list;
|
|
Packit |
90a5c9 |
parms.pool = r->pool;
|
|
Packit |
90a5c9 |
parms.temp_pool = r->pool;
|
|
Packit |
90a5c9 |
parms.server = r->server;
|
|
Packit |
90a5c9 |
parms.path = apr_pstrdup(r->pool, d);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* loop through the access names and find the first one */
|
|
Packit |
90a5c9 |
while (access_names[0]) {
|
|
Packit |
90a5c9 |
const char *access_name = ap_getword_conf(r->pool, &access_names);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
filename = NULL;
|
|
Packit |
90a5c9 |
status = ap_run_open_htaccess(r, d, access_name, &f, &filename);
|
|
Packit |
90a5c9 |
if (status == APR_SUCCESS) {
|
|
Packit |
90a5c9 |
const char *errmsg;
|
|
Packit |
90a5c9 |
ap_directive_t *temptree = NULL;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
dc = ap_create_per_dir_config(r->pool);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
parms.config_file = f;
|
|
Packit |
90a5c9 |
errmsg = ap_build_config(&parms, r->pool, r->pool, &temptree);
|
|
Packit |
90a5c9 |
if (errmsg == NULL)
|
|
Packit |
90a5c9 |
errmsg = ap_walk_config(temptree, &parms, dc);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ap_cfg_closefile(f);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (errmsg) {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_ALERT, 0, r,
|
|
Packit |
90a5c9 |
"%s: %s", filename, errmsg);
|
|
Packit |
90a5c9 |
return HTTP_INTERNAL_SERVER_ERROR;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
*result = dc;
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
if (!APR_STATUS_IS_ENOENT(status)
|
|
Packit |
90a5c9 |
&& !APR_STATUS_IS_ENOTDIR(status)) {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_CRIT, status, r, APLOGNO(00529)
|
|
Packit |
90a5c9 |
"%s pcfg_openfile: unable to check htaccess file, "
|
|
Packit |
90a5c9 |
"ensure it is readable and that '%s' "
|
|
Packit |
90a5c9 |
"is executable",
|
|
Packit |
90a5c9 |
filename, d);
|
|
Packit |
90a5c9 |
apr_table_setn(r->notes, "error-notes",
|
|
Packit |
90a5c9 |
"Server unable to read htaccess file, denying "
|
|
Packit |
90a5c9 |
"access to be safe");
|
|
Packit |
90a5c9 |
return HTTP_FORBIDDEN;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* cache it */
|
|
Packit |
90a5c9 |
new = apr_palloc(r->pool, sizeof(struct htaccess_result));
|
|
Packit |
90a5c9 |
new->dir = parms.path;
|
|
Packit |
90a5c9 |
new->override = override;
|
|
Packit |
90a5c9 |
new->override_opts = override_opts;
|
|
Packit |
90a5c9 |
new->htaccess = dc;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* add to head of list */
|
|
Packit |
90a5c9 |
new->next = r->htaccess;
|
|
Packit |
90a5c9 |
r->htaccess = new;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return OK;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_CORE_DECLARE(const char *) ap_init_virtual_host(apr_pool_t *p,
|
|
Packit |
90a5c9 |
const char *hostname,
|
|
Packit |
90a5c9 |
server_rec *main_server,
|
|
Packit |
90a5c9 |
server_rec **ps)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
server_rec *s = (server_rec *) apr_pcalloc(p, sizeof(server_rec));
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* TODO: this crap belongs in http_core */
|
|
Packit |
90a5c9 |
s->process = main_server->process;
|
|
Packit |
90a5c9 |
s->server_admin = NULL;
|
|
Packit |
90a5c9 |
s->server_hostname = NULL;
|
|
Packit |
90a5c9 |
s->server_scheme = NULL;
|
|
Packit |
90a5c9 |
s->error_fname = NULL;
|
|
Packit |
90a5c9 |
s->timeout = 0;
|
|
Packit |
90a5c9 |
s->keep_alive_timeout = 0;
|
|
Packit |
90a5c9 |
s->keep_alive = -1;
|
|
Packit |
90a5c9 |
s->keep_alive_max = -1;
|
|
Packit |
90a5c9 |
s->error_log = main_server->error_log;
|
|
Packit |
90a5c9 |
s->log.level = APLOG_UNSET;
|
|
Packit |
90a5c9 |
s->log.module_levels = NULL;
|
|
Packit |
90a5c9 |
/* useful default, otherwise we get a port of 0 on redirects */
|
|
Packit |
90a5c9 |
s->port = main_server->port;
|
|
Packit |
90a5c9 |
s->next = NULL;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
s->is_virtual = 1;
|
|
Packit |
90a5c9 |
s->names = apr_array_make(p, 4, sizeof(char **));
|
|
Packit |
90a5c9 |
s->wild_names = apr_array_make(p, 4, sizeof(char **));
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
s->module_config = create_empty_config(p);
|
|
Packit |
90a5c9 |
s->lookup_defaults = ap_create_per_dir_config(p);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
s->limit_req_line = main_server->limit_req_line;
|
|
Packit |
90a5c9 |
s->limit_req_fieldsize = main_server->limit_req_fieldsize;
|
|
Packit |
90a5c9 |
s->limit_req_fields = main_server->limit_req_fields;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
*ps = s;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return ap_parse_vhost_addrs(p, hostname, s);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_DECLARE(struct ap_logconf *) ap_new_log_config(apr_pool_t *p,
|
|
Packit |
90a5c9 |
const struct ap_logconf *old)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
struct ap_logconf *l = apr_pcalloc(p, sizeof(struct ap_logconf));
|
|
Packit |
90a5c9 |
if (old) {
|
|
Packit |
90a5c9 |
l->level = old->level;
|
|
Packit |
90a5c9 |
if (old->module_levels) {
|
|
Packit |
90a5c9 |
l->module_levels =
|
|
Packit |
90a5c9 |
apr_pmemdup(p, old->module_levels, conf_vector_length);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
l->level = APLOG_UNSET;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return l;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_DECLARE(void) ap_merge_log_config(const struct ap_logconf *old_conf,
|
|
Packit |
90a5c9 |
struct ap_logconf *new_conf)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
if (new_conf->level != APLOG_UNSET) {
|
|
Packit |
90a5c9 |
/* Setting the main loglevel resets all per-module log levels.
|
|
Packit |
90a5c9 |
* I.e. if new->level has been set, we must ignore old->module_levels.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
return;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
new_conf->level = old_conf->level;
|
|
Packit |
90a5c9 |
if (new_conf->module_levels == NULL) {
|
|
Packit |
90a5c9 |
new_conf->module_levels = old_conf->module_levels;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (old_conf->module_levels != NULL) {
|
|
Packit |
90a5c9 |
int i;
|
|
Packit |
90a5c9 |
for (i = 0; i < conf_vector_length; i++) {
|
|
Packit |
90a5c9 |
if (new_conf->module_levels[i] == APLOG_UNSET)
|
|
Packit |
90a5c9 |
new_conf->module_levels[i] = old_conf->module_levels[i];
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_DECLARE(void) ap_fixup_virtual_hosts(apr_pool_t *p, server_rec *main_server)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
server_rec *virt;
|
|
Packit |
90a5c9 |
core_dir_config *dconf =
|
|
Packit |
90a5c9 |
ap_get_core_module_config(main_server->lookup_defaults);
|
|
Packit |
90a5c9 |
dconf->log = &main_server->log;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
for (virt = main_server->next; virt; virt = virt->next) {
|
|
Packit |
90a5c9 |
merge_server_configs(p, main_server->module_config, virt);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
virt->lookup_defaults =
|
|
Packit |
90a5c9 |
ap_merge_per_dir_configs(p, main_server->lookup_defaults,
|
|
Packit |
90a5c9 |
virt->lookup_defaults);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (virt->server_admin == NULL)
|
|
Packit |
90a5c9 |
virt->server_admin = main_server->server_admin;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (virt->timeout == 0)
|
|
Packit |
90a5c9 |
virt->timeout = main_server->timeout;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (virt->keep_alive_timeout == 0)
|
|
Packit |
90a5c9 |
virt->keep_alive_timeout = main_server->keep_alive_timeout;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (virt->keep_alive == -1)
|
|
Packit |
90a5c9 |
virt->keep_alive = main_server->keep_alive;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (virt->keep_alive_max == -1)
|
|
Packit |
90a5c9 |
virt->keep_alive_max = main_server->keep_alive_max;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ap_merge_log_config(&main_server->log, &virt->log);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
dconf = ap_get_core_module_config(virt->lookup_defaults);
|
|
Packit |
90a5c9 |
dconf->log = &virt->log;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* XXX: this is really something that should be dealt with by a
|
|
Packit |
90a5c9 |
* post-config api phase
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
ap_core_reorder_directories(p, virt);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ap_core_reorder_directories(p, main_server);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*****************************************************************
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* Getting *everything* configured...
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void init_config_globals(apr_pool_t *p)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
/* Global virtual host hash bucket pointers. Init to null. */
|
|
Packit |
90a5c9 |
ap_init_vhost_config(p);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static server_rec *init_server_config(process_rec *process, apr_pool_t *p)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
apr_status_t rv;
|
|
Packit |
90a5c9 |
server_rec *s = (server_rec *) apr_pcalloc(p, sizeof(server_rec));
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
apr_file_open_stderr(&s->error_log, p);
|
|
Packit |
90a5c9 |
s->process = process;
|
|
Packit |
90a5c9 |
s->port = 0;
|
|
Packit |
90a5c9 |
s->server_admin = DEFAULT_ADMIN;
|
|
Packit |
90a5c9 |
s->server_hostname = NULL;
|
|
Packit |
90a5c9 |
s->server_scheme = NULL;
|
|
Packit |
90a5c9 |
s->error_fname = DEFAULT_ERRORLOG;
|
|
Packit |
90a5c9 |
s->log.level = DEFAULT_LOGLEVEL;
|
|
Packit |
90a5c9 |
s->log.module_levels = NULL;
|
|
Packit |
90a5c9 |
s->limit_req_line = DEFAULT_LIMIT_REQUEST_LINE;
|
|
Packit |
90a5c9 |
s->limit_req_fieldsize = DEFAULT_LIMIT_REQUEST_FIELDSIZE;
|
|
Packit |
90a5c9 |
s->limit_req_fields = DEFAULT_LIMIT_REQUEST_FIELDS;
|
|
Packit |
90a5c9 |
s->timeout = apr_time_from_sec(DEFAULT_TIMEOUT);
|
|
Packit |
90a5c9 |
s->keep_alive_timeout = apr_time_from_sec(DEFAULT_KEEPALIVE_TIMEOUT);
|
|
Packit |
90a5c9 |
s->keep_alive_max = DEFAULT_KEEPALIVE;
|
|
Packit |
90a5c9 |
s->keep_alive = 1;
|
|
Packit |
90a5c9 |
s->next = NULL;
|
|
Packit |
90a5c9 |
s->addrs = apr_pcalloc(p, sizeof(server_addr_rec));
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* NOT virtual host; don't match any real network interface */
|
|
Packit |
90a5c9 |
rv = apr_sockaddr_info_get(&s->addrs->host_addr,
|
|
Packit |
90a5c9 |
NULL, APR_UNSPEC, 0, 0, p);
|
|
Packit |
90a5c9 |
if (rv != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
/* should we test here for rv being an EAIERR? */
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_CRIT, rv, NULL, APLOGNO(00530)
|
|
Packit |
90a5c9 |
"initialisation: bug or getaddrinfo fail");
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
s->addrs->host_port = 0; /* matches any port */
|
|
Packit |
90a5c9 |
s->addrs->virthost = ""; /* must be non-NULL */
|
|
Packit |
90a5c9 |
s->names = s->wild_names = NULL;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
s->module_config = create_server_config(p, s);
|
|
Packit |
90a5c9 |
s->lookup_defaults = create_default_per_dir_config(p);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return s;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static apr_status_t reset_conf_vector_length(void *dummy)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
reserved_module_slots = 0;
|
|
Packit |
90a5c9 |
conf_vector_length = max_modules;
|
|
Packit |
90a5c9 |
return APR_SUCCESS;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static int conf_vector_length_pre_config(apr_pool_t *pconf, apr_pool_t *plog,
|
|
Packit |
90a5c9 |
apr_pool_t *ptemp)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* We have loaded all modules that are loaded by EXEC_ON_READ directives.
|
|
Packit |
90a5c9 |
* From now on we reduce the size of the config vectors to what we need,
|
|
Packit |
90a5c9 |
* plus what has been reserved (e.g. by mod_perl) for additional modules
|
|
Packit |
90a5c9 |
* loaded later on.
|
|
Packit |
90a5c9 |
* If max_modules is too small, ap_add_module() will abort.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (total_modules + reserved_module_slots < max_modules) {
|
|
Packit |
90a5c9 |
conf_vector_length = total_modules + reserved_module_slots;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
apr_pool_cleanup_register(pconf, NULL, reset_conf_vector_length,
|
|
Packit |
90a5c9 |
apr_pool_cleanup_null);
|
|
Packit |
90a5c9 |
return OK;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_CORE_DECLARE(void) ap_register_config_hooks(apr_pool_t *p)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
ap_hook_pre_config(conf_vector_length_pre_config, NULL, NULL,
|
|
Packit |
90a5c9 |
APR_HOOK_REALLY_LAST);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_DECLARE(server_rec*) ap_read_config(process_rec *process, apr_pool_t *ptemp,
|
|
Packit |
90a5c9 |
const char *filename,
|
|
Packit |
90a5c9 |
ap_directive_t **conftree)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
const char *confname, *error;
|
|
Packit |
90a5c9 |
apr_pool_t *p = process->pconf;
|
|
Packit |
90a5c9 |
server_rec *s = init_server_config(process, p);
|
|
Packit |
90a5c9 |
if (s == NULL) {
|
|
Packit |
90a5c9 |
return s;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
init_config_globals(p);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (ap_exists_config_define("DUMP_INCLUDES")) {
|
|
Packit |
90a5c9 |
apr_file_t *out = NULL;
|
|
Packit |
90a5c9 |
apr_file_open_stdout(&out, p);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Included files will be dumped as the config is walked; print a
|
|
Packit |
90a5c9 |
* header.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
apr_file_printf(out, "Included configuration files:\n");
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* All server-wide config files now have the SAME syntax... */
|
|
Packit |
90a5c9 |
error = process_command_config(s, ap_server_pre_read_config, conftree,
|
|
Packit |
90a5c9 |
p, ptemp);
|
|
Packit |
90a5c9 |
if (error) {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_CRIT, 0, NULL, "%s: %s",
|
|
Packit |
90a5c9 |
ap_server_argv0, error);
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* process_command_config may change the ServerRoot so
|
|
Packit |
90a5c9 |
* compute this config file name afterwards.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
confname = ap_server_root_relative(p, filename);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (!confname) {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_CRIT,
|
|
Packit |
90a5c9 |
APR_EBADPATH, NULL, APLOGNO(00532) "Invalid config file path %s",
|
|
Packit |
90a5c9 |
filename);
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
error = ap_process_resource_config(s, confname, conftree, p, ptemp);
|
|
Packit |
90a5c9 |
if (error) {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_CRIT, 0, NULL,
|
|
Packit |
90a5c9 |
"%s: %s", ap_server_argv0, error);
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
error = ap_check_mpm();
|
|
Packit |
90a5c9 |
if (error) {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_CRIT, 0, NULL, APLOGNO(00534)
|
|
Packit |
90a5c9 |
"%s: Configuration error: %s", ap_server_argv0, error);
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
error = process_command_config(s, ap_server_post_read_config, conftree,
|
|
Packit |
90a5c9 |
p, ptemp);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (error) {
|
|
Packit |
90a5c9 |
ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_CRIT, 0, NULL, "%s: %s",
|
|
Packit |
90a5c9 |
ap_server_argv0, error);
|
|
Packit |
90a5c9 |
return NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return s;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_DECLARE(void) ap_single_module_configure(apr_pool_t *p, server_rec *s,
|
|
Packit |
90a5c9 |
module *m)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
if (m->create_server_config)
|
|
Packit |
90a5c9 |
ap_set_module_config(s->module_config, m,
|
|
Packit |
90a5c9 |
(*m->create_server_config)(p, s));
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (m->create_dir_config)
|
|
Packit |
90a5c9 |
ap_set_module_config(s->lookup_defaults, m,
|
|
Packit |
90a5c9 |
(*m->create_dir_config)(p, NULL));
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_DECLARE(void) ap_run_rewrite_args(process_rec *process)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
module *m;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
for (m = ap_top_module; m; m = m->next) {
|
|
Packit |
90a5c9 |
if (m->rewrite_args) {
|
|
Packit |
90a5c9 |
(*m->rewrite_args)(process);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/********************************************************************
|
|
Packit |
90a5c9 |
* Configuration directives are restricted in terms of where they may
|
|
Packit |
90a5c9 |
* appear in the main configuration files and/or .htaccess files according
|
|
Packit |
90a5c9 |
* to the bitmask req_override in the command_rec structure.
|
|
Packit |
90a5c9 |
* If any of the overrides set in req_override are also allowed in the
|
|
Packit |
90a5c9 |
* context in which the command is read, then the command is allowed.
|
|
Packit |
90a5c9 |
* The context is determined as follows:
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* inside *.conf --> override = (RSRC_CONF|OR_ALL)&~(OR_AUTHCFG|OR_LIMIT);
|
|
Packit |
90a5c9 |
* within <Directory> or <Location> --> override = OR_ALL|ACCESS_CONF;
|
|
Packit |
90a5c9 |
* within .htaccess --> override = AllowOverride for current directory;
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* the result is, well, a rather confusing set of possibilities for when
|
|
Packit |
90a5c9 |
* a particular directive is allowed to be used. This procedure prints
|
|
Packit |
90a5c9 |
* in English where the given (pc) directive can be used.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
static void show_overrides(const command_rec *pc, module *pm)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
int n = 0;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
printf("\tAllowed in *.conf ");
|
|
Packit |
90a5c9 |
if ((pc->req_override & (OR_OPTIONS | OR_FILEINFO | OR_INDEXES))
|
|
Packit |
90a5c9 |
|| ((pc->req_override & RSRC_CONF)
|
|
Packit |
90a5c9 |
&& ((pc->req_override & (ACCESS_CONF | OR_AUTHCFG | OR_LIMIT))))) {
|
|
Packit |
90a5c9 |
printf("anywhere");
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (pc->req_override & RSRC_CONF) {
|
|
Packit |
90a5c9 |
printf("only outside <Directory>, <Files>, <Location>, or <If>");
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
printf("only inside <Directory>, <Files>, <Location>, or <If>");
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Warn if the directive is allowed inside <Directory> or .htaccess
|
|
Packit |
90a5c9 |
* but module doesn't support per-dir configuration
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if ((pc->req_override & (OR_ALL | ACCESS_CONF)) && !pm->create_dir_config)
|
|
Packit |
90a5c9 |
printf(" [no per-dir config]");
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (pc->req_override & OR_ALL) {
|
|
Packit |
90a5c9 |
printf(" and in .htaccess\n\twhen AllowOverride");
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if ((pc->req_override & OR_ALL) == OR_ALL) {
|
|
Packit |
90a5c9 |
printf(" isn't None");
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
printf(" includes ");
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (pc->req_override & OR_AUTHCFG) {
|
|
Packit |
90a5c9 |
if (n++)
|
|
Packit |
90a5c9 |
printf(" or ");
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
printf("AuthConfig");
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (pc->req_override & OR_LIMIT) {
|
|
Packit |
90a5c9 |
if (n++)
|
|
Packit |
90a5c9 |
printf(" or ");
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
printf("Limit");
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (pc->req_override & OR_OPTIONS) {
|
|
Packit |
90a5c9 |
if (n++)
|
|
Packit |
90a5c9 |
printf(" or ");
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
printf("Options");
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (pc->req_override & OR_FILEINFO) {
|
|
Packit |
90a5c9 |
if (n++)
|
|
Packit |
90a5c9 |
printf(" or ");
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
printf("FileInfo");
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (pc->req_override & OR_INDEXES) {
|
|
Packit |
90a5c9 |
if (n++)
|
|
Packit |
90a5c9 |
printf(" or ");
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
printf("Indexes");
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
printf("\n");
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Show the preloaded configuration directives, the help string explaining
|
|
Packit |
90a5c9 |
* the directive arguments, in what module they are handled, and in
|
|
Packit |
90a5c9 |
* what parts of the configuration they are allowed. Used for httpd -L.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
AP_DECLARE(void) ap_show_directives(void)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
const command_rec *pc;
|
|
Packit |
90a5c9 |
int n;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
for (n = 0; ap_loaded_modules[n]; ++n) {
|
|
Packit |
90a5c9 |
for (pc = ap_loaded_modules[n]->cmds; pc && pc->name; ++pc) {
|
|
Packit |
90a5c9 |
printf("%s (%s)\n", pc->name, ap_loaded_modules[n]->name);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (pc->errmsg)
|
|
Packit |
90a5c9 |
printf("\t%s\n", pc->errmsg);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
show_overrides(pc, ap_loaded_modules[n]);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Show the preloaded module names. Used for httpd -l. */
|
|
Packit |
90a5c9 |
AP_DECLARE(void) ap_show_modules(void)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
int n;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
printf("Compiled in modules:\n");
|
|
Packit |
90a5c9 |
for (n = 0; ap_loaded_modules[n]; ++n)
|
|
Packit |
90a5c9 |
printf(" %s\n", ap_loaded_modules[n]->name);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_DECLARE(int) ap_exists_directive(apr_pool_t *p, const char *name)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
char *lname = apr_pstrdup(p, name);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ap_str_tolower(lname);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return ap_config_hash &&
|
|
Packit |
90a5c9 |
apr_hash_get(ap_config_hash, lname, APR_HASH_KEY_STRING) != NULL;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_DECLARE(void *) ap_retained_data_get(const char *key)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
void *retained;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
apr_pool_userdata_get((void *)&retained, key, ap_pglobal);
|
|
Packit |
90a5c9 |
return retained;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_DECLARE(void *) ap_retained_data_create(const char *key, apr_size_t size)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
void *retained;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
retained = apr_pcalloc(ap_pglobal, size);
|
|
Packit |
90a5c9 |
apr_pool_userdata_set((const void *)retained, key, apr_pool_cleanup_null, ap_pglobal);
|
|
Packit |
90a5c9 |
return retained;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static int count_directives_sub(const char *directive, ap_directive_t *current)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
int count = 0;
|
|
Packit |
90a5c9 |
while (current != NULL) {
|
|
Packit |
90a5c9 |
if (current->first_child != NULL)
|
|
Packit |
90a5c9 |
count += count_directives_sub(directive, current->first_child);
|
|
Packit |
90a5c9 |
if (strcasecmp(current->directive, directive) == 0)
|
|
Packit |
90a5c9 |
count++;
|
|
Packit |
90a5c9 |
current = current->next;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return count;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_DECLARE(void) ap_reserve_module_slots(int count)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
reserved_module_slots += count;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_DECLARE(void) ap_reserve_module_slots_directive(const char *directive)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
ap_reserve_module_slots(count_directives_sub(directive, ap_conftree));
|
|
Packit |
90a5c9 |
}
|