Apache HTTPD
Classes | Macros | Functions | Variables
mod_cgid.c File Reference
#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 "apr_optional.h"
#include "apr_signal.h"
#include "apr_want.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 "ap_mpm.h"
#include "mpm_common.h"
#include "mod_suexec.h"
#include "../filters/mod_include.h"
#include "mod_core.h"
#include <sys/stat.h>
#include <sys/un.h>
#include "cgi_common.h"

Go to the source code of this file.

Classes

struct  cgid_dirconf
 
struct  cgid_server_conf
 
struct  cgid_req_t
 
struct  cleanup_script_info
 

Macros

#define APR_WANT_STRFUNC
 
#define DAEMON_STARTUP_ERROR   254
 
#define DEFAULT_LOGBYTES   10385760
 
#define DEFAULT_BUFBYTES   1024
 
#define DEFAULT_SOCKET   "cgisock"
 
#define CGI_REQ   1
 
#define SSI_REQ   2
 
#define GETPID_REQ   3 /* get the pid of script created for prior request */
 
#define ERRFN_USERDATA_KEY   "CGIDCHILDERRFN"
 
#define DEFAULT_CGID_LISTENBACKLOG   100
 
#define DEFAULT_CONNECT_ATTEMPTS   15
 
#define DEFAULT_CONNECT_STARTUP_DELAY   60
 
#define cgi_server_conf   cgid_server_conf
 
#define cgi_module   cgid_module
 

Functions

static int cgid_start (apr_pool_t *p, server_rec *main_server, apr_proc_t *procnew)
 
static int cgid_init (apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *main_server)
 
static void discard_script_output (apr_bucket_brigade *bb)
 
static ap_unix_identity_tcgid_suexec_id_doer (const request_rec *r)
 
static int is_scriptaliased (request_rec *r)
 
static char ** create_argv (apr_pool_t *p, char *path, char *user, char *group, char *av0, const char *args)
 
static apr_status_t close_unix_socket (void *thefd)
 
static apr_status_t sock_readhdr (int fd, int *errfd, void *vbuf, size_t buf_size)
 
static apr_status_t sock_read (int fd, void *vbuf, size_t buf_size)
 
static apr_status_t sock_write (int fd, const void *buf, size_t buf_size)
 
static apr_status_t sock_writev (int fd, int auxfd, request_rec *r, int count,...)
 
static apr_status_t get_req (int fd, request_rec *r, char **argv0, char ***env, int *errfd, cgid_req_t *req)
 
static apr_status_t send_req (int fd, apr_file_t *errpipe, request_rec *r, const char *argv0, char **env, int req_type)
 
static void daemon_signal_handler (int sig)
 
static void cgid_child_errfn (apr_pool_t *pool, apr_status_t err, const char *description)
 
static int cgid_server (void *data)
 
static int cgid_pre_config (apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp)
 
static void * create_cgid_config (apr_pool_t *p, server_rec *s)
 
static void * merge_cgid_config (apr_pool_t *p, void *basev, void *overridesv)
 
static void * create_cgid_dirconf (apr_pool_t *p, char *dummy)
 
static const charset_scriptlog (cmd_parms *cmd, void *dummy, const char *arg)
 
static const charset_scriptlog_length (cmd_parms *cmd, void *dummy, const char *arg)
 
static const charset_scriptlog_buffer (cmd_parms *cmd, void *dummy, const char *arg)
 
static const charset_script_socket (cmd_parms *cmd, void *dummy, const char *arg)
 
static const charset_script_timeout (cmd_parms *cmd, void *dummy, const char *arg)
 
static int log_script (request_rec *r, cgid_server_conf *conf, int ret, char *dbuf, const char *sbuf, apr_bucket_brigade *bb, apr_file_t *script_err)
 
static int connect_to_daemon (int *sdptr, request_rec *r, cgid_server_conf *conf)
 
static apr_status_t dead_yet (pid_t pid, apr_interval_time_t max_wait)
 
static apr_status_t cleanup_nonchild_process (request_rec *r, pid_t pid)
 
static apr_status_t get_cgi_pid (request_rec *r, cgid_server_conf *conf, pid_t *pid)
 
static apr_status_t cleanup_script (void *vptr)
 
static int cgid_handler (request_rec *r)
 
static apr_status_t include_cgi (include_ctx_t *ctx, ap_filter_t *f, apr_bucket_brigade *bb, char *s)
 
