request.c revision c4f311d9c637c74c57ef51a1a3a610bb48af1ce8
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein/* ====================================================================
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * The Apache Software License, Version 1.1
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein *
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * Copyright (c) 2000-2001 The Apache Software Foundation. All rights
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * reserved.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein *
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * Redistribution and use in source and binary forms, with or without
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * modification, are permitted provided that the following conditions
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * are met:
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein *
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * 1. Redistributions of source code must retain the above copyright
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * notice, this list of conditions and the following disclaimer.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein *
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * 2. Redistributions in binary form must reproduce the above copyright
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * notice, this list of conditions and the following disclaimer in
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * the documentation and/or other materials provided with the
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * distribution.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein *
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * 3. The end-user documentation included with the redistribution,
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * if any, must include the following acknowledgment:
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * "This product includes software developed by the
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * Apache Software Foundation (http://www.apache.org/)."
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * Alternately, this acknowledgment may appear in the software itself,
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * if and wherever such third-party acknowledgments normally appear.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein *
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * 4. The names "Apache" and "Apache Software Foundation" must
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * not be used to endorse or promote products derived from this
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * software without prior written permission. For written
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * permission, please contact apache@apache.org.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein *
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * 5. Products derived from this software may not be called "Apache",
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * nor may "Apache" appear in their name, without prior written
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * permission of the Apache Software Foundation.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein *
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * SUCH DAMAGE.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * ====================================================================
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein *
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * This software consists of voluntary contributions made by many
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * individuals on behalf of the Apache Software Foundation. For more
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * information on the Apache Software Foundation, please see
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * <http://www.apache.org/>.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein *
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Portions of this software are based upon public domain software
f4c310fd2555c6faca1f980f00b161eadb089023gstein * originally written at the National Center for Supercomputing Applications,
f4c310fd2555c6faca1f980f00b161eadb089023gstein * University of Illinois, Urbana-Champaign.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
cccd31fa4a72fe23cc3249c06db181b274a55a69gstein/*
1f6e6566a4ce31a0b95d5400c36d0aaff7a6e94agstein * http_request.c: functions to get and process requests
8a46775d163c06a8c51d1b0a3f2edfde945cb1d8stoddard *
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein * Rob McCool 3/21/93
cccd31fa4a72fe23cc3249c06db181b274a55a69gstein *
cccd31fa4a72fe23cc3249c06db181b274a55a69gstein * Thoroughly revamped by rst for Apache. NB this file reads
cccd31fa4a72fe23cc3249c06db181b274a55a69gstein * best from the bottom up.
cccd31fa4a72fe23cc3249c06db181b274a55a69gstein *
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "apr_strings.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "apr_file_io.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "apr_fnmatch.h"
1a9d922232824a7cc008d4f74e48bd82adf5bdedgstein
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein#define APR_WANT_STRFUNC
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "apr_want.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein#define CORE_PRIVATE
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "ap_config.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "httpd.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "http_config.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "http_request.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "http_core.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "http_protocol.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "http_log.h"
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm#include "http_main.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "util_filter.h"
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm#include "util_charset.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein#include "mod_core.h"
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein#if APR_HAVE_STDARG_H
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein#include <stdarg.h>
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein#endif
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gsteinAPR_HOOK_STRUCT(
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein APR_HOOK_LINK(translate_name)
f4c310fd2555c6faca1f980f00b161eadb089023gstein APR_HOOK_LINK(check_user_id)
f4c310fd2555c6faca1f980f00b161eadb089023gstein APR_HOOK_LINK(fixups)
f4c310fd2555c6faca1f980f00b161eadb089023gstein APR_HOOK_LINK(type_checker)
f4c310fd2555c6faca1f980f00b161eadb089023gstein APR_HOOK_LINK(access_checker)
707ecf9559338ec06b24334bc9abcca670325cc4gstein APR_HOOK_LINK(auth_checker)
f4c310fd2555c6faca1f980f00b161eadb089023gstein APR_HOOK_LINK(insert_filter)
707ecf9559338ec06b24334bc9abcca670325cc4gstein APR_HOOK_LINK(create_request)
707ecf9559338ec06b24334bc9abcca670325cc4gstein)
707ecf9559338ec06b24334bc9abcca670325cc4gstein
707ecf9559338ec06b24334bc9abcca670325cc4gsteinAP_IMPLEMENT_HOOK_RUN_FIRST(int,translate_name,
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein (request_rec *r),(r),DECLINED)
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_IMPLEMENT_HOOK_RUN_FIRST(int,check_user_id,
f4c310fd2555c6faca1f980f00b161eadb089023gstein (request_rec *r),(r),DECLINED)
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_IMPLEMENT_HOOK_RUN_ALL(int,fixups,
f4c310fd2555c6faca1f980f00b161eadb089023gstein (request_rec *r),(r),OK,DECLINED)
707ecf9559338ec06b24334bc9abcca670325cc4gsteinAP_IMPLEMENT_HOOK_RUN_FIRST(int,type_checker,
707ecf9559338ec06b24334bc9abcca670325cc4gstein (request_rec *r),(r),DECLINED)
707ecf9559338ec06b24334bc9abcca670325cc4gsteinAP_IMPLEMENT_HOOK_RUN_ALL(int,access_checker,
707ecf9559338ec06b24334bc9abcca670325cc4gstein (request_rec *r),(r),OK,DECLINED)
707ecf9559338ec06b24334bc9abcca670325cc4gsteinAP_IMPLEMENT_HOOK_RUN_FIRST(int,auth_checker,
707ecf9559338ec06b24334bc9abcca670325cc4gstein (request_rec *r),(r),DECLINED)
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/*****************************************************************
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 *
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.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein/*
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.
0e8fe062a6ec71b4207d1a125ee6b44b7fd30857gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic int check_safe_file(request_rec *r)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (r->finfo.filetype == 0 /* doesn't exist */
f4c310fd2555c6faca1f980f00b161eadb089023gstein || r->finfo.filetype == APR_DIR
f4c310fd2555c6faca1f980f00b161eadb089023gstein || r->finfo.filetype == APR_REG
f4c310fd2555c6faca1f980f00b161eadb089023gstein || r->finfo.filetype == APR_LNK) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein return OK;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "object is not a file, directory or symlink: %s",
f4c310fd2555c6faca1f980f00b161eadb089023gstein r->filename);
f4c310fd2555c6faca1f980f00b161eadb089023gstein return HTTP_FORBIDDEN;
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic int check_symlinks(char *d, int opts, apr_pool_t *p)
0e8fe062a6ec71b4207d1a125ee6b44b7fd30857gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein#if defined(OS2)
0e8fe062a6ec71b4207d1a125ee6b44b7fd30857gstein /* OS/2 doesn't have symlinks */
f4c310fd2555c6faca1f980f00b161eadb089023gstein return OK;
0e8fe062a6ec71b4207d1a125ee6b44b7fd30857gstein#else
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_finfo_t lfi, fi;
0e8fe062a6ec71b4207d1a125ee6b44b7fd30857gstein char *lastp;
0e8fe062a6ec71b4207d1a125ee6b44b7fd30857gstein int res;
0e8fe062a6ec71b4207d1a125ee6b44b7fd30857gstein
0e8fe062a6ec71b4207d1a125ee6b44b7fd30857gstein if (opts & OPT_SYM_LINKS)
0e8fe062a6ec71b4207d1a125ee6b44b7fd30857gstein return OK;
0e8fe062a6ec71b4207d1a125ee6b44b7fd30857gstein
0e8fe062a6ec71b4207d1a125ee6b44b7fd30857gstein /*
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 *
0e8fe062a6ec71b4207d1a125ee6b44b7fd30857gstein * Note that we don't have to worry about multiple slashes here because of
0e8fe062a6ec71b4207d1a125ee6b44b7fd30857gstein * no2slash() below...
0e8fe062a6ec71b4207d1a125ee6b44b7fd30857gstein */
0e8fe062a6ec71b4207d1a125ee6b44b7fd30857gstein
0e8fe062a6ec71b4207d1a125ee6b44b7fd30857gstein lastp = d + strlen(d) - 1;
0e8fe062a6ec71b4207d1a125ee6b44b7fd30857gstein if (lastp == d)
0e8fe062a6ec71b4207d1a125ee6b44b7fd30857gstein return OK; /* Root directory, '/' */
0e8fe062a6ec71b4207d1a125ee6b44b7fd30857gstein
0e8fe062a6ec71b4207d1a125ee6b44b7fd30857gstein if (*lastp == '/')
0e8fe062a6ec71b4207d1a125ee6b44b7fd30857gstein *lastp = '\0';
0e8fe062a6ec71b4207d1a125ee6b44b7fd30857gstein else
0e8fe062a6ec71b4207d1a125ee6b44b7fd30857gstein lastp = NULL;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
0e8fe062a6ec71b4207d1a125ee6b44b7fd30857gstein res = apr_lstat(&lfi, d, APR_FINFO_TYPE | APR_FINFO_OWNER, p);
0e8fe062a6ec71b4207d1a125ee6b44b7fd30857gstein
0e8fe062a6ec71b4207d1a125ee6b44b7fd30857gstein if (lastp)
0e8fe062a6ec71b4207d1a125ee6b44b7fd30857gstein *lastp = '/';
956f4b1551215610a57f3b52822dbac6f41a8aa9gstein
0e8fe062a6ec71b4207d1a125ee6b44b7fd30857gstein /*
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)...
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
0e8fe062a6ec71b4207d1a125ee6b44b7fd30857gstein if ((res != APR_SUCCESS && res != APR_INCOMPLETE)
0e8fe062a6ec71b4207d1a125ee6b44b7fd30857gstein || (lfi.filetype != APR_LNK))
0e8fe062a6ec71b4207d1a125ee6b44b7fd30857gstein return OK;
0e8fe062a6ec71b4207d1a125ee6b44b7fd30857gstein
0e8fe062a6ec71b4207d1a125ee6b44b7fd30857gstein /* OK, it's a symlink. May still be OK with OPT_SYM_OWNER */
0e8fe062a6ec71b4207d1a125ee6b44b7fd30857gstein
0e8fe062a6ec71b4207d1a125ee6b44b7fd30857gstein if (!(opts & OPT_SYM_OWNER))
f4c310fd2555c6faca1f980f00b161eadb089023gstein return HTTP_FORBIDDEN;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* OPT_SYM_OWNER only works if we can get the owner from the file */
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm if (res != APR_SUCCESS)
f4c310fd2555c6faca1f980f00b161eadb089023gstein return HTTP_FORBIDDEN;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (apr_stat(&fi, d, APR_FINFO_OWNER, p) != APR_SUCCESS)
f4c310fd2555c6faca1f980f00b161eadb089023gstein return HTTP_FORBIDDEN;
f94aab38f6ee899f463f0118ea395291f7c5b4cegstein
f94aab38f6ee899f463f0118ea395291f7c5b4cegstein /* TODO: replace with an apr_compare_users() fn */
707ecf9559338ec06b24334bc9abcca670325cc4gstein return (fi.user == lfi.user) ? OK : HTTP_FORBIDDEN;
707ecf9559338ec06b24334bc9abcca670325cc4gstein
707ecf9559338ec06b24334bc9abcca670325cc4gstein#endif
707ecf9559338ec06b24334bc9abcca670325cc4gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* Dealing with the file system to get PATH_INFO
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic int get_path_info(request_rec *r)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm char *cp;
f4c310fd2555c6faca1f980f00b161eadb089023gstein char *path = r->filename;
f4c310fd2555c6faca1f980f00b161eadb089023gstein char *end = &path[strlen(path)];
f4c310fd2555c6faca1f980f00b161eadb089023gstein char *last_cp = NULL;
f4c310fd2555c6faca1f980f00b161eadb089023gstein int rv;
f4c310fd2555c6faca1f980f00b161eadb089023gstein#if defined(HAVE_DRIVE_LETTERS) || defined(HAVE_UNC_PATHS)
f4c310fd2555c6faca1f980f00b161eadb089023gstein char bStripSlash=1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (r->finfo.filetype != APR_NOFILE) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* assume path_info already set */
f4c310fd2555c6faca1f980f00b161eadb089023gstein return OK;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef HAVE_DRIVE_LETTERS
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* If the directory is x:\, then we don't want to strip
f4c310fd2555c6faca1f980f00b161eadb089023gstein * the trailing slash since x: is not a valid directory.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (strlen(path) == 3 && path[1] == ':' && path[2] == '/')
f4c310fd2555c6faca1f980f00b161eadb089023gstein bStripSlash = 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein#ifdef HAVE_UNC_PATHS
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.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein cp = end;
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (path[0] == '/' && path[1] == '/' &&
f4c310fd2555c6faca1f980f00b161eadb089023gstein path[2] != '/' && cp[-1] == '/') {
f4c310fd2555c6faca1f980f00b161eadb089023gstein char *p;
f4c310fd2555c6faca1f980f00b161eadb089023gstein int iCount=0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein p = path;
f4c310fd2555c6faca1f980f00b161eadb089023gstein while ((p = strchr(p,'/')) != NULL) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein p++;
f4c310fd2555c6faca1f980f00b161eadb089023gstein iCount++;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (iCount == 4)
f4c310fd2555c6faca1f980f00b161eadb089023gstein bStripSlash = 0;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm }
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
53dafcfda483886730db8e57bf6f94cff36f0047stoddard
f71d4ec448449837beefe21cf7c9f8d9b6bd4654gstein#if defined(HAVE_DRIVE_LETTERS) || defined(HAVE_UNC_PATHS)
f71d4ec448449837beefe21cf7c9f8d9b6bd4654gstein if (bStripSlash)
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Advance over trailing slashes ... NOT part of filename
f4c310fd2555c6faca1f980f00b161eadb089023gstein * if file is not a UNC name (Win32 only).
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (cp = end; cp > path && cp[-1] == '/'; --cp)
f4c310fd2555c6faca1f980f00b161eadb089023gstein continue;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f71d4ec448449837beefe21cf7c9f8d9b6bd4654gstein while (cp > path) {
f71d4ec448449837beefe21cf7c9f8d9b6bd4654gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* See if the pathname ending here exists... */
f4c310fd2555c6faca1f980f00b161eadb089023gstein *cp = '\0';
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### We no longer need the test ap_os_is_filename_valid() here
f4c310fd2555c6faca1f980f00b161eadb089023gstein * since apr_stat isn't a posix thing - it's apr_stat's responsibility
f4c310fd2555c6faca1f980f00b161eadb089023gstein * to handle whatever path string arrives at 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 */
f71d4ec448449837beefe21cf7c9f8d9b6bd4654gstein rv = apr_stat(&r->finfo, path, APR_FINFO_MIN, r->pool);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (cp != end)
f4c310fd2555c6faca1f980f00b161eadb089023gstein *cp = '/';
f4c310fd2555c6faca1f980f00b161eadb089023gstein
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm if (rv == APR_SUCCESS || rv == APR_INCOMPLETE) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /*
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 */
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm if (r->finfo.filetype == APR_DIR && last_cp) {
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm r->finfo.filetype = APR_NOFILE; /* No such file... */
f4c310fd2555c6faca1f980f00b161eadb089023gstein cp = last_cp;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein r->path_info = apr_pstrdup(r->pool, cp);
f4c310fd2555c6faca1f980f00b161eadb089023gstein *cp = '\0';
f4c310fd2555c6faca1f980f00b161eadb089023gstein return OK;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm }
1f6e6566a4ce31a0b95d5400c36d0aaff7a6e94agstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (APR_STATUS_IS_ENOENT(rv) || APR_STATUS_IS_ENOTDIR(rv)) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein last_cp = cp;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein while (--cp > path && *cp != '/')
f4c310fd2555c6faca1f980f00b161eadb089023gstein continue;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm while (cp > path && cp[-1] == '/')
1f6e6566a4ce31a0b95d5400c36d0aaff7a6e94agstein --cp;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else {
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (APR_STATUS_IS_EACCES(rv))
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "access to %s denied", r->uri);
f4c310fd2555c6faca1f980f00b161eadb089023gstein else
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "access to %s failed", r->uri);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm return HTTP_FORBIDDEN;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm }
1f6e6566a4ce31a0b95d5400c36d0aaff7a6e94agstein }
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm return OK;
1f6e6566a4ce31a0b95d5400c36d0aaff7a6e94agstein}
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm
1ccd992d37d62c8cb2056126f2234f64ec189bfddougmAP_DECLARE(int) directory_walk(request_rec *r)
1f6e6566a4ce31a0b95d5400c36d0aaff7a6e94agstein{
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm core_server_config *sconf = ap_get_module_config(r->server->module_config,
f4c310fd2555c6faca1f980f00b161eadb089023gstein &core_module);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_conf_vector_t *per_dir_defaults = r->server->lookup_defaults;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_conf_vector_t **sec = (ap_conf_vector_t **) sconf->sec->elts;
f4c310fd2555c6faca1f980f00b161eadb089023gstein int num_sec = sconf->sec->nelts;
f4c310fd2555c6faca1f980f00b161eadb089023gstein char *test_filename;
f4c310fd2555c6faca1f980f00b161eadb089023gstein char *test_dirname;
f4c310fd2555c6faca1f980f00b161eadb089023gstein int res;
f4c310fd2555c6faca1f980f00b161eadb089023gstein unsigned i, num_dirs;
f4c310fd2555c6faca1f980f00b161eadb089023gstein int j, test_filename_len;
f4c310fd2555c6faca1f980f00b161eadb089023gstein#if defined(HAVE_UNC_PATHS) || defined(NETWARE)
f4c310fd2555c6faca1f980f00b161eadb089023gstein unsigned iStart = 1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_conf_vector_t *entry_config;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_conf_vector_t *this_conf;
1f6e6566a4ce31a0b95d5400c36d0aaff7a6e94agstein core_dir_config *entry_core;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm
f4c310fd2555c6faca1f980f00b161eadb089023gstein /*
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.
cccd31fa4a72fe23cc3249c06db181b274a55a69gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (r->filename == NULL) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein r->filename = apr_pstrdup(r->pool, r->uri);
f4c310fd2555c6faca1f980f00b161eadb089023gstein r->finfo.filetype = APR_NOFILE;
f4c310fd2555c6faca1f980f00b161eadb089023gstein r->per_dir_config = per_dir_defaults;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein return OK;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /*
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Go down the directory hierarchy. Where we have to check for symlinks,
f4c310fd2555c6faca1f980f00b161eadb089023gstein * do so. Where a .htaccess file has permission to override anything,
f4c310fd2555c6faca1f980f00b161eadb089023gstein * try to find one. If either of these things fails, we could poke
f4c310fd2555c6faca1f980f00b161eadb089023gstein * around, see why, and adjust the lookup_rec accordingly --- this might
f4c310fd2555c6faca1f980f00b161eadb089023gstein * save us a call to get_path_info (with the attendant stat()s); however,
f4c310fd2555c6faca1f980f00b161eadb089023gstein * for the moment, that's not worth the trouble.
f4c310fd2555c6faca1f980f00b161eadb089023gstein *
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Fake filenames (i.e. proxy:) only match Directory sections.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
1f6e6566a4ce31a0b95d5400c36d0aaff7a6e94agstein
1f6e6566a4ce31a0b95d5400c36d0aaff7a6e94agstein if (!ap_os_is_path_absolute(r->filename))
1f6e6566a4ce31a0b95d5400c36d0aaff7a6e94agstein {
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *entry_dir;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm for (j = 0; j < num_sec; ++j) {
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm
f4c310fd2555c6faca1f980f00b161eadb089023gstein entry_config = sec[j];
f4c310fd2555c6faca1f980f00b161eadb089023gstein entry_core = ap_get_module_config(entry_config, &core_module);
f4c310fd2555c6faca1f980f00b161eadb089023gstein entry_dir = entry_core->d;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein this_conf = NULL;
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (entry_core->r) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!ap_regexec(entry_core->r, r->filename, 0, NULL, 0))
f4c310fd2555c6faca1f980f00b161eadb089023gstein this_conf = entry_config;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else if (entry_core->d_is_fnmatch) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!apr_fnmatch(entry_dir, r->filename, 0))
f4c310fd2555c6faca1f980f00b161eadb089023gstein this_conf = entry_config;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else if (!strncmp(r->filename, entry_dir, strlen(entry_dir)))
f4c310fd2555c6faca1f980f00b161eadb089023gstein this_conf = entry_config;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (this_conf)
f4c310fd2555c6faca1f980f00b161eadb089023gstein per_dir_defaults = ap_merge_per_dir_configs(r->pool,
f4c310fd2555c6faca1f980f00b161eadb089023gstein per_dir_defaults,
f4c310fd2555c6faca1f980f00b161eadb089023gstein this_conf);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein r->per_dir_config = per_dir_defaults;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein return OK;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
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 */
f4c310fd2555c6faca1f980f00b161eadb089023gstein r->filename = ap_os_case_canonical_filename(r->pool, r->filename);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm
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 */
f4c310fd2555c6faca1f980f00b161eadb089023gstein res = get_path_info(r);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm if (res != OK) {
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm return res;
4c449c30215bd5e8bad122a4118f5a7b0e995472wrowe }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* XXX This becomes moot, and will already happen above for elements
f4c310fd2555c6faca1f980f00b161eadb089023gstein * that actually exist:
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm r->filename = ap_os_canonical_filename(r->pool, r->filename);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein test_filename = apr_pstrdup(r->pool, r->filename);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* XXX This becomes mute, since the APR canonical parsing will handle
f4c310fd2555c6faca1f980f00b161eadb089023gstein * 2slash and dot directory issues:
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_no2slash(test_filename);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm num_dirs = ap_count_dirs(test_filename);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* XXX This needs to be rolled into APR: */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((res = check_safe_file(r))) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein return res;
4c449c30215bd5e8bad122a4118f5a7b0e995472wrowe }
4c449c30215bd5e8bad122a4118f5a7b0e995472wrowe
33397e35239f202a595837571561468f02b2e806gstein test_filename_len = strlen(test_filename);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (test_filename[test_filename_len - 1] == '/')
f4c310fd2555c6faca1f980f00b161eadb089023gstein --num_dirs;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (r->finfo.filetype == APR_DIR)
f4c310fd2555c6faca1f980f00b161eadb089023gstein ++num_dirs;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /*
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 */
f4c310fd2555c6faca1f980f00b161eadb089023gstein test_dirname = apr_palloc(r->pool, test_filename_len + 2);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
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 */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein#if defined(HAVE_UNC_PATHS)
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* If the name is a UNC name, then do not perform any true file test
f4c310fd2555c6faca1f980f00b161eadb089023gstein * against the machine name (start at //machine/share/)
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * This is optimized to use the normal walk (skips the redundant '/' root)
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (num_dirs > 3 && test_filename[0] == '/' && test_filename[1] == '/')
5646ba89a25a695006edae46de226fb57a2e6270gstein iStart = 4;
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm
f4c310fd2555c6faca1f980f00b161eadb089023gstein#if defined(NETWARE)
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* If the name is a fully qualified volume name, then do not perform any
f4c310fd2555c6faca1f980f00b161eadb089023gstein * true file test on the machine name (start at machine/share:/)
f4c310fd2555c6faca1f980f00b161eadb089023gstein * XXX: The implementation eludes me at this moment...
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Does this make sense? Please test!
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein */
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein if (num_dirs > 1 && strchr(test_filename, '/') < strchr(test_filename, ':'))
f4c310fd2555c6faca1f980f00b161eadb089023gstein iStart = 2;
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein#if defined(HAVE_DRIVE_LETTERS) || defined(NETWARE)
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 *
f4c310fd2555c6faca1f980f00b161eadb089023gstein * NOTE: MUST SYNC WITH ap_make_dirstr_prefix() CHANGE IN src/main/util.c
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (test_filename[0] == '/')
f4c310fd2555c6faca1f980f00b161eadb089023gstein i = 1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein else
f4c310fd2555c6faca1f980f00b161eadb089023gstein i = 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein#else
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Normal File Systems are rooted at / */
f4c310fd2555c6faca1f980f00b161eadb089023gstein i = 1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif /* def HAVE_DRIVE_LETTERS || NETWARE */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* j keeps track of which section we're on, see core_reorder_directories */
f4c310fd2555c6faca1f980f00b161eadb089023gstein j = 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (; i <= num_dirs; ++i) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein int overrides_here;
f4c310fd2555c6faca1f980f00b161eadb089023gstein core_dir_config *core_dir = ap_get_module_config(per_dir_defaults,
f4c310fd2555c6faca1f980f00b161eadb089023gstein &core_module);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /*
f4c310fd2555c6faca1f980f00b161eadb089023gstein * XXX: this could be made faster by only copying the next component
f4c310fd2555c6faca1f980f00b161eadb089023gstein * rather than copying the entire thing all over.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_make_dirstr_prefix(test_dirname, test_filename, i);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /*
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Do symlink checks first, because they are done with the
f4c310fd2555c6faca1f980f00b161eadb089023gstein * permissions appropriate to the *parent* directory...
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein#if defined(HAVE_UNC_PATHS) || defined(NETWARE)
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Test only legal names against the real filesystem */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (i >= iStart)
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
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 "Symbolic link not allowed: %s", test_dirname);
f4c310fd2555c6faca1f980f00b161eadb089023gstein return res;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /*
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Begin *this* level by looking for matching <Directory> sections
f4c310fd2555c6faca1f980f00b161eadb089023gstein * from access.conf.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (; j < num_sec; ++j) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein char *entry_dir;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein entry_config = sec[j];
f4c310fd2555c6faca1f980f00b161eadb089023gstein entry_core = ap_get_module_config(entry_config, &core_module);
f4c310fd2555c6faca1f980f00b161eadb089023gstein entry_dir = entry_core->d;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (entry_core->r
f4c310fd2555c6faca1f980f00b161eadb089023gstein || !entry_core->d_is_absolute
f4c310fd2555c6faca1f980f00b161eadb089023gstein#if defined(HAVE_DRIVE_LETTERS) || defined(NETWARE)
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 */
f4c310fd2555c6faca1f980f00b161eadb089023gstein || (entry_core->d_components > 1
f4c310fd2555c6faca1f980f00b161eadb089023gstein && entry_core->d_components > i)
f4c310fd2555c6faca1f980f00b161eadb089023gstein#else
f4c310fd2555c6faca1f980f00b161eadb089023gstein || entry_core->d_components > i
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif /* def HAVE_DRIVE_LETTERS || NETWARE */
f4c310fd2555c6faca1f980f00b161eadb089023gstein )
f4c310fd2555c6faca1f980f00b161eadb089023gstein break;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein this_conf = NULL;
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (entry_core->d_is_fnmatch) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!apr_fnmatch(entry_dir, test_dirname, FNM_PATHNAME)) {
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm this_conf = entry_config;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else if (!strcmp(test_dirname, entry_dir))
f4c310fd2555c6faca1f980f00b161eadb089023gstein this_conf = entry_config;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (this_conf) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein per_dir_defaults = ap_merge_per_dir_configs(r->pool,
f4c310fd2555c6faca1f980f00b161eadb089023gstein per_dir_defaults,
f4c310fd2555c6faca1f980f00b161eadb089023gstein this_conf);
f4c310fd2555c6faca1f980f00b161eadb089023gstein core_dir = ap_get_module_config(per_dir_defaults,
f4c310fd2555c6faca1f980f00b161eadb089023gstein &core_module);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein#if defined(HAVE_DRIVE_LETTERS) || defined(NETWARE)
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 */
f4c310fd2555c6faca1f980f00b161eadb089023gstein else if (!i)
f4c310fd2555c6faca1f980f00b161eadb089023gstein break;
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif /* def HAVE_DRIVE_LETTERS || NETWARE */
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein overrides_here = core_dir->override;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* If .htaccess files are enabled, check for one. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein#if defined(HAVE_UNC_PATHS) || defined(NETWARE)
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Test only legal names against the real filesystem */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (i >= iStart)
f4c310fd2555c6faca1f980f00b161eadb089023gstein#endif
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (overrides_here) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_conf_vector_t *htaccess_conf = NULL;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein res = ap_parse_htaccess(&htaccess_conf, r, overrides_here,
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_pstrdup(r->pool, test_dirname),
f4c310fd2555c6faca1f980f00b161eadb089023gstein sconf->access_name);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (res)
f4c310fd2555c6faca1f980f00b161eadb089023gstein return res;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
33397e35239f202a595837571561468f02b2e806gstein if (htaccess_conf) {
33397e35239f202a595837571561468f02b2e806gstein per_dir_defaults = ap_merge_per_dir_configs(r->pool,
f4c310fd2555c6faca1f980f00b161eadb089023gstein per_dir_defaults,
f4c310fd2555c6faca1f980f00b161eadb089023gstein htaccess_conf);
f4c310fd2555c6faca1f980f00b161eadb089023gstein r->per_dir_config = per_dir_defaults;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
49bf4df23d9e5281abcd83005550bda818b17b08wrowe }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /*
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
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * regexes.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (; j < num_sec; ++j) {
ba2ad3b1bb4a729278ad8e8846d34ddd27b6551cgstein
ba2ad3b1bb4a729278ad8e8846d34ddd27b6551cgstein entry_config = sec[j];
ba2ad3b1bb4a729278ad8e8846d34ddd27b6551cgstein entry_core = ap_get_module_config(entry_config, &core_module);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein if (entry_core->r) {
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein if (!ap_regexec(entry_core->r, test_dirname, 0, NULL, REG_NOTEOL)) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein per_dir_defaults = ap_merge_per_dir_configs(r->pool,
f4c310fd2555c6faca1f980f00b161eadb089023gstein per_dir_defaults,
f4c310fd2555c6faca1f980f00b161eadb089023gstein entry_config);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein r->per_dir_config = per_dir_defaults;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /*
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Symlink permissions are determined by the parent. If the request is
f4c310fd2555c6faca1f980f00b161eadb089023gstein * for a directory then applying the symlink test here would use the
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 */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (r->finfo.filetype != APR_DIR
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 "Symbolic link not allowed: %s", r->filename);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm return res;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein return OK; /* Can only "fail" if access denied by the
f4c310fd2555c6faca1f980f00b161eadb089023gstein * symlink goop. */
ba2ad3b1bb4a729278ad8e8846d34ddd27b6551cgstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE(int) location_walk(request_rec *r)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein core_server_config *sconf = ap_get_module_config(r->server->module_config,
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm &core_module);
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 int len, num_url = sconf->sec_url->nelts;
f4c310fd2555c6faca1f980f00b161eadb089023gstein char *test_location;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_conf_vector_t *this_conf;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_conf_vector_t *entry_config;
f4c310fd2555c6faca1f980f00b161eadb089023gstein core_dir_config *entry_core;
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein char *entry_url;
f4c310fd2555c6faca1f980f00b161eadb089023gstein int j;
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!num_url) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein return OK;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Location and LocationMatch differ on their behaviour w.r.t. multiple
f4c310fd2555c6faca1f980f00b161eadb089023gstein * slashes. Location matches multiple slashes with a single slash,
f4c310fd2555c6faca1f980f00b161eadb089023gstein * LocationMatch doesn't. An exception, for backwards brokenness is
f4c310fd2555c6faca1f980f00b161eadb089023gstein * absoluteURIs... in which case neither match multiple slashes.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (r->uri[0] != '/') {
f4c310fd2555c6faca1f980f00b161eadb089023gstein test_location = r->uri;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else {
f4c310fd2555c6faca1f980f00b161eadb089023gstein test_location = apr_pstrdup(r->pool, r->uri);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_no2slash(test_location);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Go through the location entries, and check for matches. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* we apply the directive sections in some order;
f4c310fd2555c6faca1f980f00b161eadb089023gstein * should really try them with the most general first.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (j = 0; j < num_url; ++j) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein entry_config = url[j];
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein entry_core = ap_get_module_config(entry_config, &core_module);
f4c310fd2555c6faca1f980f00b161eadb089023gstein entry_url = entry_core->d;
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein len = strlen(entry_url);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein this_conf = NULL;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (entry_core->r) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!ap_regexec(entry_core->r, r->uri, 0, NULL, 0))
f4c310fd2555c6faca1f980f00b161eadb089023gstein this_conf = entry_config;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else if (entry_core->d_is_fnmatch) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!apr_fnmatch(entry_url, test_location, FNM_PATHNAME)) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein this_conf = entry_config;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else if (!strncmp(test_location, entry_url, len) &&
f4c310fd2555c6faca1f980f00b161eadb089023gstein (entry_url[len - 1] == '/' ||
f4c310fd2555c6faca1f980f00b161eadb089023gstein test_location[len] == '/' || test_location[len] == '\0'))
f4c310fd2555c6faca1f980f00b161eadb089023gstein this_conf = entry_config;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (this_conf)
f4c310fd2555c6faca1f980f00b161eadb089023gstein per_dir_defaults = ap_merge_per_dir_configs(r->pool,
f4c310fd2555c6faca1f980f00b161eadb089023gstein per_dir_defaults,
f4c310fd2555c6faca1f980f00b161eadb089023gstein this_conf);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein r->per_dir_config = per_dir_defaults;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein return OK;
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm
ba2ad3b1bb4a729278ad8e8846d34ddd27b6551cgsteinAP_DECLARE(int) file_walk(request_rec *r)
ba2ad3b1bb4a729278ad8e8846d34ddd27b6551cgstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein core_dir_config *conf = ap_get_module_config(r->per_dir_config,
f4c310fd2555c6faca1f980f00b161eadb089023gstein &core_module);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_conf_vector_t *per_dir_defaults = r->per_dir_config;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_conf_vector_t **file = (ap_conf_vector_t **) conf->sec->elts;
f4c310fd2555c6faca1f980f00b161eadb089023gstein int num_files = conf->sec->nelts;
f4c310fd2555c6faca1f980f00b161eadb089023gstein char *test_file;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm /* get the basename */
f4c310fd2555c6faca1f980f00b161eadb089023gstein test_file = strrchr(r->filename, '/');
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (test_file == NULL) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein test_file = r->filename;
ba2ad3b1bb4a729278ad8e8846d34ddd27b6551cgstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ++test_file;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Go through the file entries, and check for matches. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (num_files) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_conf_vector_t *this_conf;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm ap_conf_vector_t *entry_config;
f4c310fd2555c6faca1f980f00b161eadb089023gstein core_dir_config *entry_core;
f4c310fd2555c6faca1f980f00b161eadb089023gstein char *entry_file;
f4c310fd2555c6faca1f980f00b161eadb089023gstein int j;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* we apply the directive sections in some order;
f4c310fd2555c6faca1f980f00b161eadb089023gstein * should really try them with the most general first.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (j = 0; j < num_files; ++j) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein entry_config = file[j];
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein entry_core = ap_get_module_config(entry_config, &core_module);
f4c310fd2555c6faca1f980f00b161eadb089023gstein entry_file = entry_core->d;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein this_conf = NULL;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (entry_core->r) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!ap_regexec(entry_core->r, test_file, 0, NULL, 0))
f4c310fd2555c6faca1f980f00b161eadb089023gstein this_conf = entry_config;
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein }
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein else if (entry_core->d_is_fnmatch) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!apr_fnmatch(entry_file, test_file, FNM_PATHNAME)) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein this_conf = entry_config;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else if (!strcmp(test_file, entry_file)) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein this_conf = entry_config;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (this_conf)
f4c310fd2555c6faca1f980f00b161eadb089023gstein per_dir_defaults = ap_merge_per_dir_configs(r->pool,
f4c310fd2555c6faca1f980f00b161eadb089023gstein per_dir_defaults,
49bf4df23d9e5281abcd83005550bda818b17b08wrowe this_conf);
49bf4df23d9e5281abcd83005550bda818b17b08wrowe }
f4c310fd2555c6faca1f980f00b161eadb089023gstein r->per_dir_config = per_dir_defaults;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein return OK;
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein/*****************************************************************
f4c310fd2555c6faca1f980f00b161eadb089023gstein *
f4c310fd2555c6faca1f980f00b161eadb089023gstein * The sub_request mechanism.
f4c310fd2555c6faca1f980f00b161eadb089023gstein *
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Fns to look up a relative URI from, e.g., a map file or SSI document.
f4c310fd2555c6faca1f980f00b161eadb089023gstein * These do all access checks, etc., but don't actually run the transaction
f4c310fd2555c6faca1f980f00b161eadb089023gstein * ... use run_sub_req below for that. Also, be sure to use destroy_sub_req
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 *
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * Note more manipulation of protocol-specific vars in the request
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * structure...
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic request_rec *make_sub_request(const request_rec *r)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_pool_t *rrp;
1f6e6566a4ce31a0b95d5400c36d0aaff7a6e94agstein request_rec *rr;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_pool_create(&rrp, r->pool);
f4c310fd2555c6faca1f980f00b161eadb089023gstein rr = apr_pcalloc(rrp, sizeof(request_rec));
1f6e6566a4ce31a0b95d5400c36d0aaff7a6e94agstein rr->pool = rrp;
f4c310fd2555c6faca1f980f00b161eadb089023gstein return rr;
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
1f6e6566a4ce31a0b95d5400c36d0aaff7a6e94agstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic void fill_in_sub_req_vars(request_rec *rnew, const request_rec *r,
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_filter_t *next_filter)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein rnew->hostname = r->hostname;
f4c310fd2555c6faca1f980f00b161eadb089023gstein rnew->request_time = r->request_time;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm rnew->connection = r->connection;
1f6e6566a4ce31a0b95d5400c36d0aaff7a6e94agstein rnew->server = r->server;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein rnew->request_config = ap_create_request_config(rnew->pool);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein rnew->htaccess = r->htaccess;
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein rnew->allowed_methods = ap_make_method_list(rnew->pool, 2);
1f6e6566a4ce31a0b95d5400c36d0aaff7a6e94agstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* make a copy of the allowed-methods list */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_copy_method_list(rnew->allowed_methods, r->allowed_methods);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* start with the same set of output filters */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (next_filter) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein rnew->output_filters = next_filter;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm else {
f4c310fd2555c6faca1f980f00b161eadb089023gstein rnew->output_filters = r->output_filters;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm ap_add_output_filter("SUBREQ_CORE", NULL, rnew, rnew->connection);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* no input filters for a subrequest */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_set_sub_req_protocol(rnew, r);
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic int sub_req_common_validation(request_rec *rnew)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein int res;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((( ap_satisfies(rnew) == SATISFY_ALL
f4c310fd2555c6faca1f980f00b161eadb089023gstein || ap_satisfies(rnew) == SATISFY_NOSPEC)
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm ? ((res = ap_run_access_checker(rnew))
f4c310fd2555c6faca1f980f00b161eadb089023gstein || (ap_some_auth_required(rnew)
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm && ((res = ap_run_check_user_id(rnew))
f4c310fd2555c6faca1f980f00b161eadb089023gstein || (res = ap_run_auth_checker(rnew)))))
f4c310fd2555c6faca1f980f00b161eadb089023gstein : ((res = ap_run_access_checker(rnew))
f4c310fd2555c6faca1f980f00b161eadb089023gstein && (!ap_some_auth_required(rnew)
f4c310fd2555c6faca1f980f00b161eadb089023gstein || ((res = ap_run_check_user_id(rnew))
f4c310fd2555c6faca1f980f00b161eadb089023gstein || (res = ap_run_auth_checker(rnew)))))
f4c310fd2555c6faca1f980f00b161eadb089023gstein )
f4c310fd2555c6faca1f980f00b161eadb089023gstein || (res = ap_run_type_checker(rnew))
f4c310fd2555c6faca1f980f00b161eadb089023gstein || (res = ap_run_fixups(rnew)))
f4c310fd2555c6faca1f980f00b161eadb089023gstein return res;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm else
f4c310fd2555c6faca1f980f00b161eadb089023gstein return 0;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
1ccd992d37d62c8cb2056126f2234f64ec189bfddougmAP_CORE_DECLARE_NONSTD(apr_status_t) ap_sub_req_output_filter(ap_filter_t *f,
1f6e6566a4ce31a0b95d5400c36d0aaff7a6e94agstein apr_bucket_brigade *bb)
1f6e6566a4ce31a0b95d5400c36d0aaff7a6e94agstein{
1f6e6566a4ce31a0b95d5400c36d0aaff7a6e94agstein apr_bucket *e = APR_BRIGADE_LAST(bb);
1f6e6566a4ce31a0b95d5400c36d0aaff7a6e94agstein
1f6e6566a4ce31a0b95d5400c36d0aaff7a6e94agstein if (APR_BUCKET_IS_EOS(e)) {
1f6e6566a4ce31a0b95d5400c36d0aaff7a6e94agstein apr_bucket_delete(e);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein return ap_pass_brigade(f->next, bb);
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE(int) ap_some_auth_required(request_rec *r)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Is there a require line configured for the type of *this* req? */
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm
f4c310fd2555c6faca1f980f00b161eadb089023gstein const apr_array_header_t *reqs_arr = ap_requires(r);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm require_line *reqs;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm int i;
1f6e6566a4ce31a0b95d5400c36d0aaff7a6e94agstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!reqs_arr)
f4c310fd2555c6faca1f980f00b161eadb089023gstein return 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein reqs = (require_line *) reqs_arr->elts;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (i = 0; i < reqs_arr->nelts; ++i)
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (reqs[i].method_mask & (1 << r->method_number))
f4c310fd2555c6faca1f980f00b161eadb089023gstein return 1;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein return 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE(request_rec *) ap_sub_req_method_uri(const char *method,
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *new_file,
f4c310fd2555c6faca1f980f00b161eadb089023gstein const request_rec *r,
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_filter_t *next_filter)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein request_rec *rnew;
f4c310fd2555c6faca1f980f00b161eadb089023gstein int res;
f4c310fd2555c6faca1f980f00b161eadb089023gstein char *udir;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein rnew = make_sub_request(r);
f4c310fd2555c6faca1f980f00b161eadb089023gstein fill_in_sub_req_vars(rnew, r, next_filter);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm rnew->per_dir_config = r->server->lookup_defaults;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* We have to run this after ap_set_sub_req_protocol, or the r->main
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein * pointer won't be setup
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_run_create_request(rnew);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* would be nicer to pass "method" to ap_set_sub_req_protocol */
f4c310fd2555c6faca1f980f00b161eadb089023gstein rnew->method = method;
f4c310fd2555c6faca1f980f00b161eadb089023gstein rnew->method_number = ap_method_number_of(method);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (new_file[0] == '/')
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_parse_uri(rnew, new_file);
f4c310fd2555c6faca1f980f00b161eadb089023gstein else {
f4c310fd2555c6faca1f980f00b161eadb089023gstein udir = ap_make_dirstr_parent(rnew->pool, r->uri);
f4c310fd2555c6faca1f980f00b161eadb089023gstein udir = ap_escape_uri(rnew->pool, udir); /* re-escape it */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_parse_uri(rnew, ap_make_full_path(rnew->pool, udir, new_file));
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein res = ap_unescape_url(rnew->uri);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (res) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein rnew->status = res;
f4c310fd2555c6faca1f980f00b161eadb089023gstein return rnew;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_getparents(rnew->uri);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
33397e35239f202a595837571561468f02b2e806gstein if ((res = location_walk(rnew))) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein rnew->status = res;
f4c310fd2555c6faca1f980f00b161eadb089023gstein return rnew;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
33397e35239f202a595837571561468f02b2e806gstein res = ap_run_translate_name(rnew);
1f6e6566a4ce31a0b95d5400c36d0aaff7a6e94agstein if (res) {
33397e35239f202a595837571561468f02b2e806gstein rnew->status = res;
1f6e6566a4ce31a0b95d5400c36d0aaff7a6e94agstein return rnew;
1f6e6566a4ce31a0b95d5400c36d0aaff7a6e94agstein }
1f6e6566a4ce31a0b95d5400c36d0aaff7a6e94agstein
1f6e6566a4ce31a0b95d5400c36d0aaff7a6e94agstein /*
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 * results.
f4c310fd2555c6faca1f980f00b161eadb089023gstein *
f4c310fd2555c6faca1f980f00b161eadb089023gstein * NB: directory_walk() clears the per_dir_config, so we don't inherit
f4c310fd2555c6faca1f980f00b161eadb089023gstein * from location_walk() above
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((res = directory_walk(rnew))
f4c310fd2555c6faca1f980f00b161eadb089023gstein || (res = file_walk(rnew))
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein || (res = location_walk(rnew))
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein || (res = sub_req_common_validation(rnew))) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein rnew->status = res;
707ecf9559338ec06b24334bc9abcca670325cc4gstein }
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein return rnew;
707ecf9559338ec06b24334bc9abcca670325cc4gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE(request_rec *) ap_sub_req_lookup_uri(const char *new_file,
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein const request_rec *r,
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_filter_t *next_filter)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein return ap_sub_req_method_uri("GET", new_file, r, next_filter);
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE(request_rec *) ap_sub_req_lookup_dirent(const apr_finfo_t *dirent,
f4c310fd2555c6faca1f980f00b161eadb089023gstein const request_rec *r,
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_filter_t *next_filter)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein apr_status_t rv;
707ecf9559338ec06b24334bc9abcca670325cc4gstein request_rec *rnew;
f4c310fd2555c6faca1f980f00b161eadb089023gstein int res;
f4c310fd2555c6faca1f980f00b161eadb089023gstein char *fdir;
707ecf9559338ec06b24334bc9abcca670325cc4gstein char *udir;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein rnew = make_sub_request(r);
f4c310fd2555c6faca1f980f00b161eadb089023gstein fill_in_sub_req_vars(rnew, r, next_filter);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
707ecf9559338ec06b24334bc9abcca670325cc4gstein rnew->chunked = r->chunked;
1f6e6566a4ce31a0b95d5400c36d0aaff7a6e94agstein
1f6e6566a4ce31a0b95d5400c36d0aaff7a6e94agstein /* We have to run this after ap_set_sub_req_protocol, or the r->main
f4c310fd2555c6faca1f980f00b161eadb089023gstein * pointer won't be setup
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_run_create_request(rnew);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein fdir = ap_make_dirstr_parent(rnew->pool, r->filename);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /*
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Special case: we are looking at a relative lookup in the same directory.
f4c310fd2555c6faca1f980f00b161eadb089023gstein * That means we won't have to redo directory_walk, and we may
f4c310fd2555c6faca1f980f00b161eadb089023gstein * not even have to redo access checks.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein udir = ap_make_dirstr_parent(rnew->pool, r->uri);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
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
707ecf9559338ec06b24334bc9abcca670325cc4gstein if ((dirent->valid & APR_FINFO_MIN) != APR_FINFO_MIN) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (((rv = apr_stat(&rnew->finfo, rnew->filename,
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein APR_FINFO_MIN, rnew->pool)) != APR_SUCCESS)
f4c310fd2555c6faca1f980f00b161eadb089023gstein && (rv != APR_INCOMPLETE)) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein rnew->finfo.filetype = 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else {
f4c310fd2555c6faca1f980f00b161eadb089023gstein memcpy (&rnew->finfo, dirent, sizeof(apr_finfo_t));
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((res = check_safe_file(rnew))) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein rnew->status = res;
f4c310fd2555c6faca1f980f00b161eadb089023gstein return rnew;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein rnew->per_dir_config = r->per_dir_config;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /*
f4c310fd2555c6faca1f980f00b161eadb089023gstein * no matter what, if it's a subdirectory, we need to re-run
f4c310fd2555c6faca1f980f00b161eadb089023gstein * directory_walk
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (rnew->finfo.filetype == APR_DIR) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein res = directory_walk(rnew);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!res) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein res = file_walk(rnew);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
707ecf9559338ec06b24334bc9abcca670325cc4gstein }
707ecf9559338ec06b24334bc9abcca670325cc4gstein else {
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein if ((res = check_symlinks(rnew->filename, ap_allow_options(rnew),
707ecf9559338ec06b24334bc9abcca670325cc4gstein rnew->pool))) {
707ecf9559338ec06b24334bc9abcca670325cc4gstein ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, rnew,
707ecf9559338ec06b24334bc9abcca670325cc4gstein "Symbolic link not allowed: %s", rnew->filename);
707ecf9559338ec06b24334bc9abcca670325cc4gstein rnew->status = res;
f4c310fd2555c6faca1f980f00b161eadb089023gstein return rnew;
707ecf9559338ec06b24334bc9abcca670325cc4gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein /*
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
707ecf9559338ec06b24334bc9abcca670325cc4gstein */
707ecf9559338ec06b24334bc9abcca670325cc4gstein if ((res = file_walk(rnew))) {
707ecf9559338ec06b24334bc9abcca670325cc4gstein rnew->status = res;
f4c310fd2555c6faca1f980f00b161eadb089023gstein return rnew;
707ecf9559338ec06b24334bc9abcca670325cc4gstein }
707ecf9559338ec06b24334bc9abcca670325cc4gstein if (rnew->per_dir_config == r->per_dir_config) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((res = ap_run_type_checker(rnew)) || (res = ap_run_fixups(rnew))) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein rnew->status = res;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein return rnew;
707ecf9559338ec06b24334bc9abcca670325cc4gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (res || (res = sub_req_common_validation(rnew))) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein rnew->status = res;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein return rnew;
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE(request_rec *) ap_sub_req_lookup_file(const char *new_file,
f4c310fd2555c6faca1f980f00b161eadb089023gstein const request_rec *r,
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_filter_t *next_filter)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein request_rec *rnew;
f4c310fd2555c6faca1f980f00b161eadb089023gstein int res;
f4c310fd2555c6faca1f980f00b161eadb089023gstein char *fdir;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein rnew = make_sub_request(r);
f4c310fd2555c6faca1f980f00b161eadb089023gstein fill_in_sub_req_vars(rnew, r, next_filter);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein rnew->chunked = r->chunked;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* We have to run this after ap_set_sub_req_protocol, or the r->main
f4c310fd2555c6faca1f980f00b161eadb089023gstein * pointer won't be setup
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_run_create_request(rnew);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein fdir = ap_make_dirstr_parent(rnew->pool, r->filename);
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /*
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 */
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (ap_strchr_c(new_file, '/') == NULL) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein char *udir = ap_make_dirstr_parent(rnew->pool, r->uri);
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_status_t rv;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
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
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (((rv = apr_stat(&rnew->finfo, rnew->filename,
f4c310fd2555c6faca1f980f00b161eadb089023gstein APR_FINFO_MIN, rnew->pool)) != APR_SUCCESS)
f4c310fd2555c6faca1f980f00b161eadb089023gstein && (rv != APR_INCOMPLETE)) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein rnew->finfo.filetype = 0;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((res = check_safe_file(rnew))) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein rnew->status = res;
f4c310fd2555c6faca1f980f00b161eadb089023gstein return rnew;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein rnew->per_dir_config = r->per_dir_config;
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /*
f4c310fd2555c6faca1f980f00b161eadb089023gstein * no matter what, if it's a subdirectory, we need to re-run
f4c310fd2555c6faca1f980f00b161eadb089023gstein * directory_walk
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (rnew->finfo.filetype == APR_DIR) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein res = directory_walk(rnew);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!res) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein res = file_walk(rnew);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else {
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((res = check_symlinks(rnew->filename, ap_allow_options(rnew),
f4c310fd2555c6faca1f980f00b161eadb089023gstein rnew->pool))) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, rnew,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Symbolic link not allowed: %s", rnew->filename);
f4c310fd2555c6faca1f980f00b161eadb089023gstein rnew->status = res;
f4c310fd2555c6faca1f980f00b161eadb089023gstein return rnew;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein /*
f4c310fd2555c6faca1f980f00b161eadb089023gstein * 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
5646ba89a25a695006edae46de226fb57a2e6270gstein */
5646ba89a25a695006edae46de226fb57a2e6270gstein if ((res = file_walk(rnew))) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein rnew->status = res;
f4c310fd2555c6faca1f980f00b161eadb089023gstein return rnew;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (rnew->per_dir_config == r->per_dir_config) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((res = ap_run_type_checker(rnew)) || (res = ap_run_fixups(rnew))) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein rnew->status = res;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm }
f4c310fd2555c6faca1f980f00b161eadb089023gstein return rnew;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein else {
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm /* XXX: @@@: What should be done with the parsed_uri values? */
5646ba89a25a695006edae46de226fb57a2e6270gstein ap_parse_uri(rnew, new_file); /* fill in parsed_uri values */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /*
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
5646ba89a25a695006edae46de226fb57a2e6270gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gstein rnew->uri = "INTERNALLY GENERATED file-relative req";
5646ba89a25a695006edae46de226fb57a2e6270gstein rnew->filename = ((ap_os_is_path_absolute(new_file)) ?
5646ba89a25a695006edae46de226fb57a2e6270gstein apr_pstrdup(rnew->pool, new_file) :
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_make_full_path(rnew->pool, fdir, new_file));
f4c310fd2555c6faca1f980f00b161eadb089023gstein rnew->per_dir_config = r->server->lookup_defaults;
f4c310fd2555c6faca1f980f00b161eadb089023gstein res = directory_walk(rnew);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!res) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein res = file_walk(rnew);
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (res || (res = sub_req_common_validation(rnew))) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein rnew->status = res;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein return rnew;
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE(int) ap_run_sub_req(request_rec *r)
1f6e6566a4ce31a0b95d5400c36d0aaff7a6e94agstein{
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm int retval;
1f6e6566a4ce31a0b95d5400c36d0aaff7a6e94agstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* see comments in process_request_internal() */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_run_insert_filter(r);
f4c310fd2555c6faca1f980f00b161eadb089023gstein retval = ap_invoke_handler(r);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_finalize_sub_req_protocol(r);
f4c310fd2555c6faca1f980f00b161eadb089023gstein return retval;
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE(void) ap_destroy_sub_req(request_rec *r)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Reclaim the space */
f4c310fd2555c6faca1f980f00b161eadb089023gstein apr_pool_destroy(r->pool);
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein/*
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Function to set the r->mtime field to the specified value if it's later
f4c310fd2555c6faca1f980f00b161eadb089023gstein * than what's already there.
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE(void) ap_update_mtime(request_rec *r, apr_time_t dependency_mtime)
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm{
1f6e6566a4ce31a0b95d5400c36d0aaff7a6e94agstein if (r->mtime < dependency_mtime) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein r->mtime = dependency_mtime;
f4c310fd2555c6faca1f980f00b161eadb089023gstein }
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein/*
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Is it the initial main request, which we only get *once* per HTTP request?
f4c310fd2555c6faca1f980f00b161eadb089023gstein */
f4c310fd2555c6faca1f980f00b161eadb089023gsteinAP_DECLARE(int) ap_is_initial_req(request_rec *r)
f4c310fd2555c6faca1f980f00b161eadb089023gstein{
f4c310fd2555c6faca1f980f00b161eadb089023gstein return
f4c310fd2555c6faca1f980f00b161eadb089023gstein (r->main == NULL) /* otherwise, this is a sub-request */
f4c310fd2555c6faca1f980f00b161eadb089023gstein &&
f4c310fd2555c6faca1f980f00b161eadb089023gstein (r->prev == NULL); /* otherwise, this is an internal redirect */
f4c310fd2555c6faca1f980f00b161eadb089023gstein}
f4c310fd2555c6faca1f980f00b161eadb089023gstein
f4c310fd2555c6faca1f980f00b161eadb089023gstein