http_core.c revision cd5c0afc86ca2eb23d6d12e14590e03cf2f80450
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering/* ====================================================================
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering * The Apache Software License, Version 1.1
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering * Copyright (c) 2000 The Apache Software Foundation. All rights
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering * Redistribution and use in source and binary forms, with or without
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering * modification, are permitted provided that the following conditions
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering * 1. Redistributions of source code must retain the above copyright
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering * notice, this list of conditions and the following disclaimer.
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering * 2. Redistributions in binary form must reproduce the above copyright
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering * notice, this list of conditions and the following disclaimer in
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering * the documentation and/or other materials provided with the
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering * distribution.
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering * 3. The end-user documentation included with the redistribution,
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering * if any, must include the following acknowledgment:
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering * "This product includes software developed by the
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering * Apache Software Foundation (http://www.apache.org/)."
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering * Alternately, this acknowledgment may appear in the software itself,
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering * if and wherever such third-party acknowledgments normally appear.
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering * 4. The names "Apache" and "Apache Software Foundation" must
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering * not be used to endorse or promote products derived from this
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering * software without prior written permission. For written
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering * permission, please contact apache@apache.org.
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering * 5. Products derived from this software may not be called "Apache",
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering * nor may "Apache" appear in their name, without prior written
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering * permission of the Apache Software Foundation.
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering * SUCH DAMAGE.
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering * ====================================================================
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering * This software consists of voluntary contributions made by many
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering * individuals on behalf of the Apache Software Foundation. For more
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering * information on the Apache Software Foundation, please see
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering * Portions of this software are based upon public domain software
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering * originally written at the National Center for Supercomputing Applications,
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering * University of Illinois, Urbana-Champaign.
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering#include "http_protocol.h" /* For index_of_response(). Grump. */
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering#include "http_main.h" /* For the default_handler below... */
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering/* Allow Apache to use ap_mmap */
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering/* mmap support for static files based on ideas from John Heidemann's
b8bde11658366290521e3d03316378b482600323Jan Engelhardt * patch against 1.0.5. See
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering * <http://www.isi.edu/~johnh/SOFTWARE/APACHE/index.html>.
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering/* Files have to be at least this big before they're mmap()d. This is to deal
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering * with systems where the expense of doing an mmap() and an munmap() outweighs
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering * the benefit for small files. It shouldn't be set lower than 1.
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering #endif /* SUNOS4 */
dca348bcbb462305864526c587495a14a76bfcdeJan Engelhardt#endif /* MMAP_THRESHOLD */
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering#endif /* USE_MMAP_FILES */
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering/* LimitXMLRequestBody handling */
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering#define AP_DEFAULT_LIMIT_XML_BODY ((size_t)1000000)
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering/* Server core module... This module provides support for really basic
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering * server operations, including options and commands which control the
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering * operation of other modules. Consider this the bureaucracy module.
b8bde11658366290521e3d03316378b482600323Jan Engelhardt * The core module also defines handlers, etc., do handle just enough
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering * to allow a server with the core module ONLY to actually serve documents
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering * (though it slaps DefaultType on all of 'em); this was useful in testing,
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering * but may not be worth preserving.
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering * This file could almost be mod_core.c, except for the stuff which affects
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering * the http_conf_globals.
a6278b88305b237b02eabff0d870b57fe851822dLennart Poetteringstatic void *create_core_dir_config(ap_pool_t *a, char *dir)
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering conf = (core_dir_config *)ap_pcalloc(a, sizeof(core_dir_config));
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek if (!dir || dir[strlen(dir) - 1] == '/') {
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering else if (strncmp(dir, "proxy:", 6) == 0) {
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering conf->d_is_fnmatch = conf->d ? (ap_is_fnmatch(conf->d) != 0) : 0;
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek conf->d_components = conf->d ? ap_count_dirs(conf->d) : 0;
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering conf->opts = dir ? OPT_UNSET : OPT_UNSET|OPT_ALL;
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering conf->opts_add = conf->opts_remove = OPT_NONE;
a6278b88305b237b02eabff0d870b57fe851822dLennart Poettering conf->override = dir ? OR_UNSET : OR_UNSET|OR_ALL;
#ifdef RLIMIT_CPU
#ifdef RLIMIT_NPROC
#ifdef WIN32
return (void *)conf;
* RESPONSE_CODES);
for (i = 0; i < RESPONSE_CODES; ++i) {
#ifdef RLIMIT_CPU
#ifdef RLIMIT_NPROC
#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
return result;
if (size) {
return result;
int size;
int result;
char *buffer;
if (!ext)
return NULL;
&hkeyType);
return NULL;
if (cmdOfName) {
if (cmdOfName)
return NULL;
++*arguments;
return buffer;
char** interpreter,
char** arguments)
core_dir_config *d;
&core_module);
if (!exename) {
if (!exename) {
exename++;
if (comspec) {
return eFileTypeSCRIPT;
return eFileTypeUNKNOWN;
if (*interpreter)
return eFileTypeSCRIPT;
return eFileTypeUNKNOWN;
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;
const char *arg)
return err;
return NULL;
#ifdef GPROF
return err;
return NULL;
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]) {
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 *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;
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;
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;
#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 USE_MMAP_FILES
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 CHARSET_EBCDIC
ap_checkconv(r);
#ifdef USE_MMAP_FILES
#ifdef APACHE_XLATE
if (!r->header_only) {
if (!rangestatus) {
return HTTP_INTERNAL_SERVER_ERROR;
#ifdef USE_MMAP_FILES
unsigned char *addr;
#ifdef APACHE_XLATE
if (!r->header_only) {
if (!rangestatus) {
long length;
return OK;
{ return DEFAULT_HTTP_PORT; }
static void register_hooks(void)