static void add_ssi_vars (request_rec *r)
 
static int include_cmd (include_ctx_t *ctx, ap_filter_t *f, apr_bucket_brigade *bb, const char *command)
 
static void register_hook (apr_pool_t *p)
 

Variables

static apr_pool_tpcgi = NULL
 
static pid_t daemon_pid
 
static int daemon_should_exit = 0
 
static server_recroot_server = NULL
 
static apr_pool_troot_pool = NULL
 
static const charsockname
 
static struct sockaddr_unserver_addr
 
static apr_socklen_t server_addr_len
 
static pid_t parent_pid
 
static ap_unix_identity_t empty_ugid = { (uid_t)-1, (gid_t)-1, -1 }
 
static const command_rec cgid_cmds []
 
static int *const aplog_module_index = &( cgid_module.module_index)
 

Macro Definition Documentation

◆ APR_WANT_STRFUNC

#define APR_WANT_STRFUNC

Definition at line 39 of file mod_cgid.c.

◆ cgi_module

#define cgi_module   cgid_module

Definition at line 218 of file mod_cgid.c.

◆ CGI_REQ

#define CGI_REQ   1

Definition at line 137 of file mod_cgid.c.

◆ cgi_server_conf

Definition at line 217 of file mod_cgid.c.

◆ DAEMON_STARTUP_ERROR

#define DAEMON_STARTUP_ERROR   254

Definition at line 105 of file mod_cgid.c.

◆ DEFAULT_BUFBYTES

#define DEFAULT_BUFBYTES   1024

Definition at line 134 of file mod_cgid.c.

◆ DEFAULT_CGID_LISTENBACKLOG

#define DEFAULT_CGID_LISTENBACKLOG   100

Definition at line 151 of file mod_cgid.c.

◆ DEFAULT_CONNECT_ATTEMPTS

#define DEFAULT_CONNECT_ATTEMPTS   15

Definition at line 164 of file mod_cgid.c.

◆ DEFAULT_CONNECT_STARTUP_DELAY

#define DEFAULT_CONNECT_STARTUP_DELAY   60

Definition at line 168 of file mod_cgid.c.

◆ DEFAULT_LOGBYTES

#define DEFAULT_LOGBYTES   10385760

Definition at line 133 of file mod_cgid.c.

◆ DEFAULT_SOCKET

#define DEFAULT_SOCKET   "cgisock"

Definition at line 135 of file mod_cgid.c.

◆ ERRFN_USERDATA_KEY

#define ERRFN_USERDATA_KEY   "CGIDCHILDERRFN"

Definition at line 141 of file mod_cgid.c.

◆ GETPID_REQ

#define GETPID_REQ   3 /* get the pid of script created for prior request */

Definition at line 139 of file mod_cgid.c.

◆ SSI_REQ

#define SSI_REQ   2

Definition at line 138 of file mod_cgid.c.

Function Documentation

◆ add_ssi_vars()

static void add_ssi_vars ( request_rec r)
static

Definition at line 1697 of file mod_cgid.c.

◆ cgid_child_errfn()

static void cgid_child_errfn ( apr_pool_t pool,
apr_status_t  err,
const char description 
)
static

Definition at line 692 of file mod_cgid.c.

◆ cgid_handler()

static int cgid_handler ( request_rec r)
static

< Module declines to handle

< Module has handled this stage.

Definition at line 1465 of file mod_cgid.c.

◆ cgid_init()

static int cgid_init ( apr_pool_t p,
apr_pool_t plog,
apr_pool_t ptemp,
server_rec main_server 
)
static

< Module has handled this stage.

< Module has handled this stage.

Definition at line 1032 of file mod_cgid.c.

◆ cgid_pre_config()

static int cgid_pre_config ( apr_pool_t pconf,
apr_pool_t plog,
apr_pool_t ptemp 
)
static

< Module has handled this stage.

Definition at line 1025 of file mod_cgid.c.

◆ cgid_server()

static int cgid_server ( void *  data)
static

< Read by user

< Write by user

< Execute by user

Definition at line 717 of file mod_cgid.c.

◆ cgid_start()

static int cgid_start ( apr_pool_t p,
server_rec main_server,
apr_proc_t procnew 
)
static

< Module declines to handle

< Module has handled this stage.

Definition at line 999 of file mod_cgid.c.

◆ cgid_suexec_id_doer()

static ap_unix_identity_t * cgid_suexec_id_doer ( const request_rec r)
static

