mod_cgi.c revision d4fcf63a5d9171d50c0d04e05a35ec6bf1f85100
b24e4bec819b29f1ec8e77083d4e7610c5dd9c77Lukas Slebodnik/* ====================================================================
b24e4bec819b29f1ec8e77083d4e7610c5dd9c77Lukas Slebodnik * The Apache Software License, Version 1.1
b24e4bec819b29f1ec8e77083d4e7610c5dd9c77Lukas Slebodnik * Copyright (c) 2000-2001 The Apache Software Foundation. All rights
b24e4bec819b29f1ec8e77083d4e7610c5dd9c77Lukas Slebodnik * Redistribution and use in source and binary forms, with or without
b24e4bec819b29f1ec8e77083d4e7610c5dd9c77Lukas Slebodnik * modification, are permitted provided that the following conditions
b24e4bec819b29f1ec8e77083d4e7610c5dd9c77Lukas Slebodnik * 1. Redistributions of source code must retain the above copyright
b24e4bec819b29f1ec8e77083d4e7610c5dd9c77Lukas Slebodnik * notice, this list of conditions and the following disclaimer.
b24e4bec819b29f1ec8e77083d4e7610c5dd9c77Lukas Slebodnik * 2. Redistributions in binary form must reproduce the above copyright
b24e4bec819b29f1ec8e77083d4e7610c5dd9c77Lukas Slebodnik * notice, this list of conditions and the following disclaimer in
b24e4bec819b29f1ec8e77083d4e7610c5dd9c77Lukas Slebodnik * the documentation and/or other materials provided with the
b24e4bec819b29f1ec8e77083d4e7610c5dd9c77Lukas Slebodnik * distribution.
b24e4bec819b29f1ec8e77083d4e7610c5dd9c77Lukas Slebodnik * 3. The end-user documentation included with the redistribution,
b24e4bec819b29f1ec8e77083d4e7610c5dd9c77Lukas Slebodnik * if any, must include the following acknowledgment:
b24e4bec819b29f1ec8e77083d4e7610c5dd9c77Lukas Slebodnik * "This product includes software developed by the
b24e4bec819b29f1ec8e77083d4e7610c5dd9c77Lukas Slebodnik * Apache Software Foundation (http://www.apache.org/)."
b24e4bec819b29f1ec8e77083d4e7610c5dd9c77Lukas Slebodnik * Alternately, this acknowledgment may appear in the software itself,
b24e4bec819b29f1ec8e77083d4e7610c5dd9c77Lukas Slebodnik * if and wherever such third-party acknowledgments normally appear.
b24e4bec819b29f1ec8e77083d4e7610c5dd9c77Lukas Slebodnik * 4. The names "Apache" and "Apache Software Foundation" must
b24e4bec819b29f1ec8e77083d4e7610c5dd9c77Lukas Slebodnik * not be used to endorse or promote products derived from this
b24e4bec819b29f1ec8e77083d4e7610c5dd9c77Lukas Slebodnik * software without prior written permission. For written
b24e4bec819b29f1ec8e77083d4e7610c5dd9c77Lukas Slebodnik * permission, please contact apache@apache.org.
b24e4bec819b29f1ec8e77083d4e7610c5dd9c77Lukas Slebodnik * 5. Products derived from this software may not be called "Apache",
b24e4bec819b29f1ec8e77083d4e7610c5dd9c77Lukas Slebodnik * nor may "Apache" appear in their name, without prior written
b24e4bec819b29f1ec8e77083d4e7610c5dd9c77Lukas Slebodnik * permission of the Apache Software Foundation.
b24e4bec819b29f1ec8e77083d4e7610c5dd9c77Lukas Slebodnik * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
b24e4bec819b29f1ec8e77083d4e7610c5dd9c77Lukas Slebodnik * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
b24e4bec819b29f1ec8e77083d4e7610c5dd9c77Lukas Slebodnik * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
b24e4bec819b29f1ec8e77083d4e7610c5dd9c77Lukas Slebodnik * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
b24e4bec819b29f1ec8e77083d4e7610c5dd9c77Lukas Slebodnik * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
b24e4bec819b29f1ec8e77083d4e7610c5dd9c77Lukas Slebodnik * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
b24e4bec819b29f1ec8e77083d4e7610c5dd9c77Lukas Slebodnik * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
b24e4bec819b29f1ec8e77083d4e7610c5dd9c77Lukas Slebodnik * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
b24e4bec819b29f1ec8e77083d4e7610c5dd9c77Lukas Slebodnik * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
b24e4bec819b29f1ec8e77083d4e7610c5dd9c77Lukas Slebodnik * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
b24e4bec819b29f1ec8e77083d4e7610c5dd9c77Lukas Slebodnik * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
b24e4bec819b29f1ec8e77083d4e7610c5dd9c77Lukas Slebodnik * SUCH DAMAGE.
b24e4bec819b29f1ec8e77083d4e7610c5dd9c77Lukas Slebodnik * ====================================================================
b24e4bec819b29f1ec8e77083d4e7610c5dd9c77Lukas Slebodnik * This software consists of voluntary contributions made by many
b24e4bec819b29f1ec8e77083d4e7610c5dd9c77Lukas Slebodnik * individuals on behalf of the Apache Software Foundation. For more
b24e4bec819b29f1ec8e77083d4e7610c5dd9c77Lukas Slebodnik * information on the Apache Software Foundation, please see
b24e4bec819b29f1ec8e77083d4e7610c5dd9c77Lukas Slebodnik * Portions of this software are based upon public domain software
b24e4bec819b29f1ec8e77083d4e7610c5dd9c77Lukas Slebodnik * originally written at the National Center for Supercomputing Applications,
#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) {
return ret;
&& *dbuf) {
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);
int replace_cmd)
const char *argv0;
if (replace_cmd) {
argv0++;
++numwords;
ap_unescape_url(w);
return APR_SUCCESS;
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;
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) {
b = apr_bucket_eos_create();
b = apr_bucket_eos_create();
int rr_status;
const char **argv;
apr_bucket *b;
r->filename);
return HTTP_INTERNAL_SERVER_ERROR;
return HTTP_INTERNAL_SERVER_ERROR;
return retval;
if (!cgi_build_command) {
return OK;