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