http_core.c revision 48d7c43629323c8d5ee9f7bd0d194de0a376b391
0b152383e04dbeb10dba29bcdfaa0981e4d9df27Simon Ulbricht/* ====================================================================
0b152383e04dbeb10dba29bcdfaa0981e4d9df27Simon Ulbricht * The Apache Software License, Version 1.1
0b152383e04dbeb10dba29bcdfaa0981e4d9df27Simon Ulbricht * Copyright (c) 2000 The Apache Software Foundation. All rights
0b152383e04dbeb10dba29bcdfaa0981e4d9df27Simon Ulbricht * Redistribution and use in source and binary forms, with or without
0b152383e04dbeb10dba29bcdfaa0981e4d9df27Simon Ulbricht * modification, are permitted provided that the following conditions
0b152383e04dbeb10dba29bcdfaa0981e4d9df27Simon Ulbricht * 1. Redistributions of source code must retain the above copyright
0b152383e04dbeb10dba29bcdfaa0981e4d9df27Simon Ulbricht * notice, this list of conditions and the following disclaimer.
2643008447e30b6025f742eb6a661f38be756b1eSimon Ulbricht * 2. Redistributions in binary form must reproduce the above copyright
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht * notice, this list of conditions and the following disclaimer in
2643008447e30b6025f742eb6a661f38be756b1eSimon Ulbricht * the documentation and/or other materials provided with the
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht * distribution.
d815d2b83e945875100ceca322ebd50d96714206Simon Ulbricht * 3. The end-user documentation included with the redistribution,
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht * if any, must include the following acknowledgment:
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht * "This product includes software developed by the
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht * Apache Software Foundation (http://www.apache.org/)."
d815d2b83e945875100ceca322ebd50d96714206Simon Ulbricht * Alternately, this acknowledgment may appear in the software itself,
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht * if and wherever such third-party acknowledgments normally appear.
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht * 4. The names "Apache" and "Apache Software Foundation" must
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht * not be used to endorse or promote products derived from this
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht * software without prior written permission. For written
6150196e8d99f7161a622fdc1a872fecd378195fSimon Ulbricht * permission, please contact apache@apache.org.
3209c34f23fb83a86fbbdd6501db6d4bfb949a57Simon Ulbricht * 5. Products derived from this software may not be called "Apache",
2643008447e30b6025f742eb6a661f38be756b1eSimon Ulbricht * nor may "Apache" appear in their name, without prior written
d815d2b83e945875100ceca322ebd50d96714206Simon Ulbricht * permission of the Apache Software Foundation.
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2643008447e30b6025f742eb6a661f38be756b1eSimon Ulbricht * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht * SUCH DAMAGE.
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht * ====================================================================
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht * This software consists of voluntary contributions made by many
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht * individuals on behalf of the Apache Software Foundation. For more
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht * information on the Apache Software Foundation, please see
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht * Portions of this software are based upon public domain software
6150196e8d99f7161a622fdc1a872fecd378195fSimon Ulbricht * originally written at the National Center for Supercomputing Applications,
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht * University of Illinois, Urbana-Champaign.
1651c7f5055453e18a8c34f96c333e2aa702a34eSimon Ulbricht#include "http_protocol.h" /* For index_of_response(). Grump. */
1651c7f5055453e18a8c34f96c333e2aa702a34eSimon Ulbricht#include "http_main.h" /* For the default_handler below... */
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht/* Allow Apache to use ap_mmap */
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht/* mmap support for static files based on ideas from John Heidemann's
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht * patch against 1.0.5. See
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht * <http://www.isi.edu/~johnh/SOFTWARE/APACHE/index.html>.
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht/* Files have to be at least this big before they're mmap()d. This is to deal
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht * with systems where the expense of doing an mmap() and an munmap() outweighs
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht * the benefit for small files. It shouldn't be set lower than 1.
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht #endif /* SUNOS4 */
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht#endif /* MMAP_THRESHOLD */
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht#endif /* USE_MMAP_FILES */
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht/* Server core module... This module provides support for really basic
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht * server operations, including options and commands which control the
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht * operation of other modules. Consider this the bureaucracy module.
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht * The core module also defines handlers, etc., do handle just enough
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht * to allow a server with the core module ONLY to actually serve documents
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht * (though it slaps DefaultType on all of 'em); this was useful in testing,
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht * but may not be worth preserving.
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht * This file could almost be mod_core.c, except for the stuff which affects
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht * the http_conf_globals.
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbrichtstatic void *create_core_dir_config(ap_pool_t *a, char *dir)
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht conf = (core_dir_config *)ap_pcalloc(a, sizeof(core_dir_config));
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht conf->d_is_fnmatch = conf->d ? (ap_is_fnmatch(conf->d) != 0) : 0;
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht conf->d_components = conf->d ? ap_count_dirs(conf->d) : 0;
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht conf->opts = dir ? OPT_UNSET : OPT_UNSET|OPT_ALL;
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht conf->opts_add = conf->opts_remove = OPT_NONE;
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht conf->override = dir ? OR_UNSET : OR_UNSET|OR_ALL;
1651c7f5055453e18a8c34f96c333e2aa702a34eSimon Ulbricht conf->use_canonical_name = USE_CANONICAL_NAME_UNSET;
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht conf->hostname_lookups = HOSTNAME_LOOKUP_UNSET;
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht conf->do_rfc1413 = DEFAULT_RFC1413 | 2; /* set bit 1 to indicate default */
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht#if defined(RLIMIT_DATA) || defined(RLIMIT_VMEM) || defined(RLIMIT_AS)
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht conf->sec = ap_make_array(a, 2, sizeof(void *));
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht conf->script_interpreter_source = INTERPRETER_SOURCE_UNSET;
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht conf->add_default_charset = ADD_DEFAULT_CHARSET_UNSET;
1651c7f5055453e18a8c34f96c333e2aa702a34eSimon Ulbricht conf->add_default_charset_name = DEFAULT_ADD_DEFAULT_CHARSET_NAME;
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht return (void *)conf;
1651c7f5055453e18a8c34f96c333e2aa702a34eSimon Ulbrichtstatic void *merge_core_dir_configs(ap_pool_t *a, void *basev, void *newv)
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht core_dir_config *base = (core_dir_config *)basev;
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht core_dir_config *new = (core_dir_config *)newv;
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht conf = (core_dir_config *)ap_palloc(a, sizeof(core_dir_config));
1651c7f5055453e18a8c34f96c333e2aa702a34eSimon Ulbricht memcpy((char *)conf, (const char *)base, sizeof(core_dir_config));
1651c7f5055453e18a8c34f96c333e2aa702a34eSimon Ulbricht ap_palloc(a, sizeof(*conf->response_code_strings)
1651c7f5055453e18a8c34f96c333e2aa702a34eSimon Ulbricht memcpy(conf->response_code_strings, base->response_code_strings,
1651c7f5055453e18a8c34f96c333e2aa702a34eSimon Ulbricht sizeof(*conf->response_code_strings) * RESPONSE_CODES);
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht /* there was no explicit setting of new->opts, so we merge
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht * preserve the invariant (opts_add & opts_remove) == 0
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht conf->opts_add = (conf->opts_add & ~new->opts_remove) | new->opts_add;
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht conf->opts_remove = (conf->opts_remove & ~new->opts_add)
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht conf->opts = (conf->opts & ~conf->opts_remove) | conf->opts_add;
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht if ((base->opts & OPT_INCNOEXEC) && (new->opts & OPT_INCLUDES)) {
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht conf->opts = (conf->opts & ~OPT_INCNOEXEC) | OPT_INCLUDES;
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht /* otherwise we just copy, because an explicit opts setting
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht * overrides all earlier +/- modifiers
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht conf->ap_default_type = new->ap_default_type;
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht sizeof(*conf->response_code_strings) * RESPONSE_CODES);
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht memcpy(conf->response_code_strings, new->response_code_strings,
1651c7f5055453e18a8c34f96c333e2aa702a34eSimon Ulbricht sizeof(*conf->response_code_strings) * RESPONSE_CODES);
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht for (i = 0; i < RESPONSE_CODES; ++i) {
98e4e0125755acbcd5e0729556cd2bcfc4ee3973Simon Ulbricht if (new->hostname_lookups != HOSTNAME_LOOKUP_UNSET) {
98e4e0125755acbcd5e0729556cd2bcfc4ee3973Simon Ulbricht conf->hostname_lookups = new->hostname_lookups;
98e4e0125755acbcd5e0729556cd2bcfc4ee3973Simon Ulbricht if (new->use_canonical_name != USE_CANONICAL_NAME_UNSET) {
212a71a59d30f82bc1d22cc9cfd6b36968afb4f2Simon Ulbricht conf->use_canonical_name = new->use_canonical_name;
98e4e0125755acbcd5e0729556cd2bcfc4ee3973Simon Ulbricht#if defined(RLIMIT_DATA) || defined(RLIMIT_VMEM) || defined(RLIMIT_AS)
98e4e0125755acbcd5e0729556cd2bcfc4ee3973Simon Ulbricht conf->sec = ap_append_arrays(a, base->sec, new->sec);
212a71a59d30f82bc1d22cc9cfd6b36968afb4f2Simon Ulbricht if (new->script_interpreter_source != INTERPRETER_SOURCE_UNSET) {
212a71a59d30f82bc1d22cc9cfd6b36968afb4f2Simon Ulbricht conf->script_interpreter_source = new->script_interpreter_source;
98e4e0125755acbcd5e0729556cd2bcfc4ee3973Simon Ulbricht if (new->server_signature != srv_sig_unset) {
369771f5d48a40eda134026b1f45f63b2c00bdb8Simon Ulbricht conf->server_signature = new->server_signature;
return (void*)conf;
#ifdef GPROF
return (void *)conf;
return conf;
&core_module);
&core_module);
#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.
const char *what)
return dirp;
return NULL;
unsigned forbidden)
return NULL;
return err;
return NULL;
#ifdef GPROF
return err;
return NULL;
return err;
return NULL;
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]) {
return errmsg;
#ifdef WIN32
#define USE_ICASE 0
const char *errmsg;
return err;
&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 *arg)
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;
char *endp;
int not = 0;
arg++;
const char *retval;
return retval;
/* httpd.conf commands... beginning with the <VirtualHost> business */
const char *errmsg;
return err;
if (errmsg) {
return errmsg;
s->lookup_defaults);
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;
static int version_locked = 0;
version_locked = 0;
return APR_SUCCESS;
if (! version_locked) {
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;
#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;
#ifdef GPROF
TAKE1, "The name of the default charset to add to any Content-Type without one or 'Off' to disable" },
#ifdef _OSD_POSIX
#ifdef WIN32
#ifdef RLIMIT_CPU
#ifdef RLIMIT_NPROC
{ NULL }
if (r->proxyreq) {
return HTTP_FORBIDDEN;
return BAD_REQUEST;
NULL);
NULL);
return OK;
core_dir_config *d =
#ifdef USE_MMAP_FILES
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 CHARSET_EBCDIC
ap_checkconv(r);
#ifdef USE_MMAP_FILES
#ifdef APACHE_XLATE
if (!r->header_only) {
if (!rangestatus) {
long length;
return HTTP_INTERNAL_SERVER_ERROR;
#ifdef USE_MMAP_FILES
char *addr;
#ifdef APACHE_XLATE
if (!r->header_only) {
if (!rangestatus) {
long length;
return OK;
{ return DEFAULT_HTTP_PORT; }
static void register_hooks(void)