core.c revision ac06e54654494445fd3d39e90bd23b436b4f84cc
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb/* ====================================================================
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * The Apache Software License, Version 1.1
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Copyright (c) 2000-2001 The Apache Software Foundation. All rights
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * reserved.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Redistribution and use in source and binary forms, with or without
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * modification, are permitted provided that the following conditions
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * are met:
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * 1. Redistributions of source code must retain the above copyright
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * notice, this list of conditions and the following disclaimer.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * 2. Redistributions in binary form must reproduce the above copyright
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * notice, this list of conditions and the following disclaimer in
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * the documentation and/or other materials provided with the
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * distribution.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * 3. The end-user documentation included with the redistribution,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * if any, must include the following acknowledgment:
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * "This product includes software developed by the
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Apache Software Foundation (http://www.apache.org/)."
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Alternately, this acknowledgment may appear in the software itself,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * if and wherever such third-party acknowledgments normally appear.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * 4. The names "Apache" and "Apache Software Foundation" must
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * not be used to endorse or promote products derived from this
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * software without prior written permission. For written
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * permission, please contact apache@apache.org.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * 5. Products derived from this software may not be called "Apache",
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * nor may "Apache" appear in their name, without prior written
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * permission of the Apache Software Foundation.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * SUCH DAMAGE.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * ====================================================================
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * This software consists of voluntary contributions made by many
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * individuals on behalf of the Apache Software Foundation. For more
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * information on the Apache Software Foundation, please see
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * <http://www.apache.org/>.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Portions of this software are based upon public domain software
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * originally written at the National Center for Supercomputing Applications,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * University of Illinois, Urbana-Champaign.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "apr.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "apr_strings.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "apr_lib.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "apr_fnmatch.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "apr_hash.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "apr_thread_proc.h" /* for RLIMIT stuff */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#define APR_WANT_IOVEC
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#define APR_WANT_STRFUNC
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#define APR_WANT_MEMFUNC
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "apr_want.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#define CORE_PRIVATE
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "ap_config.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "httpd.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "http_config.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "http_core.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "http_protocol.h" /* For index_of_response(). Grump. */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "http_request.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "http_vhost.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "http_main.h" /* For the default_handler below... */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "http_log.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "rfc1413.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "util_md5.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "http_connection.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "apr_buckets.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "util_filter.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "util_ebcdic.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "mpm.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "mpm_common.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "scoreboard.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "mod_core.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb/* LimitXMLRequestBody handling */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#define AP_LIMIT_UNSET ((long) -1)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#define AP_DEFAULT_LIMIT_XML_BODY ((size_t)1000000)
a2a0abd88b19e042a3eb2a9fa1702c25ad51303dwrowe
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#define AP_MIN_SENDFILE_BYTES (256)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbAPR_HOOK_STRUCT(
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb APR_HOOK_LINK(get_mgmt_items)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b45c1c292ff1fa635004ae81fa691f8cb3cdda85rbbAP_IMPLEMENT_HOOK_RUN_ALL(int, get_mgmt_items,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb (apr_pool_t *p, const char *val, apr_hash_t *ht),
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb (p, val, ht), OK, DECLINED)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
a2a0abd88b19e042a3eb2a9fa1702c25ad51303dwrowe/* Server core module... This module provides support for really basic
a2a0abd88b19e042a3eb2a9fa1702c25ad51303dwrowe * server operations, including options and commands which control the
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * operation of other modules. Consider this the bureaucracy module.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * The core module also defines handlers, etc., do handle just enough
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * to allow a server with the core module ONLY to actually serve documents
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * (though it slaps DefaultType on all of 'em); this was useful in testing,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * but may not be worth preserving.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * This file could almost be mod_core.c, except for the stuff which affects
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * the http_conf_globals.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
c3e342e5b0b9fea6617ee16d2da02c3ef2108126dougmstatic void *create_core_dir_config(apr_pool_t *a, char *dir)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe core_dir_config *conf;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe conf = (core_dir_config *)apr_pcalloc(a, sizeof(core_dir_config));
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe /* conf->r and conf->d[_*] are initialized in */
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe conf->opts = dir ? OPT_UNSET : OPT_UNSET|OPT_ALL;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe conf->opts_add = conf->opts_remove = OPT_NONE;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe conf->override = dir ? OR_UNSET : OR_UNSET|OR_ALL;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe conf->content_md5 = 2;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe conf->use_canonical_name = USE_CANONICAL_NAME_UNSET;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe conf->hostname_lookups = HOSTNAME_LOOKUP_UNSET;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe conf->do_rfc1413 = DEFAULT_RFC1413 | 2; /* set bit 1 to indicate default */
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe conf->satisfy = SATISFY_NOSPEC;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe#ifdef RLIMIT_CPU
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe conf->limit_cpu = NULL;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe#endif
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe#if defined(RLIMIT_DATA) || defined(RLIMIT_VMEM) || defined(RLIMIT_AS)
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe conf->limit_mem = NULL;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe#endif
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe#ifdef RLIMIT_NPROC
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe conf->limit_nproc = NULL;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe#endif
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe conf->limit_req_body = 0;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe conf->limit_xml_body = AP_LIMIT_UNSET;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe conf->sec_file = apr_array_make(a, 2, sizeof(ap_conf_vector_t *));
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe#ifdef WIN32
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe conf->script_interpreter_source = INTERPRETER_SOURCE_UNSET;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe#endif
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe conf->server_signature = srv_sig_unset;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe conf->add_default_charset = ADD_DEFAULT_CHARSET_UNSET;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe conf->add_default_charset_name = DEFAULT_ADD_DEFAULT_CHARSET_NAME;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe conf->output_filters = apr_array_make(a, 2, sizeof(void *));
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe conf->input_filters = apr_array_make(a, 2, sizeof(void *));
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe return (void *)conf;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe}
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowestatic void *merge_core_dir_configs(apr_pool_t *a, void *basev, void *newv)
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe{
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe core_dir_config *base = (core_dir_config *)basev;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe core_dir_config *new = (core_dir_config *)newv;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe core_dir_config *conf;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe int i;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe conf = (core_dir_config *)apr_palloc(a, sizeof(core_dir_config));
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe memcpy((char *)conf, (const char *)base, sizeof(core_dir_config));
4775dfc34c90fada8c7c4d6a57ed8a3114d55c2dtrawick if (base->response_code_strings) {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe conf->response_code_strings =
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe apr_palloc(a, sizeof(*conf->response_code_strings)
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe * RESPONSE_CODES);
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe memcpy(conf->response_code_strings, base->response_code_strings,
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe sizeof(*conf->response_code_strings) * RESPONSE_CODES);
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe }
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe conf->d = new->d;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe conf->d_is_fnmatch = new->d_is_fnmatch;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe conf->d_components = new->d_components;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe conf->r = new->r;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if (new->opts & OPT_UNSET) {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe /* there was no explicit setting of new->opts, so we merge
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe * preserve the invariant (opts_add & opts_remove) == 0
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe */
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe conf->opts_add = (conf->opts_add & ~new->opts_remove) | new->opts_add;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe conf->opts_remove = (conf->opts_remove & ~new->opts_add)
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe | new->opts_remove;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe conf->opts = (conf->opts & ~conf->opts_remove) | conf->opts_add;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe if ((base->opts & OPT_INCNOEXEC) && (new->opts & OPT_INCLUDES)) {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe conf->opts = (conf->opts & ~OPT_INCNOEXEC) | OPT_INCLUDES;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe }
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe }
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe else {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe /* otherwise we just copy, because an explicit opts setting
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe * overrides all earlier +/- modifiers
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe */
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe conf->opts = new->opts;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe conf->opts_add = new->opts_add;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe conf->opts_remove = new->opts_remove;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe }
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe if (!(new->override & OR_UNSET)) {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe conf->override = new->override;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe }
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe if (new->ap_default_type) {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe conf->ap_default_type = new->ap_default_type;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe }
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if (new->ap_auth_type) {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe conf->ap_auth_type = new->ap_auth_type;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe }
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe if (new->ap_auth_name) {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe conf->ap_auth_name = new->ap_auth_name;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe }
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe if (new->ap_requires) {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe conf->ap_requires = new->ap_requires;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe }
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe if (new->response_code_strings) {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe if (conf->response_code_strings == NULL) {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe conf->response_code_strings = apr_palloc(a,
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe sizeof(*conf->response_code_strings) * RESPONSE_CODES);
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe memcpy(conf->response_code_strings, new->response_code_strings,
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe sizeof(*conf->response_code_strings) * RESPONSE_CODES);
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe }
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe else {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe for (i = 0; i < RESPONSE_CODES; ++i) {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe if (new->response_code_strings[i] != NULL) {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe conf->response_code_strings[i]
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe = new->response_code_strings[i];
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe }
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe }
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe }
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe }
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe if (new->hostname_lookups != HOSTNAME_LOOKUP_UNSET) {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe conf->hostname_lookups = new->hostname_lookups;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe }
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe if ((new->do_rfc1413 & 2) == 0) {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe conf->do_rfc1413 = new->do_rfc1413;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe if ((new->content_md5 & 2) == 0) {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe conf->content_md5 = new->content_md5;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if (new->use_canonical_name != USE_CANONICAL_NAME_UNSET) {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe conf->use_canonical_name = new->use_canonical_name;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe#ifdef RLIMIT_CPU
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if (new->limit_cpu) {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe conf->limit_cpu = new->limit_cpu;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe#endif
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe#if defined(RLIMIT_DATA) || defined(RLIMIT_VMEM) || defined(RLIMIT_AS)
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if (new->limit_mem) {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe conf->limit_mem = new->limit_mem;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe#endif
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe#ifdef RLIMIT_NPROC
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if (new->limit_nproc) {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe conf->limit_nproc = new->limit_nproc;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe#endif
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if (new->limit_req_body) {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe conf->limit_req_body = new->limit_req_body;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if (new->limit_xml_body != AP_LIMIT_UNSET)
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe conf->limit_xml_body = new->limit_xml_body;
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe else
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe conf->limit_xml_body = base->limit_xml_body;
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe conf->sec_file = apr_array_append(a, base->sec_file, new->sec_file);
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe if (new->satisfy != SATISFY_NOSPEC) {
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe conf->satisfy = new->satisfy;
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe }
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe
0540a0b469147b52e858587270dba31c2aaa9e09wrowe#ifdef WIN32
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe if (new->script_interpreter_source != INTERPRETER_SOURCE_UNSET) {
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe conf->script_interpreter_source = new->script_interpreter_source;
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe }
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe#endif
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe if (new->server_signature != srv_sig_unset) {
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe conf->server_signature = new->server_signature;
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe }
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe if (new->add_default_charset != ADD_DEFAULT_CHARSET_UNSET) {
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe conf->add_default_charset = new->add_default_charset;
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe if (new->add_default_charset_name) {
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe conf->add_default_charset_name = new->add_default_charset_name;
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe }
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe }
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe conf->output_filters = apr_array_append(a, base->output_filters,
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe new->output_filters);
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe conf->input_filters = apr_array_append(a, base->input_filters,
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe new->input_filters);
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe return (void*)conf;
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe}
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowestatic void *create_core_server_config(apr_pool_t *a, server_rec *s)
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe{
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe core_server_config *conf;
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe int is_virtual = s->is_virtual;
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe conf = (core_server_config *)apr_pcalloc(a, sizeof(core_server_config));
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe#ifdef GPROF
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe conf->gprof_dir = NULL;
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe#endif
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe conf->access_name = is_virtual ? NULL : DEFAULT_ACCESS_FNAME;
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe conf->ap_document_root = is_virtual ? NULL : DOCUMENT_LOCATION;
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe conf->sec_dir = apr_array_make(a, 40, sizeof(ap_conf_vector_t *));
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe conf->sec_url = apr_array_make(a, 40, sizeof(ap_conf_vector_t *));
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe return (void *)conf;
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe}
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowestatic void *merge_core_server_configs(apr_pool_t *p, void *basev, void *virtv)
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe{
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe core_server_config *base = (core_server_config *)basev;
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe core_server_config *virt = (core_server_config *)virtv;
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe core_server_config *conf;
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb conf = (core_server_config *)apr_pcalloc(p, sizeof(core_server_config));
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *conf = *virt;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (!conf->access_name) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb conf->access_name = base->access_name;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (!conf->ap_document_root) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb conf->ap_document_root = base->ap_document_root;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb conf->sec_dir = apr_array_append(p, base->sec_dir, virt->sec_dir);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb conf->sec_url = apr_array_append(p, base->sec_url, virt->sec_url);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return conf;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb/* Add per-directory configuration entry (for <directory> section);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * these are part of the core server config.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbAP_CORE_DECLARE(void) ap_add_per_dir_conf(server_rec *s, void *dir_config)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb core_server_config *sconf = ap_get_module_config(s->module_config,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb &core_module);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb void **new_space = (void **)apr_array_push(sconf->sec_dir);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *new_space = dir_config;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbAP_CORE_DECLARE(void) ap_add_per_url_conf(server_rec *s, void *url_config)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb core_server_config *sconf = ap_get_module_config(s->module_config,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb &core_module);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb void **new_space = (void **)apr_array_push(sconf->sec_url);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *new_space = url_config;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwroweAP_CORE_DECLARE(void) ap_add_file_conf(core_dir_config *conf, void *url_config)
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe{
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe void **new_space = (void **)apr_array_push(conf->sec_file);
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe *new_space = url_config;
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe}
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe/* We need to do a stable sort, qsort isn't stable. So to make it stable
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe * we'll be maintaining the original index into the list, and using it
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe * as the minor key during sorting. The major key is the number of
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe * components (where the root component is zero).
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe */
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowestruct reorder_sort_rec {
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe ap_conf_vector_t *elt;
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe int orig_index;
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe};
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowestatic int reorder_sorter(const void *va, const void *vb)
2f1949bb0e3c209db94c8d521cba7380b9d11421trawick{
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe const struct reorder_sort_rec *a = va;
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe const struct reorder_sort_rec *b = vb;
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe core_dir_config *core_a;
2f1949bb0e3c209db94c8d521cba7380b9d11421trawick core_dir_config *core_b;
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe core_a = ap_get_module_config(a->elt, &core_module);
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe core_b = ap_get_module_config(b->elt, &core_module);
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe if (core_a->r < core_b->r) {
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe return -1;
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe }
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe else if (core_a->r > core_b->r) {
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe return 1;
2f1949bb0e3c209db94c8d521cba7380b9d11421trawick }
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe if (core_a->d_components < core_b->d_components) {
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe return -1;
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe }
2f1949bb0e3c209db94c8d521cba7380b9d11421trawick else if (core_a->d_components > core_b->d_components) {
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe return 1;
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe }
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe /* They have the same number of components, we now have to compare
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe * the minor key to maintain the original order.
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe */
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe return a->orig_index - b->orig_index;
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe}
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowevoid ap_core_reorder_directories(apr_pool_t *p, server_rec *s)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
8aefbd756763807188d2e3ce336a8680e4893066wrowe core_server_config *sconf;
8aefbd756763807188d2e3ce336a8680e4893066wrowe apr_array_header_t *sec_dir;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb struct reorder_sort_rec *sortbin;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb int nelts;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_conf_vector_t **elts;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb int i;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb apr_pool_t *tmp;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb sconf = ap_get_module_config(s->module_config, &core_module);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb sec_dir = sconf->sec_dir;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb nelts = sec_dir->nelts;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb elts = (ap_conf_vector_t **)sec_dir->elts;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* we have to allocate tmp space to do a stable sort */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb apr_pool_create(&tmp, p);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb sortbin = apr_palloc(tmp, sec_dir->nelts * sizeof(*sortbin));
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb for (i = 0; i < nelts; ++i) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb sortbin[i].orig_index = i;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb sortbin[i].elt = elts[i];
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb qsort(sortbin, nelts, sizeof(*sortbin), reorder_sorter);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* and now copy back to the original array */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb for (i = 0; i < nelts; ++i) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb elts[i] = sortbin[i].elt;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb apr_pool_destroy(tmp);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb/*****************************************************************
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * There are some elements of the core config structures in which
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * other modules have a legitimate interest (this is ugly, but necessary
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * to preserve NCSA back-compatibility). So, we have a bunch of accessors
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * here...
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbAP_DECLARE(int) ap_allow_options(request_rec *r)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb core_dir_config *conf =
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb (core_dir_config *)ap_get_module_config(r->per_dir_config, &core_module);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return conf->opts;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbAP_DECLARE(int) ap_allow_overrides(request_rec *r)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb core_dir_config *conf;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb conf = (core_dir_config *)ap_get_module_config(r->per_dir_config,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb &core_module);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return conf->override;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbAP_DECLARE(const char *) ap_auth_type(request_rec *r)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb core_dir_config *conf;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb conf = (core_dir_config *)ap_get_module_config(r->per_dir_config,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb &core_module);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return conf->ap_auth_type;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbAP_DECLARE(const char *) ap_auth_name(request_rec *r)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
0540a0b469147b52e858587270dba31c2aaa9e09wrowe core_dir_config *conf;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb conf = (core_dir_config *)ap_get_module_config(r->per_dir_config,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb &core_module);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return conf->ap_auth_name;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbAP_DECLARE(const char *) ap_default_type(request_rec *r)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb core_dir_config *conf;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb conf = (core_dir_config *)ap_get_module_config(r->per_dir_config,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb &core_module);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return conf->ap_default_type
4ca6cbe768b4e0917ac0b76333c26a7d5396d454trawick ? conf->ap_default_type
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb : DEFAULT_CONTENT_TYPE;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbAP_DECLARE(const char *) ap_document_root(request_rec *r) /* Don't use this! */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb core_server_config *conf;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb conf = (core_server_config *)ap_get_module_config(r->server->module_config,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb &core_module);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return conf->ap_document_root;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbAP_DECLARE(const apr_array_header_t *) ap_requires(request_rec *r)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb core_dir_config *conf;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb conf = (core_dir_config *)ap_get_module_config(r->per_dir_config,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb &core_module);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return conf->ap_requires;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbAP_DECLARE(int) ap_satisfies(request_rec *r)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb core_dir_config *conf;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb conf = (core_dir_config *)ap_get_module_config(r->per_dir_config,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb &core_module);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return conf->satisfy;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb/* Should probably just get rid of this... the only code that cares is
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * part of the core anyway (and in fact, it isn't publicised to other
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * modules).
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbchar *ap_response_code_string(request_rec *r, int error_index)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb core_dir_config *conf;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb conf = (core_dir_config *)ap_get_module_config(r->per_dir_config,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb &core_module);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (conf->response_code_strings == NULL) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return NULL;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return conf->response_code_strings[error_index];
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b29f87f4b6c6886a04dccc296177a7033f70dfedtrawick
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb/* Code from Harald Hanche-Olsen <hanche@imf.unit.no> */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic APR_INLINE void do_double_reverse (conn_rec *conn)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb apr_sockaddr_t *sa;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb apr_status_t rv;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (conn->double_reverse) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* already done */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (conn->remote_host == NULL || conn->remote_host[0] == '\0') {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* single reverse failed, so don't bother */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb conn->double_reverse = -1;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb rv = apr_sockaddr_info_get(&sa, conn->remote_host, APR_UNSPEC, 0, 0, conn->pool);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (rv == APR_SUCCESS) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb while (sa) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (sa->ipaddr_len == conn->remote_addr->ipaddr_len &&
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb !memcmp(sa->ipaddr_ptr, conn->remote_addr->ipaddr_ptr,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb sa->ipaddr_len)) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb conn->double_reverse = 1;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#if APR_HAVE_IPV6
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* match IPv4-mapped IPv6 addresses with IPv4 A record */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (conn->remote_addr->sa.sin.sin_family == APR_INET6 &&
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb sa->sa.sin.sin_family == APR_INET &&
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb IN6_IS_ADDR_V4MAPPED((struct in6_addr *)conn->remote_addr->ipaddr_ptr) &&
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb !memcmp(&((struct in6_addr *)conn->remote_addr->ipaddr_ptr)->s6_addr[12],
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb sa->ipaddr_ptr,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb sizeof (((struct in_addr *)0)->s_addr))) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb conn->double_reverse = 1;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#endif
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb sa = sa->next;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb conn->double_reverse = -1;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbAP_DECLARE(const char *) ap_get_remote_host(conn_rec *conn, void *dir_config,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb int type, int *str_is_ip)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb int hostname_lookups;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (str_is_ip) { /* if caller wants to know */
a2a0abd88b19e042a3eb2a9fa1702c25ad51303dwrowe *str_is_ip = 0;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* If we haven't checked the host name, and we want to */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (dir_config) {
2fa5b5878e7567e2875807c3e2a2b3b0d3ef74bewrowe hostname_lookups =
2fa5b5878e7567e2875807c3e2a2b3b0d3ef74bewrowe ((core_dir_config *)ap_get_module_config(dir_config, &core_module))
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ->hostname_lookups;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (hostname_lookups == HOSTNAME_LOOKUP_UNSET) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb hostname_lookups = HOSTNAME_LOOKUP_OFF;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* the default */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb hostname_lookups = HOSTNAME_LOOKUP_OFF;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe if (type != REMOTE_NOLOOKUP
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe && conn->remote_host == NULL
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe && (type == REMOTE_DOUBLE_REV
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe || hostname_lookups != HOSTNAME_LOOKUP_OFF)) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb apr_sockaddr_t *remote_addr;
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe apr_socket_addr_get(&remote_addr, APR_REMOTE, conn->client_socket);
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe if (apr_getnameinfo(&conn->remote_host, remote_addr, 0) == APR_SUCCESS) {
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe ap_str_tolower(conn->remote_host);
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe if (hostname_lookups == HOSTNAME_LOOKUP_DOUBLE) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb do_double_reverse(conn);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (conn->double_reverse != 1) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb conn->remote_host = NULL;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* if failed, set it to the NULL string to indicate error */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (conn->remote_host == NULL) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb conn->remote_host = "";
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (type == REMOTE_DOUBLE_REV) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb do_double_reverse(conn);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (conn->double_reverse == -1) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return NULL;
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe }
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe }
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe/*
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe * Return the desired information; either the remote DNS name, if found,
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe * or either NULL (if the hostname was requested) or the IP address
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe * (if any identifier was requested).
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe */
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe if (conn->remote_host != NULL && conn->remote_host[0] != '\0') {
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe return conn->remote_host;
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else {
6fed20de38221f6f8a60c0ab1d907f1173c443f4wrowe if (type == REMOTE_HOST || type == REMOTE_DOUBLE_REV) {
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe return NULL;
6fed20de38221f6f8a60c0ab1d907f1173c443f4wrowe }
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe else {
6fed20de38221f6f8a60c0ab1d907f1173c443f4wrowe if (str_is_ip) { /* if caller wants to know */
6fed20de38221f6f8a60c0ab1d907f1173c443f4wrowe *str_is_ip = 1;
6fed20de38221f6f8a60c0ab1d907f1173c443f4wrowe }
6fed20de38221f6f8a60c0ab1d907f1173c443f4wrowe return conn->remote_ip;
6fed20de38221f6f8a60c0ab1d907f1173c443f4wrowe }
6fed20de38221f6f8a60c0ab1d907f1173c443f4wrowe }
6fed20de38221f6f8a60c0ab1d907f1173c443f4wrowe}
6fed20de38221f6f8a60c0ab1d907f1173c443f4wrowe
6fed20de38221f6f8a60c0ab1d907f1173c443f4wroweAP_DECLARE(const char *) ap_get_remote_logname(request_rec *r)
6fed20de38221f6f8a60c0ab1d907f1173c443f4wrowe{
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe core_dir_config *dir_conf;
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe
6fed20de38221f6f8a60c0ab1d907f1173c443f4wrowe if (r->connection->remote_logname != NULL) {
6fed20de38221f6f8a60c0ab1d907f1173c443f4wrowe return r->connection->remote_logname;
6fed20de38221f6f8a60c0ab1d907f1173c443f4wrowe }
6fed20de38221f6f8a60c0ab1d907f1173c443f4wrowe
6fed20de38221f6f8a60c0ab1d907f1173c443f4wrowe/* If we haven't checked the identity, and we want to */
6fed20de38221f6f8a60c0ab1d907f1173c443f4wrowe dir_conf = (core_dir_config *)ap_get_module_config(r->per_dir_config,
6fed20de38221f6f8a60c0ab1d907f1173c443f4wrowe &core_module);
6fed20de38221f6f8a60c0ab1d907f1173c443f4wrowe
6fed20de38221f6f8a60c0ab1d907f1173c443f4wrowe if (dir_conf->do_rfc1413 & 1) {
6fed20de38221f6f8a60c0ab1d907f1173c443f4wrowe return ap_rfc1413(r->connection, r->server);
6fed20de38221f6f8a60c0ab1d907f1173c443f4wrowe }
6fed20de38221f6f8a60c0ab1d907f1173c443f4wrowe else {
6fed20de38221f6f8a60c0ab1d907f1173c443f4wrowe return NULL;
580786e253bbe2fa462fdb24af47e52e1ef3dd83wrowe }
580786e253bbe2fa462fdb24af47e52e1ef3dd83wrowe}
6fed20de38221f6f8a60c0ab1d907f1173c443f4wrowe
6fed20de38221f6f8a60c0ab1d907f1173c443f4wrowe/* There are two options regarding what the "name" of a server is. The
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * "canonical" name as defined by ServerName and Port, or the "client's
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * name" as supplied by a possible Host: header or full URI. We never
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * trust the port passed in the client's headers, we always use the
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * port of the actual socket.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * The DNS option to UseCanonicalName causes this routine to do a
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * reverse lookup on the local IP address of the connection and use
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * that for the ServerName. This makes its value more reliable while
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * at the same time allowing Demon's magic virtual hosting to work.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * The assumption is that DNS lookups are sufficiently quick...
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * -- fanf 1998-10-03
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbAP_DECLARE(const char *) ap_get_server_name(request_rec *r)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb conn_rec *conn = r->connection;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb core_dir_config *d;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb d = (core_dir_config *)ap_get_module_config(r->per_dir_config,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb &core_module);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (d->use_canonical_name == USE_CANONICAL_NAME_OFF) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return r->hostname ? r->hostname : r->server->server_hostname;
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (d->use_canonical_name == USE_CANONICAL_NAME_DNS) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (conn->local_host == NULL) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb apr_sockaddr_t *local_addr;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb apr_socket_addr_get(&local_addr, APR_LOCAL, conn->client_socket);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (apr_getnameinfo(&conn->local_host, local_addr, 0) != APR_SUCCESS)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb conn->local_host = apr_pstrdup(conn->pool, r->server->server_hostname);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_str_tolower(conn->local_host);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return conn->local_host;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* default */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return r->server->server_hostname;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbAP_DECLARE(apr_port_t) ap_get_server_port(const request_rec *r)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb apr_port_t port;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb core_dir_config *d =
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe (core_dir_config *)ap_get_module_config(r->per_dir_config, &core_module);
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb port = r->server->port ? r->server->port : ap_default_port(r);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe if (d->use_canonical_name == USE_CANONICAL_NAME_OFF
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb || d->use_canonical_name == USE_CANONICAL_NAME_DNS) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (r->hostname) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb apr_sockaddr_t *localsa;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb apr_socket_addr_get(&localsa, APR_LOCAL, r->connection->client_socket);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb apr_sockaddr_port_get(&port, localsa);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* default */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return port;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbAP_DECLARE(char *) ap_construct_url(apr_pool_t *p, const char *uri,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb request_rec *r)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe unsigned port = ap_get_server_port(r);
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe const char *host = ap_get_server_name(r);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (ap_is_default_port(port, r)) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return apr_pstrcat(p, ap_http_method(r), "://", host, uri, NULL);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return apr_psprintf(p, "%s://%s:%u%s", ap_http_method(r), host, port, uri);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbAP_DECLARE(unsigned long) ap_get_limit_req_body(const request_rec *r)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb core_dir_config *d =
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb (core_dir_config *)ap_get_module_config(r->per_dir_config, &core_module);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return d->limit_req_body;
2fa5b5878e7567e2875807c3e2a2b3b0d3ef74bewrowe}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#ifdef WIN32
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic apr_status_t get_win32_registry_default_value(apr_pool_t *p, HKEY hkey,
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe char* relativepath,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb char **value)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb HKEY hkeyOpen;
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe DWORD type;
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe DWORD size = 0;
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe DWORD result = RegOpenKeyEx(hkey, relativepath, 0,
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe KEY_QUERY_VALUE, &hkeyOpen);
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe if (result != ERROR_SUCCESS)
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe return APR_FROM_OS_ERROR(result);
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Read to NULL buffer to determine value size */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb result = RegQueryValueEx(hkeyOpen, "", 0, &type, NULL, &size);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (result == ERROR_SUCCESS) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if ((size < 2) || (type != REG_SZ && type != REG_EXPAND_SZ)) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb result = ERROR_INVALID_PARAMETER;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *value = apr_palloc(p, size);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Read value based on size query above */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb result = RegQueryValueEx(hkeyOpen, "", 0, &type, *value, &size);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* TODO: This might look fine, but we need to provide some warning
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * somewhere that some environment variables may -not- be translated,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * seeing as we may have chopped the environment table down somewhat.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if ((result == ERROR_SUCCESS) && (type == REG_EXPAND_SZ))
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb {
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe char *tmp = *value;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb size = ExpandEnvironmentStrings(tmp, *value, 0);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (size) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *value = apr_palloc(p, size);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb size = ExpandEnvironmentStrings(tmp, *value, size);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb RegCloseKey(hkeyOpen);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return APR_FROM_OS_ERROR(result);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic char* get_interpreter_from_win32_registry(apr_pool_t *p, const char* ext,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb char** arguments, int strict)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb char execcgi_path[] = "SHELL\\EXECCGI\\COMMAND";
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb char execopen_path[] = "SHELL\\OPEN\\COMMAND";
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb char typeName[MAX_PATH];
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb int cmdOfName = FALSE;
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe HKEY hkeyName;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb HKEY hkeyType;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb DWORD type;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb int size;
2fa5b5878e7567e2875807c3e2a2b3b0d3ef74bewrowe int result;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb char *buffer;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb char *s;
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe if (!ext)
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe return NULL;
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe /*
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe * Future optimization:
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe * When the registry is successfully searched, store the strings for
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe * interpreter and arguments in an ext hash to speed up subsequent look-ups
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Open the key associated with the script filetype extension */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb result = RegOpenKeyEx(HKEY_CLASSES_ROOT, ext, 0, KEY_QUERY_VALUE,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb &hkeyType);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (result != ERROR_SUCCESS)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return NULL;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Retrieve the name of the script filetype extension */
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe size = sizeof(typeName);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb result = RegQueryValueEx(hkeyType, "", NULL, &type, typeName, &size);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (result == ERROR_SUCCESS && type == REG_SZ && typeName[0]) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Open the key associated with the script filetype extension */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb result = RegOpenKeyEx(HKEY_CLASSES_ROOT, typeName, 0,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb KEY_QUERY_VALUE, &hkeyName);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (result == ERROR_SUCCESS)
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe cmdOfName = TRUE;
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe }
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe /* Open the key for the script command path by:
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe *
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe * 1) the 'named' filetype key for ExecCGI/Command
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe * 2) the extension's type key for ExecCGI/Command
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * and if the strict arg is false, then continue trying:
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * 3) the 'named' filetype key for Open/Command
8aefbd756763807188d2e3ce336a8680e4893066wrowe * 4) the extension's type key for Open/Command
8aefbd756763807188d2e3ce336a8680e4893066wrowe */
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (cmdOfName) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe result = get_win32_registry_default_value(p, hkeyName,
8aefbd756763807188d2e3ce336a8680e4893066wrowe execcgi_path, &buffer);
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (!cmdOfName || (result != ERROR_SUCCESS)) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe result = get_win32_registry_default_value(p, hkeyType,
8aefbd756763807188d2e3ce336a8680e4893066wrowe execcgi_path, &buffer);
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (!strict && cmdOfName && (result != ERROR_SUCCESS)) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe result = get_win32_registry_default_value(p, hkeyName,
8aefbd756763807188d2e3ce336a8680e4893066wrowe execopen_path, &buffer);
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
a2a0abd88b19e042a3eb2a9fa1702c25ad51303dwrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (!strict && (result != ERROR_SUCCESS)) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe result = get_win32_registry_default_value(p, hkeyType,
8aefbd756763807188d2e3ce336a8680e4893066wrowe execopen_path, &buffer);
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe }
2fa5b5878e7567e2875807c3e2a2b3b0d3ef74bewrowe
2fa5b5878e7567e2875807c3e2a2b3b0d3ef74bewrowe if (cmdOfName)
2fa5b5878e7567e2875807c3e2a2b3b0d3ef74bewrowe RegCloseKey(hkeyName);
d11e96111ae8731e8785837b4c927d81bf33c9b6wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe RegCloseKey(hkeyType);
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (result != ERROR_SUCCESS)
8aefbd756763807188d2e3ce336a8680e4893066wrowe return NULL;
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe /*
8aefbd756763807188d2e3ce336a8680e4893066wrowe * The canonical way shell command entries are entered in the Win32
8aefbd756763807188d2e3ce336a8680e4893066wrowe * registry is as follows:
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe * shell [options] "%1" [args]
a8d11d78181478da6a672f7fbc58b8d523351f49wrowe * where
8aa5ca8ff2a4d8e56f62ea3d461e2799136da085trawick * shell - full path name to interpreter or shell to run.
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe * E.g., c:\usr\local\ntreskit\perl\bin\perl.exe
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe * options - optional switches
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe * E.g., \C
8aefbd756763807188d2e3ce336a8680e4893066wrowe * "%1" - Place holder for file to run the shell against.
a8d11d78181478da6a672f7fbc58b8d523351f49wrowe * Typically quoted.
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe * options - additional arguments
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe * E.g., /silent
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe *
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe * If we find a %1 or a quoted %1, lop off the remainder to arguments.
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe */
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (buffer && *buffer) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe if ((s = strstr(buffer, "\"%1")))
8aefbd756763807188d2e3ce336a8680e4893066wrowe {
8aefbd756763807188d2e3ce336a8680e4893066wrowe *s = '\0';
8aefbd756763807188d2e3ce336a8680e4893066wrowe *arguments = s + 4;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe else if ((s = strstr(buffer, "%1")))
8aefbd756763807188d2e3ce336a8680e4893066wrowe {
8aefbd756763807188d2e3ce336a8680e4893066wrowe *s = '\0';
8aefbd756763807188d2e3ce336a8680e4893066wrowe *arguments = buffer + 2;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe else
8aefbd756763807188d2e3ce336a8680e4893066wrowe *arguments = strchr(buffer, '\0');
8aefbd756763807188d2e3ce336a8680e4893066wrowe while (**arguments && isspace(**arguments))
8aefbd756763807188d2e3ce336a8680e4893066wrowe ++*arguments;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe return buffer;
8aefbd756763807188d2e3ce336a8680e4893066wrowe}
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wroweAP_DECLARE (file_type_e) ap_get_win32_interpreter(const request_rec *r,
8aefbd756763807188d2e3ce336a8680e4893066wrowe char** interpreter,
8aefbd756763807188d2e3ce336a8680e4893066wrowe char** arguments)
8aefbd756763807188d2e3ce336a8680e4893066wrowe{
8aefbd756763807188d2e3ce336a8680e4893066wrowe HANDLE hFile;
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe DWORD nBytesRead;
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe BOOLEAN bResult;
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe char buffer[1024];
a8d11d78181478da6a672f7fbc58b8d523351f49wrowe core_dir_config *d;
a8d11d78181478da6a672f7fbc58b8d523351f49wrowe int i;
a8d11d78181478da6a672f7fbc58b8d523351f49wrowe file_type_e fileType = eFileTypeUNKNOWN;
a8d11d78181478da6a672f7fbc58b8d523351f49wrowe char *ext = NULL;
a8d11d78181478da6a672f7fbc58b8d523351f49wrowe char *exename = NULL;
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe d = (core_dir_config *)ap_get_module_config(r->per_dir_config,
8aefbd756763807188d2e3ce336a8680e4893066wrowe &core_module);
8aefbd756763807188d2e3ce336a8680e4893066wrowe
2fa5b5878e7567e2875807c3e2a2b3b0d3ef74bewrowe /* Find the file extension */
8aefbd756763807188d2e3ce336a8680e4893066wrowe exename = strrchr(r->filename, '/');
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (!exename) {
d11e96111ae8731e8785837b4c927d81bf33c9b6wrowe exename = strrchr(r->filename, '\\');
2fa5b5878e7567e2875807c3e2a2b3b0d3ef74bewrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (!exename) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe exename = r->filename;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe else {
8aefbd756763807188d2e3ce336a8680e4893066wrowe exename++;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe ext = strrchr(exename, '.');
d11e96111ae8731e8785837b4c927d81bf33c9b6wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (ext && (!strcasecmp(ext,".bat") || !strcasecmp(ext,".cmd")))
8aefbd756763807188d2e3ce336a8680e4893066wrowe {
8aefbd756763807188d2e3ce336a8680e4893066wrowe char *comspec = getenv("COMSPEC");
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (comspec) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe *interpreter = apr_pstrcat(r->pool, "\"", comspec, "\" /c ", NULL);
2fa5b5878e7567e2875807c3e2a2b3b0d3ef74bewrowe return eFileTypeSCRIPT;
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_INFO, 0, r->server,
2fa5b5878e7567e2875807c3e2a2b3b0d3ef74bewrowe "Failed to start a '%s' file as a script." APR_EOL_STR
8aefbd756763807188d2e3ce336a8680e4893066wrowe "\tCOMSPEC variable is missing from the environment.", ext);
8aefbd756763807188d2e3ce336a8680e4893066wrowe return eFileTypeUNKNOWN;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe /* If the file has an extension and it is not .com and not .exe and
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe * we've been instructed to search the registry, then do it!
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe */
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (ext && strcasecmp(ext,".exe") && strcasecmp(ext,".com") &&
8aefbd756763807188d2e3ce336a8680e4893066wrowe (d->script_interpreter_source == INTERPRETER_SOURCE_REGISTRY ||
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe d->script_interpreter_source == INTERPRETER_SOURCE_REGISTRY_STRICT)) {
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe /* Check the registry */
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe int strict = (d->script_interpreter_source
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe == INTERPRETER_SOURCE_REGISTRY_STRICT);
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe *interpreter = get_interpreter_from_win32_registry(r->pool, ext,
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe arguments, strict);
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe if (*interpreter)
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe return eFileTypeSCRIPT;
a8d11d78181478da6a672f7fbc58b8d523351f49wrowe else if (d->script_interpreter_source == INTERPRETER_SOURCE_REGISTRY_STRICT) {
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_INFO, 0, r->server,
8aefbd756763807188d2e3ce336a8680e4893066wrowe "ScriptInterpreterSource config directive set to \"registry-strict\"." APR_EOL_STR
8aefbd756763807188d2e3ce336a8680e4893066wrowe "\tInterpreter not found for files of type '%s'.", ext);
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe return eFileTypeUNKNOWN;
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe }
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe else
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe {
8aefbd756763807188d2e3ce336a8680e4893066wrowe ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_INFO, 0, r->server,
8aefbd756763807188d2e3ce336a8680e4893066wrowe "ScriptInterpreterSource config directive set to \"registry\"." APR_EOL_STR
8aefbd756763807188d2e3ce336a8680e4893066wrowe "\tInterpreter not found for files of type '%s', "
8aefbd756763807188d2e3ce336a8680e4893066wrowe "trying \"script\" method...", ext);
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe /* Need to peek into the file figure out what it really is... */
8aefbd756763807188d2e3ce336a8680e4893066wrowe /* This is wrong for Unicode FS ... should move to APR */
8aefbd756763807188d2e3ce336a8680e4893066wrowe hFile = CreateFile(r->filename, GENERIC_READ, FILE_SHARE_READ, NULL,
8aefbd756763807188d2e3ce336a8680e4893066wrowe OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (hFile == INVALID_HANDLE_VALUE) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe return eFileTypeUNKNOWN;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe bResult = ReadFile(hFile, (void*) &buffer, sizeof(buffer) - 1,
8aefbd756763807188d2e3ce336a8680e4893066wrowe &nBytesRead, NULL);
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe if (!bResult || (nBytesRead == 0)) {
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe ap_log_rerror(APLOG_MARK, APLOG_ERR, GetLastError(), r,
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe "ReadFile(%s) failed", r->filename);
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe CloseHandle(hFile);
8aefbd756763807188d2e3ce336a8680e4893066wrowe return eFileTypeUNKNOWN;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe CloseHandle(hFile);
8aefbd756763807188d2e3ce336a8680e4893066wrowe buffer[nBytesRead] = '\0';
d11e96111ae8731e8785837b4c927d81bf33c9b6wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe /* Script or executable, that is the question... */
8aefbd756763807188d2e3ce336a8680e4893066wrowe if ((buffer[0] == '#') && (buffer[1] == '!')) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe /* Assuming file is a script since it starts with a shebang */
8aefbd756763807188d2e3ce336a8680e4893066wrowe fileType = eFileTypeSCRIPT;
8aefbd756763807188d2e3ce336a8680e4893066wrowe for (i = 2; i < sizeof(buffer); i++) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe if ((buffer[i] == '\r')
8aefbd756763807188d2e3ce336a8680e4893066wrowe || (buffer[i] == '\n')) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe break;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe buffer[i] = '\0';
8aefbd756763807188d2e3ce336a8680e4893066wrowe for (i = 2; buffer[i] == ' ' ; ++i)
8aefbd756763807188d2e3ce336a8680e4893066wrowe ;
8aefbd756763807188d2e3ce336a8680e4893066wrowe *interpreter = apr_pstrdup(r->pool, buffer + i );
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe else {
8aefbd756763807188d2e3ce336a8680e4893066wrowe /* Not a script, is it an executable? */
8aefbd756763807188d2e3ce336a8680e4893066wrowe IMAGE_DOS_HEADER *hdr = (IMAGE_DOS_HEADER*)buffer;
8aefbd756763807188d2e3ce336a8680e4893066wrowe if ((nBytesRead >= sizeof(IMAGE_DOS_HEADER)) && (hdr->e_magic == IMAGE_DOS_SIGNATURE)) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (hdr->e_lfarlc < 0x40)
8aefbd756763807188d2e3ce336a8680e4893066wrowe fileType = eFileTypeEXE16;
8aefbd756763807188d2e3ce336a8680e4893066wrowe else
8aefbd756763807188d2e3ce336a8680e4893066wrowe fileType = eFileTypeEXE32;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe else
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe fileType = eFileTypeUNKNOWN;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe return fileType;
8aefbd756763807188d2e3ce336a8680e4893066wrowe}
8aefbd756763807188d2e3ce336a8680e4893066wrowe#endif
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe/*****************************************************************
8aefbd756763807188d2e3ce336a8680e4893066wrowe *
8aefbd756763807188d2e3ce336a8680e4893066wrowe * Commands... this module handles almost all of the NCSA httpd.conf
8aefbd756763807188d2e3ce336a8680e4893066wrowe * commands, but most of the old srm.conf is in the the modules.
8aefbd756763807188d2e3ce336a8680e4893066wrowe */
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe/* returns a parent if it matches the given directive */
8aefbd756763807188d2e3ce336a8680e4893066wrowestatic const ap_directive_t * find_parent(const ap_directive_t *dirp,
8aefbd756763807188d2e3ce336a8680e4893066wrowe const char *what)
8aefbd756763807188d2e3ce336a8680e4893066wrowe{
b29f87f4b6c6886a04dccc296177a7033f70dfedtrawick while (dirp->parent != NULL) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe dirp = dirp->parent;
b29f87f4b6c6886a04dccc296177a7033f70dfedtrawick /* ### it would be nice to have atom-ized directives */
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (strcasecmp(dirp->directive, what) == 0)
8aefbd756763807188d2e3ce336a8680e4893066wrowe return dirp;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe return NULL;
8aefbd756763807188d2e3ce336a8680e4893066wrowe}
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wroweAP_DECLARE(const char *) ap_check_cmd_context(cmd_parms *cmd,
8aefbd756763807188d2e3ce336a8680e4893066wrowe unsigned forbidden)
8aefbd756763807188d2e3ce336a8680e4893066wrowe{
8aefbd756763807188d2e3ce336a8680e4893066wrowe const char *gt = (cmd->cmd->name[0] == '<'
8aefbd756763807188d2e3ce336a8680e4893066wrowe && cmd->cmd->name[strlen(cmd->cmd->name)-1] != '>')
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe ? ">" : "";
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe const ap_directive_t *found;
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe if ((forbidden & NOT_IN_VIRTUALHOST) && cmd->server->is_virtual) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe return apr_pstrcat(cmd->pool, cmd->cmd->name, gt,
8aefbd756763807188d2e3ce336a8680e4893066wrowe " cannot occur within <VirtualHost> section", NULL);
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe if ((forbidden & NOT_IN_LIMIT) && cmd->limited != -1) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe return apr_pstrcat(cmd->pool, cmd->cmd->name, gt,
8aefbd756763807188d2e3ce336a8680e4893066wrowe " cannot occur within <Limit> section", NULL);
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe if ((forbidden & NOT_IN_DIR_LOC_FILE) == NOT_IN_DIR_LOC_FILE
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe && cmd->path != NULL) {
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe return apr_pstrcat(cmd->pool, cmd->cmd->name, gt,
8aefbd756763807188d2e3ce336a8680e4893066wrowe " cannot occur within <Directory/Location/Files> "
8aefbd756763807188d2e3ce336a8680e4893066wrowe "section", NULL);
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (((forbidden & NOT_IN_DIRECTORY)
8aefbd756763807188d2e3ce336a8680e4893066wrowe && ((found = find_parent(cmd->directive, "<Directory"))
8aefbd756763807188d2e3ce336a8680e4893066wrowe || (found = find_parent(cmd->directive, "<DirectoryMatch"))))
8aefbd756763807188d2e3ce336a8680e4893066wrowe || ((forbidden & NOT_IN_LOCATION)
8aefbd756763807188d2e3ce336a8680e4893066wrowe && ((found = find_parent(cmd->directive, "<Location"))
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe || (found = find_parent(cmd->directive, "<LocationMatch"))))
8aefbd756763807188d2e3ce336a8680e4893066wrowe || ((forbidden & NOT_IN_FILES)
8aefbd756763807188d2e3ce336a8680e4893066wrowe && ((found = find_parent(cmd->directive, "<Files"))
8aefbd756763807188d2e3ce336a8680e4893066wrowe || (found = find_parent(cmd->directive, "<FilesMatch"))))) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe return apr_pstrcat(cmd->pool, cmd->cmd->name, gt,
8aefbd756763807188d2e3ce336a8680e4893066wrowe " cannot occur within ", found->directive,
8aefbd756763807188d2e3ce336a8680e4893066wrowe "> section", NULL);
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe }
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe return NULL;
8aefbd756763807188d2e3ce336a8680e4893066wrowe}
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowestatic const char *set_access_name(cmd_parms *cmd, void *dummy,
8aefbd756763807188d2e3ce336a8680e4893066wrowe const char *arg)
8aefbd756763807188d2e3ce336a8680e4893066wrowe{
8aefbd756763807188d2e3ce336a8680e4893066wrowe void *sconf = cmd->server->module_config;
8aefbd756763807188d2e3ce336a8680e4893066wrowe core_server_config *conf = ap_get_module_config(sconf, &core_module);
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe const char *err = ap_check_cmd_context(cmd,
8aefbd756763807188d2e3ce336a8680e4893066wrowe NOT_IN_DIR_LOC_FILE|NOT_IN_LIMIT);
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (err != NULL) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe return err;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe conf->access_name = apr_pstrdup(cmd->pool, arg);
8aefbd756763807188d2e3ce336a8680e4893066wrowe return NULL;
8aefbd756763807188d2e3ce336a8680e4893066wrowe}
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe#ifdef GPROF
8aefbd756763807188d2e3ce336a8680e4893066wrowestatic const char *set_gprof_dir(cmd_parms *cmd, void *dummy, const char *arg)
8aefbd756763807188d2e3ce336a8680e4893066wrowe{
8aefbd756763807188d2e3ce336a8680e4893066wrowe void *sconf = cmd->server->module_config;
8aefbd756763807188d2e3ce336a8680e4893066wrowe core_server_config *conf = ap_get_module_config(sconf, &core_module);
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe const char *err = ap_check_cmd_context(cmd,
2fa5b5878e7567e2875807c3e2a2b3b0d3ef74bewrowe NOT_IN_DIR_LOC_FILE|NOT_IN_LIMIT);
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (err != NULL) {
2fa5b5878e7567e2875807c3e2a2b3b0d3ef74bewrowe return err;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe conf->gprof_dir = apr_pstrdup(cmd->pool, arg);
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe return NULL;
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe}
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe#endif /*GPROF*/
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowestatic const char *set_add_default_charset(cmd_parms *cmd,
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe void *d_, const char *arg)
8aefbd756763807188d2e3ce336a8680e4893066wrowe{
8aefbd756763807188d2e3ce336a8680e4893066wrowe core_dir_config *d=d_;
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe const char *err = ap_check_cmd_context(cmd, NOT_IN_LIMIT);
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (err != NULL) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe return err;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (!strcasecmp(arg, "Off")) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe d->add_default_charset = ADD_DEFAULT_CHARSET_OFF;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe else if (!strcasecmp(arg, "On")) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe d->add_default_charset = ADD_DEFAULT_CHARSET_ON;
8aefbd756763807188d2e3ce336a8680e4893066wrowe d->add_default_charset_name = DEFAULT_ADD_DEFAULT_CHARSET_NAME;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe else {
8aefbd756763807188d2e3ce336a8680e4893066wrowe d->add_default_charset = ADD_DEFAULT_CHARSET_ON;
8aefbd756763807188d2e3ce336a8680e4893066wrowe d->add_default_charset_name = arg;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe return NULL;
8aefbd756763807188d2e3ce336a8680e4893066wrowe}
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowestatic const char *set_document_root(cmd_parms *cmd, void *dummy,
8aefbd756763807188d2e3ce336a8680e4893066wrowe const char *arg)
8aefbd756763807188d2e3ce336a8680e4893066wrowe{
8aefbd756763807188d2e3ce336a8680e4893066wrowe void *sconf = cmd->server->module_config;
0540a0b469147b52e858587270dba31c2aaa9e09wrowe core_server_config *conf = ap_get_module_config(sconf, &core_module);
0540a0b469147b52e858587270dba31c2aaa9e09wrowe
0540a0b469147b52e858587270dba31c2aaa9e09wrowe const char *err = ap_check_cmd_context(cmd,
0540a0b469147b52e858587270dba31c2aaa9e09wrowe NOT_IN_DIR_LOC_FILE|NOT_IN_LIMIT);
0540a0b469147b52e858587270dba31c2aaa9e09wrowe if (err != NULL) {
0540a0b469147b52e858587270dba31c2aaa9e09wrowe return err;
0540a0b469147b52e858587270dba31c2aaa9e09wrowe }
0540a0b469147b52e858587270dba31c2aaa9e09wrowe
0540a0b469147b52e858587270dba31c2aaa9e09wrowe /* TODO: ap_configtestonly && ap_docrootcheck && */
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe /* XXX Shouldn't this be relative to ServerRoot ??? */
0540a0b469147b52e858587270dba31c2aaa9e09wrowe if (apr_filepath_merge((char**)&conf->ap_document_root, NULL, arg,
0540a0b469147b52e858587270dba31c2aaa9e09wrowe APR_FILEPATH_TRUENAME, cmd->pool) != APR_SUCCESS
0540a0b469147b52e858587270dba31c2aaa9e09wrowe || !ap_is_directory(cmd->pool, arg)) {
0540a0b469147b52e858587270dba31c2aaa9e09wrowe if (cmd->server->is_virtual) {
0540a0b469147b52e858587270dba31c2aaa9e09wrowe ap_log_perror(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, cmd->pool,
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe "Warning: DocumentRoot [%s] does not exist",
0540a0b469147b52e858587270dba31c2aaa9e09wrowe arg);
8aefbd756763807188d2e3ce336a8680e4893066wrowe conf->ap_document_root = arg;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe else {
8aefbd756763807188d2e3ce336a8680e4893066wrowe return "DocumentRoot must be a directory";
0540a0b469147b52e858587270dba31c2aaa9e09wrowe }
a2a0abd88b19e042a3eb2a9fa1702c25ad51303dwrowe }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return NULL;
948096a99010fccf648814fecf38f75c689172d7wrowe}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbAP_DECLARE(void) ap_custom_response(request_rec *r, int status, char *string)
0540a0b469147b52e858587270dba31c2aaa9e09wrowe{
0540a0b469147b52e858587270dba31c2aaa9e09wrowe core_dir_config *conf =
948096a99010fccf648814fecf38f75c689172d7wrowe ap_get_module_config(r->per_dir_config, &core_module);
948096a99010fccf648814fecf38f75c689172d7wrowe int idx;
948096a99010fccf648814fecf38f75c689172d7wrowe
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe if(conf->response_code_strings == NULL) {
3f5b4558f5410fdac5d6feed7aab0c3668f9cd13wrowe conf->response_code_strings =
948096a99010fccf648814fecf38f75c689172d7wrowe apr_pcalloc(r->pool,
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe sizeof(*conf->response_code_strings) *
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe RESPONSE_CODES);
053497224246c4dbef9af594cacf5c00ed271e6cwrowe }
0540a0b469147b52e858587270dba31c2aaa9e09wrowe
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb idx = ap_index_of_response(status);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb conf->response_code_strings[idx] =
948096a99010fccf648814fecf38f75c689172d7wrowe ((ap_is_url(string) || (*string == '/')) && (*string != '"')) ?
948096a99010fccf648814fecf38f75c689172d7wrowe apr_pstrdup(r->pool, string) : apr_pstrcat(r->pool, "\"", string, NULL);
948096a99010fccf648814fecf38f75c689172d7wrowe}
948096a99010fccf648814fecf38f75c689172d7wrowe
948096a99010fccf648814fecf38f75c689172d7wrowestatic const char *set_error_document(cmd_parms *cmd, void *conf_,
948096a99010fccf648814fecf38f75c689172d7wrowe const char *errno_str, const char *msg)
948096a99010fccf648814fecf38f75c689172d7wrowe{
948096a99010fccf648814fecf38f75c689172d7wrowe core_dir_config *conf=conf_;
948096a99010fccf648814fecf38f75c689172d7wrowe int error_number, index_number, idx500;
948096a99010fccf648814fecf38f75c689172d7wrowe enum { MSG, LOCAL_PATH, REMOTE_PATH } what = MSG;
948096a99010fccf648814fecf38f75c689172d7wrowe
948096a99010fccf648814fecf38f75c689172d7wrowe const char *err = ap_check_cmd_context(cmd, NOT_IN_LIMIT);
948096a99010fccf648814fecf38f75c689172d7wrowe if (err != NULL) {
053497224246c4dbef9af594cacf5c00ed271e6cwrowe return err;
948096a99010fccf648814fecf38f75c689172d7wrowe }
948096a99010fccf648814fecf38f75c689172d7wrowe
948096a99010fccf648814fecf38f75c689172d7wrowe /* 1st parameter should be a 3 digit number, which we recognize;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * convert it into an array index
0540a0b469147b52e858587270dba31c2aaa9e09wrowe */
948096a99010fccf648814fecf38f75c689172d7wrowe error_number = atoi(errno_str);
948096a99010fccf648814fecf38f75c689172d7wrowe idx500 = ap_index_of_response(HTTP_INTERNAL_SERVER_ERROR);
948096a99010fccf648814fecf38f75c689172d7wrowe
948096a99010fccf648814fecf38f75c689172d7wrowe if (error_number == HTTP_INTERNAL_SERVER_ERROR) {
948096a99010fccf648814fecf38f75c689172d7wrowe index_number = idx500;
053497224246c4dbef9af594cacf5c00ed271e6cwrowe }
948096a99010fccf648814fecf38f75c689172d7wrowe else if ((index_number = ap_index_of_response(error_number)) == idx500) {
948096a99010fccf648814fecf38f75c689172d7wrowe return apr_pstrcat(cmd->pool, "Unsupported HTTP response code ",
948096a99010fccf648814fecf38f75c689172d7wrowe errno_str, NULL);
948096a99010fccf648814fecf38f75c689172d7wrowe }
948096a99010fccf648814fecf38f75c689172d7wrowe
948096a99010fccf648814fecf38f75c689172d7wrowe /* Heuristic to determine second argument. */
948096a99010fccf648814fecf38f75c689172d7wrowe if (ap_strchr_c(msg,' '))
948096a99010fccf648814fecf38f75c689172d7wrowe what = MSG;
948096a99010fccf648814fecf38f75c689172d7wrowe else if (msg[0] == '/')
948096a99010fccf648814fecf38f75c689172d7wrowe what = LOCAL_PATH;
0540a0b469147b52e858587270dba31c2aaa9e09wrowe else if (ap_is_url(msg))
948096a99010fccf648814fecf38f75c689172d7wrowe what = REMOTE_PATH;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe else
948096a99010fccf648814fecf38f75c689172d7wrowe what = MSG;
0540a0b469147b52e858587270dba31c2aaa9e09wrowe
948096a99010fccf648814fecf38f75c689172d7wrowe /* The entry should be ignored if it is a full URL for a 401 error */
948096a99010fccf648814fecf38f75c689172d7wrowe
948096a99010fccf648814fecf38f75c689172d7wrowe if (error_number == 401 && what == REMOTE_PATH) {
948096a99010fccf648814fecf38f75c689172d7wrowe ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, 0, cmd->server,
053497224246c4dbef9af594cacf5c00ed271e6cwrowe "cannot use a full URL in a 401 ErrorDocument "
0540a0b469147b52e858587270dba31c2aaa9e09wrowe "directive --- ignoring!");
053497224246c4dbef9af594cacf5c00ed271e6cwrowe }
0540a0b469147b52e858587270dba31c2aaa9e09wrowe else { /* Store it... */
0540a0b469147b52e858587270dba31c2aaa9e09wrowe if (conf->response_code_strings == NULL) {
aa047239dedf0d26e8efecfade32e7337f35df19wrowe conf->response_code_strings =
aa047239dedf0d26e8efecfade32e7337f35df19wrowe apr_pcalloc(cmd->pool,
aa047239dedf0d26e8efecfade32e7337f35df19wrowe sizeof(*conf->response_code_strings) * RESPONSE_CODES);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
053497224246c4dbef9af594cacf5c00ed271e6cwrowe /* hack. Prefix a " if it is a msg; as that is what
053497224246c4dbef9af594cacf5c00ed271e6cwrowe * http_protocol.c relies on to distinguish between
053497224246c4dbef9af594cacf5c00ed271e6cwrowe * a msg and a (local) path.
053497224246c4dbef9af594cacf5c00ed271e6cwrowe */
053497224246c4dbef9af594cacf5c00ed271e6cwrowe conf->response_code_strings[index_number] = (what == MSG) ?
053497224246c4dbef9af594cacf5c00ed271e6cwrowe apr_pstrcat(cmd->pool, "\"",msg,NULL) :
aa047239dedf0d26e8efecfade32e7337f35df19wrowe apr_pstrdup(cmd->pool, msg);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe }
aa047239dedf0d26e8efecfade32e7337f35df19wrowe
aa047239dedf0d26e8efecfade32e7337f35df19wrowe return NULL;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe}
aa047239dedf0d26e8efecfade32e7337f35df19wrowe
aa047239dedf0d26e8efecfade32e7337f35df19wrowestatic const char *set_override(cmd_parms *cmd, void *d_, const char *l)
053497224246c4dbef9af594cacf5c00ed271e6cwrowe{
053497224246c4dbef9af594cacf5c00ed271e6cwrowe core_dir_config *d=d_;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb char *w;
948096a99010fccf648814fecf38f75c689172d7wrowe
948096a99010fccf648814fecf38f75c689172d7wrowe const char *err = ap_check_cmd_context(cmd, NOT_IN_LIMIT);
948096a99010fccf648814fecf38f75c689172d7wrowe if (err != NULL) {
0540a0b469147b52e858587270dba31c2aaa9e09wrowe return err;
948096a99010fccf648814fecf38f75c689172d7wrowe }
948096a99010fccf648814fecf38f75c689172d7wrowe
948096a99010fccf648814fecf38f75c689172d7wrowe d->override = OR_NONE;
948096a99010fccf648814fecf38f75c689172d7wrowe while (l[0]) {
948096a99010fccf648814fecf38f75c689172d7wrowe w = ap_getword_conf(cmd->pool, &l);
948096a99010fccf648814fecf38f75c689172d7wrowe if (!strcasecmp(w, "Limit")) {
948096a99010fccf648814fecf38f75c689172d7wrowe d->override |= OR_LIMIT;
948096a99010fccf648814fecf38f75c689172d7wrowe }
948096a99010fccf648814fecf38f75c689172d7wrowe else if (!strcasecmp(w, "Options")) {
948096a99010fccf648814fecf38f75c689172d7wrowe d->override |= OR_OPTIONS;
948096a99010fccf648814fecf38f75c689172d7wrowe }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else if (!strcasecmp(w, "FileInfo")) {
948096a99010fccf648814fecf38f75c689172d7wrowe d->override |= OR_FILEINFO;
948096a99010fccf648814fecf38f75c689172d7wrowe }
948096a99010fccf648814fecf38f75c689172d7wrowe else if (!strcasecmp(w, "AuthConfig")) {
0540a0b469147b52e858587270dba31c2aaa9e09wrowe d->override |= OR_AUTHCFG;
948096a99010fccf648814fecf38f75c689172d7wrowe }
0540a0b469147b52e858587270dba31c2aaa9e09wrowe else if (!strcasecmp(w, "Indexes")) {
696218c49632c863d18b25fa52ab63617088cb38wrowe d->override |= OR_INDEXES;
948096a99010fccf648814fecf38f75c689172d7wrowe }
0540a0b469147b52e858587270dba31c2aaa9e09wrowe else if (!strcasecmp(w, "None")) {
948096a99010fccf648814fecf38f75c689172d7wrowe d->override = OR_NONE;
948096a99010fccf648814fecf38f75c689172d7wrowe }
948096a99010fccf648814fecf38f75c689172d7wrowe else if (!strcasecmp(w, "All")) {
948096a99010fccf648814fecf38f75c689172d7wrowe d->override = OR_ALL;
053497224246c4dbef9af594cacf5c00ed271e6cwrowe }
948096a99010fccf648814fecf38f75c689172d7wrowe else {
948096a99010fccf648814fecf38f75c689172d7wrowe return apr_pstrcat(cmd->pool, "Illegal override option ", w, NULL);
053497224246c4dbef9af594cacf5c00ed271e6cwrowe }
053497224246c4dbef9af594cacf5c00ed271e6cwrowe d->override &= ~OR_UNSET;
948096a99010fccf648814fecf38f75c689172d7wrowe }
948096a99010fccf648814fecf38f75c689172d7wrowe
053497224246c4dbef9af594cacf5c00ed271e6cwrowe return NULL;
948096a99010fccf648814fecf38f75c689172d7wrowe}
053497224246c4dbef9af594cacf5c00ed271e6cwrowe
053497224246c4dbef9af594cacf5c00ed271e6cwrowestatic const char *set_options(cmd_parms *cmd, void *d_, const char *l)
948096a99010fccf648814fecf38f75c689172d7wrowe{
948096a99010fccf648814fecf38f75c689172d7wrowe core_dir_config *d=d_;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb allow_options_t opt;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb int first = 1;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb char action;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
a2a0abd88b19e042a3eb2a9fa1702c25ad51303dwrowe while (l[0]) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb char *w = ap_getword_conf(cmd->pool, &l);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe action = '\0';
aa047239dedf0d26e8efecfade32e7337f35df19wrowe
aa047239dedf0d26e8efecfade32e7337f35df19wrowe if (*w == '+' || *w == '-') {
0540a0b469147b52e858587270dba31c2aaa9e09wrowe action = *(w++);
0540a0b469147b52e858587270dba31c2aaa9e09wrowe }
aa047239dedf0d26e8efecfade32e7337f35df19wrowe else if (first) {
aa047239dedf0d26e8efecfade32e7337f35df19wrowe d->opts = OPT_NONE;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb first = 0;
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe }
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe if (!strcasecmp(w, "Indexes")) {
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe opt = OPT_INDEXES;
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe }
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe else if (!strcasecmp(w, "Includes")) {
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe opt = OPT_INCLUDES;
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe }
aa047239dedf0d26e8efecfade32e7337f35df19wrowe else if (!strcasecmp(w, "IncludesNOEXEC")) {
aa047239dedf0d26e8efecfade32e7337f35df19wrowe opt = (OPT_INCLUDES | OPT_INCNOEXEC);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe }
aa047239dedf0d26e8efecfade32e7337f35df19wrowe else if (!strcasecmp(w, "FollowSymLinks")) {
aa047239dedf0d26e8efecfade32e7337f35df19wrowe opt = OPT_SYM_LINKS;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe }
0540a0b469147b52e858587270dba31c2aaa9e09wrowe else if (!strcasecmp(w, "SymLinksIfOwnerMatch")) {
aa047239dedf0d26e8efecfade32e7337f35df19wrowe opt = OPT_SYM_OWNER;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe }
aa047239dedf0d26e8efecfade32e7337f35df19wrowe else if (!strcasecmp(w, "execCGI")) {
aa047239dedf0d26e8efecfade32e7337f35df19wrowe opt = OPT_EXECCGI;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe }
aa047239dedf0d26e8efecfade32e7337f35df19wrowe else if (!strcasecmp(w, "MultiViews")) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb opt = OPT_MULTI;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
aa047239dedf0d26e8efecfade32e7337f35df19wrowe else if (!strcasecmp(w, "RunScripts")) { /* AI backcompat. Yuck */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb opt = OPT_MULTI|OPT_EXECCGI;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
aa047239dedf0d26e8efecfade32e7337f35df19wrowe else if (!strcasecmp(w, "None")) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb opt = OPT_NONE;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
aa047239dedf0d26e8efecfade32e7337f35df19wrowe else if (!strcasecmp(w, "All")) {
aa047239dedf0d26e8efecfade32e7337f35df19wrowe opt = OPT_ALL;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe }
aa047239dedf0d26e8efecfade32e7337f35df19wrowe else {
0540a0b469147b52e858587270dba31c2aaa9e09wrowe return apr_pstrcat(cmd->pool, "Illegal option ", w, NULL);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe }
aa047239dedf0d26e8efecfade32e7337f35df19wrowe
aa047239dedf0d26e8efecfade32e7337f35df19wrowe /* we ensure the invariant (d->opts_add & d->opts_remove) == 0 */
aa047239dedf0d26e8efecfade32e7337f35df19wrowe if (action == '-') {
aa047239dedf0d26e8efecfade32e7337f35df19wrowe d->opts_remove |= opt;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe d->opts_add &= ~opt;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe d->opts &= ~opt;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe }
aa047239dedf0d26e8efecfade32e7337f35df19wrowe else if (action == '+') {
aa047239dedf0d26e8efecfade32e7337f35df19wrowe d->opts_add |= opt;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe d->opts_remove &= ~opt;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe d->opts |= opt;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe }
aa047239dedf0d26e8efecfade32e7337f35df19wrowe else {
aa047239dedf0d26e8efecfade32e7337f35df19wrowe d->opts |= opt;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe }
0540a0b469147b52e858587270dba31c2aaa9e09wrowe }
aa047239dedf0d26e8efecfade32e7337f35df19wrowe
aa047239dedf0d26e8efecfade32e7337f35df19wrowe return NULL;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe}
0540a0b469147b52e858587270dba31c2aaa9e09wrowe
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic const char *satisfy(cmd_parms *cmd, void *c_, const char *arg)
aa047239dedf0d26e8efecfade32e7337f35df19wrowe{
aa047239dedf0d26e8efecfade32e7337f35df19wrowe core_dir_config *c=c_;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (!strcasecmp(arg, "all")) {
0540a0b469147b52e858587270dba31c2aaa9e09wrowe c->satisfy = SATISFY_ALL;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe }
0540a0b469147b52e858587270dba31c2aaa9e09wrowe else if (!strcasecmp(arg, "any")) {
0540a0b469147b52e858587270dba31c2aaa9e09wrowe c->satisfy = SATISFY_ANY;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe }
aa047239dedf0d26e8efecfade32e7337f35df19wrowe else {
aa047239dedf0d26e8efecfade32e7337f35df19wrowe return "Satisfy either 'any' or 'all'.";
aa047239dedf0d26e8efecfade32e7337f35df19wrowe }
aa047239dedf0d26e8efecfade32e7337f35df19wrowe return NULL;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe}
aa047239dedf0d26e8efecfade32e7337f35df19wrowe
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic const char *require(cmd_parms *cmd, void *c_, const char *arg)
aa047239dedf0d26e8efecfade32e7337f35df19wrowe{
aa047239dedf0d26e8efecfade32e7337f35df19wrowe require_line *r;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe core_dir_config *c=c_;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe
0540a0b469147b52e858587270dba31c2aaa9e09wrowe if (!c->ap_requires) {
aa047239dedf0d26e8efecfade32e7337f35df19wrowe c->ap_requires = apr_array_make(cmd->pool, 2, sizeof(require_line));
aa047239dedf0d26e8efecfade32e7337f35df19wrowe }
aa047239dedf0d26e8efecfade32e7337f35df19wrowe r = (require_line *)apr_array_push(c->ap_requires);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe r->requirement = apr_pstrdup(cmd->pool, arg);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb r->method_mask = cmd->limited;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe return NULL;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe}
aa047239dedf0d26e8efecfade32e7337f35df19wrowe
aa047239dedf0d26e8efecfade32e7337f35df19wroweAP_CORE_DECLARE_NONSTD(const char *) ap_limit_section(cmd_parms *cmd, void *dummy,
aa047239dedf0d26e8efecfade32e7337f35df19wrowe const char *arg) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb const char *limited_methods = ap_getword(cmd->pool, &arg, '>');
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb void *tog = cmd->cmd->cmd_data;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe apr_int64_t limited = 0;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe const char *errmsg;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe
0540a0b469147b52e858587270dba31c2aaa9e09wrowe const char *err = ap_check_cmd_context(cmd, NOT_IN_LIMIT);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe if (err != NULL) {
0540a0b469147b52e858587270dba31c2aaa9e09wrowe return err;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe }
aa047239dedf0d26e8efecfade32e7337f35df19wrowe
0540a0b469147b52e858587270dba31c2aaa9e09wrowe while (limited_methods[0]) {
aa047239dedf0d26e8efecfade32e7337f35df19wrowe char *method = ap_getword_conf(cmd->pool, &limited_methods);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb int methnum;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe
aa047239dedf0d26e8efecfade32e7337f35df19wrowe /* check for builtin or module registered method number */
aa047239dedf0d26e8efecfade32e7337f35df19wrowe methnum = ap_method_number_of(method);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe
aa047239dedf0d26e8efecfade32e7337f35df19wrowe if (methnum == M_TRACE && !tog) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return "TRACE cannot be controlled by <Limit>";
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe }
aa047239dedf0d26e8efecfade32e7337f35df19wrowe else if (methnum == M_INVALID) {
aa047239dedf0d26e8efecfade32e7337f35df19wrowe /* method has not been registered yet, but resorce restriction
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe * is always checked before method handling, so register it.
aa047239dedf0d26e8efecfade32e7337f35df19wrowe */
aa047239dedf0d26e8efecfade32e7337f35df19wrowe methnum = ap_method_register(cmd->pool, method);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe }
aa047239dedf0d26e8efecfade32e7337f35df19wrowe limited |= (AP_METHOD_BIT << methnum);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe }
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Killing two features with one function,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * if (tog == NULL) <Limit>, else <LimitExcept>
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb cmd->limited = tog ? ~limited : limited;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb errmsg = ap_walk_config(cmd->directive->first_child, cmd, cmd->context);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb cmd->limited = -1;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return errmsg;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb/* We use this in <DirectoryMatch> and <FilesMatch>, to ensure that
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * people don't get bitten by wrong-cased regex matches
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#ifdef WIN32
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#define USE_ICASE REG_ICASE
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#else
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#define USE_ICASE 0
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#endif
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb/*
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Report a missing-'>' syntax error.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic char *unclosed_directive(cmd_parms *cmd)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return apr_pstrcat(cmd->pool, cmd->cmd->name,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "> directive missing closing '>'", NULL);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowestatic const char *dirsection(cmd_parms *cmd, void *mconfig, const char *arg)
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe{
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe const char *errmsg;
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe const char *endp = ap_strrchr_c(arg, '>');
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe int old_overrides = cmd->override;
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe char *old_path = cmd->path;
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe core_dir_config *conf;
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe ap_conf_vector_t *new_dir_conf = ap_create_per_dir_config(cmd->pool);
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe regex_t *r = NULL;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe const command_rec *thiscmd = cmd->cmd;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe const char *err = ap_check_cmd_context(cmd,
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe NOT_IN_DIR_LOC_FILE|NOT_IN_LIMIT);
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe if (err != NULL) {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe return err;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe }
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe if (endp == NULL) {
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe return unclosed_directive(cmd);
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe }
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe arg=apr_pstrndup(cmd->pool, arg, endp-arg);
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe if (!arg) {
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe if (thiscmd->cmd_data)
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe return "<DirectoryMatch > block must specify a path";
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe else
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe return "<Directory > block must specify a path";
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe }
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe cmd->path = ap_getword_conf(cmd->pool, &arg);
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe cmd->override = OR_ALL|ACCESS_CONF;
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe if (!strcmp(cmd->path, "~")) {
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe cmd->path = ap_getword_conf(cmd->pool, &arg);
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe if (!cmd->path)
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe return "<Directory ~ > block must specify a path";
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else if (thiscmd->cmd_data) { /* <DirectoryMatch> */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb r = ap_pregcomp(cmd->pool, cmd->path, REG_EXTENDED|USE_ICASE);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else if (cmd->path[strlen(cmd->path) - 1] != '/') {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb cmd->path = apr_pstrcat(cmd->pool, cmd->path, "/");
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (!strcmp(cmd->path, "/") == 0)
68b29bcadd6c46aecdc9fe14c93555a2238ad2aagregames {
68b29bcadd6c46aecdc9fe14c93555a2238ad2aagregames char *newpath;
68b29bcadd6c46aecdc9fe14c93555a2238ad2aagregames /* Ensure that the pathname is canonical */
68b29bcadd6c46aecdc9fe14c93555a2238ad2aagregames if (apr_filepath_merge(&newpath, NULL, cmd->path,
68b29bcadd6c46aecdc9fe14c93555a2238ad2aagregames APR_FILEPATH_TRUENAME, cmd->pool) != APR_SUCCESS) {
68b29bcadd6c46aecdc9fe14c93555a2238ad2aagregames return apr_pstrcat(cmd->pool, "<Directory \"", cmd->path,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "\"> path is invalid.", NULL);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb cmd->path = newpath;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* initialize our config and fetch it */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb conf = ap_set_config_vectors(cmd->server, new_dir_conf, cmd->path,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb &core_module, cmd->pool);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb errmsg = ap_walk_config(cmd->directive->first_child, cmd, new_dir_conf);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (errmsg != NULL)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return errmsg;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb conf->r = r;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb conf->d = cmd->path;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb conf->d_is_fnmatch = (apr_is_fnmatch(conf->d) != 0);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
48d2edbfb84e5559b5da0f8d614ccab805cc67a8rbb /* Make this explicit - the "/" root has 0 elements, that is, we
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * will always merge it, and it will always sort and merge first.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * All others are sorted and tested by the number of slashes.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (strcmp(conf->d, "/") == 0)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb conf->d_components = 0;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe else
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe conf->d_components = ap_count_dirs(conf->d);
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe ap_add_per_dir_conf(cmd->server, new_dir_conf);
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (*arg != '\0') {
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe return apr_pstrcat(cmd->pool, "Multiple ", thiscmd->name,
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe "> arguments not (yet) supported.", NULL);
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe }
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe cmd->path = old_path;
1b839c67d5c0e4b1f22b44a4217f9860b420d47cwrowe cmd->override = old_overrides;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
1ab995011876f631740d68d960a6d729ddff5bfawrowe return NULL;
b45c1c292ff1fa635004ae81fa691f8cb3cdda85rbb}
b45c1c292ff1fa635004ae81fa691f8cb3cdda85rbb
b45c1c292ff1fa635004ae81fa691f8cb3cdda85rbbstatic const char *urlsection(cmd_parms *cmd, void *mconfig, const char *arg)
b45c1c292ff1fa635004ae81fa691f8cb3cdda85rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb const char *errmsg;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb const char *endp = ap_strrchr_c(arg, '>');
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb int old_overrides = cmd->override;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb char *old_path = cmd->path;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb core_dir_config *conf;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb regex_t *r = NULL;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb const command_rec *thiscmd = cmd->cmd;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_conf_vector_t *new_url_conf = ap_create_per_dir_config(cmd->pool);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb const char *err = ap_check_cmd_context(cmd,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb NOT_IN_DIR_LOC_FILE|NOT_IN_LIMIT);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (err != NULL) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return err;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (endp == NULL) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return unclosed_directive(cmd);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb arg=apr_pstrndup(cmd->pool, arg, endp-arg);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb cmd->path = ap_getword_conf(cmd->pool, &arg);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb cmd->override = OR_ALL|ACCESS_CONF;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (thiscmd->cmd_data) { /* <LocationMatch> */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb r = ap_pregcomp(cmd->pool, cmd->path, REG_EXTENDED);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
efa1a34b0a7785fc72863eff175b0cfc1ecb0e38wrowe else if (!strcmp(cmd->path, "~")) {
117026201e6d8fe7d82416b8a7324830f5a87292wrowe cmd->path = ap_getword_conf(cmd->pool, &arg);
117026201e6d8fe7d82416b8a7324830f5a87292wrowe r = ap_pregcomp(cmd->pool, cmd->path, REG_EXTENDED);
117026201e6d8fe7d82416b8a7324830f5a87292wrowe }
117026201e6d8fe7d82416b8a7324830f5a87292wrowe
117026201e6d8fe7d82416b8a7324830f5a87292wrowe /* initialize our config and fetch it */
117026201e6d8fe7d82416b8a7324830f5a87292wrowe conf = ap_set_config_vectors(cmd->server, new_url_conf, cmd->path,
117026201e6d8fe7d82416b8a7324830f5a87292wrowe &core_module, cmd->pool);
117026201e6d8fe7d82416b8a7324830f5a87292wrowe
117026201e6d8fe7d82416b8a7324830f5a87292wrowe errmsg = ap_walk_config(cmd->directive->first_child, cmd, new_url_conf);
117026201e6d8fe7d82416b8a7324830f5a87292wrowe if (errmsg != NULL)
117026201e6d8fe7d82416b8a7324830f5a87292wrowe return errmsg;
1ab995011876f631740d68d960a6d729ddff5bfawrowe
117026201e6d8fe7d82416b8a7324830f5a87292wrowe conf->d = apr_pstrdup(cmd->pool, cmd->path); /* No mangling, please */
117026201e6d8fe7d82416b8a7324830f5a87292wrowe conf->d_is_fnmatch = apr_is_fnmatch(conf->d) != 0;
117026201e6d8fe7d82416b8a7324830f5a87292wrowe conf->r = r;
117026201e6d8fe7d82416b8a7324830f5a87292wrowe
55eb5bb774cfb861542b827fbf4c30e6efbbfc44wrowe ap_add_per_url_conf(cmd->server, new_url_conf);
117026201e6d8fe7d82416b8a7324830f5a87292wrowe
117026201e6d8fe7d82416b8a7324830f5a87292wrowe if (*arg != '\0') {
117026201e6d8fe7d82416b8a7324830f5a87292wrowe return apr_pstrcat(cmd->pool, "Multiple ", thiscmd->name,
117026201e6d8fe7d82416b8a7324830f5a87292wrowe "> arguments not (yet) supported.", NULL);
117026201e6d8fe7d82416b8a7324830f5a87292wrowe }
117026201e6d8fe7d82416b8a7324830f5a87292wrowe
117026201e6d8fe7d82416b8a7324830f5a87292wrowe cmd->path = old_path;
117026201e6d8fe7d82416b8a7324830f5a87292wrowe cmd->override = old_overrides;
117026201e6d8fe7d82416b8a7324830f5a87292wrowe
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe return NULL;
117026201e6d8fe7d82416b8a7324830f5a87292wrowe}
117026201e6d8fe7d82416b8a7324830f5a87292wrowe
e7505ba54ac56ae30e4e250f912f3dbaf92ca45fwrowestatic const char *filesection(cmd_parms *cmd, void *mconfig, const char *arg)
e7505ba54ac56ae30e4e250f912f3dbaf92ca45fwrowe{
e7505ba54ac56ae30e4e250f912f3dbaf92ca45fwrowe const char *errmsg;
117026201e6d8fe7d82416b8a7324830f5a87292wrowe const char *endp = ap_strrchr_c(arg, '>');
117026201e6d8fe7d82416b8a7324830f5a87292wrowe int old_overrides = cmd->override;
0540a0b469147b52e858587270dba31c2aaa9e09wrowe char *old_path = cmd->path;
0540a0b469147b52e858587270dba31c2aaa9e09wrowe core_dir_config *conf;
5b3abd2fecc712f08ad728114aa77137b9f67716wrowe regex_t *r = NULL;
5b3abd2fecc712f08ad728114aa77137b9f67716wrowe const command_rec *thiscmd = cmd->cmd;
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe core_dir_config *c=mconfig;
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe ap_conf_vector_t *new_file_conf = ap_create_per_dir_config(cmd->pool);
efa1a34b0a7785fc72863eff175b0cfc1ecb0e38wrowe const char *err = ap_check_cmd_context(cmd, NOT_IN_LIMIT|NOT_IN_LOCATION);
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe
beda1fb2f11c52ca4612460a5d5ba47398143efbwrowe if (err != NULL) {
beda1fb2f11c52ca4612460a5d5ba47398143efbwrowe return err;
beda1fb2f11c52ca4612460a5d5ba47398143efbwrowe }
beda1fb2f11c52ca4612460a5d5ba47398143efbwrowe
beda1fb2f11c52ca4612460a5d5ba47398143efbwrowe if (endp == NULL) {
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe return unclosed_directive(cmd);
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe arg=apr_pstrndup(cmd->pool, arg, endp-arg);
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe cmd->path = ap_getword_conf(cmd->pool, &arg);
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe /* Only if not an .htaccess file */
117026201e6d8fe7d82416b8a7324830f5a87292wrowe if (!old_path) {
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe cmd->override = OR_ALL|ACCESS_CONF;
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe }
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe if (thiscmd->cmd_data) { /* <FilesMatch> */
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe r = ap_pregcomp(cmd->pool, cmd->path, REG_EXTENDED|USE_ICASE);
117026201e6d8fe7d82416b8a7324830f5a87292wrowe }
117026201e6d8fe7d82416b8a7324830f5a87292wrowe else if (!strcmp(cmd->path, "~")) {
efa1a34b0a7785fc72863eff175b0cfc1ecb0e38wrowe cmd->path = ap_getword_conf(cmd->pool, &arg);
117026201e6d8fe7d82416b8a7324830f5a87292wrowe r = ap_pregcomp(cmd->pool, cmd->path, REG_EXTENDED|USE_ICASE);
0540a0b469147b52e858587270dba31c2aaa9e09wrowe }
1067418d9ed9ed9daeb3ca4f74e72db810c49833wrowe else {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe char *newpath;
1067418d9ed9ed9daeb3ca4f74e72db810c49833wrowe /* Ensure that the pathname is canonical, but we
1067418d9ed9ed9daeb3ca4f74e72db810c49833wrowe * can't test the case/aliases without a fixed path */
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if (apr_filepath_merge(&newpath, "", cmd->path,
1067418d9ed9ed9daeb3ca4f74e72db810c49833wrowe 0, cmd->pool) != APR_SUCCESS)
117026201e6d8fe7d82416b8a7324830f5a87292wrowe return apr_pstrcat(cmd->pool, "<Files \"", cmd->path,
117026201e6d8fe7d82416b8a7324830f5a87292wrowe "\"> is invalid.", NULL);
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe cmd->path = newpath;
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe }
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* initialize our config and fetch it */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb conf = ap_set_config_vectors(cmd->server, new_file_conf, cmd->path,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb &core_module, cmd->pool);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe errmsg = ap_walk_config(cmd->directive->first_child, cmd, new_file_conf);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (errmsg != NULL)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return errmsg;
1b839c67d5c0e4b1f22b44a4217f9860b420d47cwrowe
b45c1c292ff1fa635004ae81fa691f8cb3cdda85rbb conf->d = cmd->path;
1ab995011876f631740d68d960a6d729ddff5bfawrowe conf->d_is_fnmatch = apr_is_fnmatch(conf->d) != 0;
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe conf->r = r;
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe ap_add_file_conf(c, new_file_conf);
b45c1c292ff1fa635004ae81fa691f8cb3cdda85rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (*arg != '\0') {
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe return apr_pstrcat(cmd->pool, "Multiple ", thiscmd->name,
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe "> arguments not (yet) supported.", NULL);
ecc4a080f07af3fbc1b91bbd00997ec1d592c6f9wrowe }
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe
2d2dadb81bf34e3bc9321eabcd971a738431b364wrowe cmd->path = old_path;
2d2dadb81bf34e3bc9321eabcd971a738431b364wrowe cmd->override = old_overrides;
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe return NULL;
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe}
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowestatic const char *start_ifmod(cmd_parms *cmd, void *mconfig, const char *arg)
2d2dadb81bf34e3bc9321eabcd971a738431b364wrowe{
ecc4a080f07af3fbc1b91bbd00997ec1d592c6f9wrowe const char *endp = ap_strrchr_c(arg, '>');
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb int not = (arg[0] == '!');
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb module *found;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe if (endp == NULL) {
5b3abd2fecc712f08ad728114aa77137b9f67716wrowe return unclosed_directive(cmd);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
af7e32b660b02a378e91d40987e59b28864db954jwoolley arg=apr_pstrndup(cmd->pool, arg, endp-arg);
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe
0540a0b469147b52e858587270dba31c2aaa9e09wrowe if (not) {
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe arg++;
0540a0b469147b52e858587270dba31c2aaa9e09wrowe }
0540a0b469147b52e858587270dba31c2aaa9e09wrowe
0540a0b469147b52e858587270dba31c2aaa9e09wrowe found = ap_find_linked_module(arg);
0540a0b469147b52e858587270dba31c2aaa9e09wrowe
0540a0b469147b52e858587270dba31c2aaa9e09wrowe if ((!not && found) || (not && !found)) {
0540a0b469147b52e858587270dba31c2aaa9e09wrowe ap_directive_t *parent = NULL;
0540a0b469147b52e858587270dba31c2aaa9e09wrowe ap_directive_t *current = NULL;
0540a0b469147b52e858587270dba31c2aaa9e09wrowe const char *retval;
0540a0b469147b52e858587270dba31c2aaa9e09wrowe
0540a0b469147b52e858587270dba31c2aaa9e09wrowe retval = ap_build_cont_config(cmd->pool, cmd->temp_pool, cmd,
0540a0b469147b52e858587270dba31c2aaa9e09wrowe &current, &parent, "<IfModule");
0540a0b469147b52e858587270dba31c2aaa9e09wrowe *(ap_directive_t **)mconfig = current;
0540a0b469147b52e858587270dba31c2aaa9e09wrowe return retval;
0540a0b469147b52e858587270dba31c2aaa9e09wrowe }
0540a0b469147b52e858587270dba31c2aaa9e09wrowe else {
0540a0b469147b52e858587270dba31c2aaa9e09wrowe *(ap_directive_t **)mconfig = NULL;
0540a0b469147b52e858587270dba31c2aaa9e09wrowe return ap_soak_end_container(cmd, "<IfModule");
0540a0b469147b52e858587270dba31c2aaa9e09wrowe }
0540a0b469147b52e858587270dba31c2aaa9e09wrowe}
0540a0b469147b52e858587270dba31c2aaa9e09wrowe
0540a0b469147b52e858587270dba31c2aaa9e09wroweAP_DECLARE(int) ap_exists_config_define(const char *name)
0540a0b469147b52e858587270dba31c2aaa9e09wrowe{
0540a0b469147b52e858587270dba31c2aaa9e09wrowe char **defines;
0540a0b469147b52e858587270dba31c2aaa9e09wrowe int i;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb defines = (char **)ap_server_config_defines->elts;
5b3abd2fecc712f08ad728114aa77137b9f67716wrowe for (i = 0; i < ap_server_config_defines->nelts; i++) {
5b3abd2fecc712f08ad728114aa77137b9f67716wrowe if (strcmp(defines[i], name) == 0) {
5b3abd2fecc712f08ad728114aa77137b9f67716wrowe return 1;
5b3abd2fecc712f08ad728114aa77137b9f67716wrowe }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return 0;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic const char *start_ifdefine(cmd_parms *cmd, void *dummy, const char *arg)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
58097d7d8d1a394092374b9f6ddf76b7993724a4rbb const char *endp;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb int defined;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb int not = 0;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb endp = ap_strrchr_c(arg, '>');
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (endp == NULL) {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe return unclosed_directive(cmd);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb arg=apr_pstrndup(cmd->pool, arg, endp-arg);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (arg[0] == '!') {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb not = 1;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb arg++;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb defined = ap_exists_config_define(arg);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if ((!not && defined) || (not && !defined)) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_directive_t *parent = NULL;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_directive_t *current = NULL;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb const char *retval;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb retval = ap_build_cont_config(cmd->pool, cmd->temp_pool, cmd,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb &current, &parent, "<IfDefine");
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *(ap_directive_t **)dummy = current;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return retval;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *(ap_directive_t **)dummy = NULL;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return ap_soak_end_container(cmd, "<IfDefine");
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb/* httpd.conf commands... beginning with the <VirtualHost> business */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic const char *virtualhost_section(cmd_parms *cmd, void *dummy,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb const char *arg)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb server_rec *main_server = cmd->server, *s;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb const char *errmsg;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb const char *endp = ap_strrchr_c(arg, '>');
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb apr_pool_t *p = cmd->pool;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (err != NULL) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return err;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
if (endp == NULL) {
return unclosed_directive(cmd);
}
arg=apr_pstrndup(cmd->pool, arg, endp-arg);
/* FIXME: There's another feature waiting to happen here -- since you
can now put multiple addresses/names on a single <VirtualHost>
you might want to use it to group common definitions and then
define other "subhosts" with their individual differences. But
personally I'd rather just do it with a macro preprocessor. -djg */
if (main_server->is_virtual) {
return "<VirtualHost> doesn't nest!";
}
errmsg = ap_init_virtual_host(p, arg, main_server, &s);
if (errmsg) {
return errmsg;
}
s->next = main_server->next;
main_server->next = s;
s->defn_name = cmd->directive->filename;
s->defn_line_number = cmd->directive->line_num;
cmd->server = s;
errmsg = ap_walk_config(cmd->directive->first_child, cmd,
s->lookup_defaults);
cmd->server = main_server;
return errmsg;
}
static const char *set_server_alias(cmd_parms *cmd, void *dummy,
const char *arg)
{
if (!cmd->server->names) {
return "ServerAlias only used in <VirtualHost>";
}
while (*arg) {
char **item, *name = ap_getword_conf(cmd->pool, &arg);
if (ap_is_matchexp(name)) {
item = (char **)apr_array_push(cmd->server->wild_names);
}
else {
item = (char **)apr_array_push(cmd->server->names);
}
*item = name;
}
return NULL;
}
static const char *add_filter(cmd_parms *cmd, void *dummy, const char *arg)
{
core_dir_config *conf = dummy;
char **newfilter;
newfilter = (char **)apr_array_push(conf->output_filters);
*newfilter = apr_pstrdup(cmd->pool, arg);
return NULL;
}
static const char *add_input_filter(cmd_parms *cmd, void *dummy, const char *arg)
{
core_dir_config *conf = dummy;
char **newfilter;
newfilter = (char **)apr_array_push(conf->input_filters);
*newfilter = apr_pstrdup(cmd->pool, arg);
return NULL;
}
static const char *set_server_string_slot(cmd_parms *cmd, void *dummy,
const char *arg)
{
/* This one's pretty generic... */
int offset = (int)(long)cmd->info;
char *struct_ptr = (char *)cmd->server;
const char *err = ap_check_cmd_context(cmd,
NOT_IN_DIR_LOC_FILE|NOT_IN_LIMIT);
if (err != NULL) {
return err;
}
*(const char **)(struct_ptr + offset) = arg;
return NULL;
}
static const char *server_port(cmd_parms *cmd, void *dummy, const char *arg)
{
const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE|NOT_IN_LIMIT);
int port;
if (err != NULL) {
return err;
}
port = atoi(arg);
if (port <= 0 || port >= 65536) { /* 65536 == 1<<16 */
return apr_pstrcat(cmd->temp_pool, "The port number \"", arg,
"\" is outside the appropriate range "
"(i.e., 1..65535).", NULL);
}
cmd->server->port = port;
return NULL;
}
static const char *set_signature_flag(cmd_parms *cmd, void *d_,
const char *arg)
{
core_dir_config *d=d_;
const char *err = ap_check_cmd_context(cmd, NOT_IN_LIMIT);
if (err != NULL) {
return err;
}
if (strcasecmp(arg, "On") == 0) {
d->server_signature = srv_sig_on;
}
else if (strcasecmp(arg, "Off") == 0) {
d->server_signature = srv_sig_off;
}
else if (strcasecmp(arg, "EMail") == 0) {
d->server_signature = srv_sig_withmail;
}
else {
return "ServerSignature: use one of: off | on | email";
}
return NULL;
}
static const char *set_server_root(cmd_parms *cmd, void *dummy,
const char *arg)
{
const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
if (err != NULL) {
return err;
}
if ((apr_filepath_merge((char**)&ap_server_root, NULL, arg,
APR_FILEPATH_TRUENAME, cmd->pool) != APR_SUCCESS)
|| !ap_is_directory(cmd->pool, ap_server_root)) {
return "ServerRoot must be a valid directory";
}
return NULL;
}
static const char *set_timeout(cmd_parms *cmd, void *dummy, const char *arg)
{
const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE|NOT_IN_LIMIT);
if (err != NULL) {
return err;
}
cmd->server->timeout = atoi(arg);
return NULL;
}
static const char *set_idcheck(cmd_parms *cmd, void *d_, int arg)
{
core_dir_config *d=d_;
const char *err = ap_check_cmd_context(cmd, NOT_IN_LIMIT);
if (err != NULL) {
return err;
}
d->do_rfc1413 = arg != 0;
return NULL;
}
static const char *set_hostname_lookups(cmd_parms *cmd, void *d_,
const char *arg)
{
core_dir_config *d=d_;
const char *err = ap_check_cmd_context(cmd, NOT_IN_LIMIT);
if (err != NULL) {
return err;
}
if (!strcasecmp(arg, "on")) {
d->hostname_lookups = HOSTNAME_LOOKUP_ON;
}
else if (!strcasecmp(arg, "off")) {
d->hostname_lookups = HOSTNAME_LOOKUP_OFF;
}
else if (!strcasecmp(arg, "double")) {
d->hostname_lookups = HOSTNAME_LOOKUP_DOUBLE;
}
else {
return "parameter must be 'on', 'off', or 'double'";
}
return NULL;
}
static const char *set_serverpath(cmd_parms *cmd, void *dummy,
const char *arg)
{
const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE|NOT_IN_LIMIT);
if (err != NULL) {
return err;
}
cmd->server->path = arg;
cmd->server->pathlen = strlen(arg);
return NULL;
}
static const char *set_content_md5(cmd_parms *cmd, void *d_, int arg)
{
core_dir_config *d=d_;
const char *err = ap_check_cmd_context(cmd, NOT_IN_LIMIT);
if (err != NULL) {
return err;
}
d->content_md5 = arg != 0;
return NULL;
}
static const char *set_use_canonical_name(cmd_parms *cmd, void *d_,
const char *arg)
{
core_dir_config *d=d_;
const char *err = ap_check_cmd_context(cmd, NOT_IN_LIMIT);
if (err != NULL) {
return err;
}
if (strcasecmp(arg, "on") == 0) {
d->use_canonical_name = USE_CANONICAL_NAME_ON;
}
else if (strcasecmp(arg, "off") == 0) {
d->use_canonical_name = USE_CANONICAL_NAME_OFF;
}
else if (strcasecmp(arg, "dns") == 0) {
d->use_canonical_name = USE_CANONICAL_NAME_DNS;
}
else {
return "parameter must be 'on', 'off', or 'dns'";
}
return NULL;
}
static const char *include_config (cmd_parms *cmd, void *dummy,
const char *name)
{
ap_directive_t *conftree = NULL;
ap_process_resource_config(cmd->server,
ap_server_root_relative(cmd->pool, name),
&conftree, cmd->pool, cmd->temp_pool);
*(ap_directive_t **)dummy = conftree;
return NULL;
}
static const char *set_loglevel(cmd_parms *cmd, void *dummy, const char *arg)
{
char *str;
const char *err = ap_check_cmd_context(cmd,
NOT_IN_DIR_LOC_FILE|NOT_IN_LIMIT);
if (err != NULL) {
return err;
}
if ((str = ap_getword_conf(cmd->pool, &arg))) {
if (!strcasecmp(str, "emerg")) {
cmd->server->loglevel = APLOG_EMERG;
}
else if (!strcasecmp(str, "alert")) {
cmd->server->loglevel = APLOG_ALERT;
}
else if (!strcasecmp(str, "crit")) {
cmd->server->loglevel = APLOG_CRIT;
}
else if (!strcasecmp(str, "error")) {
cmd->server->loglevel = APLOG_ERR;
}
else if (!strcasecmp(str, "warn")) {
cmd->server->loglevel = APLOG_WARNING;
}
else if (!strcasecmp(str, "notice")) {
cmd->server->loglevel = APLOG_NOTICE;
}
else if (!strcasecmp(str, "info")) {
cmd->server->loglevel = APLOG_INFO;
}
else if (!strcasecmp(str, "debug")) {
cmd->server->loglevel = APLOG_DEBUG;
}
else {
return "LogLevel requires level keyword: one of "
"emerg/alert/crit/error/warn/notice/info/debug";
}
}
else {
return "LogLevel requires level keyword";
}
return NULL;
}
AP_DECLARE(const char *) ap_psignature(const char *prefix, request_rec *r)
{
char sport[20];
core_dir_config *conf;
conf = (core_dir_config *)ap_get_module_config(r->per_dir_config,
&core_module);
if ((conf->server_signature == srv_sig_off)
|| (conf->server_signature == srv_sig_unset)) {
return "";
}
apr_snprintf(sport, sizeof sport, "%u", (unsigned) ap_get_server_port(r));
if (conf->server_signature == srv_sig_withmail) {
return apr_pstrcat(r->pool, prefix, "<address>" AP_SERVER_BASEVERSION
" Server at <a href=\"mailto:",
r->server->server_admin, "\">",
ap_get_server_name(r), "</a> Port ", sport,
"</address>\n", NULL);
}
return apr_pstrcat(r->pool, prefix, "<address>" AP_SERVER_BASEVERSION
" Server at ", ap_get_server_name(r), " Port ", sport,
"</address>\n", NULL);
}
/*
* Load an authorisation realm into our location configuration, applying the
* usual rules that apply to realms.
*/
static const char *set_authname(cmd_parms *cmd, void *mconfig,
const char *word1)
{
core_dir_config *aconfig = (core_dir_config *)mconfig;
aconfig->ap_auth_name = ap_escape_quotes(cmd->pool, word1);
return NULL;
}
#ifdef _OSD_POSIX /* BS2000 Logon Passwd file */
static const char *set_bs2000_account(cmd_parms *cmd, void *dummy, char *name)
{
const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
if (err != NULL) {
return err;
}
return os_set_account(cmd->pool, name);
}
#endif /*_OSD_POSIX*/
/*
* Handle a request to include the server's OS platform in the Server
* response header field (the ServerTokens directive). Unfortunately
* this requires a new global in order to communicate the setting back to
* http_main so it can insert the information in the right place in the
* string.
*/
static char *server_version = NULL;
static int version_locked = 0;
enum server_token_type {
SrvTk_MIN, /* eg: Apache/1.3.0 */
SrvTk_OS, /* eg: Apache/1.3.0 (UNIX) */
SrvTk_FULL, /* eg: Apache/1.3.0 (UNIX) PHP/3.0 FooBar/1.2b */
SrvTk_PRODUCT_ONLY /* eg: Apache */
};
static enum server_token_type ap_server_tokens = SrvTk_FULL;
static apr_status_t reset_version(void *dummy)
{
version_locked = 0;
ap_server_tokens = SrvTk_FULL;
server_version = NULL;
return APR_SUCCESS;
}
AP_DECLARE(const char *) ap_get_server_version(void)
{
return (server_version ? server_version : AP_SERVER_BASEVERSION);
}
AP_DECLARE(void) ap_add_version_component(apr_pool_t *pconf, const char *component)
{
if (! version_locked) {
/*
* If the version string is null, register our cleanup to reset the
* pointer on pool destruction. We also know that, if NULL,
* we are adding the original SERVER_BASEVERSION string.
*/
if (server_version == NULL) {
apr_pool_cleanup_register(pconf, NULL, reset_version,
apr_pool_cleanup_null);
server_version = apr_pstrdup(pconf, component);
}
else {
/*
* Tack the given component identifier to the end of
* the existing string.
*/
server_version = apr_pstrcat(pconf, server_version, " ",
component, NULL);
}
}
}
/*
* This routine adds the real server base identity to the version string,
* and then locks out changes until the next reconfig.
*/
static void ap_set_version(apr_pool_t *pconf)
{
if (ap_server_tokens == SrvTk_PRODUCT_ONLY) {
ap_add_version_component(pconf, AP_SERVER_BASEPRODUCT);
}
else if (ap_server_tokens == SrvTk_MIN) {
ap_add_version_component(pconf, AP_SERVER_BASEVERSION);
}
else {
ap_add_version_component(pconf, AP_SERVER_BASEVERSION " (" PLATFORM ")");
}
/*
* Lock the server_version string if we're not displaying
* the full set of tokens
*/
if (ap_server_tokens != SrvTk_FULL) {
version_locked++;
}
}
static const char *set_serv_tokens(cmd_parms *cmd, void *dummy,
const char *arg)
{
const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
if (err != NULL) {
return err;
}
if (!strcasecmp(arg, "OS")) {
ap_server_tokens = SrvTk_OS;
}
else if (!strcasecmp(arg, "Min") || !strcasecmp(arg, "Minimal")) {
ap_server_tokens = SrvTk_MIN;
}
else if (!strcasecmp(arg, "Prod") || !strcasecmp(arg, "ProductOnly")) {
ap_server_tokens = SrvTk_PRODUCT_ONLY;
}
else {
ap_server_tokens = SrvTk_FULL;
}
return NULL;
}
static const char *set_limit_req_line(cmd_parms *cmd, void *dummy,
const char *arg)
{
const char *err = ap_check_cmd_context(cmd,
NOT_IN_DIR_LOC_FILE|NOT_IN_LIMIT);
int lim;
if (err != NULL) {
return err;
}
lim = atoi(arg);
if (lim < 0) {
return apr_pstrcat(cmd->temp_pool, "LimitRequestLine \"", arg,
"\" must be a non-negative integer", NULL);
}
if (lim > DEFAULT_LIMIT_REQUEST_LINE) {
return apr_psprintf(cmd->temp_pool, "LimitRequestLine \"%s\" "
"must not exceed the precompiled maximum of %d",
arg, DEFAULT_LIMIT_REQUEST_LINE);
}
cmd->server->limit_req_line = lim;
return NULL;
}
static const char *set_limit_req_fieldsize(cmd_parms *cmd, void *dummy,
const char *arg)
{
const char *err = ap_check_cmd_context(cmd,
NOT_IN_DIR_LOC_FILE|NOT_IN_LIMIT);
int lim;
if (err != NULL) {
return err;
}
lim = atoi(arg);
if (lim < 0) {
return apr_pstrcat(cmd->temp_pool, "LimitRequestFieldsize \"", arg,
"\" must be a non-negative integer (0 = no limit)",
NULL);
}
if (lim > DEFAULT_LIMIT_REQUEST_FIELDSIZE) {
return apr_psprintf(cmd->temp_pool, "LimitRequestFieldsize \"%s\" "
"must not exceed the precompiled maximum of %d",
arg, DEFAULT_LIMIT_REQUEST_FIELDSIZE);
}
cmd->server->limit_req_fieldsize = lim;
return NULL;
}
static const char *set_limit_req_fields(cmd_parms *cmd, void *dummy,
const char *arg)
{
const char *err = ap_check_cmd_context(cmd,
NOT_IN_DIR_LOC_FILE|NOT_IN_LIMIT);
int lim;
if (err != NULL) {
return err;
}
lim = atoi(arg);
if (lim < 0) {
return apr_pstrcat(cmd->temp_pool, "LimitRequestFields \"", arg,
"\" must be a non-negative integer (0 = no limit)",
NULL);
}
cmd->server->limit_req_fields = lim;
return NULL;
}
static const char *set_limit_req_body(cmd_parms *cmd, void *conf_,
const char *arg)
{
core_dir_config *conf=conf_;
const char *err = ap_check_cmd_context(cmd, NOT_IN_LIMIT);
if (err != NULL) {
return err;
}
/* WTF: If strtoul is not portable, then write a replacement.
* Instead we have an idiotic define in httpd.h that prevents
* it from being used even when it is available. Sheesh.
*/
conf->limit_req_body = (unsigned long)strtol(arg, (char **)NULL, 10);
return NULL;
}
static const char *set_limit_xml_req_body(cmd_parms *cmd, void *conf_,
const char *arg)
{
core_dir_config *conf = conf_;
const char *err = ap_check_cmd_context(cmd, NOT_IN_LIMIT);
if (err != NULL) {
return err;
}
conf->limit_xml_body = atol(arg);
if (conf->limit_xml_body < 0)
return "LimitXMLRequestBody requires a non-negative integer.";
return NULL;
}
AP_DECLARE(size_t) ap_get_limit_xml_body(const request_rec *r)
{
core_dir_config *conf;
conf = ap_get_module_config(r->per_dir_config, &core_module);
if (conf->limit_xml_body == AP_LIMIT_UNSET)
return AP_DEFAULT_LIMIT_XML_BODY;
return (size_t)conf->limit_xml_body;
}
#ifdef WIN32
static const char *set_interpreter_source(cmd_parms *cmd, core_dir_config *d,
char *arg)
{
if (!strcasecmp(arg, "registry")) {
d->script_interpreter_source = INTERPRETER_SOURCE_REGISTRY;
} else if (!strcasecmp(arg, "registry-strict")) {
d->script_interpreter_source = INTERPRETER_SOURCE_REGISTRY_STRICT;
} else if (!strcasecmp(arg, "script")) {
d->script_interpreter_source = INTERPRETER_SOURCE_SHEBANG;
} else {
return apr_pstrcat(cmd->temp_pool, "ScriptInterpreterSource \"", arg,
"\" must be \"registry\", \"registry-strict\" or "
"\"script\"", NULL);
}
return NULL;
}
#endif
#if !defined (RLIMIT_CPU) || !(defined (RLIMIT_DATA) || defined (RLIMIT_VMEM) || defined(RLIMIT_AS)) || !defined (RLIMIT_NPROC)
static const char *no_set_limit(cmd_parms *cmd, void *conf_,
const char *arg, const char *arg2)
{
ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, cmd->server,
"%s not supported on this platform", cmd->cmd->name);
return NULL;
}
#endif
#ifdef RLIMIT_CPU
static const char *set_limit_cpu(cmd_parms *cmd, void *conf_,
const char *arg, const char *arg2)
{
core_dir_config *conf=conf_;
unixd_set_rlimit(cmd, &conf->limit_cpu, arg, arg2, RLIMIT_CPU);
return NULL;
}
#endif
#if defined (RLIMIT_DATA) || defined (RLIMIT_VMEM) || defined(RLIMIT_AS)
static const char *set_limit_mem(cmd_parms *cmd, void *conf_,
const char *arg, const char * arg2)
{
core_dir_config *conf=conf_;
#if defined(RLIMIT_AS)
unixd_set_rlimit(cmd, &conf->limit_mem, arg, arg2 ,RLIMIT_AS);
#elif defined(RLIMIT_DATA)
unixd_set_rlimit(cmd, &conf->limit_mem, arg, arg2, RLIMIT_DATA);
#elif defined(RLIMIT_VMEM)
unixd_set_rlimit(cmd, &conf->limit_mem, arg, arg2, RLIMIT_VMEM);
#endif
return NULL;
}
#endif
#ifdef RLIMIT_NPROC
static const char *set_limit_nproc(cmd_parms *cmd, void *conf_,
const char *arg, const char * arg2)
{
core_dir_config *conf=conf_;
unixd_set_rlimit(cmd, &conf->limit_nproc, arg, arg2, RLIMIT_NPROC);
return NULL;
}
#endif
static apr_status_t writev_it_all(apr_socket_t *s,
struct iovec *vec, int nvec,
apr_size_t len, apr_size_t *nbytes)
{
apr_size_t bytes_written = 0;
apr_status_t rv;
apr_size_t n = len;
int i = 0;
*nbytes = 0;
/* XXX handle checking for non-blocking socket */
while (bytes_written != len) {
rv = apr_sendv(s, vec + i, nvec - i, &n);
bytes_written += n;
if (rv != APR_SUCCESS)
return rv;
*nbytes += n;
/* If the write did not complete, adjust the iovecs and issue
* apr_sendv again
*/
if (bytes_written < len) {
/* Skip over the vectors that have already been written */
apr_size_t cnt = vec[i].iov_len;
while (n >= cnt && i + 1 < nvec) {
i++;
cnt += vec[i].iov_len;
}
if (n < cnt) {
/* Handle partial write of vec i */
vec[i].iov_base = (char *) vec[i].iov_base +
(vec[i].iov_len - (cnt - n));
vec[i].iov_len = cnt -n;
}
}
n = len - bytes_written;
}
return APR_SUCCESS;
}
/* sendfile_it_all()
* send the entire file using sendfile()
* handle partial writes
* return only when all bytes have been sent or an error is encountered.
*/
#if APR_HAS_SENDFILE
static apr_status_t sendfile_it_all(conn_rec *c,
apr_file_t *fd,
apr_hdtr_t *hdtr,
apr_off_t file_offset,
apr_size_t file_bytes_left,
apr_size_t total_bytes_left,
apr_int32_t flags)
{
apr_status_t rv;
#ifdef AP_DEBUG
apr_int32_t timeout = 0;
#endif
AP_DEBUG_ASSERT((apr_getsocketopt(c->client_socket, APR_SO_TIMEOUT,
&timeout) == APR_SUCCESS) &&
timeout > 0); /* socket must be in timeout mode */
do {
apr_size_t tmplen = file_bytes_left;
rv = apr_sendfile(c->client_socket, fd, hdtr, &file_offset, &tmplen,
flags);
total_bytes_left -= tmplen;
if (!total_bytes_left || rv != APR_SUCCESS) {
return rv; /* normal case & error exit */
}
AP_DEBUG_ASSERT(total_bytes_left > 0 && tmplen > 0);
/* partial write, oooh noooo...
* Skip over any header data which was written
*/
while (tmplen && hdtr->numheaders) {
if (tmplen >= hdtr->headers[0].iov_len) {
tmplen -= hdtr->headers[0].iov_len;
--hdtr->numheaders;
++hdtr->headers;
}
else {
char *iov_base = (char *)hdtr->headers[0].iov_base;
hdtr->headers[0].iov_len -= tmplen;
iov_base += tmplen;
hdtr->headers[0].iov_base = iov_base;
tmplen = 0;
}
}
/* Skip over any file data which was written */
if (tmplen <= file_bytes_left) {
file_offset += tmplen;
file_bytes_left -= tmplen;
continue;
}
tmplen -= file_bytes_left;
file_bytes_left = 0;
file_offset = 0;
/* Skip over any trailer data which was written */
while (tmplen && hdtr->numtrailers) {
if (tmplen >= hdtr->trailers[0].iov_len) {
tmplen -= hdtr->trailers[0].iov_len;
--hdtr->numtrailers;
++hdtr->trailers;
}
else {
char *iov_base = (char *)hdtr->trailers[0].iov_base;
hdtr->trailers[0].iov_len -= tmplen;
iov_base += tmplen;
hdtr->trailers[0].iov_base = iov_base;
tmplen = 0;
}
}
} while (1);
}
#endif
/*
* emulate_sendfile()
* Sends the contents of file fd along with header/trailer bytes, if any,
* to the network. emulate_sendfile will return only when all the bytes have been
* sent (i.e., it handles partial writes) or on a network error condition.
*/
static apr_status_t emulate_sendfile(conn_rec *c, apr_file_t *fd,
apr_hdtr_t *hdtr, apr_off_t offset,
apr_size_t length, apr_size_t *nbytes)
{
apr_status_t rv = APR_SUCCESS;
apr_int32_t togo; /* Remaining number of bytes in the file to send */
apr_size_t sendlen = 0;
apr_size_t bytes_sent;
apr_int32_t i;
apr_off_t o; /* Track the file offset for partial writes */
char buffer[8192];
*nbytes = 0;
/* Send the headers
* writev_it_all handles partial writes.
* XXX: optimization... if headers are less than MIN_WRITE_SIZE, copy
* them into buffer
*/
if ( hdtr && hdtr->numheaders > 0 ) {
for (i = 0; i < hdtr->numheaders; i++) {
sendlen += hdtr->headers[i].iov_len;
}
rv = writev_it_all(c->client_socket, hdtr->headers, hdtr->numheaders,
sendlen, &bytes_sent);
if (rv == APR_SUCCESS)
*nbytes += bytes_sent; /* track total bytes sent */
}
/* Seek the file to 'offset' */
if (offset != 0 && rv == APR_SUCCESS) {
rv = apr_file_seek(fd, APR_SET, &offset);
}
/* Send the file, making sure to handle partial writes */
togo = length;
while (rv == APR_SUCCESS && togo) {
sendlen = togo > sizeof(buffer) ? sizeof(buffer) : togo;
o = 0;
rv = apr_file_read(fd, buffer, &sendlen);
while (rv == APR_SUCCESS && sendlen) {
bytes_sent = sendlen;
rv = apr_send(c->client_socket, &buffer[o], &bytes_sent);
if (rv == APR_SUCCESS) {
sendlen -= bytes_sent; /* sendlen != bytes_sent ==> partial write */
o += bytes_sent; /* o is where we are in the buffer */
*nbytes += bytes_sent;
togo -= bytes_sent; /* track how much of the file we've sent */
}
}
}
/* Send the trailers
* XXX: optimization... if it will fit, send this on the last send in the
* loop above
*/
sendlen = 0;
if ( rv == APR_SUCCESS && hdtr && hdtr->numtrailers > 0 ) {
for (i = 0; i < hdtr->numtrailers; i++) {
sendlen += hdtr->trailers[i].iov_len;
}
rv = writev_it_all(c->client_socket, hdtr->trailers, hdtr->numtrailers,
sendlen, &bytes_sent);
if (rv == APR_SUCCESS)
*nbytes += bytes_sent;
}
return rv;
}
/* Note --- ErrorDocument will now work from .htaccess files.
* The AllowOverride of Fileinfo allows webmasters to turn it off
*/
static const command_rec core_cmds[] = {
/* Old access config file commands */
AP_INIT_RAW_ARGS("<Directory", dirsection, NULL, RSRC_CONF,
"Container for directives affecting resources located in the specified "
"directories"),
AP_INIT_RAW_ARGS("<Location", urlsection, NULL, RSRC_CONF,
"Container for directives affecting resources accessed through the "
"specified URL paths"),
AP_INIT_RAW_ARGS("<VirtualHost", virtualhost_section, NULL, RSRC_CONF,
"Container to map directives to a particular virtual host, takes one or "
"more host addresses"),
AP_INIT_RAW_ARGS("<Files", filesection, NULL, OR_ALL,
"Container for directives affecting files matching specified patterns"),
AP_INIT_RAW_ARGS("<Limit", ap_limit_section, NULL, OR_ALL,
"Container for authentication directives when accessed using specified HTTP "
"methods"),
AP_INIT_RAW_ARGS("<LimitExcept", ap_limit_section, (void*)1, OR_ALL,
"Container for authentication directives to be applied when any HTTP "
"method other than those specified is used to access the resource"),
AP_INIT_TAKE1("<IfModule", start_ifmod, NULL, EXEC_ON_READ | OR_ALL,
"Container for directives based on existance of specified modules"),
AP_INIT_TAKE1("<IfDefine", start_ifdefine, NULL, EXEC_ON_READ | OR_ALL,
"Container for directives based on existance of command line defines"),
AP_INIT_RAW_ARGS("<DirectoryMatch", dirsection, (void*)1, RSRC_CONF,
"Container for directives affecting resources located in the "
"specified directories"),
AP_INIT_RAW_ARGS("<LocationMatch", urlsection, (void*)1, RSRC_CONF,
"Container for directives affecting resources accessed through the "
"specified URL paths"),
AP_INIT_RAW_ARGS("<FilesMatch", filesection, (void*)1, OR_ALL,
"Container for directives affecting files matching specified patterns"),
AP_INIT_TAKE1("AuthType", ap_set_string_slot,
(void*)APR_XtOffsetOf(core_dir_config, ap_auth_type), OR_AUTHCFG,
"An HTTP authorization type (e.g., \"Basic\")"),
AP_INIT_TAKE1("AuthName", set_authname, NULL, OR_AUTHCFG,
"The authentication realm (e.g. \"Members Only\")"),
AP_INIT_RAW_ARGS("Require", require, NULL, OR_AUTHCFG,
"Selects which authenticated users or groups may access a protected space"),
AP_INIT_TAKE1("Satisfy", satisfy, NULL, OR_AUTHCFG,
"access policy if both allow and require used ('all' or 'any')"),
#ifdef GPROF
AP_INIT_TAKE1("GprofDir", set_gprof_dir, NULL, RSRC_CONF,
"Directory to plop gmon.out files"),
#endif
AP_INIT_TAKE1("AddDefaultCharset", set_add_default_charset, NULL, OR_FILEINFO,
"The name of the default charset to add to any Content-Type without one or 'Off' to disable"),
/* Old resource config file commands */
AP_INIT_RAW_ARGS("AccessFileName", set_access_name, NULL, RSRC_CONF,
"Name(s) of per-directory config files (default: .htaccess)"),
AP_INIT_TAKE1("DocumentRoot", set_document_root, NULL, RSRC_CONF,
"Root directory of the document tree"),
AP_INIT_TAKE2("ErrorDocument", set_error_document, NULL, OR_FILEINFO,
"Change responses for HTTP errors"),
AP_INIT_RAW_ARGS("AllowOverride", set_override, NULL, ACCESS_CONF,
"Controls what groups of directives can be configured by per-directory "
"config files"),
AP_INIT_RAW_ARGS("Options", set_options, NULL, OR_OPTIONS,
"Set a number of attributes for a given directory"),
AP_INIT_TAKE1("DefaultType", ap_set_string_slot,
(void*)APR_XtOffsetOf (core_dir_config, ap_default_type),
OR_FILEINFO, "the default MIME type for untypable files"),
/* Old server config file commands */
AP_INIT_TAKE1("Port", server_port, NULL, RSRC_CONF, "A TCP port number"),
AP_INIT_TAKE1("HostnameLookups", set_hostname_lookups, NULL,
ACCESS_CONF|RSRC_CONF,
"\"on\" to enable, \"off\" to disable reverse DNS lookups, or \"double\" to "
"enable double-reverse DNS lookups"),
AP_INIT_TAKE1("ServerAdmin", set_server_string_slot,
(void *)APR_XtOffsetOf (server_rec, server_admin), RSRC_CONF,
"The email address of the server administrator"),
AP_INIT_TAKE1("ServerName", set_server_string_slot,
(void *)APR_XtOffsetOf (server_rec, server_hostname), RSRC_CONF,
"The hostname of the server"),
AP_INIT_TAKE1("ServerSignature", set_signature_flag, NULL, OR_ALL,
"En-/disable server signature (on|off|email)"),
AP_INIT_TAKE1("ServerRoot", set_server_root, NULL, RSRC_CONF,
"Common directory of server-related files (logs, confs, etc.)"),
AP_INIT_TAKE1("ErrorLog", set_server_string_slot,
(void *)APR_XtOffsetOf (server_rec, error_fname), RSRC_CONF,
"The filename of the error log"),
AP_INIT_RAW_ARGS("ServerAlias", set_server_alias, NULL, RSRC_CONF,
"A name or names alternately used to access the server"),
AP_INIT_TAKE1("ServerPath", set_serverpath, NULL, RSRC_CONF,
"The pathname the server can be reached at"),
AP_INIT_TAKE1("Timeout", set_timeout, NULL, RSRC_CONF,
"Timeout duration (sec)"),
AP_INIT_FLAG("IdentityCheck", set_idcheck, NULL, RSRC_CONF|ACCESS_CONF,
"Enable identd (RFC 1413) user lookups - SLOW"),
AP_INIT_FLAG("ContentDigest", set_content_md5, NULL, OR_OPTIONS,
"whether or not to send a Content-MD5 header with each request"),
AP_INIT_TAKE1("UseCanonicalName", set_use_canonical_name, NULL,
RSRC_CONF|ACCESS_CONF,
"How to work out the ServerName : Port when constructing URLs"),
/* TODO: RlimitFoo should all be part of mod_cgi, not in the core */
/* TODO: ListenBacklog in MPM */
AP_INIT_TAKE1("Include", include_config, NULL,
(RSRC_CONF | ACCESS_CONF | EXEC_ON_READ),
"Name of the config file to be included"),
AP_INIT_TAKE1("LogLevel", set_loglevel, NULL, RSRC_CONF,
"Level of verbosity in error logging"),
AP_INIT_TAKE1("NameVirtualHost", ap_set_name_virtual_host, NULL, RSRC_CONF,
"A numeric IP address:port, or the name of a host"),
#ifdef _OSD_POSIX
AP_INIT_TAKE1("BS2000Account", set_bs2000_account, NULL, RSRC_CONF,
"Name of server User's bs2000 logon account name"),
#endif
#ifdef WIN32
AP_INIT_TAKE1("ScriptInterpreterSource", set_interpreter_source, NULL,
OR_FILEINFO,
"Where to find interpreter to run Win32 scripts (Registry or script shebang line)"),
#endif
AP_INIT_TAKE1("ServerTokens", set_serv_tokens, NULL, RSRC_CONF,
"Determine tokens displayed in the Server: header - Min(imal), OS or Full"),
AP_INIT_TAKE1("LimitRequestLine", set_limit_req_line, NULL, RSRC_CONF,
"Limit on maximum size of an HTTP request line"),
AP_INIT_TAKE1("LimitRequestFieldsize", set_limit_req_fieldsize, NULL,
RSRC_CONF,
"Limit on maximum size of an HTTP request header field"),
AP_INIT_TAKE1("LimitRequestFields", set_limit_req_fields, NULL, RSRC_CONF,
"Limit (0 = unlimited) on max number of header fields in a request message"),
AP_INIT_TAKE1("LimitRequestBody", set_limit_req_body,
(void*)APR_XtOffsetOf(core_dir_config, limit_req_body), OR_ALL,
"Limit (in bytes) on maximum size of request message body"),
AP_INIT_TAKE1("LimitXMLRequestBody", set_limit_xml_req_body, NULL, OR_ALL,
"Limit (in bytes) on maximum size of an XML-based request "
"body"),
/* System Resource Controls */
#ifdef RLIMIT_CPU
AP_INIT_TAKE12("RLimitCPU", set_limit_cpu,
(void*)APR_XtOffsetOf(core_dir_config, limit_cpu),
OR_ALL, "Soft/hard limits for max CPU usage in seconds"),
#else
AP_INIT_TAKE12("RLimitCPU", no_set_limit, NULL,
OR_ALL, "Soft/hard limits for max CPU usage in seconds"),
#endif
#if defined (RLIMIT_DATA) || defined (RLIMIT_VMEM) || defined (RLIMIT_AS)
AP_INIT_TAKE12("RLimitMEM", set_limit_mem,
(void*)APR_XtOffsetOf(core_dir_config, limit_mem),
OR_ALL, "Soft/hard limits for max memory usage per process"),
#else
AP_INIT_TAKE12("RLimitMEM", no_set_limit, NULL,
OR_ALL, "Soft/hard limits for max memory usage per process"),
#endif
#ifdef RLIMIT_NPROC
AP_INIT_TAKE12("RLimitNPROC", set_limit_nproc,
(void*)APR_XtOffsetOf(core_dir_config, limit_nproc),
OR_ALL, "soft/hard limits for max number of processes per uid"),
#else
AP_INIT_TAKE12("RLimitNPROC", no_set_limit, NULL,
OR_ALL, "soft/hard limits for max number of processes per uid"),
#endif
/* XXX These should be allowable in .htaccess files, but currently it won't
* play well with the Options stuff. Until that is fixed, I would prefer
* to leave it just in the conf file. Other should feel free to disagree
* with me. Rbb.
*/
AP_INIT_ITERATE("SetOutputFilter", add_filter, NULL, ACCESS_CONF,
"filters to be run"),
AP_INIT_ITERATE("SetInputFilter", add_input_filter, NULL, ACCESS_CONF,
"filters to be run on the request body"),
/*
* These are default configuration directives that mpms can/should
* pay attention to. If an mpm wishes to use these, they should
* #defined them in mpm.h.
*/
#ifdef AP_MPM_WANT_SET_PIDFILE
AP_INIT_TAKE1("PidFile", ap_mpm_set_pidfile, NULL, RSRC_CONF, \
"A file for logging the server process ID"),
#endif
#ifdef AP_MPM_WANT_SET_SCOREBOARD
AP_INIT_TAKE1("ScoreBoardFile", ap_mpm_set_scoreboard, NULL, RSRC_CONF, \
"A file for Apache to maintain runtime process management information"),
#endif
#ifdef AP_MPM_WANT_SET_LOCKFILE
AP_INIT_TAKE1("LockFile", ap_mpm_set_lockfile, NULL, RSRC_CONF, \
"The lockfile used when Apache needs to lock the accept() call"),
#endif
#ifdef AP_MPM_WANT_SET_MAX_REQUESTS
AP_INIT_TAKE1("MaxRequestsPerChild", ap_mpm_set_max_requests, NULL, RSRC_CONF,\
"Maximum number of requests a particular child serves before dying."),
#endif
#ifdef AP_MPM_WANT_SET_COREDUMPDIR
AP_INIT_TAKE1("CoreDumpDirectory", ap_mpm_set_coredumpdir, NULL, RSRC_CONF, \
"The location of the directory Apache changes to before dumping core"),
#endif
#ifdef AP_MPM_WANT_SET_ACCEPT_LOCK_MECH
AP_INIT_TAKE1("AcceptMutex", ap_mpm_set_accept_lock_mech, NULL, RSRC_CONF, \
"The system mutex implementation to use for the accept mutex"),
#endif
{ NULL }
};
/*****************************************************************
*
* Core handlers for various phases of server operation...
*/
AP_DECLARE_NONSTD(int) ap_core_translate(request_rec *r)
{
void *sconf = r->server->module_config;
core_server_config *conf = ap_get_module_config(sconf, &core_module);
/* XXX this seems too specific, this should probably become
* some general-case test
*/
if (r->proxyreq) {
return HTTP_FORBIDDEN;
}
if ((r->uri[0] != '/') && strcmp(r->uri, "*")) {
ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
"Invalid URI in request %s", r->the_request);
return HTTP_BAD_REQUEST;
}
if (r->server->path
&& !strncmp(r->uri, r->server->path, r->server->pathlen)
&& (r->server->path[r->server->pathlen - 1] == '/'
|| r->uri[r->server->pathlen] == '/'
|| r->uri[r->server->pathlen] == '\0')) {
if (apr_filepath_merge(&r->filename, conf->ap_document_root,
r->uri + r->server->pathlen,
APR_FILEPATH_TRUENAME
| APR_FILEPATH_SECUREROOT, r->pool)
!= APR_SUCCESS) {
return HTTP_FORBIDDEN;
}
r->canonical_filename = r->filename;
}
else {
/*
* Make sure that we do not mess up the translation by adding two
* /'s in a row. This happens under windows when the document
* root ends with a /
*/
if (apr_filepath_merge(&r->filename, conf->ap_document_root,
r->uri + ((*(r->uri) == '/') ? 1 : 0),
APR_FILEPATH_TRUENAME
| APR_FILEPATH_SECUREROOT, r->pool)
!= APR_SUCCESS) {
return HTTP_FORBIDDEN;
}
r->canonical_filename = r->filename;
}
return OK;
}
/*****************************************************************
*
* Test the filesystem name through directory_walk and file_walk
*/
static int core_map_to_storage(request_rec *r)
{
int access_status;
if ((access_status = ap_directory_walk(r))) {
return access_status;
}
if ((access_status = ap_file_walk(r))) {
return access_status;
}
return OK;
}
static int do_nothing(request_rec *r) { return OK; }
static int default_handler(request_rec *r)
{
apr_bucket_brigade *bb;
apr_bucket *e;
core_dir_config *d;
int errstatus;
apr_file_t *fd = NULL;
apr_status_t status;
/* XXX if/when somebody writes a content-md5 filter we either need to
* remove this support or coordinate when to use the filter vs.
* when to use this code
* The current choice of when to compute the md5 here matches the 1.3
* support fairly closely (unlike 1.3, we don't handle computing md5
* when the charset is translated).
*/
int bld_content_md5;
/*
* The old way of doing handlers meant that this handler would
* match literally anything - this way will require handler to
* have a / in the middle, which probably captures the original
* intent, but may cause problems at first - Ben 7th Jan 01
*/
if(strcmp(r->handler,"default-handler")
&& ap_strcmp_match(r->handler,"*/*"))
return DECLINED;
d = (core_dir_config *)ap_get_module_config(r->per_dir_config,
&core_module);
bld_content_md5 = (d->content_md5 & 1)
&& r->output_filters->frec->ftype != AP_FTYPE_CONTENT;
ap_allow_methods(r, MERGE_ALLOW, "GET", "OPTIONS", "POST", NULL);
if ((errstatus = ap_discard_request_body(r)) != OK) {
return errstatus;
}
if (r->method_number == M_INVALID) {
ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
"Invalid method in request %s", r->the_request);
return HTTP_NOT_IMPLEMENTED;
}
if (r->method_number == M_OPTIONS) {
return ap_send_http_options(r);
}
if (r->method_number == M_PUT) {
return HTTP_METHOD_NOT_ALLOWED;
}
if (r->finfo.filetype == 0 || (r->path_info && *r->path_info)) {
ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, r,
"File does not exist: %s",r->path_info ?
apr_pstrcat(r->pool, r->filename, r->path_info, NULL)
: r->filename);
return HTTP_NOT_FOUND;
}
if (r->method_number != M_GET && r->method_number != M_POST) {
return HTTP_METHOD_NOT_ALLOWED;
}
if ((status = apr_file_open(&fd, r->filename, APR_READ | APR_BINARY, 0, r->pool)) != APR_SUCCESS) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r,
"file permissions deny server access: %s", r->filename);
return HTTP_FORBIDDEN;
}
ap_update_mtime(r, r->finfo.mtime);
ap_set_last_modified(r);
ap_set_etag(r);
apr_table_setn(r->headers_out, "Accept-Ranges", "bytes");
ap_set_content_length(r, r->finfo.size);
if ((errstatus = ap_meets_conditions(r)) != OK) {
apr_file_close(fd);
return errstatus;
}
if (bld_content_md5) {
apr_table_setn(r->headers_out, "Content-MD5",
ap_md5digest(r->pool, fd));
}
bb = apr_brigade_create(r->pool);
#if APR_HAS_LARGE_FILES
if (r->finfo.size > AP_MAX_SENDFILE) {
/* APR_HAS_LARGE_FILES issue; must split into mutiple buckets,
* no greater than MAX(apr_size_t), and more granular than that
* in case the brigade code/filters attempt to read it directly.
*/
apr_off_t fsize = r->finfo.size;
e = apr_bucket_file_create(fd, 0, AP_MAX_SENDFILE, r->pool);
while (fsize > AP_MAX_SENDFILE) {
APR_BRIGADE_INSERT_TAIL(bb, e);
apr_bucket_copy(e, &e);
e->start += AP_MAX_SENDFILE;
fsize -= AP_MAX_SENDFILE;
}
e->length = (apr_size_t)fsize; /* Resize just the last bucket */
}
else
#endif
e = apr_bucket_file_create(fd, 0, (apr_size_t)r->finfo.size, r->pool);
APR_BRIGADE_INSERT_TAIL(bb, e);
e = apr_bucket_eos_create();
APR_BRIGADE_INSERT_TAIL(bb, e);
return ap_pass_brigade(r->output_filters, bb);
}
static int core_input_filter(ap_filter_t *f, apr_bucket_brigade *b, ap_input_mode_t mode, apr_off_t *readbytes)
{
apr_bucket *e;
if (!f->ctx) { /* If we haven't passed up the socket yet... */
f->ctx = (void *)1;
e = apr_bucket_socket_create(f->c->client_socket);
APR_BRIGADE_INSERT_TAIL(b, e);
return APR_SUCCESS;
}
else {
/* Either some code lost track of the socket
* bucket or we already found out that the
* client closed.
*/
return APR_EOF;
}
}
/* Default filter. This filter should almost always be used. Its only job
* is to send the headers if they haven't already been sent, and then send
* the actual data.
*/
typedef struct CORE_OUTPUT_FILTER_CTX {
apr_bucket_brigade *b;
} core_output_filter_ctx_t;
#define MAX_IOVEC_TO_WRITE 16
static apr_status_t core_output_filter(ap_filter_t *f, apr_bucket_brigade *b)
{
apr_status_t rv;
conn_rec *c = f->c;
core_output_filter_ctx_t *ctx = f->ctx;
if (ctx == NULL) {
f->ctx = ctx = apr_pcalloc(c->pool, sizeof(core_output_filter_ctx_t));
}
/* If we have a saved brigade, concatenate the new brigade to it */
if (ctx->b) {
APR_BRIGADE_CONCAT(ctx->b, b);
b = ctx->b;
ctx->b = NULL;
}
/* Perform multiple passes over the brigade, sending batches of output
to the connection. */
while (b) {
apr_size_t nbytes = 0;
apr_bucket *last_e = NULL; /* initialized for debugging */
apr_bucket *e;
/* tail of brigade if we need another pass */
apr_bucket_brigade *more = NULL;
/* one group of iovecs per pass over the brigade */
apr_size_t nvec = 0;
apr_size_t nvec_trailers = 0;
struct iovec vec[MAX_IOVEC_TO_WRITE];
struct iovec vec_trailers[MAX_IOVEC_TO_WRITE];
/* one file per pass over the brigade */
apr_file_t *fd = NULL;
apr_size_t flen = 0;
apr_off_t foffset = 0;
/* Iterate over the brigade: collect iovecs and/or a file */
APR_BRIGADE_FOREACH(e, b) {
/* XXX: APR_BRIGADE_FOREACH breaks the value of e!
* is that the expected behavior?
*/
last_e = e;
if (APR_BUCKET_IS_EOS(e) || APR_BUCKET_IS_FLUSH(e)) {
break;
}
/* It doesn't make any sense to use sendfile for a file bucket
* that represents 10 bytes.
*/
else if (APR_BUCKET_IS_FILE(e)
&& (e->length >= AP_MIN_SENDFILE_BYTES)) {
apr_bucket_file *a = e->data;
/* We can't handle more than one file bucket at a time
* so we split here and send the file we have already
* found.
*/
if (fd) {
more = apr_brigade_split(b, e);
break;
}
fd = a->fd;
flen = e->length;
foffset = e->start;
}
else {
const char *str;
apr_size_t n;
rv = apr_bucket_read(e, &str, &n, APR_BLOCK_READ);
if (n) {
if (!fd) {
if (nvec == MAX_IOVEC_TO_WRITE) {
/* woah! too many. stop now. */
more = apr_brigade_split(b, e);
break;
}
vec[nvec].iov_base = (char*) str;
vec[nvec].iov_len = n;
nvec++;
}
else {
/* The bucket is a trailer to a file bucket */
if (nvec_trailers == MAX_IOVEC_TO_WRITE) {
/* woah! too many. stop now. */
more = apr_brigade_split(b, e);
break;
}
vec_trailers[nvec_trailers].iov_base = (char*) str;
vec_trailers[nvec_trailers].iov_len = n;
nvec_trailers++;
}
nbytes += n;
}
}
}
/* Completed iterating over the brigades, now determine if we want
* to buffer the brigade or send the brigade out on the network.
*
* Save if:
*
* 1) we didn't see a file, we don't have more passes over the
* brigade to perform, we haven't accumulated enough bytes to
* send, AND we didn't stop at a FLUSH bucket.
* (IOW, we will save away plain old bytes)
* or
* 2) we hit the EOS and have a keep-alive connection
* (IOW, this response is a bit more complex, but we save it
* with the hope of concatenating with another response)
*/
if ((!fd && !more &&
(nbytes + flen < AP_MIN_BYTES_TO_WRITE) && !APR_BUCKET_IS_FLUSH(last_e))
|| (nbytes + flen < AP_MIN_BYTES_TO_WRITE && APR_BUCKET_IS_EOS(last_e) && c->keepalive)) {
/* NEVER save an EOS in here. If we are saving a brigade with
* an EOS bucket, then we are doing keepalive connections, and
* we want to process to second request fully.
*/
if (APR_BUCKET_IS_EOS(last_e)) {
apr_bucket *bucket = NULL;
/* If we are in here, then this request is a keepalive. We
* need to be certain that any data in a bucket is valid
* after the request_pool is cleared.
*/
if (ctx->b == NULL) {
ctx->b = apr_brigade_create(f->c->pool);
}
APR_BRIGADE_FOREACH(bucket, b) {
const char *str;
apr_size_t n;
rv = apr_bucket_read(bucket, &str, &n, APR_BLOCK_READ);
/* This apr_brigade_write does not use a flush function
because we assume that we will not write enough data
into it to cause a flush. However, if we *do* write
"too much", then we could end up with transient
buckets which would suck. This works for now, but is
a bit shaky if changes are made to some of the
buffering sizes. Let's do an assert to prevent
potential future problems... */
AP_DEBUG_ASSERT(AP_MIN_BYTES_TO_WRITE <=
APR_BUCKET_BUFF_SIZE);
if (rv != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_ERR, rv, c->base_server,
"core_output_filter: Error reading from bucket.");
return rv;
}
apr_brigade_write(ctx->b, NULL, NULL, str, n);
}
apr_brigade_destroy(b);
}
else {
ap_save_brigade(f, &ctx->b, &b, c->pool);
}
return APR_SUCCESS;
}
if (fd) {
apr_hdtr_t hdtr;
#if APR_HAS_SENDFILE
apr_int32_t flags = 0;
#endif
memset(&hdtr, '\0', sizeof(hdtr));
if (nvec) {
hdtr.numheaders = nvec;
hdtr.headers = vec;
}
if (nvec_trailers) {
hdtr.numtrailers = nvec_trailers;
hdtr.trailers = vec_trailers;
}
#if APR_HAS_SENDFILE
if (!c->keepalive) {
/* Prepare the socket to be reused */
flags |= APR_SENDFILE_DISCONNECT_SOCKET;
}
rv = sendfile_it_all(c, /* the connection */
fd, /* the file to send */
&hdtr, /* header and trailer iovecs */
foffset, /* offset in the file to begin
sending from */
flen, /* length of file */
nbytes + flen, /* total length including
headers */
flags); /* apr_sendfile flags */
/* If apr_sendfile() returns APR_ENOTIMPL, call emulate_sendfile().
* emulate_sendfile() is useful to enable the same Apache binary
* distribution to support Windows NT/2000 (supports TransmitFile)
* and Win95/98 (do not support TransmitFile)
*/
if (rv == APR_ENOTIMPL)
#endif
{
apr_size_t unused_bytes_sent;
rv = emulate_sendfile(c, fd, &hdtr, foffset, flen,
&unused_bytes_sent);
}
fd = NULL;
}
else {
apr_size_t unused_bytes_sent;
rv = writev_it_all(c->client_socket,
vec, nvec,
nbytes, &unused_bytes_sent);
}
apr_brigade_destroy(b);
if (rv != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_INFO, rv, c->base_server,
"core_output_filter: writing data to the network");
if (more)
apr_brigade_destroy(more);
if (APR_STATUS_IS_ECONNABORTED(rv) ||
APR_STATUS_IS_ECONNRESET(rv)) {
c->aborted = 1;
}
return rv;
}
b = more;
more = NULL;
} /* end while () */
return APR_SUCCESS;
}
static void core_post_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s)
{
ap_set_version(pconf);
}
static void core_open_logs(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s)
{
ap_open_logs(s, pconf);
}
static void core_insert_filter(request_rec *r)
{
int i;
core_dir_config *conf = (core_dir_config *)
ap_get_module_config(r->per_dir_config,
&core_module);
char **items = (char **)conf->output_filters->elts;
for (i = 0; i < conf->output_filters->nelts; i++) {
char *foobar = items[i];
ap_add_output_filter(foobar, NULL, r, r->connection);
}
items = (char **)conf->input_filters->elts;
for (i = 0; i < conf->input_filters->nelts; i++) {
char *foobar = items[i];
ap_add_input_filter(foobar, NULL, r, r->connection);
}
}
static int core_create_req(request_rec *r)
{
if (r->main) {
ap_set_module_config(r->request_config, &core_module,
ap_get_module_config(r->main->request_config, &core_module));
}
else {
core_request_config *req_cfg;
req_cfg = apr_pcalloc(r->pool, sizeof(core_request_config));
req_cfg->bb = apr_brigade_create(r->pool);
ap_set_module_config(r->request_config, &core_module, req_cfg);
}
return OK;
}
static void register_hooks(apr_pool_t *p)
{
ap_hook_post_config(core_post_config,NULL,NULL,APR_HOOK_REALLY_FIRST);
ap_hook_translate_name(ap_core_translate,NULL,NULL,APR_HOOK_REALLY_LAST);
ap_hook_map_to_storage(core_map_to_storage,NULL,NULL,APR_HOOK_REALLY_LAST);
ap_hook_open_logs(core_open_logs,NULL,NULL,APR_HOOK_MIDDLE);
ap_hook_handler(default_handler,NULL,NULL,APR_HOOK_REALLY_LAST);
/* FIXME: I suspect we can eliminate the need for these - Ben */
ap_hook_type_checker(do_nothing,NULL,NULL,APR_HOOK_REALLY_LAST);
ap_hook_access_checker(do_nothing,NULL,NULL,APR_HOOK_REALLY_LAST);
ap_hook_create_request(core_create_req, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_pre_mpm(ap_create_scoreboard, NULL, NULL, APR_HOOK_MIDDLE);
/* register the core's insert_filter hook and register core-provided
* filters
*/
ap_hook_insert_filter(core_insert_filter, NULL, NULL, APR_HOOK_MIDDLE);
ap_register_input_filter("CORE_IN", core_input_filter, AP_FTYPE_NETWORK);
ap_register_output_filter("CONTENT_LENGTH", ap_content_length_filter,
AP_FTYPE_HTTP_HEADER);
ap_register_output_filter("CORE", core_output_filter, AP_FTYPE_NETWORK);
ap_register_output_filter("SUBREQ_CORE", ap_sub_req_output_filter,
AP_FTYPE_CONTENT);
ap_register_output_filter("OLD_WRITE", ap_old_write_filter,
AP_FTYPE_CONTENT - 1);
}
AP_DECLARE_DATA module core_module = {
STANDARD20_MODULE_STUFF,
create_core_dir_config, /* create per-directory config structure */
merge_core_dir_configs, /* merge per-directory config structures */
create_core_server_config, /* create per-server config structure */
merge_core_server_configs, /* merge per-server config structures */
core_cmds, /* command apr_table_t */
register_hooks /* register hooks */
};