http_core.c revision 7646be5b9ab5b098bc81d3a08a47e1931dc87597
1982fbecb99335961659b9961d47f2425bf142abgryzor/* ====================================================================
1982fbecb99335961659b9961d47f2425bf142abgryzor * The Apache Software License, Version 1.1
a99c5d4cc3cab6a62b04d52000dbc22ce1fa2d94coar * Copyright (c) 2000 The Apache Software Foundation. All rights
1982fbecb99335961659b9961d47f2425bf142abgryzor * reserved.
1982fbecb99335961659b9961d47f2425bf142abgryzor * Redistribution and use in source and binary forms, with or without
1982fbecb99335961659b9961d47f2425bf142abgryzor * modification, are permitted provided that the following conditions
1982fbecb99335961659b9961d47f2425bf142abgryzor * 1. Redistributions of source code must retain the above copyright
1982fbecb99335961659b9961d47f2425bf142abgryzor * notice, this list of conditions and the following disclaimer.
1982fbecb99335961659b9961d47f2425bf142abgryzor * 2. Redistributions in binary form must reproduce the above copyright
1982fbecb99335961659b9961d47f2425bf142abgryzor * notice, this list of conditions and the following disclaimer in
1982fbecb99335961659b9961d47f2425bf142abgryzor * the documentation and/or other materials provided with the
1982fbecb99335961659b9961d47f2425bf142abgryzor * distribution.
1982fbecb99335961659b9961d47f2425bf142abgryzor * 3. The end-user documentation included with the redistribution,
1982fbecb99335961659b9961d47f2425bf142abgryzor * if any, must include the following acknowledgment:
1982fbecb99335961659b9961d47f2425bf142abgryzor * "This product includes software developed by the
1982fbecb99335961659b9961d47f2425bf142abgryzor * Apache Software Foundation (http://www.apache.org/)."
1982fbecb99335961659b9961d47f2425bf142abgryzor * Alternately, this acknowledgment may appear in the software itself,
1982fbecb99335961659b9961d47f2425bf142abgryzor * if and wherever such third-party acknowledgments normally appear.
1982fbecb99335961659b9961d47f2425bf142abgryzor * 4. The names "Apache" and "Apache Software Foundation" must
1982fbecb99335961659b9961d47f2425bf142abgryzor * not be used to endorse or promote products derived from this
1982fbecb99335961659b9961d47f2425bf142abgryzor * software without prior written permission. For written
1982fbecb99335961659b9961d47f2425bf142abgryzor * permission, please contact apache@apache.org.
1982fbecb99335961659b9961d47f2425bf142abgryzor * 5. Products derived from this software may not be called "Apache",
1982fbecb99335961659b9961d47f2425bf142abgryzor * nor may "Apache" appear in their name, without prior written
1982fbecb99335961659b9961d47f2425bf142abgryzor * permission of the Apache Software Foundation.
1982fbecb99335961659b9961d47f2425bf142abgryzor * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
1982fbecb99335961659b9961d47f2425bf142abgryzor * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1982fbecb99335961659b9961d47f2425bf142abgryzor * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1ef910e5e65cfbfc2455c230d8ddd6453a31a427lgentis * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
1ef910e5e65cfbfc2455c230d8ddd6453a31a427lgentis * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
1982fbecb99335961659b9961d47f2425bf142abgryzor * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
1982fbecb99335961659b9961d47f2425bf142abgryzor * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
1982fbecb99335961659b9961d47f2425bf142abgryzor * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
1982fbecb99335961659b9961d47f2425bf142abgryzor * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
1982fbecb99335961659b9961d47f2425bf142abgryzor * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
1982fbecb99335961659b9961d47f2425bf142abgryzor * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
1982fbecb99335961659b9961d47f2425bf142abgryzor * SUCH DAMAGE.
1982fbecb99335961659b9961d47f2425bf142abgryzor * ====================================================================
1982fbecb99335961659b9961d47f2425bf142abgryzor * This software consists of voluntary contributions made by many
1982fbecb99335961659b9961d47f2425bf142abgryzor * individuals on behalf of the Apache Software Foundation. For more
1982fbecb99335961659b9961d47f2425bf142abgryzor * information on the Apache Software Foundation, please see
1982fbecb99335961659b9961d47f2425bf142abgryzor * Portions of this software are based upon public domain software
1982fbecb99335961659b9961d47f2425bf142abgryzor * originally written at the National Center for Supercomputing Applications,
1982fbecb99335961659b9961d47f2425bf142abgryzor * University of Illinois, Urbana-Champaign.
1982fbecb99335961659b9961d47f2425bf142abgryzor#include "http_protocol.h" /* For index_of_response(). Grump. */
1982fbecb99335961659b9961d47f2425bf142abgryzor#include "http_main.h" /* For the default_handler below... */
1982fbecb99335961659b9961d47f2425bf142abgryzor/* Make sure we don't write less than 4096 bytes at any one time.
1982fbecb99335961659b9961d47f2425bf142abgryzor/* Allow Apache to use ap_mmap */
1982fbecb99335961659b9961d47f2425bf142abgryzor/* mmap support for static files based on ideas from John Heidemann's
1982fbecb99335961659b9961d47f2425bf142abgryzor * patch against 1.0.5. See
1982fbecb99335961659b9961d47f2425bf142abgryzor * <http://www.isi.edu/~johnh/SOFTWARE/APACHE/index.html>.
1982fbecb99335961659b9961d47f2425bf142abgryzor/* Files have to be at least this big before they're mmap()d. This is to deal
1982fbecb99335961659b9961d47f2425bf142abgryzor * with systems where the expense of doing an mmap() and an munmap() outweighs
1982fbecb99335961659b9961d47f2425bf142abgryzor * the benefit for small files. It shouldn't be set lower than 1.
1982fbecb99335961659b9961d47f2425bf142abgryzor #endif /* SUNOS4 */
1982fbecb99335961659b9961d47f2425bf142abgryzor#endif /* MMAP_THRESHOLD */
1982fbecb99335961659b9961d47f2425bf142abgryzor#endif /* AP_USE_MMAP_FILES */
1982fbecb99335961659b9961d47f2425bf142abgryzor/* LimitXMLRequestBody handling */
1982fbecb99335961659b9961d47f2425bf142abgryzor/* Server core module... This module provides support for really basic
1982fbecb99335961659b9961d47f2425bf142abgryzor * server operations, including options and commands which control the
1982fbecb99335961659b9961d47f2425bf142abgryzor * operation of other modules. Consider this the bureaucracy module.
1982fbecb99335961659b9961d47f2425bf142abgryzor * The core module also defines handlers, etc., do handle just enough
1982fbecb99335961659b9961d47f2425bf142abgryzor * to allow a server with the core module ONLY to actually serve documents
1982fbecb99335961659b9961d47f2425bf142abgryzor * (though it slaps DefaultType on all of 'em); this was useful in testing,
1982fbecb99335961659b9961d47f2425bf142abgryzor * but may not be worth preserving.
1982fbecb99335961659b9961d47f2425bf142abgryzor * This file could almost be mod_core.c, except for the stuff which affects
1982fbecb99335961659b9961d47f2425bf142abgryzor * the http_conf_globals.
1982fbecb99335961659b9961d47f2425bf142abgryzorstatic void *create_core_dir_config(apr_pool_t *a, char *dir)
1982fbecb99335961659b9961d47f2425bf142abgryzor conf = (core_dir_config *)apr_pcalloc(a, sizeof(core_dir_config));
1982fbecb99335961659b9961d47f2425bf142abgryzor conf->d_is_fnmatch = conf->d ? (apr_is_fnmatch(conf->d) != 0) : 0;
1982fbecb99335961659b9961d47f2425bf142abgryzor conf->d_components = conf->d ? ap_count_dirs(conf->d) : 0;
1982fbecb99335961659b9961d47f2425bf142abgryzor conf->do_rfc1413 = DEFAULT_RFC1413 | 2; /* set bit 1 to indicate default */
1982fbecb99335961659b9961d47f2425bf142abgryzor#if defined(RLIMIT_DATA) || defined(RLIMIT_VMEM) || defined(RLIMIT_AS)
1982fbecb99335961659b9961d47f2425bf142abgryzor conf->script_interpreter_source = INTERPRETER_SOURCE_UNSET;
1982fbecb99335961659b9961d47f2425bf142abgryzor conf->add_default_charset = ADD_DEFAULT_CHARSET_UNSET;
1982fbecb99335961659b9961d47f2425bf142abgryzor conf->add_default_charset_name = DEFAULT_ADD_DEFAULT_CHARSET_NAME;
1982fbecb99335961659b9961d47f2425bf142abgryzor conf->output_filters = apr_make_array(a, 2, sizeof(void *));
1982fbecb99335961659b9961d47f2425bf142abgryzor conf->input_filters = apr_make_array(a, 2, sizeof(void *));
1982fbecb99335961659b9961d47f2425bf142abgryzor return (void *)conf;
1982fbecb99335961659b9961d47f2425bf142abgryzorstatic void *merge_core_dir_configs(apr_pool_t *a, void *basev, void *newv)
1982fbecb99335961659b9961d47f2425bf142abgryzor conf = (core_dir_config *)apr_palloc(a, sizeof(core_dir_config));
1982fbecb99335961659b9961d47f2425bf142abgryzor memcpy((char *)conf, (const char *)base, sizeof(core_dir_config));
1982fbecb99335961659b9961d47f2425bf142abgryzor memcpy(conf->response_code_strings, base->response_code_strings,
1982fbecb99335961659b9961d47f2425bf142abgryzor sizeof(*conf->response_code_strings) * RESPONSE_CODES);
1982fbecb99335961659b9961d47f2425bf142abgryzor /* there was no explicit setting of new->opts, so we merge
06e80fa0dffc17ae61bca1715c96e08ea90d53cblgentis * preserve the invariant (opts_add & opts_remove) == 0
06e80fa0dffc17ae61bca1715c96e08ea90d53cblgentis conf->opts_add = (conf->opts_add & ~new->opts_remove) | new->opts_add;
06e80fa0dffc17ae61bca1715c96e08ea90d53cblgentis conf->opts_remove = (conf->opts_remove & ~new->opts_add)
1982fbecb99335961659b9961d47f2425bf142abgryzor conf->opts = (conf->opts & ~conf->opts_remove) | conf->opts_add;
1982fbecb99335961659b9961d47f2425bf142abgryzor if ((base->opts & OPT_INCNOEXEC) && (new->opts & OPT_INCLUDES)) {
1982fbecb99335961659b9961d47f2425bf142abgryzor conf->opts = (conf->opts & ~OPT_INCNOEXEC) | OPT_INCLUDES;
1982fbecb99335961659b9961d47f2425bf142abgryzor /* otherwise we just copy, because an explicit opts setting
1982fbecb99335961659b9961d47f2425bf142abgryzor * overrides all earlier +/- modifiers
1982fbecb99335961659b9961d47f2425bf142abgryzor sizeof(*conf->response_code_strings) * RESPONSE_CODES);
1982fbecb99335961659b9961d47f2425bf142abgryzor memcpy(conf->response_code_strings, new->response_code_strings,
1982fbecb99335961659b9961d47f2425bf142abgryzor sizeof(*conf->response_code_strings) * RESPONSE_CODES);
1982fbecb99335961659b9961d47f2425bf142abgryzor for (i = 0; i < RESPONSE_CODES; ++i) {
1982fbecb99335961659b9961d47f2425bf142abgryzor if (new->hostname_lookups != HOSTNAME_LOOKUP_UNSET) {
06e80fa0dffc17ae61bca1715c96e08ea90d53cblgentis if (new->use_canonical_name != USE_CANONICAL_NAME_UNSET) {
1982fbecb99335961659b9961d47f2425bf142abgryzor#if defined(RLIMIT_DATA) || defined(RLIMIT_VMEM) || defined(RLIMIT_AS)
1982fbecb99335961659b9961d47f2425bf142abgryzor conf->sec = apr_append_arrays(a, base->sec, new->sec);
1982fbecb99335961659b9961d47f2425bf142abgryzor if (new->script_interpreter_source != INTERPRETER_SOURCE_UNSET) {
1982fbecb99335961659b9961d47f2425bf142abgryzor conf->script_interpreter_source = new->script_interpreter_source;
2f44538c88c5310bebb17a39b171487315a45624lgentis if (new->add_default_charset != ADD_DEFAULT_CHARSET_UNSET) {
2f44538c88c5310bebb17a39b171487315a45624lgentis conf->add_default_charset = new->add_default_charset;
1982fbecb99335961659b9961d47f2425bf142abgryzor conf->add_default_charset_name = new->add_default_charset_name;
1982fbecb99335961659b9961d47f2425bf142abgryzor conf->output_filters = apr_append_arrays(a, base->output_filters,
1982fbecb99335961659b9961d47f2425bf142abgryzor conf->input_filters = apr_append_arrays(a, base->input_filters,
1982fbecb99335961659b9961d47f2425bf142abgryzor return (void*)conf;
1982fbecb99335961659b9961d47f2425bf142abgryzorstatic void *create_core_server_config(apr_pool_t *a, server_rec *s)
00ce3c4e13e755c33b63f45c5d3ae69eccd977b1lgentis conf = (core_server_config *)apr_pcalloc(a, sizeof(core_server_config));
00ce3c4e13e755c33b63f45c5d3ae69eccd977b1lgentis conf->access_name = is_virtual ? NULL : DEFAULT_ACCESS_FNAME;
00ce3c4e13e755c33b63f45c5d3ae69eccd977b1lgentis conf->ap_document_root = is_virtual ? NULL : DOCUMENT_LOCATION;
1982fbecb99335961659b9961d47f2425bf142abgryzor conf->sec_url = apr_make_array(a, 40, sizeof(void *));
1982fbecb99335961659b9961d47f2425bf142abgryzor return (void *)conf;
1982fbecb99335961659b9961d47f2425bf142abgryzorstatic void *merge_core_server_configs(apr_pool_t *p, void *basev, void *virtv)
1982fbecb99335961659b9961d47f2425bf142abgryzor core_server_config *base = (core_server_config *)basev;
1982fbecb99335961659b9961d47f2425bf142abgryzor core_server_config *virt = (core_server_config *)virtv;
1982fbecb99335961659b9961d47f2425bf142abgryzor conf = (core_server_config *)apr_pcalloc(p, sizeof(core_server_config));
fb25b82560b7fcaffa006cb4738d86acc561b6f4lgentis conf->sec = apr_append_arrays(p, base->sec, virt->sec);
fb25b82560b7fcaffa006cb4738d86acc561b6f4lgentis conf->sec_url = apr_append_arrays(p, base->sec_url, virt->sec_url);
1982fbecb99335961659b9961d47f2425bf142abgryzor/* Add per-directory configuration entry (for <directory> section);
1982fbecb99335961659b9961d47f2425bf142abgryzor * these are part of the core server config.
1982fbecb99335961659b9961d47f2425bf142abgryzorAP_CORE_DECLARE(void) ap_add_per_dir_conf(server_rec *s, void *dir_config)
fb25b82560b7fcaffa006cb4738d86acc561b6f4lgentis core_server_config *sconf = ap_get_module_config(s->module_config,
fb25b82560b7fcaffa006cb4738d86acc561b6f4lgentis void **new_space = (void **)apr_push_array(sconf->sec);
06e80fa0dffc17ae61bca1715c96e08ea90d53cblgentisAP_CORE_DECLARE(void) ap_add_per_url_conf(server_rec *s, void *url_config)
06e80fa0dffc17ae61bca1715c96e08ea90d53cblgentis core_server_config *sconf = ap_get_module_config(s->module_config,
1982fbecb99335961659b9961d47f2425bf142abgryzor void **new_space = (void **)apr_push_array(sconf->sec_url);
1982fbecb99335961659b9961d47f2425bf142abgryzorAP_CORE_DECLARE(void) ap_add_file_conf(core_dir_config *conf, void *url_config)
1982fbecb99335961659b9961d47f2425bf142abgryzor void **new_space = (void **)apr_push_array(conf->sec);
1982fbecb99335961659b9961d47f2425bf142abgryzor/* core_reorder_directories reorders the directory sections such that the
1982fbecb99335961659b9961d47f2425bf142abgryzor * 1-component sections come first, then the 2-component, and so on, finally
1982fbecb99335961659b9961d47f2425bf142abgryzor * followed by the "special" sections. A section is "special" if it's a regex,
1982fbecb99335961659b9961d47f2425bf142abgryzor * or if it doesn't start with / -- consider proxy: matching. All movements
1982fbecb99335961659b9961d47f2425bf142abgryzor * are in-order to preserve the ordering of the sections from the config files.
1982fbecb99335961659b9961d47f2425bf142abgryzor * See directory_walk().
fb25b82560b7fcaffa006cb4738d86acc561b6f4lgentis || ((entry_core)->d[0] != '/' && (entry_core)->d[1] != ':'))
1982fbecb99335961659b9961d47f2425bf142abgryzor/* XXX: Fairly certain this is correct... '/' must prefix the path
1982fbecb99335961659b9961d47f2425bf142abgryzor * or else in the case xyz:/ or abc/xyz:/, '/' must follow the ':'.
1982fbecb99335961659b9961d47f2425bf142abgryzor * If there is no leading '/' or embedded ':/', then we are special.
1982fbecb99335961659b9961d47f2425bf142abgryzor ((entry_core)->r != NULL || (entry_core)->d[0] != '/')
1982fbecb99335961659b9961d47f2425bf142abgryzor/* We need to do a stable sort, qsort isn't stable. So to make it stable
1982fbecb99335961659b9961d47f2425bf142abgryzor * we'll be maintaining the original index into the list, and using it
1982fbecb99335961659b9961d47f2425bf142abgryzor * as the minor key during sorting. The major key is the number of
1982fbecb99335961659b9961d47f2425bf142abgryzor * components (where a "special" section has infinite components).
1982fbecb99335961659b9961d47f2425bf142abgryzorstatic int reorder_sorter(const void *va, const void *vb)
1982fbecb99335961659b9961d47f2425bf142abgryzor core_a = (core_dir_config *)ap_get_module_config(a->elt, &core_module);
1982fbecb99335961659b9961d47f2425bf142abgryzor core_b = (core_dir_config *)ap_get_module_config(b->elt, &core_module);
1982fbecb99335961659b9961d47f2425bf142abgryzor /* we know they're both not special */
1982fbecb99335961659b9961d47f2425bf142abgryzor else if (core_a->d_components > core_b->d_components) {
1982fbecb99335961659b9961d47f2425bf142abgryzor /* Either they're both special, or they're both not special and have the
1982fbecb99335961659b9961d47f2425bf142abgryzor * same number of components. In any event, we now have to compare
1982fbecb99335961659b9961d47f2425bf142abgryzor * the minor key. */
1982fbecb99335961659b9961d47f2425bf142abgryzorvoid ap_core_reorder_directories(apr_pool_t *p, server_rec *s)
1982fbecb99335961659b9961d47f2425bf142abgryzor sconf = ap_get_module_config(s->module_config, &core_module);
1982fbecb99335961659b9961d47f2425bf142abgryzor /* we have to allocate tmp space to do a stable sort */
1982fbecb99335961659b9961d47f2425bf142abgryzor sortbin = apr_palloc(tmp, sec->nelts * sizeof(*sortbin));
1982fbecb99335961659b9961d47f2425bf142abgryzor for (i = 0; i < nelts; ++i) {
1982fbecb99335961659b9961d47f2425bf142abgryzor qsort(sortbin, nelts, sizeof(*sortbin), reorder_sorter);
1982fbecb99335961659b9961d47f2425bf142abgryzor /* and now copy back to the original array */
1982fbecb99335961659b9961d47f2425bf142abgryzor for (i = 0; i < nelts; ++i) {
1982fbecb99335961659b9961d47f2425bf142abgryzor/*****************************************************************
1982fbecb99335961659b9961d47f2425bf142abgryzor * There are some elements of the core config structures in which
1982fbecb99335961659b9961d47f2425bf142abgryzor * other modules have a legitimate interest (this is ugly, but necessary
1982fbecb99335961659b9961d47f2425bf142abgryzor * to preserve NCSA back-compatibility). So, we have a bunch of accessors
1982fbecb99335961659b9961d47f2425bf142abgryzor (core_dir_config *)ap_get_module_config(r->per_dir_config, &core_module);
06e80fa0dffc17ae61bca1715c96e08ea90d53cblgentis conf = (core_dir_config *)ap_get_module_config(r->per_dir_config,
1982fbecb99335961659b9961d47f2425bf142abgryzor conf = (core_dir_config *)ap_get_module_config(r->per_dir_config,
1982fbecb99335961659b9961d47f2425bf142abgryzor conf = (core_dir_config *)ap_get_module_config(r->per_dir_config,
1ef910e5e65cfbfc2455c230d8ddd6453a31a427lgentisAP_DECLARE(const char *) ap_default_type(request_rec *r)
1982fbecb99335961659b9961d47f2425bf142abgryzor conf = (core_dir_config *)ap_get_module_config(r->per_dir_config,
1982fbecb99335961659b9961d47f2425bf142abgryzorAP_DECLARE(const char *) ap_document_root(request_rec *r) /* Don't use this! */
1982fbecb99335961659b9961d47f2425bf142abgryzor conf = (core_server_config *)ap_get_module_config(r->server->module_config,
1982fbecb99335961659b9961d47f2425bf142abgryzorAP_DECLARE(const apr_array_header_t *) ap_requires(request_rec *r)
1982fbecb99335961659b9961d47f2425bf142abgryzor conf = (core_dir_config *)ap_get_module_config(r->per_dir_config,
00ce3c4e13e755c33b63f45c5d3ae69eccd977b1lgentis conf = (core_dir_config *)ap_get_module_config(r->per_dir_config,
db158bb207b0f01432bfc00b3df488226b87532dlgentis/* Should probably just get rid of this... the only code that cares is
db158bb207b0f01432bfc00b3df488226b87532dlgentis * part of the core anyway (and in fact, it isn't publicised to other
db158bb207b0f01432bfc00b3df488226b87532dlgentis * modules).
db158bb207b0f01432bfc00b3df488226b87532dlgentischar *ap_response_code_string(request_rec *r, int error_index)
db158bb207b0f01432bfc00b3df488226b87532dlgentis conf = (core_dir_config *)ap_get_module_config(r->per_dir_config,
06e80fa0dffc17ae61bca1715c96e08ea90d53cblgentis/* Code from Harald Hanche-Olsen <hanche@imf.unit.no> */
06e80fa0dffc17ae61bca1715c96e08ea90d53cblgentisstatic apr_inline void do_double_reverse (conn_rec *conn)
06e80fa0dffc17ae61bca1715c96e08ea90d53cblgentis /* already done */
db158bb207b0f01432bfc00b3df488226b87532dlgentis if (conn->remote_host == NULL || conn->remote_host[0] == '\0') {
db158bb207b0f01432bfc00b3df488226b87532dlgentis /* single reverse failed, so don't bother */
1982fbecb99335961659b9961d47f2425bf142abgryzorAP_DECLARE(const char *) ap_get_remote_host(conn_rec *conn, void *dir_config,
020366f830905b6b5dfccfa03373379ae6a13e7blgentis /* If we haven't checked the host name, and we want to */
020366f830905b6b5dfccfa03373379ae6a13e7blgentis ((core_dir_config *)ap_get_module_config(dir_config, &core_module))
020366f830905b6b5dfccfa03373379ae6a13e7blgentis /* the default */
1982fbecb99335961659b9961d47f2425bf142abgryzor hptr = gethostbyaddr((char *)iaddr, sizeof(struct in_addr), AF_INET);
b228078ccfac4cc568b6723f4d1b9a2317d67d5elgentis conn->remote_host = apr_pstrdup(conn->pool, (void *)hptr->h_name);
1982fbecb99335961659b9961d47f2425bf142abgryzor /* if failed, set it to the NULL string to indicate error */
1982fbecb99335961659b9961d47f2425bf142abgryzor * Return the desired information; either the remote DNS name, if found,
1982fbecb99335961659b9961d47f2425bf142abgryzor * or either NULL (if the hostname was requested) or the IP address
1982fbecb99335961659b9961d47f2425bf142abgryzor * (if any identifier was requested).
1982fbecb99335961659b9961d47f2425bf142abgryzor if (conn->remote_host != NULL && conn->remote_host[0] != '\0') {
1982fbecb99335961659b9961d47f2425bf142abgryzor if (type == REMOTE_HOST || type == REMOTE_DOUBLE_REV) {
1982fbecb99335961659b9961d47f2425bf142abgryzorAP_DECLARE(const char *) ap_get_remote_logname(request_rec *r)
1982fbecb99335961659b9961d47f2425bf142abgryzor/* If we haven't checked the identity, and we want to */
1982fbecb99335961659b9961d47f2425bf142abgryzor dir_conf = (core_dir_config *)ap_get_module_config(r->per_dir_config,
1bd10e3ff5b2478df23af4caa517b489df38a82clgentis/* There are two options regarding what the "name" of a server is. The
1bd10e3ff5b2478df23af4caa517b489df38a82clgentis * "canonical" name as defined by ServerName and Port, or the "client's
1982fbecb99335961659b9961d47f2425bf142abgryzor * name" as supplied by a possible Host: header or full URI. We never
1bd10e3ff5b2478df23af4caa517b489df38a82clgentis * trust the port passed in the client's headers, we always use the
1982fbecb99335961659b9961d47f2425bf142abgryzor * port of the actual socket.
1982fbecb99335961659b9961d47f2425bf142abgryzor * The DNS option to UseCanonicalName causes this routine to do a
1982fbecb99335961659b9961d47f2425bf142abgryzor * reverse lookup on the local IP address of the connectiona and use
1982fbecb99335961659b9961d47f2425bf142abgryzor * that for the ServerName. This makes its value more reliable while
1982fbecb99335961659b9961d47f2425bf142abgryzor * at the same time allowing Demon's magic virtual hosting to work.
1982fbecb99335961659b9961d47f2425bf142abgryzor * The assumption is that DNS lookups are sufficiently quick...
1982fbecb99335961659b9961d47f2425bf142abgryzor * -- fanf 1998-10-03
1982fbecb99335961659b9961d47f2425bf142abgryzorAP_DECLARE(const char *) ap_get_server_name(request_rec *r)
1982fbecb99335961659b9961d47f2425bf142abgryzor d = (core_dir_config *)ap_get_module_config(r->per_dir_config,
1982fbecb99335961659b9961d47f2425bf142abgryzor if (d->use_canonical_name == USE_CANONICAL_NAME_OFF) {
576c49cd335618ad4b5351bd1c5f2cfd7584dba4lgentis return r->hostname ? r->hostname : r->server->server_hostname;
1982fbecb99335961659b9961d47f2425bf142abgryzor if (d->use_canonical_name == USE_CANONICAL_NAME_DNS) {
1982fbecb99335961659b9961d47f2425bf142abgryzor hptr = gethostbyaddr((char *)iaddr, sizeof(struct in_addr),
1982fbecb99335961659b9961d47f2425bf142abgryzor /* default */
1982fbecb99335961659b9961d47f2425bf142abgryzorAP_DECLARE(unsigned) ap_get_server_port(const request_rec *r)
1982fbecb99335961659b9961d47f2425bf142abgryzor (core_dir_config *)ap_get_module_config(r->per_dir_config, &core_module);
1982fbecb99335961659b9961d47f2425bf142abgryzor port = r->server->port ? r->server->port : ap_default_port(r);
1982fbecb99335961659b9961d47f2425bf142abgryzor || d->use_canonical_name == USE_CANONICAL_NAME_DNS) {
1982fbecb99335961659b9961d47f2425bf142abgryzor return r->hostname ? ntohs(r->connection->local_addr.sin_port)
1982fbecb99335961659b9961d47f2425bf142abgryzor /* default */
1982fbecb99335961659b9961d47f2425bf142abgryzorAP_DECLARE(char *) ap_construct_url(apr_pool_t *p, const char *uri,
1982fbecb99335961659b9961d47f2425bf142abgryzor return apr_pstrcat(p, ap_http_method(r), "://", host, uri, NULL);
1982fbecb99335961659b9961d47f2425bf142abgryzor return apr_psprintf(p, "%s://%s:%u%s", ap_http_method(r), host, port, uri);
1982fbecb99335961659b9961d47f2425bf142abgryzorAP_DECLARE(unsigned long) ap_get_limit_req_body(const request_rec *r)
1982fbecb99335961659b9961d47f2425bf142abgryzor (core_dir_config *)ap_get_module_config(r->per_dir_config, &core_module);
1982fbecb99335961659b9961d47f2425bf142abgryzorstatic apr_status_t get_win32_registry_default_value(apr_pool_t *p, HKEY hkey,
1982fbecb99335961659b9961d47f2425bf142abgryzor /* Read to NULL buffer to determine value size */
1982fbecb99335961659b9961d47f2425bf142abgryzor result = RegQueryValueEx(hkeyOpen, "", 0, &type, NULL, &size);
1ef910e5e65cfbfc2455c230d8ddd6453a31a427lgentis if ((size < 2) || (type != REG_SZ && type != REG_EXPAND_SZ)) {
1982fbecb99335961659b9961d47f2425bf142abgryzor /* Read value based on size query above */
1982fbecb99335961659b9961d47f2425bf142abgryzor result = RegQueryValueEx(hkeyOpen, "", 0, &type, *value, &size);
1982fbecb99335961659b9961d47f2425bf142abgryzor /* TODO: This might look fine, but we need to provide some warning
1982fbecb99335961659b9961d47f2425bf142abgryzor * somewhere that some environment variables may -not- be translated,
1982fbecb99335961659b9961d47f2425bf142abgryzor * seeing as we may have chopped the environment table down somewhat.
1982fbecb99335961659b9961d47f2425bf142abgryzor if ((result == ERROR_SUCCESS) && (type == REG_EXPAND_SZ))
1982fbecb99335961659b9961d47f2425bf142abgryzorstatic char* get_interpreter_from_win32_registry(apr_pool_t *p, const char* ext,
1ef910e5e65cfbfc2455c230d8ddd6453a31a427lgentis * Future optimization:
1982fbecb99335961659b9961d47f2425bf142abgryzor * When the registry is successfully searched, store the strings for
1982fbecb99335961659b9961d47f2425bf142abgryzor * interpreter and arguments in an ext hash to speed up subsequent look-ups
1982fbecb99335961659b9961d47f2425bf142abgryzor /* Open the key associated with the script filetype extension */
1982fbecb99335961659b9961d47f2425bf142abgryzor result = RegOpenKeyEx(HKEY_CLASSES_ROOT, ext, 0, KEY_QUERY_VALUE,
1982fbecb99335961659b9961d47f2425bf142abgryzor /* Retrieve the name of the script filetype extension */
1982fbecb99335961659b9961d47f2425bf142abgryzor result = RegQueryValueEx(hkeyType, "", NULL, &type, typeName, &size);
1982fbecb99335961659b9961d47f2425bf142abgryzor if (result == ERROR_SUCCESS && type == REG_SZ && typeName[0]) {
1982fbecb99335961659b9961d47f2425bf142abgryzor /* Open the key associated with the script filetype extension */
1982fbecb99335961659b9961d47f2425bf142abgryzor result = RegOpenKeyEx(HKEY_CLASSES_ROOT, typeName, 0,
1982fbecb99335961659b9961d47f2425bf142abgryzor /* Open the key for the script command path by:
1982fbecb99335961659b9961d47f2425bf142abgryzor * 1) the 'named' filetype key for ExecCGI/Command
1982fbecb99335961659b9961d47f2425bf142abgryzor * 2) the extension's type key for ExecCGI/Command
1982fbecb99335961659b9961d47f2425bf142abgryzor * and if the strict arg is false, then continue trying:
1982fbecb99335961659b9961d47f2425bf142abgryzor * 3) the 'named' filetype key for Open/Command
1982fbecb99335961659b9961d47f2425bf142abgryzor * 4) the extension's type key for Open/Command
1ef910e5e65cfbfc2455c230d8ddd6453a31a427lgentis result = get_win32_registry_default_value(p, hkeyName,
1982fbecb99335961659b9961d47f2425bf142abgryzor result = get_win32_registry_default_value(p, hkeyType,
1982fbecb99335961659b9961d47f2425bf142abgryzor if (!strict && cmdOfName && (result != ERROR_SUCCESS)) {
1982fbecb99335961659b9961d47f2425bf142abgryzor result = get_win32_registry_default_value(p, hkeyName,
1982fbecb99335961659b9961d47f2425bf142abgryzor result = get_win32_registry_default_value(p, hkeyType,
020366f830905b6b5dfccfa03373379ae6a13e7blgentis * The canonical way shell command entries are entered in the Win32
020366f830905b6b5dfccfa03373379ae6a13e7blgentis * registry is as follows:
06e80fa0dffc17ae61bca1715c96e08ea90d53cblgentis * shell [options] "%1" [args]
06e80fa0dffc17ae61bca1715c96e08ea90d53cblgentis * shell - full path name to interpreter or shell to run.
020366f830905b6b5dfccfa03373379ae6a13e7blgentis * E.g., c:\usr\local\ntreskit\perl\bin\perl.exe
020366f830905b6b5dfccfa03373379ae6a13e7blgentis * options - optional switches
1982fbecb99335961659b9961d47f2425bf142abgryzor * "%1" - Place holder for file to run the shell against.
1982fbecb99335961659b9961d47f2425bf142abgryzor * Typically quoted.
576c49cd335618ad4b5351bd1c5f2cfd7584dba4lgentis * options - additional arguments
1982fbecb99335961659b9961d47f2425bf142abgryzor * E.g., /silent
1982fbecb99335961659b9961d47f2425bf142abgryzor * If we find a %1 or a quoted %1, lop off the remainder to arguments.
1982fbecb99335961659b9961d47f2425bf142abgryzorAP_DECLARE (file_type_e) ap_get_win32_interpreter(const request_rec *r,
1982fbecb99335961659b9961d47f2425bf142abgryzor d = (core_dir_config *)ap_get_module_config(r->per_dir_config,
1982fbecb99335961659b9961d47f2425bf142abgryzor /* Find the file extension */
06e80fa0dffc17ae61bca1715c96e08ea90d53cblgentis if (ext && (!strcasecmp(ext,".bat") || !strcasecmp(ext,".cmd")))
1982fbecb99335961659b9961d47f2425bf142abgryzor *interpreter = apr_pstrcat(r->pool, "\"", comspec, "\" /c ", NULL);
06e80fa0dffc17ae61bca1715c96e08ea90d53cblgentis ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_INFO, 0, r->server,
1982fbecb99335961659b9961d47f2425bf142abgryzor "Failed to start a '%s' file as a script." APR_EOL_STR
1982fbecb99335961659b9961d47f2425bf142abgryzor "\tCOMSPEC variable is missing from the environment.", ext);
1982fbecb99335961659b9961d47f2425bf142abgryzor /* If the file has an extension and it is not .com and not .exe and
1982fbecb99335961659b9961d47f2425bf142abgryzor * we've been instructed to search the registry, then do it!
1982fbecb99335961659b9961d47f2425bf142abgryzor if (ext && strcasecmp(ext,".exe") && strcasecmp(ext,".com") &&
1982fbecb99335961659b9961d47f2425bf142abgryzor (d->script_interpreter_source == INTERPRETER_SOURCE_REGISTRY ||
1982fbecb99335961659b9961d47f2425bf142abgryzor d->script_interpreter_source == INTERPRETER_SOURCE_REGISTRY_STRICT)) {
1982fbecb99335961659b9961d47f2425bf142abgryzor /* Check the registry */
1982fbecb99335961659b9961d47f2425bf142abgryzor *interpreter = get_interpreter_from_win32_registry(r->pool, ext,
06e80fa0dffc17ae61bca1715c96e08ea90d53cblgentis else if (d->script_interpreter_source == INTERPRETER_SOURCE_REGISTRY_STRICT) {
1982fbecb99335961659b9961d47f2425bf142abgryzor ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_INFO, 0, r->server,
1982fbecb99335961659b9961d47f2425bf142abgryzor "ScriptInterpreterSource config directive set to \"registry-strict\"." APR_EOL_STR
1982fbecb99335961659b9961d47f2425bf142abgryzor "\tInterpreter not found for files of type '%s'.", ext);
1982fbecb99335961659b9961d47f2425bf142abgryzor ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_INFO, 0, r->server,
1982fbecb99335961659b9961d47f2425bf142abgryzor "ScriptInterpreterSource config directive set to \"registry\"." APR_EOL_STR
1982fbecb99335961659b9961d47f2425bf142abgryzor "\tInterpreter not found for files of type '%s', "
1982fbecb99335961659b9961d47f2425bf142abgryzor /* Need to peek into the file figure out what it really is... */
1982fbecb99335961659b9961d47f2425bf142abgryzor hFile = CreateFile(r->filename, GENERIC_READ, FILE_SHARE_READ, NULL,
1982fbecb99335961659b9961d47f2425bf142abgryzor bResult = ReadFile(hFile, (void*) &buffer, sizeof(buffer) - 1,
1982fbecb99335961659b9961d47f2425bf142abgryzor ap_log_rerror(APLOG_MARK, APLOG_ERR, GetLastError(), r,
1982fbecb99335961659b9961d47f2425bf142abgryzor /* Script or executable, that is the question... */
1982fbecb99335961659b9961d47f2425bf142abgryzor /* Assuming file is a script since it starts with a shebang */
fb25b82560b7fcaffa006cb4738d86acc561b6f4lgentis /* Not a script, is it an executable? */
fb25b82560b7fcaffa006cb4738d86acc561b6f4lgentis if ((nBytesRead >= sizeof(IMAGE_DOS_HEADER)) && (hdr->e_magic == IMAGE_DOS_SIGNATURE)) {
1982fbecb99335961659b9961d47f2425bf142abgryzor/*****************************************************************
1982fbecb99335961659b9961d47f2425bf142abgryzor * Commands... this module handles almost all of the NCSA httpd.conf
1982fbecb99335961659b9961d47f2425bf142abgryzor * commands, but most of the old srm.conf is in the the modules.
1982fbecb99335961659b9961d47f2425bf142abgryzor/* returns a parent if it matches the given directive */
1982fbecb99335961659b9961d47f2425bf142abgryzorstatic const ap_directive_t * find_parent(const ap_directive_t *dirp,
06e80fa0dffc17ae61bca1715c96e08ea90d53cblgentis const char *what)
2f44538c88c5310bebb17a39b171487315a45624lgentis /* ### it would be nice to have atom-ized directives */
020366f830905b6b5dfccfa03373379ae6a13e7blgentisAP_DECLARE(const char *) ap_check_cmd_context(cmd_parms *cmd,
020366f830905b6b5dfccfa03373379ae6a13e7blgentis if ((forbidden & NOT_IN_VIRTUALHOST) && cmd->server->is_virtual) {
020366f830905b6b5dfccfa03373379ae6a13e7blgentis " cannot occur within <VirtualHost> section", NULL);
020366f830905b6b5dfccfa03373379ae6a13e7blgentis if ((forbidden & NOT_IN_LIMIT) && cmd->limited != -1) {
1982fbecb99335961659b9961d47f2425bf142abgryzor if ((forbidden & NOT_IN_DIR_LOC_FILE) == NOT_IN_DIR_LOC_FILE
1982fbecb99335961659b9961d47f2425bf142abgryzor " cannot occur within <Directory/Location/Files> "
1982fbecb99335961659b9961d47f2425bf142abgryzor && ((found = find_parent(cmd->directive, "<Directory"))
1982fbecb99335961659b9961d47f2425bf142abgryzor || (found = find_parent(cmd->directive, "<DirectoryMatch"))))
1982fbecb99335961659b9961d47f2425bf142abgryzor && ((found = find_parent(cmd->directive, "<Location"))
1982fbecb99335961659b9961d47f2425bf142abgryzor || (found = find_parent(cmd->directive, "<LocationMatch"))))
1982fbecb99335961659b9961d47f2425bf142abgryzor || (found = find_parent(cmd->directive, "<FilesMatch"))))) {
1982fbecb99335961659b9961d47f2425bf142abgryzorstatic const char *set_access_name(cmd_parms *cmd, void *dummy,
1982fbecb99335961659b9961d47f2425bf142abgryzor const char *arg)
1982fbecb99335961659b9961d47f2425bf142abgryzor core_server_config *conf = ap_get_module_config(sconf, &core_module);
1982fbecb99335961659b9961d47f2425bf142abgryzorstatic const char *set_gprof_dir(cmd_parms *cmd, void *dummy, char *arg)
06e80fa0dffc17ae61bca1715c96e08ea90d53cblgentis core_server_config *conf = ap_get_module_config(sconf, &core_module);
1982fbecb99335961659b9961d47f2425bf142abgryzor#endif /*GPROF*/
1982fbecb99335961659b9961d47f2425bf142abgryzorstatic const char *set_add_default_charset(cmd_parms *cmd,
return err;
return NULL;
const char *arg)
return err;
arg);
return NULL;
int idx;
return err;
* http_protocol.c relies on to distinguish between
return NULL;
return err;
return NULL;
char action;
action = *(w++);
else if (first) {
first = 0;
return NULL;
return NULL;
require_line *r;
if (!c->ap_requires) {
return NULL;
const char *arg) {
int limited = 0;
const char *errmsg;
return err;
while (limited_methods[0]) {
char **xmethod;
if (!tog) {
return errmsg;
#ifdef WIN32
#define USE_ICASE 0
const char *errmsg;
return err;
#if defined(HAVE_UNC_PATHS)
&core_module);
return errmsg;
conf->r = r;
return NULL;
const char *errmsg;
return err;
&core_module);
return errmsg;
conf->r = r;
return NULL;
const char *errmsg;
return err;
if (!old_path) {
&core_module);
return errmsg;
conf->r = r;
return NULL;
if (not) {
arg++;
const char *retval;
return retval;
char **defines;
const char *endp;
int not = 0;
arg++;
const char *retval;
return retval;
/* httpd.conf commands... beginning with the <VirtualHost> business */
const char *arg)
const char *errmsg;
return err;
if (errmsg) {
return errmsg;
s->lookup_defaults);
return errmsg;
const char *arg)
while (*arg) {
return NULL;
char **newfilter;
return NULL;
char **newfilter;
return NULL;
const char *arg)
return err;
return NULL;
return err;
return NULL;
const char *arg)
return err;
return NULL;
int port;
return err;
return NULL;
const char *arg)
return err;
return NULL;
const char *arg)
return err;
return NULL;
return err;
return NULL;
const char *arg)
return err;
return NULL;
const char *arg)
return err;
return NULL;
const char *arg)
return err;
return NULL;
return err;
return NULL;
const char *arg)
return err;
return NULL;
const char *arg)
return err;
return NULL;
return err;
return NULL;
const char *arg)
return err;
return NULL;
const char *name)
return NULL;
char *str;
return err;
return NULL;
&core_module);
const char *word1)
return NULL;
return err;
static int version_locked = 0;
enum server_token_type {
version_locked = 0;
return APR_SUCCESS;
if (! version_locked) {
const char *arg)
return err;
return NULL;
const char *arg)
int lim;
return err;
if (lim < 0) {
return NULL;
const char *arg)
int lim;
return err;
if (lim < 0) {
NULL);
return NULL;
const char *arg)
int lim;
return err;
if (lim < 0) {
NULL);
return NULL;
const char *arg)
return err;
* Instead we have an idiotic define in httpd.h that prevents
return NULL;
const char *arg)
return err;
return NULL;
return AP_DEFAULT_LIMIT_XML_BODY;
#ifdef WIN32
char *arg)
return NULL;
#if !defined (RLIMIT_CPU) || !(defined (RLIMIT_DATA) || defined (RLIMIT_VMEM) || defined(RLIMIT_AS)) || !defined (RLIMIT_NPROC)
return NULL;
#ifdef RLIMIT_CPU
return NULL;
#if defined(RLIMIT_AS)
return NULL;
#ifdef RLIMIT_NPROC
return NULL;
apr_ssize_t i = 0;
*nbytes = 0;
bytes_written += n;
return rv;
if (n < cnt) {
return APR_SUCCESS;
apr_int32_t i;
*nbytes = 0;
sendlen = 0;
return rv;
#ifdef GPROF
#ifdef _OSD_POSIX
#ifdef WIN32
#ifdef RLIMIT_CPU
#ifdef RLIMIT_NPROC
{ NULL }
if (r->proxyreq) {
return HTTP_FORBIDDEN;
return HTTP_BAD_REQUEST;
NULL);
NULL);
return OK;
core_dir_config *d =
#ifdef AP_USE_MMAP_FILES
int bld_content_md5 =
return errstatus;
return HTTP_NOT_IMPLEMENTED;
return ap_send_http_options(r);
return HTTP_METHOD_NOT_ALLOWED;
: r->filename);
return HTTP_NOT_FOUND;
return HTTP_METHOD_NOT_ALLOWED;
return HTTP_FORBIDDEN;
ap_set_etag(r);
return errstatus;
#ifdef AP_USE_MMAP_FILES
if (bld_content_md5) {
#ifdef APACHE_XLATE
if (!r->header_only) {
if (!rangestatus) {
return HTTP_INTERNAL_SERVER_ERROR;
#ifdef AP_USE_MMAP_FILES
unsigned char *addr;
if (bld_content_md5) {
if (!r->header_only) {
if (!rangestatus) {
return OK;
typedef struct BUFFER_FILTER_CTX {
AP_BRIGADE_FOREACH(e, b) {
if (destroy_me) {
const char *str;
apr_ssize_t n;
return rv;
AP_BUCKET_REMOVE(e);
destroy_me = e;
insert_before = e;
if (destroy_me) {
if (pass_the_brigade) {
if (insert_first) {
AP_BRIGADE_INSERT_HEAD(b, e);
else if (insert_before) {
return rv;
if (ctx) {
if (insert_before) {
return APR_SUCCESS;
ap_bucket *e;
AP_BRIGADE_FOREACH(e, b) {
if (AP_BUCKET_IS_EOS(e)) {
eos = e;
const char *data;
return rv;
if (len > 0) {
if (bytes > 0) {
AP_BRIGADE_INSERT_HEAD(b, e);
AP_BRIGADE_INSERT_TAIL(b, e);
return rv;
return APR_SUCCESS;
ap_bucket *e;
AP_BRIGADE_INSERT_TAIL(b, e);
return APR_SUCCESS;
return APR_EOF;
typedef struct CORE_OUTPUT_FILTER_CTX {
ap_bucket *e;
conn_rec *c = f->c;
if (ctx->b) {
b = ctx->b;
AP_BRIGADE_INSERT_HEAD(b, e);
AP_BRIGADE_FOREACH(e, b) {
if (AP_BUCKET_IS_EOS(e)) {
else if (AP_BUCKET_IS_FILE(e)) {
const char *str;
apr_ssize_t n;
nbytes += n;
if (!fd) {
nvec++;
if (!fd && (!more) && (nbytes < MIN_SIZE_TO_WRITE) && !AP_BUCKET_IS_EOS(e) && !AP_BUCKET_IS_FLUSH(e)) {
return APR_SUCCESS;
if (fd) {
#if APR_HAS_SENDFILE
if (nvec) {
if (nvec_trailers) {
#if APR_HAS_SENDFILE
if (!c->keepalive) {
&nbytes,
flags);
#if APR_HAS_SENDFILE
if (more)
return rv;
nvec = 0;
nvec_trailers = 0;
b = more;
return APR_SUCCESS;
{ return DEFAULT_HTTP_PORT; }
&core_module);
static void register_hooks(void)