mod_asis.c revision 9ede6357edc9aff1fb2f7edebefab473673298aa
842ae4bd224140319ae7feec1872b93dfd491143fielding/* ====================================================================
842ae4bd224140319ae7feec1872b93dfd491143fielding * Copyright (c) 1995-1999 The Apache Group. All rights reserved.
842ae4bd224140319ae7feec1872b93dfd491143fielding *
842ae4bd224140319ae7feec1872b93dfd491143fielding * Redistribution and use in source and binary forms, with or without
842ae4bd224140319ae7feec1872b93dfd491143fielding * modification, are permitted provided that the following conditions
842ae4bd224140319ae7feec1872b93dfd491143fielding * are met:
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes *
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * 1. Redistributions of source code must retain the above copyright
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * notice, this list of conditions and the following disclaimer.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes *
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * 2. Redistributions in binary form must reproduce the above copyright
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * notice, this list of conditions and the following disclaimer in
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * the documentation and/or other materials provided with the
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * distribution.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes *
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * 3. All advertising materials mentioning features or use of this
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * software must display the following acknowledgment:
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * "This product includes software developed by the Apache Group
e8f95a682820a599fe41b22977010636be5c2717jim * for use in the Apache HTTP server project (http://www.apache.org/)."
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes *
e8f95a682820a599fe41b22977010636be5c2717jim * 4. The names "Apache Server" and "Apache Group" must not be used to
1747d30b98aa1bdbc43994c02cd46ab4cb9319e4fielding * endorse or promote products derived from this software without
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * prior written permission. For written permission, please contact
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * apache@apache.org.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes *
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * 5. Products derived from this software may not be called "Apache"
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * nor may "Apache" appear in their names without prior written
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * permission of the Apache Group.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes *
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * 6. Redistributions of any form whatsoever must retain the following
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick * acknowledgment:
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * "This product includes software developed by the Apache Group
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * for use in the Apache HTTP server project (http://www.apache.org/)."
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes *
5c0419d51818eb02045cf923a9fe456127a44c60wrowe * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
5c0419d51818eb02045cf923a9fe456127a44c60wrowe * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE GROUP OR
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
cd3bbd6d2df78d6c75e5d159a81ef8bdd5f70df9trawick * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf * OF THE POSSIBILITY OF SUCH DAMAGE.
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim * ====================================================================
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf *
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf * This software consists of voluntary contributions made by many
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf * individuals on behalf of the Apache Group and was originally based
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf * on public domain software written at the National Center for
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf * Supercomputing Applications, University of Illinois, Urbana-Champaign.
bede2929837dfd23863ad4b39199c63126566d61jorton * For more information on the Apache Group and the Apache HTTP server
0f60998368b493f90120180a93fc2e1e74490872covener * project, please see <http://www.apache.org/>.
0f60998368b493f90120180a93fc2e1e74490872covener *
0f60998368b493f90120180a93fc2e1e74490872covener */
0f60998368b493f90120180a93fc2e1e74490872covener
0f60998368b493f90120180a93fc2e1e74490872covener#include "httpd.h"
0f60998368b493f90120180a93fc2e1e74490872covener#include "http_config.h"
0f60998368b493f90120180a93fc2e1e74490872covener#include "http_protocol.h"
0f60998368b493f90120180a93fc2e1e74490872covener#include "http_log.h"
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim#include "util_script.h"
60284a9f9158baa60cc8ab4a69066404b1dcae7acovener#include "http_main.h"
87587593f1a53030e840acc0dec6cc881022ea40covener#include "http_request.h"
87587593f1a53030e840acc0dec6cc881022ea40covener
87587593f1a53030e840acc0dec6cc881022ea40covenerstatic int asis_handler(request_rec *r)
a81c0c1ae464b2063a21b45f80c9da8d89bb840ecovener{
a81c0c1ae464b2063a21b45f80c9da8d89bb840ecovener ap_file_t *f = NULL;
a81c0c1ae464b2063a21b45f80c9da8d89bb840ecovener ap_status_t status;
97cd2f98ad4abe68aaaba96b5bfc9ebf7109a2c1covener const char *location;
97cd2f98ad4abe68aaaba96b5bfc9ebf7109a2c1covener
97cd2f98ad4abe68aaaba96b5bfc9ebf7109a2c1covener r->allowed |= (1 << M_GET);
97cd2f98ad4abe68aaaba96b5bfc9ebf7109a2c1covener if (r->method_number != M_GET)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return DECLINED;
43997561b2302d13dee973998e77743a3ddd2374trawick if (r->finfo.st_mode == 0) {
fa123db15501821e36e513afa78e839775ad2800covener ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "File does not exist: %s", r->filename);
0568280364eb026393be492ebc732795c4934643jorton return NOT_FOUND;
0568280364eb026393be492ebc732795c4934643jorton }
0568280364eb026393be492ebc732795c4934643jorton
0568280364eb026393be492ebc732795c4934643jorton if ((status = ap_open(&f, r->filename, APR_READ | APR_BUFFERED,
0568280364eb026393be492ebc732795c4934643jorton APR_OS_DEFAULT, r->pool)) != APR_SUCCESS) {
0568280364eb026393be492ebc732795c4934643jorton ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r,
0568280364eb026393be492ebc732795c4934643jorton "file permissions deny server access: %s", r->filename);
0568280364eb026393be492ebc732795c4934643jorton return FORBIDDEN;
0568280364eb026393be492ebc732795c4934643jorton }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_scan_script_header_err(r, f, NULL);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes location = ap_table_get(r->headers_out, "Location");
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (location && location[0] == '/' &&
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ((r->status == HTTP_OK) || ap_is_HTTP_REDIRECT(r->status))) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_close(f);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
796e4a7141265d8ed7036e4628161c6eafb2a789jorton /* Internal redirect -- fake-up a pseudo-request */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes r->status = HTTP_OK;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* This redirect needs to be a GET no matter what the original
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * method was.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes r->method = ap_pstrdup(r->pool, "GET");
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes r->method_number = M_GET;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_internal_redirect_handler(location, r);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return OK;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_send_http_header(r);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (!r->header_only) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_send_fd(f, r);
8113dac419143273351446c3ad653f3fe5ba5cfdwrowe }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
95b6fe1346805e1731e6e97c15d569c73be22cf7minfrin ap_close(f);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return OK;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes}
95b6fe1346805e1731e6e97c15d569c73be22cf7minfrin
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesstatic const handler_rec asis_handlers[] =
95b6fe1346805e1731e6e97c15d569c73be22cf7minfrin{
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes {ASIS_MAGIC_TYPE, asis_handler},
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes {"send-as-is", asis_handler},
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes {NULL}
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes};
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
95b6fe1346805e1731e6e97c15d569c73be22cf7minfrinmodule MODULE_VAR_EXPORT asis_module =
95b6fe1346805e1731e6e97c15d569c73be22cf7minfrin{
95b6fe1346805e1731e6e97c15d569c73be22cf7minfrin STANDARD20_MODULE_STUFF,
a1790fb35c4b352dab721370985c623a9f8f5062rpluem NULL, /* create per-directory config structure */
713a2b68bac4aeb1e9c48785006c0732451039depquerna NULL, /* merge per-directory config structures */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes NULL, /* create per-server config structure */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes NULL, /* merge per-server config structures */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes NULL, /* command ap_table_t */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes asis_handlers, /* handlers */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes NULL /* register hooks */
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe};
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe