mod_cgi.c revision f902601ea431a9b56106e0f5f641dd5fd7efbc30
76318284fc970b30e9dc4c079960807345331dadLennart Poettering/* Copyright 1999-2004 The Apache Software Foundation
76318284fc970b30e9dc4c079960807345331dadLennart Poettering * Licensed under the Apache License, Version 2.0 (the "License");
76318284fc970b30e9dc4c079960807345331dadLennart Poettering * you may not use this file except in compliance with the License.
76318284fc970b30e9dc4c079960807345331dadLennart Poettering * You may obtain a copy of the License at
76318284fc970b30e9dc4c079960807345331dadLennart Poettering * http://www.apache.org/licenses/LICENSE-2.0
5430f7f2bc7330f3088b894166bf3524a067e3d8Lennart Poettering * Unless required by applicable law or agreed to in writing, software
5430f7f2bc7330f3088b894166bf3524a067e3d8Lennart Poettering * distributed under the License is distributed on an "AS IS" BASIS,
76318284fc970b30e9dc4c079960807345331dadLennart Poettering * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
76318284fc970b30e9dc4c079960807345331dadLennart Poettering * See the License for the specific language governing permissions and
76318284fc970b30e9dc4c079960807345331dadLennart Poettering * limitations under the License.
76318284fc970b30e9dc4c079960807345331dadLennart Poettering * http_script: keeps all script-related ramblings together.
76318284fc970b30e9dc4c079960807345331dadLennart Poettering * Compliant to CGI/1.1 spec
76318284fc970b30e9dc4c079960807345331dadLennart Poettering * Adapted by rst from original NCSA code by Rob McCool
76318284fc970b30e9dc4c079960807345331dadLennart Poettering * Apache adds some new env vars; REDIRECT_URL and REDIRECT_QUERY_STRING for
76318284fc970b30e9dc4c079960807345331dadLennart Poettering * custom error responses, and DOCUMENT_ROOT because we found it useful.
76318284fc970b30e9dc4c079960807345331dadLennart Poettering * It also adds SERVER_ADMIN - useful for scripts to know who to mail when
ecca17f6eec83b58f39ff5dc7894044c524ddf41Kay Sievers * they fail.
ecca17f6eec83b58f39ff5dc7894044c524ddf41Kay Sievers#include "apr_thread_proc.h" /* for RLIMIT stuff */
2cc8d9731aff3e401bc6a5a243f20fec123d48e6Zbigniew Jędrzejewski-Szmekmodule AP_MODULE_DECLARE_DATA cgi_module;
2cc8d9731aff3e401bc6a5a243f20fec123d48e6Zbigniew Jędrzejewski-Szmekstatic APR_OPTIONAL_FN_TYPE(ap_register_include_handler) *cgi_pfn_reg_with_ssi;
2cc8d9731aff3e401bc6a5a243f20fec123d48e6Zbigniew Jędrzejewski-Szmekstatic APR_OPTIONAL_FN_TYPE(ap_ssi_get_tag_and_value) *cgi_pfn_gtv;
2cc8d9731aff3e401bc6a5a243f20fec123d48e6Zbigniew Jędrzejewski-Szmekstatic APR_OPTIONAL_FN_TYPE(ap_ssi_parse_string) *cgi_pfn_ps;
2cc8d9731aff3e401bc6a5a243f20fec123d48e6Zbigniew Jędrzejewski-Szmekstatic APR_OPTIONAL_FN_TYPE(ap_cgi_build_command) *cgi_build_command;
2cc8d9731aff3e401bc6a5a243f20fec123d48e6Zbigniew Jędrzejewski-Szmek/* Read and discard the data in the brigade produced by a CGI script */
2cc8d9731aff3e401bc6a5a243f20fec123d48e6Zbigniew Jędrzejewski-Szmekstatic void discard_script_output(apr_bucket_brigade *bb);
ecca17f6eec83b58f39ff5dc7894044c524ddf41Kay Sievers/* KLUDGE --- for back-combatibility, we don't have to check ExecCGI
702f64b93cb215d43f673dd4b2f3646b879c566eZbigniew Jędrzejewski-Szmek * in ScriptAliased directories, which means we need to know if this
702f64b93cb215d43f673dd4b2f3646b879c566eZbigniew Jędrzejewski-Szmek * request came through ScriptAlias or not... so the Alias module
702f64b93cb215d43f673dd4b2f3646b879c566eZbigniew Jędrzejewski-Szmek * leaves a note for us.
ecca17f6eec83b58f39ff5dc7894044c524ddf41Kay Sievers const char *t = apr_table_get(r->notes, "alias-forced-type");
76318284fc970b30e9dc4c079960807345331dadLennart Poettering return t && (!strcasecmp(t, "cgi-script"));
76318284fc970b30e9dc4c079960807345331dadLennart Poettering/* Configuration stuff */
const char *logname;
long logbytes;
cgi_server_conf *c =
&cgi_module);
return NULL;
const char *arg)
&cgi_module);
return NULL;
const char *arg)
&cgi_module);
return NULL;
{NULL}
return ret;
apr_file_close(f);
return ret;
char *newline;
if (newline) {
return rv;
apr_bucket *e;
const char *buf;
int first;
return ret;
*dbuf) {
e = APR_BUCKET_NEXT(e))
if (APR_BUCKET_IS_EOS(e)) {
if (first) {
first = 0;
apr_file_close(f);
return ret;
r->path_info));
r, NULL);
if (r->args) {
const char *description)
err,
#ifndef AP_UNSAFE_ERROR_LOG_UNESCAPED
#ifndef AP_UNSAFE_ERROR_LOG_UNESCAPED
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
#ifdef DEBUG_CGI
for (i = 0; env[i]; ++i)
#ifdef RLIMIT_CPU
#ifdef RLIMIT_NPROC
procattr, p);
if (!*script_in)
return APR_EBADF;
if (!*script_out)
return APR_EBADF;
if (!*script_err)
return APR_EBADF;
#ifdef DEBUG_CGI
return (rc);
if (!args) {
++numwords;
ap_unescape_url(w);
return APR_SUCCESS;
apr_bucket *e;
const char *buf;
e = APR_BUCKET_NEXT(e))
if (APR_BUCKET_IS_EOS(e)) {
struct cgi_bucket_data {
request_rec *r;
APR_BUCKET_INIT(b);
data->r = r;
APR_BUCKET_INIT(b);
char *buf;
return rv;
if (*len > 0) {
apr_bucket_heap *h;
h = a->data;
return rv;
int gotdata = 0;
return rv;
} while (!gotdata);
return rv;
int nph;
const char *argv0;
const char *command;
const char **argv;
apr_bucket *b;
int is_included;
apr_pool_t *p;
return DECLINED;
return DECLINED;
ap_add_cgi_vars(r);
r->filename);
return HTTP_INTERNAL_SERVER_ERROR;
return HTTP_INTERNAL_SERVER_ERROR;
seen_eos = 0;
dbpos = 0;
return rv;
const char *data;
if (child_stopped_reading) {
int cursize;
while (!seen_eos);
if (!nph) {
const char *location;
int ret;
return OK;
return HTTP_MOVED_TEMPORARILY;
request_rec *r = f->r;
int rr_status;
return APR_EGENERAL;
return APR_EGENERAL;
return APR_EGENERAL;
if (location) {
char *buffer;
f->c->bucket_alloc));
return APR_SUCCESS;
const char **argv;
request_rec *r = f->r;
add_ssi_vars(r);
r->filename);
return rv;
return rv;
f->c->bucket_alloc));
return APR_SUCCESS;
request_rec *r = f->r;
r->filename);
return APR_SUCCESS;
return APR_SUCCESS;
return APR_SUCCESS;
return APR_SUCCESS;
if (!cgi_build_command) {
return OK;