core.c revision 23851fdc3ee2eac45ebb85f400a5d719656dfa22
f743002678eb67b99bbc29fee116b65d9530fec0wrowe/* ====================================================================
80833bb9a1bf25dcf19e814438a4b311d2e1f4cffuankg * The Apache Software License, Version 1.1
7b7430e701e9a31ce809da7c220bb8dfcf68c86etrawick * Copyright (c) 2000-2001 The Apache Software Foundation. All rights
7b7430e701e9a31ce809da7c220bb8dfcf68c86etrawick * reserved.
ccc20788c1e5fc973f36df634399c89acb70deaejerenkrantz * Redistribution and use in source and binary forms, with or without
ccc20788c1e5fc973f36df634399c89acb70deaejerenkrantz * modification, are permitted provided that the following conditions
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin * 1. Redistributions of source code must retain the above copyright
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin * notice, this list of conditions and the following disclaimer.
60998c490ad3334eb07ae63b23b479ac564dec94kbrand * 2. Redistributions in binary form must reproduce the above copyright
60998c490ad3334eb07ae63b23b479ac564dec94kbrand * notice, this list of conditions and the following disclaimer in
60998c490ad3334eb07ae63b23b479ac564dec94kbrand * the documentation and/or other materials provided with the
60998c490ad3334eb07ae63b23b479ac564dec94kbrand * distribution.
d522f82d7ada07a0cedb8dc6b71eacf3477d7188trawick * 3. The end-user documentation included with the redistribution,
d522f82d7ada07a0cedb8dc6b71eacf3477d7188trawick * if any, must include the following acknowledgment:
1e1539a1e7d64b1af92636b81aac5aa50ee3163bminfrin * "This product includes software developed by the
1e1539a1e7d64b1af92636b81aac5aa50ee3163bminfrin * Apache Software Foundation (http://www.apache.org/)."
1e1539a1e7d64b1af92636b81aac5aa50ee3163bminfrin * Alternately, this acknowledgment may appear in the software itself,
273e512f20f262e5e2aa8e0e83371d1929fb76adjkaluza * if and wherever such third-party acknowledgments normally appear.
273e512f20f262e5e2aa8e0e83371d1929fb76adjkaluza * 4. The names "Apache" and "Apache Software Foundation" must
efe780dcf13b2b95effabf897d694d8f23feac74trawick * not be used to endorse or promote products derived from this
461dfe8009c65efd6ce168576ba872eac8d0ed4fcovener * software without prior written permission. For written
461dfe8009c65efd6ce168576ba872eac8d0ed4fcovener * permission, please contact apache@apache.org.
81849cd8925f6ffaf57412aaaac8a6df0d33cbb6covener * 5. Products derived from this software may not be called "Apache",
81849cd8925f6ffaf57412aaaac8a6df0d33cbb6covener * nor may "Apache" appear in their name, without prior written
81849cd8925f6ffaf57412aaaac8a6df0d33cbb6covener * permission of the Apache Software Foundation.
c8e4ae58e7b9eb27e5158d6980770d5064c50ba7trawick * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
c8e4ae58e7b9eb27e5158d6980770d5064c50ba7trawick * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
c8e4ae58e7b9eb27e5158d6980770d5064c50ba7trawick * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
c8e4ae58e7b9eb27e5158d6980770d5064c50ba7trawick * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
fe83f60b41477b14a37edcfcd1f7f5c5a1ebfe44minfrin * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
fe83f60b41477b14a37edcfcd1f7f5c5a1ebfe44minfrin * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
fe83f60b41477b14a37edcfcd1f7f5c5a1ebfe44minfrin * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
7f6bfe455bd605a6401d2fcc9423972a24266b16jim * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
7f6bfe455bd605a6401d2fcc9423972a24266b16jim * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
7f6bfe455bd605a6401d2fcc9423972a24266b16jim * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
993d1261a278d7322bccef219101220b7b4fb8c5jkaluza * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
993d1261a278d7322bccef219101220b7b4fb8c5jkaluza * SUCH DAMAGE.
993d1261a278d7322bccef219101220b7b4fb8c5jkaluza * ====================================================================
3b995de5609b15115a0764e6979ba43071a2988fjim * This software consists of voluntary contributions made by many
3b995de5609b15115a0764e6979ba43071a2988fjim * individuals on behalf of the Apache Software Foundation. For more
ba050a6f942b9fa0e81ed73437588005c569655ccovener * information on the Apache Software Foundation, please see
ba050a6f942b9fa0e81ed73437588005c569655ccovener * Portions of this software are based upon public domain software
ba050a6f942b9fa0e81ed73437588005c569655ccovener * originally written at the National Center for Supercomputing Applications,
ba050a6f942b9fa0e81ed73437588005c569655ccovener * University of Illinois, Urbana-Champaign.
33124689065ade0dfc8c54d8ebb734f9439cb89btrawick#include "http_protocol.h" /* For index_of_response(). Grump. */
9b0076ddd1103e5fa9c1f9bafde4b06ce244fbaecovener#include "http_main.h" /* For the default_handler below... */
c4e8006db0cf457c68876d7d4c30dcc451d8cba7jkaluza/* LimitXMLRequestBody handling */
d8a6de5eec06d4136839c8f7a56a6ab5acd2d3behumbedooh/* Server core module... This module provides support for really basic
6e1e45624d6f32110383bb0bd06c254c1dba8123humbedooh * server operations, including options and commands which control the
77ca16c5676da23155311e13cee61e7eaba9fa3ejailletc * operation of other modules. Consider this the bureaucracy module.
77ca16c5676da23155311e13cee61e7eaba9fa3ejailletc * The core module also defines handlers, etc., do handle just enough
77ca16c5676da23155311e13cee61e7eaba9fa3ejailletc * to allow a server with the core module ONLY to actually serve documents
921d32d80d8271da08f12fc374a69cb36d1d63b3covener * (though it slaps DefaultType on all of 'em); this was useful in testing,
921d32d80d8271da08f12fc374a69cb36d1d63b3covener * but may not be worth preserving.
3e097af23e40c45aa32602545155f0964ab5c69dcovener * This file could almost be mod_core.c, except for the stuff which affects
3e097af23e40c45aa32602545155f0964ab5c69dcovener * the http_conf_globals.
faea99bb676ec50ece38da6b1879aa37546483a2covenerstatic void *create_core_dir_config(apr_pool_t *a, char *dir)
344f755169e100ea8ce51e847a0bf30a13b46917covener conf = (core_dir_config *)apr_pcalloc(a, sizeof(core_dir_config));
4d12805e6c18253040223ea637acd6b3b3c18f60jorton conf->d_is_fnmatch = conf->d ? (apr_is_fnmatch(conf->d) != 0) : 0;
4d12805e6c18253040223ea637acd6b3b3c18f60jorton conf->d_components = conf->d ? ap_count_dirs(conf->d) : 0;
cb666b29f81df1d11d65002250153353568021fccovener conf->use_canonical_name = USE_CANONICAL_NAME_UNSET;
6a80c3c6f4b8ea7ba5e89402b8b779b09ce020e0covener conf->do_rfc1413 = DEFAULT_RFC1413 | 2; /* set bit 1 to indicate default */
1f50dc34ae069adeed20b2986e5ffdefa5c410e0covener#if defined(RLIMIT_DATA) || defined(RLIMIT_VMEM) || defined(RLIMIT_AS)
986f3ea2c314d4d4b3b937149853a0f23f6119aaminfrin conf->sec = apr_array_make(a, 2, sizeof(ap_conf_vector_t *));
65a4e663b82f8bce28ac22ab2edfd7502de36998sf conf->script_interpreter_source = INTERPRETER_SOURCE_UNSET;
74e7f6c55fd67b10cb400b3f6d1dc718a303d944minfrin conf->add_default_charset = ADD_DEFAULT_CHARSET_UNSET;
74e7f6c55fd67b10cb400b3f6d1dc718a303d944minfrin conf->add_default_charset_name = DEFAULT_ADD_DEFAULT_CHARSET_NAME;
a511a29faf2ff7ead3b67680154a624effb31aafminfrin conf->output_filters = apr_array_make(a, 2, sizeof(void *));
a511a29faf2ff7ead3b67680154a624effb31aafminfrin conf->input_filters = apr_array_make(a, 2, sizeof(void *));
a511a29faf2ff7ead3b67680154a624effb31aafminfrin return (void *)conf;
63921358ef93fcb41bc71d9894221ba3d7fbb87bminfrinstatic void *merge_core_dir_configs(apr_pool_t *a, void *basev, void *newv)
6d601599d3d65df0410eae6e573e75b2dbfb1fb4minfrin conf = (core_dir_config *)apr_palloc(a, sizeof(core_dir_config));
4c02bab56a528a180bbe394d8b6e6fd9c1a3ac1esf memcpy((char *)conf, (const char *)base, sizeof(core_dir_config));
684e0cfc200f66287a93bbd1708d1dd8a92a7eefcovener memcpy(conf->response_code_strings, base->response_code_strings,
684e0cfc200f66287a93bbd1708d1dd8a92a7eefcovener sizeof(*conf->response_code_strings) * RESPONSE_CODES);
ef82e8fa164e0a1f8b813f7deb6b7ead96018c94niq /* there was no explicit setting of new->opts, so we merge
ef82e8fa164e0a1f8b813f7deb6b7ead96018c94niq * preserve the invariant (opts_add & opts_remove) == 0
413ee814748f37be168ff12407fa6dba0ceeabe6trawick conf->opts_add = (conf->opts_add & ~new->opts_remove) | new->opts_add;
eafcc0ebf263d0ba69855b6e10958c4c1a2361bdsf conf->opts = (conf->opts & ~conf->opts_remove) | conf->opts_add;
eafcc0ebf263d0ba69855b6e10958c4c1a2361bdsf if ((base->opts & OPT_INCNOEXEC) && (new->opts & OPT_INCLUDES)) {
eafcc0ebf263d0ba69855b6e10958c4c1a2361bdsf conf->opts = (conf->opts & ~OPT_INCNOEXEC) | OPT_INCLUDES;
d7ffd2da16d58b1a0de212e4d56f7aebb72bef26sf /* otherwise we just copy, because an explicit opts setting
d7ffd2da16d58b1a0de212e4d56f7aebb72bef26sf * overrides all earlier +/- modifiers
f6b9c755a0b793e8a3a3aebd327ca20a86478117sf memcpy(conf->response_code_strings, new->response_code_strings,
85eacfc96a04547ef25aabbc06440039715084c2jorton for (i = 0; i < RESPONSE_CODES; ++i) {
79c5787b92ac5f0e1cc82393816c77a006399316trawick if (new->hostname_lookups != HOSTNAME_LOOKUP_UNSET) {
7b395e4e878c28a4784919cfd2e704ddd14a3390jorton if (new->use_canonical_name != USE_CANONICAL_NAME_UNSET) {
3e4e54d4e3fc0123c63d57aa84ac7ad7a8c73ff8jorton#if defined(RLIMIT_DATA) || defined(RLIMIT_VMEM) || defined(RLIMIT_AS)
6249dfa569d3b4f1f539665b979a80c6e335d93etrawick if (new->script_interpreter_source != INTERPRETER_SOURCE_UNSET) {
6249dfa569d3b4f1f539665b979a80c6e335d93etrawick conf->script_interpreter_source = new->script_interpreter_source;
74499a117b3b2cd9666715a14f90c0e5d1a4ee8ajim if (new->add_default_charset != ADD_DEFAULT_CHARSET_UNSET) {
cfa64348224b66dd1c9979b809406c4d15b1c137fielding conf->add_default_charset = new->add_default_charset;
cfa64348224b66dd1c9979b809406c4d15b1c137fielding conf->add_default_charset_name = new->add_default_charset_name;
return (void*)conf;
#ifdef GPROF
return (void *)conf;
return conf;
&core_module);
&core_module);
#if defined(HAVE_DRIVE_LETTERS)
struct reorder_sort_rec {
int orig_index;
int nelts;
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;
while (sa) {
#if APR_HAVE_IPV6
int hostname_lookups;
*str_is_ip = 0;
if (dir_config) {
return NULL;
return NULL;
&core_module);
return NULL;
core_dir_config *d;
&core_module);
core_dir_config *d =
if (r->hostname) {
return port;
request_rec *r)
core_dir_config *d =
return d->limit_req_body;
#ifdef WIN32
char* relativepath,
char **value)
if (size) {
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]) {
char **xmethod;
if (!tog) {
return errmsg;
#ifdef WIN32
#define USE_ICASE 0
const char *errmsg;
return err;
#if defined(HAVE_UNC_PATHS)
return errmsg;
conf->r = r;
return NULL;
const char *errmsg;
return err;
return errmsg;
conf->r = r;
return NULL;
const char *errmsg;
return err;
if (!old_path) {
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;
int port;
return err;
return NULL;
const char *arg)
return err;
return NULL;
const char *arg)
return err;
return NULL;
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_size_t i = 0;
*nbytes = 0;
bytes_written += n;
return rv;
*nbytes += n;
if (n < cnt) {
return APR_SUCCESS;
#if APR_HAS_SENDFILE
#ifdef AP_DEBUG
flags);
tmplen = 0;
file_bytes_left = 0;
file_offset = 0;
tmplen = 0;
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;
apr_bucket *e;
core_dir_config *d;
int errstatus;
int bld_content_md5;
return DECLINED;
&core_module);
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;
if (bld_content_md5) {
e = apr_bucket_eos_create();
static int core_input_filter(ap_filter_t *f, apr_bucket_brigade *b, ap_input_mode_t mode, apr_size_t *readbytes)
apr_bucket *e;
APR_BRIGADE_INSERT_TAIL(b, e);
return APR_SUCCESS;
return APR_EOF;
typedef struct CORE_OUTPUT_FILTER_CTX {
conn_rec *c = f->c;
if (ctx->b) {
b = ctx->b;
apr_bucket *e;
APR_BRIGADE_FOREACH(e, b) {
else if (APR_BUCKET_IS_FILE(e)
if (fd) {
const char *str;
apr_size_t n;
nbytes += n;
if (!fd) {
nvec++;
if (APR_BUCKET_IS_EOS(e)) {
const char *str;
apr_size_t n;
return APR_SUCCESS;
if (fd) {
#if APR_HAS_SENDFILE
if (nvec) {
if (nvec_trailers) {
#if APR_HAS_SENDFILE
if (!c->keepalive) {
* to loop on apr_file_read/apr_send to send the file. Our Windows
if (more)
return rv;
b = more;
return APR_SUCCESS;
&core_module);
if (r->main) {
return OK;