mod_cgi.c revision 282830c30ad9e81637c66ea801f7e995d7855fa5
76318284fc970b30e9dc4c079960807345331dadLennart Poettering/* ====================================================================
76318284fc970b30e9dc4c079960807345331dadLennart Poettering * Copyright (c) 1995-1999 The Apache Group. All rights reserved.
76318284fc970b30e9dc4c079960807345331dadLennart Poettering * Redistribution and use in source and binary forms, with or without
76318284fc970b30e9dc4c079960807345331dadLennart Poettering * modification, are permitted provided that the following conditions
76318284fc970b30e9dc4c079960807345331dadLennart Poettering * 1. Redistributions of source code must retain the above copyright
5430f7f2bc7330f3088b894166bf3524a067e3d8Lennart Poettering * notice, this list of conditions and the following disclaimer.
76318284fc970b30e9dc4c079960807345331dadLennart Poettering * 2. Redistributions in binary form must reproduce the above copyright
76318284fc970b30e9dc4c079960807345331dadLennart Poettering * notice, this list of conditions and the following disclaimer in
76318284fc970b30e9dc4c079960807345331dadLennart Poettering * the documentation and/or other materials provided with the
76318284fc970b30e9dc4c079960807345331dadLennart Poettering * distribution.
5430f7f2bc7330f3088b894166bf3524a067e3d8Lennart Poettering * 3. All advertising materials mentioning features or use of this
76318284fc970b30e9dc4c079960807345331dadLennart Poettering * software must display the following acknowledgment:
5430f7f2bc7330f3088b894166bf3524a067e3d8Lennart Poettering * "This product includes software developed by the Apache Group
76318284fc970b30e9dc4c079960807345331dadLennart Poettering * for use in the Apache HTTP server project (http://www.apache.org/)."
76318284fc970b30e9dc4c079960807345331dadLennart Poettering * 4. The names "Apache Server" and "Apache Group" must not be used to
76318284fc970b30e9dc4c079960807345331dadLennart Poettering * endorse or promote products derived from this software without
76318284fc970b30e9dc4c079960807345331dadLennart Poettering * prior written permission. For written permission, please contact
76318284fc970b30e9dc4c079960807345331dadLennart Poettering * apache@apache.org.
ecca17f6eec83b58f39ff5dc7894044c524ddf41Kay Sievers * 5. Products derived from this software may not be called "Apache"
ecca17f6eec83b58f39ff5dc7894044c524ddf41Kay Sievers * nor may "Apache" appear in their names without prior written
ecca17f6eec83b58f39ff5dc7894044c524ddf41Kay Sievers * permission of the Apache Group.
ecca17f6eec83b58f39ff5dc7894044c524ddf41Kay Sievers * 6. Redistributions of any form whatsoever must retain the following
ecca17f6eec83b58f39ff5dc7894044c524ddf41Kay Sievers * acknowledgment:
ecca17f6eec83b58f39ff5dc7894044c524ddf41Kay Sievers * "This product includes software developed by the Apache Group
ecca17f6eec83b58f39ff5dc7894044c524ddf41Kay Sievers * for use in the Apache HTTP server project (http://www.apache.org/)."
ecca17f6eec83b58f39ff5dc7894044c524ddf41Kay Sievers * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
ecca17f6eec83b58f39ff5dc7894044c524ddf41Kay Sievers * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
ecca17f6eec83b58f39ff5dc7894044c524ddf41Kay Sievers * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
ecca17f6eec83b58f39ff5dc7894044c524ddf41Kay Sievers * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE GROUP OR
ecca17f6eec83b58f39ff5dc7894044c524ddf41Kay Sievers * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
ecca17f6eec83b58f39ff5dc7894044c524ddf41Kay Sievers * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
ecca17f6eec83b58f39ff5dc7894044c524ddf41Kay Sievers * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
ecca17f6eec83b58f39ff5dc7894044c524ddf41Kay Sievers * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2cc8d9731aff3e401bc6a5a243f20fec123d48e6Zbigniew Jędrzejewski-Szmek * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
2cc8d9731aff3e401bc6a5a243f20fec123d48e6Zbigniew Jędrzejewski-Szmek * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2cc8d9731aff3e401bc6a5a243f20fec123d48e6Zbigniew Jędrzejewski-Szmek * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
2cc8d9731aff3e401bc6a5a243f20fec123d48e6Zbigniew Jędrzejewski-Szmek * OF THE POSSIBILITY OF SUCH DAMAGE.
2cc8d9731aff3e401bc6a5a243f20fec123d48e6Zbigniew Jędrzejewski-Szmek * ====================================================================
2cc8d9731aff3e401bc6a5a243f20fec123d48e6Zbigniew Jędrzejewski-Szmek * This software consists of voluntary contributions made by many
2cc8d9731aff3e401bc6a5a243f20fec123d48e6Zbigniew Jędrzejewski-Szmek * individuals on behalf of the Apache Group and was originally based
2cc8d9731aff3e401bc6a5a243f20fec123d48e6Zbigniew Jędrzejewski-Szmek * on public domain software written at the National Center for
2cc8d9731aff3e401bc6a5a243f20fec123d48e6Zbigniew Jędrzejewski-Szmek * Supercomputing Applications, University of Illinois, Urbana-Champaign.
2cc8d9731aff3e401bc6a5a243f20fec123d48e6Zbigniew Jędrzejewski-Szmek * For more information on the Apache Group and the Apache HTTP server
2cc8d9731aff3e401bc6a5a243f20fec123d48e6Zbigniew Jędrzejewski-Szmek * project, please see <http://www.apache.org/>.
2cc8d9731aff3e401bc6a5a243f20fec123d48e6Zbigniew Jędrzejewski-Szmek * http_script: keeps all script-related ramblings together.
2cc8d9731aff3e401bc6a5a243f20fec123d48e6Zbigniew Jędrzejewski-Szmek * Compliant to CGI/1.1 spec
2cc8d9731aff3e401bc6a5a243f20fec123d48e6Zbigniew Jędrzejewski-Szmek * Adapted by rst from original NCSA code by Rob McCool
2cc8d9731aff3e401bc6a5a243f20fec123d48e6Zbigniew Jędrzejewski-Szmek * Apache adds some new env vars; REDIRECT_URL and REDIRECT_QUERY_STRING for
2cc8d9731aff3e401bc6a5a243f20fec123d48e6Zbigniew Jędrzejewski-Szmek * custom error responses, and DOCUMENT_ROOT because we found it useful.
ecca17f6eec83b58f39ff5dc7894044c524ddf41Kay Sievers * It also adds SERVER_ADMIN - useful for scripts to know who to mail when
ecca17f6eec83b58f39ff5dc7894044c524ddf41Kay Sievers * they fail.
#include "http_protocol.h"
#include "http_main.h"
#include "http_log.h"
#include "util_script.h"
#include "http_conf_globals.h"
char *logname;
long logbytes;
int bufbytes;
cgi_server_conf *c =
return NULL;
return NULL;
return NULL;
{NULL}
ap_file_t *f;
return ret;
ap_close(f);
return ret;
ap_file_t *f;
#ifdef WIN32
return ret;
&& *dbuf) {
ap_close(f);
return ret;
char **env;
#ifdef DEBUG_CGI
#ifdef OS2
#ifdef DEBUG_CGI
ap_add_cgi_vars(r);
#ifdef DEBUG_CGI
for (i = 0; env[i]; ++i)
#ifndef WIN32
if (script_in) {
if (!iol)
return APR_EBADF;
if (script_out) {
if (!iol)
return APR_EBADF;
if (script_err) {
if (!iol)
return APR_EBADF;
return (rc);
++numwords;
ap_unescape_url(w);
return APR_SUCCESS;
#ifdef WIN32
*c = NULL;
r->filename);
return APR_EBADF;
return APR_SUCCESS;
char *command;
ap_context_t *p;
return DECLINED;
argv0++;
char *newfile;
return retval;
return HTTP_INTERNAL_SERVER_ERROR;
return HTTP_INTERNAL_SERVER_ERROR;
else if (run_cgi_child(&script_out, &script_in, &script_err, command, &argv, r, p) != APR_SUCCESS) {
return HTTP_INTERNAL_SERVER_ERROR;
if (ap_should_client_block(r)) {
dbpos = 0;
while ((len_read =
const char *location;
int ret;
#ifdef CHARSET_EBCDIC
ap_checkconv(r);
return OK;
return REDIRECT;
if (!r->header_only) {
{NULL}