request.c revision efa1a34b0a7785fc72863eff175b0cfc1ecb0e38
658187feb755694eb5ff29561bda7109c22c743cAlexis Tsogias/* ====================================================================
658187feb755694eb5ff29561bda7109c22c743cAlexis Tsogias * The Apache Software License, Version 1.1
658187feb755694eb5ff29561bda7109c22c743cAlexis Tsogias * Copyright (c) 2000-2001 The Apache Software Foundation. All rights
658187feb755694eb5ff29561bda7109c22c743cAlexis Tsogias * Redistribution and use in source and binary forms, with or without
658187feb755694eb5ff29561bda7109c22c743cAlexis Tsogias * modification, are permitted provided that the following conditions
658187feb755694eb5ff29561bda7109c22c743cAlexis Tsogias * 1. Redistributions of source code must retain the above copyright
658187feb755694eb5ff29561bda7109c22c743cAlexis Tsogias * notice, this list of conditions and the following disclaimer.
658187feb755694eb5ff29561bda7109c22c743cAlexis Tsogias * 2. Redistributions in binary form must reproduce the above copyright
658187feb755694eb5ff29561bda7109c22c743cAlexis Tsogias * notice, this list of conditions and the following disclaimer in
658187feb755694eb5ff29561bda7109c22c743cAlexis Tsogias * the documentation and/or other materials provided with the
658187feb755694eb5ff29561bda7109c22c743cAlexis Tsogias * distribution.
c95de7451b35950f21196b610dab702730221a98Alexis Tsogias * 3. The end-user documentation included with the redistribution,
658187feb755694eb5ff29561bda7109c22c743cAlexis Tsogias * if any, must include the following acknowledgment:
658187feb755694eb5ff29561bda7109c22c743cAlexis Tsogias * "This product includes software developed by the
658187feb755694eb5ff29561bda7109c22c743cAlexis Tsogias * Apache Software Foundation (http://www.apache.org/)."
658187feb755694eb5ff29561bda7109c22c743cAlexis Tsogias * Alternately, this acknowledgment may appear in the software itself,
658187feb755694eb5ff29561bda7109c22c743cAlexis Tsogias * if and wherever such third-party acknowledgments normally appear.
658187feb755694eb5ff29561bda7109c22c743cAlexis Tsogias * 4. The names "Apache" and "Apache Software Foundation" must
658187feb755694eb5ff29561bda7109c22c743cAlexis Tsogias * not be used to endorse or promote products derived from this
658187feb755694eb5ff29561bda7109c22c743cAlexis Tsogias * software without prior written permission. For written
658187feb755694eb5ff29561bda7109c22c743cAlexis Tsogias * permission, please contact apache@apache.org.
658187feb755694eb5ff29561bda7109c22c743cAlexis Tsogias * 5. Products derived from this software may not be called "Apache",
658187feb755694eb5ff29561bda7109c22c743cAlexis Tsogias * nor may "Apache" appear in their name, without prior written
c95de7451b35950f21196b610dab702730221a98Alexis Tsogias * permission of the Apache Software Foundation.
658187feb755694eb5ff29561bda7109c22c743cAlexis Tsogias * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
658187feb755694eb5ff29561bda7109c22c743cAlexis Tsogias * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
658187feb755694eb5ff29561bda7109c22c743cAlexis Tsogias * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
658187feb755694eb5ff29561bda7109c22c743cAlexis Tsogias * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
658187feb755694eb5ff29561bda7109c22c743cAlexis Tsogias * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
c95de7451b35950f21196b610dab702730221a98Alexis Tsogias * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
c95de7451b35950f21196b610dab702730221a98Alexis Tsogias * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
c95de7451b35950f21196b610dab702730221a98Alexis Tsogias * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
c95de7451b35950f21196b610dab702730221a98Alexis Tsogias * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
c95de7451b35950f21196b610dab702730221a98Alexis Tsogias * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
c95de7451b35950f21196b610dab702730221a98Alexis Tsogias * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
c95de7451b35950f21196b610dab702730221a98Alexis Tsogias * SUCH DAMAGE.
c95de7451b35950f21196b610dab702730221a98Alexis Tsogias * ====================================================================
c95de7451b35950f21196b610dab702730221a98Alexis Tsogias * This software consists of voluntary contributions made by many
c95de7451b35950f21196b610dab702730221a98Alexis Tsogias * individuals on behalf of the Apache Software Foundation. For more
c95de7451b35950f21196b610dab702730221a98Alexis Tsogias * information on the Apache Software Foundation, please see
c95de7451b35950f21196b610dab702730221a98Alexis Tsogias * Portions of this software are based upon public domain software
c95de7451b35950f21196b610dab702730221a98Alexis Tsogias * originally written at the National Center for Supercomputing Applications,
c95de7451b35950f21196b610dab702730221a98Alexis Tsogias * University of Illinois, Urbana-Champaign.
c95de7451b35950f21196b610dab702730221a98Alexis Tsogias * http_request.c: functions to get and process requests
658187feb755694eb5ff29561bda7109c22c743cAlexis Tsogias * Rob McCool 3/21/93
658187feb755694eb5ff29561bda7109c22c743cAlexis Tsogias * Thoroughly revamped by rst for Apache. NB this file reads
658187feb755694eb5ff29561bda7109c22c743cAlexis Tsogias * best from the bottom up.
658187feb755694eb5ff29561bda7109c22c743cAlexis TsogiasAP_IMPLEMENT_HOOK_RUN_FIRST(int,translate_name,
658187feb755694eb5ff29561bda7109c22c743cAlexis TsogiasAP_IMPLEMENT_HOOK_RUN_FIRST(int,check_user_id,
658187feb755694eb5ff29561bda7109c22c743cAlexis TsogiasAP_IMPLEMENT_HOOK_VOID(insert_filter, (request_rec *r), (r))
658187feb755694eb5ff29561bda7109c22c743cAlexis TsogiasAP_IMPLEMENT_HOOK_RUN_ALL(int,create_request,(request_rec *r),(r),OK,DECLINED)
658187feb755694eb5ff29561bda7109c22c743cAlexis Tsogias/*****************************************************************
c95de7451b35950f21196b610dab702730221a98Alexis Tsogias * Getting and checking directory configuration. Also checks the
c95de7451b35950f21196b610dab702730221a98Alexis Tsogias * FollowSymlinks and FollowSymOwner stuff, since this is really the
c95de7451b35950f21196b610dab702730221a98Alexis Tsogias * only place that can happen (barring a new mid_dir_walk callout).
c95de7451b35950f21196b610dab702730221a98Alexis Tsogias * We can't do it as an access_checker module function which gets
c95de7451b35950f21196b610dab702730221a98Alexis Tsogias * called with the final per_dir_config, since we could have a directory
c95de7451b35950f21196b610dab702730221a98Alexis Tsogias * with FollowSymLinks disabled, which contains a symlink to another
c95de7451b35950f21196b610dab702730221a98Alexis Tsogias * with a .htaccess file which turns FollowSymLinks back on --- and
c95de7451b35950f21196b610dab702730221a98Alexis Tsogias * access in such a case must be denied. So, whatever it is that
c95de7451b35950f21196b610dab702730221a98Alexis Tsogias * checks FollowSymLinks needs to know the state of the options as
c95de7451b35950f21196b610dab702730221a98Alexis Tsogias * they change, all the way down.
c95de7451b35950f21196b610dab702730221a98Alexis Tsogias * We don't want people able to serve up pipes, or unix sockets, or other
c95de7451b35950f21196b610dab702730221a98Alexis Tsogias * scary things. Note that symlink tests are performed later.
658187feb755694eb5ff29561bda7109c22c743cAlexis Tsogias if (r->finfo.filetype == 0 /* doesn't exist */
658187feb755694eb5ff29561bda7109c22c743cAlexis Tsogias ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
658187feb755694eb5ff29561bda7109c22c743cAlexis Tsogias "object is not a file, directory or symlink: %s",
658187feb755694eb5ff29561bda7109c22c743cAlexis Tsogiasstatic int check_symlinks(char *d, int opts, apr_pool_t *p)
658187feb755694eb5ff29561bda7109c22c743cAlexis Tsogias /* OS/2 doesn't have symlinks */
658187feb755694eb5ff29561bda7109c22c743cAlexis Tsogias * Strip trailing '/', if any, off what we're checking; trailing slashes
658187feb755694eb5ff29561bda7109c22c743cAlexis Tsogias * make some systems follow symlinks to directories even in lstat().
658187feb755694eb5ff29561bda7109c22c743cAlexis Tsogias * After we've done the lstat, put it back. Also, don't bother checking
658187feb755694eb5ff29561bda7109c22c743cAlexis Tsogias * '/' at all...
658187feb755694eb5ff29561bda7109c22c743cAlexis Tsogias * Note that we don't have to worry about multiple slashes here because of
658187feb755694eb5ff29561bda7109c22c743cAlexis Tsogias * no2slash() below...
658187feb755694eb5ff29561bda7109c22c743cAlexis Tsogias res = apr_lstat(&lfi, d, APR_FINFO_TYPE | APR_FINFO_OWNER, p);
658187feb755694eb5ff29561bda7109c22c743cAlexis Tsogias * Note that we don't reject accesses to nonexistent files (multiviews or
658187feb755694eb5ff29561bda7109c22c743cAlexis Tsogias * the like may cons up a way to run the transaction anyway)...
658187feb755694eb5ff29561bda7109c22c743cAlexis Tsogias if ((res != APR_SUCCESS && res != APR_INCOMPLETE)
658187feb755694eb5ff29561bda7109c22c743cAlexis Tsogias /* OK, it's a symlink. May still be OK with OPT_SYM_OWNER */
658187feb755694eb5ff29561bda7109c22c743cAlexis Tsogias /* OPT_SYM_OWNER only works if we can get the owner from the file */
658187feb755694eb5ff29561bda7109c22c743cAlexis Tsogias if (apr_stat(&fi, d, APR_FINFO_OWNER, p) != APR_SUCCESS)
658187feb755694eb5ff29561bda7109c22c743cAlexis Tsogias /* TODO: replace with an apr_compare_users() fn */
658187feb755694eb5ff29561bda7109c22c743cAlexis Tsogias return (fi.user == lfi.user) ? OK : HTTP_FORBIDDEN;
658187feb755694eb5ff29561bda7109c22c743cAlexis Tsogias/* Dealing with the file system to get PATH_INFO
658187feb755694eb5ff29561bda7109c22c743cAlexis Tsogias#if defined(HAVE_DRIVE_LETTERS) || defined(HAVE_UNC_PATHS)
658187feb755694eb5ff29561bda7109c22c743cAlexis Tsogias /* assume path_info already set */
658187feb755694eb5ff29561bda7109c22c743cAlexis Tsogias /* If the directory is x:\, then we don't want to strip
658187feb755694eb5ff29561bda7109c22c743cAlexis Tsogias * the trailing slash since x: is not a valid directory.
658187feb755694eb5ff29561bda7109c22c743cAlexis Tsogias if (strlen(path) == 3 && path[1] == ':' && path[2] == '/')
#ifdef HAVE_UNC_PATHS
int iCount=0;
p = path;
iCount++;
bStripSlash = 0;
if (bStripSlash)
return OK;
--cp;
return HTTP_FORBIDDEN;
return OK;
&core_module);
char *test_filename;
char *test_dirname;
int res;
unsigned i, num_dirs;
int j, test_filename_len;
return OK;
const char *entry_dir;
for (j = 0; j < num_sec; ++j) {
if (entry_core->r) {
if (this_conf)
return OK;
return res;
return res;
--num_dirs;
++num_dirs;
#if defined(HAVE_UNC_PATHS)
#if defined(NETWARE)
for (; i <= num_dirs; ++i) {
int overrides_here;
&core_module);
if (i >= iStart)
return res;
* from access.conf.
for (; j < num_sec; ++j) {
char *entry_dir;
if (entry_core->r
if (this_conf) {
&core_module);
if (i >= iStart)
if (overrides_here) {
if (res)
return res;
if (htaccess_conf) {
* There's two types of IS_SPECIAL sections (see http_core.c), and we've
for (; j < num_sec; ++j) {
if (entry_core->r) {
* S_ISDIR test. But if you accessed /symlink/index.html, for example,
return res;
&core_module);
char *test_location;
char *entry_url;
if (!num_url) {
return OK;
/* Location and LocationMatch differ on their behaviour w.r.t. multiple
for (j = 0; j < num_url; ++j) {
if (entry_core->r) {
if (this_conf)
return OK;
&core_module);
char *test_file;
++test_file;
if (num_files) {
char *entry_file;
for (j = 0; j < num_files; ++j) {
if (entry_core->r) {
if (this_conf)
return OK;
return rr;
if (next_filter) {
if (APR_BUCKET_IS_EOS(e)) {
if (!reqs_arr)
const char *new_file,
const request_rec *r,
int res;
char *udir;
if (res) {
return rnew;
return rnew;
if (res) {
return rnew;
return rnew;
const request_rec *r,
const request_rec *r,
int res;
char *fdir;
char *udir;
return rnew;
if (!res) {
return rnew;
return rnew;
return rnew;
const request_rec *r,
int res;
char *fdir;
return rnew;
if (!res) {
return rnew;
return rnew;
return rnew;
if (!res) {
if (res
return rnew;
int retval;
return retval;