mod_cgid.c revision 5a2dcc476c33985b7681aa72256bcd7266057edd
8ddfe3a457c91c8e7d48134398fb178b091366d7rbb/* Licensed to the Apache Software Foundation (ASF) under one or more
8ddfe3a457c91c8e7d48134398fb178b091366d7rbb * contributor license agreements. See the NOTICE file distributed with
8ddfe3a457c91c8e7d48134398fb178b091366d7rbb * this work for additional information regarding copyright ownership.
8ddfe3a457c91c8e7d48134398fb178b091366d7rbb * The ASF licenses this file to You under the Apache License, Version 2.0
8ddfe3a457c91c8e7d48134398fb178b091366d7rbb * (the "License"); you may not use this file except in compliance with
8ddfe3a457c91c8e7d48134398fb178b091366d7rbb * the License. You may obtain a copy of the License at
8ddfe3a457c91c8e7d48134398fb178b091366d7rbb * Unless required by applicable law or agreed to in writing, software
8ddfe3a457c91c8e7d48134398fb178b091366d7rbb * distributed under the License is distributed on an "AS IS" BASIS,
8ddfe3a457c91c8e7d48134398fb178b091366d7rbb * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
8ddfe3a457c91c8e7d48134398fb178b091366d7rbb * See the License for the specific language governing permissions and
8ddfe3a457c91c8e7d48134398fb178b091366d7rbb * limitations under the License.
8ddfe3a457c91c8e7d48134398fb178b091366d7rbb * http_script: keeps all script-related ramblings together.
8ddfe3a457c91c8e7d48134398fb178b091366d7rbb * Compliant to cgi/1.1 spec
8ddfe3a457c91c8e7d48134398fb178b091366d7rbb * Adapted by rst from original NCSA code by Rob McCool
8ddfe3a457c91c8e7d48134398fb178b091366d7rbb * Apache adds some new env vars; REDIRECT_URL and REDIRECT_QUERY_STRING for
8ddfe3a457c91c8e7d48134398fb178b091366d7rbb * custom error responses, and DOCUMENT_ROOT because we found it useful.
8ddfe3a457c91c8e7d48134398fb178b091366d7rbb * It also adds SERVER_ADMIN - useful for scripts to know who to mail when
8ddfe3a457c91c8e7d48134398fb178b091366d7rbb * they fail.
8ddfe3a457c91c8e7d48134398fb178b091366d7rbb/* ### should be tossed in favor of APR */
static int total_modules = 0;
static int daemon_should_exit = 0;
static const char *sockname;
return (ap_unix_identity_t *)
#ifndef DEFAULT_CGID_LISTENBACKLOG
#ifndef DEFAULT_CONNECT_ATTEMPTS
const char *logname;
long logbytes;
int bufbytes;
int core_module_index;
int env_count;
} cgid_req_t;
int x, numwords;
char **av;
int idx = 0;
numwords = 0;
++numwords;
if (path) {
if (user) {
if (group) {
ap_unescape_url(w);
return av;
int mpm_state;
int stopping;
switch (reason) {
case APR_OC_REASON_DEATH:
stopping = 0;
if (!stopping) {
case APR_OC_REASON_RESTART:
case APR_OC_REASON_LOST:
case APR_OC_REASON_UNREGISTER:
sockname);
int rc;
switch(rc) {
return errno;
return ECONNRESET;
return APR_SUCCESS;
int rc;
if (rc < 0) {
return errno;
return APR_SUCCESS;
int rc;
for (i = 0; i < count; i++) {
if (rc < 0) {
return errno;
return APR_SUCCESS;
char **environ;
void **rconf;
return stat;
return APR_SUCCESS;
return stat;
return stat;
return stat;
return stat;
#ifdef RLIMIT_CPU
#ifdef RLIMIT_NPROC
return APR_SUCCESS;
int req_type)
return stat;
return stat;
#ifdef RLIMIT_CPU
len = 0;
len = 0;
#ifdef RLIMIT_NPROC
len = 0;
return APR_SUCCESS;
const char *description)
request_rec *r;
void *vr;
r = vr;
return errno;
if (rc < 0) {
sockname);
return errno;
sockname);
return rv;
return errno;
if (!geteuid()) {
sockname);
return errno;
return rc;
while (!daemon_should_exit) {
const char * const *argv;
request_rec *r;
void *key;
if (sd2 < 0) {
#if defined(ENETDOWN)
(const char * const *)env,
(const char * const *)env,
return DECLINED;
else if (daemon_pid == 0) {
return OK;
return OK;
int first_time = 0;
module **m;
void *data;
root_pool = p;
if (!data) {
if (!first_time) {
char *tmp_sockname;
total_modules = 0;
return ret;
return ret;
cgid_server_conf *c =
&cgid_module);
return NULL;
&cgid_module);
return NULL;
&cgid_module);
return NULL;
return err;
if (!sockname) {
return NULL;
{NULL}
return ret;
apr_file_close(f);
return ret;
apr_bucket *e;
const char *buf;
int first;
if (script_err) {
return ret;
&& *dbuf) {
e = APR_BUCKET_NEXT(e))
if (APR_BUCKET_IS_EOS(e)) {
if (first) {
first = 0;
if (script_err) {
if (script_err) {
apr_file_close(f);
return ret;
int sd;
int connect_tries;
connect_tries = 0;
return OK;
apr_bucket *e;
const char *buf;
e = APR_BUCKET_NEXT(e))
if (APR_BUCKET_IS_EOS(e)) {
struct cleanup_script_info {
request_rec *r;
unsigned long conn_id;
#ifdef _AIX
return APR_SUCCESS;
return APR_EGENERAL;
return APR_SUCCESS;
pid);
return APR_SUCCESS;
pid);
return APR_EGENERAL;
int sd;
int rc;
return APR_EGENERAL;
return stat;
return stat;
if (pid == 0) {
return APR_EGENERAL;
apr_bucket *b;
int is_included;
int sd;
char **env;
return DECLINED;
argv0++;
ap_add_cgi_vars(r);
return retval;
info->r = r;
argv0++;
seen_eos = 0;
dbpos = 0;
return HTTP_REQUEST_TIME_OUT;
return HTTP_INTERNAL_SERVER_ERROR;
const char *data;
if (child_stopped_reading) {
int cursize;
while (!seen_eos);
if (!nph) {
const char *location;
int ret;
return OK;
return ret;
return OK;
return HTTP_MOVED_TEMPORARILY;
if (nph) {
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;
if (r->args) {
char **env;
int sd;
int retval;
request_rec *r = f->r;
&cgid_module);
add_ssi_vars(r);
return retval;
info->r = r;
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;