Definition at line 113 of file mod_cgid.c.

◆ cleanup_nonchild_process()

static apr_status_t cleanup_nonchild_process ( request_rec r,
pid_t  pid 
)
static

Definition at line 1400 of file mod_cgid.c.

◆ cleanup_script()

static apr_status_t cleanup_script ( void *  vptr)
static

Definition at line 1459 of file mod_cgid.c.

◆ close_unix_socket()

static apr_status_t close_unix_socket ( void *  thefd)
static

Definition at line 341 of file mod_cgid.c.

◆ connect_to_daemon()

static int connect_to_daemon ( int sdptr,
request_rec r,
cgid_server_conf conf 
)
static

< Module has handled this stage.

Definition at line 1293 of file mod_cgid.c.

◆ create_argv()

static char ** create_argv ( apr_pool_t p,
char path,
char user,
char group,
char av0,
const char args 
)
static

Definition at line 234 of file mod_cgid.c.

◆ create_cgid_config()

static void * create_cgid_config ( apr_pool_t p,
server_rec s 
)
static

Definition at line 1082 of file mod_cgid.c.

◆ create_cgid_dirconf()

static void * create_cgid_dirconf ( apr_pool_t p,
char dummy 
)
static

Definition at line 1100 of file mod_cgid.c.

◆ daemon_signal_handler()

static void daemon_signal_handler ( int  sig)
static

Definition at line 680 of file mod_cgid.c.

◆ dead_yet()

static apr_status_t dead_yet ( pid_t  pid,
apr_interval_time_t  max_wait 
)
static

Definition at line 1372 of file mod_cgid.c.

◆ discard_script_output()

static void discard_script_output ( apr_bucket_brigade bb)
static

◆ get_cgi_pid()

static apr_status_t get_cgi_pid ( request_rec r,
cgid_server_conf conf,
pid_t pid 
)
static

< Module has handled this stage.

Definition at line 1421 of file mod_cgid.c.

◆ get_req()

static apr_status_t get_req ( int  fd,
request_rec r,
char **  argv0,
char ***  env,
int errfd,
cgid_req_t req 
)
static

Definition at line 500 of file mod_cgid.c.

◆ include_cgi()

static apr_status_t include_cgi ( include_ctx_t ctx,
ap_filter_t f,
apr_bucket_brigade bb,
char s 
)
static

Definition at line 1640 of file mod_cgid.c.

◆ include_cmd()

static int include_cmd ( include_ctx_t ctx,
ap_filter_t f,
apr_bucket_brigade bb,
const char command 
)
static

< Module has handled this stage.

Definition at line 1723 of file mod_cgid.c.

◆ is_scriptaliased()

static int is_scriptaliased ( request_rec r)
static

Definition at line 125 of file mod_cgid.c.

◆ log_script()

static int log_script ( request_rec r,
cgid_server_conf conf,
int  ret,
char dbuf,
const char sbuf,
apr_bucket_brigade bb,
apr_file_t script_err 
)
static

< Append to the end of the file

<

Deprecated:
See also
APR_FOPEN_APPEND

< Open the file for writing

<

Deprecated:
See also
APR_FOPEN_WRITE

< Create the file if not there

<

Deprecated:
See also
APR_FOPEN_CREATE

< use OS's default permissions

<

Deprecated:
See also
APR_FPROT_OS_DEFAULT

Definition at line 1188 of file mod_cgid.c.

◆ merge_cgid_config()

static void * merge_cgid_config ( apr_pool_t p,
void *  basev,
void *  overridesv 
)
static

Definition at line 1093 of file mod_cgid.c.

◆ register_hook()

static void register_hook ( apr_pool_t p)
static

Definition at line 1790 of file mod_cgid.c.

◆ send_req()

static apr_status_t send_req ( int  fd,
apr_file_t errpipe,
request_rec r,
const char argv0,
char **  env,
int  req_type 
)
static

Definition at line 578 of file mod_cgid.c.

◆ set_script_socket()

static const char * set_script_socket ( cmd_parms cmd,
void *  dummy,
const char arg 
)
static

< Forbidden in <VirtualHost>

< Forbidden in <Limit>

< Forbidden in <Directory>

< Forbidden in <Location>

< Forbidden in <Files> or <If>

< Forbidden in <Proxy>

Definition at line 1142 of file mod_cgid.c.

◆ set_script_timeout()

static const char * set_script_timeout ( cmd_parms cmd,
void *  dummy,
const char arg 
)
static

