842ae4bd224140319ae7feec1872b93dfd491143fielding/* Licensed to the Apache Software Foundation (ASF) under one or more
842ae4bd224140319ae7feec1872b93dfd491143fielding * contributor license agreements. See the NOTICE file distributed with
842ae4bd224140319ae7feec1872b93dfd491143fielding * this work for additional information regarding copyright ownership.
842ae4bd224140319ae7feec1872b93dfd491143fielding * The ASF licenses this file to You under the Apache License, Version 2.0
842ae4bd224140319ae7feec1872b93dfd491143fielding * (the "License"); you may not use this file except in compliance with
842ae4bd224140319ae7feec1872b93dfd491143fielding * the License. You may obtain a copy of the License at
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * http://www.apache.org/licenses/LICENSE-2.0
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * Unless required by applicable law or agreed to in writing, software
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * distributed under the License is distributed on an "AS IS" BASIS,
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * See the License for the specific language governing permissions and
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * limitations under the License.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb/*
9d129b55f5a43abf43865c6b0eb6dd19bc22aba8ianh * @file request.c
9d129b55f5a43abf43865c6b0eb6dd19bc22aba8ianh * @brief functions to get and process requests
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *
9d129b55f5a43abf43865c6b0eb6dd19bc22aba8ianh * @author Rob McCool 3/21/93
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Thoroughly revamped by rst for Apache. NB this file reads
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * best from the bottom up.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "apr_strings.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "apr_file_io.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "apr_fnmatch.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#define APR_WANT_STRFUNC
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "apr_want.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "ap_config.h"
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd#include "ap_provider.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "httpd.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "http_config.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "http_request.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "http_core.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "http_protocol.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "http_log.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "http_main.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "util_filter.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "util_charset.h"
f888346b48f5e5b5e3f0a47dedb8cefd2759a4e2gregames#include "util_script.h"
750d12c59545dbbac70390988de94f7e901b08f2niq#include "ap_expr.h"
82632a19f2f9c346fee2b28a65920ba9737b3973minfrin#include "mod_request.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "mod_core.h"
db455cbc662c98dbbf53175393c50086ff63370cchrisd#include "mod_auth.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#if APR_HAVE_STDARG_H
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include <stdarg.h>
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#endif
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
7184de27ec1d62a83c41cdeac0953ca9fd661e8csf/* we know core's module_index is 0 */
7184de27ec1d62a83c41cdeac0953ca9fd661e8csf#undef APLOG_MODULE_INDEX
7184de27ec1d62a83c41cdeac0953ca9fd661e8csf#define APLOG_MODULE_INDEX AP_CORE_MODULE_INDEX
36ef8f77bffe75d1aa327882be1b5bdbe2ff567asf
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbAPR_HOOK_STRUCT(
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz APR_HOOK_LINK(translate_name)
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz APR_HOOK_LINK(map_to_storage)
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz APR_HOOK_LINK(check_user_id)
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz APR_HOOK_LINK(fixups)
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz APR_HOOK_LINK(type_checker)
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz APR_HOOK_LINK(access_checker)
18b5268e013574026b2503b1641baf3299045f45sf APR_HOOK_LINK(access_checker_ex)
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz APR_HOOK_LINK(auth_checker)
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz APR_HOOK_LINK(insert_filter)
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz APR_HOOK_LINK(create_request)
60a765cccbd3f3b5997b65b0034220c79f78369etrawick APR_HOOK_LINK(post_perdir_config)
f4ca9f6f002fece336168a16355434ca966f96a9trawick APR_HOOK_LINK(dirwalk_stat)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbAP_IMPLEMENT_HOOK_RUN_FIRST(int,translate_name,
4f9c22c4f27571d54197be9674e1fc0d528192aestriker (request_rec *r), (r), DECLINED)
a2a0abd88b19e042a3eb2a9fa1702c25ad51303dwroweAP_IMPLEMENT_HOOK_RUN_FIRST(int,map_to_storage,
4f9c22c4f27571d54197be9674e1fc0d528192aestriker (request_rec *r), (r), DECLINED)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbAP_IMPLEMENT_HOOK_RUN_FIRST(int,check_user_id,
4f9c22c4f27571d54197be9674e1fc0d528192aestriker (request_rec *r), (r), DECLINED)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbAP_IMPLEMENT_HOOK_RUN_ALL(int,fixups,
4f9c22c4f27571d54197be9674e1fc0d528192aestriker (request_rec *r), (r), OK, DECLINED)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbAP_IMPLEMENT_HOOK_RUN_FIRST(int,type_checker,
4f9c22c4f27571d54197be9674e1fc0d528192aestriker (request_rec *r), (r), DECLINED)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbAP_IMPLEMENT_HOOK_RUN_ALL(int,access_checker,
4f9c22c4f27571d54197be9674e1fc0d528192aestriker (request_rec *r), (r), OK, DECLINED)
18b5268e013574026b2503b1641baf3299045f45sfAP_IMPLEMENT_HOOK_RUN_FIRST(int,access_checker_ex,
18b5268e013574026b2503b1641baf3299045f45sf (request_rec *r), (r), DECLINED)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbAP_IMPLEMENT_HOOK_RUN_FIRST(int,auth_checker,
4f9c22c4f27571d54197be9674e1fc0d528192aestriker (request_rec *r), (r), DECLINED)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbAP_IMPLEMENT_HOOK_VOID(insert_filter, (request_rec *r), (r))
4f9c22c4f27571d54197be9674e1fc0d528192aestrikerAP_IMPLEMENT_HOOK_RUN_ALL(int, create_request,
4f9c22c4f27571d54197be9674e1fc0d528192aestriker (request_rec *r), (r), OK, DECLINED)
60a765cccbd3f3b5997b65b0034220c79f78369etrawickAP_IMPLEMENT_HOOK_RUN_ALL(int, post_perdir_config,
60a765cccbd3f3b5997b65b0034220c79f78369etrawick (request_rec *r), (r), OK, DECLINED)
f4ca9f6f002fece336168a16355434ca966f96a9trawickAP_IMPLEMENT_HOOK_RUN_FIRST(apr_status_t,dirwalk_stat,
f4ca9f6f002fece336168a16355434ca966f96a9trawick (apr_finfo_t *finfo, request_rec *r, apr_int32_t wanted),
f4ca9f6f002fece336168a16355434ca966f96a9trawick (finfo, r, wanted), AP_DECLINED)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisdstatic int auth_internal_per_conf = 0;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisdstatic int auth_internal_per_conf_hooks = 0;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisdstatic int auth_internal_per_conf_providers = 0;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
963f8b44ac95132458ea3b6aaa8ebc135188e473takashistatic int decl_die(int status, const char *phase, request_rec *r)
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe{
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if (status == DECLINED) {
185aa71728867671e105178b4c66fbc22b65ae26sf ap_log_rerror(APLOG_MARK, APLOG_CRIT, 0, r, APLOGNO(00025)
c2cf53a40a9814eb91db2cdf820f97d943f21628coar "configuration error: couldn't %s: %s", phase, r->uri);
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe return HTTP_INTERNAL_SERVER_ERROR;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar else {
4760b58cc9fe170e4ad4648ed4ff7a422a2cef38sf ap_log_rerror(APLOG_MARK, APLOG_TRACE3, 0, r,
4760b58cc9fe170e4ad4648ed4ff7a422a2cef38sf "auth phase '%s' gave status %d: %s", phase,
4760b58cc9fe170e4ad4648ed4ff7a422a2cef38sf status, r->uri);
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe return status;
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe}
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe/* This is the master logic for processing requests. Do NOT duplicate
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe * this logic elsewhere, or the security model will be broken by future
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe * API changes. Each phase must be individually optimized to pick up
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe * redundant/duplicate calls by subrequests, and redirects.
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe */
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewroweAP_DECLARE(int) ap_process_request_internal(request_rec *r)
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe{
3e392a5afd51526de3cb15d57ee46d8cb160ae65gregames int file_req = (r->main && r->filename);
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe int access_status;
efd83d1dd1a25688a3093c5a542ae16bacef62ddsf core_dir_config *d;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe /* Ignore embedded %2F's in path for proxy requests */
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if (!r->proxyreq && r->parsed_uri.path) {
7184de27ec1d62a83c41cdeac0953ca9fd661e8csf d = ap_get_core_module_config(r->per_dir_config);
8419e6f8bff1a3617933f3ba760d2bdec7442f44coar if (d->allow_encoded_slashes) {
3770ed746d69c7a4111cba9966169bd5d7a509a6poirier access_status = ap_unescape_url_keep2f(r->parsed_uri.path, d->decode_encoded_slashes);
8419e6f8bff1a3617933f3ba760d2bdec7442f44coar }
8419e6f8bff1a3617933f3ba760d2bdec7442f44coar else {
8419e6f8bff1a3617933f3ba760d2bdec7442f44coar access_status = ap_unescape_url(r->parsed_uri.path);
8419e6f8bff1a3617933f3ba760d2bdec7442f44coar }
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz if (access_status) {
2a6e98ba4ffa30ded5d8831664c5cb2a170a56b6coar if (access_status == HTTP_NOT_FOUND) {
8419e6f8bff1a3617933f3ba760d2bdec7442f44coar if (! d->allow_encoded_slashes) {
185aa71728867671e105178b4c66fbc22b65ae26sf ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, APLOGNO(00026)
8419e6f8bff1a3617933f3ba760d2bdec7442f44coar "found %%2f (encoded '/') in URI "
8419e6f8bff1a3617933f3ba760d2bdec7442f44coar "(decoded='%s'), returning 404",
8419e6f8bff1a3617933f3ba760d2bdec7442f44coar r->parsed_uri.path);
8419e6f8bff1a3617933f3ba760d2bdec7442f44coar }
2a6e98ba4ffa30ded5d8831664c5cb2a170a56b6coar }
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz return access_status;
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe ap_getparents(r->uri); /* OK --- shrinking transformations... */
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
4f9c22c4f27571d54197be9674e1fc0d528192aestriker /* All file subrequests are a huge pain... they cannot bubble through the
4f9c22c4f27571d54197be9674e1fc0d528192aestriker * next several steps. Only file subrequests are allowed an empty uri,
3e392a5afd51526de3cb15d57ee46d8cb160ae65gregames * otherwise let translate_name kill the request.
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe */
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar if (!file_req) {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe if ((access_status = ap_location_walk(r))) {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe return access_status;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe }
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf if ((access_status = ap_if_walk(r))) {
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf return access_status;
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
bd3f5647b96d378d9c75c954e3f13582af32c643sf /* Don't set per-dir loglevel if LogLevelOverride is set */
bd3f5647b96d378d9c75c954e3f13582af32c643sf if (!r->connection->log) {
bd3f5647b96d378d9c75c954e3f13582af32c643sf d = ap_get_core_module_config(r->per_dir_config);
bd3f5647b96d378d9c75c954e3f13582af32c643sf if (d->log)
bd3f5647b96d378d9c75c954e3f13582af32c643sf r->log = d->log;
efd83d1dd1a25688a3093c5a542ae16bacef62ddsf }
efd83d1dd1a25688a3093c5a542ae16bacef62ddsf
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe if ((access_status = ap_run_translate_name(r))) {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe return decl_die(access_status, "translate", r);
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
4f9c22c4f27571d54197be9674e1fc0d528192aestriker /* Reset to the server default config prior to running map_to_storage
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe */
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe r->per_dir_config = r->server->lookup_defaults;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe
c2cf53a40a9814eb91db2cdf820f97d943f21628coar if ((access_status = ap_run_map_to_storage(r))) {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe /* This request wasn't in storage (e.g. TRACE) */
4775dfc34c90fada8c7c4d6a57ed8a3114d55c2dtrawick return access_status;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
11a0edf478ca9c59d80bf73491d89cf019259feeniq /* Rerun the location walk, which overrides any map_to_storage config.
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe */
11a0edf478ca9c59d80bf73491d89cf019259feeniq if ((access_status = ap_location_walk(r))) {
11a0edf478ca9c59d80bf73491d89cf019259feeniq return access_status;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf if ((access_status = ap_if_walk(r))) {
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf return access_status;
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
bd3f5647b96d378d9c75c954e3f13582af32c643sf /* Don't set per-dir loglevel if LogLevelOverride is set */
bd3f5647b96d378d9c75c954e3f13582af32c643sf if (!r->connection->log) {
bd3f5647b96d378d9c75c954e3f13582af32c643sf d = ap_get_core_module_config(r->per_dir_config);
bd3f5647b96d378d9c75c954e3f13582af32c643sf if (d->log)
bd3f5647b96d378d9c75c954e3f13582af32c643sf r->log = d->log;
efd83d1dd1a25688a3093c5a542ae16bacef62ddsf }
efd83d1dd1a25688a3093c5a542ae16bacef62ddsf
60a765cccbd3f3b5997b65b0034220c79f78369etrawick if ((access_status = ap_run_post_perdir_config(r))) {
60a765cccbd3f3b5997b65b0034220c79f78369etrawick return access_status;
60a765cccbd3f3b5997b65b0034220c79f78369etrawick }
60a765cccbd3f3b5997b65b0034220c79f78369etrawick
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe /* Only on the main request! */
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if (r->main == NULL) {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if ((access_status = ap_run_header_parser(r))) {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe return access_status;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe /* Skip authn/authz if the parent or prior request passed the authn/authz,
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe * and that configuration didn't change (this requires optimized _walk()
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe * functions in map_to_storage that use the same merge results given
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe * identical input.) If the config changes, we must re-auth.
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe */
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd if (r->prev && (r->prev->per_dir_config == r->per_dir_config)) {
4f9c22c4f27571d54197be9674e1fc0d528192aestriker r->user = r->prev->user;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe r->ap_auth_type = r->prev->ap_auth_type;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe }
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd else if (r->main && (r->main->per_dir_config == r->per_dir_config)) {
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd r->user = r->main->user;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd r->ap_auth_type = r->main->ap_auth_type;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd }
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar else {
0d26b42fc1735e110c6dc83b114c56257b20070bbnicholes switch (ap_satisfies(r)) {
0d26b42fc1735e110c6dc83b114c56257b20070bbnicholes case SATISFY_ALL:
0d26b42fc1735e110c6dc83b114c56257b20070bbnicholes case SATISFY_NOSPEC:
0d26b42fc1735e110c6dc83b114c56257b20070bbnicholes if ((access_status = ap_run_access_checker(r)) != OK) {
18b5268e013574026b2503b1641baf3299045f45sf return decl_die(access_status,
18b5268e013574026b2503b1641baf3299045f45sf "check access (with Satisfy All)", r);
0d26b42fc1735e110c6dc83b114c56257b20070bbnicholes }
4f9c22c4f27571d54197be9674e1fc0d528192aestriker
18b5268e013574026b2503b1641baf3299045f45sf access_status = ap_run_access_checker_ex(r);
18b5268e013574026b2503b1641baf3299045f45sf if (access_status == OK) {
18b5268e013574026b2503b1641baf3299045f45sf ap_log_rerror(APLOG_MARK, APLOG_TRACE3, 0, r,
18b5268e013574026b2503b1641baf3299045f45sf "request authorized without authentication by "
d9cc5de428947d5c7221d7d42ceefea649bcab48sf "access_checker_ex hook: %s", r->uri);
18b5268e013574026b2503b1641baf3299045f45sf }
18b5268e013574026b2503b1641baf3299045f45sf else if (access_status != DECLINED) {
18b5268e013574026b2503b1641baf3299045f45sf return decl_die(access_status, "check access", r);
18b5268e013574026b2503b1641baf3299045f45sf }
18b5268e013574026b2503b1641baf3299045f45sf else {
18b5268e013574026b2503b1641baf3299045f45sf if ((access_status = ap_run_check_user_id(r)) != OK) {
404381a78d109fd3a4a7702e69815e4d7ff6d93asf return decl_die(access_status, "check user", r);
404381a78d109fd3a4a7702e69815e4d7ff6d93asf }
1a7a4f8c6a312cb237e428c77da0792eb165dc7aniq if (r->user == NULL) {
1a7a4f8c6a312cb237e428c77da0792eb165dc7aniq /* don't let buggy authn module crash us in authz */
185aa71728867671e105178b4c66fbc22b65ae26sf ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00027)
60fc37bb7b498f4bba5eaaa73a42a25daa27a9dasf "No authentication done but request not "
60fc37bb7b498f4bba5eaaa73a42a25daa27a9dasf "allowed without authentication for %s. "
60fc37bb7b498f4bba5eaaa73a42a25daa27a9dasf "Authentication not configured?",
1a7a4f8c6a312cb237e428c77da0792eb165dc7aniq r->uri);
1a7a4f8c6a312cb237e428c77da0792eb165dc7aniq access_status = HTTP_INTERNAL_SERVER_ERROR;
1a7a4f8c6a312cb237e428c77da0792eb165dc7aniq return decl_die(access_status, "check user", r);
1a7a4f8c6a312cb237e428c77da0792eb165dc7aniq }
18b5268e013574026b2503b1641baf3299045f45sf if ((access_status = ap_run_auth_checker(r)) != OK) {
18b5268e013574026b2503b1641baf3299045f45sf return decl_die(access_status, "check authorization", r);
18b5268e013574026b2503b1641baf3299045f45sf }
0d26b42fc1735e110c6dc83b114c56257b20070bbnicholes }
0d26b42fc1735e110c6dc83b114c56257b20070bbnicholes break;
0d26b42fc1735e110c6dc83b114c56257b20070bbnicholes case SATISFY_ANY:
18b5268e013574026b2503b1641baf3299045f45sf if ((access_status = ap_run_access_checker(r)) == OK) {
18b5268e013574026b2503b1641baf3299045f45sf ap_log_rerror(APLOG_MARK, APLOG_TRACE3, 0, r,
18b5268e013574026b2503b1641baf3299045f45sf "request authorized without authentication by "
18b5268e013574026b2503b1641baf3299045f45sf "access_checker hook and 'Satisfy any': %s",
18b5268e013574026b2503b1641baf3299045f45sf r->uri);
18b5268e013574026b2503b1641baf3299045f45sf break;
18b5268e013574026b2503b1641baf3299045f45sf }
4f9c22c4f27571d54197be9674e1fc0d528192aestriker
18b5268e013574026b2503b1641baf3299045f45sf access_status = ap_run_access_checker_ex(r);
18b5268e013574026b2503b1641baf3299045f45sf if (access_status == OK) {
18b5268e013574026b2503b1641baf3299045f45sf ap_log_rerror(APLOG_MARK, APLOG_TRACE3, 0, r,
18b5268e013574026b2503b1641baf3299045f45sf "request authorized without authentication by "
d9cc5de428947d5c7221d7d42ceefea649bcab48sf "access_checker_ex hook: %s", r->uri);
18b5268e013574026b2503b1641baf3299045f45sf }
18b5268e013574026b2503b1641baf3299045f45sf else if (access_status != DECLINED) {
18b5268e013574026b2503b1641baf3299045f45sf return decl_die(access_status, "check access", r);
18b5268e013574026b2503b1641baf3299045f45sf }
18b5268e013574026b2503b1641baf3299045f45sf else {
0d26b42fc1735e110c6dc83b114c56257b20070bbnicholes if ((access_status = ap_run_check_user_id(r)) != OK) {
18b5268e013574026b2503b1641baf3299045f45sf return decl_die(access_status, "check user", r);
0d26b42fc1735e110c6dc83b114c56257b20070bbnicholes }
69bbd0a9d1892949e1d4e454c10e8ad24b37c759sf if (r->user == NULL) {
69bbd0a9d1892949e1d4e454c10e8ad24b37c759sf /* don't let buggy authn module crash us in authz */
185aa71728867671e105178b4c66fbc22b65ae26sf ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00028)
60fc37bb7b498f4bba5eaaa73a42a25daa27a9dasf "No authentication done but request not "
60fc37bb7b498f4bba5eaaa73a42a25daa27a9dasf "allowed without authentication for %s. "
60fc37bb7b498f4bba5eaaa73a42a25daa27a9dasf "Authentication not configured?",
69bbd0a9d1892949e1d4e454c10e8ad24b37c759sf r->uri);
69bbd0a9d1892949e1d4e454c10e8ad24b37c759sf access_status = HTTP_INTERNAL_SERVER_ERROR;
69bbd0a9d1892949e1d4e454c10e8ad24b37c759sf return decl_die(access_status, "check user", r);
69bbd0a9d1892949e1d4e454c10e8ad24b37c759sf }
0d26b42fc1735e110c6dc83b114c56257b20070bbnicholes if ((access_status = ap_run_auth_checker(r)) != OK) {
0d26b42fc1735e110c6dc83b114c56257b20070bbnicholes return decl_die(access_status, "check authorization", r);
0d26b42fc1735e110c6dc83b114c56257b20070bbnicholes }
0d26b42fc1735e110c6dc83b114c56257b20070bbnicholes }
0d26b42fc1735e110c6dc83b114c56257b20070bbnicholes break;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe /* XXX Must make certain the ap_run_type_checker short circuits mime
4f9c22c4f27571d54197be9674e1fc0d528192aestriker * in mod-proxy for r->proxyreq && r->parsed_uri.scheme
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe * && !strcmp(r->parsed_uri.scheme, "http")
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe */
d176cb9e596e4603f76490f9211f62b5581b3091rooneg if ((access_status = ap_run_type_checker(r)) != OK) {
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz return decl_die(access_status, "find types", r);
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
d176cb9e596e4603f76490f9211f62b5581b3091rooneg if ((access_status = ap_run_fixups(r)) != OK) {
4760b58cc9fe170e4ad4648ed4ff7a422a2cef38sf ap_log_rerror(APLOG_MARK, APLOG_TRACE3, 0, r, "fixups hook gave %d: %s",
4760b58cc9fe170e4ad4648ed4ff7a422a2cef38sf access_status, r->uri);
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe return access_status;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe return OK;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe}
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe/* Useful caching structures to repeat _walk/merge sequences as required
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe * when a subrequest or redirect reuses substantially the same config.
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe *
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe * Directive order in the httpd.conf file and its Includes significantly
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe * impact this optimization. Grouping common blocks at the front of the
4f9c22c4f27571d54197be9674e1fc0d528192aestriker * config that are less likely to change between a request and
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe * its subrequests, or between a request and its redirects reduced
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe * the work of these functions significantly.
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe */
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe
0540a0b469147b52e858587270dba31c2aaa9e09wrowetypedef struct walk_walked_t {
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe ap_conf_vector_t *matched; /* A dir_conf sections we matched */
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe ap_conf_vector_t *merged; /* The dir_conf merged result */
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe} walk_walked_t;
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowetypedef struct walk_cache_t {
4f9c22c4f27571d54197be9674e1fc0d528192aestriker const char *cached; /* The identifier we matched */
4f9c22c4f27571d54197be9674e1fc0d528192aestriker ap_conf_vector_t **dir_conf_tested; /* The sections we matched against */
4f9c22c4f27571d54197be9674e1fc0d528192aestriker ap_conf_vector_t *dir_conf_merged; /* Base per_dir_config */
4f9c22c4f27571d54197be9674e1fc0d528192aestriker ap_conf_vector_t *per_dir_result; /* per_dir_config += walked result */
4f9c22c4f27571d54197be9674e1fc0d528192aestriker apr_array_header_t *walked; /* The list of walk_walked_t results */
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd struct walk_cache_t *prev; /* Prev cache of same call in this (sub)req */
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd int count; /* Number of prev invocations of same call in this (sub)req */
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe} walk_cache_t;
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe
a2b181763cb35fd899feb4a436aeadaa80bf91eabrianpstatic walk_cache_t *prep_walk_cache(apr_size_t t, request_rec *r)
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe{
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd void **note, **inherit_note;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd walk_cache_t *cache, *prev_cache, *copy_cache;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd int count;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd /* Find the most relevant, recent walk cache to work from and provide
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd * a copy the caller is allowed to munge. In the case of a sub-request
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd * or internal redirect, this is the cache corresponding to the equivalent
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd * invocation of the same function call in the "parent" request, if such
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd * a cache exists. Otherwise it is the walk cache of the previous
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd * invocation of the same function call in the current request, if
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd * that exists; if not, then create a new walk cache.
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe */
a2b181763cb35fd899feb4a436aeadaa80bf91eabrianp note = ap_get_request_note(r, t);
f46cb698a1b32d16a0107566568f67d8c3f8ee9csf AP_DEBUG_ASSERT(note != NULL);
4f9c22c4f27571d54197be9674e1fc0d528192aestriker
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd copy_cache = prev_cache = *note;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd count = prev_cache ? (prev_cache->count + 1) : 0;
4f9c22c4f27571d54197be9674e1fc0d528192aestriker
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd if ((r->prev
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd && (inherit_note = ap_get_request_note(r->prev, t))
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd && *inherit_note)
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd || (r->main
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd && (inherit_note = ap_get_request_note(r->main, t))
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd && *inherit_note)) {
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd walk_cache_t *inherit_cache = *inherit_note;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd while (inherit_cache->count > count) {
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd inherit_cache = inherit_cache->prev;
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe }
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd if (inherit_cache->count == count) {
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd copy_cache = inherit_cache;
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe }
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd }
4f9c22c4f27571d54197be9674e1fc0d528192aestriker
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd if (copy_cache) {
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd cache = apr_pmemdup(r->pool, copy_cache, sizeof(*cache));
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd cache->walked = apr_array_copy(r->pool, cache->walked);
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd cache->prev = prev_cache;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd cache->count = count;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd }
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd else {
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd cache = apr_pcalloc(r->pool, sizeof(*cache));
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd cache->walked = apr_array_make(r->pool, 4, sizeof(walk_walked_t));
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe }
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd *note = cache;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe return cache;
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe}
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb/*****************************************************************
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Getting and checking directory configuration. Also checks the
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * FollowSymlinks and FollowSymOwner stuff, since this is really the
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * only place that can happen (barring a new mid_dir_walk callout).
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * We can't do it as an access_checker module function which gets
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * called with the final per_dir_config, since we could have a directory
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * with FollowSymLinks disabled, which contains a symlink to another
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * with a .htaccess file which turns FollowSymLinks back on --- and
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * access in such a case must be denied. So, whatever it is that
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * checks FollowSymLinks needs to know the state of the options as
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * they change, all the way down.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe/*
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe * resolve_symlink must _always_ be called on an APR_LNK file type!
4f9c22c4f27571d54197be9674e1fc0d528192aestriker * It will resolve the actual target file type, modification date, etc,
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe * and provide any processing required for symlink evaluation.
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe * Path must already be cleaned, no trailing slash, no multi-slashes,
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe * and don't call this on the root!
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe *
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe * Simply, the number of times we deref a symlink are minimal compared
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe * to the number of times we had an extra lstat() since we 'weren't sure'.
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe *
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe * To optimize, we stat() anything when given (opts & OPT_SYM_LINKS), otherwise
4f9c22c4f27571d54197be9674e1fc0d528192aestriker * we start off with an lstat(). Every lstat() must be dereferenced in case
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe * it points at a 'nasty' - we must always rerun check_safe_file (or similar.)
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe */
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowestatic int resolve_symlink(char *d, apr_finfo_t *lfi, int opts, apr_pool_t *p)
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe{
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe apr_finfo_t fi;
7c301a1818939f85da8f3629cc3e9b5588610ef0jerenkrantz const char *savename;
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar if (!(opts & (OPT_SYM_OWNER | OPT_SYM_LINKS))) {
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe return HTTP_FORBIDDEN;
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar }
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe
7c301a1818939f85da8f3629cc3e9b5588610ef0jerenkrantz /* Save the name from the valid bits. */
7c301a1818939f85da8f3629cc3e9b5588610ef0jerenkrantz savename = (lfi->valid & APR_FINFO_NAME) ? lfi->name : NULL;
7c301a1818939f85da8f3629cc3e9b5588610ef0jerenkrantz
1e911973bcb9df6701a4c16c037771ecf25ade13niq /* if OPT_SYM_OWNER is unset, we only need to check target accessible */
1e911973bcb9df6701a4c16c037771ecf25ade13niq if (!(opts & OPT_SYM_OWNER)) {
c3e233736c4a453cbb2166a041f779e86230630asf if (apr_stat(&fi, d, lfi->valid & ~(APR_FINFO_NAME | APR_FINFO_LINK), p)
c3e233736c4a453cbb2166a041f779e86230630asf != APR_SUCCESS)
c3e233736c4a453cbb2166a041f779e86230630asf {
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe return HTTP_FORBIDDEN;
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar }
11fb2f3611e6ff9a541e10b13e3108934f828141gregames
11fb2f3611e6ff9a541e10b13e3108934f828141gregames /* Give back the target */
11fb2f3611e6ff9a541e10b13e3108934f828141gregames memcpy(lfi, &fi, sizeof(fi));
7c301a1818939f85da8f3629cc3e9b5588610ef0jerenkrantz if (savename) {
7c301a1818939f85da8f3629cc3e9b5588610ef0jerenkrantz lfi->name = savename;
7c301a1818939f85da8f3629cc3e9b5588610ef0jerenkrantz lfi->valid |= APR_FINFO_NAME;
7c301a1818939f85da8f3629cc3e9b5588610ef0jerenkrantz }
4f9c22c4f27571d54197be9674e1fc0d528192aestriker
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe return OK;
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe }
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe
4f9c22c4f27571d54197be9674e1fc0d528192aestriker /* OPT_SYM_OWNER only works if we can get the owner of
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe * both the file and symlink. First fill in a missing
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe * owner of the symlink, then get the info of the target.
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe */
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar if (!(lfi->valid & APR_FINFO_OWNER)) {
c3e233736c4a453cbb2166a041f779e86230630asf if (apr_stat(lfi, d, lfi->valid | APR_FINFO_LINK | APR_FINFO_OWNER, p)
c3e233736c4a453cbb2166a041f779e86230630asf != APR_SUCCESS)
c3e233736c4a453cbb2166a041f779e86230630asf {
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe return HTTP_FORBIDDEN;
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar }
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar }
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe
c3e233736c4a453cbb2166a041f779e86230630asf if (apr_stat(&fi, d, lfi->valid & ~(APR_FINFO_NAME), p) != APR_SUCCESS) {
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe return HTTP_FORBIDDEN;
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar }
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe
1fbf6ba0f5207e6637b49f9a9dfcc779bbe952a9trawick if (apr_uid_compare(fi.user, lfi->user) != APR_SUCCESS) {
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe return HTTP_FORBIDDEN;
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar }
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe /* Give back the target */
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe memcpy(lfi, &fi, sizeof(fi));
7c301a1818939f85da8f3629cc3e9b5588610ef0jerenkrantz if (savename) {
7c301a1818939f85da8f3629cc3e9b5588610ef0jerenkrantz lfi->name = savename;
7c301a1818939f85da8f3629cc3e9b5588610ef0jerenkrantz lfi->valid |= APR_FINFO_NAME;
7c301a1818939f85da8f3629cc3e9b5588610ef0jerenkrantz }
4f9c22c4f27571d54197be9674e1fc0d528192aestriker
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe return OK;
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
8aefbd756763807188d2e3ce336a8680e4893066wrowe
700b96db75e7cfadb5219978c1735b710d583763wrowe/*
700b96db75e7cfadb5219978c1735b710d583763wrowe * As we walk the directory configuration, the merged config won't
700b96db75e7cfadb5219978c1735b710d583763wrowe * be 'rooted' to a specific vhost until the very end of the merge.
700b96db75e7cfadb5219978c1735b710d583763wrowe *
700b96db75e7cfadb5219978c1735b710d583763wrowe * We need a very fast mini-merge to a real, vhost-rooted merge
700b96db75e7cfadb5219978c1735b710d583763wrowe * of core.opts and core.override, the only options tested within
700b96db75e7cfadb5219978c1735b710d583763wrowe * directory_walk itself.
700b96db75e7cfadb5219978c1735b710d583763wrowe *
700b96db75e7cfadb5219978c1735b710d583763wrowe * See core.c::merge_core_dir_configs() for explanation.
700b96db75e7cfadb5219978c1735b710d583763wrowe */
700b96db75e7cfadb5219978c1735b710d583763wrowe
700b96db75e7cfadb5219978c1735b710d583763wrowetypedef struct core_opts_t {
700b96db75e7cfadb5219978c1735b710d583763wrowe allow_options_t opts;
700b96db75e7cfadb5219978c1735b710d583763wrowe allow_options_t add;
700b96db75e7cfadb5219978c1735b710d583763wrowe allow_options_t remove;
700b96db75e7cfadb5219978c1735b710d583763wrowe overrides_t override;
103a93c625bcde1a6a7a5155b64dcda36f612180pquerna overrides_t override_opts;
113961f0559eb026ea0d379cb7350f82bc09d710druggeri apr_table_t *override_list;
700b96db75e7cfadb5219978c1735b710d583763wrowe} core_opts_t;
700b96db75e7cfadb5219978c1735b710d583763wrowe
6964758306167dd898baedd21048bd1515dd9d30trawickstatic void core_opts_merge(const ap_conf_vector_t *sec, core_opts_t *opts)
700b96db75e7cfadb5219978c1735b710d583763wrowe{
7184de27ec1d62a83c41cdeac0953ca9fd661e8csf core_dir_config *this_dir = ap_get_core_module_config(sec);
700b96db75e7cfadb5219978c1735b710d583763wrowe
700b96db75e7cfadb5219978c1735b710d583763wrowe if (!this_dir) {
700b96db75e7cfadb5219978c1735b710d583763wrowe return;
700b96db75e7cfadb5219978c1735b710d583763wrowe }
700b96db75e7cfadb5219978c1735b710d583763wrowe
700b96db75e7cfadb5219978c1735b710d583763wrowe if (this_dir->opts & OPT_UNSET) {
700b96db75e7cfadb5219978c1735b710d583763wrowe opts->add = (opts->add & ~this_dir->opts_remove)
700b96db75e7cfadb5219978c1735b710d583763wrowe | this_dir->opts_add;
700b96db75e7cfadb5219978c1735b710d583763wrowe opts->remove = (opts->remove & ~this_dir->opts_add)
700b96db75e7cfadb5219978c1735b710d583763wrowe | this_dir->opts_remove;
700b96db75e7cfadb5219978c1735b710d583763wrowe opts->opts = (opts->opts & ~opts->remove) | opts->add;
700b96db75e7cfadb5219978c1735b710d583763wrowe }
700b96db75e7cfadb5219978c1735b710d583763wrowe else {
700b96db75e7cfadb5219978c1735b710d583763wrowe opts->opts = this_dir->opts;
700b96db75e7cfadb5219978c1735b710d583763wrowe opts->add = this_dir->opts_add;
700b96db75e7cfadb5219978c1735b710d583763wrowe opts->remove = this_dir->opts_remove;
700b96db75e7cfadb5219978c1735b710d583763wrowe }
700b96db75e7cfadb5219978c1735b710d583763wrowe
700b96db75e7cfadb5219978c1735b710d583763wrowe if (!(this_dir->override & OR_UNSET)) {
700b96db75e7cfadb5219978c1735b710d583763wrowe opts->override = this_dir->override;
103a93c625bcde1a6a7a5155b64dcda36f612180pquerna opts->override_opts = this_dir->override_opts;
103a93c625bcde1a6a7a5155b64dcda36f612180pquerna }
113961f0559eb026ea0d379cb7350f82bc09d710druggeri
113961f0559eb026ea0d379cb7350f82bc09d710druggeri if (this_dir->override_list != NULL) {
113961f0559eb026ea0d379cb7350f82bc09d710druggeri opts->override_list = this_dir->override_list;
113961f0559eb026ea0d379cb7350f82bc09d710druggeri }
113961f0559eb026ea0d379cb7350f82bc09d710druggeri
700b96db75e7cfadb5219978c1735b710d583763wrowe}
700b96db75e7cfadb5219978c1735b710d583763wrowe
700b96db75e7cfadb5219978c1735b710d583763wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe/*****************************************************************
8aefbd756763807188d2e3ce336a8680e4893066wrowe *
8aefbd756763807188d2e3ce336a8680e4893066wrowe * Getting and checking directory configuration. Also checks the
8aefbd756763807188d2e3ce336a8680e4893066wrowe * FollowSymlinks and FollowSymOwner stuff, since this is really the
8aefbd756763807188d2e3ce336a8680e4893066wrowe * only place that can happen (barring a new mid_dir_walk callout).
8aefbd756763807188d2e3ce336a8680e4893066wrowe *
8aefbd756763807188d2e3ce336a8680e4893066wrowe * We can't do it as an access_checker module function which gets
8aefbd756763807188d2e3ce336a8680e4893066wrowe * called with the final per_dir_config, since we could have a directory
8aefbd756763807188d2e3ce336a8680e4893066wrowe * with FollowSymLinks disabled, which contains a symlink to another
8aefbd756763807188d2e3ce336a8680e4893066wrowe * with a .htaccess file which turns FollowSymLinks back on --- and
8aefbd756763807188d2e3ce336a8680e4893066wrowe * access in such a case must be denied. So, whatever it is that
8aefbd756763807188d2e3ce336a8680e4893066wrowe * checks FollowSymLinks needs to know the state of the options as
8aefbd756763807188d2e3ce336a8680e4893066wrowe * they change, all the way down.
8aefbd756763807188d2e3ce336a8680e4893066wrowe */
8aefbd756763807188d2e3ce336a8680e4893066wrowe
a2a0abd88b19e042a3eb2a9fa1702c25ad51303dwroweAP_DECLARE(int) ap_directory_walk(request_rec *r)
8aefbd756763807188d2e3ce336a8680e4893066wrowe{
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_conf_vector_t *now_merged = NULL;
7184de27ec1d62a83c41cdeac0953ca9fd661e8csf core_server_config *sconf =
7184de27ec1d62a83c41cdeac0953ca9fd661e8csf ap_get_core_module_config(r->server->module_config);
2fa5b5878e7567e2875807c3e2a2b3b0d3ef74bewrowe ap_conf_vector_t **sec_ent = (ap_conf_vector_t **) sconf->sec_dir->elts;
2fa5b5878e7567e2875807c3e2a2b3b0d3ef74bewrowe int num_sec = sconf->sec_dir->nelts;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe walk_cache_t *cache;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe char *entry_dir;
8aefbd756763807188d2e3ce336a8680e4893066wrowe apr_status_t rv;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd int cached;
8aefbd756763807188d2e3ce336a8680e4893066wrowe
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe /* XXX: Better (faster) tests needed!!!
a8d11d78181478da6a672f7fbc58b8d523351f49wrowe *
4f9c22c4f27571d54197be9674e1fc0d528192aestriker * "OK" as a response to a real problem is not _OK_, but to allow broken
23c6309e36a63b13b61c35999c978017521993d6wrowe * modules to proceed, we will permit the not-a-path filename to pass the
23c6309e36a63b13b61c35999c978017521993d6wrowe * following two tests. This behavior may be revoked in future versions
4f9c22c4f27571d54197be9674e1fc0d528192aestriker * of Apache. We still must catch it later if it's heading for the core
23c6309e36a63b13b61c35999c978017521993d6wrowe * handler. Leave INFO notes here for module debugging.
8aefbd756763807188d2e3ce336a8680e4893066wrowe */
23c6309e36a63b13b61c35999c978017521993d6wrowe if (r->filename == NULL) {
185aa71728867671e105178b4c66fbc22b65ae26sf ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, APLOGNO(00029)
4f9c22c4f27571d54197be9674e1fc0d528192aestriker "Module bug? Request filename is missing for URI %s",
23c6309e36a63b13b61c35999c978017521993d6wrowe r->uri);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe return OK;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
cf6ef072483172309861d06e85b1aeff4573c060wrowe /* Canonicalize the file path without resolving filename case or aliases
cf6ef072483172309861d06e85b1aeff4573c060wrowe * so we can begin by checking the cache for a recent directory walk.
cf6ef072483172309861d06e85b1aeff4573c060wrowe * This call will ensure we have an absolute path in the same pass.
8aefbd756763807188d2e3ce336a8680e4893066wrowe */
4f9c22c4f27571d54197be9674e1fc0d528192aestriker if ((rv = apr_filepath_merge(&entry_dir, NULL, r->filename,
4f9c22c4f27571d54197be9674e1fc0d528192aestriker APR_FILEPATH_NOTRELATIVE, r->pool))
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe != APR_SUCCESS) {
185aa71728867671e105178b4c66fbc22b65ae26sf ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, APLOGNO(00030)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe "Module bug? Request filename path %s is invalid or "
4f9c22c4f27571d54197be9674e1fc0d528192aestriker "or not absolute for uri %s",
a8d11d78181478da6a672f7fbc58b8d523351f49wrowe r->filename, r->uri);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe return OK;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
cf6ef072483172309861d06e85b1aeff4573c060wrowe /* XXX Notice that this forces path_info to be canonical. That might
cf6ef072483172309861d06e85b1aeff4573c060wrowe * not be desired by all apps. However, some of those same apps likely
cf6ef072483172309861d06e85b1aeff4573c060wrowe * have significant security holes.
8aefbd756763807188d2e3ce336a8680e4893066wrowe */
cf6ef072483172309861d06e85b1aeff4573c060wrowe r->filename = entry_dir;
cf6ef072483172309861d06e85b1aeff4573c060wrowe
a2b181763cb35fd899feb4a436aeadaa80bf91eabrianp cache = prep_walk_cache(AP_NOTE_DIRECTORY_WALK, r);
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd cached = (cache->cached != NULL);
cf6ef072483172309861d06e85b1aeff4573c060wrowe
4f9c22c4f27571d54197be9674e1fc0d528192aestriker /* If this is not a dirent subrequest with a preconstructed
cf6ef072483172309861d06e85b1aeff4573c060wrowe * r->finfo value, then we can simply stat the filename to
cf6ef072483172309861d06e85b1aeff4573c060wrowe * save burning mega-cycles with unneeded stats - if this is
cf6ef072483172309861d06e85b1aeff4573c060wrowe * an exact file match. We don't care about failure... we
cf6ef072483172309861d06e85b1aeff4573c060wrowe * will stat by component failing this meager attempt.
cf6ef072483172309861d06e85b1aeff4573c060wrowe *
cf6ef072483172309861d06e85b1aeff4573c060wrowe * It would be nice to distinguish APR_ENOENT from other
cf6ef072483172309861d06e85b1aeff4573c060wrowe * types of failure, such as APR_ENOTDIR. We can do something
cf6ef072483172309861d06e85b1aeff4573c060wrowe * with APR_ENOENT, knowing that the path is good.
cf6ef072483172309861d06e85b1aeff4573c060wrowe */
2d4ea77e21ef7f3707d2c27f6117cc0a36e99b83trawick if (r->finfo.filetype == APR_NOFILE || r->finfo.filetype == APR_LNK) {
f4ca9f6f002fece336168a16355434ca966f96a9trawick rv = ap_run_dirwalk_stat(&r->finfo, r, APR_FINFO_MIN);
d75626f0952c6152a99acd013a4f127d46f0f9edtrawick
d75626f0952c6152a99acd013a4f127d46f0f9edtrawick /* some OSs will return APR_SUCCESS/APR_REG if we stat
d75626f0952c6152a99acd013a4f127d46f0f9edtrawick * a regular file but we have '/' at the end of the name;
d75626f0952c6152a99acd013a4f127d46f0f9edtrawick *
d75626f0952c6152a99acd013a4f127d46f0f9edtrawick * other OSs will return APR_ENOTDIR for that situation;
d75626f0952c6152a99acd013a4f127d46f0f9edtrawick *
d75626f0952c6152a99acd013a4f127d46f0f9edtrawick * handle it the same everywhere by simulating a failure
d75626f0952c6152a99acd013a4f127d46f0f9edtrawick * if it looks like a directory but really isn't
ecde48c75338ff5712f2036711f813c6dedca28ewrowe *
ecde48c75338ff5712f2036711f813c6dedca28ewrowe * Also reset if the stat failed, just for safety.
d75626f0952c6152a99acd013a4f127d46f0f9edtrawick */
ecde48c75338ff5712f2036711f813c6dedca28ewrowe if ((rv != APR_SUCCESS) ||
2d4ea77e21ef7f3707d2c27f6117cc0a36e99b83trawick (r->finfo.filetype != APR_NOFILE &&
ecde48c75338ff5712f2036711f813c6dedca28ewrowe (r->finfo.filetype != APR_DIR) &&
ecde48c75338ff5712f2036711f813c6dedca28ewrowe (r->filename[strlen(r->filename) - 1] == '/'))) {
2d4ea77e21ef7f3707d2c27f6117cc0a36e99b83trawick r->finfo.filetype = APR_NOFILE; /* forget what we learned */
d75626f0952c6152a99acd013a4f127d46f0f9edtrawick }
cf6ef072483172309861d06e85b1aeff4573c060wrowe }
cf6ef072483172309861d06e85b1aeff4573c060wrowe
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar if (r->finfo.filetype == APR_REG) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe entry_dir = ap_make_dirstr_parent(r->pool, entry_dir);
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar }
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar else if (r->filename[strlen(r->filename) - 1] != '/') {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe entry_dir = apr_pstrcat(r->pool, r->filename, "/", NULL);
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* If we have a file already matches the path of r->filename,
4f9c22c4f27571d54197be9674e1fc0d528192aestriker * and the vhost's list of directory sections hasn't changed,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * we can skip rewalking the directory_walk entries.
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe */
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd if (cached
23c6309e36a63b13b61c35999c978017521993d6wrowe && ((r->finfo.filetype == APR_REG)
4f9c22c4f27571d54197be9674e1fc0d528192aestriker || ((r->finfo.filetype == APR_DIR)
4f9c22c4f27571d54197be9674e1fc0d528192aestriker && (!r->path_info || !*r->path_info)))
4f9c22c4f27571d54197be9674e1fc0d528192aestriker && (cache->dir_conf_tested == sec_ent)
c2cf53a40a9814eb91db2cdf820f97d943f21628coar && (strcmp(entry_dir, cache->cached) == 0)) {
170476518c96db46fff6fdce7cb9a3f24abfaea7rpluem int familiar = 0;
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* Well this looks really familiar! If our end-result (per_dir_result)
4f9c22c4f27571d54197be9674e1fc0d528192aestriker * didn't change, we have absolutely nothing to do :)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * Otherwise (as is the case with most dir_merged/file_merged requests)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * we must merge our dir_conf_merged onto this new r->per_dir_config.
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe */
a9a4544168a37b43bd180b3703ccee995f27a80awrowe if (r->per_dir_config == cache->per_dir_result) {
170476518c96db46fff6fdce7cb9a3f24abfaea7rpluem familiar = 1;
a9a4544168a37b43bd180b3703ccee995f27a80awrowe }
4f9c22c4f27571d54197be9674e1fc0d528192aestriker
a9a4544168a37b43bd180b3703ccee995f27a80awrowe if (r->per_dir_config == cache->dir_conf_merged) {
a9a4544168a37b43bd180b3703ccee995f27a80awrowe r->per_dir_config = cache->per_dir_result;
170476518c96db46fff6fdce7cb9a3f24abfaea7rpluem familiar = 1;
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem }
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem
170476518c96db46fff6fdce7cb9a3f24abfaea7rpluem if (familiar) {
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem apr_finfo_t thisinfo;
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem int res;
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem allow_options_t opts;
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem core_dir_config *this_dir;
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem
7184de27ec1d62a83c41cdeac0953ca9fd661e8csf this_dir = ap_get_core_module_config(r->per_dir_config);
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem opts = this_dir->opts;
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem /*
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem * If Symlinks are allowed in general we do not need the following
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem * check.
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem */
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem if (!(opts & OPT_SYM_LINKS)) {
f4ca9f6f002fece336168a16355434ca966f96a9trawick rv = ap_run_dirwalk_stat(&thisinfo, r,
f4ca9f6f002fece336168a16355434ca966f96a9trawick APR_FINFO_MIN | APR_FINFO_NAME | APR_FINFO_LINK);
eb12400ff685a3b69476736ca4b5389f348b9d63rpluem /*
eb12400ff685a3b69476736ca4b5389f348b9d63rpluem * APR_INCOMPLETE is as fine as result as APR_SUCCESS as we
eb12400ff685a3b69476736ca4b5389f348b9d63rpluem * have added APR_FINFO_NAME to the wanted parameter of
eb12400ff685a3b69476736ca4b5389f348b9d63rpluem * apr_stat above. On Unix platforms this means that apr_stat
eb12400ff685a3b69476736ca4b5389f348b9d63rpluem * is always going to return APR_INCOMPLETE in the case that
eb12400ff685a3b69476736ca4b5389f348b9d63rpluem * the call to the native stat / lstat did not fail.
eb12400ff685a3b69476736ca4b5389f348b9d63rpluem */
eb12400ff685a3b69476736ca4b5389f348b9d63rpluem if ((rv != APR_INCOMPLETE) && (rv != APR_SUCCESS)) {
ad099b4d62597be19f8dba650663e796cbaa8d28rpluem /*
ad099b4d62597be19f8dba650663e796cbaa8d28rpluem * This should never happen, because we did a stat on the
ad099b4d62597be19f8dba650663e796cbaa8d28rpluem * same file, resolving a possible symlink several lines
ad099b4d62597be19f8dba650663e796cbaa8d28rpluem * above. Therefore do not make a detailed analysis of rv
ad099b4d62597be19f8dba650663e796cbaa8d28rpluem * in this case for the reason of the failure, just bail out
ad099b4d62597be19f8dba650663e796cbaa8d28rpluem * with a HTTP_FORBIDDEN in case we hit a race condition
ad099b4d62597be19f8dba650663e796cbaa8d28rpluem * here.
ad099b4d62597be19f8dba650663e796cbaa8d28rpluem */
185aa71728867671e105178b4c66fbc22b65ae26sf ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(00031)
75c02648f9afe9a1da5d5482703fcbca306ffcdcpquerna "access to %s failed; stat of '%s' failed.",
75c02648f9afe9a1da5d5482703fcbca306ffcdcpquerna r->uri, r->filename);
ad099b4d62597be19f8dba650663e796cbaa8d28rpluem return r->status = HTTP_FORBIDDEN;
ad099b4d62597be19f8dba650663e796cbaa8d28rpluem }
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem if (thisinfo.filetype == APR_LNK) {
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem /* Is this a possibly acceptable symlink? */
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem if ((res = resolve_symlink(r->filename, &thisinfo,
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem opts, r->pool)) != OK) {
185aa71728867671e105178b4c66fbc22b65ae26sf ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00032)
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem "Symbolic link not allowed "
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem "or link target not accessible: %s",
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem r->filename);
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem return r->status = res;
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem }
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem }
534611d341a1a48b93c7a1fd5e333dbd261527d3rpluem }
a9a4544168a37b43bd180b3703ccee995f27a80awrowe return OK;
a9a4544168a37b43bd180b3703ccee995f27a80awrowe }
4f9c22c4f27571d54197be9674e1fc0d528192aestriker
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar if (cache->walked->nelts) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe now_merged = ((walk_walked_t*)cache->walked->elts)
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar [cache->walked->nelts - 1].merged;
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe else {
4f9c22c4f27571d54197be9674e1fc0d528192aestriker /* We start now_merged from NULL since we want to build
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * a locations list that can be merged to any vhost.
8aefbd756763807188d2e3ce336a8680e4893066wrowe */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe int sec_idx;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe int matches = cache->walked->nelts;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd int cached_matches = matches;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe walk_walked_t *last_walk = (walk_walked_t*)cache->walked->elts;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe core_dir_config *this_dir;
700b96db75e7cfadb5219978c1735b710d583763wrowe core_opts_t opts;
cf6ef072483172309861d06e85b1aeff4573c060wrowe apr_finfo_t thisinfo;
cf6ef072483172309861d06e85b1aeff4573c060wrowe char *save_path_info;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe apr_size_t buflen;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe char *buf;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe unsigned int seg, startseg;
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin apr_pool_t *rxpool = NULL;
8aefbd756763807188d2e3ce336a8680e4893066wrowe
0e58e92812f2f679d6bf2ff66cbcfa6c1d1e14bbjerenkrantz /* Invariant: from the first time filename_len is set until
0e58e92812f2f679d6bf2ff66cbcfa6c1d1e14bbjerenkrantz * it goes out of scope, filename_len==strlen(r->filename)
0e58e92812f2f679d6bf2ff66cbcfa6c1d1e14bbjerenkrantz */
cf6ef072483172309861d06e85b1aeff4573c060wrowe apr_size_t filename_len;
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe#ifdef CASE_BLIND_FILESYSTEM
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe apr_size_t canonical_len;
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe#endif
4f9c22c4f27571d54197be9674e1fc0d528192aestriker
3dcf67a5060400edb8ccef3fb4a2024388965af9martin cached &= auth_internal_per_conf;
3dcf67a5060400edb8ccef3fb4a2024388965af9martin
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /*
2fd8d1e14fc47762d1e01660b544d5e2a75c825dtrawick * We must play our own mini-merge game here, for the few
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * running dir_config values we care about within dir_walk.
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * We didn't start the merge from r->per_dir_config, so we
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * accumulate opts and override as we merge, from the globals.
8aefbd756763807188d2e3ce336a8680e4893066wrowe */
7184de27ec1d62a83c41cdeac0953ca9fd661e8csf this_dir = ap_get_core_module_config(r->per_dir_config);
700b96db75e7cfadb5219978c1735b710d583763wrowe opts.opts = this_dir->opts;
700b96db75e7cfadb5219978c1735b710d583763wrowe opts.add = this_dir->opts_add;
700b96db75e7cfadb5219978c1735b710d583763wrowe opts.remove = this_dir->opts_remove;
700b96db75e7cfadb5219978c1735b710d583763wrowe opts.override = this_dir->override;
e0c4ebfec83bb3b424184984e5788f31297fe429sctemme opts.override_opts = this_dir->override_opts;
113961f0559eb026ea0d379cb7350f82bc09d710druggeri opts.override_list = this_dir->override_list;
8aefbd756763807188d2e3ce336a8680e4893066wrowe
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe /* Set aside path_info to merge back onto path_info later.
4f9c22c4f27571d54197be9674e1fc0d528192aestriker * If r->filename is a directory, we must remerge the path_info,
25afd195b9c3c514c5195c87ca281b1b93138ac9trawick * before we continue! [Directories cannot, by definition, have
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe * path info. Either the next segment is not-found, or a file.]
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe *
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe * r->path_info tracks the unconsumed source path.
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe * r->filename tracks the path as we process it
59513b1275fdc2021d4949ee03ae8229469abb86wrowe */
4f9c22c4f27571d54197be9674e1fc0d528192aestriker if ((r->finfo.filetype == APR_DIR) && r->path_info && *r->path_info)
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe {
4f9c22c4f27571d54197be9674e1fc0d528192aestriker if ((rv = apr_filepath_merge(&r->path_info, r->filename,
4f9c22c4f27571d54197be9674e1fc0d528192aestriker r->path_info,
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe APR_FILEPATH_NOTABOVEROOT, r->pool))
4f9c22c4f27571d54197be9674e1fc0d528192aestriker != APR_SUCCESS) {
185aa71728867671e105178b4c66fbc22b65ae26sf ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(00033)
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe "dir_walk error, path_info %s is not relative "
4f9c22c4f27571d54197be9674e1fc0d528192aestriker "to the filename path %s for uri %s",
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe r->path_info, r->filename, r->uri);
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe return HTTP_INTERNAL_SERVER_ERROR;
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe }
4f9c22c4f27571d54197be9674e1fc0d528192aestriker
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe save_path_info = NULL;
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe }
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe else {
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe save_path_info = r->path_info;
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe r->path_info = r->filename;
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe }
cf6ef072483172309861d06e85b1aeff4573c060wrowe
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe#ifdef CASE_BLIND_FILESYSTEM
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe
4f9c22c4f27571d54197be9674e1fc0d528192aestriker canonical_len = 0;
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe while (r->canonical_filename && r->canonical_filename[canonical_len]
4f9c22c4f27571d54197be9674e1fc0d528192aestriker && (r->canonical_filename[canonical_len]
4f9c22c4f27571d54197be9674e1fc0d528192aestriker == r->path_info[canonical_len])) {
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe ++canonical_len;
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe }
4f9c22c4f27571d54197be9674e1fc0d528192aestriker
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe while (canonical_len
4f9c22c4f27571d54197be9674e1fc0d528192aestriker && ((r->canonical_filename[canonical_len - 1] != '/'
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe && r->canonical_filename[canonical_len - 1])
4f9c22c4f27571d54197be9674e1fc0d528192aestriker || (r->path_info[canonical_len - 1] != '/'
4f9c22c4f27571d54197be9674e1fc0d528192aestriker && r->path_info[canonical_len - 1]))) {
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe --canonical_len;
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe }
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe
4f9c22c4f27571d54197be9674e1fc0d528192aestriker /*
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe * Now build r->filename component by component, starting
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe * with the root (on Unix, simply "/"). We will make a huge
4f9c22c4f27571d54197be9674e1fc0d528192aestriker * assumption here for efficiency, that any canonical path
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe * already given included a canonical root.
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe */
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe rv = apr_filepath_root((const char **)&r->filename,
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe (const char **)&r->path_info,
4f9c22c4f27571d54197be9674e1fc0d528192aestriker canonical_len ? 0 : APR_FILEPATH_TRUENAME,
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe r->pool);
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe filename_len = strlen(r->filename);
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe /*
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe * Bad assumption above? If the root's length is longer
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe * than the canonical length, then it cannot be trusted as
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe * a truename. So try again, this time more seriously.
cf6ef072483172309861d06e85b1aeff4573c060wrowe */
4f9c22c4f27571d54197be9674e1fc0d528192aestriker if ((rv == APR_SUCCESS) && canonical_len
4f9c22c4f27571d54197be9674e1fc0d528192aestriker && (filename_len > canonical_len)) {
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe rv = apr_filepath_root((const char **)&r->filename,
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe (const char **)&r->path_info,
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe APR_FILEPATH_TRUENAME, r->pool);
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe filename_len = strlen(r->filename);
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe canonical_len = 0;
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe }
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe#else /* ndef CASE_BLIND_FILESYSTEM, really this simple for Unix today; */
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe
38bcc87d9a06e8ba81165421403f275eca4e313btrawick rv = apr_filepath_root((const char **)&r->filename,
38bcc87d9a06e8ba81165421403f275eca4e313btrawick (const char **)&r->path_info,
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe 0, r->pool);
0e58e92812f2f679d6bf2ff66cbcfa6c1d1e14bbjerenkrantz filename_len = strlen(r->filename);
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe#endif
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe if (rv != APR_SUCCESS) {
185aa71728867671e105178b4c66fbc22b65ae26sf ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(00034)
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe "dir_walk error, could not determine the root "
4f9c22c4f27571d54197be9674e1fc0d528192aestriker "path of filename %s%s for uri %s",
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe r->filename, r->path_info, r->uri);
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe return HTTP_INTERNAL_SERVER_ERROR;
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe }
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe /* Working space for terminating null and an extra / is required.
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe */
0e58e92812f2f679d6bf2ff66cbcfa6c1d1e14bbjerenkrantz buflen = filename_len + strlen(r->path_info) + 2;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe buf = apr_palloc(r->pool, buflen);
0e58e92812f2f679d6bf2ff66cbcfa6c1d1e14bbjerenkrantz memcpy(buf, r->filename, filename_len + 1);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe r->filename = buf;
cf6ef072483172309861d06e85b1aeff4573c060wrowe thisinfo.valid = APR_FINFO_TYPE;
cf6ef072483172309861d06e85b1aeff4573c060wrowe thisinfo.filetype = APR_DIR; /* It's the root, of course it's a dir */
8aefbd756763807188d2e3ce336a8680e4893066wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /*
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * seg keeps track of which segment we've copied.
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * sec_idx keeps track of which section we're on, since sections are
4f9c22c4f27571d54197be9674e1fc0d528192aestriker * ordered by number of segments. See core_reorder_directories
700b96db75e7cfadb5219978c1735b710d583763wrowe * startseg tells us how many segments describe the root path
700b96db75e7cfadb5219978c1735b710d583763wrowe * e.g. the complete path "//host/foo/" to a UNC share (4)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe startseg = seg = ap_count_dirs(r->filename);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe sec_idx = 0;
cf6ef072483172309861d06e85b1aeff4573c060wrowe
cf6ef072483172309861d06e85b1aeff4573c060wrowe /*
4f9c22c4f27571d54197be9674e1fc0d528192aestriker * Go down the directory hierarchy. Where we have to check for
4f9c22c4f27571d54197be9674e1fc0d528192aestriker * symlinks, do so. Where a .htaccess file has permission to
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz * override anything, try to find one.
cf6ef072483172309861d06e85b1aeff4573c060wrowe */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe do {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe int res;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe char *seg_name;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe char *delim;
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz int temp_slash=0;
4f9c22c4f27571d54197be9674e1fc0d528192aestriker
548b2980e83f609186a76e98fb245d02e8547bc3jerenkrantz /* We have no trailing slash, but we sure would appreciate one.
548b2980e83f609186a76e98fb245d02e8547bc3jerenkrantz * However, we don't want to append a / our first time through.
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe */
548b2980e83f609186a76e98fb245d02e8547bc3jerenkrantz if ((seg > startseg) && r->filename[filename_len-1] != '/') {
0e58e92812f2f679d6bf2ff66cbcfa6c1d1e14bbjerenkrantz r->filename[filename_len++] = '/';
0e58e92812f2f679d6bf2ff66cbcfa6c1d1e14bbjerenkrantz r->filename[filename_len] = 0;
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz temp_slash=1;
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* Begin *this* level by looking for matching <Directory> sections
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * from the server config.
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe for (; sec_idx < num_sec; ++sec_idx) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_conf_vector_t *entry_config = sec_ent[sec_idx];
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe core_dir_config *entry_core;
7184de27ec1d62a83c41cdeac0953ca9fd661e8csf entry_core = ap_get_core_module_config(entry_config);
8aefbd756763807188d2e3ce336a8680e4893066wrowe
4f9c22c4f27571d54197be9674e1fc0d528192aestriker /* No more possible matches for this many segments?
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * We are done when we find relative/regex/longer components.
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe */
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar if (entry_core->r || entry_core->d_components > seg) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe break;
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* We will never skip '0' element components, e.g. plain old
4f9c22c4f27571d54197be9674e1fc0d528192aestriker * <Directory >, and <Directory "/"> are classified as zero
4a13940dc2990df0a798718d3a3f9cf1566c2217bjh * so that Win32/Netware/OS2 etc all pick them up.
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * Otherwise, skip over the mismatches.
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (entry_core->d_components
f08810eff40a2bddd2bc0103453c4ae775ea62bewrowe && ((entry_core->d_components < seg)
f08810eff40a2bddd2bc0103453c4ae775ea62bewrowe || (entry_core->d_is_fnmatch
f08810eff40a2bddd2bc0103453c4ae775ea62bewrowe ? (apr_fnmatch(entry_core->d, r->filename,
1fbf6ba0f5207e6637b49f9a9dfcc779bbe952a9trawick APR_FNM_PATHNAME) != APR_SUCCESS)
f08810eff40a2bddd2bc0103453c4ae775ea62bewrowe : (strcmp(r->filename, entry_core->d) != 0)))) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe continue;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
700b96db75e7cfadb5219978c1735b710d583763wrowe /* If we haven't continue'd above, we have a match.
700b96db75e7cfadb5219978c1735b710d583763wrowe *
700b96db75e7cfadb5219978c1735b710d583763wrowe * Calculate our full-context core opts & override.
700b96db75e7cfadb5219978c1735b710d583763wrowe */
700b96db75e7cfadb5219978c1735b710d583763wrowe core_opts_merge(sec_ent[sec_idx], &opts);
700b96db75e7cfadb5219978c1735b710d583763wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* If we merged this same section last time, reuse it
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (matches) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (last_walk->matched == sec_ent[sec_idx]) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe now_merged = last_walk->merged;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ++last_walk;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe --matches;
700b96db75e7cfadb5219978c1735b710d583763wrowe continue;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
4f9c22c4f27571d54197be9674e1fc0d528192aestriker
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* We fell out of sync. This is our own copy of walked,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * so truncate the remaining matches and reset remaining.
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe cache->walked->nelts -= matches;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe matches = 0;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd cached = 0;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar if (now_merged) {
4f9c22c4f27571d54197be9674e1fc0d528192aestriker now_merged = ap_merge_per_dir_configs(r->pool,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe now_merged,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe sec_ent[sec_idx]);
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar }
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar else {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe now_merged = sec_ent[sec_idx];
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe last_walk = (walk_walked_t*)apr_array_push(cache->walked);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe last_walk->matched = sec_ent[sec_idx];
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe last_walk->merged = now_merged;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* If .htaccess files are enabled, check for one, provided we
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * have reached a real path.
8aefbd756763807188d2e3ce336a8680e4893066wrowe */
700b96db75e7cfadb5219978c1735b710d583763wrowe do { /* Not really a loop, just a break'able code block */
700b96db75e7cfadb5219978c1735b710d583763wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_conf_vector_t *htaccess_conf = NULL;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e8f95a682820a599fe41b22977010636be5c2717jim /* No htaccess in an incomplete root path,
e8f95a682820a599fe41b22977010636be5c2717jim * nor if it's disabled
700b96db75e7cfadb5219978c1735b710d583763wrowe */
113961f0559eb026ea0d379cb7350f82bc09d710druggeri if (seg < startseg || (!opts.override && opts.override_list == NULL)) {
700b96db75e7cfadb5219978c1735b710d583763wrowe break;
700b96db75e7cfadb5219978c1735b710d583763wrowe }
700b96db75e7cfadb5219978c1735b710d583763wrowe
113961f0559eb026ea0d379cb7350f82bc09d710druggeri
700b96db75e7cfadb5219978c1735b710d583763wrowe res = ap_parse_htaccess(&htaccess_conf, r, opts.override,
113961f0559eb026ea0d379cb7350f82bc09d710druggeri opts.override_opts, opts.override_list,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe apr_pstrdup(r->pool, r->filename),
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe sconf->access_name);
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar if (res) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe return res;
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
700b96db75e7cfadb5219978c1735b710d583763wrowe if (!htaccess_conf) {
700b96db75e7cfadb5219978c1735b710d583763wrowe break;
700b96db75e7cfadb5219978c1735b710d583763wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
700b96db75e7cfadb5219978c1735b710d583763wrowe /* If we are still here, we found our htaccess.
700b96db75e7cfadb5219978c1735b710d583763wrowe *
700b96db75e7cfadb5219978c1735b710d583763wrowe * Calculate our full-context core opts & override.
700b96db75e7cfadb5219978c1735b710d583763wrowe */
700b96db75e7cfadb5219978c1735b710d583763wrowe core_opts_merge(htaccess_conf, &opts);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
700b96db75e7cfadb5219978c1735b710d583763wrowe /* If we merged this same htaccess last time, reuse it...
700b96db75e7cfadb5219978c1735b710d583763wrowe * this wouldn't work except that we cache the htaccess
700b96db75e7cfadb5219978c1735b710d583763wrowe * sections for the lifetime of the request, so we match
700b96db75e7cfadb5219978c1735b710d583763wrowe * the same conf. Good planning (no, pure luck ;)
700b96db75e7cfadb5219978c1735b710d583763wrowe */
700b96db75e7cfadb5219978c1735b710d583763wrowe if (matches) {
700b96db75e7cfadb5219978c1735b710d583763wrowe if (last_walk->matched == htaccess_conf) {
700b96db75e7cfadb5219978c1735b710d583763wrowe now_merged = last_walk->merged;
700b96db75e7cfadb5219978c1735b710d583763wrowe ++last_walk;
700b96db75e7cfadb5219978c1735b710d583763wrowe --matches;
700b96db75e7cfadb5219978c1735b710d583763wrowe break;
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
700b96db75e7cfadb5219978c1735b710d583763wrowe /* We fell out of sync. This is our own copy of walked,
700b96db75e7cfadb5219978c1735b710d583763wrowe * so truncate the remaining matches and reset
700b96db75e7cfadb5219978c1735b710d583763wrowe * remaining.
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe */
700b96db75e7cfadb5219978c1735b710d583763wrowe cache->walked->nelts -= matches;
700b96db75e7cfadb5219978c1735b710d583763wrowe matches = 0;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd cached = 0;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
700b96db75e7cfadb5219978c1735b710d583763wrowe
700b96db75e7cfadb5219978c1735b710d583763wrowe if (now_merged) {
700b96db75e7cfadb5219978c1735b710d583763wrowe now_merged = ap_merge_per_dir_configs(r->pool,
700b96db75e7cfadb5219978c1735b710d583763wrowe now_merged,
700b96db75e7cfadb5219978c1735b710d583763wrowe htaccess_conf);
700b96db75e7cfadb5219978c1735b710d583763wrowe }
700b96db75e7cfadb5219978c1735b710d583763wrowe else {
700b96db75e7cfadb5219978c1735b710d583763wrowe now_merged = htaccess_conf;
700b96db75e7cfadb5219978c1735b710d583763wrowe }
700b96db75e7cfadb5219978c1735b710d583763wrowe
700b96db75e7cfadb5219978c1735b710d583763wrowe last_walk = (walk_walked_t*)apr_array_push(cache->walked);
700b96db75e7cfadb5219978c1735b710d583763wrowe last_walk->matched = htaccess_conf;
700b96db75e7cfadb5219978c1735b710d583763wrowe last_walk->merged = now_merged;
700b96db75e7cfadb5219978c1735b710d583763wrowe
700b96db75e7cfadb5219978c1735b710d583763wrowe } while (0); /* Only one htaccess, not a real loop */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* That temporary trailing slash was useful, now drop it.
8aefbd756763807188d2e3ce336a8680e4893066wrowe */
2520f59894a3e07fefa881ef68aaded763a8d447ben if (temp_slash) {
0e58e92812f2f679d6bf2ff66cbcfa6c1d1e14bbjerenkrantz r->filename[--filename_len] = '\0';
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* Time for all good things to come to an end?
8aefbd756763807188d2e3ce336a8680e4893066wrowe */
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar if (!r->path_info || !*r->path_info) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe break;
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
4f9c22c4f27571d54197be9674e1fc0d528192aestriker /* Now it's time for the next segment...
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * We will assume the next element is an end node, and fix it up
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * below as necessary...
8aefbd756763807188d2e3ce336a8680e4893066wrowe */
4f9c22c4f27571d54197be9674e1fc0d528192aestriker
0e58e92812f2f679d6bf2ff66cbcfa6c1d1e14bbjerenkrantz seg_name = r->filename + filename_len;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe delim = strchr(r->path_info + (*r->path_info == '/' ? 1 : 0), '/');
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (delim) {
b02dfdb611f84136664b3c05e4d4d704aeabbf63wrowe apr_size_t path_info_len = delim - r->path_info;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe *delim = '\0';
0e58e92812f2f679d6bf2ff66cbcfa6c1d1e14bbjerenkrantz memcpy(seg_name, r->path_info, path_info_len + 1);
0e58e92812f2f679d6bf2ff66cbcfa6c1d1e14bbjerenkrantz filename_len += path_info_len;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe r->path_info = delim;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe *delim = '/';
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe else {
b02dfdb611f84136664b3c05e4d4d704aeabbf63wrowe apr_size_t path_info_len = strlen(r->path_info);
0e58e92812f2f679d6bf2ff66cbcfa6c1d1e14bbjerenkrantz memcpy(seg_name, r->path_info, path_info_len + 1);
0e58e92812f2f679d6bf2ff66cbcfa6c1d1e14bbjerenkrantz filename_len += path_info_len;
0e58e92812f2f679d6bf2ff66cbcfa6c1d1e14bbjerenkrantz r->path_info += path_info_len;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
4f9c22c4f27571d54197be9674e1fc0d528192aestriker if (*seg_name == '/')
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ++seg_name;
4f9c22c4f27571d54197be9674e1fc0d528192aestriker
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* If nothing remained but a '/' string, we are finished
ecde48c75338ff5712f2036711f813c6dedca28ewrowe * XXX: NO WE ARE NOT!!! Now process this puppy!!! */
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar if (!*seg_name) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe break;
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
cf6ef072483172309861d06e85b1aeff4573c060wrowe /* First optimization;
cf6ef072483172309861d06e85b1aeff4573c060wrowe * If...we knew r->filename was a file, and
cf6ef072483172309861d06e85b1aeff4573c060wrowe * if...we have strict (case-sensitive) filenames, or
cf6ef072483172309861d06e85b1aeff4573c060wrowe * we know the canonical_filename matches to _this_ name, and
cf6ef072483172309861d06e85b1aeff4573c060wrowe * if...we have allowed symlinks
cf6ef072483172309861d06e85b1aeff4573c060wrowe * skip the lstat and dummy up an APR_DIR value for thisinfo.
cf6ef072483172309861d06e85b1aeff4573c060wrowe */
2d4ea77e21ef7f3707d2c27f6117cc0a36e99b83trawick if (r->finfo.filetype != APR_NOFILE
cf6ef072483172309861d06e85b1aeff4573c060wrowe#ifdef CASE_BLIND_FILESYSTEM
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe && (filename_len <= canonical_len)
cf6ef072483172309861d06e85b1aeff4573c060wrowe#endif
700b96db75e7cfadb5219978c1735b710d583763wrowe && ((opts.opts & (OPT_SYM_OWNER | OPT_SYM_LINKS)) == OPT_SYM_LINKS))
69adb3d949e3dd17c0492a01fc2cf298832c7eefwrowe {
69adb3d949e3dd17c0492a01fc2cf298832c7eefwrowe
cf6ef072483172309861d06e85b1aeff4573c060wrowe thisinfo.filetype = APR_DIR;
cf6ef072483172309861d06e85b1aeff4573c060wrowe ++seg;
cf6ef072483172309861d06e85b1aeff4573c060wrowe continue;
cf6ef072483172309861d06e85b1aeff4573c060wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e8f95a682820a599fe41b22977010636be5c2717jim /* We choose apr_stat with flag APR_FINFO_LINK here, rather that
1fbf6ba0f5207e6637b49f9a9dfcc779bbe952a9trawick * plain apr_stat, so that we capture this path object rather than
e8f95a682820a599fe41b22977010636be5c2717jim * its target. We will replace the info with our target's info
e8f95a682820a599fe41b22977010636be5c2717jim * below. We especially want the name of this 'link' object, not
e8f95a682820a599fe41b22977010636be5c2717jim * the name of its target, if we are fixing the filename
1fbf6ba0f5207e6637b49f9a9dfcc779bbe952a9trawick * case/resolving aliases.
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe */
f4ca9f6f002fece336168a16355434ca966f96a9trawick rv = ap_run_dirwalk_stat(&thisinfo, r,
f4ca9f6f002fece336168a16355434ca966f96a9trawick APR_FINFO_MIN | APR_FINFO_NAME | APR_FINFO_LINK);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (APR_STATUS_IS_ENOENT(rv)) {
c2cf53a40a9814eb91db2cdf820f97d943f21628coar /* Nothing? That could be nice. But our directory
c2cf53a40a9814eb91db2cdf820f97d943f21628coar * walk is done.
8aefbd756763807188d2e3ce336a8680e4893066wrowe */
cf6ef072483172309861d06e85b1aeff4573c060wrowe thisinfo.filetype = APR_NOFILE;
8aefbd756763807188d2e3ce336a8680e4893066wrowe break;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe else if (APR_STATUS_IS_EACCES(rv)) {
185aa71728867671e105178b4c66fbc22b65ae26sf ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(00035)
44761f3e3072cf78a4997a88bb9a515ca101a1f4covener "access to %s denied (filesystem path '%s') "
44761f3e3072cf78a4997a88bb9a515ca101a1f4covener "because search permissions are missing on a "
44761f3e3072cf78a4997a88bb9a515ca101a1f4covener "component of the path", r->uri, r->filename);
8aefbd756763807188d2e3ce336a8680e4893066wrowe return r->status = HTTP_FORBIDDEN;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
4f9c22c4f27571d54197be9674e1fc0d528192aestriker else if ((rv != APR_SUCCESS && rv != APR_INCOMPLETE)
cf6ef072483172309861d06e85b1aeff4573c060wrowe || !(thisinfo.valid & APR_FINFO_TYPE)) {
4f9c22c4f27571d54197be9674e1fc0d528192aestriker /* If we hit ENOTDIR, we must have over-optimized, deny
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * rather than assume not found.
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe */
185aa71728867671e105178b4c66fbc22b65ae26sf ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(00036)
44761f3e3072cf78a4997a88bb9a515ca101a1f4covener "access to %s failed (filesystem path '%s')",
44761f3e3072cf78a4997a88bb9a515ca101a1f4covener r->uri, r->filename);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe return r->status = HTTP_FORBIDDEN;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
69adb3d949e3dd17c0492a01fc2cf298832c7eefwrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* Fix up the path now if we have a name, and they don't agree
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe */
4f9c22c4f27571d54197be9674e1fc0d528192aestriker if ((thisinfo.valid & APR_FINFO_NAME)
cf6ef072483172309861d06e85b1aeff4573c060wrowe && strcmp(seg_name, thisinfo.name)) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* TODO: provide users an option that an internal/external
cadddb2c31d24d48f4017db4df0a29687432326cwrowe * redirect is required here? We need to walk the URI and
cadddb2c31d24d48f4017db4df0a29687432326cwrowe * filename in tandem to properly correlate these.
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe */
cf6ef072483172309861d06e85b1aeff4573c060wrowe strcpy(seg_name, thisinfo.name);
0e58e92812f2f679d6bf2ff66cbcfa6c1d1e14bbjerenkrantz filename_len = strlen(r->filename);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
cf6ef072483172309861d06e85b1aeff4573c060wrowe if (thisinfo.filetype == APR_LNK) {
cf6ef072483172309861d06e85b1aeff4573c060wrowe /* Is this a possibly acceptable symlink?
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe */
4f9c22c4f27571d54197be9674e1fc0d528192aestriker if ((res = resolve_symlink(r->filename, &thisinfo,
700b96db75e7cfadb5219978c1735b710d583763wrowe opts.opts, r->pool)) != OK) {
185aa71728867671e105178b4c66fbc22b65ae26sf ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00037)
71fe373d064756fb261876443806ece033ee3309slive "Symbolic link not allowed "
71fe373d064756fb261876443806ece033ee3309slive "or link target not accessible: %s",
c2cf53a40a9814eb91db2cdf820f97d943f21628coar r->filename);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe return r->status = res;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
ecde48c75338ff5712f2036711f813c6dedca28ewrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
ecde48c75338ff5712f2036711f813c6dedca28ewrowe /* Ok, we are done with the link's info, test the real target
ecde48c75338ff5712f2036711f813c6dedca28ewrowe */
e8f95a682820a599fe41b22977010636be5c2717jim if (thisinfo.filetype == APR_REG ||
ecde48c75338ff5712f2036711f813c6dedca28ewrowe thisinfo.filetype == APR_NOFILE) {
ecde48c75338ff5712f2036711f813c6dedca28ewrowe /* That was fun, nothing left for us here
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe */
ecde48c75338ff5712f2036711f813c6dedca28ewrowe break;
ecde48c75338ff5712f2036711f813c6dedca28ewrowe }
ecde48c75338ff5712f2036711f813c6dedca28ewrowe else if (thisinfo.filetype != APR_DIR) {
185aa71728867671e105178b4c66fbc22b65ae26sf ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00038)
ecde48c75338ff5712f2036711f813c6dedca28ewrowe "Forbidden: %s doesn't point to "
ecde48c75338ff5712f2036711f813c6dedca28ewrowe "a file or directory",
ecde48c75338ff5712f2036711f813c6dedca28ewrowe r->filename);
ecde48c75338ff5712f2036711f813c6dedca28ewrowe return r->status = HTTP_FORBIDDEN;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ++seg;
cf6ef072483172309861d06e85b1aeff4573c060wrowe } while (thisinfo.filetype == APR_DIR);
cf6ef072483172309861d06e85b1aeff4573c060wrowe
cf6ef072483172309861d06e85b1aeff4573c060wrowe /* If we have _not_ optimized, this is the time to recover
cf6ef072483172309861d06e85b1aeff4573c060wrowe * the final stat result.
cf6ef072483172309861d06e85b1aeff4573c060wrowe */
2d4ea77e21ef7f3707d2c27f6117cc0a36e99b83trawick if (r->finfo.filetype == APR_NOFILE || r->finfo.filetype == APR_LNK) {
cf6ef072483172309861d06e85b1aeff4573c060wrowe r->finfo = thisinfo;
cf6ef072483172309861d06e85b1aeff4573c060wrowe }
cf6ef072483172309861d06e85b1aeff4573c060wrowe
cf6ef072483172309861d06e85b1aeff4573c060wrowe /* Now splice the saved path_info back onto any new path_info
cf6ef072483172309861d06e85b1aeff4573c060wrowe */
cf6ef072483172309861d06e85b1aeff4573c060wrowe if (save_path_info) {
cf6ef072483172309861d06e85b1aeff4573c060wrowe if (r->path_info && *r->path_info) {
4f9c22c4f27571d54197be9674e1fc0d528192aestriker r->path_info = ap_make_full_path(r->pool, r->path_info,
cf6ef072483172309861d06e85b1aeff4573c060wrowe save_path_info);
cf6ef072483172309861d06e85b1aeff4573c060wrowe }
cf6ef072483172309861d06e85b1aeff4573c060wrowe else {
cf6ef072483172309861d06e85b1aeff4573c060wrowe r->path_info = save_path_info;
cf6ef072483172309861d06e85b1aeff4573c060wrowe }
cf6ef072483172309861d06e85b1aeff4573c060wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /*
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * Now we'll deal with the regexes, note we pick up sec_idx
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * where we left off (we gave up after we hit entry_core->r)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe for (; sec_idx < num_sec; ++sec_idx) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin int nmatch = 0;
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin int i;
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin ap_regmatch_t *pmatch = NULL;
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin
4f9c22c4f27571d54197be9674e1fc0d528192aestriker core_dir_config *entry_core;
7184de27ec1d62a83c41cdeac0953ca9fd661e8csf entry_core = ap_get_core_module_config(sec_ent[sec_idx]);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar if (!entry_core->r) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe continue;
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin if (entry_core->refs && entry_core->refs->nelts) {
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin if (!rxpool) {
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin apr_pool_create(&rxpool, r->pool);
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin }
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin nmatch = entry_core->refs->nelts;
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin pmatch = apr_palloc(rxpool, nmatch*sizeof(ap_regmatch_t));
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin }
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin if (ap_regexec(entry_core->r, r->filename, nmatch, pmatch, 0)) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe continue;
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin for (i = 0; i < nmatch; i++) {
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin if (pmatch[i].rm_so >= 0 && pmatch[i].rm_eo >= 0 &&
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin ((const char **)entry_core->refs->elts)[i]) {
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin apr_table_setn(r->subprocess_env,
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin ((const char **)entry_core->refs->elts)[i],
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin apr_pstrndup(r->pool,
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin r->filename + pmatch[i].rm_so,
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin pmatch[i].rm_eo - pmatch[i].rm_so));
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin }
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin }
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin
700b96db75e7cfadb5219978c1735b710d583763wrowe /* If we haven't already continue'd above, we have a match.
700b96db75e7cfadb5219978c1735b710d583763wrowe *
700b96db75e7cfadb5219978c1735b710d583763wrowe * Calculate our full-context core opts & override.
700b96db75e7cfadb5219978c1735b710d583763wrowe */
700b96db75e7cfadb5219978c1735b710d583763wrowe core_opts_merge(sec_ent[sec_idx], &opts);
700b96db75e7cfadb5219978c1735b710d583763wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* If we merged this same section last time, reuse it
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (matches) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (last_walk->matched == sec_ent[sec_idx]) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe now_merged = last_walk->merged;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ++last_walk;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe --matches;
700b96db75e7cfadb5219978c1735b710d583763wrowe continue;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
4f9c22c4f27571d54197be9674e1fc0d528192aestriker
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* We fell out of sync. This is our own copy of walked,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * so truncate the remaining matches and reset remaining.
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe cache->walked->nelts -= matches;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe matches = 0;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd cached = 0;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar if (now_merged) {
4f9c22c4f27571d54197be9674e1fc0d528192aestriker now_merged = ap_merge_per_dir_configs(r->pool,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe now_merged,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe sec_ent[sec_idx]);
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar }
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar else {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe now_merged = sec_ent[sec_idx];
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe last_walk = (walk_walked_t*)apr_array_push(cache->walked);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe last_walk->matched = sec_ent[sec_idx];
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe last_walk->merged = now_merged;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin if (rxpool) {
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin apr_pool_destroy(rxpool);
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin }
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd /* Whoops - everything matched in sequence, but either the original
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd * walk found some additional matches (which we need to truncate), or
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd * this walk found some additional matches.
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe */
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar if (matches) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe cache->walked->nelts -= matches;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd cached = 0;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd }
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd else if (cache->walked->nelts > cached_matches) {
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd cached = 0;
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar }
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
c2cf53a40a9814eb91db2cdf820f97d943f21628coar/* It seems this shouldn't be needed anymore. We translated the
c2cf53a40a9814eb91db2cdf820f97d943f21628coar x symlink above into a real resource, and should have died up there.
c2cf53a40a9814eb91db2cdf820f97d943f21628coar x Even if we keep this, it needs more thought (maybe an r->file_is_symlink)
c2cf53a40a9814eb91db2cdf820f97d943f21628coar x perhaps it should actually happen in file_walk, so we catch more
0ec08ecdcb42129d147888bda504787b164da39cerikabele x obscure cases in autoindex subrequests, etc.
8aefbd756763807188d2e3ce336a8680e4893066wrowe x
8aefbd756763807188d2e3ce336a8680e4893066wrowe x * Symlink permissions are determined by the parent. If the request is
8aefbd756763807188d2e3ce336a8680e4893066wrowe x * for a directory then applying the symlink test here would use the
8aefbd756763807188d2e3ce336a8680e4893066wrowe x * permissions of the directory as opposed to its parent. Consider a
8aefbd756763807188d2e3ce336a8680e4893066wrowe x * symlink pointing to a dir with a .htaccess disallowing symlinks. If
8aefbd756763807188d2e3ce336a8680e4893066wrowe x * you access /symlink (or /symlink/) you would get a 403 without this
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe x * APR_DIR test. But if you accessed /symlink/index.html, for example,
8aefbd756763807188d2e3ce336a8680e4893066wrowe x * you would *not* get the 403.
8aefbd756763807188d2e3ce336a8680e4893066wrowe x
8aefbd756763807188d2e3ce336a8680e4893066wrowe x if (r->finfo.filetype != APR_DIR
c2cf53a40a9814eb91db2cdf820f97d943f21628coar x && (res = resolve_symlink(r->filename, r->info, ap_allow_options(r),
c2cf53a40a9814eb91db2cdf820f97d943f21628coar x r->pool))) {
2d399cd7535887fceaa9f8f116eb98ce68ddd602trawick x ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
c2cf53a40a9814eb91db2cdf820f97d943f21628coar x "Symbolic link not allowed: %s", r->filename);
8aefbd756763807188d2e3ce336a8680e4893066wrowe x return res;
8aefbd756763807188d2e3ce336a8680e4893066wrowe x }
8aefbd756763807188d2e3ce336a8680e4893066wrowe */
8aefbd756763807188d2e3ce336a8680e4893066wrowe
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe /* Save future sub-requestors much angst in processing
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe * this subrequest. If dir_walk couldn't canonicalize
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe * the file path, nothing can.
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe */
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe r->canonical_filename = r->filename;
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar if (r->finfo.filetype == APR_DIR) {
0540a0b469147b52e858587270dba31c2aaa9e09wrowe cache->cached = r->filename;
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar }
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar else {
0540a0b469147b52e858587270dba31c2aaa9e09wrowe cache->cached = ap_make_dirstr_parent(r->pool, r->filename);
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar }
0540a0b469147b52e858587270dba31c2aaa9e09wrowe
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd if (cached
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd && r->per_dir_config == cache->dir_conf_merged) {
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd r->per_dir_config = cache->per_dir_result;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd return OK;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd }
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd
0540a0b469147b52e858587270dba31c2aaa9e09wrowe cache->dir_conf_tested = sec_ent;
a9a4544168a37b43bd180b3703ccee995f27a80awrowe cache->dir_conf_merged = r->per_dir_config;
0540a0b469147b52e858587270dba31c2aaa9e09wrowe
0540a0b469147b52e858587270dba31c2aaa9e09wrowe /* Merge our cache->dir_conf_merged construct with the r->per_dir_configs,
0540a0b469147b52e858587270dba31c2aaa9e09wrowe * and note the end result to (potentially) skip this step next time.
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe */
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar if (now_merged) {
0540a0b469147b52e858587270dba31c2aaa9e09wrowe r->per_dir_config = ap_merge_per_dir_configs(r->pool,
0540a0b469147b52e858587270dba31c2aaa9e09wrowe r->per_dir_config,
0540a0b469147b52e858587270dba31c2aaa9e09wrowe now_merged);
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar }
0540a0b469147b52e858587270dba31c2aaa9e09wrowe cache->per_dir_result = r->per_dir_config;
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe
0540a0b469147b52e858587270dba31c2aaa9e09wrowe return OK;
8aefbd756763807188d2e3ce336a8680e4893066wrowe}
8aefbd756763807188d2e3ce336a8680e4893066wrowe
0540a0b469147b52e858587270dba31c2aaa9e09wrowe
a2a0abd88b19e042a3eb2a9fa1702c25ad51303dwroweAP_DECLARE(int) ap_location_walk(request_rec *r)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
948096a99010fccf648814fecf38f75c689172d7wrowe ap_conf_vector_t *now_merged = NULL;
7184de27ec1d62a83c41cdeac0953ca9fd661e8csf core_server_config *sconf =
7184de27ec1d62a83c41cdeac0953ca9fd661e8csf ap_get_core_module_config(r->server->module_config);
4f9c22c4f27571d54197be9674e1fc0d528192aestriker ap_conf_vector_t **sec_ent = (ap_conf_vector_t **)sconf->sec_url->elts;
0540a0b469147b52e858587270dba31c2aaa9e09wrowe int num_sec = sconf->sec_url->nelts;
948096a99010fccf648814fecf38f75c689172d7wrowe walk_cache_t *cache;
948096a99010fccf648814fecf38f75c689172d7wrowe const char *entry_uri;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd int cached;
948096a99010fccf648814fecf38f75c689172d7wrowe
948096a99010fccf648814fecf38f75c689172d7wrowe /* No tricks here, there are no <Locations > to parse in this vhost.
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe * We won't destroy the cache, just in case _this_ redirect is later
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe * redirected again to a vhost with <Location > blocks to optimize.
053497224246c4dbef9af594cacf5c00ed271e6cwrowe */
0540a0b469147b52e858587270dba31c2aaa9e09wrowe if (!num_sec) {
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz return OK;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
42da244268b11ec661b528510f80a18b73c51727brianp cache = prep_walk_cache(AP_NOTE_LOCATION_WALK, r);
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd cached = (cache->cached != NULL);
42da244268b11ec661b528510f80a18b73c51727brianp
948096a99010fccf648814fecf38f75c689172d7wrowe /* Location and LocationMatch differ on their behaviour w.r.t. multiple
948096a99010fccf648814fecf38f75c689172d7wrowe * slashes. Location matches multiple slashes with a single slash,
948096a99010fccf648814fecf38f75c689172d7wrowe * LocationMatch doesn't. An exception, for backwards brokenness is
948096a99010fccf648814fecf38f75c689172d7wrowe * absoluteURIs... in which case neither match multiple slashes.
948096a99010fccf648814fecf38f75c689172d7wrowe */
948096a99010fccf648814fecf38f75c689172d7wrowe if (r->uri[0] != '/') {
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz entry_uri = r->uri;
948096a99010fccf648814fecf38f75c689172d7wrowe }
948096a99010fccf648814fecf38f75c689172d7wrowe else {
948096a99010fccf648814fecf38f75c689172d7wrowe char *uri = apr_pstrdup(r->pool, r->uri);
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz ap_no2slash(uri);
948096a99010fccf648814fecf38f75c689172d7wrowe entry_uri = uri;
948096a99010fccf648814fecf38f75c689172d7wrowe }
053497224246c4dbef9af594cacf5c00ed271e6cwrowe
948096a99010fccf648814fecf38f75c689172d7wrowe /* If we have an cache->cached location that matches r->uri,
948096a99010fccf648814fecf38f75c689172d7wrowe * and the vhost's list of locations hasn't changed, we can skip
948096a99010fccf648814fecf38f75c689172d7wrowe * rewalking the location_walk entries.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd if (cached
4f9c22c4f27571d54197be9674e1fc0d528192aestriker && (cache->dir_conf_tested == sec_ent)
c2cf53a40a9814eb91db2cdf820f97d943f21628coar && (strcmp(entry_uri, cache->cached) == 0)) {
948096a99010fccf648814fecf38f75c689172d7wrowe /* Well this looks really familiar! If our end-result (per_dir_result)
4f9c22c4f27571d54197be9674e1fc0d528192aestriker * didn't change, we have absolutely nothing to do :)
948096a99010fccf648814fecf38f75c689172d7wrowe * Otherwise (as is the case with most dir_merged/file_merged requests)
948096a99010fccf648814fecf38f75c689172d7wrowe * we must merge our dir_conf_merged onto this new r->per_dir_config.
053497224246c4dbef9af594cacf5c00ed271e6cwrowe */
a9a4544168a37b43bd180b3703ccee995f27a80awrowe if (r->per_dir_config == cache->per_dir_result) {
948096a99010fccf648814fecf38f75c689172d7wrowe return OK;
a9a4544168a37b43bd180b3703ccee995f27a80awrowe }
4f9c22c4f27571d54197be9674e1fc0d528192aestriker
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar if (cache->walked->nelts) {
948096a99010fccf648814fecf38f75c689172d7wrowe now_merged = ((walk_walked_t*)cache->walked->elts)
948096a99010fccf648814fecf38f75c689172d7wrowe [cache->walked->nelts - 1].merged;
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar }
948096a99010fccf648814fecf38f75c689172d7wrowe }
948096a99010fccf648814fecf38f75c689172d7wrowe else {
4f9c22c4f27571d54197be9674e1fc0d528192aestriker /* We start now_merged from NULL since we want to build
948096a99010fccf648814fecf38f75c689172d7wrowe * a locations list that can be merged to any vhost.
948096a99010fccf648814fecf38f75c689172d7wrowe */
aecb17a45c6d3ee4729ed5f68dc4270f211ee7a8fielding int len, sec_idx;
948096a99010fccf648814fecf38f75c689172d7wrowe int matches = cache->walked->nelts;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd int cached_matches = matches;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe walk_walked_t *last_walk = (walk_walked_t*)cache->walked->elts;
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin apr_pool_t *rxpool = NULL;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd cached &= auth_internal_per_conf;
948096a99010fccf648814fecf38f75c689172d7wrowe cache->cached = entry_uri;
948096a99010fccf648814fecf38f75c689172d7wrowe
948096a99010fccf648814fecf38f75c689172d7wrowe /* Go through the location entries, and check for matches.
948096a99010fccf648814fecf38f75c689172d7wrowe * We apply the directive sections in given order, we should
948096a99010fccf648814fecf38f75c689172d7wrowe * really try them with the most general first.
053497224246c4dbef9af594cacf5c00ed271e6cwrowe */
0540a0b469147b52e858587270dba31c2aaa9e09wrowe for (sec_idx = 0; sec_idx < num_sec; ++sec_idx) {
053497224246c4dbef9af594cacf5c00ed271e6cwrowe
4f9c22c4f27571d54197be9674e1fc0d528192aestriker core_dir_config *entry_core;
7184de27ec1d62a83c41cdeac0953ca9fd661e8csf entry_core = ap_get_core_module_config(sec_ent[sec_idx]);
4f9c22c4f27571d54197be9674e1fc0d528192aestriker
aa047239dedf0d26e8efecfade32e7337f35df19wrowe /* ### const strlen can be optimized in location config parsing */
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz len = strlen(entry_core->d);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
053497224246c4dbef9af594cacf5c00ed271e6cwrowe /* Test the regex, fnmatch or string as appropriate.
4f9c22c4f27571d54197be9674e1fc0d528192aestriker * If it's a strcmp, and the <Location > pattern was
053497224246c4dbef9af594cacf5c00ed271e6cwrowe * not slash terminated, then this uri must be slash
053497224246c4dbef9af594cacf5c00ed271e6cwrowe * terminated (or at the end of the string) to match.
053497224246c4dbef9af594cacf5c00ed271e6cwrowe */
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin if (entry_core->r) {
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin int nmatch = 0;
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin int i;
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin ap_regmatch_t *pmatch = NULL;
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin if (entry_core->refs && entry_core->refs->nelts) {
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin if (!rxpool) {
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin apr_pool_create(&rxpool, r->pool);
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin }
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin nmatch = entry_core->refs->nelts;
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin pmatch = apr_palloc(rxpool, nmatch*sizeof(ap_regmatch_t));
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin }
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin if (ap_regexec(entry_core->r, r->uri, nmatch, pmatch, 0)) {
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin continue;
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin }
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin for (i = 0; i < nmatch; i++) {
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin if (pmatch[i].rm_so >= 0 && pmatch[i].rm_eo >= 0 &&
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin ((const char **)entry_core->refs->elts)[i]) {
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin apr_table_setn(r->subprocess_env,
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin ((const char **)entry_core->refs->elts)[i],
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin apr_pstrndup(r->pool,
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin r->uri + pmatch[i].rm_so,
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin pmatch[i].rm_eo - pmatch[i].rm_so));
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin }
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin }
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin }
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin else {
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin if ((entry_core->d_is_fnmatch
1fbf6ba0f5207e6637b49f9a9dfcc779bbe952a9trawick ? apr_fnmatch(entry_core->d, cache->cached, APR_FNM_PATHNAME)
c2cf53a40a9814eb91db2cdf820f97d943f21628coar : (strncmp(entry_core->d, cache->cached, len)
b6b1df87b7ce62620d48526a7ab630897cdaad90chrisd || (len > 0
b6b1df87b7ce62620d48526a7ab630897cdaad90chrisd && entry_core->d[len - 1] != '/'
4f9c22c4f27571d54197be9674e1fc0d528192aestriker && cache->cached[len] != '/'
4f9c22c4f27571d54197be9674e1fc0d528192aestriker && cache->cached[len] != '\0')))) {
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin continue;
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin }
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin
053497224246c4dbef9af594cacf5c00ed271e6cwrowe }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
948096a99010fccf648814fecf38f75c689172d7wrowe /* If we merged this same section last time, reuse it
948096a99010fccf648814fecf38f75c689172d7wrowe */
948096a99010fccf648814fecf38f75c689172d7wrowe if (matches) {
0540a0b469147b52e858587270dba31c2aaa9e09wrowe if (last_walk->matched == sec_ent[sec_idx]) {
948096a99010fccf648814fecf38f75c689172d7wrowe now_merged = last_walk->merged;
948096a99010fccf648814fecf38f75c689172d7wrowe ++last_walk;
948096a99010fccf648814fecf38f75c689172d7wrowe --matches;
948096a99010fccf648814fecf38f75c689172d7wrowe continue;
948096a99010fccf648814fecf38f75c689172d7wrowe }
4f9c22c4f27571d54197be9674e1fc0d528192aestriker
948096a99010fccf648814fecf38f75c689172d7wrowe /* We fell out of sync. This is our own copy of walked,
948096a99010fccf648814fecf38f75c689172d7wrowe * so truncate the remaining matches and reset remaining.
948096a99010fccf648814fecf38f75c689172d7wrowe */
948096a99010fccf648814fecf38f75c689172d7wrowe cache->walked->nelts -= matches;
948096a99010fccf648814fecf38f75c689172d7wrowe matches = 0;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd cached = 0;
948096a99010fccf648814fecf38f75c689172d7wrowe }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar if (now_merged) {
4f9c22c4f27571d54197be9674e1fc0d528192aestriker now_merged = ap_merge_per_dir_configs(r->pool,
948096a99010fccf648814fecf38f75c689172d7wrowe now_merged,
0540a0b469147b52e858587270dba31c2aaa9e09wrowe sec_ent[sec_idx]);
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar }
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar else {
0540a0b469147b52e858587270dba31c2aaa9e09wrowe now_merged = sec_ent[sec_idx];
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar }
696218c49632c863d18b25fa52ab63617088cb38wrowe
948096a99010fccf648814fecf38f75c689172d7wrowe last_walk = (walk_walked_t*)apr_array_push(cache->walked);
0540a0b469147b52e858587270dba31c2aaa9e09wrowe last_walk->matched = sec_ent[sec_idx];
948096a99010fccf648814fecf38f75c689172d7wrowe last_walk->merged = now_merged;
948096a99010fccf648814fecf38f75c689172d7wrowe }
4f9c22c4f27571d54197be9674e1fc0d528192aestriker
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin if (rxpool) {
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin apr_pool_destroy(rxpool);
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin }
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd /* Whoops - everything matched in sequence, but either the original
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd * walk found some additional matches (which we need to truncate), or
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd * this walk found some additional matches.
053497224246c4dbef9af594cacf5c00ed271e6cwrowe */
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar if (matches) {
948096a99010fccf648814fecf38f75c689172d7wrowe cache->walked->nelts -= matches;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd cached = 0;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd }
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd else if (cache->walked->nelts > cached_matches) {
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd cached = 0;
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar }
053497224246c4dbef9af594cacf5c00ed271e6cwrowe }
053497224246c4dbef9af594cacf5c00ed271e6cwrowe
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd if (cached
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd && r->per_dir_config == cache->dir_conf_merged) {
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd r->per_dir_config = cache->per_dir_result;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd return OK;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd }
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd
a9a4544168a37b43bd180b3703ccee995f27a80awrowe cache->dir_conf_tested = sec_ent;
a9a4544168a37b43bd180b3703ccee995f27a80awrowe cache->dir_conf_merged = r->per_dir_config;
a9a4544168a37b43bd180b3703ccee995f27a80awrowe
948096a99010fccf648814fecf38f75c689172d7wrowe /* Merge our cache->dir_conf_merged construct with the r->per_dir_configs,
948096a99010fccf648814fecf38f75c689172d7wrowe * and note the end result to (potentially) skip this step next time.
053497224246c4dbef9af594cacf5c00ed271e6cwrowe */
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar if (now_merged) {
053497224246c4dbef9af594cacf5c00ed271e6cwrowe r->per_dir_config = ap_merge_per_dir_configs(r->pool,
053497224246c4dbef9af594cacf5c00ed271e6cwrowe r->per_dir_config,
948096a99010fccf648814fecf38f75c689172d7wrowe now_merged);
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar }
948096a99010fccf648814fecf38f75c689172d7wrowe cache->per_dir_result = r->per_dir_config;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return OK;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
a2a0abd88b19e042a3eb2a9fa1702c25ad51303dwroweAP_DECLARE(int) ap_file_walk(request_rec *r)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ap_conf_vector_t *now_merged = NULL;
7184de27ec1d62a83c41cdeac0953ca9fd661e8csf core_dir_config *dconf = ap_get_core_module_config(r->per_dir_config);
7a3c5fd3b3f86cdd450d551e326b3b9a04ea8248sf ap_conf_vector_t **sec_ent = NULL;
7a3c5fd3b3f86cdd450d551e326b3b9a04ea8248sf int num_sec = 0;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe walk_cache_t *cache;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe const char *test_file;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd int cached;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
7a3c5fd3b3f86cdd450d551e326b3b9a04ea8248sf if (dconf->sec_file) {
11e076839c8d5a82d55e710194d0daac51390dbdsf sec_ent = (ap_conf_vector_t **)dconf->sec_file->elts;
11e076839c8d5a82d55e710194d0daac51390dbdsf num_sec = dconf->sec_file->nelts;
7a3c5fd3b3f86cdd450d551e326b3b9a04ea8248sf }
7a3c5fd3b3f86cdd450d551e326b3b9a04ea8248sf
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe /* To allow broken modules to proceed, we allow missing filenames to pass.
4f9c22c4f27571d54197be9674e1fc0d528192aestriker * We will catch it later if it's heading for the core handler.
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe * directory_walk already posted an INFO note for module debugging.
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe */
b5bd19d82874782007a2f9bcb19341a483c1270cwrowe if (r->filename == NULL) {
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe return OK;
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe }
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe
a2b181763cb35fd899feb4a436aeadaa80bf91eabrianp cache = prep_walk_cache(AP_NOTE_FILE_WALK, r);
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd cached = (cache->cached != NULL);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe
aa047239dedf0d26e8efecfade32e7337f35df19wrowe /* No tricks here, there are just no <Files > to parse in this context.
aa047239dedf0d26e8efecfade32e7337f35df19wrowe * We won't destroy the cache, just in case _this_ redirect is later
aa047239dedf0d26e8efecfade32e7337f35df19wrowe * redirected again to a context containing the same or similar <Files >.
aa047239dedf0d26e8efecfade32e7337f35df19wrowe */
0540a0b469147b52e858587270dba31c2aaa9e09wrowe if (!num_sec) {
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz return OK;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe }
aa047239dedf0d26e8efecfade32e7337f35df19wrowe
4f9c22c4f27571d54197be9674e1fc0d528192aestriker /* Get the basename .. and copy for the cache just
aa047239dedf0d26e8efecfade32e7337f35df19wrowe * in case r->filename is munged by another module
aa047239dedf0d26e8efecfade32e7337f35df19wrowe */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb test_file = strrchr(r->filename, '/');
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (test_file == NULL) {
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz test_file = apr_pstrdup(r->pool, r->filename);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else {
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz test_file = apr_pstrdup(r->pool, ++test_file);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
aa047239dedf0d26e8efecfade32e7337f35df19wrowe /* If we have an cache->cached file name that matches test_file,
4f9c22c4f27571d54197be9674e1fc0d528192aestriker * and the directory's list of file sections hasn't changed, we
aa047239dedf0d26e8efecfade32e7337f35df19wrowe * can skip rewalking the file_walk entries.
aa047239dedf0d26e8efecfade32e7337f35df19wrowe */
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd if (cached
4f9c22c4f27571d54197be9674e1fc0d528192aestriker && (cache->dir_conf_tested == sec_ent)
c2cf53a40a9814eb91db2cdf820f97d943f21628coar && (strcmp(test_file, cache->cached) == 0)) {
aa047239dedf0d26e8efecfade32e7337f35df19wrowe /* Well this looks really familiar! If our end-result (per_dir_result)
4f9c22c4f27571d54197be9674e1fc0d528192aestriker * didn't change, we have absolutely nothing to do :)
aa047239dedf0d26e8efecfade32e7337f35df19wrowe * Otherwise (as is the case with most dir_merged requests)
aa047239dedf0d26e8efecfade32e7337f35df19wrowe * we must merge our dir_conf_merged onto this new r->per_dir_config.
aa047239dedf0d26e8efecfade32e7337f35df19wrowe */
a9a4544168a37b43bd180b3703ccee995f27a80awrowe if (r->per_dir_config == cache->per_dir_result) {
a9a4544168a37b43bd180b3703ccee995f27a80awrowe return OK;
a9a4544168a37b43bd180b3703ccee995f27a80awrowe }
4f9c22c4f27571d54197be9674e1fc0d528192aestriker
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar if (cache->walked->nelts) {
aa047239dedf0d26e8efecfade32e7337f35df19wrowe now_merged = ((walk_walked_t*)cache->walked->elts)
c2cf53a40a9814eb91db2cdf820f97d943f21628coar [cache->walked->nelts - 1].merged;
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar }
aa047239dedf0d26e8efecfade32e7337f35df19wrowe }
aa047239dedf0d26e8efecfade32e7337f35df19wrowe else {
4f9c22c4f27571d54197be9674e1fc0d528192aestriker /* We start now_merged from NULL since we want to build
aa047239dedf0d26e8efecfade32e7337f35df19wrowe * a file section list that can be merged to any dir_walk.
aa047239dedf0d26e8efecfade32e7337f35df19wrowe */
0540a0b469147b52e858587270dba31c2aaa9e09wrowe int sec_idx;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe int matches = cache->walked->nelts;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd int cached_matches = matches;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe walk_walked_t *last_walk = (walk_walked_t*)cache->walked->elts;
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin apr_pool_t *rxpool = NULL;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd cached &= auth_internal_per_conf;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe cache->cached = test_file;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
aa047239dedf0d26e8efecfade32e7337f35df19wrowe /* Go through the location entries, and check for matches.
aa047239dedf0d26e8efecfade32e7337f35df19wrowe * We apply the directive sections in given order, we should
aa047239dedf0d26e8efecfade32e7337f35df19wrowe * really try them with the most general first.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
0540a0b469147b52e858587270dba31c2aaa9e09wrowe for (sec_idx = 0; sec_idx < num_sec; ++sec_idx) {
0540a0b469147b52e858587270dba31c2aaa9e09wrowe core_dir_config *entry_core;
7184de27ec1d62a83c41cdeac0953ca9fd661e8csf entry_core = ap_get_core_module_config(sec_ent[sec_idx]);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin if (entry_core->r) {
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin int nmatch = 0;
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin int i;
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin ap_regmatch_t *pmatch = NULL;
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin if (entry_core->refs && entry_core->refs->nelts) {
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin if (!rxpool) {
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin apr_pool_create(&rxpool, r->pool);
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin }
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin nmatch = entry_core->refs->nelts;
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin pmatch = apr_palloc(rxpool, nmatch*sizeof(ap_regmatch_t));
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin }
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin if (ap_regexec(entry_core->r, cache->cached, nmatch, pmatch, 0)) {
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin continue;
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin }
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin for (i = 0; i < nmatch; i++) {
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin if (pmatch[i].rm_so >= 0 && pmatch[i].rm_eo >= 0 &&
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin ((const char **)entry_core->refs->elts)[i]) {
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin apr_table_setn(r->subprocess_env,
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin ((const char **)entry_core->refs->elts)[i],
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin apr_pstrndup(r->pool,
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin cache->cached + pmatch[i].rm_so,
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin pmatch[i].rm_eo - pmatch[i].rm_so));
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin }
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin }
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin }
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin else {
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin if ((entry_core->d_is_fnmatch
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin ? apr_fnmatch(entry_core->d, cache->cached, APR_FNM_PATHNAME)
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin : strcmp(entry_core->d, cache->cached))) {
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin continue;
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
aa047239dedf0d26e8efecfade32e7337f35df19wrowe
aa047239dedf0d26e8efecfade32e7337f35df19wrowe /* If we merged this same section last time, reuse it
aa047239dedf0d26e8efecfade32e7337f35df19wrowe */
aa047239dedf0d26e8efecfade32e7337f35df19wrowe if (matches) {
0540a0b469147b52e858587270dba31c2aaa9e09wrowe if (last_walk->matched == sec_ent[sec_idx]) {
aa047239dedf0d26e8efecfade32e7337f35df19wrowe now_merged = last_walk->merged;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ++last_walk;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe --matches;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe continue;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
4f9c22c4f27571d54197be9674e1fc0d528192aestriker
aa047239dedf0d26e8efecfade32e7337f35df19wrowe /* We fell out of sync. This is our own copy of walked,
aa047239dedf0d26e8efecfade32e7337f35df19wrowe * so truncate the remaining matches and reset remaining.
aa047239dedf0d26e8efecfade32e7337f35df19wrowe */
aa047239dedf0d26e8efecfade32e7337f35df19wrowe cache->walked->nelts -= matches;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe matches = 0;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd cached = 0;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar if (now_merged) {
4f9c22c4f27571d54197be9674e1fc0d528192aestriker now_merged = ap_merge_per_dir_configs(r->pool,
aa047239dedf0d26e8efecfade32e7337f35df19wrowe now_merged,
0540a0b469147b52e858587270dba31c2aaa9e09wrowe sec_ent[sec_idx]);
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar }
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar else {
0540a0b469147b52e858587270dba31c2aaa9e09wrowe now_merged = sec_ent[sec_idx];
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar }
aa047239dedf0d26e8efecfade32e7337f35df19wrowe
aa047239dedf0d26e8efecfade32e7337f35df19wrowe last_walk = (walk_walked_t*)apr_array_push(cache->walked);
0540a0b469147b52e858587270dba31c2aaa9e09wrowe last_walk->matched = sec_ent[sec_idx];
aa047239dedf0d26e8efecfade32e7337f35df19wrowe last_walk->merged = now_merged;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
4f9c22c4f27571d54197be9674e1fc0d528192aestriker
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin if (rxpool) {
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin apr_pool_destroy(rxpool);
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin }
a370a774825bc89fc6b0d8e45035a590e39b0bd6minfrin
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd /* Whoops - everything matched in sequence, but either the original
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd * walk found some additional matches (which we need to truncate), or
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd * this walk found some additional matches.
aa047239dedf0d26e8efecfade32e7337f35df19wrowe */
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar if (matches) {
aa047239dedf0d26e8efecfade32e7337f35df19wrowe cache->walked->nelts -= matches;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd cached = 0;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd }
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd else if (cache->walked->nelts > cached_matches) {
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd cached = 0;
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd if (cached
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd && r->per_dir_config == cache->dir_conf_merged) {
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd r->per_dir_config = cache->per_dir_result;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd return OK;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd }
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd
a9a4544168a37b43bd180b3703ccee995f27a80awrowe cache->dir_conf_tested = sec_ent;
a9a4544168a37b43bd180b3703ccee995f27a80awrowe cache->dir_conf_merged = r->per_dir_config;
a9a4544168a37b43bd180b3703ccee995f27a80awrowe
aa047239dedf0d26e8efecfade32e7337f35df19wrowe /* Merge our cache->dir_conf_merged construct with the r->per_dir_configs,
aa047239dedf0d26e8efecfade32e7337f35df19wrowe * and note the end result to (potentially) skip this step next time.
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe */
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar if (now_merged) {
aa047239dedf0d26e8efecfade32e7337f35df19wrowe r->per_dir_config = ap_merge_per_dir_configs(r->pool,
aa047239dedf0d26e8efecfade32e7337f35df19wrowe r->per_dir_config,
aa047239dedf0d26e8efecfade32e7337f35df19wrowe now_merged);
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar }
aa047239dedf0d26e8efecfade32e7337f35df19wrowe cache->per_dir_result = r->per_dir_config;
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return OK;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sfAP_DECLARE(int) ap_if_walk(request_rec *r)
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf{
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf ap_conf_vector_t *now_merged = NULL;
7184de27ec1d62a83c41cdeac0953ca9fd661e8csf core_dir_config *dconf = ap_get_core_module_config(r->per_dir_config);
7a3c5fd3b3f86cdd450d551e326b3b9a04ea8248sf ap_conf_vector_t **sec_ent = NULL;
7a3c5fd3b3f86cdd450d551e326b3b9a04ea8248sf int num_sec = 0;
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf walk_cache_t *cache;
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf int cached;
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf int sec_idx;
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf int matches;
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf int cached_matches;
6b15044d54a096e6323ff1540f1a491e8de7622dsf int prev_result = -1;
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf walk_walked_t *last_walk;
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf
7a3c5fd3b3f86cdd450d551e326b3b9a04ea8248sf if (dconf->sec_if) {
11e076839c8d5a82d55e710194d0daac51390dbdsf sec_ent = (ap_conf_vector_t **)dconf->sec_if->elts;
11e076839c8d5a82d55e710194d0daac51390dbdsf num_sec = dconf->sec_if->nelts;
7a3c5fd3b3f86cdd450d551e326b3b9a04ea8248sf }
7a3c5fd3b3f86cdd450d551e326b3b9a04ea8248sf
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf /* No tricks here, there are just no <If > to parse in this context.
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf * We won't destroy the cache, just in case _this_ redirect is later
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf * redirected again to a context containing the same or similar <If >.
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf */
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf if (!num_sec) {
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf return OK;
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf }
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf cache = prep_walk_cache(AP_NOTE_IF_WALK, r);
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf cached = (cache->cached != NULL);
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf cache->cached = (void *)1;
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf matches = cache->walked->nelts;
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf cached_matches = matches;
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf last_walk = (walk_walked_t*)cache->walked->elts;
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf cached &= auth_internal_per_conf;
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf /* Go through the if entries, and check for matches */
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf for (sec_idx = 0; sec_idx < num_sec; ++sec_idx) {
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf const char *err = NULL;
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf core_dir_config *entry_core;
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf int rc;
7184de27ec1d62a83c41cdeac0953ca9fd661e8csf entry_core = ap_get_core_module_config(sec_ent[sec_idx]);
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf
6b15044d54a096e6323ff1540f1a491e8de7622dsf AP_DEBUG_ASSERT(entry_core->condition_ifelse != 0);
6b15044d54a096e6323ff1540f1a491e8de7622dsf if (entry_core->condition_ifelse & AP_CONDITION_ELSE) {
6b15044d54a096e6323ff1540f1a491e8de7622dsf AP_DEBUG_ASSERT(prev_result != -1);
6b15044d54a096e6323ff1540f1a491e8de7622dsf if (prev_result == 1)
6b15044d54a096e6323ff1540f1a491e8de7622dsf continue;
6b15044d54a096e6323ff1540f1a491e8de7622dsf }
6b15044d54a096e6323ff1540f1a491e8de7622dsf
6b15044d54a096e6323ff1540f1a491e8de7622dsf if (entry_core->condition_ifelse & AP_CONDITION_IF) {
6b15044d54a096e6323ff1540f1a491e8de7622dsf rc = ap_expr_exec(r, entry_core->condition, &err);
6b15044d54a096e6323ff1540f1a491e8de7622dsf if (rc <= 0) {
6b15044d54a096e6323ff1540f1a491e8de7622dsf if (rc < 0)
185aa71728867671e105178b4c66fbc22b65ae26sf ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00039)
6b15044d54a096e6323ff1540f1a491e8de7622dsf "Failed to evaluate <If > condition: %s",
6b15044d54a096e6323ff1540f1a491e8de7622dsf err);
6b15044d54a096e6323ff1540f1a491e8de7622dsf prev_result = 0;
6b15044d54a096e6323ff1540f1a491e8de7622dsf continue;
6b15044d54a096e6323ff1540f1a491e8de7622dsf }
6b15044d54a096e6323ff1540f1a491e8de7622dsf prev_result = 1;
6b15044d54a096e6323ff1540f1a491e8de7622dsf }
6b15044d54a096e6323ff1540f1a491e8de7622dsf else {
6b15044d54a096e6323ff1540f1a491e8de7622dsf prev_result = -1;
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf }
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf /* If we merged this same section last time, reuse it
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf */
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf if (matches) {
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf if (last_walk->matched == sec_ent[sec_idx]) {
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf now_merged = last_walk->merged;
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf ++last_walk;
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf --matches;
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf continue;
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf }
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf /* We fell out of sync. This is our own copy of walked,
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf * so truncate the remaining matches and reset remaining.
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf */
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf cache->walked->nelts -= matches;
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf matches = 0;
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf cached = 0;
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf }
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf if (now_merged) {
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf now_merged = ap_merge_per_dir_configs(r->pool,
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf now_merged,
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf sec_ent[sec_idx]);
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf }
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf else {
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf now_merged = sec_ent[sec_idx];
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf }
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf last_walk = (walk_walked_t*)apr_array_push(cache->walked);
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf last_walk->matched = sec_ent[sec_idx];
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf last_walk->merged = now_merged;
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf }
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf /* Everything matched in sequence, but it may be that the original
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf * walk found some additional matches (which we need to truncate), or
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf * this walk found some additional matches.
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf */
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf if (matches) {
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf cache->walked->nelts -= matches;
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf cached = 0;
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf }
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf else if (cache->walked->nelts > cached_matches) {
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf cached = 0;
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf }
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf if (cached
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf && r->per_dir_config == cache->dir_conf_merged) {
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf r->per_dir_config = cache->per_dir_result;
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf return OK;
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf }
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf cache->dir_conf_tested = sec_ent;
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf cache->dir_conf_merged = r->per_dir_config;
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf /* Merge our cache->dir_conf_merged construct with the r->per_dir_configs,
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf * and note the end result to (potentially) skip this step next time.
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf */
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf if (now_merged) {
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf r->per_dir_config = ap_merge_per_dir_configs(r->pool,
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf r->per_dir_config,
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf now_merged);
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf }
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf cache->per_dir_result = r->per_dir_config;
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf return OK;
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf}
48e4b65042d94992c50f1db6c0b0cdbd99ca77e8sf
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb/*****************************************************************
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * The sub_request mechanism.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Fns to look up a relative URI from, e.g., a map file or SSI document.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * These do all access checks, etc., but don't actually run the transaction
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * ... use run_sub_req below for that. Also, be sure to use destroy_sub_req
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * as appropriate if you're likely to be creating more than a few of these.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * (An early Apache version didn't destroy the sub_reqs used in directory
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * indexing. The result, when indexing a directory with 800-odd files in
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * it, was massively excessive storage allocation).
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Note more manipulation of protocol-specific vars in the request
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * structure...
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
4f9c22c4f27571d54197be9674e1fc0d528192aestrikerstatic request_rec *make_sub_request(const request_rec *r,
d2220a04f870f632b8cec1e6713dbb980ed5e386wrowe ap_filter_t *next_filter)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb apr_pool_t *rrp;
d2220a04f870f632b8cec1e6713dbb980ed5e386wrowe request_rec *rnew;
4f9c22c4f27571d54197be9674e1fc0d528192aestriker
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb apr_pool_create(&rrp, r->pool);
6fd5761878f22fb9a2de0835807a29784bf367abtrawick apr_pool_tag(rrp, "subrequest");
d2220a04f870f632b8cec1e6713dbb980ed5e386wrowe rnew = apr_pcalloc(rrp, sizeof(request_rec));
d2220a04f870f632b8cec1e6713dbb980ed5e386wrowe rnew->pool = rrp;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe rnew->hostname = r->hostname;
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe rnew->request_time = r->request_time;
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe rnew->connection = r->connection;
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe rnew->server = r->server;
efd83d1dd1a25688a3093c5a542ae16bacef62ddsf rnew->log = r->log;
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe rnew->request_config = ap_create_request_config(rnew->pool);
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe /* Start a clean config from this subrequest's vhost. Optimization in
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe * Location/File/Dir walks from the parent request assure that if the
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe * config blocks of the subrequest match the parent request, no merges
4f9c22c4f27571d54197be9674e1fc0d528192aestriker * will actually occur (and generally a minimal number of merges are
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe * required, even if the parent and subrequest aren't quite identical.)
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe */
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe rnew->per_dir_config = r->server->lookup_defaults;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe
4f9c22c4f27571d54197be9674e1fc0d528192aestriker rnew->htaccess = r->htaccess;
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe rnew->allowed_methods = ap_make_method_list(rnew->pool, 2);
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe /* make a copy of the allowed-methods list */
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe ap_copy_method_list(rnew->allowed_methods, r->allowed_methods);
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe /* start with the same set of output filters */
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe if (next_filter) {
ebe7da316894e2b93b4a905fccd2496d0ed1bc78rbb /* while there are no input filters for a subrequest, we will
ebe7da316894e2b93b4a905fccd2496d0ed1bc78rbb * try to insert some, so if we don't have valid data, the code
ebe7da316894e2b93b4a905fccd2496d0ed1bc78rbb * will seg fault.
ebe7da316894e2b93b4a905fccd2496d0ed1bc78rbb */
4f9c22c4f27571d54197be9674e1fc0d528192aestriker rnew->input_filters = r->input_filters;
4f9c22c4f27571d54197be9674e1fc0d528192aestriker rnew->proto_input_filters = r->proto_input_filters;
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe rnew->output_filters = next_filter;
4f9c22c4f27571d54197be9674e1fc0d528192aestriker rnew->proto_output_filters = r->proto_output_filters;
e57e920838f31508f1418aa4c25ce55b345b2cebrbb ap_add_output_filter_handle(ap_subreq_core_filter_handle,
4f9c22c4f27571d54197be9674e1fc0d528192aestriker NULL, rnew, rnew->connection);
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe }
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe else {
e57e920838f31508f1418aa4c25ce55b345b2cebrbb /* If NULL - we are expecting to be internal_fast_redirect'ed
e57e920838f31508f1418aa4c25ce55b345b2cebrbb * to this subrequest - or this request will never be invoked.
e57e920838f31508f1418aa4c25ce55b345b2cebrbb * Ignore the original request filter stack entirely, and
e57e920838f31508f1418aa4c25ce55b345b2cebrbb * drill the input and output stacks back to the connection.
e57e920838f31508f1418aa4c25ce55b345b2cebrbb */
e57e920838f31508f1418aa4c25ce55b345b2cebrbb rnew->proto_input_filters = r->proto_input_filters;
e57e920838f31508f1418aa4c25ce55b345b2cebrbb rnew->proto_output_filters = r->proto_output_filters;
e57e920838f31508f1418aa4c25ce55b345b2cebrbb
e57e920838f31508f1418aa4c25ce55b345b2cebrbb rnew->input_filters = r->proto_input_filters;
e57e920838f31508f1418aa4c25ce55b345b2cebrbb rnew->output_filters = r->proto_output_filters;
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe }
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe
4240daa133bbeddbc3141553879eda4fccfe93feminfrin rnew->useragent_addr = r->useragent_addr;
4240daa133bbeddbc3141553879eda4fccfe93feminfrin rnew->useragent_ip = r->useragent_ip;
49fd87ed00b95bdd7a4cfc874e5c5fe4a04faf5aminfrin
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe /* no input filters for a subrequest */
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe ap_set_sub_req_protocol(rnew, r);
d2220a04f870f632b8cec1e6713dbb980ed5e386wrowe
4f9c22c4f27571d54197be9674e1fc0d528192aestriker /* We have to run this after we fill in sub req vars,
d2220a04f870f632b8cec1e6713dbb980ed5e386wrowe * or the r->main pointer won't be setup
d2220a04f870f632b8cec1e6713dbb980ed5e386wrowe */
d2220a04f870f632b8cec1e6713dbb980ed5e386wrowe ap_run_create_request(rnew);
d2220a04f870f632b8cec1e6713dbb980ed5e386wrowe
098ae874f43f7a0b66be5406a7e2fb971bbbe00ewrowe /* Begin by presuming any module can make its own path_info assumptions,
098ae874f43f7a0b66be5406a7e2fb971bbbe00ewrowe * until some module interjects and changes the value.
098ae874f43f7a0b66be5406a7e2fb971bbbe00ewrowe */
098ae874f43f7a0b66be5406a7e2fb971bbbe00ewrowe rnew->used_path_info = AP_REQ_DEFAULT_PATH_INFO;
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim
439ccf2a084e1da566548931c585cbcc3a9e7f4cminfrin /* Pass on the kept body (if any) into the new request. */
439ccf2a084e1da566548931c585cbcc3a9e7f4cminfrin rnew->kept_body = r->kept_body;
439ccf2a084e1da566548931c585cbcc3a9e7f4cminfrin
d2220a04f870f632b8cec1e6713dbb980ed5e386wrowe return rnew;
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe}
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbAP_CORE_DECLARE_NONSTD(apr_status_t) ap_sub_req_output_filter(ap_filter_t *f,
c2cf53a40a9814eb91db2cdf820f97d943f21628coar apr_bucket_brigade *bb)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb apr_bucket *e = APR_BRIGADE_LAST(bb);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (APR_BUCKET_IS_EOS(e)) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb apr_bucket_delete(e);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
4f9c22c4f27571d54197be9674e1fc0d528192aestriker
68b29bcadd6c46aecdc9fe14c93555a2238ad2aagregames if (!APR_BRIGADE_EMPTY(bb)) {
68b29bcadd6c46aecdc9fe14c93555a2238ad2aagregames return ap_pass_brigade(f->next, bb);
68b29bcadd6c46aecdc9fe14c93555a2238ad2aagregames }
4f9c22c4f27571d54197be9674e1fc0d528192aestriker
4f9c22c4f27571d54197be9674e1fc0d528192aestriker return APR_SUCCESS;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
a91a59d0b0ceed7cd5621fe8757eda5ff6a043a8pquernaextern APR_OPTIONAL_FN_TYPE(authz_some_auth_required) *ap__authz_ap_some_auth_required;
4f9c22c4f27571d54197be9674e1fc0d528192aestriker
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbAP_DECLARE(int) ap_some_auth_required(request_rec *r)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Is there a require line configured for the type of *this* req? */
a91a59d0b0ceed7cd5621fe8757eda5ff6a043a8pquerna if (ap__authz_ap_some_auth_required) {
a91a59d0b0ceed7cd5621fe8757eda5ff6a043a8pquerna return ap__authz_ap_some_auth_required(r);
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar }
367d146f245f3b1c9f77c18e6ec591b52e0b344cbnicholes else
367d146f245f3b1c9f77c18e6ec591b52e0b344cbnicholes return 0;
4f9c22c4f27571d54197be9674e1fc0d528192aestriker}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisdAP_DECLARE(void) ap_clear_auth_internal(void)
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd{
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd auth_internal_per_conf_hooks = 0;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd auth_internal_per_conf_providers = 0;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd}
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisdAP_DECLARE(void) ap_setup_auth_internal(apr_pool_t *ptemp)
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd{
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd int total_auth_hooks = 0;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd int total_auth_providers = 0;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd auth_internal_per_conf = 0;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd if (_hooks.link_access_checker) {
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd total_auth_hooks += _hooks.link_access_checker->nelts;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd }
18b5268e013574026b2503b1641baf3299045f45sf if (_hooks.link_access_checker_ex) {
18b5268e013574026b2503b1641baf3299045f45sf total_auth_hooks += _hooks.link_access_checker_ex->nelts;
18b5268e013574026b2503b1641baf3299045f45sf }
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd if (_hooks.link_check_user_id) {
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd total_auth_hooks += _hooks.link_check_user_id->nelts;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd }
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd if (_hooks.link_auth_checker) {
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd total_auth_hooks += _hooks.link_auth_checker->nelts;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd }
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd if (total_auth_hooks > auth_internal_per_conf_hooks) {
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd return;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd }
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd
db455cbc662c98dbbf53175393c50086ff63370cchrisd total_auth_providers +=
db455cbc662c98dbbf53175393c50086ff63370cchrisd ap_list_provider_names(ptemp, AUTHN_PROVIDER_GROUP,
db455cbc662c98dbbf53175393c50086ff63370cchrisd AUTHN_PROVIDER_VERSION)->nelts;
db455cbc662c98dbbf53175393c50086ff63370cchrisd total_auth_providers +=
db455cbc662c98dbbf53175393c50086ff63370cchrisd ap_list_provider_names(ptemp, AUTHZ_PROVIDER_GROUP,
db455cbc662c98dbbf53175393c50086ff63370cchrisd AUTHZ_PROVIDER_VERSION)->nelts;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd if (total_auth_providers > auth_internal_per_conf_providers) {
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd return;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd }
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd auth_internal_per_conf = 1;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd}
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisdAP_DECLARE(apr_status_t) ap_register_auth_provider(apr_pool_t *pool,
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd const char *provider_group,
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd const char *provider_name,
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd const char *provider_version,
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd const void *provider,
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd int type)
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd{
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd if ((type & AP_AUTH_INTERNAL_MASK) == AP_AUTH_INTERNAL_PER_CONF) {
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd ++auth_internal_per_conf_providers;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd }
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd return ap_register_provider(pool, provider_group, provider_name,
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd provider_version, provider);
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd}
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisdAP_DECLARE(void) ap_hook_check_access(ap_HOOK_access_checker_t *pf,
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd const char * const *aszPre,
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd const char * const *aszSucc,
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd int nOrder, int type)
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd{
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd if ((type & AP_AUTH_INTERNAL_MASK) == AP_AUTH_INTERNAL_PER_CONF) {
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd ++auth_internal_per_conf_hooks;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd }
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd ap_hook_access_checker(pf, aszPre, aszSucc, nOrder);
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd}
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd
18b5268e013574026b2503b1641baf3299045f45sfAP_DECLARE(void) ap_hook_check_access_ex(ap_HOOK_access_checker_ex_t *pf,
18b5268e013574026b2503b1641baf3299045f45sf const char * const *aszPre,
18b5268e013574026b2503b1641baf3299045f45sf const char * const *aszSucc,
18b5268e013574026b2503b1641baf3299045f45sf int nOrder, int type)
18b5268e013574026b2503b1641baf3299045f45sf{
18b5268e013574026b2503b1641baf3299045f45sf if ((type & AP_AUTH_INTERNAL_MASK) == AP_AUTH_INTERNAL_PER_CONF) {
18b5268e013574026b2503b1641baf3299045f45sf ++auth_internal_per_conf_hooks;
18b5268e013574026b2503b1641baf3299045f45sf }
18b5268e013574026b2503b1641baf3299045f45sf
18b5268e013574026b2503b1641baf3299045f45sf ap_hook_access_checker_ex(pf, aszPre, aszSucc, nOrder);
18b5268e013574026b2503b1641baf3299045f45sf}
18b5268e013574026b2503b1641baf3299045f45sf
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisdAP_DECLARE(void) ap_hook_check_authn(ap_HOOK_check_user_id_t *pf,
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd const char * const *aszPre,
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd const char * const *aszSucc,
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd int nOrder, int type)
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd{
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd if ((type & AP_AUTH_INTERNAL_MASK) == AP_AUTH_INTERNAL_PER_CONF) {
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd ++auth_internal_per_conf_hooks;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd }
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd ap_hook_check_user_id(pf, aszPre, aszSucc, nOrder);
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd}
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisdAP_DECLARE(void) ap_hook_check_authz(ap_HOOK_auth_checker_t *pf,
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd const char * const *aszPre,
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd const char * const *aszSucc,
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd int nOrder, int type)
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd{
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd if ((type & AP_AUTH_INTERNAL_MASK) == AP_AUTH_INTERNAL_PER_CONF) {
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd ++auth_internal_per_conf_hooks;
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd }
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd ap_hook_auth_checker(pf, aszPre, aszSucc, nOrder);
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd}
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wroweAP_DECLARE(request_rec *) ap_sub_req_method_uri(const char *method,
e8eee56a2ea20f673e5942fb58e1426a7561c7acstas const char *new_uri,
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe const request_rec *r,
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe ap_filter_t *next_filter)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe request_rec *rnew;
8011ccb9e0700e5a396e2362dab1d9386206277fcolm /* Initialise res, to avoid a gcc warning */
e8f95a682820a599fe41b22977010636be5c2717jim int res = HTTP_INTERNAL_SERVER_ERROR;
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe char *udir;
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe
d2220a04f870f632b8cec1e6713dbb980ed5e386wrowe rnew = make_sub_request(r, next_filter);
b45c1c292ff1fa635004ae81fa691f8cb3cdda85rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* would be nicer to pass "method" to ap_set_sub_req_protocol */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb rnew->method = method;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb rnew->method_number = ap_method_number_of(method);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
e8eee56a2ea20f673e5942fb58e1426a7561c7acstas if (new_uri[0] == '/') {
e8eee56a2ea20f673e5942fb58e1426a7561c7acstas ap_parse_uri(rnew, new_uri);
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb udir = ap_make_dirstr_parent(rnew->pool, r->uri);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb udir = ap_escape_uri(rnew->pool, udir); /* re-escape it */
e8eee56a2ea20f673e5942fb58e1426a7561c7acstas ap_parse_uri(rnew, ap_make_full_path(rnew->pool, udir, new_uri));
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
c880637396a01f4acfcf7e35fe423ced2d86c3b4nd
c880637396a01f4acfcf7e35fe423ced2d86c3b4nd /* We cannot return NULL without violating the API. So just turn this
c880637396a01f4acfcf7e35fe423ced2d86c3b4nd * subrequest into a 500 to indicate the failure. */
a8c55845ffa7170766e410dbd799353127b628f9nd if (ap_is_recursion_limit_exceeded(r)) {
c880637396a01f4acfcf7e35fe423ced2d86c3b4nd rnew->status = HTTP_INTERNAL_SERVER_ERROR;
c880637396a01f4acfcf7e35fe423ced2d86c3b4nd return rnew;
c880637396a01f4acfcf7e35fe423ced2d86c3b4nd }
c880637396a01f4acfcf7e35fe423ced2d86c3b4nd
e8f95a682820a599fe41b22977010636be5c2717jim /* lookup_uri
30b4a330a5f651eb5198fa93dbb9f3d3594564c9stoddard * If the content can be served by the quick_handler, we can
30b4a330a5f651eb5198fa93dbb9f3d3594564c9stoddard * safely bypass request_internal processing.
6edf0ccf36ca2792b20058833680375b9256f2e0colm *
e8f95a682820a599fe41b22977010636be5c2717jim * If next_filter is NULL we are expecting to be
e8f95a682820a599fe41b22977010636be5c2717jim * internal_fast_redirect'ed to the subrequest, or the subrequest will
e8f95a682820a599fe41b22977010636be5c2717jim * never be invoked. We need to make sure that the quickhandler is not
e8f95a682820a599fe41b22977010636be5c2717jim * invoked by any lookups. Since an internal_fast_redirect will always
6edf0ccf36ca2792b20058833680375b9256f2e0colm * occur too late for the quickhandler to handle the request.
30b4a330a5f651eb5198fa93dbb9f3d3594564c9stoddard */
6edf0ccf36ca2792b20058833680375b9256f2e0colm if (next_filter) {
6edf0ccf36ca2792b20058833680375b9256f2e0colm res = ap_run_quick_handler(rnew, 1);
6edf0ccf36ca2792b20058833680375b9256f2e0colm }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
6edf0ccf36ca2792b20058833680375b9256f2e0colm if (next_filter == NULL || res != OK) {
30b4a330a5f651eb5198fa93dbb9f3d3594564c9stoddard if ((res = ap_process_request_internal(rnew))) {
30b4a330a5f651eb5198fa93dbb9f3d3594564c9stoddard rnew->status = res;
30b4a330a5f651eb5198fa93dbb9f3d3594564c9stoddard }
e8f95a682820a599fe41b22977010636be5c2717jim }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return rnew;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
e8eee56a2ea20f673e5942fb58e1426a7561c7acstasAP_DECLARE(request_rec *) ap_sub_req_lookup_uri(const char *new_uri,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb const request_rec *r,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_filter_t *next_filter)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
e8eee56a2ea20f673e5942fb58e1426a7561c7acstas return ap_sub_req_method_uri("GET", new_uri, r, next_filter);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
efa1a34b0a7785fc72863eff175b0cfc1ecb0e38wroweAP_DECLARE(request_rec *) ap_sub_req_lookup_dirent(const apr_finfo_t *dirent,
117026201e6d8fe7d82416b8a7324830f5a87292wrowe const request_rec *r,
3cd826b00280881e5a2f03d8ec1f8d55802b93dewrowe int subtype,
117026201e6d8fe7d82416b8a7324830f5a87292wrowe ap_filter_t *next_filter)
117026201e6d8fe7d82416b8a7324830f5a87292wrowe{
117026201e6d8fe7d82416b8a7324830f5a87292wrowe request_rec *rnew;
117026201e6d8fe7d82416b8a7324830f5a87292wrowe int res;
117026201e6d8fe7d82416b8a7324830f5a87292wrowe char *fdir;
6c24fd6cfe148639988d5b335185ffb215662801wrowe char *udir;
117026201e6d8fe7d82416b8a7324830f5a87292wrowe
d2220a04f870f632b8cec1e6713dbb980ed5e386wrowe rnew = make_sub_request(r, next_filter);
117026201e6d8fe7d82416b8a7324830f5a87292wrowe
4f9c22c4f27571d54197be9674e1fc0d528192aestriker /* Special case: we are looking at a relative lookup in the same directory.
cadddb2c31d24d48f4017db4df0a29687432326cwrowe * This is 100% safe, since dirent->name just came from the filesystem.
117026201e6d8fe7d82416b8a7324830f5a87292wrowe */
f888346b48f5e5b5e3f0a47dedb8cefd2759a4e2gregames if (r->path_info && *r->path_info) {
f888346b48f5e5b5e3f0a47dedb8cefd2759a4e2gregames /* strip path_info off the end of the uri to keep it in sync
3cd826b00280881e5a2f03d8ec1f8d55802b93dewrowe * with r->filename, which has already been stripped by directory_walk,
4f9c22c4f27571d54197be9674e1fc0d528192aestriker * merge the dirent->name, and then, if the caller wants us to remerge
3cd826b00280881e5a2f03d8ec1f8d55802b93dewrowe * the original path info, do so. Note we never fix the path_info back
3cd826b00280881e5a2f03d8ec1f8d55802b93dewrowe * to r->filename, since dir_walk would do so (but we don't expect it
3cd826b00280881e5a2f03d8ec1f8d55802b93dewrowe * to happen in the usual cases)
f888346b48f5e5b5e3f0a47dedb8cefd2759a4e2gregames */
f888346b48f5e5b5e3f0a47dedb8cefd2759a4e2gregames udir = apr_pstrdup(rnew->pool, r->uri);
f888346b48f5e5b5e3f0a47dedb8cefd2759a4e2gregames udir[ap_find_path_info(udir, r->path_info)] = '\0';
f888346b48f5e5b5e3f0a47dedb8cefd2759a4e2gregames udir = ap_make_dirstr_parent(rnew->pool, udir);
3cd826b00280881e5a2f03d8ec1f8d55802b93dewrowe
3cd826b00280881e5a2f03d8ec1f8d55802b93dewrowe rnew->uri = ap_make_full_path(rnew->pool, udir, dirent->name);
3cd826b00280881e5a2f03d8ec1f8d55802b93dewrowe if (subtype == AP_SUBREQ_MERGE_ARGS) {
3cd826b00280881e5a2f03d8ec1f8d55802b93dewrowe rnew->uri = ap_make_full_path(rnew->pool, rnew->uri, r->path_info + 1);
3cd826b00280881e5a2f03d8ec1f8d55802b93dewrowe rnew->path_info = apr_pstrdup(rnew->pool, r->path_info);
3cd826b00280881e5a2f03d8ec1f8d55802b93dewrowe }
dc3a3d949b7ef46b8385858c822267e39b665c12nd rnew->uri = ap_escape_uri(rnew->pool, rnew->uri);
f888346b48f5e5b5e3f0a47dedb8cefd2759a4e2gregames }
f888346b48f5e5b5e3f0a47dedb8cefd2759a4e2gregames else {
f888346b48f5e5b5e3f0a47dedb8cefd2759a4e2gregames udir = ap_make_dirstr_parent(rnew->pool, r->uri);
dc3a3d949b7ef46b8385858c822267e39b665c12nd rnew->uri = ap_escape_uri(rnew->pool, ap_make_full_path(rnew->pool,
dc3a3d949b7ef46b8385858c822267e39b665c12nd udir,
dc3a3d949b7ef46b8385858c822267e39b665c12nd dirent->name));
f888346b48f5e5b5e3f0a47dedb8cefd2759a4e2gregames }
4f9c22c4f27571d54197be9674e1fc0d528192aestriker
cadddb2c31d24d48f4017db4df0a29687432326cwrowe fdir = ap_make_dirstr_parent(rnew->pool, r->filename);
117026201e6d8fe7d82416b8a7324830f5a87292wrowe rnew->filename = ap_make_full_path(rnew->pool, fdir, dirent->name);
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar if (r->canonical_filename == r->filename) {
e7505ba54ac56ae30e4e250f912f3dbaf92ca45fwrowe rnew->canonical_filename = rnew->filename;
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar }
4f9c22c4f27571d54197be9674e1fc0d528192aestriker
cadddb2c31d24d48f4017db4df0a29687432326cwrowe /* XXX This is now less relevant; we will do a full location walk
4f9c22c4f27571d54197be9674e1fc0d528192aestriker * these days for this case. Preserve the apr_stat results, and
4f9c22c4f27571d54197be9674e1fc0d528192aestriker * perhaps we also tag that symlinks were tested and/or found for
cadddb2c31d24d48f4017db4df0a29687432326cwrowe * r->filename.
5b3abd2fecc712f08ad728114aa77137b9f67716wrowe */
85bb5b92490e4f095aae394118fc588a8f4c486fwrowe rnew->per_dir_config = r->server->lookup_defaults;
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe
efa1a34b0a7785fc72863eff175b0cfc1ecb0e38wrowe if ((dirent->valid & APR_FINFO_MIN) != APR_FINFO_MIN) {
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe /*
beda1fb2f11c52ca4612460a5d5ba47398143efbwrowe * apr_dir_read isn't very complete on this platform, so
1fbf6ba0f5207e6637b49f9a9dfcc779bbe952a9trawick * we need another apr_stat (with or without APR_FINFO_LINK
e8f95a682820a599fe41b22977010636be5c2717jim * depending on whether we allow all symlinks here.) If this
e8f95a682820a599fe41b22977010636be5c2717jim * is an APR_LNK that resolves to an APR_DIR, then we will rerun
1fbf6ba0f5207e6637b49f9a9dfcc779bbe952a9trawick * everything anyways... this should be safe.
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe */
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe apr_status_t rv;
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe if (ap_allow_options(rnew) & OPT_SYM_LINKS) {
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe if (((rv = apr_stat(&rnew->finfo, rnew->filename,
c2cf53a40a9814eb91db2cdf820f97d943f21628coar APR_FINFO_MIN, rnew->pool)) != APR_SUCCESS)
c2cf53a40a9814eb91db2cdf820f97d943f21628coar && (rv != APR_INCOMPLETE)) {
2d4ea77e21ef7f3707d2c27f6117cc0a36e99b83trawick rnew->finfo.filetype = APR_NOFILE;
c2cf53a40a9814eb91db2cdf820f97d943f21628coar }
117026201e6d8fe7d82416b8a7324830f5a87292wrowe }
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar else {
1fbf6ba0f5207e6637b49f9a9dfcc779bbe952a9trawick if (((rv = apr_stat(&rnew->finfo, rnew->filename,
e8f95a682820a599fe41b22977010636be5c2717jim APR_FINFO_LINK | APR_FINFO_MIN,
1fbf6ba0f5207e6637b49f9a9dfcc779bbe952a9trawick rnew->pool)) != APR_SUCCESS)
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar && (rv != APR_INCOMPLETE)) {
2d4ea77e21ef7f3707d2c27f6117cc0a36e99b83trawick rnew->finfo.filetype = APR_NOFILE;
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar }
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar }
117026201e6d8fe7d82416b8a7324830f5a87292wrowe }
117026201e6d8fe7d82416b8a7324830f5a87292wrowe else {
c2cf53a40a9814eb91db2cdf820f97d943f21628coar memcpy(&rnew->finfo, dirent, sizeof(apr_finfo_t));
117026201e6d8fe7d82416b8a7324830f5a87292wrowe }
1067418d9ed9ed9daeb3ca4f74e72db810c49833wrowe
cadddb2c31d24d48f4017db4df0a29687432326cwrowe if (rnew->finfo.filetype == APR_LNK) {
cadddb2c31d24d48f4017db4df0a29687432326cwrowe /*
cadddb2c31d24d48f4017db4df0a29687432326cwrowe * Resolve this symlink. We should tie this back to dir_walk's cache
cadddb2c31d24d48f4017db4df0a29687432326cwrowe */
4f9c22c4f27571d54197be9674e1fc0d528192aestriker if ((res = resolve_symlink(rnew->filename, &rnew->finfo,
c2cf53a40a9814eb91db2cdf820f97d943f21628coar ap_allow_options(rnew), rnew->pool))
c2cf53a40a9814eb91db2cdf820f97d943f21628coar != OK) {
cadddb2c31d24d48f4017db4df0a29687432326cwrowe rnew->status = res;
cadddb2c31d24d48f4017db4df0a29687432326cwrowe return rnew;
cadddb2c31d24d48f4017db4df0a29687432326cwrowe }
cadddb2c31d24d48f4017db4df0a29687432326cwrowe }
cadddb2c31d24d48f4017db4df0a29687432326cwrowe
cadddb2c31d24d48f4017db4df0a29687432326cwrowe if (rnew->finfo.filetype == APR_DIR) {
6c0e8bc4051537fb59dbca7d80c0a0ca9cf8917asf /* ap_make_full_path and ap_escape_uri overallocated the buffers
3cd826b00280881e5a2f03d8ec1f8d55802b93dewrowe * by one character to help us out here.
cadddb2c31d24d48f4017db4df0a29687432326cwrowe */
0696197a54f186a65abacba1037f6fbe0cb975a1niq strcat(rnew->filename, "/");
3cd826b00280881e5a2f03d8ec1f8d55802b93dewrowe if (!rnew->path_info || !*rnew->path_info) {
0696197a54f186a65abacba1037f6fbe0cb975a1niq strcat(rnew->uri, "/");
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar }
cadddb2c31d24d48f4017db4df0a29687432326cwrowe }
cadddb2c31d24d48f4017db4df0a29687432326cwrowe
4f9c22c4f27571d54197be9674e1fc0d528192aestriker /* fill in parsed_uri values
3cd826b00280881e5a2f03d8ec1f8d55802b93dewrowe */
3cd826b00280881e5a2f03d8ec1f8d55802b93dewrowe if (r->args && *r->args && (subtype == AP_SUBREQ_MERGE_ARGS)) {
4f9c22c4f27571d54197be9674e1fc0d528192aestriker ap_parse_uri(rnew, apr_pstrcat(r->pool, rnew->uri, "?",
4f9c22c4f27571d54197be9674e1fc0d528192aestriker r->args, NULL));
3cd826b00280881e5a2f03d8ec1f8d55802b93dewrowe }
3cd826b00280881e5a2f03d8ec1f8d55802b93dewrowe else {
3cd826b00280881e5a2f03d8ec1f8d55802b93dewrowe ap_parse_uri(rnew, rnew->uri);
3cd826b00280881e5a2f03d8ec1f8d55802b93dewrowe }
cadddb2c31d24d48f4017db4df0a29687432326cwrowe
c880637396a01f4acfcf7e35fe423ced2d86c3b4nd /* We cannot return NULL without violating the API. So just turn this
c880637396a01f4acfcf7e35fe423ced2d86c3b4nd * subrequest into a 500. */
a8c55845ffa7170766e410dbd799353127b628f9nd if (ap_is_recursion_limit_exceeded(r)) {
c880637396a01f4acfcf7e35fe423ced2d86c3b4nd rnew->status = HTTP_INTERNAL_SERVER_ERROR;
c880637396a01f4acfcf7e35fe423ced2d86c3b4nd return rnew;
c880637396a01f4acfcf7e35fe423ced2d86c3b4nd }
c880637396a01f4acfcf7e35fe423ced2d86c3b4nd
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if ((res = ap_process_request_internal(rnew))) {
1067418d9ed9ed9daeb3ca4f74e72db810c49833wrowe rnew->status = res;
1067418d9ed9ed9daeb3ca4f74e72db810c49833wrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
1067418d9ed9ed9daeb3ca4f74e72db810c49833wrowe return rnew;
117026201e6d8fe7d82416b8a7324830f5a87292wrowe}
117026201e6d8fe7d82416b8a7324830f5a87292wrowe
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wroweAP_DECLARE(request_rec *) ap_sub_req_lookup_file(const char *new_file,
c2cf53a40a9814eb91db2cdf820f97d943f21628coar const request_rec *r,
c2cf53a40a9814eb91db2cdf820f97d943f21628coar ap_filter_t *next_filter)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb request_rec *rnew;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb int res;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb char *fdir;
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe apr_size_t fdirlen;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
d2220a04f870f632b8cec1e6713dbb980ed5e386wrowe rnew = make_sub_request(r, next_filter);
b45c1c292ff1fa635004ae81fa691f8cb3cdda85rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb fdir = ap_make_dirstr_parent(rnew->pool, r->filename);
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe fdirlen = strlen(fdir);
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe
ecc4a080f07af3fbc1b91bbd00997ec1d592c6f9wrowe /* Translate r->filename, if it was canonical, it stays canonical
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe */
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar if (r->canonical_filename == r->filename) {
2d2dadb81bf34e3bc9321eabcd971a738431b364wrowe rnew->canonical_filename = (char*)(1);
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar }
4f9c22c4f27571d54197be9674e1fc0d528192aestriker
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe if (apr_filepath_merge(&rnew->filename, fdir, new_file,
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe APR_FILEPATH_TRUENAME, rnew->pool) != APR_SUCCESS) {
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe rnew->status = HTTP_FORBIDDEN;
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe return rnew;
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe }
4f9c22c4f27571d54197be9674e1fc0d528192aestriker
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar if (rnew->canonical_filename) {
ecc4a080f07af3fbc1b91bbd00997ec1d592c6f9wrowe rnew->canonical_filename = rnew->filename;
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /*
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Check for a special case... if there are no '/' characters in new_file
4f9c22c4f27571d54197be9674e1fc0d528192aestriker * at all, and the path was the same, then we are looking at a relative
5b3abd2fecc712f08ad728114aa77137b9f67716wrowe * lookup in the same directory. Fixup the URI to match.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
af7e32b660b02a378e91d40987e59b28864db954jwoolley if (strncmp(rnew->filename, fdir, fdirlen) == 0
4f9c22c4f27571d54197be9674e1fc0d528192aestriker && rnew->filename[fdirlen]
c2cf53a40a9814eb91db2cdf820f97d943f21628coar && ap_strchr_c(rnew->filename + fdirlen, '/') == NULL) {
0540a0b469147b52e858587270dba31c2aaa9e09wrowe apr_status_t rv;
0540a0b469147b52e858587270dba31c2aaa9e09wrowe if (ap_allow_options(rnew) & OPT_SYM_LINKS) {
0540a0b469147b52e858587270dba31c2aaa9e09wrowe if (((rv = apr_stat(&rnew->finfo, rnew->filename,
c2cf53a40a9814eb91db2cdf820f97d943f21628coar APR_FINFO_MIN, rnew->pool)) != APR_SUCCESS)
c2cf53a40a9814eb91db2cdf820f97d943f21628coar && (rv != APR_INCOMPLETE)) {
2d4ea77e21ef7f3707d2c27f6117cc0a36e99b83trawick rnew->finfo.filetype = APR_NOFILE;
c2cf53a40a9814eb91db2cdf820f97d943f21628coar }
0540a0b469147b52e858587270dba31c2aaa9e09wrowe }
0540a0b469147b52e858587270dba31c2aaa9e09wrowe else {
1fbf6ba0f5207e6637b49f9a9dfcc779bbe952a9trawick if (((rv = apr_stat(&rnew->finfo, rnew->filename,
e8f95a682820a599fe41b22977010636be5c2717jim APR_FINFO_LINK | APR_FINFO_MIN,
1fbf6ba0f5207e6637b49f9a9dfcc779bbe952a9trawick rnew->pool)) != APR_SUCCESS)
c2cf53a40a9814eb91db2cdf820f97d943f21628coar && (rv != APR_INCOMPLETE)) {
2d4ea77e21ef7f3707d2c27f6117cc0a36e99b83trawick rnew->finfo.filetype = APR_NOFILE;
c2cf53a40a9814eb91db2cdf820f97d943f21628coar }
0540a0b469147b52e858587270dba31c2aaa9e09wrowe }
7763a4beb8afca9c8f93db0cb6836124901af52awrowe
0540a0b469147b52e858587270dba31c2aaa9e09wrowe if (r->uri && *r->uri) {
0540a0b469147b52e858587270dba31c2aaa9e09wrowe char *udir = ap_make_dirstr_parent(rnew->pool, r->uri);
c2cf53a40a9814eb91db2cdf820f97d943f21628coar rnew->uri = ap_make_full_path(rnew->pool, udir,
c2cf53a40a9814eb91db2cdf820f97d943f21628coar rnew->filename + fdirlen);
0540a0b469147b52e858587270dba31c2aaa9e09wrowe ap_parse_uri(rnew, rnew->uri); /* fill in parsed_uri values */
0540a0b469147b52e858587270dba31c2aaa9e09wrowe }
0540a0b469147b52e858587270dba31c2aaa9e09wrowe else {
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz ap_parse_uri(rnew, new_file); /* fill in parsed_uri values */
0540a0b469147b52e858587270dba31c2aaa9e09wrowe rnew->uri = apr_pstrdup(rnew->pool, "");
0540a0b469147b52e858587270dba31c2aaa9e09wrowe }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else {
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz /* XXX: @@@: What should be done with the parsed_uri values?
5b3abd2fecc712f08ad728114aa77137b9f67716wrowe * We would be better off stripping down to the 'common' elements
5b3abd2fecc712f08ad728114aa77137b9f67716wrowe * of the path, then reassembling the URI as best as we can.
5b3abd2fecc712f08ad728114aa77137b9f67716wrowe */
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz ap_parse_uri(rnew, new_file); /* fill in parsed_uri values */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /*
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * XXX: this should be set properly like it is in the same-dir case
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * but it's actually sometimes to impossible to do it... because the
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * file may not have a uri associated with it -djg
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
58097d7d8d1a394092374b9f6ddf76b7993724a4rbb rnew->uri = apr_pstrdup(rnew->pool, "");
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
c880637396a01f4acfcf7e35fe423ced2d86c3b4nd /* We cannot return NULL without violating the API. So just turn this
c880637396a01f4acfcf7e35fe423ced2d86c3b4nd * subrequest into a 500. */
a8c55845ffa7170766e410dbd799353127b628f9nd if (ap_is_recursion_limit_exceeded(r)) {
c880637396a01f4acfcf7e35fe423ced2d86c3b4nd rnew->status = HTTP_INTERNAL_SERVER_ERROR;
c880637396a01f4acfcf7e35fe423ced2d86c3b4nd return rnew;
c880637396a01f4acfcf7e35fe423ced2d86c3b4nd }
c880637396a01f4acfcf7e35fe423ced2d86c3b4nd
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if ((res = ap_process_request_internal(rnew))) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb rnew->status = res;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return rnew;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbAP_DECLARE(int) ap_run_sub_req(request_rec *r)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
30b4a330a5f651eb5198fa93dbb9f3d3594564c9stoddard int retval = DECLINED;
e8f95a682820a599fe41b22977010636be5c2717jim /* Run the quick handler if the subrequest is not a dirent or file
e8f95a682820a599fe41b22977010636be5c2717jim * subrequest
30b4a330a5f651eb5198fa93dbb9f3d3594564c9stoddard */
2d4ea77e21ef7f3707d2c27f6117cc0a36e99b83trawick if (!(r->filename && r->finfo.filetype != APR_NOFILE)) {
30b4a330a5f651eb5198fa93dbb9f3d3594564c9stoddard retval = ap_run_quick_handler(r, 0);
30b4a330a5f651eb5198fa93dbb9f3d3594564c9stoddard }
30b4a330a5f651eb5198fa93dbb9f3d3594564c9stoddard if (retval != OK) {
30b4a330a5f651eb5198fa93dbb9f3d3594564c9stoddard retval = ap_invoke_handler(r);
66e89b91046a4d0998bcb11c8aeb39ac444ed2dfjerenkrantz if (retval == DONE) {
66e89b91046a4d0998bcb11c8aeb39ac444ed2dfjerenkrantz retval = OK;
66e89b91046a4d0998bcb11c8aeb39ac444ed2dfjerenkrantz }
30b4a330a5f651eb5198fa93dbb9f3d3594564c9stoddard }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_finalize_sub_req_protocol(r);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return retval;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbAP_DECLARE(void) ap_destroy_sub_req(request_rec *r)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Reclaim the space */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb apr_pool_destroy(r->pool);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb/*
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Function to set the r->mtime field to the specified value if it's later
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * than what's already there.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbAP_DECLARE(void) ap_update_mtime(request_rec *r, apr_time_t dependency_mtime)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (r->mtime < dependency_mtime) {
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz r->mtime = dependency_mtime;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb/*
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Is it the initial main request, which we only get *once* per HTTP request?
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbAP_DECLARE(int) ap_is_initial_req(request_rec *r)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
4f9c22c4f27571d54197be9674e1fc0d528192aestriker return (r->main == NULL) /* otherwise, this is a sub-request */
4f9c22c4f27571d54197be9674e1fc0d528192aestriker && (r->prev == NULL); /* otherwise, this is an internal redirect */
4f9c22c4f27571d54197be9674e1fc0d528192aestriker}
a72211e92bab814bfa28ee086ca9b2a1a6095c92chrisd