mod_cgi.c revision a3fbce4c162e73ad70f26bfebcbce48f89523b7f
76318284fc970b30e9dc4c079960807345331dadLennart Poettering/* ====================================================================
76318284fc970b30e9dc4c079960807345331dadLennart Poettering * The Apache Software License, Version 1.1
76318284fc970b30e9dc4c079960807345331dadLennart Poettering *
76318284fc970b30e9dc4c079960807345331dadLennart Poettering * Copyright (c) 2000 The Apache Software Foundation. All rights
76318284fc970b30e9dc4c079960807345331dadLennart Poettering * reserved.
76318284fc970b30e9dc4c079960807345331dadLennart Poettering *
76318284fc970b30e9dc4c079960807345331dadLennart Poettering * Redistribution and use in source and binary forms, with or without
76318284fc970b30e9dc4c079960807345331dadLennart Poettering * modification, are permitted provided that the following conditions
5430f7f2bc7330f3088b894166bf3524a067e3d8Lennart Poettering * are met:
5430f7f2bc7330f3088b894166bf3524a067e3d8Lennart Poettering *
76318284fc970b30e9dc4c079960807345331dadLennart Poettering * 1. Redistributions of source code must retain the above copyright
76318284fc970b30e9dc4c079960807345331dadLennart Poettering * notice, this list of conditions and the following disclaimer.
76318284fc970b30e9dc4c079960807345331dadLennart Poettering *
76318284fc970b30e9dc4c079960807345331dadLennart Poettering * 2. Redistributions in binary form must reproduce the above copyright
76318284fc970b30e9dc4c079960807345331dadLennart Poettering * notice, this list of conditions and the following disclaimer in
5430f7f2bc7330f3088b894166bf3524a067e3d8Lennart Poettering * the documentation and/or other materials provided with the
76318284fc970b30e9dc4c079960807345331dadLennart Poettering * distribution.
5430f7f2bc7330f3088b894166bf3524a067e3d8Lennart Poettering *
76318284fc970b30e9dc4c079960807345331dadLennart Poettering * 3. The end-user documentation included with the redistribution,
76318284fc970b30e9dc4c079960807345331dadLennart Poettering * if any, must include the following acknowledgment:
76318284fc970b30e9dc4c079960807345331dadLennart Poettering * "This product includes software developed by the
76318284fc970b30e9dc4c079960807345331dadLennart Poettering * Apache Software Foundation (http://www.apache.org/)."
76318284fc970b30e9dc4c079960807345331dadLennart Poettering * Alternately, this acknowledgment may appear in the software itself,
76318284fc970b30e9dc4c079960807345331dadLennart Poettering * if and wherever such third-party acknowledgments normally appear.
76318284fc970b30e9dc4c079960807345331dadLennart Poettering *
ecca17f6eec83b58f39ff5dc7894044c524ddf41Kay Sievers * 4. The names "Apache" and "Apache Software Foundation" must
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek * not be used to endorse or promote products derived from this
ecca17f6eec83b58f39ff5dc7894044c524ddf41Kay Sievers * software without prior written permission. For written
ecca17f6eec83b58f39ff5dc7894044c524ddf41Kay Sievers * permission, please contact apache@apache.org.
ecca17f6eec83b58f39ff5dc7894044c524ddf41Kay Sievers *
ecca17f6eec83b58f39ff5dc7894044c524ddf41Kay Sievers * 5. Products derived from this software may not be called "Apache",
ecca17f6eec83b58f39ff5dc7894044c524ddf41Kay Sievers * nor may "Apache" appear in their name, without prior written
ecca17f6eec83b58f39ff5dc7894044c524ddf41Kay Sievers * permission of the Apache Software Foundation.
ecca17f6eec83b58f39ff5dc7894044c524ddf41Kay Sievers *
ecca17f6eec83b58f39ff5dc7894044c524ddf41Kay Sievers * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek * SUCH DAMAGE.
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek * ====================================================================
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek *
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek * This software consists of voluntary contributions made by many
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek * individuals on behalf of the Apache Software Foundation. For more
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek * information on the Apache Software Foundation, please see
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek * <http://www.apache.org/>.
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek *
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek * Portions of this software are based upon public domain software
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek * originally written at the National Center for Supercomputing Applications,
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek * University of Illinois, Urbana-Champaign.
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek */
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek/*
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek * http_script: keeps all script-related ramblings together.
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek *
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek * Compliant to CGI/1.1 spec
74a6d87d0cd1f2213869e168b6ca55eded6f4ae8Zbigniew Jędrzejewski-Szmek *
74a6d87d0cd1f2213869e168b6ca55eded6f4ae8Zbigniew Jędrzejewski-Szmek * Adapted by rst from original NCSA code by Rob McCool
74a6d87d0cd1f2213869e168b6ca55eded6f4ae8Zbigniew Jędrzejewski-Szmek *
74a6d87d0cd1f2213869e168b6ca55eded6f4ae8Zbigniew Jędrzejewski-Szmek * Apache adds some new env vars; REDIRECT_URL and REDIRECT_QUERY_STRING for
74a6d87d0cd1f2213869e168b6ca55eded6f4ae8Zbigniew Jędrzejewski-Szmek * custom error responses, and DOCUMENT_ROOT because we found it useful.
74a6d87d0cd1f2213869e168b6ca55eded6f4ae8Zbigniew Jędrzejewski-Szmek * It also adds SERVER_ADMIN - useful for scripts to know who to mail when
74a6d87d0cd1f2213869e168b6ca55eded6f4ae8Zbigniew Jędrzejewski-Szmek * they fail.
74a6d87d0cd1f2213869e168b6ca55eded6f4ae8Zbigniew Jędrzejewski-Szmek */
74a6d87d0cd1f2213869e168b6ca55eded6f4ae8Zbigniew Jędrzejewski-Szmek
74a6d87d0cd1f2213869e168b6ca55eded6f4ae8Zbigniew Jędrzejewski-Szmek#define CORE_PRIVATE
74a6d87d0cd1f2213869e168b6ca55eded6f4ae8Zbigniew Jędrzejewski-Szmek
74a6d87d0cd1f2213869e168b6ca55eded6f4ae8Zbigniew Jędrzejewski-Szmek#include "apr_strings.h"
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek#include "ap_config.h"
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek#include "httpd.h"
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek#include "http_config.h"
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek#include "http_request.h"
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek#include "http_core.h"
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek#include "http_protocol.h"
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek#include "http_main.h"
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek#include "http_log.h"
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek#include "util_script.h"
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek#include "http_conf_globals.h"
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek#ifdef HAVE_STRING_H
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek#include <string.h>
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek#endif
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek#ifdef HAVE_STRINGS_H
5aded369782f28255bc6b494ca905d7acaea7a56Zbigniew Jędrzejewski-Szmek#include <strings.h>
b5c7d097ec7d16facaaeb0da5ba2abb2b1fc230bZbigniew Jędrzejewski-Szmek#endif
b5c7d097ec7d16facaaeb0da5ba2abb2b1fc230bZbigniew Jędrzejewski-Szmek
b5c7d097ec7d16facaaeb0da5ba2abb2b1fc230bZbigniew Jędrzejewski-Szmekmodule MODULE_VAR_EXPORT cgi_module;
b5c7d097ec7d16facaaeb0da5ba2abb2b1fc230bZbigniew Jędrzejewski-Szmek
b5c7d097ec7d16facaaeb0da5ba2abb2b1fc230bZbigniew Jędrzejewski-Szmek/* KLUDGE --- for back-combatibility, we don't have to check ExecCGI
b5c7d097ec7d16facaaeb0da5ba2abb2b1fc230bZbigniew Jędrzejewski-Szmek * in ScriptAliased directories, which means we need to know if this
b5c7d097ec7d16facaaeb0da5ba2abb2b1fc230bZbigniew Jędrzejewski-Szmek * request came through ScriptAlias or not... so the Alias module
b5c7d097ec7d16facaaeb0da5ba2abb2b1fc230bZbigniew Jędrzejewski-Szmek * leaves a note for us.
b5c7d097ec7d16facaaeb0da5ba2abb2b1fc230bZbigniew Jędrzejewski-Szmek */
b5c7d097ec7d16facaaeb0da5ba2abb2b1fc230bZbigniew Jędrzejewski-Szmek
b5c7d097ec7d16facaaeb0da5ba2abb2b1fc230bZbigniew Jędrzejewski-Szmekstatic int is_scriptaliased(request_rec *r)
b5c7d097ec7d16facaaeb0da5ba2abb2b1fc230bZbigniew Jędrzejewski-Szmek{
b5c7d097ec7d16facaaeb0da5ba2abb2b1fc230bZbigniew Jędrzejewski-Szmek const char *t = apr_table_get(r->notes, "alias-forced-type");
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek return t && (!strcasecmp(t, "cgi-script"));
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek}
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek/* Configuration stuff */
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek#define DEFAULT_LOGBYTES 10385760
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek#define DEFAULT_BUFBYTES 1024
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmektypedef struct {
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek const char *logname;
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek long logbytes;
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek int bufbytes;
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek} cgi_server_conf;
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmekstatic void *create_cgi_config(apr_pool_t *p, server_rec *s)
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek{
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek cgi_server_conf *c =
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek (cgi_server_conf *) apr_pcalloc(p, sizeof(cgi_server_conf));
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek c->logname = NULL;
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek c->logbytes = DEFAULT_LOGBYTES;
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek c->bufbytes = DEFAULT_BUFBYTES;
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek
fa13e4a78487971a5093db3fdc61cad224d47c16Zbigniew Jędrzejewski-Szmek return c;
fa13e4a78487971a5093db3fdc61cad224d47c16Zbigniew Jędrzejewski-Szmek}
fa13e4a78487971a5093db3fdc61cad224d47c16Zbigniew Jędrzejewski-Szmek
fa13e4a78487971a5093db3fdc61cad224d47c16Zbigniew Jędrzejewski-Szmekstatic void *merge_cgi_config(apr_pool_t *p, void *basev, void *overridesv)
fa13e4a78487971a5093db3fdc61cad224d47c16Zbigniew Jędrzejewski-Szmek{
fa13e4a78487971a5093db3fdc61cad224d47c16Zbigniew Jędrzejewski-Szmek cgi_server_conf *base = (cgi_server_conf *) basev, *overrides = (cgi_server_conf *) overridesv;
fa13e4a78487971a5093db3fdc61cad224d47c16Zbigniew Jędrzejewski-Szmek
fa13e4a78487971a5093db3fdc61cad224d47c16Zbigniew Jędrzejewski-Szmek return overrides->logname ? overrides : base;
fa13e4a78487971a5093db3fdc61cad224d47c16Zbigniew Jędrzejewski-Szmek}
fa13e4a78487971a5093db3fdc61cad224d47c16Zbigniew Jędrzejewski-Szmek
fa13e4a78487971a5093db3fdc61cad224d47c16Zbigniew Jędrzejewski-Szmekstatic const char *set_scriptlog(cmd_parms *cmd, void *dummy, const char *arg)
fa13e4a78487971a5093db3fdc61cad224d47c16Zbigniew Jędrzejewski-Szmek{
fa13e4a78487971a5093db3fdc61cad224d47c16Zbigniew Jędrzejewski-Szmek server_rec *s = cmd->server;
fa13e4a78487971a5093db3fdc61cad224d47c16Zbigniew Jędrzejewski-Szmek cgi_server_conf *conf =
fa13e4a78487971a5093db3fdc61cad224d47c16Zbigniew Jędrzejewski-Szmek (cgi_server_conf *) ap_get_module_config(s->module_config, &cgi_module);
fa13e4a78487971a5093db3fdc61cad224d47c16Zbigniew Jędrzejewski-Szmek
fa13e4a78487971a5093db3fdc61cad224d47c16Zbigniew Jędrzejewski-Szmek conf->logname = arg;
fa13e4a78487971a5093db3fdc61cad224d47c16Zbigniew Jędrzejewski-Szmek return NULL;
fa13e4a78487971a5093db3fdc61cad224d47c16Zbigniew Jędrzejewski-Szmek}
fa13e4a78487971a5093db3fdc61cad224d47c16Zbigniew Jędrzejewski-Szmek
fa13e4a78487971a5093db3fdc61cad224d47c16Zbigniew Jędrzejewski-Szmekstatic const char *set_scriptlog_length(cmd_parms *cmd, void *dummy,
fa13e4a78487971a5093db3fdc61cad224d47c16Zbigniew Jędrzejewski-Szmek const char *arg)
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek{
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek server_rec *s = cmd->server;
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek cgi_server_conf *conf =
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek (cgi_server_conf *) ap_get_module_config(s->module_config, &cgi_module);
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek conf->logbytes = atol(arg);
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek return NULL;
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek}
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmekstatic const char *set_scriptlog_buffer(cmd_parms *cmd, void *dummy,
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek const char *arg)
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek{
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek server_rec *s = cmd->server;
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek cgi_server_conf *conf =
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek (cgi_server_conf *) ap_get_module_config(s->module_config, &cgi_module);
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek conf->bufbytes = atoi(arg);
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek return NULL;
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek}
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmekstatic const command_rec cgi_cmds[] =
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek{
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-SzmekAP_INIT_TAKE1("ScriptLog", set_scriptlog, NULL, RSRC_CONF,
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek "the name of a log for script debugging info"),
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-SzmekAP_INIT_TAKE1("ScriptLogLength", set_scriptlog_length, NULL, RSRC_CONF,
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek "the maximum length (in bytes) of the script debug log"),
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-SzmekAP_INIT_TAKE1("ScriptLogBuffer", set_scriptlog_buffer, NULL, RSRC_CONF,
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek "the maximum size (in bytes) to record of a POST request"),
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek {NULL}
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek};
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmekstatic int log_scripterror(request_rec *r, cgi_server_conf * conf, int ret,
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek int show_errno, char *error)
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek{
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek apr_file_t *f = NULL;
ecca17f6eec83b58f39ff5dc7894044c524ddf41Kay Sievers apr_finfo_t finfo;
ecca17f6eec83b58f39ff5dc7894044c524ddf41Kay Sievers char time_str[APR_CTIME_LEN];
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek ap_log_rerror(APLOG_MARK, show_errno|APLOG_ERR, errno, r,
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek "%s: %s", error, r->filename);
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek if (!conf->logname ||
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek ((apr_stat(&finfo, ap_server_root_relative(r->pool, conf->logname), r->pool) == APR_SUCCESS)
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek && (finfo.size > conf->logbytes)) ||
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek (apr_open(&f, ap_server_root_relative(r->pool, conf->logname),
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek APR_APPEND|APR_WRITE|APR_CREATE, APR_OS_DEFAULT, r->pool) != APR_SUCCESS)) {
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek return ret;
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek }
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek /* "%% [Wed Jun 19 10:53:21 1996] GET /cgi-bin/printenv HTTP/1.0" */
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek apr_ctime(time_str, apr_now());
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek apr_fprintf(f, "%%%% [%s] %s %s%s%s %s\n", time_str, r->method, r->uri,
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek r->args ? "?" : "", r->args ? r->args : "", r->protocol);
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek /* "%% 500 /usr/local/apache/cgi-bin */
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek apr_fprintf(f, "%%%% %d %s\n", ret, r->filename);
20089f95e83dd6a3e9238b3448ce2e55536184ffZbigniew Jędrzejewski-Szmek
ecca17f6eec83b58f39ff5dc7894044c524ddf41Kay Sievers apr_fprintf(f, "%%error\n%s\n", error);
ecca17f6eec83b58f39ff5dc7894044c524ddf41Kay Sievers
ecca17f6eec83b58f39ff5dc7894044c524ddf41Kay Sievers apr_close(f);
ecca17f6eec83b58f39ff5dc7894044c524ddf41Kay Sievers return ret;
ecca17f6eec83b58f39ff5dc7894044c524ddf41Kay Sievers}
2cc8d9731aff3e401bc6a5a243f20fec123d48e6Zbigniew Jędrzejewski-Szmek
2cc8d9731aff3e401bc6a5a243f20fec123d48e6Zbigniew Jędrzejewski-Szmek/* Soak up stderr from a script and redirect it to the error log.
2cc8d9731aff3e401bc6a5a243f20fec123d48e6Zbigniew Jędrzejewski-Szmek */
2cc8d9731aff3e401bc6a5a243f20fec123d48e6Zbigniew Jędrzejewski-Szmekstatic void log_script_err(request_rec *r, BUFF *script_err)
2cc8d9731aff3e401bc6a5a243f20fec123d48e6Zbigniew Jędrzejewski-Szmek{
2cc8d9731aff3e401bc6a5a243f20fec123d48e6Zbigniew Jędrzejewski-Szmek char argsbuffer[HUGE_STRING_LEN];
2cc8d9731aff3e401bc6a5a243f20fec123d48e6Zbigniew Jędrzejewski-Szmek char *newline;
2cc8d9731aff3e401bc6a5a243f20fec123d48e6Zbigniew Jędrzejewski-Szmek
2cc8d9731aff3e401bc6a5a243f20fec123d48e6Zbigniew Jędrzejewski-Szmek while (ap_bgets(argsbuffer, HUGE_STRING_LEN, script_err) > 0) {
2cc8d9731aff3e401bc6a5a243f20fec123d48e6Zbigniew Jędrzejewski-Szmek newline = strchr(argsbuffer, '\n');
2cc8d9731aff3e401bc6a5a243f20fec123d48e6Zbigniew Jędrzejewski-Szmek if (newline) {
2cc8d9731aff3e401bc6a5a243f20fec123d48e6Zbigniew Jędrzejewski-Szmek *newline = '\0';
2cc8d9731aff3e401bc6a5a243f20fec123d48e6Zbigniew Jędrzejewski-Szmek }
2cc8d9731aff3e401bc6a5a243f20fec123d48e6Zbigniew Jędrzejewski-Szmek ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, r,
2cc8d9731aff3e401bc6a5a243f20fec123d48e6Zbigniew Jędrzejewski-Szmek "%s", argsbuffer);
2cc8d9731aff3e401bc6a5a243f20fec123d48e6Zbigniew Jędrzejewski-Szmek }
2cc8d9731aff3e401bc6a5a243f20fec123d48e6Zbigniew Jędrzejewski-Szmek}
2cc8d9731aff3e401bc6a5a243f20fec123d48e6Zbigniew Jędrzejewski-Szmek
2cc8d9731aff3e401bc6a5a243f20fec123d48e6Zbigniew Jędrzejewski-Szmekstatic int log_script(request_rec *r, cgi_server_conf * conf, int ret,
2cc8d9731aff3e401bc6a5a243f20fec123d48e6Zbigniew Jędrzejewski-Szmek char *dbuf, const char *sbuf, BUFF *script_in, BUFF *script_err)
2cc8d9731aff3e401bc6a5a243f20fec123d48e6Zbigniew Jędrzejewski-Szmek{
2cc8d9731aff3e401bc6a5a243f20fec123d48e6Zbigniew Jędrzejewski-Szmek apr_array_header_t *hdrs_arr = apr_table_elts(r->headers_in);
2cc8d9731aff3e401bc6a5a243f20fec123d48e6Zbigniew Jędrzejewski-Szmek apr_table_entry_t *hdrs = (apr_table_entry_t *) hdrs_arr->elts;
2cc8d9731aff3e401bc6a5a243f20fec123d48e6Zbigniew Jędrzejewski-Szmek char argsbuffer[HUGE_STRING_LEN];
ecca17f6eec83b58f39ff5dc7894044c524ddf41Kay Sievers apr_file_t *f = NULL;
702f64b93cb215d43f673dd4b2f3646b879c566eZbigniew Jędrzejewski-Szmek int i;
702f64b93cb215d43f673dd4b2f3646b879c566eZbigniew Jędrzejewski-Szmek apr_finfo_t finfo;
702f64b93cb215d43f673dd4b2f3646b879c566eZbigniew Jędrzejewski-Szmek char time_str[APR_CTIME_LEN];
702f64b93cb215d43f673dd4b2f3646b879c566eZbigniew Jędrzejewski-Szmek
702f64b93cb215d43f673dd4b2f3646b879c566eZbigniew Jędrzejewski-Szmek if (!conf->logname ||
ecca17f6eec83b58f39ff5dc7894044c524ddf41Kay Sievers ((apr_stat(&finfo, ap_server_root_relative(r->pool, conf->logname), r->pool) == APR_SUCCESS)
ecca17f6eec83b58f39ff5dc7894044c524ddf41Kay Sievers && (finfo.size > conf->logbytes)) ||
ecca17f6eec83b58f39ff5dc7894044c524ddf41Kay Sievers (apr_open(&f, ap_server_root_relative(r->pool, conf->logname),
909f413d3c572baadf9b13e36e1e90beba42af86Zbigniew Jędrzejewski-Szmek APR_APPEND|APR_WRITE|APR_CREATE, APR_OS_DEFAULT, r->pool) != APR_SUCCESS)) {
909f413d3c572baadf9b13e36e1e90beba42af86Zbigniew Jędrzejewski-Szmek /* Soak up script output */
909f413d3c572baadf9b13e36e1e90beba42af86Zbigniew Jędrzejewski-Szmek while (ap_bgets(argsbuffer, HUGE_STRING_LEN, script_in) > 0)
909f413d3c572baadf9b13e36e1e90beba42af86Zbigniew Jędrzejewski-Szmek continue;
909f413d3c572baadf9b13e36e1e90beba42af86Zbigniew Jędrzejewski-Szmek
909f413d3c572baadf9b13e36e1e90beba42af86Zbigniew Jędrzejewski-Szmek log_script_err(r, script_err);
76318284fc970b30e9dc4c079960807345331dadLennart Poettering return ret;
76318284fc970b30e9dc4c079960807345331dadLennart Poettering }
76318284fc970b30e9dc4c079960807345331dadLennart Poettering
76318284fc970b30e9dc4c079960807345331dadLennart Poettering /* "%% [Wed Jun 19 10:53:21 1996] GET /cgi-bin/printenv HTTP/1.0" */
apr_ctime(time_str, apr_now());
apr_fprintf(f, "%%%% [%s] %s %s%s%s %s\n", time_str, r->method, r->uri,
r->args ? "?" : "", r->args ? r->args : "", r->protocol);
/* "%% 500 /usr/local/apache/cgi-bin" */
apr_fprintf(f, "%%%% %d %s\n", ret, r->filename);
apr_puts("%request\n", f);
for (i = 0; i < hdrs_arr->nelts; ++i) {
if (!hdrs[i].key)
continue;
apr_fprintf(f, "%s: %s\n", hdrs[i].key, hdrs[i].val);
}
if ((r->method_number == M_POST || r->method_number == M_PUT)
&& *dbuf) {
apr_fprintf(f, "\n%s\n", dbuf);
}
apr_puts("%response\n", f);
hdrs_arr = apr_table_elts(r->err_headers_out);
hdrs = (apr_table_entry_t *) hdrs_arr->elts;
for (i = 0; i < hdrs_arr->nelts; ++i) {
if (!hdrs[i].key)
continue;
apr_fprintf(f, "%s: %s\n", hdrs[i].key, hdrs[i].val);
}
if (sbuf && *sbuf)
apr_fprintf(f, "%s\n", sbuf);
if (ap_bgets(argsbuffer, HUGE_STRING_LEN, script_in) > 0) {
apr_puts("%stdout\n", f);
apr_puts(argsbuffer, f);
while (ap_bgets(argsbuffer, HUGE_STRING_LEN, script_in) > 0)
apr_puts(argsbuffer, f);
apr_puts("\n", f);
}
if (ap_bgets(argsbuffer, HUGE_STRING_LEN, script_err) > 0) {
apr_puts("%stderr\n", f);
apr_puts(argsbuffer, f);
while (ap_bgets(argsbuffer, HUGE_STRING_LEN, script_err) > 0)
apr_puts(argsbuffer, f);
apr_puts("\n", f);
}
ap_bclose(script_in);
ap_bclose(script_err);
apr_close(f);
return ret;
}
static apr_status_t run_cgi_child(BUFF **script_out, BUFF **script_in, BUFF **script_err,
char *command, char *const argv[], request_rec *r, apr_pool_t *p)
{
char **env;
apr_procattr_t *procattr;
apr_proc_t *procnew = apr_pcalloc(p, sizeof(*procnew));
apr_status_t rc = APR_SUCCESS;
apr_file_t *file = NULL;
apr_socket_t *sock = NULL;
#if defined(RLIMIT_CPU) || defined(RLIMIT_NPROC) || \
defined(RLIMIT_DATA) || defined(RLIMIT_VMEM) || defined (RLIMIT_AS)
core_dir_config *conf;
conf = (core_dir_config *) ap_get_module_config(r->per_dir_config, &core_module);
#endif
#ifdef DEBUG_CGI
#ifdef OS2
/* Under OS/2 need to use device con. */
FILE *dbg = fopen("con", "w");
#else
FILE *dbg = fopen("/dev/tty", "w");
#endif
int i;
#endif
RAISE_SIGSTOP(CGI_CHILD);
#ifdef DEBUG_CGI
fprintf(dbg, "Attempting to exec %s as %sCGI child (argv0 = %s)\n",
r->filename, cld->nph ? "NPH " : "", argv0);
#endif
ap_add_cgi_vars(r);
env = ap_create_environment(p, r->subprocess_env);
#ifdef DEBUG_CGI
fprintf(dbg, "Environment: \n");
for (i = 0; env[i]; ++i)
fprintf(dbg, "'%s'\n", env[i]);
#endif
/* Transmute ourselves into the script.
* NB only ISINDEX scripts get decoded arguments.
*/
if (((rc = apr_createprocattr_init(&procattr, p)) != APR_SUCCESS) ||
((rc = apr_setprocattr_io(procattr,
APR_CHILD_BLOCK,
APR_CHILD_BLOCK,
APR_CHILD_BLOCK)) != APR_SUCCESS) ||
((rc = apr_setprocattr_dir(procattr,
ap_make_dirstr_parent(r->pool, r->filename))) != APR_SUCCESS) ||
#ifdef RLIMIT_CPU
((rc = apr_setprocattr_limit(procattr, APR_LIMIT_CPU, conf->limit_cpu)) != APR_SUCCESS) ||
#endif
#if defined(RLIMIT_DATA) || defined(RLIMIT_VMEM) || defined(RLIMIT_AS)
((rc = apr_setprocattr_limit(procattr, APR_LIMIT_MEM, conf->limit_mem)) != APR_SUCCESS) ||
#endif
#ifdef RLIMIT_NPROC
((rc = apr_setprocattr_limit(procattr, APR_LIMIT_NPROC, conf->limit_nproc)) != APR_SUCCESS) ||
#endif
((rc = apr_setprocattr_cmdtype(procattr, APR_PROGRAM)) != APR_SUCCESS)) {
/* Something bad happened, tell the world. */
ap_log_rerror(APLOG_MARK, APLOG_ERR, rc, r,
"couldn't set child process attributes: %s", r->filename);
}
else {
rc = apr_create_process(procnew, command, argv, env, procattr, p);
if (rc != APR_SUCCESS) {
/* Bad things happened. Everyone should have cleaned up. */
ap_log_rerror(APLOG_MARK, APLOG_ERR, rc, r,
"couldn't create child process: %d: %s", rc, r->filename);
}
else {
apr_note_subprocess(p, procnew, kill_after_timeout);
/* Fill in BUFF structure for parents pipe to child's stdout */
file = procnew->out;
if (!file)
return APR_EBADF;
/* XXX This is a hack. The correct solution is to create a
* pipe bucket, and just pass it down. Since that bucket type
* hasn't been written, we can hack it for the moment.
*/
apr_socket_from_file(&sock, file);
*script_in = ap_bcreate(p, B_RD);
ap_bpush_socket(*script_in, sock);
ap_bsetopt(*script_in, BO_TIMEOUT, &r->server->timeout);
/* Fill in BUFF structure for parents pipe to child's stdin */
file = procnew->in;
if (!file)
return APR_EBADF;
/* XXX This is a hack. The correct solution is to create a
* pipe bucket, and just pass it down. Since that bucket type
* hasn't been written, we can hack it for the moment.
*/
apr_socket_from_file(&sock, file);
*script_out = ap_bcreate(p, B_WR);
ap_bpush_socket(*script_out, sock);
ap_bsetopt(*script_out, BO_TIMEOUT, &r->server->timeout);
/* Fill in BUFF structure for parents pipe to child's stderr */
file = procnew->err;
if (!file)
return APR_EBADF;
/* XXX This is a hack. The correct solution is to create a
* pipe bucket, and just pass it down. Since that bucket type
* hasn't been written, we can hack it for the moment.
*/
apr_socket_from_file(&sock, file);
*script_err = ap_bcreate(p, B_RD);
ap_bpush_socket(*script_err, sock);
ap_bsetopt(*script_err, BO_TIMEOUT, &r->server->timeout);
}
}
return (rc);
}
static apr_status_t build_argv_list(char ***argv, request_rec *r, apr_pool_t *p)
{
int numwords, x, idx;
char *w;
const char *args = r->args;
if (!args || !args[0] || ap_strchr_c(args, '=')) {
numwords = 1;
}
else {
/* count the number of keywords */
for (x = 0, numwords = 2; args[x]; x++) {
if (args[x] == '+') {
++numwords;
}
}
}
/* Everything is - 1 to account for the first parameter which is the
* program name. We didn't used to have to do this, but APR wants it.
*/
if (numwords > APACHE_ARG_MAX - 1) {
numwords = APACHE_ARG_MAX - 1; /* Truncate args to prevent overrun */
}
*argv = (char **) apr_palloc(p, (numwords + 2) * sizeof(char *));
for (x = 1, idx = 1; x < numwords; x++) {
w = ap_getword_nulls(p, &args, '+');
ap_unescape_url(w);
(*argv)[idx++] = ap_escape_shell_cmd(p, w);
}
(*argv)[idx] = NULL;
return APR_SUCCESS;
}
static apr_status_t build_command_line(char **cmd, request_rec *r, apr_pool_t *p)
{
#ifdef WIN32
char *quoted_filename = NULL;
char *interpreter = NULL;
char *arguments = NULL;
file_type_e fileType;
*cmd = NULL;
fileType = ap_get_win32_interpreter(r, &interpreter, &arguments);
if (fileType == eFileTypeUNKNOWN) {
ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, r,
"%s is not executable; ensure interpreted scripts have "
"\"#!\" first line",
r->filename);
return APR_EBADF;
}
/*
* Build the command string to pass to apr_create_process()
*/
quoted_filename = apr_pstrcat(p, "\"", r->filename, "\"", NULL);
if (interpreter && *interpreter) {
if (arguments && *arguments)
*cmd = apr_pstrcat(p, interpreter, " ", quoted_filename, " ",
arguments, NULL);
else
*cmd = apr_pstrcat(p, interpreter, " ", quoted_filename, " ", NULL);
}
else if (arguments && *arguments) {
*cmd = apr_pstrcat(p, quoted_filename, " ", arguments, NULL);
}
else {
*cmd = apr_pstrcat(p, quoted_filename, NULL);
}
#else
*cmd = apr_pstrcat(p, r->filename, NULL);
#endif
return APR_SUCCESS;
}
static int cgi_handler(request_rec *r)
{
int retval, nph, dbpos = 0;
char *argv0, *dbuf = NULL;
char *command;
char **argv = NULL;
BUFF *script_out = NULL, *script_in = NULL, *script_err = NULL;
char argsbuffer[HUGE_STRING_LEN];
int is_included = !strcmp(r->protocol, "INCLUDED");
void *sconf = r->server->module_config;
apr_pool_t *p;
cgi_server_conf *conf =
(cgi_server_conf *) ap_get_module_config(sconf, &cgi_module);
p = r->main ? r->main->pool : r->pool;
if (r->method_number == M_OPTIONS) {
/* 99 out of 100 CGI scripts, this is all they support */
r->allowed |= (1 << M_GET);
r->allowed |= (1 << M_POST);
return DECLINED;
}
if ((argv0 = strrchr(r->filename, '/')) != NULL)
argv0++;
else
argv0 = r->filename;
nph = !(strncmp(argv0, "nph-", 4));
if (!(ap_allow_options(r) & OPT_EXECCGI) && !is_scriptaliased(r))
return log_scripterror(r, conf, HTTP_FORBIDDEN, APLOG_NOERRNO,
"Options ExecCGI is off in this directory");
if (nph && is_included)
return log_scripterror(r, conf, HTTP_FORBIDDEN, APLOG_NOERRNO,
"attempt to include NPH CGI script");
#if defined(OS2) || defined(WIN32)
/* Allow for cgi files without the .EXE extension on them under OS/2 */
if (r->finfo.protection == 0) {
apr_finfo_t finfo;
char *newfile;
newfile = apr_pstrcat(r->pool, r->filename, ".EXE", NULL);
if ((apr_stat(&finfo, newfile, r->pool) != APR_SUCCESS) ||
(finfo.filetype != APR_REG)) {
return log_scripterror(r, conf, HTTP_NOT_FOUND, 0,
"script not found or unable to stat");
} else {
r->filename = newfile;
}
}
#else
if (r->finfo.protection == 0)
return log_scripterror(r, conf, HTTP_NOT_FOUND, APLOG_NOERRNO,
"script not found or unable to stat");
#endif
if (r->finfo.filetype == APR_DIR)
return log_scripterror(r, conf, HTTP_FORBIDDEN, APLOG_NOERRNO,
"attempt to invoke directory as script");
/*
if (!ap_suexec_enabled) {
if (!ap_can_exec(&r->finfo))
return log_scripterror(r, conf, HTTP_FORBIDDEN, APLOG_NOERRNO,
"file permissions deny server execution");
}
*/
if ((retval = ap_setup_client_block(r, REQUEST_CHUNKED_ERROR)))
return retval;
ap_add_common_vars(r);
/* build the command line */
if (build_command_line(&command, r, p) != APR_SUCCESS) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, errno, r,
"couldn't spawn child process: %s", r->filename);
return HTTP_INTERNAL_SERVER_ERROR;
}
/* build the argument list */
else if (build_argv_list(&argv, r, p) != APR_SUCCESS) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, errno, r,
"couldn't spawn child process: %s", r->filename);
return HTTP_INTERNAL_SERVER_ERROR;
}
argv[0] = apr_pstrdup(p, command);
/* run the script in its own process */
if (run_cgi_child(&script_out, &script_in, &script_err, command, argv, r, p) != APR_SUCCESS) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, errno, r,
"couldn't spawn child process: %s", r->filename);
return HTTP_INTERNAL_SERVER_ERROR;
}
/* Transfer any put/post args, CERN style...
* Note that we already ignore SIGPIPE in the core server.
*/
if (ap_should_client_block(r)) {
int dbsize, len_read;
apr_ssize_t bytes_written;
if (conf->logname) {
dbuf = apr_pcalloc(r->pool, conf->bufbytes + 1);
dbpos = 0;
}
while ((len_read =
ap_get_client_block(r, argsbuffer, HUGE_STRING_LEN)) > 0) {
if (conf->logname) {
if ((dbpos + len_read) > conf->bufbytes) {
dbsize = conf->bufbytes - dbpos;
}
else {
dbsize = len_read;
}
memcpy(dbuf + dbpos, argsbuffer, dbsize);
dbpos += dbsize;
}
(void) ap_bwrite(script_out, argsbuffer, len_read, &bytes_written);
if (bytes_written < len_read) {
/* silly script stopped reading, soak up remaining message */
while (ap_get_client_block(r, argsbuffer, HUGE_STRING_LEN) > 0) {
/* dump it */
}
break;
}
}
ap_bflush(script_out);
}
ap_bclose(script_out);
/* Handle script return... */
if (script_in && !nph) {
const char *location;
char sbuf[MAX_STRING_LEN];
int ret;
if ((ret = ap_scan_script_header_err_buff(r, script_in, sbuf))) {
return log_script(r, conf, ret, dbuf, sbuf, script_in, script_err);
}
location = apr_table_get(r->headers_out, "Location");
if (location && location[0] == '/' && r->status == 200) {
/* Soak up all the script output */
while (ap_bgets(argsbuffer, HUGE_STRING_LEN, script_in) > 0) {
continue;
}
log_script_err(r, script_err);
/* This redirect needs to be a GET no matter what the original
* method was.
*/
r->method = apr_pstrdup(r->pool, "GET");
r->method_number = M_GET;
/* We already read the message body (if any), so don't allow
* the redirected request to think it has one. We can ignore
* Transfer-Encoding, since we used REQUEST_CHUNKED_ERROR.
*/
apr_table_unset(r->headers_in, "Content-Length");
ap_internal_redirect_handler(location, r);
return OK;
}
else if (location && r->status == 200) {
/* XX Note that if a script wants to produce its own Redirect
* body, it now has to explicitly *say* "Status: 302"
*/
return HTTP_MOVED_TEMPORARILY;
}
ap_send_http_header(r);
if (!r->header_only) {
ap_send_fb(script_in, r);
}
ap_bclose(script_in);
log_script_err(r, script_err);
ap_bclose(script_err);
}
if (script_in && nph) {
ap_send_fb(script_in, r);
}
return OK; /* NOT r->status, even if it has changed. */
}
static const handler_rec cgi_handlers[] =
{
{CGI_MAGIC_TYPE, cgi_handler},
{"cgi-script", cgi_handler},
{NULL}
};
module MODULE_VAR_EXPORT cgi_module =
{
STANDARD20_MODULE_STUFF,
NULL, /* dir config creater */
NULL, /* dir merger --- default is to override */
create_cgi_config, /* server config */
merge_cgi_config, /* merge server config */
cgi_cmds, /* command apr_table_t */
cgi_handlers, /* handlers */
NULL /* register hooks */
};