Definition at line 1160 of file mod_cgid.c.

◆ set_scriptlog()

static const char * set_scriptlog ( cmd_parms cmd,
void *  dummy,
const char arg 
)
static

Definition at line 1106 of file mod_cgid.c.

◆ set_scriptlog_buffer()

static const char * set_scriptlog_buffer ( cmd_parms cmd,
void *  dummy,
const char arg 
)
static

Definition at line 1132 of file mod_cgid.c.

◆ set_scriptlog_length()

static const char * set_scriptlog_length ( cmd_parms cmd,
void *  dummy,
const char arg 
)
static

Definition at line 1122 of file mod_cgid.c.

◆ sock_read()

static apr_status_t sock_read ( int  fd,
void *  vbuf,
size_t  buf_size 
)
static

Definition at line 424 of file mod_cgid.c.

◆ sock_readhdr()

static apr_status_t sock_readhdr ( int  fd,
int errfd,
void *  vbuf,
size_t  buf_size 
)
static

Definition at line 352 of file mod_cgid.c.

◆ sock_write()

static apr_status_t sock_write ( int  fd,
const void *  buf,
size_t  buf_size 
)
static

Definition at line 431 of file mod_cgid.c.

◆ sock_writev()

static apr_status_t sock_writev ( int  fd,
int  auxfd,
request_rec r,
int  count,
  ... 
)
static

Definition at line 445 of file mod_cgid.c.

Variable Documentation

◆ aplog_module_index

int* const aplog_module_index = &( cgid_module.module_index)
static

Definition at line 1800 of file mod_cgid.c.

◆ cgid_cmds

const command_rec cgid_cmds[]
static
Initial value:
=
{
{ "ScriptLog" , set_scriptlog , NULL , 128 , TAKE1, "the name of a log for script debugging info" },
{ "ScriptLogLength" , set_scriptlog_length , NULL , 128 , TAKE1, "the maximum length (in bytes) of the script debug log" },
{ "ScriptLogBuffer" , set_scriptlog_buffer , NULL , 128 , TAKE1, "the maximum size (in bytes) to record of a POST request" },
{ "ScriptSock" , set_script_socket , NULL , 128 , TAKE1, "the name of the socket to use for communication with " "the cgi daemon." },
{ "CGIDScriptTimeout" , set_script_timeout , NULL , 128 | 64 , TAKE1, "The amount of time to wait between successful reads from " "the CGI script, in seconds." },
{NULL}
}
@ TAKE1
Definition http_config.h:51
static const char * set_scriptlog_length(cmd_parms *cmd, void *dummy, const char *arg)
Definition mod_cgid.c:1122
static const char * set_script_timeout(cmd_parms *cmd, void *dummy, const char *arg)
Definition mod_cgid.c:1160
static const char * set_script_socket(cmd_parms *cmd, void *dummy, const char *arg)
Definition mod_cgid.c:1142
static const char * set_scriptlog_buffer(cmd_parms *cmd, void *dummy, const char *arg)
Definition mod_cgid.c:1132
static const char * set_scriptlog(cmd_parms *cmd, void *dummy, const char *arg)
Definition mod_cgid.c:1106
return NULL
Definition mod_so.c:359

Definition at line 1170 of file mod_cgid.c.

◆ daemon_pid

pid_t daemon_pid
static

Definition at line 84 of file mod_cgid.c.

◆ daemon_should_exit

int daemon_should_exit = 0
static

Definition at line 85 of file mod_cgid.c.

◆ empty_ugid

ap_unix_identity_t empty_ugid = { (uid_t)-1, (gid_t)-1, -1 }
static

Definition at line 92 of file mod_cgid.c.

◆ parent_pid

pid_t parent_pid
static

Definition at line 91 of file mod_cgid.c.

◆ pcgi

apr_pool_t* pcgi = NULL
static

Definition at line 83 of file mod_cgid.c.

◆ root_pool

apr_pool_t* root_pool = NULL
static

Definition at line 87 of file mod_cgid.c.

◆ root_server

server_rec* root_server = NULL
static

Definition at line 86 of file mod_cgid.c.

◆ server_addr

struct sockaddr_un* server_addr
static

Definition at line 89 of file mod_cgid.c.

◆ server_addr_len

apr_socklen_t server_addr_len
static

Definition at line 90 of file mod_cgid.c.

◆ sockname

const char* sockname
static

Definition at line 88 of file mod_cgid.c.