mod_cgi.c revision 12901074f5d6b36d08be84d8637b6f2c21e0da26
2e3d069236777cd62f755a02f4a239306b4ad21aLennart Poettering/* ====================================================================
2e3d069236777cd62f755a02f4a239306b4ad21aLennart Poettering * The Apache Software License, Version 1.1
2e3d069236777cd62f755a02f4a239306b4ad21aLennart Poettering * Copyright (c) 2000-2002 The Apache Software Foundation. All rights
2e3d069236777cd62f755a02f4a239306b4ad21aLennart Poettering * Redistribution and use in source and binary forms, with or without
2e3d069236777cd62f755a02f4a239306b4ad21aLennart Poettering * modification, are permitted provided that the following conditions
2e3d069236777cd62f755a02f4a239306b4ad21aLennart Poettering * 1. Redistributions of source code must retain the above copyright
2e3d069236777cd62f755a02f4a239306b4ad21aLennart Poettering * notice, this list of conditions and the following disclaimer.
2e3d069236777cd62f755a02f4a239306b4ad21aLennart Poettering * 2. Redistributions in binary form must reproduce the above copyright
2e3d069236777cd62f755a02f4a239306b4ad21aLennart Poettering * notice, this list of conditions and the following disclaimer in
2e3d069236777cd62f755a02f4a239306b4ad21aLennart Poettering * the documentation and/or other materials provided with the
2e3d069236777cd62f755a02f4a239306b4ad21aLennart Poettering * distribution.
2e3d069236777cd62f755a02f4a239306b4ad21aLennart Poettering * 3. The end-user documentation included with the redistribution,
2e3d069236777cd62f755a02f4a239306b4ad21aLennart Poettering * if any, must include the following acknowledgment:
2e3d069236777cd62f755a02f4a239306b4ad21aLennart Poettering * "This product includes software developed by the
2e3d069236777cd62f755a02f4a239306b4ad21aLennart Poettering * Apache Software Foundation (http://www.apache.org/)."
2e3d069236777cd62f755a02f4a239306b4ad21aLennart Poettering * Alternately, this acknowledgment may appear in the software itself,
2e3d069236777cd62f755a02f4a239306b4ad21aLennart Poettering * if and wherever such third-party acknowledgments normally appear.
f4ce2b3e5ce93b83f14f8785e205ebb5a9b8c1dfLennart Poettering * 4. The names "Apache" and "Apache Software Foundation" must
2e3d069236777cd62f755a02f4a239306b4ad21aLennart Poettering * not be used to endorse or promote products derived from this
2e3d069236777cd62f755a02f4a239306b4ad21aLennart Poettering * software without prior written permission. For written
f4ce2b3e5ce93b83f14f8785e205ebb5a9b8c1dfLennart Poettering * permission, please contact apache@apache.org.
7b4d7cc08283e5485dcfa49ffdf1915de1d5e81bKay Sievers * 5. Products derived from this software may not be called "Apache",
7b4d7cc08283e5485dcfa49ffdf1915de1d5e81bKay Sievers * nor may "Apache" appear in their name, without prior written
7b4d7cc08283e5485dcfa49ffdf1915de1d5e81bKay Sievers * permission of the Apache Software Foundation.
bc6f2e7c62bcd08177f879423188c54289694619Kay Sievers * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
bc6f2e7c62bcd08177f879423188c54289694619Kay Sievers * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
34e5a31ec5897de8ba1436dad53df99637569d0aLennart Poettering * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
2e3d069236777cd62f755a02f4a239306b4ad21aLennart Poettering * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
9cde64ff264c432fc83be638e57d8fd6392793a6Lennart Poettering * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
7b4d7cc08283e5485dcfa49ffdf1915de1d5e81bKay Sievers * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9cde64ff264c432fc83be638e57d8fd6392793a6Lennart Poettering * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
9cde64ff264c432fc83be638e57d8fd6392793a6Lennart Poettering * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
9cde64ff264c432fc83be638e57d8fd6392793a6Lennart Poettering * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
34e5a31ec5897de8ba1436dad53df99637569d0aLennart Poettering * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
c51d84dc09476d9c06b8aac726220bf3c7d62e8dKay Sievers * SUCH DAMAGE.
#include "apr.h"
#include "apr_strings.h"
#include "apr_optional.h"
#include "apr_buckets.h"
#include "apr_lib.h"
#define APR_WANT_STRFUNC
#include "apr_want.h"
#define CORE_PRIVATE
#include "util_filter.h"
#include "ap_config.h"
#include "httpd.h"
#include "http_config.h"
#include "http_request.h"
#include "http_core.h"
#include "http_protocol.h"
#include "http_main.h"
#include "http_log.h"
#include "util_script.h"
#include "ap_mpm.h"
#include "mod_core.h"
#include "../filters/mod_include.h"
#include "mod_cgi.h"
} exec_info;
const char *logname;
long logbytes;
int bufbytes;
cgi_server_conf *c =
&cgi_module);
return NULL;
const char *arg)
&cgi_module);
return NULL;
const char *arg)
&cgi_module);
return NULL;
{NULL}
!= APR_SUCCESS)) {
return ret;
apr_file_close(f);
return ret;
char *newline;
if (newline) {
apr_bucket *e;
const char *buf;
int first;
return ret;
&& *dbuf) {
if (APR_BUCKET_IS_EOS(e)) {
if (first) {
first = 0;
apr_file_close(f);
return ret;
if (r->args) {
const char *command,
const char * const argv[],
request_rec *r,
apr_pool_t *p,
const char * const *env;
&core_module);
#ifdef DEBUG_CGI
#ifdef OS2
#ifdef DEBUG_CGI
ap_add_cgi_vars(r);
#ifdef DEBUG_CGI
for (i = 0; env[i]; ++i)
#ifdef RLIMIT_CPU
#ifdef RLIMIT_NPROC
return rc;
if (!*script_in)
return APR_EBADF;
if (!*script_out)
return APR_EBADF;
if (!*script_err)
return APR_EBADF;
#ifdef DEBUG_CGI
return (rc);
if (process_cgi) {
argv0++;
if (!args) {
++numwords;
ap_unescape_url(w);
return APR_SUCCESS;
apr_bucket *e;
const char *buf;
if (APR_BUCKET_IS_EOS(e)) {
const char *argv0;
const char *command;
const char **argv;
apr_bucket *b;
int is_included;
apr_pool_t *p;
return DECLINED;
return DECLINED;
return retval;
!= APR_SUCCESS) {
r->filename);
return HTTP_INTERNAL_SERVER_ERROR;
return HTTP_INTERNAL_SERVER_ERROR;
if (ap_should_client_block(r)) {
dbpos = 0;
while ((len_read =
bytes_written = 0;
const char *location;
int ret;
return OK;
return HTTP_MOVED_TEMPORARILY;
if (!r->header_only) {
int rr_status;
c->bucket_alloc);
c->bucket_alloc);
c->bucket_alloc);
c->bucket_alloc);
c->bucket_alloc);
const char **argv;
apr_bucket *b;
!= APR_SUCCESS) {
r->filename);
return HTTP_INTERNAL_SERVER_ERROR;
return HTTP_INTERNAL_SERVER_ERROR;
return retval;
if (!cgi_build_command) {
return OK;