request.c revision c6ed63d53853f79bf8265c434d2e25c9db8a7fd8
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein/* ====================================================================
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * The Apache Software License, Version 1.1
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein *
b99dbaab171d91e1b664397cc40e039d0c087c65fielding * Copyright (c) 2000-2001 The Apache Software Foundation. All rights
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * reserved.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein *
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * Redistribution and use in source and binary forms, with or without
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * modification, are permitted provided that the following conditions
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * are met:
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein *
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * 1. Redistributions of source code must retain the above copyright
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * notice, this list of conditions and the following disclaimer.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein *
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * 2. Redistributions in binary form must reproduce the above copyright
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * notice, this list of conditions and the following disclaimer in
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * the documentation and/or other materials provided with the
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * distribution.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein *
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * 3. The end-user documentation included with the redistribution,
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * if any, must include the following acknowledgment:
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * "This product includes software developed by the
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * Apache Software Foundation (http://www.apache.org/)."
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * Alternately, this acknowledgment may appear in the software itself,
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * if and wherever such third-party acknowledgments normally appear.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein *
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * 4. The names "Apache" and "Apache Software Foundation" must
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * not be used to endorse or promote products derived from this
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * software without prior written permission. For written
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * permission, please contact apache@apache.org.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein *
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * 5. Products derived from this software may not be called "Apache",
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * nor may "Apache" appear in their name, without prior written
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * permission of the Apache Software Foundation.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein *
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * SUCH DAMAGE.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * ====================================================================
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein *
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * This software consists of voluntary contributions made by many
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * individuals on behalf of the Apache Software Foundation. For more
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * information on the Apache Software Foundation, please see
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * <http://www.apache.org/>.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein *
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Portions of this software are based upon public domain software
f4c310fd2555c6faca1f980f00b161eadb089023gstein * originally written at the National Center for Supercomputing Applications,
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * University of Illinois, Urbana-Champaign.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein/*
1b21d7b3d97def358b2e923655edeb16613a1c31gstein * http_request.c: functions to get and process requests
952023a04a2f9d51553babd9094fb857f1c97548trawick *
1b21d7b3d97def358b2e923655edeb16613a1c31gstein * Rob McCool 3/21/93
1b21d7b3d97def358b2e923655edeb16613a1c31gstein *
1b21d7b3d97def358b2e923655edeb16613a1c31gstein * Thoroughly revamped by rst for Apache. NB this file reads
1b21d7b3d97def358b2e923655edeb16613a1c31gstein * best from the bottom up.
f4c310fd2555c6faca1f980f00b161eadb089023gstein *
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "apr_strings.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "apr_file_io.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "apr_fnmatch.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein#define APR_WANT_STRFUNC
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe#include "apr_want.h"
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe
f4c310fd2555c6faca1f980f00b161eadb089023gstein#define CORE_PRIVATE
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "ap_config.h"
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm#include "httpd.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "http_config.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "http_request.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "http_core.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "http_protocol.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "http_log.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "http_main.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "util_filter.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "util_charset.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "mod_core.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe#if APR_HAVE_STDARG_H
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe#include <stdarg.h>
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein
1ccd992d37d62c8cb2056126f2234f64ec189bfddougmAPR_HOOK_STRUCT(
f4c310fd2555c6faca1f980f00b161eadb089023gstein APR_HOOK_LINK(translate_name)
f4c310fd2555c6faca1f980f00b161eadb089023gstein APR_HOOK_LINK(map_to_storage)
f4c310fd2555c6faca1f980f00b161eadb089023gstein APR_HOOK_LINK(check_user_id)
f4c310fd2555c6faca1f980f00b161eadb089023gstein APR_HOOK_LINK(fixups)
f4c310fd2555c6faca1f980f00b161eadb089023gstein APR_HOOK_LINK(type_checker)
f4c310fd2555c6faca1f980f00b161eadb089023gstein APR_HOOK_LINK(access_checker)
f4c310fd2555c6faca1f980f00b161eadb089023gstein APR_HOOK_LINK(auth_checker)
f4c310fd2555c6faca1f980f00b161eadb089023gstein APR_HOOK_LINK(insert_filter)
f4c310fd2555c6faca1f980f00b161eadb089023gstein APR_HOOK_LINK(create_request)
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe)
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_IMPLEMENT_HOOK_RUN_FIRST(int,translate_name,
f4c310fd2555c6faca1f980f00b161eadb089023gstein (request_rec *r),(r),DECLINED)
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_IMPLEMENT_HOOK_RUN_FIRST(int,map_to_storage,
f4c310fd2555c6faca1f980f00b161eadb089023gstein (request_rec *r),(r),DECLINED)
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_IMPLEMENT_HOOK_RUN_FIRST(int,check_user_id,
f4c310fd2555c6faca1f980f00b161eadb089023gstein (request_rec *r),(r),DECLINED)
1ccd992d37d62c8cb2056126f2234f64ec189bfddougmAP_IMPLEMENT_HOOK_RUN_ALL(int,fixups,
f4c310fd2555c6faca1f980f00b161eadb089023gstein (request_rec *r),(r),OK,DECLINED)
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_IMPLEMENT_HOOK_RUN_FIRST(int,type_checker,
f4c310fd2555c6faca1f980f00b161eadb089023gstein (request_rec *r),(r),DECLINED)
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_IMPLEMENT_HOOK_RUN_ALL(int,access_checker,
f4c310fd2555c6faca1f980f00b161eadb089023gstein (request_rec *r),(r),OK,DECLINED)
98e9c4a310bb623ff788680f88b6bd200ff36a24wroweAP_IMPLEMENT_HOOK_RUN_FIRST(int,auth_checker,
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe (request_rec *r),(r),DECLINED)
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_IMPLEMENT_HOOK_VOID(insert_filter, (request_rec *r), (r))
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_IMPLEMENT_HOOK_RUN_ALL(int,create_request,(request_rec *r),(r),OK,DECLINED)
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic int decl_die(int status, char *phase, request_rec *r)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (status == DECLINED) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_CRIT, 0, r,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "configuration error: couldn't %s: %s", phase, r->uri);
f4c310fd2555c6faca1f980f00b161eadb089023gstein return HTTP_INTERNAL_SERVER_ERROR;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else
f4c310fd2555c6faca1f980f00b161eadb089023gstein return status;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* This is the master logic for processing requests. Do NOT duplicate
f4c310fd2555c6faca1f980f00b161eadb089023gstein * this logic elsewhere, or the security model will be broken by future
f4c310fd2555c6faca1f980f00b161eadb089023gstein * API changes. Each phase must be individually optimized to pick up
f4c310fd2555c6faca1f980f00b161eadb089023gstein * redundant/duplicate calls by subrequests, and redirects.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
98e9c4a310bb623ff788680f88b6bd200ff36a24wroweAP_DECLARE(int) ap_process_request_internal(request_rec *r)
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe{
f4c310fd2555c6faca1f980f00b161eadb089023gstein int access_status;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Ignore embedded %2F's in path for proxy requests */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!r->proxyreq && r->parsed_uri.path) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein access_status = ap_unescape_url(r->parsed_uri.path);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (access_status) {
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe return access_status;
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe }
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_getparents(r->uri); /* OK --- shrinking transformations... */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((access_status = ap_location_walk(r))) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein return access_status;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((access_status = ap_run_translate_name(r))) {
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe return decl_die(access_status, "translate", r);
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe return access_status;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((access_status = ap_run_map_to_storage(r))) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* This request wasn't in storage (e.g. TRACE) */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (access_status == DONE)
f4c310fd2555c6faca1f980f00b161eadb089023gstein return OK;
f4c310fd2555c6faca1f980f00b161eadb089023gstein else
f4c310fd2555c6faca1f980f00b161eadb089023gstein return access_status;
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe }
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe if ((access_status = ap_location_walk(r))) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein return access_status;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Only on the main request! */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (r->main == NULL) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((access_status = ap_run_header_parser(r))) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein return access_status;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein switch (ap_satisfies(r)) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein case SATISFY_ALL:
f4c310fd2555c6faca1f980f00b161eadb089023gstein case SATISFY_NOSPEC:
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((access_status = ap_run_access_checker(r)) != 0) {
48f35e10f195dd594d75738fc536bb885eda537cgstein return decl_die(access_status, "check access", r);
48f35e10f195dd594d75738fc536bb885eda537cgstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (ap_some_auth_required(r)) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (((access_status = ap_run_check_user_id(r)) != 0) || !ap_auth_type(r)) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein return decl_die(access_status, ap_auth_type(r)
91644a5f4d3e992dc208304b50e80bbb236fca89trawick ? "check user. No user file?"
f4c310fd2555c6faca1f980f00b161eadb089023gstein : "perform authentication. AuthType not set!", r);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (((access_status = ap_run_auth_checker(r)) != 0) || !ap_auth_type(r)) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein return decl_die(access_status, ap_auth_type(r)
f4c310fd2555c6faca1f980f00b161eadb089023gstein ? "check access. No groups file?"
f4c310fd2555c6faca1f980f00b161eadb089023gstein : "perform authentication. AuthType not set!", r);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein break;
f4c310fd2555c6faca1f980f00b161eadb089023gstein case SATISFY_ANY:
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (((access_status = ap_run_access_checker(r)) != 0) || !ap_auth_type(r)) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!ap_some_auth_required(r)) {
48f35e10f195dd594d75738fc536bb885eda537cgstein return decl_die(access_status, ap_auth_type(r)
f4c310fd2555c6faca1f980f00b161eadb089023gstein ? "check access"
f4c310fd2555c6faca1f980f00b161eadb089023gstein : "perform authentication. AuthType not set!", r);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (((access_status = ap_run_check_user_id(r)) != 0) || !ap_auth_type(r)) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein return decl_die(access_status, ap_auth_type(r)
48f35e10f195dd594d75738fc536bb885eda537cgstein ? "check user. No user file?"
f4c310fd2555c6faca1f980f00b161eadb089023gstein : "perform authentication. AuthType not set!", r);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (((access_status = ap_run_auth_checker(r)) != 0) || !ap_auth_type(r)) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein return decl_die(access_status, ap_auth_type(r)
f4c310fd2555c6faca1f980f00b161eadb089023gstein ? "check access. No groups file?"
f4c310fd2555c6faca1f980f00b161eadb089023gstein : "perform authentication. AuthType not set!", r);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
48f35e10f195dd594d75738fc536bb885eda537cgstein break;
48f35e10f195dd594d75738fc536bb885eda537cgstein }
48f35e10f195dd594d75738fc536bb885eda537cgstein
48f35e10f195dd594d75738fc536bb885eda537cgstein /* XXX Must make certain the ap_run_type_checker short circuits mime
48f35e10f195dd594d75738fc536bb885eda537cgstein * in mod-proxy for r->proxyreq && r->parsed_uri.scheme
48f35e10f195dd594d75738fc536bb885eda537cgstein * && !strcmp(r->parsed_uri.scheme, "http")
48f35e10f195dd594d75738fc536bb885eda537cgstein */
48f35e10f195dd594d75738fc536bb885eda537cgstein if ((access_status = ap_run_type_checker(r)) != 0) {
48f35e10f195dd594d75738fc536bb885eda537cgstein return decl_die(access_status, "find types", r);
48f35e10f195dd594d75738fc536bb885eda537cgstein }
48f35e10f195dd594d75738fc536bb885eda537cgstein
48f35e10f195dd594d75738fc536bb885eda537cgstein if ((access_status = ap_run_fixups(r)) != 0) {
48f35e10f195dd594d75738fc536bb885eda537cgstein return access_status;
48f35e10f195dd594d75738fc536bb885eda537cgstein }
48f35e10f195dd594d75738fc536bb885eda537cgstein
48f35e10f195dd594d75738fc536bb885eda537cgstein /* The new insert_filter stage makes sense here IMHO. We are sure that
48f35e10f195dd594d75738fc536bb885eda537cgstein * we are going to run the request now, so we may as well insert filters
48f35e10f195dd594d75738fc536bb885eda537cgstein * if any are available. Since the goal of this phase is to allow all
48f35e10f195dd594d75738fc536bb885eda537cgstein * modules to insert a filter if they want to, this filter returns
48f35e10f195dd594d75738fc536bb885eda537cgstein * void. I just can't see any way that this filter can reasonably
48f35e10f195dd594d75738fc536bb885eda537cgstein * fail, either your modules inserts something or it doesn't. rbb
48f35e10f195dd594d75738fc536bb885eda537cgstein */
48f35e10f195dd594d75738fc536bb885eda537cgstein ap_run_insert_filter(r);
48f35e10f195dd594d75738fc536bb885eda537cgstein
48f35e10f195dd594d75738fc536bb885eda537cgstein return OK;
48f35e10f195dd594d75738fc536bb885eda537cgstein}
48f35e10f195dd594d75738fc536bb885eda537cgstein
48f35e10f195dd594d75738fc536bb885eda537cgstein
48f35e10f195dd594d75738fc536bb885eda537cgstein/*****************************************************************
48f35e10f195dd594d75738fc536bb885eda537cgstein *
48f35e10f195dd594d75738fc536bb885eda537cgstein * Getting and checking directory configuration. Also checks the
48f35e10f195dd594d75738fc536bb885eda537cgstein * FollowSymlinks and FollowSymOwner stuff, since this is really the
48f35e10f195dd594d75738fc536bb885eda537cgstein * only place that can happen (barring a new mid_dir_walk callout).
48f35e10f195dd594d75738fc536bb885eda537cgstein *
48f35e10f195dd594d75738fc536bb885eda537cgstein * We can't do it as an access_checker module function which gets
48f35e10f195dd594d75738fc536bb885eda537cgstein * called with the final per_dir_config, since we could have a directory
48f35e10f195dd594d75738fc536bb885eda537cgstein * with FollowSymLinks disabled, which contains a symlink to another
48f35e10f195dd594d75738fc536bb885eda537cgstein * with a .htaccess file which turns FollowSymLinks back on --- and
f4c310fd2555c6faca1f980f00b161eadb089023gstein * access in such a case must be denied. So, whatever it is that
f4c310fd2555c6faca1f980f00b161eadb089023gstein * checks FollowSymLinks needs to know the state of the options as
f4c310fd2555c6faca1f980f00b161eadb089023gstein * they change, all the way down.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein/*
f4c310fd2555c6faca1f980f00b161eadb089023gstein * We don't want people able to serve up pipes, or unix sockets, or other
f4c310fd2555c6faca1f980f00b161eadb089023gstein * scary things. Note that symlink tests are performed later.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic int check_safe_file(request_rec *r)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (r->finfo.filetype == 0 /* doesn't exist */
f4c310fd2555c6faca1f980f00b161eadb089023gstein || r->finfo.filetype == APR_DIR
48f35e10f195dd594d75738fc536bb885eda537cgstein || r->finfo.filetype == APR_REG
48f35e10f195dd594d75738fc536bb885eda537cgstein || r->finfo.filetype == APR_LNK) {
48f35e10f195dd594d75738fc536bb885eda537cgstein return OK;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "object is not a file, directory or symlink: %s",
f4c310fd2555c6faca1f980f00b161eadb089023gstein r->filename);
f4c310fd2555c6faca1f980f00b161eadb089023gstein return HTTP_FORBIDDEN;
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef REPLACE_PATH_INFO_METHOD
f4c310fd2555c6faca1f980f00b161eadb089023gstein/*
f4c310fd2555c6faca1f980f00b161eadb089023gstein * resolve_symlink must _always_ be called on an APR_LNK file type!
f4c310fd2555c6faca1f980f00b161eadb089023gstein * It will resolve the actual target file type, modification date, etc,
f4c310fd2555c6faca1f980f00b161eadb089023gstein * and provide any processing required for symlink evaluation.
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Path must already be cleaned, no trailing slash, no multi-slashes,
f4c310fd2555c6faca1f980f00b161eadb089023gstein * and don't call this on the root!
f4c310fd2555c6faca1f980f00b161eadb089023gstein *
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Simply, the number of times we deref a symlink are minimal compared
f4c310fd2555c6faca1f980f00b161eadb089023gstein * to the number of times we had an extra lstat() since we 'weren't sure'.
f4c310fd2555c6faca1f980f00b161eadb089023gstein *
f4c310fd2555c6faca1f980f00b161eadb089023gstein * To optimize, we stat() anything when given (opts & OPT_SYM_LINKS), otherwise
f4c310fd2555c6faca1f980f00b161eadb089023gstein * we start off with an lstat(). Every lstat() must be dereferenced in case
f4c310fd2555c6faca1f980f00b161eadb089023gstein * it points at a 'nasty' - we must always rerun check_safe_file (or similar.)
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic int resolve_symlink(char *d, apr_finfo_t *lfi, int opts, apr_pool_t *p)
f958dac1550254a59b45f4655138bb34dad5e76egstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_finfo_t fi;
f4c310fd2555c6faca1f980f00b161eadb089023gstein int res;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!(opts & (OPT_SYM_OWNER | OPT_SYM_LINKS)))
f4c310fd2555c6faca1f980f00b161eadb089023gstein return HTTP_FORBIDDEN;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (opts & OPT_SYM_LINKS) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((res = apr_stat(&fi, d, lfi->valid, p)) != APR_SUCCESS)
f4c310fd2555c6faca1f980f00b161eadb089023gstein return HTTP_FORBIDDEN;
f4c310fd2555c6faca1f980f00b161eadb089023gstein return OK;
252e2478cb56afb5ca8585b50bc2ffb780d2efb6gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* OPT_SYM_OWNER only works if we can get the owner of
252e2478cb56afb5ca8585b50bc2ffb780d2efb6gstein * both the file and symlink. First fill in a missing
f4c310fd2555c6faca1f980f00b161eadb089023gstein * owner of the symlink, then get the info of the target.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!(lfi->valid & APR_FINFO_OWNER))
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((res = apr_lstat(&fi, d, lfi->valid | APR_FINFO_OWNER, p))
252e2478cb56afb5ca8585b50bc2ffb780d2efb6gstein != APR_SUCCESS)
f4c310fd2555c6faca1f980f00b161eadb089023gstein return HTTP_FORBIDDEN;
252e2478cb56afb5ca8585b50bc2ffb780d2efb6gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((res = apr_stat(&fi, d, lfi->valid, p)) != APR_SUCCESS)
f4c310fd2555c6faca1f980f00b161eadb089023gstein return HTTP_FORBIDDEN;
252e2478cb56afb5ca8585b50bc2ffb780d2efb6gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (apr_compare_users(fi.user, lfi->user) != APR_SUCCESS)
f4c310fd2555c6faca1f980f00b161eadb089023gstein return HTTP_FORBIDDEN;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Give back the target */
f39230a531b23d94f86a087963299bbe2e431a4agstein memcpy(lfi, &fi, sizeof(fi));
f39230a531b23d94f86a087963299bbe2e431a4agstein return OK;
f39230a531b23d94f86a087963299bbe2e431a4agstein}
f39230a531b23d94f86a087963299bbe2e431a4agstein#endif /* REPLACE_PATH_INFO_METHOD */
f39230a531b23d94f86a087963299bbe2e431a4agstein
f39230a531b23d94f86a087963299bbe2e431a4agstein#ifndef REPLACE_PATH_INFO_METHOD
f39230a531b23d94f86a087963299bbe2e431a4agstein
f39230a531b23d94f86a087963299bbe2e431a4agsteinstatic int check_symlinks(char *d, int opts, apr_pool_t *p)
f39230a531b23d94f86a087963299bbe2e431a4agstein{
f39230a531b23d94f86a087963299bbe2e431a4agstein#if defined(OS2)
1e2133fe37e6cbcd683233057ef62236bc8e5826trawick /* OS/2 doesn't have symlinks */
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein return OK;
f39230a531b23d94f86a087963299bbe2e431a4agstein#else
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein apr_finfo_t lfi, fi;
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein char *lastp;
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein int res;
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein if (opts & OPT_SYM_LINKS)
f39230a531b23d94f86a087963299bbe2e431a4agstein return OK;
f39230a531b23d94f86a087963299bbe2e431a4agstein
f39230a531b23d94f86a087963299bbe2e431a4agstein /*
f39230a531b23d94f86a087963299bbe2e431a4agstein * Strip trailing '/', if any, off what we're checking; trailing slashes
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein * make some systems follow symlinks to directories even in lstat().
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein * After we've done the lstat, put it back. Also, don't bother checking
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein * '/' at all...
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein *
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein * Note that we don't have to worry about multiple slashes here because of
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein * no2slash() below...
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein */
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein lastp = d + strlen(d) - 1;
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein if (lastp == d)
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein return OK; /* Root directory, '/' */
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein if (*lastp == '/')
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein *lastp = '\0';
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein else
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein lastp = NULL;
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein res = apr_lstat(&lfi, d, APR_FINFO_TYPE | APR_FINFO_OWNER, p);
f39230a531b23d94f86a087963299bbe2e431a4agstein
f39230a531b23d94f86a087963299bbe2e431a4agstein if (lastp)
f39230a531b23d94f86a087963299bbe2e431a4agstein *lastp = '/';
f39230a531b23d94f86a087963299bbe2e431a4agstein
f39230a531b23d94f86a087963299bbe2e431a4agstein /*
f39230a531b23d94f86a087963299bbe2e431a4agstein * Note that we don't reject accesses to nonexistent files (multiviews or
f39230a531b23d94f86a087963299bbe2e431a4agstein * the like may cons up a way to run the transaction anyway)...
f39230a531b23d94f86a087963299bbe2e431a4agstein */
f39230a531b23d94f86a087963299bbe2e431a4agstein
f39230a531b23d94f86a087963299bbe2e431a4agstein if ((res != APR_SUCCESS && res != APR_INCOMPLETE)
f39230a531b23d94f86a087963299bbe2e431a4agstein || (lfi.filetype != APR_LNK))
f39230a531b23d94f86a087963299bbe2e431a4agstein return OK;
f39230a531b23d94f86a087963299bbe2e431a4agstein
f39230a531b23d94f86a087963299bbe2e431a4agstein /* OK, it's a symlink. May still be OK with OPT_SYM_OWNER */
f39230a531b23d94f86a087963299bbe2e431a4agstein
f39230a531b23d94f86a087963299bbe2e431a4agstein if (!(opts & OPT_SYM_OWNER))
f39230a531b23d94f86a087963299bbe2e431a4agstein return HTTP_FORBIDDEN;
f39230a531b23d94f86a087963299bbe2e431a4agstein
f39230a531b23d94f86a087963299bbe2e431a4agstein /* OPT_SYM_OWNER only works if we can get the owner from the file */
f39230a531b23d94f86a087963299bbe2e431a4agstein
f39230a531b23d94f86a087963299bbe2e431a4agstein if (res != APR_SUCCESS)
f39230a531b23d94f86a087963299bbe2e431a4agstein return HTTP_FORBIDDEN;
ab78b55c6dc4431d2c68d6bb4d169ba1554290a8gstein
f39230a531b23d94f86a087963299bbe2e431a4agstein if (apr_stat(&fi, d, APR_FINFO_OWNER, p) != APR_SUCCESS)
f39230a531b23d94f86a087963299bbe2e431a4agstein return HTTP_FORBIDDEN;
f39230a531b23d94f86a087963299bbe2e431a4agstein
f39230a531b23d94f86a087963299bbe2e431a4agstein /* TODO: replace with an apr_compare_users() fn */
f39230a531b23d94f86a087963299bbe2e431a4agstein return (fi.user == lfi.user) ? OK : HTTP_FORBIDDEN;
f39230a531b23d94f86a087963299bbe2e431a4agstein
f39230a531b23d94f86a087963299bbe2e431a4agstein#endif
f39230a531b23d94f86a087963299bbe2e431a4agstein}
f39230a531b23d94f86a087963299bbe2e431a4agstein
f39230a531b23d94f86a087963299bbe2e431a4agstein/* Dealing with the file system to get PATH_INFO
f39230a531b23d94f86a087963299bbe2e431a4agstein */
f39230a531b23d94f86a087963299bbe2e431a4agsteinstatic int get_path_info(request_rec *r)
f39230a531b23d94f86a087963299bbe2e431a4agstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein char *cp;
f4c310fd2555c6faca1f980f00b161eadb089023gstein char *path = r->filename;
f4c310fd2555c6faca1f980f00b161eadb089023gstein char *end = &path[strlen(path)];
f4c310fd2555c6faca1f980f00b161eadb089023gstein char *last_cp = NULL;
f4c310fd2555c6faca1f980f00b161eadb089023gstein int rv;
f4c310fd2555c6faca1f980f00b161eadb089023gstein#if defined(HAVE_DRIVE_LETTERS) || defined(HAVE_UNC_PATHS)
f4c310fd2555c6faca1f980f00b161eadb089023gstein char bStripSlash=1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (r->finfo.filetype != APR_NOFILE) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* assume path_info already set */
f4c310fd2555c6faca1f980f00b161eadb089023gstein return OK;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef HAVE_DRIVE_LETTERS
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* If the directory is x:\, then we don't want to strip
f4c310fd2555c6faca1f980f00b161eadb089023gstein * the trailing slash since x: is not a valid directory.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm if (strlen(path) == 3 && path[1] == ':' && path[2] == '/')
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm bStripSlash = 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef HAVE_UNC_PATHS
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* If UNC name == //machine/share/, do not
f4c310fd2555c6faca1f980f00b161eadb089023gstein * advance over the trailing slash. Any other
f4c310fd2555c6faca1f980f00b161eadb089023gstein * UNC name is OK to strip the slash.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein cp = end;
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (path[0] == '/' && path[1] == '/' &&
f4c310fd2555c6faca1f980f00b161eadb089023gstein path[2] != '/' && cp[-1] == '/') {
f4c310fd2555c6faca1f980f00b161eadb089023gstein char *p;
f4c310fd2555c6faca1f980f00b161eadb089023gstein int iCount=0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein p = path;
f4c310fd2555c6faca1f980f00b161eadb089023gstein while ((p = strchr(p,'/')) != NULL) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein p++;
f4c310fd2555c6faca1f980f00b161eadb089023gstein iCount++;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (iCount == 4)
f4c310fd2555c6faca1f980f00b161eadb089023gstein bStripSlash = 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein#if defined(HAVE_DRIVE_LETTERS) || defined(HAVE_UNC_PATHS)
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (bStripSlash)
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Advance over trailing slashes ... NOT part of filename
f4c310fd2555c6faca1f980f00b161eadb089023gstein * if file is not a UNC name (Win32 only).
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (cp = end; cp > path && cp[-1] == '/'; --cp)
f4c310fd2555c6faca1f980f00b161eadb089023gstein continue;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein while (cp > path) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* See if the pathname ending here exists... */
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm *cp = '\0';
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### We no longer need the test ap_os_is_filename_valid() here
f4c310fd2555c6faca1f980f00b161eadb089023gstein * since apr_stat isn't a posix thing - it's apr_stat's responsibility
f4c310fd2555c6faca1f980f00b161eadb089023gstein * to handle whatever path string arrives at its door - by platform
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * and volume restrictions as applicable...
f4c310fd2555c6faca1f980f00b161eadb089023gstein * TODO: This code becomes even simpler if apr_stat grows
f4c310fd2555c6faca1f980f00b161eadb089023gstein * an APR_PATHINCOMPLETE result to indicate that we are staring at
f4c310fd2555c6faca1f980f00b161eadb089023gstein * an partial virtual root. Only OS2/Win32/Netware need apply it :-)
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein rv = apr_stat(&r->finfo, path, APR_FINFO_MIN, r->pool);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (cp != end)
f4c310fd2555c6faca1f980f00b161eadb089023gstein *cp = '/';
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (rv == APR_SUCCESS || rv == APR_INCOMPLETE) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /*
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * Aha! Found something. If it was a directory, we will search
f4c310fd2555c6faca1f980f00b161eadb089023gstein * contents of that directory for a multi_match, so the PATH_INFO
f4c310fd2555c6faca1f980f00b161eadb089023gstein * argument starts with the component after that.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (r->finfo.filetype == APR_DIR && last_cp) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein r->finfo.filetype = APR_NOFILE; /* No such file... */
f4c310fd2555c6faca1f980f00b161eadb089023gstein cp = last_cp;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein r->path_info = apr_pstrdup(r->pool, cp);
f4c310fd2555c6faca1f980f00b161eadb089023gstein *cp = '\0';
f4c310fd2555c6faca1f980f00b161eadb089023gstein return OK;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (APR_STATUS_IS_ENOENT(rv) || APR_STATUS_IS_ENOTDIR(rv)) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein last_cp = cp;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein while (--cp > path && *cp != '/')
f4c310fd2555c6faca1f980f00b161eadb089023gstein continue;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein while (cp > path && cp[-1] == '/')
f4c310fd2555c6faca1f980f00b161eadb089023gstein --cp;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else {
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (APR_STATUS_IS_EACCES(rv))
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "access to %s denied", r->uri);
f4c310fd2555c6faca1f980f00b161eadb089023gstein else
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "access to %s failed", r->uri);
f4c310fd2555c6faca1f980f00b161eadb089023gstein return HTTP_FORBIDDEN;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein return OK;
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE(int) ap_directory_walk(request_rec *r)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein core_server_config *sconf = ap_get_module_config(r->server->module_config,
f4c310fd2555c6faca1f980f00b161eadb089023gstein &core_module);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_conf_vector_t *per_dir_defaults = r->server->lookup_defaults;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_conf_vector_t **sec_dir = (ap_conf_vector_t **) sconf->sec_dir->elts;
f4c310fd2555c6faca1f980f00b161eadb089023gstein int num_sec = sconf->sec_dir->nelts;
f4c310fd2555c6faca1f980f00b161eadb089023gstein char *test_filename;
f4c310fd2555c6faca1f980f00b161eadb089023gstein char *test_dirname;
f4c310fd2555c6faca1f980f00b161eadb089023gstein int res;
f4c310fd2555c6faca1f980f00b161eadb089023gstein unsigned i, num_dirs;
f4c310fd2555c6faca1f980f00b161eadb089023gstein int j, test_filename_len;
f4c310fd2555c6faca1f980f00b161eadb089023gstein unsigned iStart = 1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_conf_vector_t *entry_config;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_conf_vector_t *this_conf;
f4c310fd2555c6faca1f980f00b161eadb089023gstein core_dir_config *entry_core;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /*
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Are we dealing with a file? If not, the handler needed to register
f4c310fd2555c6faca1f980f00b161eadb089023gstein * a hook to escape from our walking the file. Since they haven't, we
f4c310fd2555c6faca1f980f00b161eadb089023gstein * are going to assume the worst and refuse to proceed.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (r->filename == NULL || !ap_os_is_path_absolute(r->pool, r->filename)) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Module bug? Request filename path %s is missing or "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "or not absolute for uri %s",
f4c310fd2555c6faca1f980f00b161eadb089023gstein r->filename ? r->filename : "<NULL>", r->uri);
f4c310fd2555c6faca1f980f00b161eadb089023gstein return HTTP_INTERNAL_SERVER_ERROR;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /*
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Go down the directory hierarchy. Where we have to check for symlinks,
26250b0077972bf21b6d8a8d23772a4cf53f9477gstein * do so. Where a .htaccess file has permission to override anything,
f4c310fd2555c6faca1f980f00b161eadb089023gstein * try to find one. If either of these things fails, we could poke
f4c310fd2555c6faca1f980f00b161eadb089023gstein * around, see why, and adjust the lookup_rec accordingly --- this might
f4c310fd2555c6faca1f980f00b161eadb089023gstein * save us a call to get_path_info (with the attendant stat()s); however,
f4c310fd2555c6faca1f980f00b161eadb089023gstein * for the moment, that's not worth the trouble.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein res = get_path_info(r);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (res != OK) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein return res;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* XXX Momentary period of extreme danger, Will Robinson.
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Removed ap_os_canonical_filename. Anybody munging the
f4c310fd2555c6faca1f980f00b161eadb089023gstein * r->filename better have pre-canonicalized the name that
f4c310fd2555c6faca1f980f00b161eadb089023gstein * they just changed. Since the two most key functions
f4c310fd2555c6faca1f980f00b161eadb089023gstein * in the entire server, ap_server_root_relative() and
f4c310fd2555c6faca1f980f00b161eadb089023gstein * ap_make_full_path now canonicalize as they go.
f4c310fd2555c6faca1f980f00b161eadb089023gstein *
f4c310fd2555c6faca1f980f00b161eadb089023gstein * To be very safe, the server is in hyper-paranoid mode.
f4c310fd2555c6faca1f980f00b161eadb089023gstein * That means that non-canonical paths will be captured and
f4c310fd2555c6faca1f980f00b161eadb089023gstein * denied. This is very cpu/fs intensive, we need to finish
f4c310fd2555c6faca1f980f00b161eadb089023gstein * auditing, and remove the paranoia trigger.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (r->filename == r->canonical_filename)
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef NO_LONGER_PARANOID
f4c310fd2555c6faca1f980f00b161eadb089023gstein test_filename = apr_pstrdup(r->pool, r->filename);
f4c310fd2555c6faca1f980f00b161eadb089023gstein#else
f4c310fd2555c6faca1f980f00b161eadb089023gstein {
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (apr_filepath_merge(&test_filename, "", r->filename,
f4c310fd2555c6faca1f980f00b161eadb089023gstein APR_FILEPATH_NOTRELATIVE | APR_FILEPATH_TRUENAME,
f4c310fd2555c6faca1f980f00b161eadb089023gstein r->pool) != APR_SUCCESS
f4c310fd2555c6faca1f980f00b161eadb089023gstein || strcmp(test_filename, r->filename) != 0) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Module bug? Filepath: %s is not the canonical %s",
f4c310fd2555c6faca1f980f00b161eadb089023gstein r->filename, test_filename);
f4c310fd2555c6faca1f980f00b161eadb089023gstein return HTTP_FORBIDDEN;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein else {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Apparently, somebody didn't know to update r->canonical_filename
f4c310fd2555c6faca1f980f00b161eadb089023gstein * which is lucky, since they didn't canonicalize r->filename either.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (apr_filepath_merge(&test_filename, NULL, r->filename,
f4c310fd2555c6faca1f980f00b161eadb089023gstein APR_FILEPATH_NOTRELATIVE | APR_FILEPATH_TRUENAME,
f4c310fd2555c6faca1f980f00b161eadb089023gstein r->pool) != APR_SUCCESS) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Module bug? Filepath: %s is not an absolute path",
f4c310fd2555c6faca1f980f00b161eadb089023gstein r->filename);
f4c310fd2555c6faca1f980f00b161eadb089023gstein return HTTP_FORBIDDEN;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (strcmp(r->filename, test_filename) != 0)
f4c310fd2555c6faca1f980f00b161eadb089023gstein r->filename = apr_pstrdup(r->pool, test_filename);
f4c310fd2555c6faca1f980f00b161eadb089023gstein r->canonical_filename = r->filename;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein num_dirs = ap_count_dirs(test_filename);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((res = check_safe_file(r))) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein return res;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein test_filename_len = strlen(test_filename);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (test_filename[test_filename_len - 1] == '/')
f4c310fd2555c6faca1f980f00b161eadb089023gstein --num_dirs;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (r->finfo.filetype == APR_DIR)
f4c310fd2555c6faca1f980f00b161eadb089023gstein ++num_dirs;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /*
f4c310fd2555c6faca1f980f00b161eadb089023gstein * We will use test_dirname as scratch space while we build directory
f4c310fd2555c6faca1f980f00b161eadb089023gstein * names during the walk. Profiling shows directory_walk to be a busy
f4c310fd2555c6faca1f980f00b161eadb089023gstein * function so we try to avoid allocating lots of extra memory here.
f4c310fd2555c6faca1f980f00b161eadb089023gstein * We need 2 extra bytes, one for trailing \0 and one because
f4c310fd2555c6faca1f980f00b161eadb089023gstein * make_dirstr_prefix will add potentially one extra /.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein test_dirname = apr_palloc(r->pool, test_filename_len + 2);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* XXX The garbage below disappears in the new directory_walk;
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein#if defined(HAVE_UNC_PATHS)
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* If the name is a UNC name, then do not perform any true file test
f4c310fd2555c6faca1f980f00b161eadb089023gstein * against the machine name (start at //machine/share/)
f4c310fd2555c6faca1f980f00b161eadb089023gstein * This is optimized to use the normal walk (skips the redundant '/' root)
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (num_dirs > 3 && test_filename[0] == '/' && test_filename[1] == '/')
f4c310fd2555c6faca1f980f00b161eadb089023gstein iStart = 4;
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein#if defined(NETWARE)
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* If the name is a fully qualified volume name, then do not perform any
f4c310fd2555c6faca1f980f00b161eadb089023gstein * true file test on the machine name (start at machine/share:/)
f4c310fd2555c6faca1f980f00b161eadb089023gstein * XXX: The implementation eludes me at this moment...
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Does this make sense? Please test!
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (num_dirs > 1 && strchr(test_filename, '/') < strchr(test_filename, ':'))
f4c310fd2555c6faca1f980f00b161eadb089023gstein iStart = 2;
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* i keeps track of how many segments we are testing
f4c310fd2555c6faca1f980f00b161eadb089023gstein * j keeps track of which section we're on, see core_reorder_directories
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein j = 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (i = 1; i <= num_dirs; ++i) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein int overrides_here;
f4c310fd2555c6faca1f980f00b161eadb089023gstein core_dir_config *core_dir = ap_get_module_config(per_dir_defaults,
f4c310fd2555c6faca1f980f00b161eadb089023gstein &core_module);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /*
f4c310fd2555c6faca1f980f00b161eadb089023gstein * XXX: this could be made faster by only copying the next component
f4c310fd2555c6faca1f980f00b161eadb089023gstein * rather than copying the entire thing all over.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_make_dirstr_prefix(test_dirname, test_filename, i);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /*
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Do symlink checks first, because they are done with the
f4c310fd2555c6faca1f980f00b161eadb089023gstein * permissions appropriate to the *parent* directory...
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Test only real names (after the root) against the real filesystem */
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm if ((i > iStart) && (res = check_symlinks(test_dirname, core_dir->opts, r->pool))) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Symbolic link not allowed: %s", test_dirname);
f4c310fd2555c6faca1f980f00b161eadb089023gstein return res;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /*
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Begin *this* level by looking for matching <Directory> sections
f4c310fd2555c6faca1f980f00b161eadb089023gstein * from access.conf.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (; j < num_sec; ++j) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein char *entry_dir;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein entry_config = sec_dir[j];
f4c310fd2555c6faca1f980f00b161eadb089023gstein entry_core = ap_get_module_config(entry_config, &core_module);
f4c310fd2555c6faca1f980f00b161eadb089023gstein entry_dir = entry_core->d;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (entry_core->r || entry_core->d_components > i)
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm break;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein this_conf = NULL;
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* We will always add in '0' element components, e.g. plain old
f4c310fd2555c6faca1f980f00b161eadb089023gstein * <Directory >, and <Directory "/"> is classified as zero
f4c310fd2555c6faca1f980f00b161eadb089023gstein * so that Win32/Netware/OS2 etc all pick that up.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!entry_core->d_components) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein this_conf = entry_config;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else if (entry_core->d_is_fnmatch) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!apr_fnmatch(entry_dir, test_dirname, FNM_PATHNAME)) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein this_conf = entry_config;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else if (!strcmp(test_dirname, entry_dir))
f4c310fd2555c6faca1f980f00b161eadb089023gstein this_conf = entry_config;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (this_conf) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein per_dir_defaults = ap_merge_per_dir_configs(r->pool,
f4c310fd2555c6faca1f980f00b161eadb089023gstein per_dir_defaults,
f4c310fd2555c6faca1f980f00b161eadb089023gstein this_conf);
f4c310fd2555c6faca1f980f00b161eadb089023gstein core_dir = ap_get_module_config(per_dir_defaults,
f4c310fd2555c6faca1f980f00b161eadb089023gstein &core_module);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein overrides_here = core_dir->override;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* If .htaccess files are enabled, check for one. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Test only legal names against the real filesystem */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((i >= iStart) && overrides_here) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_conf_vector_t *htaccess_conf = NULL;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein res = ap_parse_htaccess(&htaccess_conf, r, overrides_here,
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_pstrdup(r->pool, test_dirname),
f4c310fd2555c6faca1f980f00b161eadb089023gstein sconf->access_name);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (res)
f4c310fd2555c6faca1f980f00b161eadb089023gstein return res;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (htaccess_conf) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein per_dir_defaults = ap_merge_per_dir_configs(r->pool,
f4c310fd2555c6faca1f980f00b161eadb089023gstein per_dir_defaults,
f4c310fd2555c6faca1f980f00b161eadb089023gstein htaccess_conf);
f4c310fd2555c6faca1f980f00b161eadb089023gstein r->per_dir_config = per_dir_defaults;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /*
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Now we'll deal with the regexes.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (; j < num_sec; ++j) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein entry_config = sec_dir[j];
f4c310fd2555c6faca1f980f00b161eadb089023gstein entry_core = ap_get_module_config(entry_config, &core_module);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!entry_core->r) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein continue;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm }
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!ap_regexec(entry_core->r, test_dirname, 0, NULL, REG_NOTEOL)) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein per_dir_defaults = ap_merge_per_dir_configs(r->pool,
f4c310fd2555c6faca1f980f00b161eadb089023gstein per_dir_defaults,
f4c310fd2555c6faca1f980f00b161eadb089023gstein entry_config);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein r->per_dir_config = per_dir_defaults;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /*
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Symlink permissions are determined by the parent. If the request is
f4c310fd2555c6faca1f980f00b161eadb089023gstein * for a directory then applying the symlink test here would use the
f4c310fd2555c6faca1f980f00b161eadb089023gstein * permissions of the directory as opposed to its parent. Consider a
f4c310fd2555c6faca1f980f00b161eadb089023gstein * symlink pointing to a dir with a .htaccess disallowing symlinks. If
f4c310fd2555c6faca1f980f00b161eadb089023gstein * you access /symlink (or /symlink/) you would get a 403 without this
f4c310fd2555c6faca1f980f00b161eadb089023gstein * APR_DIR test. But if you accessed /symlink/index.html, for example,
f4c310fd2555c6faca1f980f00b161eadb089023gstein * you would *not* get the 403.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (r->finfo.filetype != APR_DIR
98e9c4a310bb623ff788680f88b6bd200ff36a24wrowe && (res = check_symlinks(r->filename, ap_allow_options(r), r->pool))) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Symbolic link not allowed: %s", r->filename);
f4c310fd2555c6faca1f980f00b161eadb089023gstein return res;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein return OK; /* Can only "fail" if access denied by the
f4c310fd2555c6faca1f980f00b161eadb089023gstein * symlink goop. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein#else /* defined REPLACE_PATH_INFO_METHOD */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein/*****************************************************************
f4c310fd2555c6faca1f980f00b161eadb089023gstein *
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Getting and checking directory configuration. Also checks the
f4c310fd2555c6faca1f980f00b161eadb089023gstein * FollowSymlinks and FollowSymOwner stuff, since this is really the
f4c310fd2555c6faca1f980f00b161eadb089023gstein * only place that can happen (barring a new mid_dir_walk callout).
f4c310fd2555c6faca1f980f00b161eadb089023gstein *
f4c310fd2555c6faca1f980f00b161eadb089023gstein * We can't do it as an access_checker module function which gets
f4c310fd2555c6faca1f980f00b161eadb089023gstein * called with the final per_dir_config, since we could have a directory
f4c310fd2555c6faca1f980f00b161eadb089023gstein * with FollowSymLinks disabled, which contains a symlink to another
f4c310fd2555c6faca1f980f00b161eadb089023gstein * with a .htaccess file which turns FollowSymLinks back on --- and
f4c310fd2555c6faca1f980f00b161eadb089023gstein * access in such a case must be denied. So, whatever it is that
f4c310fd2555c6faca1f980f00b161eadb089023gstein * checks FollowSymLinks needs to know the state of the options as
f4c310fd2555c6faca1f980f00b161eadb089023gstein * they change, all the way down.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE(int) ap_directory_walk(request_rec *r)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein core_server_config *sconf = ap_get_module_config(r->server->module_config,
f4c310fd2555c6faca1f980f00b161eadb089023gstein &core_module);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_conf_vector_t *per_dir_defaults = r->server->lookup_defaults;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_conf_vector_t **sec_ent = (ap_conf_vector_t **) sconf->sec_dir->elts;
f4c310fd2555c6faca1f980f00b161eadb089023gstein int num_sec = sconf->sec_dir->nelts;
f4c310fd2555c6faca1f980f00b161eadb089023gstein int sec_idx;
f4c310fd2555c6faca1f980f00b161eadb089023gstein unsigned int seg, startseg;
f4c310fd2555c6faca1f980f00b161eadb089023gstein int res;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_conf_vector_t *entry_config;
f4c310fd2555c6faca1f980f00b161eadb089023gstein core_dir_config *entry_core;
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_status_t rv;
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_size_t buflen;
f4c310fd2555c6faca1f980f00b161eadb089023gstein char *seg_name;
f4c310fd2555c6faca1f980f00b161eadb089023gstein char *delim;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /*
f4c310fd2555c6faca1f980f00b161eadb089023gstein * XXX: Better (faster) tests needed!!!
f4c310fd2555c6faca1f980f00b161eadb089023gstein *
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Are we dealing with a file? If not, the handler needed to register
f4c310fd2555c6faca1f980f00b161eadb089023gstein * a hook to escape from our walking the file. Since they haven't, we
f4c310fd2555c6faca1f980f00b161eadb089023gstein * are going to assume the worst and refuse to proceed.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (r->filename == NULL || !ap_os_is_path_absolute(r->pool, r->filename)) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Module bug? Request filename path %s is missing or "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "or not absolute for uri %s",
f4c310fd2555c6faca1f980f00b161eadb089023gstein r->filename ? r->filename : "<NULL>", r->uri);
f4c310fd2555c6faca1f980f00b161eadb089023gstein return HTTP_INTERNAL_SERVER_ERROR;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /*
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Go down the directory hierarchy. Where we have to check for symlinks,
f4c310fd2555c6faca1f980f00b161eadb089023gstein * do so. Where a .htaccess file has permission to override anything,
f4c310fd2555c6faca1f980f00b161eadb089023gstein * try to find one. If either of these things fails, we could poke
f4c310fd2555c6faca1f980f00b161eadb089023gstein * around, see why, and adjust the lookup_rec accordingly --- this might
f4c310fd2555c6faca1f980f00b161eadb089023gstein * save us a call to get_path_info (with the attendant stat()s); however,
f4c310fd2555c6faca1f980f00b161eadb089023gstein * for the moment, that's not worth the trouble.
f4c310fd2555c6faca1f980f00b161eadb089023gstein *
f4c310fd2555c6faca1f980f00b161eadb089023gstein * r->path_info tracks the remaining source path.
f4c310fd2555c6faca1f980f00b161eadb089023gstein * r->filename tracks the path as we build it.
f4c310fd2555c6faca1f980f00b161eadb089023gstein * we begin our adventure at the root...
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein r->path_info = r->filename;
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((rv = apr_filepath_merge(&r->path_info, NULL, r->filename,
f4c310fd2555c6faca1f980f00b161eadb089023gstein APR_FILEPATH_NOTRELATIVE, r->pool))
f4c310fd2555c6faca1f980f00b161eadb089023gstein == APR_SUCCESS) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein char *buf;
f4c310fd2555c6faca1f980f00b161eadb089023gstein rv = apr_filepath_root(&r->filename, &r->path_info,
f4c310fd2555c6faca1f980f00b161eadb089023gstein APR_FILEPATH_TRUENAME, r->pool);
f4c310fd2555c6faca1f980f00b161eadb089023gstein buflen = strlen(r->filename) + strlen(r->path_info) + 1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein buf = apr_palloc(r->pool, buflen);
f4c310fd2555c6faca1f980f00b161eadb089023gstein strcpy (buf, r->filename);
f4c310fd2555c6faca1f980f00b161eadb089023gstein r->filename = buf;
f4c310fd2555c6faca1f980f00b161eadb089023gstein r->finfo.valid = APR_FINFO_TYPE;
f4c310fd2555c6faca1f980f00b161eadb089023gstein r->finfo.filetype = APR_DIR; /* It's the root, of course it's a dir */
f4c310fd2555c6faca1f980f00b161eadb089023gstein } else {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Config bug? Request filename path %s is invalid or "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "or not absolute for uri %s",
f4c310fd2555c6faca1f980f00b161eadb089023gstein r->filename, r->uri);
f4c310fd2555c6faca1f980f00b161eadb089023gstein return HTTP_INTERNAL_SERVER_ERROR;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /*
f4c310fd2555c6faca1f980f00b161eadb089023gstein * seg keeps track of which segment we've copied.
f4c310fd2555c6faca1f980f00b161eadb089023gstein * sec_idx keeps track of which section we're on, since sections are
f4c310fd2555c6faca1f980f00b161eadb089023gstein * ordered by number of segments. See core_reorder_directories
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein startseg = seg = ap_count_dirs(r->filename);
f4c310fd2555c6faca1f980f00b161eadb089023gstein sec_idx = 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein do {
f4c310fd2555c6faca1f980f00b161eadb089023gstein int overrides_here;
f4c310fd2555c6faca1f980f00b161eadb089023gstein core_dir_config *core_dir = ap_get_module_config(per_dir_defaults,
f4c310fd2555c6faca1f980f00b161eadb089023gstein &core_module);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* We have no trailing slash, but we sure would appreciate one...
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (sec_idx && r->filename[strlen(r->filename)-1] != '/')
f4c310fd2555c6faca1f980f00b161eadb089023gstein strcat(r->filename, "/");
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Begin *this* level by looking for matching <Directory> sections
f4c310fd2555c6faca1f980f00b161eadb089023gstein * from the server config.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (; sec_idx < num_sec; ++sec_idx) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *entry_dir;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein entry_config = sec_ent[sec_idx];
f4c310fd2555c6faca1f980f00b161eadb089023gstein entry_core = ap_get_module_config(entry_config, &core_module);
f4c310fd2555c6faca1f980f00b161eadb089023gstein entry_dir = entry_core->d;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* No more possible matches for this many segments?
f4c310fd2555c6faca1f980f00b161eadb089023gstein * We are done when we find relative/regex/longer components.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (entry_core->r || entry_core->d_components > seg)
f4c310fd2555c6faca1f980f00b161eadb089023gstein break;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* We will never skip '0' element components, e.g. plain old
f4c310fd2555c6faca1f980f00b161eadb089023gstein * <Directory >, and <Directory "/"> are classified as zero
f4c310fd2555c6faca1f980f00b161eadb089023gstein * so that Win32/Netware/OS2 etc all pick them up.
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Otherwise, skip over the mismatches.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (entry_core->d_components
f4c310fd2555c6faca1f980f00b161eadb089023gstein && (entry_core->d_is_fnmatch
f4c310fd2555c6faca1f980f00b161eadb089023gstein ? (apr_fnmatch(entry_dir, r->filename, FNM_PATHNAME) != APR_SUCCESS)
f4c310fd2555c6faca1f980f00b161eadb089023gstein : (strcmp(r->filename, entry_dir) != 0))) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein continue;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein per_dir_defaults = ap_merge_per_dir_configs(r->pool,
f4c310fd2555c6faca1f980f00b161eadb089023gstein per_dir_defaults,
f4c310fd2555c6faca1f980f00b161eadb089023gstein entry_config);
f4c310fd2555c6faca1f980f00b161eadb089023gstein core_dir = ap_get_module_config(per_dir_defaults,
f4c310fd2555c6faca1f980f00b161eadb089023gstein &core_module);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein overrides_here = core_dir->override;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* If .htaccess files are enabled, check for one. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (overrides_here) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_conf_vector_t *htaccess_conf = NULL;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein res = ap_parse_htaccess(&htaccess_conf, r, overrides_here,
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_pstrdup(r->pool, r->filename),
f4c310fd2555c6faca1f980f00b161eadb089023gstein sconf->access_name);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (res)
f4c310fd2555c6faca1f980f00b161eadb089023gstein return res;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (htaccess_conf) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein per_dir_defaults = ap_merge_per_dir_configs(r->pool,
f4c310fd2555c6faca1f980f00b161eadb089023gstein per_dir_defaults,
f4c310fd2555c6faca1f980f00b161eadb089023gstein htaccess_conf);
f4c310fd2555c6faca1f980f00b161eadb089023gstein r->per_dir_config = per_dir_defaults;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* That temporary trailing slash was useful, now drop it.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (seg > startseg)
f4c310fd2555c6faca1f980f00b161eadb089023gstein r->filename[strlen(r->filename) - 1] = '\0';
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Time for all good things to come to an end?
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!r->path_info || !*r->path_info)
f4c310fd2555c6faca1f980f00b161eadb089023gstein break;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Now it's time for the next segment...
f4c310fd2555c6faca1f980f00b161eadb089023gstein * We will assume the next element is an end node, and fix it up
f4c310fd2555c6faca1f980f00b161eadb089023gstein * below as necessary...
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein seg_name = strchr(r->filename, '\0');
f4c310fd2555c6faca1f980f00b161eadb089023gstein delim = strchr(r->path_info + (*r->path_info == '/' ? 1 : 0), '/');
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (delim) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein *delim = '\0';
f4c310fd2555c6faca1f980f00b161eadb089023gstein strcpy(seg_name, r->path_info);
f4c310fd2555c6faca1f980f00b161eadb089023gstein r->path_info = delim;
f4c310fd2555c6faca1f980f00b161eadb089023gstein *delim = '/';
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else {
f4c310fd2555c6faca1f980f00b161eadb089023gstein strcpy(seg_name, r->path_info);
f4c310fd2555c6faca1f980f00b161eadb089023gstein r->path_info = strchr(r->path_info, '\0');
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (*seg_name == '/')
f4c310fd2555c6faca1f980f00b161eadb089023gstein ++seg_name;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* If nothing remained but a '/' string, we are finished
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!*seg_name)
f4c310fd2555c6faca1f980f00b161eadb089023gstein break;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* XXX: Optimization required:
f4c310fd2555c6faca1f980f00b161eadb089023gstein * If...we have allowed symlinks, and
f4c310fd2555c6faca1f980f00b161eadb089023gstein * if...we find the segment exists in the directory list
f4c310fd2555c6faca1f980f00b161eadb089023gstein * skip the lstat and dummy up an APR_DIR value for r->finfo
f4c310fd2555c6faca1f980f00b161eadb089023gstein * this means case sensitive platforms go quite quickly.
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Case insensitive platforms might be given the wrong path,
f4c310fd2555c6faca1f980f00b161eadb089023gstein * but if it's not found in the cache, then we know we have
f4c310fd2555c6faca1f980f00b161eadb089023gstein * something to test (the misspelling is never cached.)
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* We choose apr_lstat here, rather that apr_stat, so that we
f4c310fd2555c6faca1f980f00b161eadb089023gstein * capture this path object rather than its target. We will
f4c310fd2555c6faca1f980f00b161eadb089023gstein * replace the info with our target's info below. We especially
f4c310fd2555c6faca1f980f00b161eadb089023gstein * want the name of this 'link' object, not the name of its
f4c310fd2555c6faca1f980f00b161eadb089023gstein * target, if we are fixing case.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein rv = apr_lstat(&r->finfo, r->filename, APR_FINFO_MIN | APR_FINFO_NAME, r->pool);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (APR_STATUS_IS_ENOENT(rv)) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Nothing? That could be nice. But our directory walk is done.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein r->finfo.filetype = APR_NOFILE;
f4c310fd2555c6faca1f980f00b161eadb089023gstein break;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else if (APR_STATUS_IS_EACCES(rv)) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "access to %s denied", r->uri);
f4c310fd2555c6faca1f980f00b161eadb089023gstein return r->status = HTTP_FORBIDDEN;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else if ((rv != APR_SUCCESS && rv != APR_INCOMPLETE)
f4c310fd2555c6faca1f980f00b161eadb089023gstein || !(r->finfo.valid & APR_FINFO_TYPE)) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* If we hit ENOTDIR, we must have over-optimized, deny
f4c310fd2555c6faca1f980f00b161eadb089023gstein * rather than assume not found.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "access to %s failed", r->uri);
f4c310fd2555c6faca1f980f00b161eadb089023gstein return r->status = HTTP_FORBIDDEN;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else if ((res = check_safe_file(r))) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein r->status = res;
f4c310fd2555c6faca1f980f00b161eadb089023gstein return res;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Fix up the path now if we have a name, and they don't agree
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((r->finfo.valid & APR_FINFO_NAME)
f4c310fd2555c6faca1f980f00b161eadb089023gstein && strcmp(seg_name, r->finfo.name)) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* TODO: provide users an option that an internal/external
f4c310fd2555c6faca1f980f00b161eadb089023gstein * redirect is required here?
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein strcpy(seg_name, r->finfo.name);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (r->finfo.filetype == APR_LNK)
f4c310fd2555c6faca1f980f00b161eadb089023gstein {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Is this an possibly acceptable symlink?
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((res = resolve_symlink(r->filename, &r->finfo,
f4c310fd2555c6faca1f980f00b161eadb089023gstein core_dir->opts, r->pool)) != OK) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Symbolic link not allowed: %s", r->filename);
f4c310fd2555c6faca1f980f00b161eadb089023gstein return r->status = res;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Ok, we are done with the link's info, test the real target
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (r->finfo.filetype == APR_REG) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* That was fun, nothing left for us here
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein break;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else if (r->finfo.filetype != APR_DIR) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "symlink doesn't point to a file or directory: %s",
f4c310fd2555c6faca1f980f00b161eadb089023gstein r->filename);
f4c310fd2555c6faca1f980f00b161eadb089023gstein return r->status = HTTP_FORBIDDEN;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ++seg;
f4c310fd2555c6faca1f980f00b161eadb089023gstein } while (r->finfo.filetype == APR_DIR);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /*
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Now we'll deal with the regexes.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (; sec_idx < num_sec; ++sec_idx) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein entry_config = sec_ent[sec_idx];
f4c310fd2555c6faca1f980f00b161eadb089023gstein entry_core = ap_get_module_config(entry_config, &core_module);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!entry_core->r) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein continue;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!ap_regexec(entry_core->r, r->filename, 0, NULL, REG_NOTEOL)) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein per_dir_defaults = ap_merge_per_dir_configs(r->pool,
f4c310fd2555c6faca1f980f00b161eadb089023gstein per_dir_defaults,
f4c310fd2555c6faca1f980f00b161eadb089023gstein entry_config);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein r->per_dir_config = per_dir_defaults;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* It seems this shouldn't be needed anymore. We translated the symlink above
f4c310fd2555c6faca1f980f00b161eadb089023gstein x into a real resource, and should have died up there. Even if we keep this,
f4c310fd2555c6faca1f980f00b161eadb089023gstein x it needs more thought (maybe an r->file_is_symlink) perhaps it should actually
f4c310fd2555c6faca1f980f00b161eadb089023gstein x happen in file_walk, so we catch more obscure cases in autoindex sub requests, etc.
f4c310fd2555c6faca1f980f00b161eadb089023gstein x
f4c310fd2555c6faca1f980f00b161eadb089023gstein x * Symlink permissions are determined by the parent. If the request is
f4c310fd2555c6faca1f980f00b161eadb089023gstein x * for a directory then applying the symlink test here would use the
f4c310fd2555c6faca1f980f00b161eadb089023gstein x * permissions of the directory as opposed to its parent. Consider a
f4c310fd2555c6faca1f980f00b161eadb089023gstein x * symlink pointing to a dir with a .htaccess disallowing symlinks. If
f4c310fd2555c6faca1f980f00b161eadb089023gstein x * you access /symlink (or /symlink/) you would get a 403 without this
f4c310fd2555c6faca1f980f00b161eadb089023gstein x * APR_DIR test. But if you accessed /symlink/index.html, for example,
f4c310fd2555c6faca1f980f00b161eadb089023gstein x * you would *not* get the 403.
f4c310fd2555c6faca1f980f00b161eadb089023gstein x
f4c310fd2555c6faca1f980f00b161eadb089023gstein x if (r->finfo.filetype != APR_DIR
f4c310fd2555c6faca1f980f00b161eadb089023gstein x && (res = resolve_symlink(r->filename, r->info, ap_allow_options(r), r->pool))) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein x ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
f4c310fd2555c6faca1f980f00b161eadb089023gstein x "Symbolic link not allowed: %s", r->filename);
f4c310fd2555c6faca1f980f00b161eadb089023gstein x return res;
f4c310fd2555c6faca1f980f00b161eadb089023gstein x }
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein return OK; /* 'no excuses' */
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif /* defined REPLACE_PATH_INFO_METHOD */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagsteinAP_DECLARE(int) ap_location_walk(request_rec *r)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein core_server_config *sconf = ap_get_module_config(r->server->module_config,
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm &core_module);
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein ap_conf_vector_t *per_uri_defaults = NULL;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_conf_vector_t **locations = (ap_conf_vector_t **) sconf->sec_url->elts;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_conf_vector_t **loc_done = NULL;
f4c310fd2555c6faca1f980f00b161eadb089023gstein int len, num_loc = sconf->sec_url->nelts;
f4c310fd2555c6faca1f980f00b161eadb089023gstein char *test_location;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_conf_vector_t *this_conf;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_conf_vector_t *entry_config;
f4c310fd2555c6faca1f980f00b161eadb089023gstein core_dir_config *entry_core;
f4c310fd2555c6faca1f980f00b161eadb089023gstein char *entry_uri;
f4c310fd2555c6faca1f980f00b161eadb089023gstein int j;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* No tricks here, there are no <Locations > to parse in this vhost
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!num_loc) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_pool_userdata_set(NULL, "ap_location_walk::dir_conf",
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_pool_cleanup_null, r->pool);
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_pool_userdata_set(NULL, "ap_location_walk::loc_done",
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_pool_cleanup_null, r->pool);
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_pool_userdata_set(NULL, "ap_location_walk::last_uri",
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_pool_cleanup_null, r->pool);
f4c310fd2555c6faca1f980f00b161eadb089023gstein return OK;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_pool_userdata_get((void **)&entry_uri, "ap_location_walk::last_uri", r->pool);
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_pool_userdata_get((void **)&loc_done, "ap_location_walk::loc_done", r->pool);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* If we have an ap_location_walk::last_uri that matches r->uri,
f4c310fd2555c6faca1f980f00b161eadb089023gstein * and the vhost's list of locations hasn't changed,
f4c310fd2555c6faca1f980f00b161eadb089023gstein * we will go through the location_walk entries.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!entry_uri || (loc_done != locations)
f4c310fd2555c6faca1f980f00b161eadb089023gstein || (strcmp(r->uri, entry_uri) != 0))
f4c310fd2555c6faca1f980f00b161eadb089023gstein {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Location and LocationMatch differ on their behaviour w.r.t. multiple
f4c310fd2555c6faca1f980f00b161eadb089023gstein * slashes. Location matches multiple slashes with a single slash,
f4c310fd2555c6faca1f980f00b161eadb089023gstein * LocationMatch doesn't. An exception, for backwards brokenness is
f4c310fd2555c6faca1f980f00b161eadb089023gstein * absoluteURIs... in which case neither match multiple slashes.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (r->uri[0] != '/') {
f4c310fd2555c6faca1f980f00b161eadb089023gstein test_location = r->uri;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else {
f4c310fd2555c6faca1f980f00b161eadb089023gstein test_location = apr_pstrdup(r->pool, r->uri);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_no2slash(test_location);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Go through the location entries, and check for matches. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* we apply the directive sections in some order;
f4c310fd2555c6faca1f980f00b161eadb089023gstein * should really try them with the most general first.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (j = 0; j < num_loc; ++j) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein entry_config = locations[j];
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein entry_core = ap_get_module_config(entry_config, &core_module);
f4c310fd2555c6faca1f980f00b161eadb089023gstein entry_uri = entry_core->d;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein len = strlen(entry_uri);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein this_conf = NULL;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Test the regex, fnmatch or string as appropriate.
f4c310fd2555c6faca1f980f00b161eadb089023gstein * If it's a strcmp, and the <Location > pattern was
f4c310fd2555c6faca1f980f00b161eadb089023gstein * not slash terminated, then this uri must be slash
f4c310fd2555c6faca1f980f00b161eadb089023gstein * terminated (or at the end of the string) to match.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (entry_core->r
f4c310fd2555c6faca1f980f00b161eadb089023gstein ? ap_regexec(entry_core->r, r->uri, 0, NULL, 0)
f4c310fd2555c6faca1f980f00b161eadb089023gstein : (entry_core->d_is_fnmatch
f4c310fd2555c6faca1f980f00b161eadb089023gstein ? apr_fnmatch(entry_uri, test_location, FNM_PATHNAME)
f4c310fd2555c6faca1f980f00b161eadb089023gstein : (strncmp(test_location, entry_uri, len)
f4c310fd2555c6faca1f980f00b161eadb089023gstein || (entry_uri[len - 1] != '/'
f4c310fd2555c6faca1f980f00b161eadb089023gstein && test_location[len] != '/'
f4c310fd2555c6faca1f980f00b161eadb089023gstein && test_location[len] != '\0')))) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein continue;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (per_uri_defaults)
f4c310fd2555c6faca1f980f00b161eadb089023gstein per_uri_defaults = ap_merge_per_dir_configs(r->pool,
f4c310fd2555c6faca1f980f00b161eadb089023gstein per_uri_defaults,
f4c310fd2555c6faca1f980f00b161eadb089023gstein entry_config);
f4c310fd2555c6faca1f980f00b161eadb089023gstein else
f4c310fd2555c6faca1f980f00b161eadb089023gstein per_uri_defaults = entry_config;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Set aside this walk result, in case we end up back here with
f4c310fd2555c6faca1f980f00b161eadb089023gstein * the same uri again.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_pool_userdata_set(per_uri_defaults, "ap_location_walk::dir_conf",
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_pool_cleanup_null, r->pool);
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_pool_userdata_set(locations, "ap_location_walk::loc_done",
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_pool_cleanup_null, r->pool);
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_pool_userdata_set(r->uri, "ap_location_walk::last_uri",
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_pool_cleanup_null, r->pool);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Well this looks familiar! If our end-result (dir_merged) hasn't
f80b9e9d38dff8bc3f51406475adb99d7fe888cegstein * changed, we have nothing to do :) This test really doesn't play well
f80b9e9d38dff8bc3f51406475adb99d7fe888cegstein * with other walkers who reset to the vhost default, but we will
f80b9e9d38dff8bc3f51406475adb99d7fe888cegstein * leave this escape in for simpler modules.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_pool_userdata_get((void **)&per_uri_defaults, "ap_location_walk::dir_merged",
f4c310fd2555c6faca1f980f00b161eadb089023gstein r->pool);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (per_uri_defaults == r->per_dir_config)
f4c310fd2555c6faca1f980f00b161eadb089023gstein return OK;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Well, we will need our per_uri_defaults from the last location walk.
f4c310fd2555c6faca1f980f00b161eadb089023gstein * after all.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_pool_userdata_get((void **)&per_uri_defaults, "ap_location_walk::dir_conf",
f4c310fd2555c6faca1f980f00b161eadb089023gstein r->pool);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Merge our per_uri_defaults preconstruct onto the r->per_dir_configs,
f4c310fd2555c6faca1f980f00b161eadb089023gstein * and note the end result for later optimization.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (per_uri_defaults)
f4c310fd2555c6faca1f980f00b161eadb089023gstein r->per_dir_config = ap_merge_per_dir_configs(r->pool,
f4c310fd2555c6faca1f980f00b161eadb089023gstein r->per_dir_config,
f4c310fd2555c6faca1f980f00b161eadb089023gstein per_uri_defaults);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_pool_userdata_set(r->per_dir_config, "ap_location_walk::dir_merged",
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_pool_cleanup_null, r->pool);
f4c310fd2555c6faca1f980f00b161eadb089023gstein return OK;
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE(int) ap_file_walk(request_rec *r)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein core_dir_config *conf = ap_get_module_config(r->per_dir_config,
f4c310fd2555c6faca1f980f00b161eadb089023gstein &core_module);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_conf_vector_t *per_dir_defaults = r->per_dir_config;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_conf_vector_t **file = (ap_conf_vector_t **) conf->sec_file->elts;
f4c310fd2555c6faca1f980f00b161eadb089023gstein int num_files = conf->sec_file->nelts;
f4c310fd2555c6faca1f980f00b161eadb089023gstein char *test_file;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* get the basename */
f4c310fd2555c6faca1f980f00b161eadb089023gstein test_file = strrchr(r->filename, '/');
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (test_file == NULL) {
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm test_file = r->filename;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ++test_file;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Go through the file entries, and check for matches. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (num_files) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_conf_vector_t *this_conf;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_conf_vector_t *entry_config;
f4c310fd2555c6faca1f980f00b161eadb089023gstein core_dir_config *entry_core;
f4c310fd2555c6faca1f980f00b161eadb089023gstein char *entry_file;
f4c310fd2555c6faca1f980f00b161eadb089023gstein int j;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* we apply the directive sections in some order;
f4c310fd2555c6faca1f980f00b161eadb089023gstein * should really try them with the most general first.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (j = 0; j < num_files; ++j) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein entry_config = file[j];
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein entry_core = ap_get_module_config(entry_config, &core_module);
f4c310fd2555c6faca1f980f00b161eadb089023gstein entry_file = entry_core->d;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein this_conf = NULL;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (entry_core->r) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!ap_regexec(entry_core->r, test_file, 0, NULL, 0))
f4c310fd2555c6faca1f980f00b161eadb089023gstein this_conf = entry_config;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else if (entry_core->d_is_fnmatch) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!apr_fnmatch(entry_file, test_file, FNM_PATHNAME)) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein this_conf = entry_config;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else if (!strcmp(test_file, entry_file)) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein this_conf = entry_config;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (this_conf)
f4c310fd2555c6faca1f980f00b161eadb089023gstein per_dir_defaults = ap_merge_per_dir_configs(r->pool,
f4c310fd2555c6faca1f980f00b161eadb089023gstein per_dir_defaults,
f4c310fd2555c6faca1f980f00b161eadb089023gstein this_conf);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein r->per_dir_config = per_dir_defaults;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein return OK;
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein/*****************************************************************
f4c310fd2555c6faca1f980f00b161eadb089023gstein *
f4c310fd2555c6faca1f980f00b161eadb089023gstein * The sub_request mechanism.
f4c310fd2555c6faca1f980f00b161eadb089023gstein *
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Fns to look up a relative URI from, e.g., a map file or SSI document.
f4c310fd2555c6faca1f980f00b161eadb089023gstein * These do all access checks, etc., but don't actually run the transaction
f4c310fd2555c6faca1f980f00b161eadb089023gstein * ... use run_sub_req below for that. Also, be sure to use destroy_sub_req
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein * as appropriate if you're likely to be creating more than a few of these.
f4c310fd2555c6faca1f980f00b161eadb089023gstein * (An early Apache version didn't destroy the sub_reqs used in directory
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein * indexing. The result, when indexing a directory with 800-odd files in
f4c310fd2555c6faca1f980f00b161eadb089023gstein * it, was massively excessive storage allocation).
f4c310fd2555c6faca1f980f00b161eadb089023gstein *
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein * Note more manipulation of protocol-specific vars in the request
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein * structure...
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic request_rec *make_sub_request(const request_rec *r)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_pool_t *rrp;
f4c310fd2555c6faca1f980f00b161eadb089023gstein request_rec *rr;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_pool_create(&rrp, r->pool);
f4c310fd2555c6faca1f980f00b161eadb089023gstein rr = apr_pcalloc(rrp, sizeof(request_rec));
f4c310fd2555c6faca1f980f00b161eadb089023gstein rr->pool = rrp;
f4c310fd2555c6faca1f980f00b161eadb089023gstein return rr;
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein}
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic void fill_in_sub_req_vars(request_rec *rnew, const request_rec *r,
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_filter_t *next_filter)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein rnew->hostname = r->hostname;
f4c310fd2555c6faca1f980f00b161eadb089023gstein rnew->request_time = r->request_time;
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein rnew->connection = r->connection;
f4c310fd2555c6faca1f980f00b161eadb089023gstein rnew->server = r->server;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein rnew->request_config = ap_create_request_config(rnew->pool);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein rnew->htaccess = r->htaccess;
f4c310fd2555c6faca1f980f00b161eadb089023gstein rnew->allowed_methods = ap_make_method_list(rnew->pool, 2);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* make a copy of the allowed-methods list */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_copy_method_list(rnew->allowed_methods, r->allowed_methods);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* start with the same set of output filters */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (next_filter) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein rnew->output_filters = next_filter;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else {
f4c310fd2555c6faca1f980f00b161eadb089023gstein rnew->output_filters = r->output_filters;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_add_output_filter("SUBREQ_CORE", NULL, rnew, rnew->connection);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* no input filters for a subrequest */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_set_sub_req_protocol(rnew, r);
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_CORE_DECLARE_NONSTD(apr_status_t) ap_sub_req_output_filter(ap_filter_t *f,
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_bucket_brigade *bb)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_bucket *e = APR_BRIGADE_LAST(bb);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (APR_BUCKET_IS_EOS(e)) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_bucket_delete(e);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein return ap_pass_brigade(f->next, bb);
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE(int) ap_some_auth_required(request_rec *r)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Is there a require line configured for the type of *this* req? */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein const apr_array_header_t *reqs_arr = ap_requires(r);
f4c310fd2555c6faca1f980f00b161eadb089023gstein require_line *reqs;
f4c310fd2555c6faca1f980f00b161eadb089023gstein int i;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!reqs_arr)
f4c310fd2555c6faca1f980f00b161eadb089023gstein return 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein reqs = (require_line *) reqs_arr->elts;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (i = 0; i < reqs_arr->nelts; ++i)
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (reqs[i].method_mask & (AP_METHOD_BIT << r->method_number))
f4c310fd2555c6faca1f980f00b161eadb089023gstein return 1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein return 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE(request_rec *) ap_sub_req_method_uri(const char *method,
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *new_file,
f4c310fd2555c6faca1f980f00b161eadb089023gstein const request_rec *r,
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_filter_t *next_filter)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein request_rec *rnew;
f4c310fd2555c6faca1f980f00b161eadb089023gstein int res;
f4c310fd2555c6faca1f980f00b161eadb089023gstein char *udir;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm
f4c310fd2555c6faca1f980f00b161eadb089023gstein rnew = make_sub_request(r);
f4c310fd2555c6faca1f980f00b161eadb089023gstein fill_in_sub_req_vars(rnew, r, next_filter);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein rnew->per_dir_config = r->server->lookup_defaults;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* We have to run this after ap_set_sub_req_protocol, or the r->main
f4c310fd2555c6faca1f980f00b161eadb089023gstein * pointer won't be setup
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_run_create_request(rnew);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* would be nicer to pass "method" to ap_set_sub_req_protocol */
f4c310fd2555c6faca1f980f00b161eadb089023gstein rnew->method = method;
f4c310fd2555c6faca1f980f00b161eadb089023gstein rnew->method_number = ap_method_number_of(method);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (new_file[0] == '/')
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_parse_uri(rnew, new_file);
f4c310fd2555c6faca1f980f00b161eadb089023gstein else {
f4c310fd2555c6faca1f980f00b161eadb089023gstein udir = ap_make_dirstr_parent(rnew->pool, r->uri);
f4c310fd2555c6faca1f980f00b161eadb089023gstein udir = ap_escape_uri(rnew->pool, udir); /* re-escape it */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_parse_uri(rnew, ap_make_full_path(rnew->pool, udir, new_file));
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((res = ap_process_request_internal(rnew))) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein rnew->status = res;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein return rnew;
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE(request_rec *) ap_sub_req_lookup_uri(const char *new_file,
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein const request_rec *r,
f94aab38f6ee899f463f0118ea395291f7c5b4cegstein ap_filter_t *next_filter)
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein{
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein return ap_sub_req_method_uri("GET", new_file, r, next_filter);
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein}
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gsteinAP_DECLARE(request_rec *) ap_sub_req_lookup_dirent(const apr_finfo_t *dirent,
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein const request_rec *r,
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_filter_t *next_filter)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein request_rec *rnew;
f4c310fd2555c6faca1f980f00b161eadb089023gstein int res;
f4c310fd2555c6faca1f980f00b161eadb089023gstein char *fdir;
f4c310fd2555c6faca1f980f00b161eadb089023gstein char *udir;
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein rnew = make_sub_request(r);
f4c310fd2555c6faca1f980f00b161eadb089023gstein fill_in_sub_req_vars(rnew, r, next_filter);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f94aab38f6ee899f463f0118ea395291f7c5b4cegstein rnew->chunked = r->chunked;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f94aab38f6ee899f463f0118ea395291f7c5b4cegstein /* We have to run this after ap_set_sub_req_protocol, or the r->main
f4c310fd2555c6faca1f980f00b161eadb089023gstein * pointer won't be setup
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_run_create_request(rnew);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein fdir = ap_make_dirstr_parent(rnew->pool, r->filename);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /*
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Special case: we are looking at a relative lookup in the same directory.
f4c310fd2555c6faca1f980f00b161eadb089023gstein * That means we won't have to redo directory_walk, and we may
f4c310fd2555c6faca1f980f00b161eadb089023gstein * not even have to redo access checks.
866b521be8a30b2798ad3c3b73de5e965edd7c2fgstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
866b521be8a30b2798ad3c3b73de5e965edd7c2fgstein udir = ap_make_dirstr_parent(rnew->pool, r->uri);
866b521be8a30b2798ad3c3b73de5e965edd7c2fgstein
866b521be8a30b2798ad3c3b73de5e965edd7c2fgstein /* This is 100% safe, since dirent->name just came from the filesystem */
f4c310fd2555c6faca1f980f00b161eadb089023gstein rnew->uri = ap_make_full_path(rnew->pool, udir, dirent->name);
f4c310fd2555c6faca1f980f00b161eadb089023gstein rnew->filename = ap_make_full_path(rnew->pool, fdir, dirent->name);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (r->canonical_filename == r->filename)
866b521be8a30b2798ad3c3b73de5e965edd7c2fgstein rnew->canonical_filename = rnew->filename;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_parse_uri(rnew, rnew->uri); /* fill in parsed_uri values */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein#if 0 /* XXX When this is reenabled, the cache triggers need to be set to faux
f4c310fd2555c6faca1f980f00b161eadb089023gstein * dir_walk/file_walk values.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein rnew->per_dir_config = r->per_dir_config;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((dirent->valid & APR_FINFO_MIN) != APR_FINFO_MIN) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /*
f4c310fd2555c6faca1f980f00b161eadb089023gstein * apr_dir_read isn't very complete on this platform, so
f4c310fd2555c6faca1f980f00b161eadb089023gstein * we need another apr_lstat (or simply apr_stat if we allow
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * all symlinks here.) If this is an APR_LNK that resolves
f4c310fd2555c6faca1f980f00b161eadb089023gstein * to an APR_DIR, then we will rerun everything anyways...
f4c310fd2555c6faca1f980f00b161eadb089023gstein * this should be safe.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_status_t rv;
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (ap_allow_options(rnew) & OPT_SYM_LINKS) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (((rv = apr_stat(&rnew->finfo, rnew->filename,
f4c310fd2555c6faca1f980f00b161eadb089023gstein APR_FINFO_MIN, rnew->pool)) != APR_SUCCESS)
f4c310fd2555c6faca1f980f00b161eadb089023gstein && (rv != APR_INCOMPLETE))
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm rnew->finfo.filetype = 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (((rv = apr_lstat(&rnew->finfo, rnew->filename,
f4c310fd2555c6faca1f980f00b161eadb089023gstein APR_FINFO_MIN, rnew->pool)) != APR_SUCCESS)
f4c310fd2555c6faca1f980f00b161eadb089023gstein && (rv != APR_INCOMPLETE))
f4c310fd2555c6faca1f980f00b161eadb089023gstein rnew->finfo.filetype = 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else {
f4c310fd2555c6faca1f980f00b161eadb089023gstein memcpy (&rnew->finfo, dirent, sizeof(apr_finfo_t));
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((res = check_safe_file(rnew))) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein rnew->status = res;
f4c310fd2555c6faca1f980f00b161eadb089023gstein return rnew;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (rnew->finfo.filetype == APR_LNK
f4c310fd2555c6faca1f980f00b161eadb089023gstein && (res = resolve_symlink(rnew->filename, &rnew->finfo,
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_allow_options(rnew), rnew->pool)) != OK) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, rnew,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Symbolic link not allowed: %s", rnew->filename);
f4c310fd2555c6faca1f980f00b161eadb089023gstein rnew->status = res;
f4c310fd2555c6faca1f980f00b161eadb089023gstein return rnew;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /*
252e2478cb56afb5ca8585b50bc2ffb780d2efb6gstein * no matter what, if it's a subdirectory, we need to re-run
f4c310fd2555c6faca1f980f00b161eadb089023gstein * directory_walk
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (rnew->finfo.filetype == APR_DIR) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!(res = ap_directory_walk(rnew)))
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!(res = ap_file_walk(rnew)))
f4c310fd2555c6faca1f980f00b161eadb089023gstein res = ap_location_walk(rnew);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else if (rnew->finfo.filetype == APR_REG || !rnew->finfo.filetype) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /*
f4c310fd2555c6faca1f980f00b161eadb089023gstein * do a file_walk, if it doesn't change the per_dir_config then
f4c310fd2555c6faca1f980f00b161eadb089023gstein * we know that we don't have to redo all the access checks
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ( !(res = ap_file_walk(rnew))
f4c310fd2555c6faca1f980f00b161eadb089023gstein && !(res = ap_location_walk(rnew))
f4c310fd2555c6faca1f980f00b161eadb089023gstein && (rnew->per_dir_config == r->per_dir_config))
f4c310fd2555c6faca1f980f00b161eadb089023gstein {
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ( (res = ap_run_type_checker(rnew))
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm || (res = ap_run_fixups(rnew))) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein rnew->status = res;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein return rnew;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((res = ap_process_request_internal(rnew))) {
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm rnew->status = res;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein return rnew;
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE(request_rec *) ap_sub_req_lookup_file(const char *new_file,
f4c310fd2555c6faca1f980f00b161eadb089023gstein const request_rec *r,
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_filter_t *next_filter)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein request_rec *rnew;
f4c310fd2555c6faca1f980f00b161eadb089023gstein int res;
f4c310fd2555c6faca1f980f00b161eadb089023gstein char *fdir;
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_size_t fdirlen;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein rnew = make_sub_request(r);
f4c310fd2555c6faca1f980f00b161eadb089023gstein fill_in_sub_req_vars(rnew, r, next_filter);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein rnew->chunked = r->chunked;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* We have to run this after ap_set_sub_req_protocol, or the r->main
f4c310fd2555c6faca1f980f00b161eadb089023gstein * pointer won't be setup
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_run_create_request(rnew);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein fdir = ap_make_dirstr_parent(rnew->pool, r->filename);
f4c310fd2555c6faca1f980f00b161eadb089023gstein fdirlen = strlen(fdir);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Translate r->filename
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (apr_filepath_merge(&rnew->filename, fdir, new_file,
f4c310fd2555c6faca1f980f00b161eadb089023gstein APR_FILEPATH_TRUENAME, rnew->pool) != APR_SUCCESS) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein rnew->status = HTTP_FORBIDDEN;
f4c310fd2555c6faca1f980f00b161eadb089023gstein return rnew;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /*
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Check for a special case... if there are no '/' characters in new_file
f4c310fd2555c6faca1f980f00b161eadb089023gstein * at all, and the path was the same, then we are looking at a relative
f4c310fd2555c6faca1f980f00b161eadb089023gstein * lookup in the same directory. That means we won't have to redo
f4c310fd2555c6faca1f980f00b161eadb089023gstein * directory_walk, and we may not even have to redo access checks.
f4c310fd2555c6faca1f980f00b161eadb089023gstein * ### Someday we don't even have to redo the entire directory walk,
f4c310fd2555c6faca1f980f00b161eadb089023gstein * either, if the base paths match, we can pick up where we leave off.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (strncmp(rnew->filename, fdir, fdirlen) == 0
f4c310fd2555c6faca1f980f00b161eadb089023gstein && rnew->filename[fdirlen]
f4c310fd2555c6faca1f980f00b161eadb089023gstein && ap_strchr_c(rnew->filename + fdirlen, '/') == NULL)
f4c310fd2555c6faca1f980f00b161eadb089023gstein {
f4c310fd2555c6faca1f980f00b161eadb089023gstein char *udir = ap_make_dirstr_parent(rnew->pool, r->uri);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein rnew->uri = ap_make_full_path(rnew->pool, udir, new_file);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_parse_uri(rnew, rnew->uri); /* fill in parsed_uri values */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein#if 0 /* XXX When this is reenabled, the cache triggers need to be set to faux
f4c310fd2555c6faca1f980f00b161eadb089023gstein * dir_walk/file_walk values.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein rnew->per_dir_config = r->per_dir_config;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /*
f4c310fd2555c6faca1f980f00b161eadb089023gstein * If this is an APR_LNK that resolves to an APR_DIR, then
f4c310fd2555c6faca1f980f00b161eadb089023gstein * we will rerun everything anyways... this should be safe.
f39230a531b23d94f86a087963299bbe2e431a4agstein */
f39230a531b23d94f86a087963299bbe2e431a4agstein if (ap_allow_options(rnew) & OPT_SYM_LINKS) {
50bd75672ef114fb839dd9643c192b432fdf344cgstein apr_status_t rv;
50bd75672ef114fb839dd9643c192b432fdf344cgstein if (((rv = apr_stat(&rnew->finfo, rnew->filename,
50bd75672ef114fb839dd9643c192b432fdf344cgstein APR_FINFO_MIN, rnew->pool)) != APR_SUCCESS)
50bd75672ef114fb839dd9643c192b432fdf344cgstein && (rv != APR_INCOMPLETE))
50bd75672ef114fb839dd9643c192b432fdf344cgstein rnew->finfo.filetype = 0;
50bd75672ef114fb839dd9643c192b432fdf344cgstein }
50bd75672ef114fb839dd9643c192b432fdf344cgstein else {
50bd75672ef114fb839dd9643c192b432fdf344cgstein apr_status_t rv;
50bd75672ef114fb839dd9643c192b432fdf344cgstein if (((rv = apr_lstat(&rnew->finfo, rnew->filename,
50bd75672ef114fb839dd9643c192b432fdf344cgstein APR_FINFO_MIN, rnew->pool)) != APR_SUCCESS)
50bd75672ef114fb839dd9643c192b432fdf344cgstein && (rv != APR_INCOMPLETE))
50bd75672ef114fb839dd9643c192b432fdf344cgstein rnew->finfo.filetype = 0;
50bd75672ef114fb839dd9643c192b432fdf344cgstein }
50bd75672ef114fb839dd9643c192b432fdf344cgstein
50bd75672ef114fb839dd9643c192b432fdf344cgstein if ((res = check_safe_file(rnew))) {
50bd75672ef114fb839dd9643c192b432fdf344cgstein rnew->status = res;
50bd75672ef114fb839dd9643c192b432fdf344cgstein return rnew;
50bd75672ef114fb839dd9643c192b432fdf344cgstein }
50bd75672ef114fb839dd9643c192b432fdf344cgstein
50bd75672ef114fb839dd9643c192b432fdf344cgstein if (rnew->finfo.filetype == APR_LNK
50bd75672ef114fb839dd9643c192b432fdf344cgstein && (res = resolve_symlink(rnew->filename, &rnew->finfo,
f39230a531b23d94f86a087963299bbe2e431a4agstein ap_allow_options(rnew), rnew->pool)) != OK) {
50bd75672ef114fb839dd9643c192b432fdf344cgstein ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, rnew,
f39230a531b23d94f86a087963299bbe2e431a4agstein "Symbolic link not allowed: %s", rnew->filename);
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein rnew->status = res;
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein return rnew;
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein }
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein /*
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein * no matter what, if it's a subdirectory, we need to re-run
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein * directory_walk
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein */
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein if (rnew->finfo.filetype == APR_DIR) {
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein if (!(res = ap_directory_walk(rnew)))
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein if (!(res = ap_file_walk(rnew)))
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein res = ap_location_walk(rnew);
f39230a531b23d94f86a087963299bbe2e431a4agstein }
f39230a531b23d94f86a087963299bbe2e431a4agstein else if (rnew->finfo.filetype == APR_REG || !rnew->finfo.filetype) {
f39230a531b23d94f86a087963299bbe2e431a4agstein /*
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein * do a file_walk, if it doesn't change the per_dir_config then
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein * we know that we don't have to redo all the access checks
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein */
f39230a531b23d94f86a087963299bbe2e431a4agstein if ( !(res = ap_file_walk(rnew))
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein && !(res = ap_location_walk(rnew))
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein && (rnew->per_dir_config == r->per_dir_config))
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein {
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein if ( (res = ap_run_type_checker(rnew))
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein || (res = ap_run_fixups(rnew))) {
f39230a531b23d94f86a087963299bbe2e431a4agstein rnew->status = res;
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein }
f39230a531b23d94f86a087963299bbe2e431a4agstein return rnew;
f39230a531b23d94f86a087963299bbe2e431a4agstein }
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein }
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein else {
7281ea331999debdc337b02ce37a3169e0e033a2gstein ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, rnew,
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein "symlink doesn't point to a file or directory: %s",
f4c310fd2555c6faca1f980f00b161eadb089023gstein r->filename);
f4c310fd2555c6faca1f980f00b161eadb089023gstein res = HTTP_FORBIDDEN;
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein }
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein#endif
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein }
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein else {
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein /* XXX: @@@: What should be done with the parsed_uri values? */
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein ap_parse_uri(rnew, new_file); /* fill in parsed_uri values */
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein /*
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein * XXX: this should be set properly like it is in the same-dir case
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein * but it's actually sometimes to impossible to do it... because the
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein * file may not have a uri associated with it -djg
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein */
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein rnew->uri = "INTERNALLY GENERATED file-relative req";
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein#if 0 /* XXX When this is reenabled, the cache triggers need to be set to faux
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein * dir_walk/file_walk values.
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein */
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein rnew->per_dir_config = r->server->lookup_defaults;
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein res = ap_directory_walk(rnew);
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein if (!res) {
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein res = ap_file_walk(rnew);
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein }
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein#endif
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein }
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein if ((res = ap_process_request_internal(rnew))) {
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein rnew->status = res;
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein }
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein return rnew;
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein}
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gsteinAP_DECLARE(int) ap_run_sub_req(request_rec *r)
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein{
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein int retval;
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein retval = ap_invoke_handler(r);
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein ap_finalize_sub_req_protocol(r);
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein return retval;
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein}
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gsteinAP_DECLARE(void) ap_destroy_sub_req(request_rec *r)
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein{
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein /* Reclaim the space */
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein apr_pool_destroy(r->pool);
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein}
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein/*
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein * Function to set the r->mtime field to the specified value if it's later
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein * than what's already there.
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein */
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gsteinAP_DECLARE(void) ap_update_mtime(request_rec *r, apr_time_t dependency_mtime)
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein{
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein if (r->mtime < dependency_mtime) {
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein r->mtime = dependency_mtime;
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein }
50bd75672ef114fb839dd9643c192b432fdf344cgstein}
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein/*
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein * Is it the initial main request, which we only get *once* per HTTP request?
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein */
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gsteinAP_DECLARE(int) ap_is_initial_req(request_rec *r)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein return
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein (r->main == NULL) /* otherwise, this is a sub-request */
4d0b0b6d8341c5e54b2081665fc91b4e4f781753gstein &&
f4c310fd2555c6faca1f980f00b161eadb089023gstein (r->prev == NULL); /* otherwise, this is an internal redirect */
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein}
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein