MCPcopy Create free account
hub / github.com/apache/httpd / cgi_handler

Function cgi_handler

modules/generators/mod_cgi.c:509–637  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

507}
508
509static int cgi_handler(request_rec *r)
510{
511 int nph;
512 apr_size_t dbufsize;
513 const char *argv0;
514 const char *command;
515 const char **argv;
516 char *dbuf = NULL;
517 apr_file_t *script_out = NULL, *script_in = NULL, *script_err = NULL;
518 conn_rec *c = r->connection;
519 apr_bucket_brigade *bb = apr_brigade_create(r->pool, c->bucket_alloc);
520 apr_bucket *b;
521 int is_included;
522 apr_pool_t *p;
523 cgi_server_conf *conf;
524 apr_status_t rv;
525 cgi_exec_info_t e_info;
526 cgi_dirconf *dc = ap_get_module_config(r->per_dir_config, &cgi_module);
527 apr_interval_time_t timeout = dc->timeout > 0 ? dc->timeout : r->server->timeout;
528
529 if (strcmp(r->handler, CGI_MAGIC_TYPE) && strcmp(r->handler, "cgi-script")) {
530 return DECLINED;
531 }
532
533 is_included = !strcmp(r->protocol, "INCLUDED");
534
535 p = r->main ? r->main->pool : r->pool;
536
537 argv0 = apr_filepath_name_get(r->filename);
538 nph = !(strncmp(argv0, "nph-", 4));
539 conf = ap_get_module_config(r->server->module_config, &cgi_module);
540
541 if (!(ap_allow_options(r) & OPT_EXECCGI) && !is_scriptaliased(r))
542 return log_scripterror(r, conf, HTTP_FORBIDDEN, 0, APLOGNO(02809),
543 "Options ExecCGI is off in this directory");
544 if (nph && is_included)
545 return log_scripterror(r, conf, HTTP_FORBIDDEN, 0, APLOGNO(02810),
546 "attempt to include NPH CGI script");
547
548 if (r->finfo.filetype == APR_NOFILE)
549 return log_scripterror(r, conf, HTTP_NOT_FOUND, 0, APLOGNO(02811),
550 "script not found or unable to stat");
551 if (r->finfo.filetype == APR_DIR)
552 return log_scripterror(r, conf, HTTP_FORBIDDEN, 0, APLOGNO(02812),
553 "attempt to invoke directory as script");
554
555 if ((r->used_path_info == AP_REQ_REJECT_PATH_INFO) &&
556 r->path_info && *r->path_info)
557 {
558 /* default to accept */
559 return log_scripterror(r, conf, HTTP_NOT_FOUND, 0, APLOGNO(02813),
560 "AcceptPathInfo off disallows user's path");
561 }
562/*
563 if (!ap_suexec_enabled) {
564 if (!ap_can_exec(&r->finfo))
565 return log_scripterror(r, conf, HTTP_FORBIDDEN, 0, APLOGNO(03194)
566 "file permissions deny server execution");

Callers

nothing calls this directly

Calls 11

ap_get_module_configFunction · 0.85
ap_allow_optionsFunction · 0.85
log_scripterrorFunction · 0.85
ap_add_common_varsFunction · 0.85
ap_add_cgi_varsFunction · 0.85
run_cgi_childFunction · 0.85
cgi_handle_requestFunction · 0.85
cgi_bucket_createFunction · 0.85
cgi_handle_responseFunction · 0.85
is_scriptaliasedFunction · 0.70

Tested by

no test coverage detected