request.c revision 59513b1275fdc2021d4949ee03ae8229469abb86
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/*
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * http_request.c: functions to get and process requests
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Rob McCool 3/21/93
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Thoroughly revamped by rst for Apache. NB this file reads
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * best from the bottom up.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "apr_strings.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "apr_file_io.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "apr_fnmatch.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#define APR_WANT_STRFUNC
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_request.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "http_core.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "http_protocol.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "http_log.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "http_main.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "util_filter.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "util_charset.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "mod_core.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#if APR_HAVE_STDARG_H
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include <stdarg.h>
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#endif
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbAPR_HOOK_STRUCT(
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb APR_HOOK_LINK(translate_name)
a2a0abd88b19e042a3eb2a9fa1702c25ad51303dwrowe APR_HOOK_LINK(map_to_storage)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb APR_HOOK_LINK(check_user_id)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb APR_HOOK_LINK(fixups)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb APR_HOOK_LINK(type_checker)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb APR_HOOK_LINK(access_checker)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb APR_HOOK_LINK(auth_checker)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb APR_HOOK_LINK(insert_filter)
b45c1c292ff1fa635004ae81fa691f8cb3cdda85rbb APR_HOOK_LINK(create_request)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbAP_IMPLEMENT_HOOK_RUN_FIRST(int,translate_name,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb (request_rec *r),(r),DECLINED)
a2a0abd88b19e042a3eb2a9fa1702c25ad51303dwroweAP_IMPLEMENT_HOOK_RUN_FIRST(int,map_to_storage,
a2a0abd88b19e042a3eb2a9fa1702c25ad51303dwrowe (request_rec *r),(r),DECLINED)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbAP_IMPLEMENT_HOOK_RUN_FIRST(int,check_user_id,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb (request_rec *r),(r),DECLINED)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbAP_IMPLEMENT_HOOK_RUN_ALL(int,fixups,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb (request_rec *r),(r),OK,DECLINED)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbAP_IMPLEMENT_HOOK_RUN_FIRST(int,type_checker,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb (request_rec *r),(r),DECLINED)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbAP_IMPLEMENT_HOOK_RUN_ALL(int,access_checker,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb (request_rec *r),(r),OK,DECLINED)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbAP_IMPLEMENT_HOOK_RUN_FIRST(int,auth_checker,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb (request_rec *r),(r),DECLINED)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbAP_IMPLEMENT_HOOK_VOID(insert_filter, (request_rec *r), (r))
c3e342e5b0b9fea6617ee16d2da02c3ef2108126dougmAP_IMPLEMENT_HOOK_RUN_ALL(int,create_request,(request_rec *r),(r),OK,DECLINED)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowestatic int decl_die(int status, char *phase, request_rec *r)
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe{
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if (status == DECLINED) {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_CRIT, 0, r,
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe "configuration error: couldn't %s: %s", phase, r->uri);
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe return HTTP_INTERNAL_SERVER_ERROR;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe else
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe return status;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe}
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe/* This is the master logic for processing requests. Do NOT duplicate
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe * this logic elsewhere, or the security model will be broken by future
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe * API changes. Each phase must be individually optimized to pick up
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe * redundant/duplicate calls by subrequests, and redirects.
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe */
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewroweAP_DECLARE(int) ap_process_request_internal(request_rec *r)
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe{
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe int access_status;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe /* Ignore embedded %2F's in path for proxy requests */
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if (!r->proxyreq && r->parsed_uri.path) {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe access_status = ap_unescape_url(r->parsed_uri.path);
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if (access_status) {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe return access_status;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe ap_getparents(r->uri); /* OK --- shrinking transformations... */
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe /* File-specific requests with no 'true' URI are a huge pain... they
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe * cannot bubble through the next several steps. Only subrequests may
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe * have an empty uri, otherwise let translate_name kill the request.
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe */
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe if (!r->main || (r->uri && r->uri[0]))
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe if ((access_status = ap_location_walk(r))) {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe return access_status;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe if ((access_status = ap_run_translate_name(r))) {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe return decl_die(access_status, "translate", r);
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe return access_status;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe /* Reset to the server default config prior to running map_to_storage
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe */
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe r->per_dir_config = r->server->lookup_defaults;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe if ((access_status = ap_run_map_to_storage(r)))
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe /* This request wasn't in storage (e.g. TRACE) */
4775dfc34c90fada8c7c4d6a57ed8a3114d55c2dtrawick return access_status;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe /* Excluding file-specific requests with no 'true' URI...
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe */
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe if (!r->main || (r->uri && r->uri[0]))
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe /* Rerun the location walk, which overrides any map_to_storage config.
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe */
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe if ((access_status = ap_location_walk(r))) {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe return access_status;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe /* Only on the main request! */
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if (r->main == NULL) {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if ((access_status = ap_run_header_parser(r))) {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe return access_status;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe /* Skip authn/authz if the parent or prior request passed the authn/authz,
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe * and that configuration didn't change (this requires optimized _walk()
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe * functions in map_to_storage that use the same merge results given
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe * identical input.) If the config changes, we must re-auth.
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe */
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe if (r->main && (r->main->per_dir_config == r->per_dir_config)) {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe r->user = r->main->user;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe r->ap_auth_type = r->main->ap_auth_type;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe }
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe else if (r->prev && (r->prev->per_dir_config == r->per_dir_config)) {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe r->user = r->prev->user;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe r->ap_auth_type = r->prev->ap_auth_type;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe }
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe else
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe switch (ap_satisfies(r)) {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe case SATISFY_ALL:
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe case SATISFY_NOSPEC:
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe if ((access_status = ap_run_access_checker(r)) != 0) {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe return decl_die(access_status, "check access", r);
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe if (ap_some_auth_required(r)) {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe if (((access_status = ap_run_check_user_id(r)) != 0) || !ap_auth_type(r)) {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe return decl_die(access_status, ap_auth_type(r)
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe ? "check user. No user file?"
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe : "perform authentication. AuthType not set!", r);
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe }
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe if (((access_status = ap_run_auth_checker(r)) != 0) || !ap_auth_type(r)) {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe return decl_die(access_status, ap_auth_type(r)
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe ? "check access. No groups file?"
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe : "perform authentication. AuthType not set!", r);
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe break;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe case SATISFY_ANY:
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe if (((access_status = ap_run_access_checker(r)) != 0) || !ap_auth_type(r)) {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe if (!ap_some_auth_required(r)) {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe return decl_die(access_status, ap_auth_type(r)
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe ? "check access"
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe : "perform authentication. AuthType not set!", r);
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe }
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe if (((access_status = ap_run_check_user_id(r)) != 0) || !ap_auth_type(r)) {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe return decl_die(access_status, ap_auth_type(r)
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe ? "check user. No user file?"
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe : "perform authentication. AuthType not set!", r);
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe }
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe if (((access_status = ap_run_auth_checker(r)) != 0) || !ap_auth_type(r)) {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe return decl_die(access_status, ap_auth_type(r)
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe ? "check access. No groups file?"
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe : "perform authentication. AuthType not set!", r);
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe break;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe /* XXX Must make certain the ap_run_type_checker short circuits mime
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe * in mod-proxy for r->proxyreq && r->parsed_uri.scheme
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe * && !strcmp(r->parsed_uri.scheme, "http")
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe */
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if ((access_status = ap_run_type_checker(r)) != 0) {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe return decl_die(access_status, "find types", r);
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if ((access_status = ap_run_fixups(r)) != 0) {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe return access_status;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe /* The new insert_filter stage makes sense here IMHO. We are sure that
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe * we are going to run the request now, so we may as well insert filters
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe * if any are available. Since the goal of this phase is to allow all
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe * modules to insert a filter if they want to, this filter returns
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe * void. I just can't see any way that this filter can reasonably
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe * fail, either your modules inserts something or it doesn't. rbb
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe */
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe ap_run_insert_filter(r);
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe return OK;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe}
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe/* Useful caching structures to repeat _walk/merge sequences as required
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe * when a subrequest or redirect reuses substantially the same config.
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe *
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe * Directive order in the httpd.conf file and its Includes significantly
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe * impact this optimization. Grouping common blocks at the front of the
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe * config that are less likely to change between a request and
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe * its subrequests, or between a request and its redirects reduced
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe * the work of these functions significantly.
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe */
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe
0540a0b469147b52e858587270dba31c2aaa9e09wrowetypedef struct walk_walked_t {
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe ap_conf_vector_t *matched; /* A dir_conf sections we matched */
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe ap_conf_vector_t *merged; /* The dir_conf merged result */
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe} walk_walked_t;
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowetypedef struct walk_cache_t {
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe const char *cached; /* The identifier we matched */
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe ap_conf_vector_t **dir_conf_tested;/* The sections we matched against */
0f6fdc73136a064819585afe03bc3503826ee592wrowe ap_conf_vector_t *dir_conf_merged;/* Base per_dir_config */
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe ap_conf_vector_t *per_dir_result; /* per_dir_config += walked result */
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe apr_array_header_t *walked; /* The list of walk_walked_t results */
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe} walk_cache_t;
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowestatic walk_cache_t *prep_walk_cache(const char *cache_name, request_rec *r)
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe{
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe walk_cache_t *cache;
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe /* Find the most relevant, recent entry to work from. That would be
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe * this request (on the second call), or the parent request of a
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe * subrequest, or the prior request of an internal redirect. Provide
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe * this _walk()er with a copy it is allowed to munge. If there is no
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe * parent or prior cached request, then create a new walk cache.
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe */
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe if ((apr_pool_userdata_get((void **)&cache,
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe cache_name, r->pool)
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe != APR_SUCCESS) || !cache)
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe {
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe if ((r->main && (apr_pool_userdata_get((void **)&cache,
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe cache_name,
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe r->main->pool)
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe == APR_SUCCESS) && cache)
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe || (r->prev && (apr_pool_userdata_get((void **)&cache,
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe cache_name,
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe r->prev->pool)
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe == APR_SUCCESS) && cache)) {
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe cache = apr_pmemdup(r->pool, cache, sizeof(*cache));
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe cache->walked = apr_array_copy(r->pool, cache->walked);
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe }
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe else {
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe cache = apr_pcalloc(r->pool, sizeof(*cache));
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe cache->walked = apr_array_make(r->pool, 4, sizeof(walk_walked_t));
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe }
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe apr_pool_userdata_set(cache, cache_name,
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe apr_pool_cleanup_null, r->pool);
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe }
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe return cache;
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe}
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb/*****************************************************************
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Getting and checking directory configuration. Also checks the
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * FollowSymlinks and FollowSymOwner stuff, since this is really the
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * only place that can happen (barring a new mid_dir_walk callout).
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * We can't do it as an access_checker module function which gets
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * called with the final per_dir_config, since we could have a directory
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * with FollowSymLinks disabled, which contains a symlink to another
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * with a .htaccess file which turns FollowSymLinks back on --- and
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * access in such a case must be denied. So, whatever it is that
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * checks FollowSymLinks needs to know the state of the options as
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * they change, all the way down.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb/*
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * We don't want people able to serve up pipes, or unix sockets, or other
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * scary things. Note that symlink tests are performed later.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic int check_safe_file(request_rec *r)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (r->finfo.filetype == 0 /* doesn't exist */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb || r->finfo.filetype == APR_DIR
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb || r->finfo.filetype == APR_REG
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb || r->finfo.filetype == APR_LNK) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return OK;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "object is not a file, directory or symlink: %s",
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb r->filename);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return HTTP_FORBIDDEN;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe/*
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe * resolve_symlink must _always_ be called on an APR_LNK file type!
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe * It will resolve the actual target file type, modification date, etc,
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe * and provide any processing required for symlink evaluation.
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe * Path must already be cleaned, no trailing slash, no multi-slashes,
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe * and don't call this on the root!
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe *
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe * Simply, the number of times we deref a symlink are minimal compared
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe * to the number of times we had an extra lstat() since we 'weren't sure'.
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe *
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe * To optimize, we stat() anything when given (opts & OPT_SYM_LINKS), otherwise
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe * we start off with an lstat(). Every lstat() must be dereferenced in case
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe * it points at a 'nasty' - we must always rerun check_safe_file (or similar.)
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe */
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowestatic int resolve_symlink(char *d, apr_finfo_t *lfi, int opts, apr_pool_t *p)
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe{
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe apr_finfo_t fi;
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe int res;
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe
2f1949bb0e3c209db94c8d521cba7380b9d11421trawick if (!(opts & (OPT_SYM_OWNER | OPT_SYM_LINKS)))
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe return HTTP_FORBIDDEN;
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe if (opts & OPT_SYM_LINKS) {
2f1949bb0e3c209db94c8d521cba7380b9d11421trawick if ((res = apr_stat(&fi, d, lfi->valid, p)) != APR_SUCCESS)
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe return HTTP_FORBIDDEN;
11fb2f3611e6ff9a541e10b13e3108934f828141gregames
11fb2f3611e6ff9a541e10b13e3108934f828141gregames /* Give back the target */
11fb2f3611e6ff9a541e10b13e3108934f828141gregames memcpy(lfi, &fi, sizeof(fi));
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe return OK;
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe }
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe /* OPT_SYM_OWNER only works if we can get the owner of
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe * both the file and symlink. First fill in a missing
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe * owner of the symlink, then get the info of the target.
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe */
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe if (!(lfi->valid & APR_FINFO_OWNER))
2f1949bb0e3c209db94c8d521cba7380b9d11421trawick if ((res = apr_lstat(&fi, d, lfi->valid | APR_FINFO_OWNER, p))
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe != APR_SUCCESS)
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe return HTTP_FORBIDDEN;
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe
2f1949bb0e3c209db94c8d521cba7380b9d11421trawick if ((res = apr_stat(&fi, d, lfi->valid, p)) != APR_SUCCESS)
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe return HTTP_FORBIDDEN;
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe if (apr_compare_users(fi.user, lfi->user) != APR_SUCCESS)
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe return HTTP_FORBIDDEN;
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe /* Give back the target */
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe memcpy(lfi, &fi, sizeof(fi));
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe return OK;
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe/*****************************************************************
8aefbd756763807188d2e3ce336a8680e4893066wrowe *
8aefbd756763807188d2e3ce336a8680e4893066wrowe * Getting and checking directory configuration. Also checks the
8aefbd756763807188d2e3ce336a8680e4893066wrowe * FollowSymlinks and FollowSymOwner stuff, since this is really the
8aefbd756763807188d2e3ce336a8680e4893066wrowe * only place that can happen (barring a new mid_dir_walk callout).
8aefbd756763807188d2e3ce336a8680e4893066wrowe *
8aefbd756763807188d2e3ce336a8680e4893066wrowe * We can't do it as an access_checker module function which gets
8aefbd756763807188d2e3ce336a8680e4893066wrowe * called with the final per_dir_config, since we could have a directory
8aefbd756763807188d2e3ce336a8680e4893066wrowe * with FollowSymLinks disabled, which contains a symlink to another
8aefbd756763807188d2e3ce336a8680e4893066wrowe * with a .htaccess file which turns FollowSymLinks back on --- and
8aefbd756763807188d2e3ce336a8680e4893066wrowe * access in such a case must be denied. So, whatever it is that
8aefbd756763807188d2e3ce336a8680e4893066wrowe * checks FollowSymLinks needs to know the state of the options as
8aefbd756763807188d2e3ce336a8680e4893066wrowe * they change, all the way down.
8aefbd756763807188d2e3ce336a8680e4893066wrowe */
8aefbd756763807188d2e3ce336a8680e4893066wrowe
a2a0abd88b19e042a3eb2a9fa1702c25ad51303dwroweAP_DECLARE(int) ap_directory_walk(request_rec *r)
8aefbd756763807188d2e3ce336a8680e4893066wrowe{
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_conf_vector_t *now_merged = NULL;
8aefbd756763807188d2e3ce336a8680e4893066wrowe core_server_config *sconf = ap_get_module_config(r->server->module_config,
8aefbd756763807188d2e3ce336a8680e4893066wrowe &core_module);
2fa5b5878e7567e2875807c3e2a2b3b0d3ef74bewrowe ap_conf_vector_t **sec_ent = (ap_conf_vector_t **) sconf->sec_dir->elts;
2fa5b5878e7567e2875807c3e2a2b3b0d3ef74bewrowe int num_sec = sconf->sec_dir->nelts;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe walk_cache_t *cache;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe char *entry_dir;
8aefbd756763807188d2e3ce336a8680e4893066wrowe apr_status_t rv;
8aefbd756763807188d2e3ce336a8680e4893066wrowe
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe /* XXX: Better (faster) tests needed!!!
a8d11d78181478da6a672f7fbc58b8d523351f49wrowe *
8aa5ca8ff2a4d8e56f62ea3d461e2799136da085trawick * "OK" as a response to a real problem is not _OK_, but to allow broken
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe * modules to proceed, we will permit the not-a-path filename to pass here.
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe * We must catch it later if it's heading for the core handler. Leave an
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe * INFO note here for module debugging.
8aefbd756763807188d2e3ce336a8680e4893066wrowe */
a8d11d78181478da6a672f7fbc58b8d523351f49wrowe if (r->filename == NULL || !ap_os_is_path_absolute(r->pool, r->filename)) {
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_INFO, 0, r,
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe "Module bug? Request filename path %s is missing or "
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe "or not absolute for uri %s",
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe r->filename ? r->filename : "<NULL>", r->uri);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe return OK;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe /*
8aefbd756763807188d2e3ce336a8680e4893066wrowe * r->path_info tracks the remaining source path.
8aefbd756763807188d2e3ce336a8680e4893066wrowe * r->filename tracks the path as we build it.
8aefbd756763807188d2e3ce336a8680e4893066wrowe * we begin our adventure at the root...
8aefbd756763807188d2e3ce336a8680e4893066wrowe */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if ((rv = apr_filepath_merge(&entry_dir, NULL, r->filename,
8aefbd756763807188d2e3ce336a8680e4893066wrowe APR_FILEPATH_NOTRELATIVE, r->pool))
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe != APR_SUCCESS) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_INFO, 0, r,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe "Module bug? Request filename path %s is invalid or "
a8d11d78181478da6a672f7fbc58b8d523351f49wrowe "or not absolute for uri %s",
a8d11d78181478da6a672f7fbc58b8d523351f49wrowe r->filename, r->uri);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe return OK;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe r->filename = entry_dir;
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe /*
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe *
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * Go down the directory hierarchy. Where we have to check for symlinks,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * do so. Where a .htaccess file has permission to override anything,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * try to find one.
8aefbd756763807188d2e3ce336a8680e4893066wrowe */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe cache = prep_walk_cache("ap_directory_walk::cache", r);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (r->finfo.filetype == APR_REG)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe entry_dir = ap_make_dirstr_parent(r->pool, entry_dir);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe else if (r->filename[strlen(r->filename) - 1] != '/')
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe entry_dir = apr_pstrcat(r->pool, r->filename, "/", NULL);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* If we have a file already matches the path of r->filename,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * and the vhost's list of directory sections hasn't changed,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * we can skip rewalking the directory_walk entries.
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (cache->cached && ((r->finfo.filetype == APR_REG)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe || (r->finfo.filetype == APR_DIR))
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe && (cache->dir_conf_tested == sec_ent)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe && (strcmp(entry_dir, cache->cached) == 0)) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* Well this looks really familiar! If our end-result (per_dir_result)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * didn't change, we have absolutely nothing to do :)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * Otherwise (as is the case with most dir_merged/file_merged requests)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * we must merge our dir_conf_merged onto this new r->per_dir_config.
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe */
a9a4544168a37b43bd180b3703ccee995f27a80awrowe if (r->per_dir_config == cache->per_dir_result) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe return OK;
a9a4544168a37b43bd180b3703ccee995f27a80awrowe }
a9a4544168a37b43bd180b3703ccee995f27a80awrowe if (r->per_dir_config == cache->dir_conf_merged) {
a9a4544168a37b43bd180b3703ccee995f27a80awrowe r->per_dir_config = cache->per_dir_result;
a9a4544168a37b43bd180b3703ccee995f27a80awrowe return OK;
a9a4544168a37b43bd180b3703ccee995f27a80awrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (cache->walked->nelts)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe now_merged = ((walk_walked_t*)cache->walked->elts)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe [cache->walked->nelts - 1].merged;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe else {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* We start now_merged from NULL since we want to build
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * a locations list that can be merged to any vhost.
8aefbd756763807188d2e3ce336a8680e4893066wrowe */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe int sec_idx;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe int matches = cache->walked->nelts;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe walk_walked_t *last_walk = (walk_walked_t*)cache->walked->elts;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe core_dir_config *this_dir;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe allow_options_t opts;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe allow_options_t opts_add;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe allow_options_t opts_remove;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe overrides_t override;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe apr_size_t buflen;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe char *buf;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe unsigned int seg, startseg;
8aefbd756763807188d2e3ce336a8680e4893066wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /*
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * We must play our own mimi-merge game here, for the few
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * running dir_config values we care about within dir_walk.
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * We didn't start the merge from r->per_dir_config, so we
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * accumulate opts and override as we merge, from the globals.
8aefbd756763807188d2e3ce336a8680e4893066wrowe */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe this_dir = ap_get_module_config(r->per_dir_config, &core_module);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe opts = this_dir->opts;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe opts_add = this_dir->opts_add;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe opts_remove = this_dir->opts_remove;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe override = this_dir->override;
8aefbd756763807188d2e3ce336a8680e4893066wrowe
59513b1275fdc2021d4949ee03ae8229469abb86wrowe /* XXX: Remerge path_info, or we are broken. Needs more thought.
59513b1275fdc2021d4949ee03ae8229469abb86wrowe */
59513b1275fdc2021d4949ee03ae8229469abb86wrowe if (r->path_info)
59513b1275fdc2021d4949ee03ae8229469abb86wrowe r->path_info = ap_make_full_path(r->pool, r->filename,
59513b1275fdc2021d4949ee03ae8229469abb86wrowe r->path_info);
38bcc87d9a06e8ba81165421403f275eca4e313btrawick rv = apr_filepath_root((const char **)&r->filename,
38bcc87d9a06e8ba81165421403f275eca4e313btrawick (const char **)&r->path_info,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe APR_FILEPATH_TRUENAME, r->pool);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe buflen = strlen(r->filename) + strlen(r->path_info) + 1;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe buf = apr_palloc(r->pool, buflen);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe strcpy (buf, r->filename);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe r->filename = buf;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe r->finfo.valid = APR_FINFO_TYPE;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe r->finfo.filetype = APR_DIR; /* It's the root, of course it's a dir */
8aefbd756763807188d2e3ce336a8680e4893066wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /*
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * seg keeps track of which segment we've copied.
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * sec_idx keeps track of which section we're on, since sections are
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * ordered by number of segments. See core_reorder_directories
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe startseg = seg = ap_count_dirs(r->filename);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe sec_idx = 0;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe do {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe int res;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe char *seg_name;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe char *delim;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* We have no trailing slash, but we sure would appreciate one...
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (sec_idx && r->filename[strlen(r->filename)-1] != '/')
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe strcat(r->filename, "/");
8aefbd756763807188d2e3ce336a8680e4893066wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* Begin *this* level by looking for matching <Directory> sections
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * from the server config.
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe for (; sec_idx < num_sec; ++sec_idx) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_conf_vector_t *entry_config = sec_ent[sec_idx];
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe core_dir_config *entry_core;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe entry_core = ap_get_module_config(entry_config, &core_module);
8aefbd756763807188d2e3ce336a8680e4893066wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* No more possible matches for this many segments?
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * We are done when we find relative/regex/longer components.
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (entry_core->r || entry_core->d_components > seg)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe break;
8aefbd756763807188d2e3ce336a8680e4893066wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* We will never skip '0' element components, e.g. plain old
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * <Directory >, and <Directory "/"> are classified as zero
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * so that Win32/Netware/OS2 etc all pick them up.
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * Otherwise, skip over the mismatches.
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (entry_core->d_components
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe && (entry_core->d_is_fnmatch
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ? (apr_fnmatch(entry_core->d, r->filename, FNM_PATHNAME) != APR_SUCCESS)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe : (strcmp(r->filename, entry_core->d) != 0))) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe continue;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* If we merged this same section last time, reuse it
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (matches) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (last_walk->matched == sec_ent[sec_idx]) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe now_merged = last_walk->merged;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ++last_walk;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe --matches;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe goto minimerge;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* We fell out of sync. This is our own copy of walked,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * so truncate the remaining matches and reset remaining.
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe cache->walked->nelts -= matches;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe matches = 0;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (now_merged)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe now_merged = ap_merge_per_dir_configs(r->pool,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe now_merged,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe sec_ent[sec_idx]);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe else
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe now_merged = sec_ent[sec_idx];
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe last_walk = (walk_walked_t*)apr_array_push(cache->walked);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe last_walk->matched = sec_ent[sec_idx];
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe last_walk->merged = now_merged;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* Do a mini-merge to our globally-based running calculations of
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * core_dir->override and core_dir->opts, since now_merged
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * never considered the global config. Of course, if there is no
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * core config at this level, continue without a thought.
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * See core.c::merge_core_dir_configs() for explanation.
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe */
e4a3f3c2f080cac75a15a6454cca429b8161c050wroweminimerge:
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe this_dir = ap_get_module_config(sec_ent[sec_idx], &core_module);
8aefbd756763807188d2e3ce336a8680e4893066wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (!this_dir)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe continue;
8aefbd756763807188d2e3ce336a8680e4893066wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (this_dir->opts & OPT_UNSET) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe opts_add = (opts_add & ~this_dir->opts_remove) | this_dir->opts_add;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe opts_remove = (opts_remove & ~this_dir->opts_add)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe | this_dir->opts_remove;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe opts = (opts & ~opts_remove) | opts_add;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe else {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe opts = this_dir->opts;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe opts_add = this_dir->opts_add;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe opts_remove = this_dir->opts_remove;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (!(this_dir->override & OR_UNSET)) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe override = this_dir->override;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* If .htaccess files are enabled, check for one, provided we
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * have reached a real path.
8aefbd756763807188d2e3ce336a8680e4893066wrowe */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (seg >= startseg && override) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_conf_vector_t *htaccess_conf = NULL;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe res = ap_parse_htaccess(&htaccess_conf, r, override,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe apr_pstrdup(r->pool, r->filename),
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe sconf->access_name);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (res)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe return res;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (htaccess_conf) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* If we merged this same htaccess last time, reuse it...
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * this wouldn't work except that we cache the htaccess
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * sections for the lifetime of the request, so we match
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * the same conf. Good planning (no, pure luck ;)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (matches) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (last_walk->matched == htaccess_conf) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe now_merged = last_walk->merged;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ++last_walk;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe --matches;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe goto minimerge2;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* We fell out of sync. This is our own copy of walked,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * so truncate the remaining matches and reset remaining.
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe cache->walked->nelts -= matches;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe matches = 0;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (now_merged)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe now_merged = ap_merge_per_dir_configs(r->pool,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe now_merged,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe htaccess_conf);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe else
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe now_merged = htaccess_conf;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe last_walk = (walk_walked_t*)apr_array_push(cache->walked);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe last_walk->matched = htaccess_conf;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe last_walk->merged = now_merged;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* Do a mini-merge to our globally-based running calculations of
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * core_dir->override and core_dir->opts, since now_merged
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * never considered the global config. Of course, if there is no
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * core config at this level, continue without a thought.
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * See core.c::merge_core_dir_configs() for explanation.
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe */
e4a3f3c2f080cac75a15a6454cca429b8161c050wroweminimerge2:
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe this_dir = ap_get_module_config(htaccess_conf, &core_module);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
2787ef5edc27fa4f6777ba8d51aa48fd9fdf54bbwrowe if (this_dir)
2787ef5edc27fa4f6777ba8d51aa48fd9fdf54bbwrowe {
2787ef5edc27fa4f6777ba8d51aa48fd9fdf54bbwrowe if (this_dir->opts & OPT_UNSET) {
2787ef5edc27fa4f6777ba8d51aa48fd9fdf54bbwrowe opts_add = (opts_add & ~this_dir->opts_remove) | this_dir->opts_add;
2787ef5edc27fa4f6777ba8d51aa48fd9fdf54bbwrowe opts_remove = (opts_remove & ~this_dir->opts_add)
2787ef5edc27fa4f6777ba8d51aa48fd9fdf54bbwrowe | this_dir->opts_remove;
2787ef5edc27fa4f6777ba8d51aa48fd9fdf54bbwrowe opts = (opts & ~opts_remove) | opts_add;
2787ef5edc27fa4f6777ba8d51aa48fd9fdf54bbwrowe }
2787ef5edc27fa4f6777ba8d51aa48fd9fdf54bbwrowe else {
2787ef5edc27fa4f6777ba8d51aa48fd9fdf54bbwrowe opts = this_dir->opts;
2787ef5edc27fa4f6777ba8d51aa48fd9fdf54bbwrowe opts_add = this_dir->opts_add;
2787ef5edc27fa4f6777ba8d51aa48fd9fdf54bbwrowe opts_remove = this_dir->opts_remove;
2787ef5edc27fa4f6777ba8d51aa48fd9fdf54bbwrowe }
2787ef5edc27fa4f6777ba8d51aa48fd9fdf54bbwrowe if (!(this_dir->override & OR_UNSET)) {
2787ef5edc27fa4f6777ba8d51aa48fd9fdf54bbwrowe override = this_dir->override;
2787ef5edc27fa4f6777ba8d51aa48fd9fdf54bbwrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* That temporary trailing slash was useful, now drop it.
8aefbd756763807188d2e3ce336a8680e4893066wrowe */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (seg > startseg)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe r->filename[strlen(r->filename) - 1] = '\0';
8aefbd756763807188d2e3ce336a8680e4893066wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* Time for all good things to come to an end?
8aefbd756763807188d2e3ce336a8680e4893066wrowe */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (!r->path_info || !*r->path_info)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe break;
8aefbd756763807188d2e3ce336a8680e4893066wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* Now it's time for the next segment...
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * We will assume the next element is an end node, and fix it up
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * below as necessary...
8aefbd756763807188d2e3ce336a8680e4893066wrowe */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe seg_name = strchr(r->filename, '\0');
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe delim = strchr(r->path_info + (*r->path_info == '/' ? 1 : 0), '/');
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (delim) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe *delim = '\0';
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe strcpy(seg_name, r->path_info);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe r->path_info = delim;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe *delim = '/';
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe else {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe strcpy(seg_name, r->path_info);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe r->path_info = strchr(r->path_info, '\0');
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (*seg_name == '/')
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ++seg_name;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* If nothing remained but a '/' string, we are finished
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (!*seg_name)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe break;
8aefbd756763807188d2e3ce336a8680e4893066wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* XXX: Optimization required:
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * If...we have allowed symlinks, and
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * if...we find the segment exists in the directory list
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * skip the lstat and dummy up an APR_DIR value for r->finfo
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * this means case sensitive platforms go quite quickly.
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * Case insensitive platforms might be given the wrong path,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * but if it's not found in the cache, then we know we have
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * something to test (the misspelling is never cached.)
8aefbd756763807188d2e3ce336a8680e4893066wrowe */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* We choose apr_lstat here, rather that apr_stat, so that we
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * capture this path object rather than its target. We will
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * replace the info with our target's info below. We especially
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * want the name of this 'link' object, not the name of its
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * target, if we are fixing case.
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe rv = apr_lstat(&r->finfo, r->filename, APR_FINFO_MIN | APR_FINFO_NAME, r->pool);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (APR_STATUS_IS_ENOENT(rv)) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* Nothing? That could be nice. But our directory walk is done.
8aefbd756763807188d2e3ce336a8680e4893066wrowe */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe r->finfo.filetype = APR_NOFILE;
8aefbd756763807188d2e3ce336a8680e4893066wrowe break;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe else if (APR_STATUS_IS_EACCES(rv)) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe "access to %s denied", r->uri);
8aefbd756763807188d2e3ce336a8680e4893066wrowe return r->status = HTTP_FORBIDDEN;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe else if ((rv != APR_SUCCESS && rv != APR_INCOMPLETE)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe || !(r->finfo.valid & APR_FINFO_TYPE)) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* If we hit ENOTDIR, we must have over-optimized, deny
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * rather than assume not found.
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe "access to %s failed", r->uri);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe return r->status = HTTP_FORBIDDEN;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe else if ((res = check_safe_file(r))) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe r->status = res;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe return res;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* Fix up the path now if we have a name, and they don't agree
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if ((r->finfo.valid & APR_FINFO_NAME)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe && strcmp(seg_name, r->finfo.name)) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* TODO: provide users an option that an internal/external
cadddb2c31d24d48f4017db4df0a29687432326cwrowe * redirect is required here? We need to walk the URI and
cadddb2c31d24d48f4017db4df0a29687432326cwrowe * filename in tandem to properly correlate these.
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe strcpy(seg_name, r->finfo.name);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (r->finfo.filetype == APR_LNK)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* Is this an possibly acceptable symlink?
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if ((res = resolve_symlink(r->filename, &r->finfo,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe opts, r->pool)) != OK) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe "Symbolic link not allowed: %s", r->filename);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe return r->status = res;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* Ok, we are done with the link's info, test the real target
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (r->finfo.filetype == APR_REG) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* That was fun, nothing left for us here
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe break;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe else if (r->finfo.filetype != APR_DIR) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe "symlink doesn't point to a file or directory: %s",
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe r->filename);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe return r->status = HTTP_FORBIDDEN;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ++seg;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe } while (r->finfo.filetype == APR_DIR);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /*
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * Now we'll deal with the regexes, note we pick up sec_idx
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * where we left off (we gave up after we hit entry_core->r)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe for (; sec_idx < num_sec; ++sec_idx) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe core_dir_config *entry_core;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe entry_core = ap_get_module_config(sec_ent[sec_idx], &core_module);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (!entry_core->r)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe continue;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (ap_regexec(entry_core->r, r->filename, 0, NULL, REG_NOTEOL))
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe continue;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* If we merged this same section last time, reuse it
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (matches) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (last_walk->matched == sec_ent[sec_idx]) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe now_merged = last_walk->merged;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ++last_walk;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe --matches;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe goto minimerge;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* We fell out of sync. This is our own copy of walked,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * so truncate the remaining matches and reset remaining.
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe cache->walked->nelts -= matches;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe matches = 0;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (now_merged)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe now_merged = ap_merge_per_dir_configs(r->pool,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe now_merged,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe sec_ent[sec_idx]);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe else
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe now_merged = sec_ent[sec_idx];
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe last_walk = (walk_walked_t*)apr_array_push(cache->walked);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe last_walk->matched = sec_ent[sec_idx];
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe last_walk->merged = now_merged;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* Whoops - everything matched in sequence, but the original walk
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * found some additional matches. Truncate them.
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (matches)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe cache->walked->nelts -= matches;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe/* It seems this shouldn't be needed anymore. We translated the symlink above
8aefbd756763807188d2e3ce336a8680e4893066wrowe x into a real resource, and should have died up there. Even if we keep this,
8aefbd756763807188d2e3ce336a8680e4893066wrowe x it needs more thought (maybe an r->file_is_symlink) perhaps it should actually
8aefbd756763807188d2e3ce336a8680e4893066wrowe x happen in file_walk, so we catch more obscure cases in autoindex sub requests, etc.
8aefbd756763807188d2e3ce336a8680e4893066wrowe x
8aefbd756763807188d2e3ce336a8680e4893066wrowe x * Symlink permissions are determined by the parent. If the request is
8aefbd756763807188d2e3ce336a8680e4893066wrowe x * for a directory then applying the symlink test here would use the
8aefbd756763807188d2e3ce336a8680e4893066wrowe x * permissions of the directory as opposed to its parent. Consider a
8aefbd756763807188d2e3ce336a8680e4893066wrowe x * symlink pointing to a dir with a .htaccess disallowing symlinks. If
8aefbd756763807188d2e3ce336a8680e4893066wrowe x * you access /symlink (or /symlink/) you would get a 403 without this
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe x * APR_DIR test. But if you accessed /symlink/index.html, for example,
8aefbd756763807188d2e3ce336a8680e4893066wrowe x * you would *not* get the 403.
8aefbd756763807188d2e3ce336a8680e4893066wrowe x
8aefbd756763807188d2e3ce336a8680e4893066wrowe x if (r->finfo.filetype != APR_DIR
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe x && (res = resolve_symlink(r->filename, r->info, ap_allow_options(r), r->pool))) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe x ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
8aefbd756763807188d2e3ce336a8680e4893066wrowe x "Symbolic link not allowed: %s", r->filename);
8aefbd756763807188d2e3ce336a8680e4893066wrowe x return res;
8aefbd756763807188d2e3ce336a8680e4893066wrowe x }
8aefbd756763807188d2e3ce336a8680e4893066wrowe */
8aefbd756763807188d2e3ce336a8680e4893066wrowe
0540a0b469147b52e858587270dba31c2aaa9e09wrowe if (r->finfo.filetype == APR_DIR)
0540a0b469147b52e858587270dba31c2aaa9e09wrowe cache->cached = r->filename;
0540a0b469147b52e858587270dba31c2aaa9e09wrowe else
0540a0b469147b52e858587270dba31c2aaa9e09wrowe cache->cached = ap_make_dirstr_parent(r->pool, r->filename);
0540a0b469147b52e858587270dba31c2aaa9e09wrowe
0540a0b469147b52e858587270dba31c2aaa9e09wrowe cache->dir_conf_tested = sec_ent;
a9a4544168a37b43bd180b3703ccee995f27a80awrowe cache->dir_conf_merged = r->per_dir_config;
0540a0b469147b52e858587270dba31c2aaa9e09wrowe
0540a0b469147b52e858587270dba31c2aaa9e09wrowe /* Merge our cache->dir_conf_merged construct with the r->per_dir_configs,
0540a0b469147b52e858587270dba31c2aaa9e09wrowe * and note the end result to (potentially) skip this step next time.
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe */
0540a0b469147b52e858587270dba31c2aaa9e09wrowe if (now_merged)
0540a0b469147b52e858587270dba31c2aaa9e09wrowe r->per_dir_config = ap_merge_per_dir_configs(r->pool,
0540a0b469147b52e858587270dba31c2aaa9e09wrowe r->per_dir_config,
0540a0b469147b52e858587270dba31c2aaa9e09wrowe now_merged);
0540a0b469147b52e858587270dba31c2aaa9e09wrowe cache->per_dir_result = r->per_dir_config;
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe
0540a0b469147b52e858587270dba31c2aaa9e09wrowe return OK;
8aefbd756763807188d2e3ce336a8680e4893066wrowe}
8aefbd756763807188d2e3ce336a8680e4893066wrowe
0540a0b469147b52e858587270dba31c2aaa9e09wrowe
a2a0abd88b19e042a3eb2a9fa1702c25ad51303dwroweAP_DECLARE(int) ap_location_walk(request_rec *r)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
948096a99010fccf648814fecf38f75c689172d7wrowe ap_conf_vector_t *now_merged = NULL;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb core_server_config *sconf = ap_get_module_config(r->server->module_config,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb &core_module);
0540a0b469147b52e858587270dba31c2aaa9e09wrowe ap_conf_vector_t **sec_ent = (ap_conf_vector_t **) sconf->sec_url->elts;
0540a0b469147b52e858587270dba31c2aaa9e09wrowe int num_sec = sconf->sec_url->nelts;
948096a99010fccf648814fecf38f75c689172d7wrowe walk_cache_t *cache;
948096a99010fccf648814fecf38f75c689172d7wrowe const char *entry_uri;
948096a99010fccf648814fecf38f75c689172d7wrowe
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe cache = prep_walk_cache("ap_location_walk::cache", r);
3f5b4558f5410fdac5d6feed7aab0c3668f9cd13wrowe
948096a99010fccf648814fecf38f75c689172d7wrowe /* No tricks here, there are no <Locations > to parse in this vhost.
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe * We won't destroy the cache, just in case _this_ redirect is later
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe * redirected again to a vhost with <Location > blocks to optimize.
053497224246c4dbef9af594cacf5c00ed271e6cwrowe */
0540a0b469147b52e858587270dba31c2aaa9e09wrowe if (!num_sec) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return OK;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
948096a99010fccf648814fecf38f75c689172d7wrowe /* Location and LocationMatch differ on their behaviour w.r.t. multiple
948096a99010fccf648814fecf38f75c689172d7wrowe * slashes. Location matches multiple slashes with a single slash,
948096a99010fccf648814fecf38f75c689172d7wrowe * LocationMatch doesn't. An exception, for backwards brokenness is
948096a99010fccf648814fecf38f75c689172d7wrowe * absoluteURIs... in which case neither match multiple slashes.
948096a99010fccf648814fecf38f75c689172d7wrowe */
948096a99010fccf648814fecf38f75c689172d7wrowe if (r->uri[0] != '/') {
948096a99010fccf648814fecf38f75c689172d7wrowe entry_uri = r->uri;
948096a99010fccf648814fecf38f75c689172d7wrowe }
948096a99010fccf648814fecf38f75c689172d7wrowe else {
948096a99010fccf648814fecf38f75c689172d7wrowe char *uri = apr_pstrdup(r->pool, r->uri);
948096a99010fccf648814fecf38f75c689172d7wrowe ap_no2slash(uri);
948096a99010fccf648814fecf38f75c689172d7wrowe entry_uri = uri;
948096a99010fccf648814fecf38f75c689172d7wrowe }
053497224246c4dbef9af594cacf5c00ed271e6cwrowe
948096a99010fccf648814fecf38f75c689172d7wrowe /* If we have an cache->cached location that matches r->uri,
948096a99010fccf648814fecf38f75c689172d7wrowe * and the vhost's list of locations hasn't changed, we can skip
948096a99010fccf648814fecf38f75c689172d7wrowe * rewalking the location_walk entries.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
0540a0b469147b52e858587270dba31c2aaa9e09wrowe if (cache->cached && (cache->dir_conf_tested == sec_ent)
948096a99010fccf648814fecf38f75c689172d7wrowe && (strcmp(entry_uri, cache->cached) == 0)) {
948096a99010fccf648814fecf38f75c689172d7wrowe /* Well this looks really familiar! If our end-result (per_dir_result)
948096a99010fccf648814fecf38f75c689172d7wrowe * didn't change, we have absolutely nothing to do :)
948096a99010fccf648814fecf38f75c689172d7wrowe * Otherwise (as is the case with most dir_merged/file_merged requests)
948096a99010fccf648814fecf38f75c689172d7wrowe * we must merge our dir_conf_merged onto this new r->per_dir_config.
053497224246c4dbef9af594cacf5c00ed271e6cwrowe */
a9a4544168a37b43bd180b3703ccee995f27a80awrowe if (r->per_dir_config == cache->per_dir_result) {
948096a99010fccf648814fecf38f75c689172d7wrowe return OK;
a9a4544168a37b43bd180b3703ccee995f27a80awrowe }
a9a4544168a37b43bd180b3703ccee995f27a80awrowe if (r->per_dir_config == cache->dir_conf_merged) {
a9a4544168a37b43bd180b3703ccee995f27a80awrowe r->per_dir_config = cache->per_dir_result;
a9a4544168a37b43bd180b3703ccee995f27a80awrowe return OK;
a9a4544168a37b43bd180b3703ccee995f27a80awrowe }
948096a99010fccf648814fecf38f75c689172d7wrowe if (cache->walked->nelts)
948096a99010fccf648814fecf38f75c689172d7wrowe now_merged = ((walk_walked_t*)cache->walked->elts)
948096a99010fccf648814fecf38f75c689172d7wrowe [cache->walked->nelts - 1].merged;
948096a99010fccf648814fecf38f75c689172d7wrowe }
948096a99010fccf648814fecf38f75c689172d7wrowe else {
948096a99010fccf648814fecf38f75c689172d7wrowe /* We start now_merged from NULL since we want to build
948096a99010fccf648814fecf38f75c689172d7wrowe * a locations list that can be merged to any vhost.
948096a99010fccf648814fecf38f75c689172d7wrowe */
0540a0b469147b52e858587270dba31c2aaa9e09wrowe int len, sec_idx;
948096a99010fccf648814fecf38f75c689172d7wrowe int matches = cache->walked->nelts;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe walk_walked_t *last_walk = (walk_walked_t*)cache->walked->elts;
948096a99010fccf648814fecf38f75c689172d7wrowe cache->cached = entry_uri;
948096a99010fccf648814fecf38f75c689172d7wrowe
948096a99010fccf648814fecf38f75c689172d7wrowe /* Go through the location entries, and check for matches.
948096a99010fccf648814fecf38f75c689172d7wrowe * We apply the directive sections in given order, we should
948096a99010fccf648814fecf38f75c689172d7wrowe * really try them with the most general first.
053497224246c4dbef9af594cacf5c00ed271e6cwrowe */
0540a0b469147b52e858587270dba31c2aaa9e09wrowe for (sec_idx = 0; sec_idx < num_sec; ++sec_idx) {
053497224246c4dbef9af594cacf5c00ed271e6cwrowe
0540a0b469147b52e858587270dba31c2aaa9e09wrowe core_dir_config *entry_core;
0540a0b469147b52e858587270dba31c2aaa9e09wrowe entry_core = ap_get_module_config(sec_ent[sec_idx], &core_module);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe
aa047239dedf0d26e8efecfade32e7337f35df19wrowe /* ### const strlen can be optimized in location config parsing */
aa047239dedf0d26e8efecfade32e7337f35df19wrowe len = strlen(entry_core->d);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
053497224246c4dbef9af594cacf5c00ed271e6cwrowe /* Test the regex, fnmatch or string as appropriate.
053497224246c4dbef9af594cacf5c00ed271e6cwrowe * If it's a strcmp, and the <Location > pattern was
053497224246c4dbef9af594cacf5c00ed271e6cwrowe * not slash terminated, then this uri must be slash
053497224246c4dbef9af594cacf5c00ed271e6cwrowe * terminated (or at the end of the string) to match.
053497224246c4dbef9af594cacf5c00ed271e6cwrowe */
053497224246c4dbef9af594cacf5c00ed271e6cwrowe if (entry_core->r
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ? ap_regexec(entry_core->r, r->uri, 0, NULL, 0)
aa047239dedf0d26e8efecfade32e7337f35df19wrowe : (entry_core->d_is_fnmatch
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ? apr_fnmatch(entry_core->d, cache->cached, FNM_PATHNAME)
aa047239dedf0d26e8efecfade32e7337f35df19wrowe : (strncmp(entry_core->d, cache->cached, len)
aa047239dedf0d26e8efecfade32e7337f35df19wrowe || (entry_core->d[len - 1] != '/'
aa047239dedf0d26e8efecfade32e7337f35df19wrowe && cache->cached[len] != '/'
aa047239dedf0d26e8efecfade32e7337f35df19wrowe && cache->cached[len] != '\0')))) {
053497224246c4dbef9af594cacf5c00ed271e6cwrowe continue;
053497224246c4dbef9af594cacf5c00ed271e6cwrowe }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
948096a99010fccf648814fecf38f75c689172d7wrowe /* If we merged this same section last time, reuse it
948096a99010fccf648814fecf38f75c689172d7wrowe */
948096a99010fccf648814fecf38f75c689172d7wrowe if (matches) {
0540a0b469147b52e858587270dba31c2aaa9e09wrowe if (last_walk->matched == sec_ent[sec_idx]) {
948096a99010fccf648814fecf38f75c689172d7wrowe now_merged = last_walk->merged;
948096a99010fccf648814fecf38f75c689172d7wrowe ++last_walk;
948096a99010fccf648814fecf38f75c689172d7wrowe --matches;
948096a99010fccf648814fecf38f75c689172d7wrowe continue;
948096a99010fccf648814fecf38f75c689172d7wrowe }
948096a99010fccf648814fecf38f75c689172d7wrowe /* We fell out of sync. This is our own copy of walked,
948096a99010fccf648814fecf38f75c689172d7wrowe * so truncate the remaining matches and reset remaining.
948096a99010fccf648814fecf38f75c689172d7wrowe */
948096a99010fccf648814fecf38f75c689172d7wrowe cache->walked->nelts -= matches;
948096a99010fccf648814fecf38f75c689172d7wrowe matches = 0;
948096a99010fccf648814fecf38f75c689172d7wrowe }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
948096a99010fccf648814fecf38f75c689172d7wrowe if (now_merged)
948096a99010fccf648814fecf38f75c689172d7wrowe now_merged = ap_merge_per_dir_configs(r->pool,
948096a99010fccf648814fecf38f75c689172d7wrowe now_merged,
0540a0b469147b52e858587270dba31c2aaa9e09wrowe sec_ent[sec_idx]);
948096a99010fccf648814fecf38f75c689172d7wrowe else
0540a0b469147b52e858587270dba31c2aaa9e09wrowe now_merged = sec_ent[sec_idx];
696218c49632c863d18b25fa52ab63617088cb38wrowe
948096a99010fccf648814fecf38f75c689172d7wrowe last_walk = (walk_walked_t*)apr_array_push(cache->walked);
0540a0b469147b52e858587270dba31c2aaa9e09wrowe last_walk->matched = sec_ent[sec_idx];
948096a99010fccf648814fecf38f75c689172d7wrowe last_walk->merged = now_merged;
948096a99010fccf648814fecf38f75c689172d7wrowe }
948096a99010fccf648814fecf38f75c689172d7wrowe /* Whoops - everything matched in sequence, but the original walk
948096a99010fccf648814fecf38f75c689172d7wrowe * found some additional matches. Truncate them.
053497224246c4dbef9af594cacf5c00ed271e6cwrowe */
948096a99010fccf648814fecf38f75c689172d7wrowe if (matches)
948096a99010fccf648814fecf38f75c689172d7wrowe cache->walked->nelts -= matches;
053497224246c4dbef9af594cacf5c00ed271e6cwrowe }
053497224246c4dbef9af594cacf5c00ed271e6cwrowe
a9a4544168a37b43bd180b3703ccee995f27a80awrowe cache->dir_conf_tested = sec_ent;
a9a4544168a37b43bd180b3703ccee995f27a80awrowe cache->dir_conf_merged = r->per_dir_config;
a9a4544168a37b43bd180b3703ccee995f27a80awrowe
948096a99010fccf648814fecf38f75c689172d7wrowe /* Merge our cache->dir_conf_merged construct with the r->per_dir_configs,
948096a99010fccf648814fecf38f75c689172d7wrowe * and note the end result to (potentially) skip this step next time.
053497224246c4dbef9af594cacf5c00ed271e6cwrowe */
948096a99010fccf648814fecf38f75c689172d7wrowe if (now_merged)
053497224246c4dbef9af594cacf5c00ed271e6cwrowe r->per_dir_config = ap_merge_per_dir_configs(r->pool,
053497224246c4dbef9af594cacf5c00ed271e6cwrowe r->per_dir_config,
948096a99010fccf648814fecf38f75c689172d7wrowe now_merged);
948096a99010fccf648814fecf38f75c689172d7wrowe cache->per_dir_result = r->per_dir_config;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return OK;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
a2a0abd88b19e042a3eb2a9fa1702c25ad51303dwroweAP_DECLARE(int) ap_file_walk(request_rec *r)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ap_conf_vector_t *now_merged = NULL;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe core_dir_config *dconf = ap_get_module_config(r->per_dir_config,
aa047239dedf0d26e8efecfade32e7337f35df19wrowe &core_module);
0540a0b469147b52e858587270dba31c2aaa9e09wrowe ap_conf_vector_t **sec_ent = (ap_conf_vector_t **) dconf->sec_file->elts;
0540a0b469147b52e858587270dba31c2aaa9e09wrowe int num_sec = dconf->sec_file->nelts;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe walk_cache_t *cache;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe const char *test_file;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe /* To allow broken modules to proceed, we allow missing filenames to pass.
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe * We will catch it later if it's heading for the core handler.
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe * directory_walk already posted an INFO note for module debugging.
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe */
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe if (r->filename == NULL) {
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe return OK;
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe }
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe
aa047239dedf0d26e8efecfade32e7337f35df19wrowe cache = prep_walk_cache("ap_file_walk::cache", r);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe
aa047239dedf0d26e8efecfade32e7337f35df19wrowe /* No tricks here, there are just no <Files > to parse in this context.
aa047239dedf0d26e8efecfade32e7337f35df19wrowe * We won't destroy the cache, just in case _this_ redirect is later
aa047239dedf0d26e8efecfade32e7337f35df19wrowe * redirected again to a context containing the same or similar <Files >.
aa047239dedf0d26e8efecfade32e7337f35df19wrowe */
0540a0b469147b52e858587270dba31c2aaa9e09wrowe if (!num_sec) {
aa047239dedf0d26e8efecfade32e7337f35df19wrowe return OK;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe }
aa047239dedf0d26e8efecfade32e7337f35df19wrowe
aa047239dedf0d26e8efecfade32e7337f35df19wrowe /* Get the basename .. and copy for the cache just
aa047239dedf0d26e8efecfade32e7337f35df19wrowe * in case r->filename is munged by another module
aa047239dedf0d26e8efecfade32e7337f35df19wrowe */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb test_file = strrchr(r->filename, '/');
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (test_file == NULL) {
aa047239dedf0d26e8efecfade32e7337f35df19wrowe test_file = apr_pstrdup(r->pool, r->filename);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else {
aa047239dedf0d26e8efecfade32e7337f35df19wrowe test_file = apr_pstrdup(r->pool, ++test_file);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
aa047239dedf0d26e8efecfade32e7337f35df19wrowe /* If we have an cache->cached file name that matches test_file,
aa047239dedf0d26e8efecfade32e7337f35df19wrowe * and the directory's list of file sections hasn't changed, we
aa047239dedf0d26e8efecfade32e7337f35df19wrowe * can skip rewalking the file_walk entries.
aa047239dedf0d26e8efecfade32e7337f35df19wrowe */
0540a0b469147b52e858587270dba31c2aaa9e09wrowe if (cache->cached && (cache->dir_conf_tested == sec_ent)
aa047239dedf0d26e8efecfade32e7337f35df19wrowe && (strcmp(test_file, cache->cached) == 0)) {
aa047239dedf0d26e8efecfade32e7337f35df19wrowe /* Well this looks really familiar! If our end-result (per_dir_result)
aa047239dedf0d26e8efecfade32e7337f35df19wrowe * didn't change, we have absolutely nothing to do :)
aa047239dedf0d26e8efecfade32e7337f35df19wrowe * Otherwise (as is the case with most dir_merged requests)
aa047239dedf0d26e8efecfade32e7337f35df19wrowe * we must merge our dir_conf_merged onto this new r->per_dir_config.
aa047239dedf0d26e8efecfade32e7337f35df19wrowe */
a9a4544168a37b43bd180b3703ccee995f27a80awrowe if (r->per_dir_config == cache->per_dir_result) {
a9a4544168a37b43bd180b3703ccee995f27a80awrowe return OK;
a9a4544168a37b43bd180b3703ccee995f27a80awrowe }
a9a4544168a37b43bd180b3703ccee995f27a80awrowe if (r->per_dir_config == cache->dir_conf_merged) {
a9a4544168a37b43bd180b3703ccee995f27a80awrowe r->per_dir_config = cache->per_dir_result;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe return OK;
a9a4544168a37b43bd180b3703ccee995f27a80awrowe }
aa047239dedf0d26e8efecfade32e7337f35df19wrowe if (cache->walked->nelts)
aa047239dedf0d26e8efecfade32e7337f35df19wrowe now_merged = ((walk_walked_t*)cache->walked->elts)
aa047239dedf0d26e8efecfade32e7337f35df19wrowe [cache->walked->nelts - 1].merged;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe }
aa047239dedf0d26e8efecfade32e7337f35df19wrowe else {
aa047239dedf0d26e8efecfade32e7337f35df19wrowe /* We start now_merged from NULL since we want to build
aa047239dedf0d26e8efecfade32e7337f35df19wrowe * a file section list that can be merged to any dir_walk.
aa047239dedf0d26e8efecfade32e7337f35df19wrowe */
0540a0b469147b52e858587270dba31c2aaa9e09wrowe int sec_idx;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe int matches = cache->walked->nelts;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe walk_walked_t *last_walk = (walk_walked_t*)cache->walked->elts;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe cache->cached = test_file;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
aa047239dedf0d26e8efecfade32e7337f35df19wrowe /* Go through the location entries, and check for matches.
aa047239dedf0d26e8efecfade32e7337f35df19wrowe * We apply the directive sections in given order, we should
aa047239dedf0d26e8efecfade32e7337f35df19wrowe * really try them with the most general first.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
0540a0b469147b52e858587270dba31c2aaa9e09wrowe for (sec_idx = 0; sec_idx < num_sec; ++sec_idx) {
aa047239dedf0d26e8efecfade32e7337f35df19wrowe
0540a0b469147b52e858587270dba31c2aaa9e09wrowe core_dir_config *entry_core;
0540a0b469147b52e858587270dba31c2aaa9e09wrowe entry_core = ap_get_module_config(sec_ent[sec_idx], &core_module);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe
aa047239dedf0d26e8efecfade32e7337f35df19wrowe if (entry_core->r
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ? ap_regexec(entry_core->r, cache->cached , 0, NULL, 0)
aa047239dedf0d26e8efecfade32e7337f35df19wrowe : (entry_core->d_is_fnmatch
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ? apr_fnmatch(entry_core->d, cache->cached, FNM_PATHNAME)
aa047239dedf0d26e8efecfade32e7337f35df19wrowe : strcmp(entry_core->d, cache->cached))) {
aa047239dedf0d26e8efecfade32e7337f35df19wrowe continue;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
aa047239dedf0d26e8efecfade32e7337f35df19wrowe
aa047239dedf0d26e8efecfade32e7337f35df19wrowe /* If we merged this same section last time, reuse it
aa047239dedf0d26e8efecfade32e7337f35df19wrowe */
aa047239dedf0d26e8efecfade32e7337f35df19wrowe if (matches) {
0540a0b469147b52e858587270dba31c2aaa9e09wrowe if (last_walk->matched == sec_ent[sec_idx]) {
aa047239dedf0d26e8efecfade32e7337f35df19wrowe now_merged = last_walk->merged;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ++last_walk;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe --matches;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe continue;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
aa047239dedf0d26e8efecfade32e7337f35df19wrowe /* We fell out of sync. This is our own copy of walked,
aa047239dedf0d26e8efecfade32e7337f35df19wrowe * so truncate the remaining matches and reset remaining.
aa047239dedf0d26e8efecfade32e7337f35df19wrowe */
aa047239dedf0d26e8efecfade32e7337f35df19wrowe cache->walked->nelts -= matches;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe matches = 0;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
aa047239dedf0d26e8efecfade32e7337f35df19wrowe if (now_merged)
aa047239dedf0d26e8efecfade32e7337f35df19wrowe now_merged = ap_merge_per_dir_configs(r->pool,
aa047239dedf0d26e8efecfade32e7337f35df19wrowe now_merged,
0540a0b469147b52e858587270dba31c2aaa9e09wrowe sec_ent[sec_idx]);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe else
0540a0b469147b52e858587270dba31c2aaa9e09wrowe now_merged = sec_ent[sec_idx];
aa047239dedf0d26e8efecfade32e7337f35df19wrowe
aa047239dedf0d26e8efecfade32e7337f35df19wrowe last_walk = (walk_walked_t*)apr_array_push(cache->walked);
0540a0b469147b52e858587270dba31c2aaa9e09wrowe last_walk->matched = sec_ent[sec_idx];
aa047239dedf0d26e8efecfade32e7337f35df19wrowe last_walk->merged = now_merged;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
aa047239dedf0d26e8efecfade32e7337f35df19wrowe /* Whoops - everything matched in sequence, but the original walk
aa047239dedf0d26e8efecfade32e7337f35df19wrowe * found some additional matches. Truncate them.
aa047239dedf0d26e8efecfade32e7337f35df19wrowe */
aa047239dedf0d26e8efecfade32e7337f35df19wrowe if (matches)
aa047239dedf0d26e8efecfade32e7337f35df19wrowe cache->walked->nelts -= matches;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe
a9a4544168a37b43bd180b3703ccee995f27a80awrowe cache->dir_conf_tested = sec_ent;
a9a4544168a37b43bd180b3703ccee995f27a80awrowe cache->dir_conf_merged = r->per_dir_config;
a9a4544168a37b43bd180b3703ccee995f27a80awrowe
aa047239dedf0d26e8efecfade32e7337f35df19wrowe /* Merge our cache->dir_conf_merged construct with the r->per_dir_configs,
aa047239dedf0d26e8efecfade32e7337f35df19wrowe * and note the end result to (potentially) skip this step next time.
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe */
aa047239dedf0d26e8efecfade32e7337f35df19wrowe if (now_merged)
aa047239dedf0d26e8efecfade32e7337f35df19wrowe r->per_dir_config = ap_merge_per_dir_configs(r->pool,
aa047239dedf0d26e8efecfade32e7337f35df19wrowe r->per_dir_config,
aa047239dedf0d26e8efecfade32e7337f35df19wrowe now_merged);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe cache->per_dir_result = r->per_dir_config;
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return OK;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb/*****************************************************************
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * The sub_request mechanism.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Fns to look up a relative URI from, e.g., a map file or SSI document.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * These do all access checks, etc., but don't actually run the transaction
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * ... use run_sub_req below for that. Also, be sure to use destroy_sub_req
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * as appropriate if you're likely to be creating more than a few of these.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * (An early Apache version didn't destroy the sub_reqs used in directory
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * indexing. The result, when indexing a directory with 800-odd files in
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * it, was massively excessive storage allocation).
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Note more manipulation of protocol-specific vars in the request
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * structure...
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic request_rec *make_sub_request(const request_rec *r)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb apr_pool_t *rrp;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb request_rec *rr;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb apr_pool_create(&rrp, r->pool);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb rr = apr_pcalloc(rrp, sizeof(request_rec));
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb rr->pool = rrp;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return rr;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowestatic void fill_in_sub_req_vars(request_rec *rnew, const request_rec *r,
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe ap_filter_t *next_filter)
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe{
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe rnew->hostname = r->hostname;
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe rnew->request_time = r->request_time;
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe rnew->connection = r->connection;
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe rnew->server = r->server;
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe rnew->request_config = ap_create_request_config(rnew->pool);
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe /* Start a clean config from this subrequest's vhost. Optimization in
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe * Location/File/Dir walks from the parent request assure that if the
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe * config blocks of the subrequest match the parent request, no merges
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe * will actually occur (and generally a minimal number of merges are
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe * required, even if the parent and subrequest aren't quite identical.)
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe */
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe rnew->per_dir_config = r->server->lookup_defaults;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe rnew->htaccess = r->htaccess;
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe rnew->allowed_methods = ap_make_method_list(rnew->pool, 2);
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe /* make a copy of the allowed-methods list */
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe ap_copy_method_list(rnew->allowed_methods, r->allowed_methods);
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe /* start with the same set of output filters */
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe if (next_filter) {
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe rnew->output_filters = next_filter;
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe }
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe else {
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe rnew->output_filters = r->output_filters;
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe }
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe ap_add_output_filter("SUBREQ_CORE", NULL, rnew, rnew->connection);
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe /* no input filters for a subrequest */
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe ap_set_sub_req_protocol(rnew, r);
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe}
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbAP_CORE_DECLARE_NONSTD(apr_status_t) ap_sub_req_output_filter(ap_filter_t *f,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb apr_bucket_brigade *bb)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb apr_bucket *e = APR_BRIGADE_LAST(bb);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (APR_BUCKET_IS_EOS(e)) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb apr_bucket_delete(e);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
68b29bcadd6c46aecdc9fe14c93555a2238ad2aagregames if (!APR_BRIGADE_EMPTY(bb)) {
68b29bcadd6c46aecdc9fe14c93555a2238ad2aagregames return ap_pass_brigade(f->next, bb);
68b29bcadd6c46aecdc9fe14c93555a2238ad2aagregames }
68b29bcadd6c46aecdc9fe14c93555a2238ad2aagregames else {
68b29bcadd6c46aecdc9fe14c93555a2238ad2aagregames return APR_SUCCESS;
68b29bcadd6c46aecdc9fe14c93555a2238ad2aagregames }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbAP_DECLARE(int) ap_some_auth_required(request_rec *r)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Is there a require line configured for the type of *this* req? */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb const apr_array_header_t *reqs_arr = ap_requires(r);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb require_line *reqs;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb int i;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (!reqs_arr)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return 0;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb reqs = (require_line *) reqs_arr->elts;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb for (i = 0; i < reqs_arr->nelts; ++i)
48d2edbfb84e5559b5da0f8d614ccab805cc67a8rbb if (reqs[i].method_mask & (AP_METHOD_BIT << r->method_number))
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return 1;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return 0;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wroweAP_DECLARE(request_rec *) ap_sub_req_method_uri(const char *method,
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe const char *new_file,
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe const request_rec *r,
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe ap_filter_t *next_filter)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe request_rec *rnew;
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe int res;
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe char *udir;
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe rnew = make_sub_request(r);
1b839c67d5c0e4b1f22b44a4217f9860b420d47cwrowe fill_in_sub_req_vars(rnew, r, next_filter);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
1ab995011876f631740d68d960a6d729ddff5bfawrowe /* We have to run this after fill_in_sub_req_vars, or the r->main
b45c1c292ff1fa635004ae81fa691f8cb3cdda85rbb * pointer won't be setup
b45c1c292ff1fa635004ae81fa691f8cb3cdda85rbb */
b45c1c292ff1fa635004ae81fa691f8cb3cdda85rbb ap_run_create_request(rnew);
b45c1c292ff1fa635004ae81fa691f8cb3cdda85rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* would be nicer to pass "method" to ap_set_sub_req_protocol */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb rnew->method = method;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb rnew->method_number = ap_method_number_of(method);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (new_file[0] == '/')
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_parse_uri(rnew, new_file);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb udir = ap_make_dirstr_parent(rnew->pool, r->uri);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb udir = ap_escape_uri(rnew->pool, udir); /* re-escape it */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_parse_uri(rnew, ap_make_full_path(rnew->pool, udir, new_file));
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if ((res = ap_process_request_internal(rnew))) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb rnew->status = res;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return rnew;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbAP_DECLARE(request_rec *) ap_sub_req_lookup_uri(const char *new_file,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb const request_rec *r,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_filter_t *next_filter)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return ap_sub_req_method_uri("GET", new_file, r, next_filter);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
efa1a34b0a7785fc72863eff175b0cfc1ecb0e38wroweAP_DECLARE(request_rec *) ap_sub_req_lookup_dirent(const apr_finfo_t *dirent,
117026201e6d8fe7d82416b8a7324830f5a87292wrowe const request_rec *r,
117026201e6d8fe7d82416b8a7324830f5a87292wrowe ap_filter_t *next_filter)
117026201e6d8fe7d82416b8a7324830f5a87292wrowe{
117026201e6d8fe7d82416b8a7324830f5a87292wrowe request_rec *rnew;
117026201e6d8fe7d82416b8a7324830f5a87292wrowe int res;
117026201e6d8fe7d82416b8a7324830f5a87292wrowe char *fdir;
6c24fd6cfe148639988d5b335185ffb215662801wrowe char *udir;
117026201e6d8fe7d82416b8a7324830f5a87292wrowe
117026201e6d8fe7d82416b8a7324830f5a87292wrowe rnew = make_sub_request(r);
117026201e6d8fe7d82416b8a7324830f5a87292wrowe fill_in_sub_req_vars(rnew, r, next_filter);
117026201e6d8fe7d82416b8a7324830f5a87292wrowe
1ab995011876f631740d68d960a6d729ddff5bfawrowe /* We have to run this after fill_in_sub_req_vars, or the r->main
117026201e6d8fe7d82416b8a7324830f5a87292wrowe * pointer won't be setup
117026201e6d8fe7d82416b8a7324830f5a87292wrowe */
117026201e6d8fe7d82416b8a7324830f5a87292wrowe ap_run_create_request(rnew);
117026201e6d8fe7d82416b8a7324830f5a87292wrowe
cadddb2c31d24d48f4017db4df0a29687432326cwrowe /* Special case: we are looking at a relative lookup in the same directory.
cadddb2c31d24d48f4017db4df0a29687432326cwrowe * This is 100% safe, since dirent->name just came from the filesystem.
117026201e6d8fe7d82416b8a7324830f5a87292wrowe */
6c24fd6cfe148639988d5b335185ffb215662801wrowe udir = ap_make_dirstr_parent(rnew->pool, r->uri);
6c24fd6cfe148639988d5b335185ffb215662801wrowe rnew->uri = ap_make_full_path(rnew->pool, udir, dirent->name);
cadddb2c31d24d48f4017db4df0a29687432326cwrowe fdir = ap_make_dirstr_parent(rnew->pool, r->filename);
117026201e6d8fe7d82416b8a7324830f5a87292wrowe rnew->filename = ap_make_full_path(rnew->pool, fdir, dirent->name);
e7505ba54ac56ae30e4e250f912f3dbaf92ca45fwrowe if (r->canonical_filename == r->filename)
e7505ba54ac56ae30e4e250f912f3dbaf92ca45fwrowe rnew->canonical_filename = rnew->filename;
e7505ba54ac56ae30e4e250f912f3dbaf92ca45fwrowe
cadddb2c31d24d48f4017db4df0a29687432326cwrowe /* XXX This is now less relevant; we will do a full location walk
cadddb2c31d24d48f4017db4df0a29687432326cwrowe * these days for this case. Preserve the apr_stat results, and
cadddb2c31d24d48f4017db4df0a29687432326cwrowe * perhaps we also tag that symlinks were tested and/or found for
cadddb2c31d24d48f4017db4df0a29687432326cwrowe * r->filename.
5b3abd2fecc712f08ad728114aa77137b9f67716wrowe */
cadddb2c31d24d48f4017db4df0a29687432326cwrowe rnew->per_dir_config = r->per_dir_default;
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe
efa1a34b0a7785fc72863eff175b0cfc1ecb0e38wrowe if ((dirent->valid & APR_FINFO_MIN) != APR_FINFO_MIN) {
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe /*
beda1fb2f11c52ca4612460a5d5ba47398143efbwrowe * apr_dir_read isn't very complete on this platform, so
beda1fb2f11c52ca4612460a5d5ba47398143efbwrowe * we need another apr_lstat (or simply apr_stat if we allow
beda1fb2f11c52ca4612460a5d5ba47398143efbwrowe * all symlinks here.) If this is an APR_LNK that resolves
beda1fb2f11c52ca4612460a5d5ba47398143efbwrowe * to an APR_DIR, then we will rerun everything anyways...
beda1fb2f11c52ca4612460a5d5ba47398143efbwrowe * this should be safe.
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe */
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe apr_status_t rv;
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe if (ap_allow_options(rnew) & OPT_SYM_LINKS) {
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe if (((rv = apr_stat(&rnew->finfo, rnew->filename,
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe APR_FINFO_MIN, rnew->pool)) != APR_SUCCESS)
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe && (rv != APR_INCOMPLETE))
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe rnew->finfo.filetype = 0;
117026201e6d8fe7d82416b8a7324830f5a87292wrowe }
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe else
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe if (((rv = apr_lstat(&rnew->finfo, rnew->filename,
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe APR_FINFO_MIN, rnew->pool)) != APR_SUCCESS)
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe && (rv != APR_INCOMPLETE))
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe rnew->finfo.filetype = 0;
117026201e6d8fe7d82416b8a7324830f5a87292wrowe }
117026201e6d8fe7d82416b8a7324830f5a87292wrowe else {
efa1a34b0a7785fc72863eff175b0cfc1ecb0e38wrowe memcpy (&rnew->finfo, dirent, sizeof(apr_finfo_t));
117026201e6d8fe7d82416b8a7324830f5a87292wrowe }
1067418d9ed9ed9daeb3ca4f74e72db810c49833wrowe
cadddb2c31d24d48f4017db4df0a29687432326cwrowe if (rnew->finfo.filetype == APR_LNK) {
cadddb2c31d24d48f4017db4df0a29687432326cwrowe /*
cadddb2c31d24d48f4017db4df0a29687432326cwrowe * Resolve this symlink. We should tie this back to dir_walk's cache
cadddb2c31d24d48f4017db4df0a29687432326cwrowe */
cadddb2c31d24d48f4017db4df0a29687432326cwrowe if (!(res = resolve_symlink(rnew->filename, &rnew->finfo,
cadddb2c31d24d48f4017db4df0a29687432326cwrowe ap_allow_options(rnew), rnew->pool)) {
cadddb2c31d24d48f4017db4df0a29687432326cwrowe rnew->status = res;
cadddb2c31d24d48f4017db4df0a29687432326cwrowe return rnew;
cadddb2c31d24d48f4017db4df0a29687432326cwrowe }
cadddb2c31d24d48f4017db4df0a29687432326cwrowe }
cadddb2c31d24d48f4017db4df0a29687432326cwrowe
cadddb2c31d24d48f4017db4df0a29687432326cwrowe if (rnew->finfo.filetype == APR_DIR) {
cadddb2c31d24d48f4017db4df0a29687432326cwrowe /* ### Would be real nice if apr_make_full_path overallocated
cadddb2c31d24d48f4017db4df0a29687432326cwrowe * the buffer by one character instead of a complete copy.
cadddb2c31d24d48f4017db4df0a29687432326cwrowe */
cadddb2c31d24d48f4017db4df0a29687432326cwrowe rnew->filename = apr_pstrcat(rnew->pool, rnew->filename, "/", NULL);
cadddb2c31d24d48f4017db4df0a29687432326cwrowe rnew->uri = ap_make_full_path(rnew->pool, rnew->uri, "/", NULL);
cadddb2c31d24d48f4017db4df0a29687432326cwrowe if (r->canonical_filename == r->filename)
cadddb2c31d24d48f4017db4df0a29687432326cwrowe r->canonical_filename = r->filename;
cadddb2c31d24d48f4017db4df0a29687432326cwrowe }
cadddb2c31d24d48f4017db4df0a29687432326cwrowe
cadddb2c31d24d48f4017db4df0a29687432326cwrowe ap_parse_uri(rnew, rnew->uri); /* fill in parsed_uri values */
cadddb2c31d24d48f4017db4df0a29687432326cwrowe
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if ((res = ap_process_request_internal(rnew))) {
1067418d9ed9ed9daeb3ca4f74e72db810c49833wrowe rnew->status = res;
1067418d9ed9ed9daeb3ca4f74e72db810c49833wrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
1067418d9ed9ed9daeb3ca4f74e72db810c49833wrowe return rnew;
117026201e6d8fe7d82416b8a7324830f5a87292wrowe}
117026201e6d8fe7d82416b8a7324830f5a87292wrowe
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wroweAP_DECLARE(request_rec *) ap_sub_req_lookup_file(const char *new_file,
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe const request_rec *r,
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe ap_filter_t *next_filter)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb request_rec *rnew;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb int res;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb char *fdir;
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe apr_size_t fdirlen;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb rnew = make_sub_request(r);
1b839c67d5c0e4b1f22b44a4217f9860b420d47cwrowe fill_in_sub_req_vars(rnew, r, next_filter);
b45c1c292ff1fa635004ae81fa691f8cb3cdda85rbb
1ab995011876f631740d68d960a6d729ddff5bfawrowe /* We have to run this after fill_in_sub_req_vars, or the r->main
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe * pointer won't be setup
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe */
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe ap_run_create_request(rnew);
b45c1c292ff1fa635004ae81fa691f8cb3cdda85rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb fdir = ap_make_dirstr_parent(rnew->pool, r->filename);
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe fdirlen = strlen(fdir);
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe
ecc4a080f07af3fbc1b91bbd00997ec1d592c6f9wrowe /* Translate r->filename, if it was canonical, it stays canonical
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe */
2d2dadb81bf34e3bc9321eabcd971a738431b364wrowe if (r->canonical_filename == r->filename)
2d2dadb81bf34e3bc9321eabcd971a738431b364wrowe rnew->canonical_filename = (char*)(1);
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe if (apr_filepath_merge(&rnew->filename, fdir, new_file,
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe APR_FILEPATH_TRUENAME, rnew->pool) != APR_SUCCESS) {
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe rnew->status = HTTP_FORBIDDEN;
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe return rnew;
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe }
2d2dadb81bf34e3bc9321eabcd971a738431b364wrowe if (rnew->canonical_filename)
ecc4a080f07af3fbc1b91bbd00997ec1d592c6f9wrowe rnew->canonical_filename = rnew->filename;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /*
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Check for a special case... if there are no '/' characters in new_file
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe * at all, and the path was the same, then we are looking at a relative
5b3abd2fecc712f08ad728114aa77137b9f67716wrowe * lookup in the same directory. Fixup the URI to match.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
af7e32b660b02a378e91d40987e59b28864db954jwoolley if (strncmp(rnew->filename, fdir, fdirlen) == 0
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe && rnew->filename[fdirlen]
0540a0b469147b52e858587270dba31c2aaa9e09wrowe && ap_strchr_c(rnew->filename + fdirlen, '/') == NULL)
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe {
0540a0b469147b52e858587270dba31c2aaa9e09wrowe apr_status_t rv;
0540a0b469147b52e858587270dba31c2aaa9e09wrowe if (ap_allow_options(rnew) & OPT_SYM_LINKS) {
0540a0b469147b52e858587270dba31c2aaa9e09wrowe if (((rv = apr_stat(&rnew->finfo, rnew->filename,
0540a0b469147b52e858587270dba31c2aaa9e09wrowe APR_FINFO_MIN, rnew->pool)) != APR_SUCCESS)
0540a0b469147b52e858587270dba31c2aaa9e09wrowe && (rv != APR_INCOMPLETE))
0540a0b469147b52e858587270dba31c2aaa9e09wrowe rnew->finfo.filetype = 0;
0540a0b469147b52e858587270dba31c2aaa9e09wrowe }
0540a0b469147b52e858587270dba31c2aaa9e09wrowe else {
0540a0b469147b52e858587270dba31c2aaa9e09wrowe if (((rv = apr_lstat(&rnew->finfo, rnew->filename,
0540a0b469147b52e858587270dba31c2aaa9e09wrowe APR_FINFO_MIN, rnew->pool)) != APR_SUCCESS)
0540a0b469147b52e858587270dba31c2aaa9e09wrowe && (rv != APR_INCOMPLETE))
0540a0b469147b52e858587270dba31c2aaa9e09wrowe rnew->finfo.filetype = 0;
0540a0b469147b52e858587270dba31c2aaa9e09wrowe }
7763a4beb8afca9c8f93db0cb6836124901af52awrowe
0540a0b469147b52e858587270dba31c2aaa9e09wrowe if (r->uri && *r->uri) {
0540a0b469147b52e858587270dba31c2aaa9e09wrowe char *udir = ap_make_dirstr_parent(rnew->pool, r->uri);
0540a0b469147b52e858587270dba31c2aaa9e09wrowe rnew->uri = ap_make_full_path(rnew->pool, udir, rnew->filename + fdirlen);
0540a0b469147b52e858587270dba31c2aaa9e09wrowe ap_parse_uri(rnew, rnew->uri); /* fill in parsed_uri values */
0540a0b469147b52e858587270dba31c2aaa9e09wrowe }
0540a0b469147b52e858587270dba31c2aaa9e09wrowe else {
0540a0b469147b52e858587270dba31c2aaa9e09wrowe ap_parse_uri(rnew, new_file); /* fill in parsed_uri values */
0540a0b469147b52e858587270dba31c2aaa9e09wrowe rnew->uri = apr_pstrdup(rnew->pool, "");
0540a0b469147b52e858587270dba31c2aaa9e09wrowe }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else {
5b3abd2fecc712f08ad728114aa77137b9f67716wrowe /* XXX: @@@: What should be done with the parsed_uri values?
5b3abd2fecc712f08ad728114aa77137b9f67716wrowe * We would be better off stripping down to the 'common' elements
5b3abd2fecc712f08ad728114aa77137b9f67716wrowe * of the path, then reassembling the URI as best as we can.
5b3abd2fecc712f08ad728114aa77137b9f67716wrowe */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_parse_uri(rnew, new_file); /* fill in parsed_uri values */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /*
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * XXX: this should be set properly like it is in the same-dir case
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * but it's actually sometimes to impossible to do it... because the
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * file may not have a uri associated with it -djg
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
58097d7d8d1a394092374b9f6ddf76b7993724a4rbb rnew->uri = apr_pstrdup(rnew->pool, "");
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if ((res = ap_process_request_internal(rnew))) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb rnew->status = res;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return rnew;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbAP_DECLARE(int) ap_run_sub_req(request_rec *r)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb int retval;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb retval = ap_invoke_handler(r);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_finalize_sub_req_protocol(r);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return retval;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbAP_DECLARE(void) ap_destroy_sub_req(request_rec *r)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Reclaim the space */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb apr_pool_destroy(r->pool);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb/*
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Function to set the r->mtime field to the specified value if it's later
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * than what's already there.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbAP_DECLARE(void) ap_update_mtime(request_rec *r, apr_time_t dependency_mtime)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (r->mtime < dependency_mtime) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb r->mtime = dependency_mtime;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb/*
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Is it the initial main request, which we only get *once* per HTTP request?
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbAP_DECLARE(int) ap_is_initial_req(request_rec *r)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb (r->main == NULL) /* otherwise, this is a sub-request */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb &&
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb (r->prev == NULL); /* otherwise, this is an internal redirect */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb