http_core.c revision b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44c
181e56d8b348d301d615ccf5465ae600fee2867berikabele/* ====================================================================
181e56d8b348d301d615ccf5465ae600fee2867berikabele * Copyright (c) 1995-1999 The Apache Group. All rights reserved.
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd * Redistribution and use in source and binary forms, with or without
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd * modification, are permitted provided that the following conditions
5ce121e164ea2c1b0cc554cb8c2e8540cfdac02fslive * 1. Redistributions of source code must retain the above copyright
5a58787efeb02a1c3f06569d019ad81fd2efa06end * notice, this list of conditions and the following disclaimer.
7add1372edb1ee95a2c4d1314df4c7567bda7c62jim * 2. Redistributions in binary form must reproduce the above copyright
7add1372edb1ee95a2c4d1314df4c7567bda7c62jim * notice, this list of conditions and the following disclaimer in
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * the documentation and/or other materials provided with the
2e545ce2450a9953665f701bb05350f0d3f26275nd * distribution.
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * 3. All advertising materials mentioning features or use of this
7add1372edb1ee95a2c4d1314df4c7567bda7c62jim * software must display the following acknowledgment:
5a58787efeb02a1c3f06569d019ad81fd2efa06end * "This product includes software developed by the Apache Group
af33a4994ae2ff15bc67d19ff1a7feb906745bf8rbowen * for use in the Apache HTTP server project (http://www.apache.org/)."
7add1372edb1ee95a2c4d1314df4c7567bda7c62jim * 4. The names "Apache Server" and "Apache Group" must not be used to
7add1372edb1ee95a2c4d1314df4c7567bda7c62jim * endorse or promote products derived from this software without
5a58787efeb02a1c3f06569d019ad81fd2efa06end * prior written permission. For written permission, please contact
3f08db06526d6901aa08c110b5bc7dde6bc39905nd * apache@apache.org.
7add1372edb1ee95a2c4d1314df4c7567bda7c62jim * 5. Products derived from this software may not be called "Apache"
af84459fbf938e508fd10b01cb8d699c79083813takashi * nor may "Apache" appear in their names without prior written
7f5b59ccc63c0c0e3e678a168f09ee6a2f51f9d0nd * permission of the Apache Group.
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjung * 6. Redistributions of any form whatsoever must retain the following
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd * acknowledgment:
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd * "This product includes software developed by the Apache Group
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen * for use in the Apache HTTP server project (http://www.apache.org/)."
c7ed811e89712261aaa4432198e331389044e1f8rjung * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
c7ed811e89712261aaa4432198e331389044e1f8rjung * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
c7ed811e89712261aaa4432198e331389044e1f8rjung * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
c7ed811e89712261aaa4432198e331389044e1f8rjung * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE GROUP OR
c7ed811e89712261aaa4432198e331389044e1f8rjung * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
c7ed811e89712261aaa4432198e331389044e1f8rjung * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
c7ed811e89712261aaa4432198e331389044e1f8rjung * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
c7ed811e89712261aaa4432198e331389044e1f8rjung * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
5a58787efeb02a1c3f06569d019ad81fd2efa06end * OF THE POSSIBILITY OF SUCH DAMAGE.
7add1372edb1ee95a2c4d1314df4c7567bda7c62jim * ====================================================================
7add1372edb1ee95a2c4d1314df4c7567bda7c62jim * This software consists of voluntary contributions made by many
7add1372edb1ee95a2c4d1314df4c7567bda7c62jim * individuals on behalf of the Apache Group and was originally based
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh * on public domain software written at the National Center for
7add1372edb1ee95a2c4d1314df4c7567bda7c62jim * Supercomputing Applications, University of Illinois, Urbana-Champaign.
5a58787efeb02a1c3f06569d019ad81fd2efa06end * For more information on the Apache Group and the Apache HTTP server
5a58787efeb02a1c3f06569d019ad81fd2efa06end * project, please see <http://www.apache.org/>.
c7ed811e89712261aaa4432198e331389044e1f8rjung#include "http_protocol.h" /* For index_of_response(). Grump. */
5ce121e164ea2c1b0cc554cb8c2e8540cfdac02fslive#include "http_main.h" /* For the default_handler below... */
7add1372edb1ee95a2c4d1314df4c7567bda7c62jim/* Allow Apache to use ap_mmap */
c6e63344e43c53e7a81e94fac04c1842767de22arbowen/* mmap support for static files based on ideas from John Heidemann's
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen * patch against 1.0.5. See
7add1372edb1ee95a2c4d1314df4c7567bda7c62jim * <http://www.isi.edu/~johnh/SOFTWARE/APACHE/index.html>.
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen/* Files have to be at least this big before they're mmap()d. This is to deal
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen * with systems where the expense of doing an mmap() and an munmap() outweighs
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen * the benefit for small files. It shouldn't be set lower than 1.
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen #endif /* SUNOS4 */
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen#endif /* MMAP_THRESHOLD */
42dcfa2aba12aaa08c30caa333d67b96889eb4ffrbowen#endif /* USE_MMAP_FILES */
181e56d8b348d301d615ccf5465ae600fee2867berikabele/* Server core module... This module provides support for really basic
c7ed811e89712261aaa4432198e331389044e1f8rjung * server operations, including options and commands which control the
35c69680976019d8c68d83236614752d1d8e6081slive * operation of other modules. Consider this the bureaucracy module.
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen * The core module also defines handlers, etc., do handle just enough
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen * to allow a server with the core module ONLY to actually serve documents
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen * (though it slaps DefaultType on all of 'em); this was useful in testing,
eceded617d1b6f35497902cea1788f87596d9854rjung * but may not be worth preserving.
eceded617d1b6f35497902cea1788f87596d9854rjung * This file could almost be mod_core.c, except for the stuff which affects
42dcfa2aba12aaa08c30caa333d67b96889eb4ffrbowen * the http_conf_globals.
c7ed811e89712261aaa4432198e331389044e1f8rjungstatic void *create_core_dir_config(ap_context_t *a, char *dir)
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen conf = (core_dir_config *)ap_pcalloc(a, sizeof(core_dir_config));
eceded617d1b6f35497902cea1788f87596d9854rjung conf->d_is_fnmatch = conf->d ? (ap_is_fnmatch(conf->d) != 0) : 0;
eceded617d1b6f35497902cea1788f87596d9854rjung conf->d_components = conf->d ? ap_count_dirs(conf->d) : 0;
181e56d8b348d301d615ccf5465ae600fee2867berikabele conf->do_rfc1413 = DEFAULT_RFC1413 | 2; /* set bit 1 to indicate default */
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen conf->script_interpreter_source = INTERPRETER_SOURCE_UNSET;
42dcfa2aba12aaa08c30caa333d67b96889eb4ffrbowen return (void *)conf;
5a58787efeb02a1c3f06569d019ad81fd2efa06endstatic void *merge_core_dir_configs(ap_context_t *a, void *basev, void *newv)
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen conf = (core_dir_config *)ap_palloc(a, sizeof(core_dir_config));
50abbb3ef90b5708d61f9c92a7bed70a993da36arbowen memcpy((char *)conf, (const char *)base, sizeof(core_dir_config));
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen memcpy(conf->response_code_strings, base->response_code_strings,
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen sizeof(*conf->response_code_strings) * RESPONSE_CODES);
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen /* there was no explicit setting of new->opts, so we merge
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen * preserve the invariant (opts_add & opts_remove) == 0
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen conf->opts_add = (conf->opts_add & ~new->opts_remove) | new->opts_add;
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen conf->opts_remove = (conf->opts_remove & ~new->opts_add)
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen conf->opts = (conf->opts & ~conf->opts_remove) | conf->opts_add;
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen if ((base->opts & OPT_INCNOEXEC) && (new->opts & OPT_INCLUDES)) {
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen conf->opts = (conf->opts & ~OPT_INCNOEXEC) | OPT_INCLUDES;
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen /* otherwise we just copy, because an explicit opts setting
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen * overrides all earlier +/- modifiers
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen sizeof(*conf->response_code_strings) * RESPONSE_CODES);
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen memcpy(conf->response_code_strings, new->response_code_strings,
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen sizeof(*conf->response_code_strings) * RESPONSE_CODES);
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen for (i = 0; i < RESPONSE_CODES; ++i) {
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen if (new->hostname_lookups != HOSTNAME_LOOKUP_UNSET) {
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen if (new->use_canonical_name != USE_CANONICAL_NAME_UNSET) {
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen conf->sec = ap_append_arrays(a, base->sec, new->sec);
7add1372edb1ee95a2c4d1314df4c7567bda7c62jim if (new->script_interpreter_source != INTERPRETER_SOURCE_UNSET) {
50abbb3ef90b5708d61f9c92a7bed70a993da36arbowen conf->script_interpreter_source = new->script_interpreter_source;
50abbb3ef90b5708d61f9c92a7bed70a993da36arbowen return (void*)conf;
50abbb3ef90b5708d61f9c92a7bed70a993da36arbowenstatic void *create_core_server_config(ap_context_t *a, server_rec *s)
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen conf = (core_server_config *)ap_pcalloc(a, sizeof(core_server_config));
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen conf->access_name = is_virtual ? NULL : DEFAULT_ACCESS_FNAME;
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen conf->ap_document_root = is_virtual ? NULL : DOCUMENT_LOCATION;
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen conf->sec_url = ap_make_array(a, 40, sizeof(void *));
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen return (void *)conf;
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowenstatic void *merge_core_server_configs(ap_context_t *p, void *basev, void *virtv)
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen core_server_config *base = (core_server_config *)basev;
50abbb3ef90b5708d61f9c92a7bed70a993da36arbowen core_server_config *virt = (core_server_config *)virtv;
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen conf = (core_server_config *)ap_pcalloc(p, sizeof(core_server_config));
c6e63344e43c53e7a81e94fac04c1842767de22arbowen conf->sec = ap_append_arrays(p, base->sec, virt->sec);
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen conf->sec_url = ap_append_arrays(p, base->sec_url, virt->sec_url);
57d0156f7bbd9ea3a72342cf9912aba61d118702rbowen/* Add per-directory configuration entry (for <directory> section);
5a58787efeb02a1c3f06569d019ad81fd2efa06end * these are part of the core server config.
af84459fbf938e508fd10b01cb8d699c79083813takashiCORE_EXPORT(void) ap_add_per_dir_conf(server_rec *s, void *dir_config)
f3ec420152ca921e4c1ce77782f51b53f659018dnd core_server_config *sconf = ap_get_module_config(s->module_config,
727872d18412fc021f03969b8641810d8896820bhumbedooh void **new_space = (void **)ap_push_array(sconf->sec);
cc7e1025de9ac63bd4db6fe7f71c158b2cf09fe4humbedoohCORE_EXPORT(void) ap_add_per_url_conf(server_rec *s, void *url_config)
0d0ba3a410038e179b695446bb149cce6264e0abnd core_server_config *sconf = ap_get_module_config(s->module_config,
0d0ba3a410038e179b695446bb149cce6264e0abnd void **new_space = (void **)ap_push_array(sconf->sec_url);
727872d18412fc021f03969b8641810d8896820bhumbedoohCORE_EXPORT(void) ap_add_file_conf(core_dir_config *conf, void *url_config)
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd/* core_reorder_directories reorders the directory sections such that the
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd * 1-component sections come first, then the 2-component, and so on, finally
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd * followed by the "special" sections. A section is "special" if it's a regex,
5a58787efeb02a1c3f06569d019ad81fd2efa06end * or if it doesn't start with / -- consider proxy: matching. All movements
#ifdef HAVE_DRIVE_LETTERS
struct reorder_sort_rec {
void *elt;
int orig_index;
int nelts;
void **elts;
for (i = 0; i < nelts; ++i) {
for (i = 0; i < nelts; ++i) {
&core_module);
&core_module);
&core_module);
&core_module);
&core_module);
&core_module);
&core_module);
&core_module);
return NULL;
if (hptr) {
char **haddr;
int type)
int hostname_lookups;
if (dir_config) {
return NULL;
return NULL;
&core_module);
return NULL;
core_dir_config *d;
&core_module);
AF_INET);
unsigned port;
core_dir_config *d =
: port;
return port;
request_rec *r)
core_dir_config *d =
return d->limit_req_body;
#ifdef WIN32
int size;
int result;
char *keyName;
char *buffer;
if (!ext)
return NULL;
&hkeyOpen);
return NULL;
size = 0;
return NULL;
&hkeyOpen);
return NULL;
size = 0;
return NULL;
return buffer;
char** interpreter )
core_dir_config *d;
&core_module);
if (!exename) {
if (!exename) {
exename++;
return eFileTypeEXE32;
if (*interpreter)
return eFileTypeSCRIPT;
return eFileTypeUNKNOWN;
return eFileTypeUNKNOWN;
return fileType;
* Commands... this module handles almost all of the NCSA httpd.conf
* commands, but most of the old srm.conf is in the the modules.
unsigned forbidden)
return NULL;
return err;
return NULL;
#ifdef GPROF
return err;
return NULL;
return err;
arg);
return NULL;
int idx;
char *line)
return err;
w, NULL);
return NULL;
/* access.conf commands...
* The *only* thing that can appear in access.conf at top level is a
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;
return err;
while (limited_methods[0]) {
return NULL;
return NULL;
#ifdef WIN32
#define USE_ICASE 0
const char *errmsg;
const char *old_end_token;
return err;
: end_directory_section)) {
return errmsg;
conf->r = r;
return NULL;
const char *errmsg;
const char *old_end_token;
return err;
: end_location_section)) {
return errmsg;
conf->r = r;
return NULL;
const char *arg)
const char *errmsg;
const char *old_end_token;
return err;
if (!old_path) {
: end_files_section)) {
return errmsg;
&core_module);
conf->r = r;
return NULL;
return NULL;
char l[MAX_STRING_LEN];
if (not) {
arg++;
return NULL;
nest++;
nest--;
if (nest) {
return NULL;
char **defines;
return NULL;
char *endp;
char l[MAX_STRING_LEN];
int not = 0;
arg++;
return NULL;
nest++;
nest--;
if (nest) {
return NULL;
/* httpd.conf commands... beginning with the <VirtualHost> business */
const char *errmsg;
const char *old_end_token;
return err;
if (errmsg) {
return errmsg;
if (s->srm_confname) {
if (s->access_confname) {
return NULL;
return errmsg;
const char *arg)
while (*arg) {
return NULL;
return err;
return NULL;
return err;
return NULL;
char *arg)
return err;
return NULL;
int port;
return err;
return NULL;
char *arg)
return err;
return NULL;
return err;
return NULL;
return err;
return NULL;
char *arg)
return err;
return NULL;
return err;
return NULL;
return err;
return NULL;
return err;
return NULL;
char *arg)
return err;
return NULL;
return err;
return NULL;
return err;
return NULL;
char *arg)
return err;
return NULL;
return NULL;
char *str;
return err;
return NULL;
&core_module);
return NULL;
return err;
return err;
return NULL;
int lim;
return err;
if (lim < 0) {
return NULL;
char *arg)
int lim;
return err;
if (lim < 0) {
NULL);
return NULL;
int lim;
return err;
if (lim < 0) {
NULL);
return NULL;
char *arg)
return err;
* Instead we have an idiotic define in httpd.h that prevents
return NULL;
#ifdef WIN32
char *arg)
return NULL;
#ifdef GPROF
NULL },
#ifdef _OSD_POSIX
#ifdef WIN32
{ NULL }
if (r->proxyreq) {
return HTTP_FORBIDDEN;
return BAD_REQUEST;
NULL);
NULL);
return OK;
core_dir_config *d =
#ifdef USE_MMAP_FILES
#ifdef CHARSET_EBCDIC
return errstatus;
return NOT_IMPLEMENTED;
return ap_send_http_options(r);
return METHOD_NOT_ALLOWED;
: r->filename);
return HTTP_NOT_FOUND;
return METHOD_NOT_ALLOWED;
return FORBIDDEN;
ap_set_etag(r);
return errstatus;
#ifdef USE_MMAP_FILES
#ifdef CHARSET_EBCDIC
if (!r->header_only) {
if (!rangestatus) {
long length;
return HTTP_INTERNAL_SERVER_ERROR;
#ifdef USE_MMAP_FILES
char *addr;
if (!r->header_only) {
if (!rangestatus) {
long length;
return OK;
static void core_open_logs(ap_context_t *pconf, ap_context_t *plog, ap_context_t *ptemp, server_rec *s)
{ return DEFAULT_HTTP_PORT; }
static void register_hooks(void)