mod_cgi.c revision d41217398f0e1031adbb6f5bd37f45737c805def
b87efd3db0d2dc41615ea28669faf80fc1b48d56Corneliu-Claudiu Prodescu/* ====================================================================
b87efd3db0d2dc41615ea28669faf80fc1b48d56Corneliu-Claudiu Prodescu * The Apache Software License, Version 1.1
b87efd3db0d2dc41615ea28669faf80fc1b48d56Corneliu-Claudiu Prodescu * Copyright (c) 2000 The Apache Software Foundation. All rights
b87efd3db0d2dc41615ea28669faf80fc1b48d56Corneliu-Claudiu Prodescu * Redistribution and use in source and binary forms, with or without
b87efd3db0d2dc41615ea28669faf80fc1b48d56Corneliu-Claudiu Prodescu * modification, are permitted provided that the following conditions
b87efd3db0d2dc41615ea28669faf80fc1b48d56Corneliu-Claudiu Prodescu * 1. Redistributions of source code must retain the above copyright
b87efd3db0d2dc41615ea28669faf80fc1b48d56Corneliu-Claudiu Prodescu * notice, this list of conditions and the following disclaimer.
902bfaac7e88afebb6684fe1f2414ae2efbc7edfChristian Maeder * 2. Redistributions in binary form must reproduce the above copyright
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * notice, this list of conditions and the following disclaimer in
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * the documentation and/or other materials provided with the
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * distribution.
81c09542d31779a407196fbd710aa8e69a815522Georgel Calin * 3. The end-user documentation included with the redistribution,
81c09542d31779a407196fbd710aa8e69a815522Georgel Calin * if any, must include the following acknowledgment:
05d4bb01e11ad19f2efb41a3efec59a7784c9942Christian Maeder * "This product includes software developed by the
05d4bb01e11ad19f2efb41a3efec59a7784c9942Christian Maeder * Apache Software Foundation (http://www.apache.org/)."
81c09542d31779a407196fbd710aa8e69a815522Georgel Calin * Alternately, this acknowledgment may appear in the software itself,
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * if and wherever such third-party acknowledgments normally appear.
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * 4. The names "Apache" and "Apache Software Foundation" must
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * not be used to endorse or promote products derived from this
902bfaac7e88afebb6684fe1f2414ae2efbc7edfChristian Maeder * software without prior written permission. For written
81c09542d31779a407196fbd710aa8e69a815522Georgel Calin * permission, please contact apache@apache.org.
81c09542d31779a407196fbd710aa8e69a815522Georgel Calin * 5. Products derived from this software may not be called "Apache",
81c09542d31779a407196fbd710aa8e69a815522Georgel Calin * nor may "Apache" appear in their name, without prior written
81c09542d31779a407196fbd710aa8e69a815522Georgel Calin * permission of the Apache Software Foundation.
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
902bfaac7e88afebb6684fe1f2414ae2efbc7edfChristian Maeder * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
81c09542d31779a407196fbd710aa8e69a815522Georgel Calin * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
902bfaac7e88afebb6684fe1f2414ae2efbc7edfChristian Maeder * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
81c09542d31779a407196fbd710aa8e69a815522Georgel Calin * SUCH DAMAGE.
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * ====================================================================
902bfaac7e88afebb6684fe1f2414ae2efbc7edfChristian Maeder * This software consists of voluntary contributions made by many
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * individuals on behalf of the Apache Software Foundation. For more
902bfaac7e88afebb6684fe1f2414ae2efbc7edfChristian Maeder * information on the Apache Software Foundation, please see
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * Portions of this software are based upon public domain software
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * originally written at the National Center for Supercomputing Applications,
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * University of Illinois, Urbana-Champaign.
81c09542d31779a407196fbd710aa8e69a815522Georgel Calin * http_script: keeps all script-related ramblings together.
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * Compliant to CGI/1.1 spec
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * Adapted by rst from original NCSA code by Rob McCool
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * Apache adds some new env vars; REDIRECT_URL and REDIRECT_QUERY_STRING for
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * custom error responses, and DOCUMENT_ROOT because we found it useful.
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * It also adds SERVER_ADMIN - useful for scripts to know who to mail when
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin/* KLUDGE --- for back-combatibility, we don't have to check ExecCGI
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * in ScriptAliased directories, which means we need to know if this
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * request came through ScriptAlias or not... so the Alias module
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin * leaves a note for us.
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin const char *t = ap_table_get(r->notes, "alias-forced-type");
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin/* Configuration stuff */
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calintypedef struct {
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calinstatic void *create_cgi_config(ap_pool_t *p, server_rec *s)
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin (cgi_server_conf *) ap_pcalloc(p, sizeof(cgi_server_conf));
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calinstatic void *merge_cgi_config(ap_pool_t *p, void *basev, void *overridesv)
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin cgi_server_conf *base = (cgi_server_conf *) basev, *overrides = (cgi_server_conf *) overridesv;
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calinstatic const char *set_scriptlog(cmd_parms *cmd, void *dummy, const char *arg)
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin (cgi_server_conf *) ap_get_module_config(s->module_config, &cgi_module);
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calinstatic const char *set_scriptlog_length(cmd_parms *cmd, void *dummy,
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin const char *arg)
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin (cgi_server_conf *) ap_get_module_config(s->module_config, &cgi_module);
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calinstatic const char *set_scriptlog_buffer(cmd_parms *cmd, void *dummy,
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin const char *arg)
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin (cgi_server_conf *) ap_get_module_config(s->module_config, &cgi_module);
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel CalinAP_INIT_TAKE1("ScriptLog", set_scriptlog, NULL, RSRC_CONF,
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin "the name of a log for script debugging info"),
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel CalinAP_INIT_TAKE1("ScriptLogLength", set_scriptlog_length, NULL, RSRC_CONF,
05d4bb01e11ad19f2efb41a3efec59a7784c9942Christian Maeder "the maximum length (in bytes) of the script debug log"),
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel CalinAP_INIT_TAKE1("ScriptLogBuffer", set_scriptlog_buffer, NULL, RSRC_CONF,
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calin "the maximum size (in bytes) to record of a POST request"),
3d13c5135e7bab987599acf23afe9c59df49b06fGeorgel Calinstatic int log_scripterror(request_rec *r, cgi_server_conf * conf, int ret,
return ret;
ap_close(f);
return ret;
char *newline;
if (newline) {
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)
#ifdef RLIMIT_CPU
#ifdef RLIMIT_NPROC
if (!iol)
return APR_EBADF;
if (!iol)
return APR_EBADF;
if (!iol)
return APR_EBADF;
return (rc);
++numwords;
ap_unescape_url(w);
return APR_SUCCESS;
#ifdef WIN32
r->filename);
return APR_EBADF;
return APR_SUCCESS;
char *command;
ap_pool_t *p;
return DECLINED;
argv0++;
char *newfile;
return retval;
return HTTP_INTERNAL_SERVER_ERROR;
return HTTP_INTERNAL_SERVER_ERROR;
return HTTP_INTERNAL_SERVER_ERROR;
if (ap_should_client_block(r)) {
dbpos = 0;
while ((len_read =
const char *location;
int ret;
return OK;
return HTTP_MOVED_TEMPORARILY;
if (!r->header_only) {
{NULL}