request.c revision c880637396a01f4acfcf7e35fe423ced2d86c3b4
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb/* ====================================================================
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * The Apache Software License, Version 1.1
33bdcae1f7a1a65e351dda2a766a0cf28b1e695dnd * Copyright (c) 2000-2003 The Apache Software Foundation. All rights
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * reserved.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Redistribution and use in source and binary forms, with or without
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * modification, are permitted provided that the following conditions
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * are met:
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * 1. Redistributions of source code must retain the above copyright
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * notice, this list of conditions and the following disclaimer.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * 2. Redistributions in binary form must reproduce the above copyright
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * notice, this list of conditions and the following disclaimer in
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * the documentation and/or other materials provided with the
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * distribution.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * 3. The end-user documentation included with the redistribution,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * if any, must include the following acknowledgment:
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * "This product includes software developed by the
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Apache Software Foundation (http://www.apache.org/)."
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Alternately, this acknowledgment may appear in the software itself,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * if and wherever such third-party acknowledgments normally appear.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * 4. The names "Apache" and "Apache Software Foundation" must
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * not be used to endorse or promote products derived from this
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * software without prior written permission. For written
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * permission, please contact apache@apache.org.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * 5. Products derived from this software may not be called "Apache",
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * nor may "Apache" appear in their name, without prior written
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * permission of the Apache Software Foundation.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * SUCH DAMAGE.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * ====================================================================
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * This software consists of voluntary contributions made by many
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * individuals on behalf of the Apache Software Foundation. For more
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * information on the Apache Software Foundation, please see
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Portions of this software are based upon public domain software
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * originally written at the National Center for Supercomputing Applications,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * University of Illinois, Urbana-Champaign.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * http_request.c: functions to get and process requests
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Rob McCool 3/21/93
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Thoroughly revamped by rst for Apache. NB this file reads
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * best from the bottom up.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbAP_IMPLEMENT_HOOK_VOID(insert_filter, (request_rec *r), (r))
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowestatic int decl_die(int status, char *phase, request_rec *r)
c2cf53a40a9814eb91db2cdf820f97d943f21628coar "configuration error: couldn't %s: %s", phase, r->uri);
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.
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewroweAP_DECLARE(int) ap_process_request_internal(request_rec *r)
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe /* Ignore embedded %2F's in path for proxy requests */
8419e6f8bff1a3617933f3ba760d2bdec7442f44coar d = ap_get_module_config(r->per_dir_config, &core_module);
8419e6f8bff1a3617933f3ba760d2bdec7442f44coar access_status = ap_unescape_url_keep2f(r->parsed_uri.path);
8419e6f8bff1a3617933f3ba760d2bdec7442f44coar "found %%2f (encoded '/') in URI "
8419e6f8bff1a3617933f3ba760d2bdec7442f44coar "(decoded='%s'), returning 404",
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe ap_getparents(r->uri); /* OK --- shrinking transformations... */
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.
4f9c22c4f27571d54197be9674e1fc0d528192aestriker /* Reset to the server default config prior to running map_to_storage
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe /* This request wasn't in storage (e.g. TRACE) */
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe /* Excluding file-specific requests with no 'true' URI...
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe /* Rerun the location walk, which overrides any map_to_storage config.
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe /* Only on the main request! */
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 if (r->main && (r->main->per_dir_config == r->per_dir_config)) {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe else if (r->prev && (r->prev->per_dir_config == r->per_dir_config)) {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe switch (ap_satisfies(r)) {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe if ((access_status = ap_run_access_checker(r)) != 0) {
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz ? "check user. No user file?"
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz : "perform authentication. AuthType not set!",
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz ? "check access. No groups file?"
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz : "perform authentication. AuthType not set!",
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz ? "check user. No user file?"
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz : "perform authentication. AuthType not set!",
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz ? "check access. No groups file?"
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz : "perform authentication. AuthType not set!",
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")
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz return decl_die(access_status, "find types", r);
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe/* Useful caching structures to repeat _walk/merge sequences as required
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe * when a subrequest or redirect reuses substantially the same config.
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.
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 */
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowetypedef struct walk_cache_t {
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 */
a2b181763cb35fd899feb4a436aeadaa80bf91eabrianpstatic walk_cache_t *prep_walk_cache(apr_size_t t, request_rec *r)
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe /* Find the most relevant, recent entry to work from. That would be
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe * this request (on the second call), or the parent request of a
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe * subrequest, or the prior request of an internal redirect. Provide
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe * this _walk()er with a copy it is allowed to munge. If there is no
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe * parent or prior cached request, then create a new walk cache.
4f9c22c4f27571d54197be9674e1fc0d528192aestriker && ((inherit_note = ap_get_request_note(r->main, t)))
4f9c22c4f27571d54197be9674e1fc0d528192aestriker && ((inherit_note = ap_get_request_note(r->prev, t)))
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe cache->walked = apr_array_copy(r->pool, cache->walked);
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe cache->walked = apr_array_make(r->pool, 4, sizeof(walk_walked_t));
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 * 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.
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 * 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 * 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.)
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowestatic int resolve_symlink(char *d, apr_finfo_t *lfi, int opts, apr_pool_t *p)
7c301a1818939f85da8f3629cc3e9b5588610ef0jerenkrantz /* Save the name from the valid bits. */
7c301a1818939f85da8f3629cc3e9b5588610ef0jerenkrantz savename = (lfi->valid & APR_FINFO_NAME) ? lfi->name : NULL;
659ad814f714e556bdd03e1d771cba156baab92ewrowe if ((res = apr_stat(&fi, d, lfi->valid & ~(APR_FINFO_NAME
11fb2f3611e6ff9a541e10b13e3108934f828141gregames /* Give back the target */
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.
2f1949bb0e3c209db94c8d521cba7380b9d11421trawick if ((res = apr_lstat(&fi, d, lfi->valid | APR_FINFO_OWNER, p))
4f9c22c4f27571d54197be9674e1fc0d528192aestriker if ((res = apr_stat(&fi, d, lfi->valid & ~(APR_FINFO_NAME), p))
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar if (apr_compare_users(fi.user, lfi->user) != APR_SUCCESS) {
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe /* Give back the target */
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 * 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 * See core.c::merge_core_dir_configs() for explanation.
700b96db75e7cfadb5219978c1735b710d583763wrowetypedef struct core_opts_t {
6964758306167dd898baedd21048bd1515dd9d30trawickstatic void core_opts_merge(const ap_conf_vector_t *sec, core_opts_t *opts)
700b96db75e7cfadb5219978c1735b710d583763wrowe core_dir_config *this_dir = ap_get_module_config(sec, &core_module);
700b96db75e7cfadb5219978c1735b710d583763wrowe opts->opts = (opts->opts & ~opts->remove) | opts->add;
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 * 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 core_server_config *sconf = ap_get_module_config(r->server->module_config,
2fa5b5878e7567e2875807c3e2a2b3b0d3ef74bewrowe ap_conf_vector_t **sec_ent = (ap_conf_vector_t **) sconf->sec_dir->elts;
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe /* XXX: Better (faster) tests needed!!!
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.
4f9c22c4f27571d54197be9674e1fc0d528192aestriker "Module bug? Request filename is missing for URI %s",
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.
4f9c22c4f27571d54197be9674e1fc0d528192aestriker if ((rv = apr_filepath_merge(&entry_dir, NULL, r->filename,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe "Module bug? Request filename path %s is invalid or "
4f9c22c4f27571d54197be9674e1fc0d528192aestriker "or not absolute for uri %s",
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.
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 * 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.
69adb3d949e3dd17c0492a01fc2cf298832c7eefwrowe if (!r->finfo.filetype || r->finfo.filetype == APR_LNK) {
ecde48c75338ff5712f2036711f813c6dedca28ewrowe rv = apr_stat(&r->finfo, r->filename, APR_FINFO_MIN, r->pool);
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 * other OSs will return APR_ENOTDIR for that situation;
d75626f0952c6152a99acd013a4f127d46f0f9edtrawick * handle it the same everywhere by simulating a failure
d75626f0952c6152a99acd013a4f127d46f0f9edtrawick * if it looks like a directory but really isn't
ecde48c75338ff5712f2036711f813c6dedca28ewrowe * Also reset if the stat failed, just for safety.
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe entry_dir = ap_make_dirstr_parent(r->pool, entry_dir);
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar else if (r->filename[strlen(r->filename) - 1] != '/') {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe entry_dir = apr_pstrcat(r->pool, r->filename, "/", NULL);
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 /* 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.
4f9c22c4f27571d54197be9674e1fc0d528192aestriker /* We start now_merged from NULL since we want to build
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * a locations list that can be merged to any vhost.
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe walk_walked_t *last_walk = (walk_walked_t*)cache->walked->elts;
0e58e92812f2f679d6bf2ff66cbcfa6c1d1e14bbjerenkrantz /* Invariant: from the first time filename_len is set until
0e58e92812f2f679d6bf2ff66cbcfa6c1d1e14bbjerenkrantz * it goes out of scope, filename_len==strlen(r->filename)
4f9c22c4f27571d54197be9674e1fc0d528192aestriker * We must play our own mimi-merge game here, for the few
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * running dir_config values we care about within dir_walk.
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * We didn't start the merge from r->per_dir_config, so we
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * accumulate opts and override as we merge, from the globals.
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe this_dir = ap_get_module_config(r->per_dir_config, &core_module);
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,
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe * before we continue! [Directories cannot, by defintion, have
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe * path info. Either the next segment is not-found, or a file.]
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe * r->path_info tracks the unconsumed source path.
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe * r->filename tracks the path as we process it
4f9c22c4f27571d54197be9674e1fc0d528192aestriker if ((r->finfo.filetype == APR_DIR) && r->path_info && *r->path_info)
4f9c22c4f27571d54197be9674e1fc0d528192aestriker if ((rv = apr_filepath_merge(&r->path_info, r->filename,
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe "dir_walk error, path_info %s is not relative "
4f9c22c4f27571d54197be9674e1fc0d528192aestriker "to the filename path %s for uri %s",
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe while (r->canonical_filename && r->canonical_filename[canonical_len]
4f9c22c4f27571d54197be9674e1fc0d528192aestriker && ((r->canonical_filename[canonical_len - 1] != '/'
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 (const char **)&r->path_info,
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.
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe (const char **)&r->path_info,
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe#else /* ndef CASE_BLIND_FILESYSTEM, really this simple for Unix today; */
38bcc87d9a06e8ba81165421403f275eca4e313btrawick (const char **)&r->path_info,
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe "dir_walk error, could not determine the root "
4f9c22c4f27571d54197be9674e1fc0d528192aestriker "path of filename %s%s for uri %s",
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe /* Working space for terminating null and an extra / is required.
0e58e92812f2f679d6bf2ff66cbcfa6c1d1e14bbjerenkrantz buflen = filename_len + strlen(r->path_info) + 2;
cf6ef072483172309861d06e85b1aeff4573c060wrowe thisinfo.filetype = APR_DIR; /* It's the root, of course it's a dir */
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)
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.
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.
548b2980e83f609186a76e98fb245d02e8547bc3jerenkrantz if ((seg > startseg) && r->filename[filename_len-1] != '/') {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* Begin *this* level by looking for matching <Directory> sections
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * from the server config.
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe entry_core = ap_get_module_config(entry_config, &core_module);
4f9c22c4f27571d54197be9674e1fc0d528192aestriker /* No more possible matches for this many segments?
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * We are done when we find relative/regex/longer components.
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* We will never skip '0' element components, e.g. plain old
4f9c22c4f27571d54197be9674e1fc0d528192aestriker * <Directory >, and <Directory "/"> are classified as zero
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * so that Win32/Netware/OS2 etc all pick them up.
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * Otherwise, skip over the mismatches.
700b96db75e7cfadb5219978c1735b710d583763wrowe /* If we haven't continue'd above, we have a match.
700b96db75e7cfadb5219978c1735b710d583763wrowe * Calculate our full-context core opts & override.
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* If we merged this same section last time, reuse it
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* We fell out of sync. This is our own copy of walked,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * so truncate the remaining matches and reset remaining.
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe last_walk = (walk_walked_t*)apr_array_push(cache->walked);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* If .htaccess files are enabled, check for one, provided we
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * have reached a real path.
700b96db75e7cfadb5219978c1735b710d583763wrowe do { /* Not really a loop, just a break'able code block */
700b96db75e7cfadb5219978c1735b710d583763wrowe /* No htaccess in an incomplete root path,
700b96db75e7cfadb5219978c1735b710d583763wrowe * nor if it's disabled
700b96db75e7cfadb5219978c1735b710d583763wrowe res = ap_parse_htaccess(&htaccess_conf, r, opts.override,
700b96db75e7cfadb5219978c1735b710d583763wrowe /* If we are still here, we found our htaccess.
700b96db75e7cfadb5219978c1735b710d583763wrowe * Calculate our full-context core opts & override.
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 /* We fell out of sync. This is our own copy of walked,
700b96db75e7cfadb5219978c1735b710d583763wrowe * so truncate the remaining matches and reset
700b96db75e7cfadb5219978c1735b710d583763wrowe * remaining.
700b96db75e7cfadb5219978c1735b710d583763wrowe last_walk = (walk_walked_t*)apr_array_push(cache->walked);
700b96db75e7cfadb5219978c1735b710d583763wrowe } while (0); /* Only one htaccess, not a real loop */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* That temporary trailing slash was useful, now drop it.
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* Time for all good things to come to an end?
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...
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe delim = strchr(r->path_info + (*r->path_info == '/' ? 1 : 0), '/');
0e58e92812f2f679d6bf2ff66cbcfa6c1d1e14bbjerenkrantz memcpy(seg_name, r->path_info, path_info_len + 1);
0e58e92812f2f679d6bf2ff66cbcfa6c1d1e14bbjerenkrantz memcpy(seg_name, r->path_info, path_info_len + 1);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* If nothing remained but a '/' string, we are finished
ecde48c75338ff5712f2036711f813c6dedca28ewrowe * XXX: NO WE ARE NOT!!! Now process this puppy!!! */
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.
700b96db75e7cfadb5219978c1735b710d583763wrowe && ((opts.opts & (OPT_SYM_OWNER | OPT_SYM_LINKS)) == OPT_SYM_LINKS))
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* We choose apr_lstat here, rather that apr_stat, so that we
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * capture this path object rather than its target. We will
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * replace the info with our target's info below. We especially
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * want the name of this 'link' object, not the name of its
cf6ef072483172309861d06e85b1aeff4573c060wrowe * target, if we are fixing the filename case/resolving aliases.
c2cf53a40a9814eb91db2cdf820f97d943f21628coar /* Nothing? That could be nice. But our directory
c2cf53a40a9814eb91db2cdf820f97d943f21628coar * walk is done.
4f9c22c4f27571d54197be9674e1fc0d528192aestriker else if ((rv != APR_SUCCESS && rv != APR_INCOMPLETE)
4f9c22c4f27571d54197be9674e1fc0d528192aestriker /* If we hit ENOTDIR, we must have over-optimized, deny
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * rather than assume not found.
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* Fix up the path now if we have a name, and they don't agree
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.
cf6ef072483172309861d06e85b1aeff4573c060wrowe /* Is this a possibly acceptable symlink?
c2cf53a40a9814eb91db2cdf820f97d943f21628coar "Symbolic link not allowed: %s",
ecde48c75338ff5712f2036711f813c6dedca28ewrowe /* Ok, we are done with the link's info, test the real target
ecde48c75338ff5712f2036711f813c6dedca28ewrowe /* That was fun, nothing left for us here
ecde48c75338ff5712f2036711f813c6dedca28ewrowe "Forbidden: %s doesn't point to "
ecde48c75338ff5712f2036711f813c6dedca28ewrowe "a file or directory",
cf6ef072483172309861d06e85b1aeff4573c060wrowe /* If we have _not_ optimized, this is the time to recover
cf6ef072483172309861d06e85b1aeff4573c060wrowe * the final stat result.
69adb3d949e3dd17c0492a01fc2cf298832c7eefwrowe if (!r->finfo.filetype || r->finfo.filetype == APR_LNK) {
cf6ef072483172309861d06e85b1aeff4573c060wrowe /* Now splice the saved path_info back onto any new path_info
4f9c22c4f27571d54197be9674e1fc0d528192aestriker r->path_info = ap_make_full_path(r->pool, r->path_info,
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 entry_core = ap_get_module_config(sec_ent[sec_idx], &core_module);
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar if (ap_regexec(entry_core->r, r->filename, 0, NULL, REG_NOTEOL)) {
700b96db75e7cfadb5219978c1735b710d583763wrowe /* If we haven't already continue'd above, we have a match.
700b96db75e7cfadb5219978c1735b710d583763wrowe * Calculate our full-context core opts & override.
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* If we merged this same section last time, reuse it
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* We fell out of sync. This is our own copy of walked,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * so truncate the remaining matches and reset remaining.
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe last_walk = (walk_walked_t*)apr_array_push(cache->walked);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* Whoops - everything matched in sequence, but the original walk
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * found some additional matches. Truncate them.
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
c2cf53a40a9814eb91db2cdf820f97d943f21628coar x obscure cases in autoindex sub requests, etc.
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 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;
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe /* Save future sub-requestors much angst in processing
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe * this subrequest. If dir_walk couldn't canonicalize
1b315ee865b0f11e582beb64127ca3a99a319d2fwrowe * the file path, nothing can.
0540a0b469147b52e858587270dba31c2aaa9e09wrowe cache->cached = ap_make_dirstr_parent(r->pool, r->filename);
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.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb core_server_config *sconf = ap_get_module_config(r->server->module_config,
4f9c22c4f27571d54197be9674e1fc0d528192aestriker ap_conf_vector_t **sec_ent = (ap_conf_vector_t **)sconf->sec_url->elts;
948096a99010fccf648814fecf38f75c689172d7wrowe const char *entry_uri;
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.
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 /* 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.
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.
4f9c22c4f27571d54197be9674e1fc0d528192aestriker /* We start now_merged from NULL since we want to build
948096a99010fccf648814fecf38f75c689172d7wrowe * a locations list that can be merged to any vhost.
aa047239dedf0d26e8efecfade32e7337f35df19wrowe walk_walked_t *last_walk = (walk_walked_t*)cache->walked->elts;
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.
0540a0b469147b52e858587270dba31c2aaa9e09wrowe entry_core = ap_get_module_config(sec_ent[sec_idx], &core_module);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe /* ### const strlen can be optimized in location config parsing */
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.
c2cf53a40a9814eb91db2cdf820f97d943f21628coar ? apr_fnmatch(entry_core->d, cache->cached, FNM_PATHNAME)
948096a99010fccf648814fecf38f75c689172d7wrowe /* If we merged this same section last time, reuse it
948096a99010fccf648814fecf38f75c689172d7wrowe /* We fell out of sync. This is our own copy of walked,
948096a99010fccf648814fecf38f75c689172d7wrowe * so truncate the remaining matches and reset remaining.
948096a99010fccf648814fecf38f75c689172d7wrowe last_walk = (walk_walked_t*)apr_array_push(cache->walked);
948096a99010fccf648814fecf38f75c689172d7wrowe /* Whoops - everything matched in sequence, but the original walk
948096a99010fccf648814fecf38f75c689172d7wrowe * found some additional matches. Truncate them.
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.
aa047239dedf0d26e8efecfade32e7337f35df19wrowe core_dir_config *dconf = ap_get_module_config(r->per_dir_config,
4f9c22c4f27571d54197be9674e1fc0d528192aestriker ap_conf_vector_t **sec_ent = (ap_conf_vector_t **)dconf->sec_file->elts;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe const char *test_file;
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.
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 >.
4f9c22c4f27571d54197be9674e1fc0d528192aestriker /* Get the basename .. and copy for the cache just
aa047239dedf0d26e8efecfade32e7337f35df19wrowe * in case r->filename is munged by another module
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 /* 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.
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 walk_walked_t *last_walk = (walk_walked_t*)cache->walked->elts;
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.
0540a0b469147b52e858587270dba31c2aaa9e09wrowe entry_core = ap_get_module_config(sec_ent[sec_idx], &core_module);
c2cf53a40a9814eb91db2cdf820f97d943f21628coar ? ap_regexec(entry_core->r, cache->cached , 0, NULL, 0)
c2cf53a40a9814eb91db2cdf820f97d943f21628coar ? apr_fnmatch(entry_core->d, cache->cached, FNM_PATHNAME)
aa047239dedf0d26e8efecfade32e7337f35df19wrowe /* If we merged this same section last time, reuse it
aa047239dedf0d26e8efecfade32e7337f35df19wrowe /* We fell out of sync. This is our own copy of walked,
aa047239dedf0d26e8efecfade32e7337f35df19wrowe * so truncate the remaining matches and reset remaining.
aa047239dedf0d26e8efecfade32e7337f35df19wrowe last_walk = (walk_walked_t*)apr_array_push(cache->walked);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe /* Whoops - everything matched in sequence, but the original walk
aa047239dedf0d26e8efecfade32e7337f35df19wrowe * found some additional matches. Truncate them.
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.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb/*****************************************************************
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * The sub_request mechanism.
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 * Note more manipulation of protocol-specific vars in the request
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * structure...
4f9c22c4f27571d54197be9674e1fc0d528192aestrikerstatic request_rec *make_sub_request(const request_rec *r,
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe rnew->request_config = ap_create_request_config(rnew->pool);
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.)
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe rnew->allowed_methods = ap_make_method_list(rnew->pool, 2);
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe /* make a copy of the allowed-methods list */
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe ap_copy_method_list(rnew->allowed_methods, r->allowed_methods);
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe /* start with the same set of output filters */
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.
4f9c22c4f27571d54197be9674e1fc0d528192aestriker rnew->proto_output_filters = r->proto_output_filters;
e57e920838f31508f1418aa4c25ce55b345b2cebrbb ap_add_output_filter_handle(ap_subreq_core_filter_handle,
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.
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe /* no input filters for a subrequest */
4f9c22c4f27571d54197be9674e1fc0d528192aestriker /* We have to run this after we fill in sub req vars,
d2220a04f870f632b8cec1e6713dbb980ed5e386wrowe * or the r->main pointer won't be setup
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbAP_CORE_DECLARE_NONSTD(apr_status_t) ap_sub_req_output_filter(ap_filter_t *f,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Is there a require line configured for the type of *this* req? */
731344ed8f3677d1661c261ca5fcdd2ee3dbc74ccoar if (reqs[i].method_mask & (AP_METHOD_BIT << r->method_number)) {
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wroweAP_DECLARE(request_rec *) ap_sub_req_method_uri(const char *method,
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe const char *new_file,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* would be nicer to pass "method" to ap_set_sub_req_protocol */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb udir = ap_escape_uri(rnew->pool, udir); /* re-escape it */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_parse_uri(rnew, ap_make_full_path(rnew->pool, udir, new_file));
c880637396a01f4acfcf7e35fe423ced2d86c3b4nd /* We cannot return NULL without violating the API. So just turn this
c880637396a01f4acfcf7e35fe423ced2d86c3b4nd * subrequest into a 500 to indicate the failure. */
30b4a330a5f651eb5198fa93dbb9f3d3594564c9stoddard /* lookup_uri
30b4a330a5f651eb5198fa93dbb9f3d3594564c9stoddard * If the content can be served by the quick_handler, we can
30b4a330a5f651eb5198fa93dbb9f3d3594564c9stoddard * safely bypass request_internal processing.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbAP_DECLARE(request_rec *) ap_sub_req_lookup_uri(const char *new_file,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return ap_sub_req_method_uri("GET", new_file, r, next_filter);
efa1a34b0a7785fc72863eff175b0cfc1ecb0e38wroweAP_DECLARE(request_rec *) ap_sub_req_lookup_dirent(const apr_finfo_t *dirent,
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.
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 udir[ap_find_path_info(udir, r->path_info)] = '\0';
3cd826b00280881e5a2f03d8ec1f8d55802b93dewrowe rnew->uri = ap_make_full_path(rnew->pool, udir, dirent->name);
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 rnew->uri = ap_make_full_path(rnew->pool, udir, dirent->name);
cadddb2c31d24d48f4017db4df0a29687432326cwrowe fdir = ap_make_dirstr_parent(rnew->pool, r->filename);
117026201e6d8fe7d82416b8a7324830f5a87292wrowe rnew->filename = ap_make_full_path(rnew->pool, fdir, dirent->name);
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.
efa1a34b0a7785fc72863eff175b0cfc1ecb0e38wrowe if ((dirent->valid & APR_FINFO_MIN) != APR_FINFO_MIN) {
beda1fb2f11c52ca4612460a5d5ba47398143efbwrowe * apr_dir_read isn't very complete on this platform, so
beda1fb2f11c52ca4612460a5d5ba47398143efbwrowe * we need another apr_lstat (or simply apr_stat if we allow
4f9c22c4f27571d54197be9674e1fc0d528192aestriker * all symlinks here.) If this is an APR_LNK that resolves
4f9c22c4f27571d54197be9674e1fc0d528192aestriker * to an APR_DIR, then we will rerun everything anyways...
beda1fb2f11c52ca4612460a5d5ba47398143efbwrowe * this should be safe.
cadddb2c31d24d48f4017db4df0a29687432326cwrowe * Resolve this symlink. We should tie this back to dir_walk's cache
4f9c22c4f27571d54197be9674e1fc0d528192aestriker if ((res = resolve_symlink(rnew->filename, &rnew->finfo,
3cd826b00280881e5a2f03d8ec1f8d55802b93dewrowe /* ap_make_full_path overallocated the buffers
3cd826b00280881e5a2f03d8ec1f8d55802b93dewrowe * by one character to help us out here.
4f9c22c4f27571d54197be9674e1fc0d528192aestriker /* fill in parsed_uri values
3cd826b00280881e5a2f03d8ec1f8d55802b93dewrowe if (r->args && *r->args && (subtype == AP_SUBREQ_MERGE_ARGS)) {
4f9c22c4f27571d54197be9674e1fc0d528192aestriker ap_parse_uri(rnew, apr_pstrcat(r->pool, rnew->uri, "?",
c880637396a01f4acfcf7e35fe423ced2d86c3b4nd /* We cannot return NULL without violating the API. So just turn this
c880637396a01f4acfcf7e35fe423ced2d86c3b4nd * subrequest into a 500. */
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wroweAP_DECLARE(request_rec *) ap_sub_req_lookup_file(const char *new_file,
ecc4a080f07af3fbc1b91bbd00997ec1d592c6f9wrowe /* Translate r->filename, if it was canonical, it stays canonical
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe if (apr_filepath_merge(&rnew->filename, fdir, new_file,
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.
c2cf53a40a9814eb91db2cdf820f97d943f21628coar && ap_strchr_c(rnew->filename + fdirlen, '/') == NULL) {
0540a0b469147b52e858587270dba31c2aaa9e09wrowe char *udir = ap_make_dirstr_parent(rnew->pool, r->uri);
0540a0b469147b52e858587270dba31c2aaa9e09wrowe ap_parse_uri(rnew, rnew->uri); /* fill in parsed_uri values */
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz ap_parse_uri(rnew, new_file); /* fill in parsed_uri values */
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.
d4abb06ac220bb280ae996b6d21bbd257db51bb1jerenkrantz ap_parse_uri(rnew, new_file); /* fill in parsed_uri values */
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
c880637396a01f4acfcf7e35fe423ced2d86c3b4nd /* We cannot return NULL without violating the API. So just turn this
c880637396a01f4acfcf7e35fe423ced2d86c3b4nd * subrequest into a 500. */
30b4a330a5f651eb5198fa93dbb9f3d3594564c9stoddard /* Run the quick handler if the subrequest is not a dirent or file
30b4a330a5f651eb5198fa93dbb9f3d3594564c9stoddard * subrequest
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Reclaim the space */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Function to set the r->mtime field to the specified value if it's later
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * than what's already there.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbAP_DECLARE(void) ap_update_mtime(request_rec *r, apr_time_t dependency_mtime)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Is it the initial main request, which we only get *once* per HTTP request?
4f9c22c4f27571d54197be9674e1fc0d528192aestriker return (r->main == NULL) /* otherwise, this is a sub-request */
4f9c22c4f27571d54197be9674e1fc0d528192aestriker && (r->prev == NULL); /* otherwise, this is an internal redirect */