mod_dir.c revision fd0edaa8e3d4dd67d0604ccef2e96b071db96643
af84459fbf938e508fd10b01cb8d699c79083813takashi/* ====================================================================
af84459fbf938e508fd10b01cb8d699c79083813takashi * Copyright (c) 1995-1999 The Apache Group. All rights reserved.
af84459fbf938e508fd10b01cb8d699c79083813takashi * Redistribution and use in source and binary forms, with or without
af84459fbf938e508fd10b01cb8d699c79083813takashi * modification, are permitted provided that the following conditions
fed47023e9be04c612b5f6d4a5ee2b8e7c587181rbowen * 1. Redistributions of source code must retain the above copyright
af84459fbf938e508fd10b01cb8d699c79083813takashi * notice, this list of conditions and the following disclaimer.
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * 2. Redistributions in binary form must reproduce the above copyright
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * notice, this list of conditions and the following disclaimer in
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * the documentation and/or other materials provided with the
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * distribution.
af84459fbf938e508fd10b01cb8d699c79083813takashi * 3. All advertising materials mentioning features or use of this
d229f940abfb2490dee17979e9a5ff31b7012eb5rbowen * software must display the following acknowledgment:
3f08db06526d6901aa08c110b5bc7dde6bc39905nd * "This product includes software developed by the Apache Group
af84459fbf938e508fd10b01cb8d699c79083813takashi * for use in the Apache HTTP server project (http://www.apache.org/)."
af84459fbf938e508fd10b01cb8d699c79083813takashi * 4. The names "Apache Server" and "Apache Group" must not be used to
3f08db06526d6901aa08c110b5bc7dde6bc39905nd * endorse or promote products derived from this software without
af84459fbf938e508fd10b01cb8d699c79083813takashi * prior written permission. For written permission, please contact
af84459fbf938e508fd10b01cb8d699c79083813takashi * apache@apache.org.
af84459fbf938e508fd10b01cb8d699c79083813takashi * 5. Products derived from this software may not be called "Apache"
af84459fbf938e508fd10b01cb8d699c79083813takashi * nor may "Apache" appear in their names without prior written
af84459fbf938e508fd10b01cb8d699c79083813takashi * permission of the Apache Group.
af84459fbf938e508fd10b01cb8d699c79083813takashi * 6. Redistributions of any form whatsoever must retain the following
3c13a815670b54d1c17bf02954f7d2b066cde95cnd * acknowledgment:
3c13a815670b54d1c17bf02954f7d2b066cde95cnd * "This product includes software developed by the Apache Group
2d39a41e98476f5235b7c37ce745a4aa0904b1cbrbowen * for use in the Apache HTTP server project (http://www.apache.org/)."
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE GROUP OR
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
fed47023e9be04c612b5f6d4a5ee2b8e7c587181rbowen * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
af84459fbf938e508fd10b01cb8d699c79083813takashi * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
af84459fbf938e508fd10b01cb8d699c79083813takashi * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
af84459fbf938e508fd10b01cb8d699c79083813takashi * OF THE POSSIBILITY OF SUCH DAMAGE.
af84459fbf938e508fd10b01cb8d699c79083813takashi * ====================================================================
af84459fbf938e508fd10b01cb8d699c79083813takashi * This software consists of voluntary contributions made by many
af84459fbf938e508fd10b01cb8d699c79083813takashi * individuals on behalf of the Apache Group and was originally based
af84459fbf938e508fd10b01cb8d699c79083813takashi * on public domain software written at the National Center for
fed47023e9be04c612b5f6d4a5ee2b8e7c587181rbowen * Supercomputing Applications, University of Illinois, Urbana-Champaign.
af84459fbf938e508fd10b01cb8d699c79083813takashi * For more information on the Apache Group and the Apache HTTP server
af84459fbf938e508fd10b01cb8d699c79083813takashi * project, please see <http://www.apache.org/>.
af84459fbf938e508fd10b01cb8d699c79083813takashi * mod_dir.c: handle default index files, and trailing-/ redirects
fed47023e9be04c612b5f6d4a5ee2b8e7c587181rbowentypedef struct dir_config_struct {
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowestatic const char *add_index(cmd_parms *cmd, void *dummy, char *arg)
fed47023e9be04c612b5f6d4a5ee2b8e7c587181rbowen d->index_names = ap_make_array(cmd->pool, 2, sizeof(char *));
4bebf996eb7002ebfe897d46a0e0572390604a77nd "a list of file names"},
af84459fbf938e508fd10b01cb8d699c79083813takashi (dir_config_rec *) ap_pcalloc(p, sizeof(dir_config_rec));
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe return (void *) new;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowestatic void *merge_dir_configs(pool *p, void *basev, void *addv)
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe dir_config_rec *new = (dir_config_rec *) ap_pcalloc(p, sizeof(dir_config_rec));
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe new->index_names = add->index_names ? add->index_names : base->index_names;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe (dir_config_rec *) ap_get_module_config(r->per_dir_config,
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe if (r->uri[0] == '\0' || r->uri[strlen(r->uri) - 1] != '/') {
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe ifile = ap_pstrcat(r->pool, ap_escape_uri(r->pool, r->uri),
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe ifile = ap_pstrcat(r->pool, ap_escape_uri(r->pool, r->uri),
888cb40bdeec5abf452bd85d6bf63b26d5913d4chumbedooh /* KLUDGE --- make the sub_req lookups happen in the right directory.
888cb40bdeec5abf452bd85d6bf63b26d5913d4chumbedooh * Fixing this in the sub_req_lookup functions themselves is difficult,
888cb40bdeec5abf452bd85d6bf63b26d5913d4chumbedooh * and would probably break virtual includes...
888cb40bdeec5abf452bd85d6bf63b26d5913d4chumbedooh if (r->filename[strlen(r->filename) - 1] != '/') {
888cb40bdeec5abf452bd85d6bf63b26d5913d4chumbedooh r->filename = ap_pstrcat(r->pool, r->filename, "/", NULL);
888cb40bdeec5abf452bd85d6bf63b26d5913d4chumbedooh if (rr->status == HTTP_OK && S_ISREG(rr->finfo.st_mode)) {
888cb40bdeec5abf452bd85d6bf63b26d5913d4chumbedooh new_uri = ap_pstrcat(r->pool, new_uri, "?", rr->args, NULL);
f039cf01b271a31e317d5b84f24cb135f1c1b6d7nd new_uri = ap_pstrcat(r->pool, new_uri, "?", r->args, NULL);
fed47023e9be04c612b5f6d4a5ee2b8e7c587181rbowen /* If the request returned a redirect, propagate it to the client */
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe (rr->status == HTTP_NOT_ACCEPTABLE && num_names == 1)) {
c8c717fafa0a09ed13469a603a178921b851dd22igalic r->notes = ap_overlay_tables(r->pool, r->notes, rr->notes);
c8c717fafa0a09ed13469a603a178921b851dd22igalic r->headers_out = ap_overlay_tables(r->pool, r->headers_out,
b7f8d802ecaed65eada1fc31472d06d8460d5528igalic r->err_headers_out = ap_overlay_tables(r->pool, r->err_headers_out,
b7f8d802ecaed65eada1fc31472d06d8460d5528igalic /* If the request returned something other than 404 (or 200),
b7f8d802ecaed65eada1fc31472d06d8460d5528igalic * it means the module encountered some sort of problem. To be
b7f8d802ecaed65eada1fc31472d06d8460d5528igalic * secure, we should return the error, rather than create
7c7e501f542451bf7225b23cb299ee4228bfe15dgryzor * along a (possibly unsafe) directory index.
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe * So we store the error, and if none of the listed files
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe * exist, we return the last error response we got, instead
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe * of a directory listing.
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe if (rr->status && rr->status != HTTP_NOT_FOUND && rr->status != HTTP_OK)
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe /* nothing for us to do, pass on through */
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe create_dir_config, /* create per-directory config structure */
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe merge_dir_configs, /* merge per-directory config structures */