mod_cgi.c revision 4f6effa17a5084085c9104b0bb97c2ba1622cfa6
c6d33447e28403a90ad817dba4df75fae785be28pquerna/* ====================================================================
c6d33447e28403a90ad817dba4df75fae785be28pquerna * The Apache Software License, Version 1.1
c6d33447e28403a90ad817dba4df75fae785be28pquerna * Copyright (c) 2000-2002 The Apache Software Foundation. All rights
c6d33447e28403a90ad817dba4df75fae785be28pquerna * reserved.
c6d33447e28403a90ad817dba4df75fae785be28pquerna * Redistribution and use in source and binary forms, with or without
c6d33447e28403a90ad817dba4df75fae785be28pquerna * modification, are permitted provided that the following conditions
c6d33447e28403a90ad817dba4df75fae785be28pquerna * 1. Redistributions of source code must retain the above copyright
c6d33447e28403a90ad817dba4df75fae785be28pquerna * notice, this list of conditions and the following disclaimer.
c6d33447e28403a90ad817dba4df75fae785be28pquerna * 2. Redistributions in binary form must reproduce the above copyright
c6d33447e28403a90ad817dba4df75fae785be28pquerna * notice, this list of conditions and the following disclaimer in
c6d33447e28403a90ad817dba4df75fae785be28pquerna * the documentation and/or other materials provided with the
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * distribution.
c6d33447e28403a90ad817dba4df75fae785be28pquerna * 3. The end-user documentation included with the redistribution,
c6d33447e28403a90ad817dba4df75fae785be28pquerna * if any, must include the following acknowledgment:
c6d33447e28403a90ad817dba4df75fae785be28pquerna * "This product includes software developed by the
c6d33447e28403a90ad817dba4df75fae785be28pquerna * Apache Software Foundation (http://www.apache.org/)."
c6d33447e28403a90ad817dba4df75fae785be28pquerna * Alternately, this acknowledgment may appear in the software itself,
c6d33447e28403a90ad817dba4df75fae785be28pquerna * if and wherever such third-party acknowledgments normally appear.
c6d33447e28403a90ad817dba4df75fae785be28pquerna * 4. The names "Apache" and "Apache Software Foundation" must
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * not be used to endorse or promote products derived from this
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * software without prior written permission. For written
c6d33447e28403a90ad817dba4df75fae785be28pquerna * permission, please contact apache@apache.org.
c6d33447e28403a90ad817dba4df75fae785be28pquerna * 5. Products derived from this software may not be called "Apache",
c6d33447e28403a90ad817dba4df75fae785be28pquerna * nor may "Apache" appear in their name, without prior written
c6d33447e28403a90ad817dba4df75fae785be28pquerna * permission of the Apache Software Foundation.
c6d33447e28403a90ad817dba4df75fae785be28pquerna * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * SUCH DAMAGE.
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * ====================================================================
c6d33447e28403a90ad817dba4df75fae785be28pquerna * This software consists of voluntary contributions made by many
c6d33447e28403a90ad817dba4df75fae785be28pquerna * individuals on behalf of the Apache Software Foundation. For more
c6d33447e28403a90ad817dba4df75fae785be28pquerna * information on the Apache Software Foundation, please see
c6d33447e28403a90ad817dba4df75fae785be28pquerna * Portions of this software are based upon public domain software
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * originally written at the National Center for Supercomputing Applications,
c6d33447e28403a90ad817dba4df75fae785be28pquerna * University of Illinois, Urbana-Champaign.
c6d33447e28403a90ad817dba4df75fae785be28pquerna * http_script: keeps all script-related ramblings together.
c6d33447e28403a90ad817dba4df75fae785be28pquerna * Compliant to CGI/1.1 spec
c6d33447e28403a90ad817dba4df75fae785be28pquerna * Adapted by rst from original NCSA code by Rob McCool
c6d33447e28403a90ad817dba4df75fae785be28pquerna * Apache adds some new env vars; REDIRECT_URL and REDIRECT_QUERY_STRING for
c6d33447e28403a90ad817dba4df75fae785be28pquerna * custom error responses, and DOCUMENT_ROOT because we found it useful.
c6d33447e28403a90ad817dba4df75fae785be28pquerna * It also adds SERVER_ADMIN - useful for scripts to know who to mail when
c6d33447e28403a90ad817dba4df75fae785be28pquerna * they fail.
c6d33447e28403a90ad817dba4df75fae785be28pquernastatic APR_OPTIONAL_FN_TYPE(ap_register_include_handler) *cgi_pfn_reg_with_ssi;
c6d33447e28403a90ad817dba4df75fae785be28pquernastatic APR_OPTIONAL_FN_TYPE(ap_ssi_get_tag_and_value) *cgi_pfn_gtv;
c6d33447e28403a90ad817dba4df75fae785be28pquernastatic APR_OPTIONAL_FN_TYPE(ap_ssi_parse_string) *cgi_pfn_ps;
c6d33447e28403a90ad817dba4df75fae785be28pquernastatic APR_OPTIONAL_FN_TYPE(ap_cgi_build_command) *cgi_build_command;
c6d33447e28403a90ad817dba4df75fae785be28pquerna/* Read and discard the data in the brigade produced by a CGI script */
c6d33447e28403a90ad817dba4df75fae785be28pquernastatic void discard_script_output(apr_bucket_brigade *bb);
c6d33447e28403a90ad817dba4df75fae785be28pquerna/* KLUDGE --- for back-combatibility, we don't have to check ExecCGI
c6d33447e28403a90ad817dba4df75fae785be28pquerna * in ScriptAliased directories, which means we need to know if this
c6d33447e28403a90ad817dba4df75fae785be28pquerna * request came through ScriptAlias or not... so the Alias module
c6d33447e28403a90ad817dba4df75fae785be28pquerna * leaves a note for us.
c6d33447e28403a90ad817dba4df75fae785be28pquerna const char *t = apr_table_get(r->notes, "alias-forced-type");
c6d33447e28403a90ad817dba4df75fae785be28pquerna/* Configuration stuff */
c6d33447e28403a90ad817dba4df75fae785be28pquernatypedef struct {
c6d33447e28403a90ad817dba4df75fae785be28pquerna const char *logname;
c6d33447e28403a90ad817dba4df75fae785be28pquernastatic void *create_cgi_config(apr_pool_t *p, server_rec *s)
c6d33447e28403a90ad817dba4df75fae785be28pquerna (cgi_server_conf *) apr_pcalloc(p, sizeof(cgi_server_conf));
c6d33447e28403a90ad817dba4df75fae785be28pquernastatic void *merge_cgi_config(apr_pool_t *p, void *basev, void *overridesv)
c6d33447e28403a90ad817dba4df75fae785be28pquernastatic const char *set_scriptlog(cmd_parms *cmd, void *dummy, const char *arg)
c6d33447e28403a90ad817dba4df75fae785be28pquerna cgi_server_conf *conf = ap_get_module_config(s->module_config,
c6d33447e28403a90ad817dba4df75fae785be28pquerna conf->logname = ap_server_root_relative(cmd->pool, arg);
c6d33447e28403a90ad817dba4df75fae785be28pquerna return apr_pstrcat(cmd->pool, "Invalid ScriptLog path ",
c6d33447e28403a90ad817dba4df75fae785be28pquernastatic const char *set_scriptlog_length(cmd_parms *cmd, void *dummy,
c6d33447e28403a90ad817dba4df75fae785be28pquerna const char *arg)
c6d33447e28403a90ad817dba4df75fae785be28pquerna cgi_server_conf *conf = ap_get_module_config(s->module_config,
c6d33447e28403a90ad817dba4df75fae785be28pquernastatic const char *set_scriptlog_buffer(cmd_parms *cmd, void *dummy,
c6d33447e28403a90ad817dba4df75fae785be28pquerna const char *arg)
c6d33447e28403a90ad817dba4df75fae785be28pquerna cgi_server_conf *conf = ap_get_module_config(s->module_config,
c6d33447e28403a90ad817dba4df75fae785be28pquernaAP_INIT_TAKE1("ScriptLog", set_scriptlog, NULL, RSRC_CONF,
c6d33447e28403a90ad817dba4df75fae785be28pquerna "the name of a log for script debugging info"),
c6d33447e28403a90ad817dba4df75fae785be28pquernaAP_INIT_TAKE1("ScriptLogLength", set_scriptlog_length, NULL, RSRC_CONF,
c6d33447e28403a90ad817dba4df75fae785be28pquerna "the maximum length (in bytes) of the script debug log"),
c6d33447e28403a90ad817dba4df75fae785be28pquernaAP_INIT_TAKE1("ScriptLogBuffer", set_scriptlog_buffer, NULL, RSRC_CONF,
c6d33447e28403a90ad817dba4df75fae785be28pquerna "the maximum size (in bytes) to record of a POST request"),
c6d33447e28403a90ad817dba4df75fae785be28pquernastatic int log_scripterror(request_rec *r, cgi_server_conf * conf, int ret,
c6d33447e28403a90ad817dba4df75fae785be28pquerna /* XXX Very expensive mainline case! Open, then getfileinfo! */
c6d33447e28403a90ad817dba4df75fae785be28pquerna /* "%% [Wed Jun 19 10:53:21 1996] GET /cgi-bin/printenv HTTP/1.0" */
c6d33447e28403a90ad817dba4df75fae785be28pquerna apr_file_printf(f, "%%%% [%s] %s %s%s%s %s\n", time_str, r->method, r->uri,
c6d33447e28403a90ad817dba4df75fae785be28pquerna r->args ? "?" : "", r->args ? r->args : "", r->protocol);
c6d33447e28403a90ad817dba4df75fae785be28pquerna apr_file_printf(f, "%%%% %d %s\n", ret, r->filename);
c6d33447e28403a90ad817dba4df75fae785be28pquerna/* Soak up stderr from a script and redirect it to the error log.
c6d33447e28403a90ad817dba4df75fae785be28pquernastatic void log_script_err(request_rec *r, apr_file_t *script_err)
c6d33447e28403a90ad817dba4df75fae785be28pquernastatic int log_script(request_rec *r, cgi_server_conf * conf, int ret,
c6d33447e28403a90ad817dba4df75fae785be28pquerna char *dbuf, const char *sbuf, apr_bucket_brigade *bb,
c6d33447e28403a90ad817dba4df75fae785be28pquerna const apr_array_header_t *hdrs_arr = apr_table_elts(r->headers_in);
c6d33447e28403a90ad817dba4df75fae785be28pquerna const apr_table_entry_t *hdrs = (const apr_table_entry_t *) hdrs_arr->elts;
c6d33447e28403a90ad817dba4df75fae785be28pquerna const char *buf;
c6d33447e28403a90ad817dba4df75fae785be28pquerna /* XXX Very expensive mainline case! Open, then getfileinfo! */
c6d33447e28403a90ad817dba4df75fae785be28pquerna /* Soak up script output */
c6d33447e28403a90ad817dba4df75fae785be28pquerna /* "%% [Wed Jun 19 10:53:21 1996] GET /cgi-bin/printenv HTTP/1.0" */
c6d33447e28403a90ad817dba4df75fae785be28pquerna apr_file_printf(f, "%%%% [%s] %s %s%s%s %s\n", time_str, r->method, r->uri,
c6d33447e28403a90ad817dba4df75fae785be28pquerna r->args ? "?" : "", r->args ? r->args : "", r->protocol);
c6d33447e28403a90ad817dba4df75fae785be28pquerna apr_file_printf(f, "%%%% %d %s\n", ret, r->filename);
fa9496078a83e18311b90b33574fdeb9c115ed7dpquerna apr_file_printf(f, "%s: %s\n", hdrs[i].key, hdrs[i].val);
fa9496078a83e18311b90b33574fdeb9c115ed7dpquerna if ((r->method_number == M_POST || r->method_number == M_PUT) &&
c6d33447e28403a90ad817dba4df75fae785be28pquerna apr_file_printf(f, "%s: %s\n", hdrs[i].key, hdrs[i].val);
c6d33447e28403a90ad817dba4df75fae785be28pquerna rv = apr_bucket_read(e, &buf, &len, APR_BLOCK_READ);
c6d33447e28403a90ad817dba4df75fae785be28pquerna if (apr_file_gets(argsbuffer, HUGE_STRING_LEN, script_err) == APR_SUCCESS) {
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna/* This is the special environment used for running the "exec cmd="
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * variety of SSI directives.
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquernastatic void add_ssi_vars(request_rec *r, ap_filter_t *next)
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna apr_table_setn(e, "PATH_INFO", ap_escape_shell_cmd(r->pool,
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna pa_req = ap_sub_req_lookup_uri(ap_escape_uri(r->pool, r->path_info),
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquernastatic apr_status_t run_cgi_child(apr_file_t **script_out,
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna const char *command,
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna const char * const argv[],
c6d33447e28403a90ad817dba4df75fae785be28pquerna const char * const *env;
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna#if defined(RLIMIT_CPU) || defined(RLIMIT_NPROC) || \
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna defined(RLIMIT_DATA) || defined(RLIMIT_VMEM) || defined (RLIMIT_AS)
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna core_dir_config *conf = ap_get_module_config(r->per_dir_config,
c6d33447e28403a90ad817dba4df75fae785be28pquerna /* Under OS/2 need to use device con. */
c6d33447e28403a90ad817dba4df75fae785be28pquerna fprintf(dbg, "Attempting to exec %s as CGI child (argv0 = %s)\n",
c6d33447e28403a90ad817dba4df75fae785be28pquerna else /* SSIs want a controlled environment and a special path. */
c6d33447e28403a90ad817dba4df75fae785be28pquerna env = (const char * const *)ap_create_environment(p, r->subprocess_env);
c6d33447e28403a90ad817dba4df75fae785be28pquerna for (i = 0; env[i]; ++i)
c6d33447e28403a90ad817dba4df75fae785be28pquerna /* Transmute ourselves into the script.
c6d33447e28403a90ad817dba4df75fae785be28pquerna * NB only ISINDEX scripts get decoded arguments.
c6d33447e28403a90ad817dba4df75fae785be28pquerna if (((rc = apr_procattr_create(&procattr, p)) != APR_SUCCESS) ||
c6d33447e28403a90ad817dba4df75fae785be28pquerna ((rc = apr_procattr_limit_set(procattr, APR_LIMIT_CPU,
c6d33447e28403a90ad817dba4df75fae785be28pquerna#if defined(RLIMIT_DATA) || defined(RLIMIT_VMEM) || defined(RLIMIT_AS)
c6d33447e28403a90ad817dba4df75fae785be28pquerna ((rc = apr_procattr_limit_set(procattr, APR_LIMIT_MEM,
c6d33447e28403a90ad817dba4df75fae785be28pquerna ((rc = apr_procattr_limit_set(procattr, APR_LIMIT_NPROC,
c6d33447e28403a90ad817dba4df75fae785be28pquerna /* Something bad happened, tell the world. */
c6d33447e28403a90ad817dba4df75fae785be28pquerna "couldn't set child process attributes: %s", r->filename);
fa9496078a83e18311b90b33574fdeb9c115ed7dpquerna SPLIT_AND_PASS_PRETAG_BUCKETS(*(e_info->bb), e_info->ctx,
fa9496078a83e18311b90b33574fdeb9c115ed7dpquerna rc = ap_os_create_privileged_process(r, procnew, command, argv, env,
c6d33447e28403a90ad817dba4df75fae785be28pquerna /* Bad things happened. Everyone should have cleaned up. */
fa9496078a83e18311b90b33574fdeb9c115ed7dpquerna apr_pool_note_subprocess(p, procnew, APR_KILL_AFTER_TIMEOUT);
c6d33447e28403a90ad817dba4df75fae785be28pquerna apr_file_pipe_timeout_set(*script_in, r->server->timeout);
c6d33447e28403a90ad817dba4df75fae785be28pquerna apr_file_pipe_timeout_set(*script_out, r->server->timeout);
c6d33447e28403a90ad817dba4df75fae785be28pquerna apr_file_pipe_timeout_set(*script_err, r->server->timeout);
fa9496078a83e18311b90b33574fdeb9c115ed7dpquernastatic apr_status_t default_build_command(const char **cmd, const char ***argv,
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna /* Allow suexec's "/" check to succeed */
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna /* Do not process r->args if they contain an '=' assignment
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna if (r->args && r->args[0] && !ap_strchr_c(r->args, '=')) {
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna /* count the number of keywords */
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna /* Everything is - 1 to account for the first parameter
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * which is the program name.
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna numwords = APACHE_ARG_MAX - 1; /* Truncate args to prevent overrun */
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna *argv = apr_palloc(p, (numwords + 2) * sizeof(char *));
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquernastatic void discard_script_output(apr_bucket_brigade *bb)
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna const char *buf;
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna rv = apr_bucket_read(e, &buf, &len, APR_BLOCK_READ);
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna const char *argv0;
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna const char *command;
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna const char **argv;
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna apr_file_t *script_out = NULL, *script_in = NULL, *script_err = NULL;
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna if(strcmp(r->handler, CGI_MAGIC_TYPE) && strcmp(r->handler, "cgi-script"))
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna /* 99 out of 100 CGI scripts, this is all they support */
c6d33447e28403a90ad817dba4df75fae785be28pquerna conf = ap_get_module_config(r->server->module_config, &cgi_module);
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna if (!(ap_allow_options(r) & OPT_EXECCGI) && !is_scriptaliased(r))
fa9496078a83e18311b90b33574fdeb9c115ed7dpquerna "Options ExecCGI is off in this directory");
c6d33447e28403a90ad817dba4df75fae785be28pquerna "attempt to include NPH CGI script");
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna "script not found or unable to stat");
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna "attempt to invoke directory as script");
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna if ((r->used_path_info == AP_REQ_REJECT_PATH_INFO) &&
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna /* default to accept */
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna "AcceptPathInfo off disallows user's path");
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna if (!ap_suexec_enabled) {
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna if (!ap_can_exec(&r->finfo))
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna return log_scripterror(r, conf, HTTP_FORBIDDEN, 0,
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna "file permissions deny server execution");
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna /* build the command line */
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna if ((rv = cgi_build_command(&command, &argv, r, p, &e_info)) != APR_SUCCESS) {
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna "don't know how to spawn child process: %s",
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna /* run the script in its own process */
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna if ((rv = run_cgi_child(&script_out, &script_in, &script_err,
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna /* Transfer any put/post args, CERN style...
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * Note that we already ignore SIGPIPE in the core server.
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna bb = apr_brigade_create(r->pool, r->connection->bucket_alloc);
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna rv = ap_get_brigade(r->input_filters, bb, AP_MODE_READBYTES,
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna const char *data;
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna /* We can't do much with this. */
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna /* If the child stopped, we still must read to EOS. */
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna apr_bucket_read(bucket, &data, &len, APR_BLOCK_READ);
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna /* Keep writing data to the child until done or too much time
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * elapses with no progress or an error occurs.
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna rv = apr_file_write_full(script_out, data, len, NULL);
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna /* silly script stopped reading, soak up remaining message */
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna /* Is this flush really needed? */
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna /* Handle script return... */
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna const char *location;
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna b = apr_bucket_pipe_create(script_in, c->bucket_alloc);
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna if ((ret = ap_scan_script_header_err_brigade(r, bb, sbuf))) {
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna return log_script(r, conf, ret, dbuf, sbuf, bb, script_err);
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna location = apr_table_get(r->headers_out, "Location");
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna if (location && location[0] == '/' && r->status == 200) {
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna /* This redirect needs to be a GET no matter what the original
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * method was.
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna /* We already read the message body (if any), so don't allow
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * the redirected request to think it has one. We can ignore
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * Transfer-Encoding, since we used REQUEST_CHUNKED_ERROR.
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna /* XX Note that if a script wants to produce its own Redirect
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * body, it now has to explicitly *say* "Status: 302"
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna /* get rid of all filters up through protocol... since we
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * haven't parsed off the headers, there is no way they can
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna while (cur && cur->frec->ftype < AP_FTYPE_CONNECTION) {
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna b = apr_bucket_pipe_create(script_in, c->bucket_alloc);
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna return OK; /* NOT r->status, even if it has changed. */
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna/*============================================================================
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna *============================================================================
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * This is the beginning of the cgi filter code moved from mod_include. This
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna * is the code required to handle the "exec" SSI directive.
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna *============================================================================
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna *============================================================================*/
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquernastatic int include_cgi(char *s, request_rec *r, ap_filter_t *next,
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna request_rec *rr = ap_sub_req_lookup_uri(s, r, next);
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna /* No hardwired path info or query allowed */
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna if ((rr->path_info && rr->path_info[0]) || rr->args) {
c6d33447e28403a90ad817dba4df75fae785be28pquerna /* Script gets parameters of the *document*, for back compatibility */
546d45814f6de2976187f3eaad9ba7a4b01c8b77pquerna rr->path_info = r->path_info; /* hard to get right; see mod_cgi.c */
c6d33447e28403a90ad817dba4df75fae785be28pquerna /* Force sub_req to be treated as a CGI request, even if ordinary
c6d33447e28403a90ad817dba4df75fae785be28pquerna * typing rules would have called it something else.
c6d33447e28403a90ad817dba4df75fae785be28pquerna /* Run it. */
c6d33447e28403a90ad817dba4df75fae785be28pquerna const char *location = apr_table_get(rr->headers_out, "Location");
c->bucket_alloc);
c->bucket_alloc);
c->bucket_alloc);
c->bucket_alloc);
c->bucket_alloc);
const char **argv;
apr_bucket *b;
r->filename);
return HTTP_INTERNAL_SERVER_ERROR;
return HTTP_INTERNAL_SERVER_ERROR;
sizeof(parsed_string), 0);
return retval;
if (!cgi_build_command) {
return OK;