http_core.c revision 3a9bc6532fbe8439fc748d8ffedb87415904d16a
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering/* ====================================================================
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering * Copyright (c) 1995-2000 The Apache Software Foundation. All rights reserved.
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering * Redistribution and use in source and binary forms, with or without
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering * modification, are permitted provided that the following conditions
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering * 1. Redistributions of source code must retain the above copyright
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering * notice, this list of conditions and the following disclaimer.
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering * 2. Redistributions in binary form must reproduce the above copyright
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering * notice, this list of conditions and the following disclaimer in
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering * the documentation and/or other materials provided with the
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering * distribution.
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering * 3. All advertising materials mentioning features or use of this
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering * software must display the following acknowledgment:
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering * "This product includes software developed by the Apache Software Foundation
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering * for use in the Apache HTTP server project (http://www.apache.org/)."
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering * 4. The names "Apache Server" and "Apache Software Foundation" must not be used to
dc3a1b76a6a6f9dfe9b451f534587251b50a0685Lennart Poettering * endorse or promote products derived from this software without
dc3a1b76a6a6f9dfe9b451f534587251b50a0685Lennart Poettering * prior written permission. For written permission, please contact
e8e581bf256b8c0fbd430935af79fa0e8ee570a1Zbigniew Jędrzejewski-Szmek * apache@apache.org.
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering * 5. Products derived from this software may not be called "Apache"
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering * nor may "Apache" appear in their names without prior written
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering * permission of the Apache Software Foundation.
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek * 6. Redistributions of any form whatsoever must retain the following
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering * acknowledgment:
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering * "This product includes software developed by the Apache Software Foundation
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering * for use in the Apache HTTP server project (http://www.apache.org/)."
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering * THIS SOFTWARE IS PROVIDED BY THE Apache Software Foundation ``AS IS'' AND ANY
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE Apache Software Foundation OR
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering * OF THE POSSIBILITY OF SUCH DAMAGE.
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering * ====================================================================
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering * This software consists of voluntary contributions made by many
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering * individuals on behalf of the Apache Software Foundation and was originally based
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering * on public domain software written at the National Center for
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering * Supercomputing Applications, University of Illinois, Urbana-Champaign.
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering * For more information on the Apache Software Foundation and the Apache HTTP server
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering * project, please see <http://www.apache.org/>.
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering#include "http_protocol.h" /* For index_of_response(). Grump. */
af9792ac7f39354f80e9006c42c2400c5e41c447Lennart Poettering#include "http_main.h" /* For the default_handler below... */
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering/* Allow Apache to use ap_mmap */
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek/* mmap support for static files based on ideas from John Heidemann's
dc3a1b76a6a6f9dfe9b451f534587251b50a0685Lennart Poettering * patch against 1.0.5. See
19adb8a3204fefd91411b5f0f350c8bc6bcf75feZbigniew Jędrzejewski-Szmek * <http://www.isi.edu/~johnh/SOFTWARE/APACHE/index.html>.
dc3a1b76a6a6f9dfe9b451f534587251b50a0685Lennart Poettering/* Files have to be at least this big before they're mmap()d. This is to deal
7801356442578ff6e1c65844eb9e65c819af4660Zbigniew Jędrzejewski-Szmek * with systems where the expense of doing an mmap() and an munmap() outweighs
af9792ac7f39354f80e9006c42c2400c5e41c447Lennart Poettering * the benefit for small files. It shouldn't be set lower than 1.
dc3a1b76a6a6f9dfe9b451f534587251b50a0685Lennart Poettering #endif /* SUNOS4 */
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering#endif /* MMAP_THRESHOLD */
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering#endif /* USE_MMAP_FILES */
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering/* Server core module... This module provides support for really basic
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering * server operations, including options and commands which control the
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering * operation of other modules. Consider this the bureaucracy module.
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering * The core module also defines handlers, etc., do handle just enough
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering * to allow a server with the core module ONLY to actually serve documents
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering * (though it slaps DefaultType on all of 'em); this was useful in testing,
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering * but may not be worth preserving.
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering * This file could almost be mod_core.c, except for the stuff which affects
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering * the http_conf_globals.
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poetteringstatic void *create_core_dir_config(ap_context_t *a, char *dir)
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering conf = (core_dir_config *)ap_pcalloc(a, sizeof(core_dir_config));
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering if (!dir || dir[strlen(dir) - 1] == '/') {
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering else if (strncmp(dir, "proxy:", 6) == 0) {
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering conf->d_is_fnmatch = conf->d ? (ap_is_fnmatch(conf->d) != 0) : 0;
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering conf->d_components = conf->d ? ap_count_dirs(conf->d) : 0;
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering conf->opts = dir ? OPT_UNSET : OPT_UNSET|OPT_ALL;
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering conf->opts_add = conf->opts_remove = OPT_NONE;
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering conf->override = dir ? OR_UNSET : OR_UNSET|OR_ALL;
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering conf->use_canonical_name = USE_CANONICAL_NAME_UNSET;
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering conf->hostname_lookups = HOSTNAME_LOOKUP_UNSET;
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering conf->do_rfc1413 = DEFAULT_RFC1413 | 2; /* set bit 1 to indicate default */
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering conf->sec = ap_make_array(a, 2, sizeof(void *));
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering conf->script_interpreter_source = INTERPRETER_SOURCE_UNSET;
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering conf->add_default_charset = ADD_DEFAULT_CHARSET_UNSET;
23406ce58aa7142e8df3c5c9e5ac34a01e90e3e0Lennart Poettering conf->add_default_charset_name = DEFAULT_ADD_DEFAULT_CHARSET_NAME;
return (void *)conf;
* RESPONSE_CODES);
for (i = 0; i < RESPONSE_CODES; ++i) {
#ifdef WIN32
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.
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;
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
TAKE1, "The name of the default charset to add to any Content-Type without one or 'Off' to disable" },
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)