mod_cgi.c revision 30c289e6bc6d28d210b21edd800ab2cfc78a8381
2128N/A/* ==================================================================== 2128N/A * The Apache Software License, Version 1.1 2128N/A * Copyright (c) 2000 The Apache Software Foundation. All rights 2128N/A * Redistribution and use in source and binary forms, with or without 2128N/A * modification, are permitted provided that the following conditions 2128N/A * 1. Redistributions of source code must retain the above copyright 2128N/A * notice, this list of conditions and the following disclaimer. 2128N/A * 2. Redistributions in binary form must reproduce the above copyright 2128N/A * notice, this list of conditions and the following disclaimer in 2128N/A * the documentation and/or other materials provided with the 2128N/A * 3. The end-user documentation included with the redistribution, 2128N/A * if any, must include the following acknowledgment: 3817N/A * "This product includes software developed by the 2128N/A * Alternately, this acknowledgment may appear in the software itself, 2128N/A * if and wherever such third-party acknowledgments normally appear. 2128N/A * 4. The names "Apache" and "Apache Software Foundation" must 2128N/A * not be used to endorse or promote products derived from this 2128N/A * software without prior written permission. For written 2128N/A * permission, please contact apache@apache.org. 3817N/A * 5. Products derived from this software may not be called "Apache", 2128N/A * nor may "Apache" appear in their name, without prior written 2128N/A * permission of the Apache Software Foundation. 2128N/A * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 2128N/A * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 3817N/A * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 3817N/A * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR 2128N/A * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2128N/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 3817N/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 3817N/A * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 3817N/A * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 3817N/A * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * ==================================================================== * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * Portions of this software are based upon public domain software * originally written at the National Center for Supercomputing Applications, * University of Illinois, Urbana-Champaign. * http_script: keeps all script-related ramblings together. * Compliant to CGI/1.1 spec * Adapted by rst from original NCSA code by Rob McCool * Apache adds some new env vars; REDIRECT_URL and REDIRECT_QUERY_STRING for * custom error responses, and DOCUMENT_ROOT because we found it useful. * It also adds SERVER_ADMIN - useful for scripts to know who to mail when /* KLUDGE --- for back-combatibility, we don't have to check ExecCGI * in ScriptAliased directories, which means we need to know if this * request came through ScriptAlias or not... so the Alias module /* Configuration stuff */ "the name of a log for script debugging info"},
"the maximum length (in bytes) of the script debug log"},
"the maximum size (in bytes) to record of a POST request"},
/* Soak up script output */ /* Soak up stderr and redirect it to the error log. * Script output to stderr is already directed to the error log * on Unix, thanks to the magic of fork(). /* Under OS/2 need to use device con. */ fprintf(
dbg,
"Attempting to exec %s as %sCGI child (argv0 = %s)\n",
/* Transumute ourselves into the script. * NB only ISINDEX scripts get decoded arguments. /* Something bad happened, tell the world. */ "couldn't create child process: %s", r->
filename);
/* Bad things happened. Everyone should have cleaned up. */ "couldn't create child process: %d: %s",
rc, r->
filename);
/* Fill in BUFF structure for parents pipe to child's stdout */ /* Fill in BUFF structure for parents pipe to child's stdin */ /* Fill in BUFF structure for parents pipe to child's stderr */ /* count the number of keywords */ /* Everything is - 1 to account for the first parameter which is the * program name. We didn't used to have to do this, but APR wants it. "%s is not executable; ensure interpreted scripts have " * Build the command string to pass to ap_create_process() /* 99 out of 100 CGI scripts, this is all they support */ "Options ExecCGI is off in this directory");
"attempt to include NPH CGI script");
/* Allow for cgi files without the .EXE extension on them under OS/2 */ "script not found or unable to stat");
"script not found or unable to stat");
"attempt to invoke directory as script");
if (!ap_suexec_enabled) { if (!ap_can_exec(&r->finfo)) return log_scripterror(r, conf, FORBIDDEN, APLOG_NOERRNO, "file permissions deny server execution"); /* build the command line */ "couldn't spawn child process: %s", r->
filename);
/* build the argument list */ "couldn't spawn child process: %s", r->
filename);
/* run the script in its own process */ "couldn't spawn child process: %s", r->
filename);
/* Transfer any put/post args, CERN style... * Note that we already ignore SIGPIPE in the core server. /* silly script stopped reading, soak up remaining message */ /* Handle script return... */ /* Now check the Content-Type to decide if conversion is needed */ #
endif /*CHARSET_EBCDIC*/ /* Soak up all the script output */ /* This redirect needs to be a GET no matter what the original /* We already read the message body (if any), so don't allow * the redirected request to think it has one. We can ignore * Transfer-Encoding, since we used REQUEST_CHUNKED_ERROR. /* XX Note that if a script wants to produce its own Redirect * body, it now has to explicitly *say* "Status: 302" return OK;
/* NOT r->status, even if it has changed. */ NULL,
/* dir config creater */ NULL,
/* dir merger --- default is to override */ NULL /* register hooks */