mod_cgid.c revision 5c2f87932a2b72c65a02aff9932343275ea9dd5b
f73f2c2fae0ded6c8273c28d025ba8aa8136a0fend/* Copyright 1999-2005 The Apache Software Foundation or its licensors, as
2d0611ffc9f91c5fc2ddccb93f9a3d17791ae650takashi * applicable.
f73f2c2fae0ded6c8273c28d025ba8aa8136a0fend * Licensed under the Apache License, Version 2.0 (the "License");
f73f2c2fae0ded6c8273c28d025ba8aa8136a0fend * you may not use this file except in compliance with the License.
7ec4d5cc4aa574e3191bc5a612e68fd8f25ab7earpluem * You may obtain a copy of the License at
f73f2c2fae0ded6c8273c28d025ba8aa8136a0fend * Unless required by applicable law or agreed to in writing, software
f73f2c2fae0ded6c8273c28d025ba8aa8136a0fend * distributed under the License is distributed on an "AS IS" BASIS,
d9b843d090f14405079b4a61a493316cd3f1e5b9minfrin * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
f73f2c2fae0ded6c8273c28d025ba8aa8136a0fend * See the License for the specific language governing permissions and
367d146f245f3b1c9f77c18e6ec591b52e0b344cbnicholes * limitations under the License.
42af92a661a06b3cebc88d585aad75064a309d51nd * http_script: keeps all script-related ramblings together.
6fe26506780e73be2a412d758af77fafdf03291and * Compliant to cgi/1.1 spec
f73f2c2fae0ded6c8273c28d025ba8aa8136a0fend * Adapted by rst from original NCSA code by Rob McCool
f73f2c2fae0ded6c8273c28d025ba8aa8136a0fend * Apache adds some new env vars; REDIRECT_URL and REDIRECT_QUERY_STRING for
f73f2c2fae0ded6c8273c28d025ba8aa8136a0fend * custom error responses, and DOCUMENT_ROOT because we found it useful.
f73f2c2fae0ded6c8273c28d025ba8aa8136a0fend * It also adds SERVER_ADMIN - useful for scripts to know who to mail when
43f6cc6aa3312619633538b8978619a48c0ce52eminfrin * they fail.
6b0fe1f447ba35827cd5cf1d2a703bd8517f33ffmturk/* ### should be tossed in favor of APR */
5f4e50966b2b9b58436a1651cbe588d1b595657ewrowestatic int cgid_start(apr_pool_t *p, server_rec *main_server, apr_proc_t *procnew);
623eebe956d9c2d6d073ed3eae855b56030b40e9noodlstatic int cgid_init(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *main_server);
f73f2c2fae0ded6c8273c28d025ba8aa8136a0fendstatic int handle_exec(include_ctx_t *ctx, ap_filter_t *f, apr_bucket_brigade *bb);
4277c95b5a9454a5c25f8d8762634fcff37aa840minfrinstatic APR_OPTIONAL_FN_TYPE(ap_register_include_handler) *cgid_pfn_reg_with_ssi;
4277c95b5a9454a5c25f8d8762634fcff37aa840minfrinstatic APR_OPTIONAL_FN_TYPE(ap_ssi_get_tag_and_value) *cgid_pfn_gtv;
4277c95b5a9454a5c25f8d8762634fcff37aa840minfrinstatic APR_OPTIONAL_FN_TYPE(ap_ssi_parse_string) *cgid_pfn_ps;
1de1266f0ea387d6373be8415745dfd2ab876341jimstatic int total_modules = 0;
f73f2c2fae0ded6c8273c28d025ba8aa8136a0fendstatic int daemon_should_exit = 0;
f73f2c2fae0ded6c8273c28d025ba8aa8136a0fendstatic const char *sockname;
f73f2c2fae0ded6c8273c28d025ba8aa8136a0fendstatic ap_unix_identity_t empty_ugid = { (uid_t)-1, (gid_t)-1, -1 };
4db28ee269aa06f7c6232e11cd01f58c3349af23noodl/* Read and discard the data in the brigade produced by a CGI script */
f73f2c2fae0ded6c8273c28d025ba8aa8136a0fendstatic void discard_script_output(apr_bucket_brigade *bb);
03c25fb6f628ac81f2ecb637d1e7502dcee783f3nd/* This doer will only ever be called when we are sure that we have
f73f2c2fae0ded6c8273c28d025ba8aa8136a0fend * a valid ugid.
7fa75a06a4fee19e995c069ee00310455d1452e1pquernastatic ap_unix_identity_t *cgid_suexec_id_doer(const request_rec *r)
#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;
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;
return stat;
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;
return errno;
if (!geteuid()) {
sockname);
return errno;
while (!daemon_should_exit) {
char *argv0;
char **env;
const char * const *argv;
request_rec *r;
if (sd2 < 0) {
#if defined(ENETDOWN)
(const char * const *)env,
(const char * const *)env,
void *key;
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) {
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 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;
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;