mod_cgid.c revision 066877f1a045103acfdd376d48cdd473c33f409b
51846950b4b1f31342008cf17f667859a5f21949Christian Maeder/* ====================================================================
51846950b4b1f31342008cf17f667859a5f21949Christian Maeder * The Apache Software License, Version 1.1
6d81916b9004f8d9b6032113c5987ab07da47015Karl Luc * Copyright (c) 2000 The Apache Software Foundation. All rights
7165a916d2fa1bf87c4741ec63b253413eebbf69Karl Luc * Redistribution and use in source and binary forms, with or without
51846950b4b1f31342008cf17f667859a5f21949Christian Maeder * modification, are permitted provided that the following conditions
7165a916d2fa1bf87c4741ec63b253413eebbf69Karl Luc * 1. Redistributions of source code must retain the above copyright
51846950b4b1f31342008cf17f667859a5f21949Christian Maeder * notice, this list of conditions and the following disclaimer.
51846950b4b1f31342008cf17f667859a5f21949Christian Maeder * 2. Redistributions in binary form must reproduce the above copyright
51846950b4b1f31342008cf17f667859a5f21949Christian Maeder * notice, this list of conditions and the following disclaimer in
7165a916d2fa1bf87c4741ec63b253413eebbf69Karl Luc * the documentation and/or other materials provided with the
51846950b4b1f31342008cf17f667859a5f21949Christian Maeder * distribution.
51846950b4b1f31342008cf17f667859a5f21949Christian Maeder * 3. The end-user documentation included with the redistribution,
7165a916d2fa1bf87c4741ec63b253413eebbf69Karl Luc * if any, must include the following acknowledgment:
7165a916d2fa1bf87c4741ec63b253413eebbf69Karl Luc * "This product includes software developed by the
d6ce032cac688f3698be7133d27f53d3967e6749Christian Maeder * Apache Software Foundation (http://www.apache.org/)."
de03ed90ff6efbbc4751301bcf6b50d9790c1afbKarl Luc * Alternately, this acknowledgment may appear in the software itself,
de03ed90ff6efbbc4751301bcf6b50d9790c1afbKarl Luc * if and wherever such third-party acknowledgments normally appear.
66977d201b3ff7ee9c1f992c0f3f701b69eac2c9Karl Luc * 4. The names "Apache" and "Apache Software Foundation" must
51846950b4b1f31342008cf17f667859a5f21949Christian Maeder * not be used to endorse or promote products derived from this
51846950b4b1f31342008cf17f667859a5f21949Christian Maeder * software without prior written permission. For written
51846950b4b1f31342008cf17f667859a5f21949Christian Maeder * permission, please contact apache@apache.org.
3831cf8a3b0ea144a80d13fe0314cc2752e32107Christian Maeder * 5. Products derived from this software may not be called "Apache",
7165a916d2fa1bf87c4741ec63b253413eebbf69Karl Luc * nor may "Apache" appear in their name, without prior written
51846950b4b1f31342008cf17f667859a5f21949Christian Maeder * permission of the Apache Software Foundation.
7165a916d2fa1bf87c4741ec63b253413eebbf69Karl Luc * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
d6ce032cac688f3698be7133d27f53d3967e6749Christian Maeder * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
7165a916d2fa1bf87c4741ec63b253413eebbf69Karl Luc * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
de03ed90ff6efbbc4751301bcf6b50d9790c1afbKarl Luc * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
7165a916d2fa1bf87c4741ec63b253413eebbf69Karl Luc * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
7165a916d2fa1bf87c4741ec63b253413eebbf69Karl Luc * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
c51d1f5ff88cce030fe543e271ca6b85625b70d8Karl Luc * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
c51d1f5ff88cce030fe543e271ca6b85625b70d8Karl Luc * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
d75d2d11170f1339ebe37d9d9c06aff148637b13Christian Maeder * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
c51d1f5ff88cce030fe543e271ca6b85625b70d8Karl Luc * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
b696e806e85f1c07f2f5ea07f2b5babcd656e0d6Karl Luc * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
c51d1f5ff88cce030fe543e271ca6b85625b70d8Karl Luc * SUCH DAMAGE.
51846950b4b1f31342008cf17f667859a5f21949Christian Maeder * ====================================================================
7165a916d2fa1bf87c4741ec63b253413eebbf69Karl Luc * This software consists of voluntary contributions made by many
c51d1f5ff88cce030fe543e271ca6b85625b70d8Karl Luc * individuals on behalf of the Apache Software Foundation. For more
7165a916d2fa1bf87c4741ec63b253413eebbf69Karl Luc * information on the Apache Software Foundation, please see
7165a916d2fa1bf87c4741ec63b253413eebbf69Karl Luc * Portions of this software are based upon public domain software
d6ce032cac688f3698be7133d27f53d3967e6749Christian Maeder * originally written at the National Center for Supercomputing Applications,
de03ed90ff6efbbc4751301bcf6b50d9790c1afbKarl Luc * University of Illinois, Urbana-Champaign.
3831cf8a3b0ea144a80d13fe0314cc2752e32107Christian Maeder * http_script: keeps all script-related ramblings together.
7165a916d2fa1bf87c4741ec63b253413eebbf69Karl Luc * Compliant to cgi/1.1 spec
3831cf8a3b0ea144a80d13fe0314cc2752e32107Christian Maeder * Adapted by rst from original NCSA code by Rob McCool
7165a916d2fa1bf87c4741ec63b253413eebbf69Karl Luc * Apache adds some new env vars; REDIRECT_URL and REDIRECT_QUERY_STRING for
de03ed90ff6efbbc4751301bcf6b50d9790c1afbKarl Luc * custom error responses, and DOCUMENT_ROOT because we found it useful.
de03ed90ff6efbbc4751301bcf6b50d9790c1afbKarl Luc * It also adds SERVER_ADMIN - useful for scripts to know who to mail when
7165a916d2fa1bf87c4741ec63b253413eebbf69Karl Luc * they fail.
#include "apr_lib.h"
#include "apr_strings.h"
#include "apr_general.h"
#include "apr_file_io.h"
#include "apr_portable.h"
#include "apr_buckets.h"
#include "util_filter.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 "http_conf_globals.h"
#include "ap_mpm.h"
#include "unixd.h"
#include "mod_suexec.h"
#include "apr_optional.h"
#include "../filters/mod_include.h"
#ifdef HAVE_SYS_SOCKET_H
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#ifdef HAVE_STRINGS_H
#include <strings.h>
static int total_modules = 0;
#ifndef DEFAULT_CGID_LISTENBACKLOG
const char *sockname;
const char *logname;
long logbytes;
int bufbytes;
int x, numwords;
char **av;
int idx = 0;
++numwords;
if (path) {
if (user) {
if (group) {
ap_unescape_url(w);
return av;
switch (reason) {
case APR_OC_REASON_DEATH:
case APR_OC_REASON_LOST:
case APR_OC_REASON_RESTART:
case APR_OC_REASON_UNREGISTER:
static void get_req(int fd, request_rec *r, char **filename, char **argv0, char ***env, int *req_type)
int i, len, j;
unsigned char *data;
char **environ;
void **dconf;
if (suexec_mod) {
#ifdef RLIMIT_CPU
#ifdef RLIMIT_NPROC
char *data;
NULL);
for (i =0; env[i]; i++) {
for (i = 0; env[i]; i++) {
if (suexec_mod) {
#ifdef RLIMIT_CPU
len = 0;
len = 0;
#ifdef RLIMIT_NPROC
len = 0;
return errno;
if (rc < 0) {
return errno;
return errno;
if (!geteuid()) {
return errno;
char *argv0;
char *filename;
char **env;
const char * const *argv;
apr_pool_t *p;
request_rec *r;
if (sd2 < 0) {
r->pool = p;
(const char * const *)env,
procattr, p);
void *data;
int first_time = 0;
module **m;
if (!data) {
if (!first_time) {
total_modules = 0;
else if (pid == 0) {
cgid_server_conf *c =
return NULL;
return NULL;
return NULL;
return NULL;
{NULL}
return ret;
apr_file_close(f);
return ret;
if (script_err) {
return ret;
&& *dbuf) {
if (script_err) {
if (script_err) {
apr_file_close(f);
return ret;
apr_bucket *b;
void *sconf;
int is_included;
int sd;
char **env;
return DECLINED;
return DECLINED;
argv0++;
argv0++;
ap_add_cgi_vars(r);
return retval;
argv0++;
if (ap_should_client_block(r)) {
dbpos = 0;
while ((len_read =
if (!nph) {
const char *location;
int ret;
return OK;
return HTTP_MOVED_TEMPORARILY;
if (!r->header_only) {
b = apr_bucket_eos_create();
if (nph) {
b = apr_bucket_eos_create();
int rr_status;
if (r->args) {
char **env;
const char *location;
int sd;
int retval;
apr_bucket *b;
return retval;
return OK;
return HTTP_MOVED_TEMPORARILY;
if (!r->header_only) {