request.c revision c4f311d9c637c74c57ef51a1a3a610bb48af1ce8
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein/* ====================================================================
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * The Apache Software License, Version 1.1
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * 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,
f4c310fd2555c6faca1f980f00b161eadb089023gstein * University of Illinois, Urbana-Champaign.
1f6e6566a4ce31a0b95d5400c36d0aaff7a6e94agstein * http_request.c: functions to get and process requests
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein * Rob McCool 3/21/93
cccd31fa4a72fe23cc3249c06db181b274a55a69gstein * Thoroughly revamped by rst for Apache. NB this file reads
cccd31fa4a72fe23cc3249c06db181b274a55a69gstein * best from the bottom up.
707ecf9559338ec06b24334bc9abcca670325cc4gsteinAP_IMPLEMENT_HOOK_VOID(insert_filter, (request_rec *r), (r))
707ecf9559338ec06b24334bc9abcca670325cc4gsteinAP_IMPLEMENT_HOOK_RUN_ALL(int,create_request,(request_rec *r),(r),OK,DECLINED)
707ecf9559338ec06b24334bc9abcca670325cc4gstein/*****************************************************************
707ecf9559338ec06b24334bc9abcca670325cc4gstein * Getting and checking directory configuration. Also checks the
707ecf9559338ec06b24334bc9abcca670325cc4gstein * FollowSymlinks and FollowSymOwner stuff, since this is really the
707ecf9559338ec06b24334bc9abcca670325cc4gstein * only place that can happen (barring a new mid_dir_walk callout).
707ecf9559338ec06b24334bc9abcca670325cc4gstein * We can't do it as an access_checker module function which gets
707ecf9559338ec06b24334bc9abcca670325cc4gstein * called with the final per_dir_config, since we could have a directory
707ecf9559338ec06b24334bc9abcca670325cc4gstein * with FollowSymLinks disabled, which contains a symlink to another
707ecf9559338ec06b24334bc9abcca670325cc4gstein * with a .htaccess file which turns FollowSymLinks back on --- and
707ecf9559338ec06b24334bc9abcca670325cc4gstein * access in such a case must be denied. So, whatever it is that
707ecf9559338ec06b24334bc9abcca670325cc4gstein * checks FollowSymLinks needs to know the state of the options as
707ecf9559338ec06b24334bc9abcca670325cc4gstein * they change, all the way down.
0e8fe062a6ec71b4207d1a125ee6b44b7fd30857gstein * 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",
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic int check_symlinks(char *d, int opts, apr_pool_t *p)
f4c310fd2555c6faca1f980f00b161eadb089023gstein#if defined(OS2)
0e8fe062a6ec71b4207d1a125ee6b44b7fd30857gstein /* OS/2 doesn't have symlinks */
0e8fe062a6ec71b4207d1a125ee6b44b7fd30857gstein * Strip trailing '/', if any, off what we're checking; trailing slashes
0e8fe062a6ec71b4207d1a125ee6b44b7fd30857gstein * make some systems follow symlinks to directories even in lstat().
0e8fe062a6ec71b4207d1a125ee6b44b7fd30857gstein * After we've done the lstat, put it back. Also, don't bother checking
0e8fe062a6ec71b4207d1a125ee6b44b7fd30857gstein * '/' at all...
0e8fe062a6ec71b4207d1a125ee6b44b7fd30857gstein * Note that we don't have to worry about multiple slashes here because of
0e8fe062a6ec71b4207d1a125ee6b44b7fd30857gstein * no2slash() below...
0e8fe062a6ec71b4207d1a125ee6b44b7fd30857gstein res = apr_lstat(&lfi, d, APR_FINFO_TYPE | APR_FINFO_OWNER, p);
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Note that we don't reject accesses to nonexistent files (multiviews or
f4c310fd2555c6faca1f980f00b161eadb089023gstein * the like may cons up a way to run the transaction anyway)...
0e8fe062a6ec71b4207d1a125ee6b44b7fd30857gstein /* OK, it's a symlink. May still be OK with OPT_SYM_OWNER */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* OPT_SYM_OWNER only works if we can get the owner from the file */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (apr_stat(&fi, d, APR_FINFO_OWNER, p) != APR_SUCCESS)
f94aab38f6ee899f463f0118ea395291f7c5b4cegstein /* TODO: replace with an apr_compare_users() fn */
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* 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.
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (strlen(path) == 3 && path[1] == ':' && path[2] == '/')
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* If UNC name == //machine/share/, do not
49bf4df23d9e5281abcd83005550bda818b17b08wrowe * advance over the trailing slash. Any other
f4c310fd2555c6faca1f980f00b161eadb089023gstein * UNC name is OK to strip the slash.
f71d4ec448449837beefe21cf7c9f8d9b6bd4654gstein#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 it's door - by platform
f4c310fd2555c6faca1f980f00b161eadb089023gstein * and volume restrictions as applicable...
f4c310fd2555c6faca1f980f00b161eadb089023gstein * TODO: This code becomes even simpler if apr_stat grows
10a4cdd68ef1ca0e54af296fe1d08ac00150c90bwrowe * an APR_PATHINCOMPLETE result to indicate that we are staring at
10a4cdd68ef1ca0e54af296fe1d08ac00150c90bwrowe * an partial virtual root. Only OS2/Win32/Netware need apply it :-)
f71d4ec448449837beefe21cf7c9f8d9b6bd4654gstein rv = apr_stat(&r->finfo, path, APR_FINFO_MIN, r->pool);
f4c310fd2555c6faca1f980f00b161eadb089023gstein * 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 if (APR_STATUS_IS_ENOENT(rv) || APR_STATUS_IS_ENOTDIR(rv)) {
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm 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 = (ap_conf_vector_t **) sconf->sec->elts;
f4c310fd2555c6faca1f980f00b161eadb089023gstein unsigned i, num_dirs;
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Are we dealing with a file? If not, we can (hopefuly) safely assume we
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * have a handler that doesn't require one, but for safety's sake, and so
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * we have something find_types() can get something out of, fake one. But
f4c310fd2555c6faca1f980f00b161eadb089023gstein * don't run through the directory entries.
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 * Fake filenames (i.e. proxy:) only match Directory sections.
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *entry_dir;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm for (j = 0; j < num_sec; ++j) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein entry_core = ap_get_module_config(entry_config, &core_module);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!ap_regexec(entry_core->r, r->filename, 0, NULL, 0))
f4c310fd2555c6faca1f980f00b161eadb089023gstein else if (!strncmp(r->filename, entry_dir, strlen(entry_dir)))
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* XXX This needs to be rolled into APR, the APR function will not
f4c310fd2555c6faca1f980f00b161eadb089023gstein * be allowed to fold the case of any non-existant segment of the path:
f4c310fd2555c6faca1f980f00b161eadb089023gstein r->filename = ap_os_case_canonical_filename(r->pool, r->filename);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* TODO This is rather silly right here, we should simply be setting
f4c310fd2555c6faca1f980f00b161eadb089023gstein * filename and path_info at the end of our directory_walk
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* XXX This becomes moot, and will already happen above for elements
f4c310fd2555c6faca1f980f00b161eadb089023gstein * that actually exist:
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm r->filename = ap_os_canonical_filename(r->pool, r->filename);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* XXX This becomes mute, since the APR canonical parsing will handle
f4c310fd2555c6faca1f980f00b161eadb089023gstein * 2slash and dot directory issues:
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* XXX This needs to be rolled into APR: */
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * 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);
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein /* XXX These exception cases go away if apr_stat() returns the
f4c310fd2555c6faca1f980f00b161eadb089023gstein * APR_PATHINCOMPLETE status, so we skip hard filesystem testing
f4c310fd2555c6faca1f980f00b161eadb089023gstein * of the initial 'pseudo' elements:
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/)
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * 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!
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein if (num_dirs > 1 && strchr(test_filename, '/') < strchr(test_filename, ':'))
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Should match <Directory> sections starting from '/', not 'e:/'
f4c310fd2555c6faca1f980f00b161eadb089023gstein * (for example). WIN32/OS2/NETWARE do not have a single root directory,
f4c310fd2555c6faca1f980f00b161eadb089023gstein * they have one for each filesystem. Traditionally, Apache has treated
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * <Directory /> permissions as the base for the whole server, and this
f4c310fd2555c6faca1f980f00b161eadb089023gstein * tradition should probably be preserved.
f4c310fd2555c6faca1f980f00b161eadb089023gstein * NOTE: MUST SYNC WITH ap_make_dirstr_prefix() CHANGE IN src/main/util.c
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Normal File Systems are rooted at / */
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif /* def HAVE_DRIVE_LETTERS || NETWARE */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* j keeps track of which section we're on, see core_reorder_directories */
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (; i <= num_dirs; ++i) {
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 legal names against the real filesystem */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((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 /* To account for the top-level "/" directory when i == 0
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * XXX: The net test may be wrong... may fail ap_os_is_path_absolute
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif /* def HAVE_DRIVE_LETTERS || NETWARE */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!apr_fnmatch(entry_dir, test_dirname, FNM_PATHNAME)) {
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm /* So that other top-level directory sections (e.g. "e:/") aren't
f4c310fd2555c6faca1f980f00b161eadb089023gstein * skipped when i == 0
f4c310fd2555c6faca1f980f00b161eadb089023gstein * XXX: I don't get you here, Tim... That's a level 1 section, but
f4c310fd2555c6faca1f980f00b161eadb089023gstein * we are at level 0. Did you mean fast-forward to the next?
f4c310fd2555c6faca1f980f00b161eadb089023gstein else if (!i)
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif /* def HAVE_DRIVE_LETTERS || NETWARE */
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 * There's two types of IS_SPECIAL sections (see http_core.c), and we've
f4c310fd2555c6faca1f980f00b161eadb089023gstein * already handled the proxy:-style stuff. Now we'll deal with the
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (; j < num_sec; ++j) {
ba2ad3b1bb4a729278ad8e8846d34ddd27b6551cgstein entry_core = ap_get_module_config(entry_config, &core_module);
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein 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
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * 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 * S_ISDIR test. But if you accessed /symlink/index.html, for example,
f4c310fd2555c6faca1f980f00b161eadb089023gstein * you would *not* get the 403.
f4c310fd2555c6faca1f980f00b161eadb089023gstein && (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 core_server_config *sconf = ap_get_module_config(r->server->module_config,
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_conf_vector_t *per_dir_defaults = r->per_dir_config;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_conf_vector_t **url = (ap_conf_vector_t **) sconf->sec_url->elts;
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_url; ++j) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein entry_core = ap_get_module_config(entry_config, &core_module);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!apr_fnmatch(entry_url, test_location, FNM_PATHNAME)) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein test_location[len] == '/' || test_location[len] == '\0'))
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->elts;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm /* 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
f4c310fd2555c6faca1f980f00b161eadb089023gstein * 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
f4c310fd2555c6faca1f980f00b161eadb089023gstein * indexing. The result, when indexing a directory with 800-odd files in
f4c310fd2555c6faca1f980f00b161eadb089023gstein * it, was massively excessive storage allocation).
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * Note more manipulation of protocol-specific vars in the request
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * 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);
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein 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 */
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm ap_add_output_filter("SUBREQ_CORE", NULL, rnew, rnew->connection);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* no input filters for a subrequest */
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic int sub_req_common_validation(request_rec *rnew)
1ccd992d37d62c8cb2056126f2234f64ec189bfddougmAP_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? */
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
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein * 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));
f4c310fd2555c6faca1f980f00b161eadb089023gstein * We could be clever at this point, and avoid calling directory_walk,
33397e35239f202a595837571561468f02b2e806gstein * etc. However, we'd need to test that the old and new filenames contain
f4c310fd2555c6faca1f980f00b161eadb089023gstein * the same directory components, so it would require duplicating the
f4c310fd2555c6faca1f980f00b161eadb089023gstein * start of translate_name. Instead we rely on the cache of .htaccess
f4c310fd2555c6faca1f980f00b161eadb089023gstein * NB: directory_walk() clears the per_dir_config, so we don't inherit
f4c310fd2555c6faca1f980f00b161eadb089023gstein * from location_walk() above
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE(request_rec *) ap_sub_req_lookup_uri(const char *new_file,
f4c310fd2555c6faca1f980f00b161eadb089023gstein return ap_sub_req_method_uri("GET", new_file, r, next_filter);
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE(request_rec *) ap_sub_req_lookup_dirent(const apr_finfo_t *dirent,
1f6e6566a4ce31a0b95d5400c36d0aaff7a6e94agstein /* 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.
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 */
707ecf9559338ec06b24334bc9abcca670325cc4gstein if ((dirent->valid & APR_FINFO_MIN) != APR_FINFO_MIN) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein * no matter what, if it's a subdirectory, we need to re-run
f4c310fd2555c6faca1f980f00b161eadb089023gstein * directory_walk
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein if ((res = check_symlinks(rnew->filename, ap_allow_options(rnew),
707ecf9559338ec06b24334bc9abcca670325cc4gstein ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, rnew,
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein * do a file_walk, if it doesn't change the per_dir_config then
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein * we know that we don't have to redo all the access checks
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((res = ap_run_type_checker(rnew)) || (res = ap_run_fixups(rnew))) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (res || (res = sub_req_common_validation(rnew))) {
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 * Check for a special case... if there are no '/' characters in new_file
f4c310fd2555c6faca1f980f00b161eadb089023gstein * at all, then we are looking at a relative lookup in the same
f4c310fd2555c6faca1f980f00b161eadb089023gstein * directory. That means we won't have to redo directory_walk, and we may
f4c310fd2555c6faca1f980f00b161eadb089023gstein * not even have to redo access checks.
f4c310fd2555c6faca1f980f00b161eadb089023gstein char *udir = ap_make_dirstr_parent(rnew->pool, r->uri);
f4c310fd2555c6faca1f980f00b161eadb089023gstein rnew->uri = ap_make_full_path(rnew->pool, udir, new_file);
f4c310fd2555c6faca1f980f00b161eadb089023gstein rnew->filename = ap_make_full_path(rnew->pool, fdir, new_file);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_parse_uri(rnew, rnew->uri); /* fill in parsed_uri values */
f4c310fd2555c6faca1f980f00b161eadb089023gstein * no matter what, if it's a subdirectory, we need to re-run
f4c310fd2555c6faca1f980f00b161eadb089023gstein * directory_walk
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((res = check_symlinks(rnew->filename, ap_allow_options(rnew),
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, rnew,
f4c310fd2555c6faca1f980f00b161eadb089023gstein * do a file_walk, if it doesn't change the per_dir_config then
f4c310fd2555c6faca1f980f00b161eadb089023gstein * we know that we don't have to redo all the access checks
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((res = ap_run_type_checker(rnew)) || (res = ap_run_fixups(rnew))) {
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm /* XXX: @@@: What should be done with the parsed_uri values? */
5646ba89a25a695006edae46de226fb57a2e6270gstein ap_parse_uri(rnew, new_file); /* fill in parsed_uri values */
f4c310fd2555c6faca1f980f00b161eadb089023gstein * XXX: this should be set properly like it is in the same-dir case
f4c310fd2555c6faca1f980f00b161eadb089023gstein * but it's actually sometimes to impossible to do it... because the
f4c310fd2555c6faca1f980f00b161eadb089023gstein * file may not have a uri associated with it -djg
f4c310fd2555c6faca1f980f00b161eadb089023gstein rnew->uri = "INTERNALLY GENERATED file-relative req";
5646ba89a25a695006edae46de226fb57a2e6270gstein rnew->filename = ((ap_os_is_path_absolute(new_file)) ?
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (res || (res = sub_req_common_validation(rnew))) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* see comments in process_request_internal() */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Reclaim the space */
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Function to set the r->mtime field to the specified value if it's later
f4c310fd2555c6faca1f980f00b161eadb089023gstein * than what's already there.
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE(void) ap_update_mtime(request_rec *r, apr_time_t dependency_mtime)
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Is it the initial main request, which we only get *once* per HTTP request?
f4c310fd2555c6faca1f980f00b161eadb089023gstein (r->main == NULL) /* otherwise, this is a sub-request */
f4c310fd2555c6faca1f980f00b161eadb089023gstein (r->prev == NULL); /* otherwise, this is an internal redirect */