/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.
*/
/* * http_config.c: once was auxiliary functions for reading httpd's config * file and converting filenames into a namespace * * Rob McCool * * Wall-to-wall rewrite for Apache... commands which are part of the * server core can now be found next door in "http_core.c". Now contains * general command loop, and functions which do bookkeeping for the new * Apache config stuff (modules and configuration vectors). * * rst *
*/
/* During the course of debugging I expanded this macro out, so * rather than remove all the useful information there is in the * following lines, I'm going to leave it here in case anyone * else finds it useful. * * Ben has looked at it and thinks it correct :) * AP_DECLARE(int) ap_hook_post_config(ap_HOOK_post_config_t *pf, const char * const *aszPre, const char * const *aszSucc, int nOrder) { ap_LINK_post_config_t *pHook;
/* hooks with no args are implemented last, after disabling APR hook probes */ #ifdefined(APR_HOOK_PROBES_ENABLED) #undef APR_HOOK_PROBES_ENABLED #undef APR_HOOK_PROBE_ENTRY #define APR_HOOK_PROBE_ENTRY(ud,ns,name,args) #undef APR_HOOK_PROBE_RETURN #define APR_HOOK_PROBE_RETURN(ud,ns,name,rv,args) #undef APR_HOOK_PROBE_INVOKE #define APR_HOOK_PROBE_INVOKE(ud,ns,name,src,args) #undef APR_HOOK_PROBE_COMPLETE #define APR_HOOK_PROBE_COMPLETE(ud,ns,name,src,rv,args) #undef APR_HOOK_INT_DCL_UD #define APR_HOOK_INT_DCL_UD #endif
AP_IMPLEMENT_HOOK_VOID(optional_fn_retrieve, (void), ())
/**************************************************************** * * We begin with the functions which deal with the linked list * of modules which control just about all of the server operation.
*/
/* total_modules is the number of modules that have been linked * into the server.
*/ staticint total_modules = 0;
/* dynamic_modules is the number of modules that have been added * after the pre-loaded ones have been set up. It shouldn't be larger * than DYNAMIC_MODULE_LIMIT.
*/ staticint dynamic_modules = 0;
/* The maximum possible value for total_modules, i.e. number of static * modules plus DYNAMIC_MODULE_LIMIT.
*/ staticint max_modules = 0;
/* The number of elements we need to alloc for config vectors. Before loading * of dynamic modules, we must be liberal and set this to max_modules. After * loading of dynamic modules, we can trim it down to total_modules. On * restart, reset to max_modules.
*/ staticint conf_vector_length = 0;
/* A list of the merge_dir_config functions of all loaded modules, sorted * by module_index. * Using this list in ap_merge_per_dir_configs() is faster than following * the module->next linked list because of better memory locality (resulting * in better cache usage).
*/ static merger_func *merger_func_cache;
/* maximum nesting level for config directories */ #ifndef AP_MAX_INCLUDE_DIR_DEPTH #define AP_MAX_INCLUDE_DIR_DEPTH (128) #endif
/* Dealing with config vectors. These are associated with per-directory, * per-server, and per-request configuration, and have a void* pointer for * each modules. The nature of the structure pointed to is private to the * module in question... the core doesn't (and can't) know. However, there * are defined interfaces which allow it to create instances of its private * per-directory and per-server structures, and to merge the per-directory * structures of a directory and its subdirectory (producing a new one in * which the defaults applying to the base directory have been properly * overridden).
*/
for (modp = ap_top_module; modp; modp = modp->next) { if (modp->create_server_config)
conf_vector[modp->module_index] = (*modp->create_server_config)(p, s);
}
return (ap_conf_vector_t *)conf_vector;
}
staticvoid merge_server_configs(apr_pool_t *p, ap_conf_vector_t *base,
server_rec *virt)
{ /* Can reuse the 'virt' vector for the spine of it, since we don't * have to deal with the moral equivalent of .htaccess files here...
*/
/* Invoke the filter_init_func for all filters with FILTERS where f->r * matches R. Restricting to a matching R avoids re-running init * functions for filters configured for r->main where r is a
* subrequest. */ staticint invoke_filter_init(request_rec *r, ap_filter_t *filters)
{ while (filters) { if (filters->frec->filter_init_func && filters->r == r) { int result = filters->frec->filter_init_func(filters); if (result != OK) { return result;
}
}
filters = filters->next;
} return OK;
}
/* * The new insert_filter stage makes the most sense here. We only use * it when we are going to run the request, so we must insert filters * if any are available. Since the goal of this phase is to allow all * modules to insert a filter if they want to, this filter returns * void. I just can't see any way that this filter can reasonably * fail, either your modules inserts something or it doesn't. rbb
*/
ap_run_insert_filter(r);
/* Before continuing, allow each filter that is in the two chains to * run their init function to let them do any magic before we could * start generating data.
*/
result = invoke_filter_init(r, r->input_filters); if (result != OK) { return result;
}
result = invoke_filter_init(r, r->output_filters); if (result != OK) { return result;
}
if (!r->handler) { if (r->content_type && AP_REQUEST_IS_TRUSTED_CT(r)) {
handler = r->content_type; if ((p=ap_strchr_c(handler, ';')) != NULL) { char *new_handler = (char *)apr_pmemdup(r->pool, handler,
p - handler + 1); char *p2 = new_handler + (p - handler);
handler = new_handler;
/* exclude media type arguments */ while (p2 > handler && p2[-1] == ' ')
--p2; /* strip trailing spaces */
if (result == DECLINED && r->handler && r->filename) {
ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, APLOGNO(00523) "handler \"%s\" not found for: %s", r->handler, r->filename);
} if ((result != OK) && (result != DONE) && (result != DECLINED) && (result != SUSPENDED)
&& (result != AP_FILTER_ERROR) /* ap_die() knows about this specifically */
&& !ap_is_HTTP_VALID_RESPONSE(result)) { /* If a module is deliberately returning something else * (request_rec in non-HTTP or proprietary extension?) * let it set a note to allow it explicitly. * Otherwise, a return code that is neither reserved nor HTTP * is a bug, as in PR#31759.
*/
ignore = apr_table_get(r->notes, "HTTP_IGNORE_RANGE"); if (!ignore) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00524) "Handler for %s returned invalid result code %d",
r->handler, result);
result = HTTP_INTERNAL_SERVER_ERROR;
}
}
return result == DECLINED ? HTTP_INTERNAL_SERVER_ERROR : result;
}
AP_DECLARE(int) ap_method_is_limited(cmd_parms *cmd, constchar *method)
{ int methnum;
methnum = ap_method_number_of(method);
/* * A method number either hardcoded into apache or * added by a module and registered.
*/ if (methnum != M_INVALID) { return (cmd->limited & (AP_METHOD_BIT << methnum)) ? 1 : 0;
}
return 0; /* not found */
}
AP_DECLARE(void) ap_register_hooks(module *m, apr_pool_t *p)
{ if (m->register_hooks) { if (getenv("SHOW_HOOKS")) {
printf("Registering hooks for %s\n", m->name);
apr_hook_debug_enabled = 1;
}
/* This could be called from a LoadModule httpd.conf command, * after the file has been linked and the module structure within it * teased out...
*/
if (m->version != MODULE_MAGIC_NUMBER_MAJOR) { return apr_psprintf(p, "Module \"%s\" is not compatible with this " "version of Apache (found %d, need %d). Please " "contact the vendor for the correct version.",
m->name, m->version, MODULE_MAGIC_NUMBER_MAJOR);
}
if (m->module_index == -1) { if (dynamic_modules >= DYNAMIC_MODULE_LIMIT) { return apr_psprintf(p, "Module \"%s\" could not be loaded, " "because the dynamic module limit was " "reached. Please increase " "DYNAMIC_MODULE_LIMIT and recompile.", m->name);
} /* * If this fails some module forgot to call ap_reserve_module_slots*.
*/
ap_assert(total_modules < conf_vector_length);
} elseif (!sym_name) { while (sym->modp != NULL) { if (sym->modp == m) {
sym_name = sym->name; break;
}
sym++;
}
}
if (m->next == NULL) {
m->next = ap_top_module;
ap_top_module = m;
}
if (sym_name) { int len = strlen(sym_name); int slen = strlen("_module"); if (len > slen && !strcmp(sym_name + len - slen, "_module")) {
len -= slen;
}
/* Some C compilers put a complete path into __FILE__, but we want * only the filename (e.g. mod_includes.c). So check for path * components (Unix and DOS), and remove them.
*/
if (ap_strrchr_c(m->name, '/'))
m->name = 1 + ap_strrchr_c(m->name, '/');
if (ap_strrchr_c(m->name, '\\'))
m->name = 1 + ap_strrchr_c(m->name, '\\');
/* We cannot fix the string in-place, because it's const */ if (m->name[strlen(m->name)-1] == ')') { char *tmp = ap_malloc(strlen(m->name)); /* FIXME: memory leak, albeit a small one */
memcpy(tmp, m->name, strlen(m->name)-1);
tmp[strlen(m->name)-1] = '\0';
m->name = tmp;
} #endif/*_OSD_POSIX*/
ap_add_module_commands(m, p); /* FIXME: is this the right place to call this? * It doesn't appear to be
*/
ap_register_hooks(m, p);
return NULL;
}
/* * remove_module undoes what add_module did. There are some caveats: * when the module is removed, its slot is lost so all the current * per-dir and per-server configurations are invalid. So we should * only ever call this function when you are invalidating almost * all our current data. I.e. when doing a restart.
*/
modp = ap_top_module; if (modp == m) { /* We are the top module, special case */
ap_top_module = modp->next;
m->next = NULL;
} else { /* Not the top module, find use. When found modp will * point to the module _before_ us in the list
*/
while (modp && modp->next != m) {
modp = modp->next;
}
if (!modp) { /* Uh-oh, this module doesn't exist */
ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL, APLOGNO(00525) "Cannot remove module %s: not found in module list",
m->name); return;
}
/* Eliminate us from the module list */
modp->next = modp->next->next;
}
/* * Add module pointer to top of chained module list
*/
error = ap_add_module(mod, p, short_name); if (error) { return error;
}
/* * And module pointer to list of loaded modules * * Notes: 1. ap_add_module() would already complain if no more space * exists for adding a dynamically loaded module * 2. ap_add_module() accepts double inclusion, so we have * to accept this, too.
*/ for (m = ap_loaded_modules; *m != NULL; m++)
;
*m++ = mod;
*m = NULL;
return NULL;
}
AP_DECLARE(void) ap_remove_loaded_module(module *mod)
{
module **m;
module **m2; int done;
/* * Remove module pointer from chained module list
*/
ap_remove_module(mod);
/* * Remove module pointer from list of loaded modules * * Note: 1. We cannot determine if the module was successfully * removed by ap_remove_module(). * 2. We have not to complain explicitly when the module * is not found because ap_remove_module() did it * for us already.
*/ for (m = m2 = ap_loaded_modules, done = 0; *m2 != NULL; m2++) { if (*m2 == mod && done == 0)
done = 1; else
*m++ = *m2;
}
/* * Initialise list of loaded modules and short names
*/
ap_loaded_modules = (module **)apr_palloc(process->pool, sizeof(module *) * conf_vector_length); if (!ap_module_short_names)
ap_module_short_names = ap_calloc(sizeof(char *), conf_vector_length);
if (!merger_func_cache)
merger_func_cache = ap_calloc(sizeof(merger_func), conf_vector_length);
if (ap_loaded_modules == NULL || ap_module_short_names == NULL
|| merger_func_cache == NULL) return"Ouch! Out of memory in ap_setup_prelinked_modules()!";
for (modp = ap_top_module; modp; modp = modp->next) { if (strcmp(modp->name, name) == 0) return modp;
}
return NULL;
}
/***************************************************************** * * Resource, access, and .htaccess config files now parsed by a common * command loop. * * Let's begin with the basics; parsing the line and * invoking the function...
*/
/* Have we been provided a list of acceptable directives? */ if (parms->override_list != NULL) { if (apr_table_get(parms->override_list, cmd->name) != NULL) {
override_list_ok = 1;
}
}
if ((parms->override & cmd->req_override) == 0 && !override_list_ok) { if (parms->override & NONFATAL_OVERRIDE) {
ap_log_perror(APLOG_MARK, APLOG_WARNING, 0, parms->temp_pool,
APLOGNO(02295) "%s in .htaccess forbidden by AllowOverride",
cmd->name); return NULL;
} elseif (parms->directive && parms->directive->parent) { return apr_pstrcat(parms->pool, cmd->name, " not allowed in ",
parms->directive->parent->directive, ">", " context", NULL);
} else { return apr_pstrcat(parms->pool, cmd->name, " not allowed here", NULL);
}
}
if (*w == '\0' || (w2 && *w2 && !w3) || *args != 0) return apr_pstrcat(parms->pool, cmd->name, " takes one or three arguments",
cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
return cmd->AP_TAKE3(parms, mconfig, w, w2, w3);
case ITERATE:
w = ap_getword_conf(parms->pool, &args);
if (*w == '\0') return apr_pstrcat(parms->pool, cmd->name, " requires at least one argument",
cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
while (*w != '\0') {
errmsg = cmd->AP_TAKE1(parms, mconfig, w);
if (errmsg && strcmp(errmsg, DECLINE_CMD) != 0) return errmsg;
w = ap_getword_conf(parms->pool, &args);
}
return errmsg;
case ITERATE2:
w = ap_getword_conf(parms->pool, &args);
if (*w == '\0' || *args == 0) return apr_pstrcat(parms->pool, cmd->name, " requires at least two arguments",
cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
while (*(w2 = ap_getword_conf(parms->pool, &args)) != '\0') {
errmsg = cmd->AP_TAKE2(parms, mconfig, w, w2);
if (errmsg && strcmp(errmsg, DECLINE_CMD) != 0) return errmsg;
}
return errmsg;
case FLAG: /* * This is safe to use temp_pool here, because the 'flag' itself is not * forwarded as-is
*/
w = ap_getword_conf(parms->temp_pool, &args);
if (*w == '\0' || (ap_cstr_casecmp(w, "on") && ap_cstr_casecmp(w, "off"))) return apr_pstrcat(parms->pool, cmd->name, " must be On or Off",
NULL);
/* The first word is the name of a directive. We can safely use the * 'temp_pool' for it. If it matches the name of a known directive, we * can reference the string within the module if needed. Otherwise, we
* can still make a copy in the 'p' pool. */
cmd_name = ap_getword_conf(temp_pool, &args); if (*cmd_name == '\0') { /* Note: this branch should not occur. An empty line should have * triggered the exit further above.
*/ return NULL;
}
parms->err_directive = newdir;
retval = execute_now(cmd_name, args, parms, p, temp_pool,
&sub_tree, *curr_parent); if (*current) {
(*current)->next = sub_tree;
} else {
*current = sub_tree; if (*curr_parent) {
(*curr_parent)->first_child = (*current);
} if (*current) {
(*current)->parent = (*curr_parent);
}
} if (*current) { if (!*conftree) { /* Before walking *current to the end of the list, * set the head to *current.
*/
*conftree = *current;
} while ((*current)->next != NULL) {
(*current) = (*current)->next;
(*current)->parent = (*curr_parent);
}
} return retval;
}
} else { /* No known directive found? Make a copy of what we have parsed. */
newdir->directive = apr_pstrdup(p, cmd_name);
}
ml = apr_hash_get(ap_config_hash, dir, APR_HASH_KEY_STRING);
if (ml == NULL) {
parms->err_directive = current; if (parms->override & NONFATAL_UNKNOWN) {
ap_log_perror(APLOG_MARK, APLOG_WARNING, 0, parms->temp_pool,
APLOGNO(02296) "Unknown directive %s " "perhaps misspelled or defined by a module " "not included in the server configuration", dir); return NULL;
} else { return apr_pstrcat(parms->pool, "Invalid command '",
current->directive, "', perhaps misspelled or defined by a module " "not included in the server configuration",
NULL);
}
}
for ( ; ml != NULL; ml = ml->next) { void *dir_config = ap_set_config_vectors(parms->server,
section_vector,
parms->path,
ml->m,
parms->pool); constchar *retval;
cmd = ml->cmd;
/* Once was enough? */ if (cmd->req_override & EXEC_ON_READ) { continue;
}
if (retval != NULL && strcmp(retval, DECLINE_CMD) != 0) { /* If the directive in error has already been set, don't * replace it. Otherwise, an error inside a container * will be reported as occurring on the first line of the * container.
*/ if (!parms->err_directive) {
parms->err_directive = current;
} return retval;
}
}
if (current != NULL) { /* If we have to traverse the whole tree again for every included * config file, the required time grows as O(n^2) with the number of * files. This can be a significant delay for large configurations. * Therefore we cache a pointer to the last node.
*/
last_ptr = &(current->last);
if (last_ptr && *last_ptr) {
current = *last_ptr;
}
while (current->next) {
current = current->next;
}
if (last_ptr) { /* update cached pointer to last node */
*last_ptr = current;
}
}
AP_DECLARE_NONSTD(constchar *) ap_set_flag_slot(cmd_parms *cmd, void *struct_ptr_v, int arg)
{ int offset = (int)(long)cmd->info; char *struct_ptr = (char *)struct_ptr_v;
*(int *)(struct_ptr + offset) = arg ? 1 : 0;
return NULL;
}
AP_DECLARE_NONSTD(constchar *) ap_set_flag_slot_char(cmd_parms *cmd, void *struct_ptr_v, int arg)
{ int offset = (int)(long)cmd->info; char *struct_ptr = (char *)struct_ptr_v;
*(struct_ptr + offset) = arg ? 1 : 0;
return NULL;
}
AP_DECLARE_NONSTD(constchar *) ap_set_file_slot(cmd_parms *cmd, void *struct_ptr, constchar *arg)
{ /* Prepend server_root to relative arg. * This allows most args to be independent of server_root, * so the server can be moved or mirrored with less pain.
*/ constchar *path; int offset = (int)(long)cmd->info;
ml = apr_hash_get(ap_config_hash, dir, APR_HASH_KEY_STRING);
if (ml == NULL) { return apr_pstrcat(parms->pool, "Invalid command '",
cmd_line, "', perhaps misspelled or defined by a module " "not included in the server configuration",
NULL);
}
for ( ; ml != NULL; ml = ml->next) { constchar *retval;
cmd = ml->cmd;
retval = invoke_cmd(cmd, parms, sub_tree, args);
if (retval != NULL) { return retval;
}
}
return NULL;
}
/* This structure and the following functions are needed for the * table-based config file reading. They are passed to the * cfg_open_custom() routine.
*/
/* Structure to be passed to cfg_open_custom(): it contains an * index which is incremented from 0 to nelts on each call to * cfg_getline() (which in turn calls arr_elts_getstr()) * and an apr_array_header_t pointer for the string array.
*/ typedefstruct {
apr_array_header_t *array; int curr_idx;
} arr_elts_param_t;
/* arr_elts_getstr() returns the next line from the string array. */ static apr_status_t arr_elts_getstr(void *buf, apr_size_t bufsiz, void *param)
{
arr_elts_param_t *arr_param = (arr_elts_param_t *)param; constchar *elt;
/* End of array reached? */ if (++arr_param->curr_idx > arr_param->array->nelts) return APR_EOF;
/* return the line */
elt = ((constchar **)arr_param->array->elts)[arr_param->curr_idx - 1]; if (apr_cpystrn(buf, elt, bufsiz) - (char *)buf >= bufsiz - 1) return APR_ENOSPC; return APR_SUCCESS;
}
/* arr_elts_close(): dummy close routine (makes sure no more lines can be read) */ static apr_status_t arr_elts_close(void *param)
{
arr_elts_param_t *arr_param = (arr_elts_param_t *)param;
if (errmsg) { return apr_pstrcat(p, "Syntax error in -C/-c directive: ", errmsg,
NULL);
}
return NULL;
}
/** * Used by -D DUMP_INCLUDES to output the config file "tree".
*/ staticvoid dump_config_name(constchar *fname, apr_pool_t *p)
{ unsigned i, recursion, line_number; void *data;
apr_file_t *out = NULL;
apr_file_open_stdout(&out, p);
/* ap_include_sentinel is defined by the core Include directive; use it to * figure out how deep in the stack we are.
*/
apr_pool_userdata_get(&data, "ap_include_sentinel", p);
/* Print the line number and the name of the parsed file. */ if (line_number > 0) {
apr_file_printf(out, "(%u)", line_number);
} else {
apr_file_printf(out, "(*)");
}
if (error) { if (parms.err_directive) return apr_psprintf(p, "Syntax error on line %d of %s: %s",
parms.err_directive->line_num,
parms.err_directive->filename, error); else return error;
}
/* don't require conf/httpd.conf if we have a -C or -c switch */ if ((ap_server_pre_read_config->nelts
|| ap_server_post_read_config->nelts)
&& !(strcmp(fname, ap_server_root_relative(ptemp, SERVER_CONFIG_FILE)))) {
apr_finfo_t finfo;
/* locate the start of the directories proper */
status = apr_filepath_root(&rootpath, &filepath, APR_FILEPATH_TRUENAME, ptemp);
/* we allow APR_SUCCESS and APR_EINCOMPLETE */ if (APR_ERELATIVE == status) { return apr_pstrcat(p, "Include must have an absolute path, ", fname, NULL);
} elseif (APR_EBADPATH == status) { return apr_pstrcat(p, "Include has a bad path, ", fname, NULL);
}
/* walk the filepath */ return ap_dir_fnmatch(&w, rootpath, filepath);
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.