util_script.c revision 8fdb7710b01f7d33f487ae558559c242d87eda41
6115N/A/* ==================================================================== 6115N/A * The Apache Software License, Version 1.1 6115N/A * Copyright (c) 2000 The Apache Software Foundation. All rights 6115N/A * Redistribution and use in source and binary forms, with or without 6115N/A * modification, are permitted provided that the following conditions 6115N/A * 1. Redistributions of source code must retain the above copyright 6115N/A * notice, this list of conditions and the following disclaimer. 6115N/A * 2. Redistributions in binary form must reproduce the above copyright 6115N/A * notice, this list of conditions and the following disclaimer in 6115N/A * the documentation and/or other materials provided with the 6115N/A * 3. The end-user documentation included with the redistribution, 6115N/A * if any, must include the following acknowledgment: 6115N/A * "This product includes software developed by the 6115N/A * Alternately, this acknowledgment may appear in the software itself, 6115N/A * if and wherever such third-party acknowledgments normally appear. 6115N/A * 4. The names "Apache" and "Apache Software Foundation" must 6115N/A * not be used to endorse or promote products derived from this 6115N/A * software without prior written permission. For written 6115N/A * permission, please contact apache@apache.org. 6115N/A * 5. Products derived from this software may not be called "Apache", 6115N/A * nor may "Apache" appear in their name, without prior written 6115N/A * permission of the Apache Software Foundation. 6115N/A * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 6115N/A * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 6115N/A * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 6115N/A * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR 6115N/A * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 6115N/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 6115N/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 6115N/A * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 6115N/A * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 6115N/A * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 6115N/A * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 6115N/A * ==================================================================== 6115N/A * This software consists of voluntary contributions made by many 6115N/A * individuals on behalf of the Apache Software Foundation. For more 6115N/A * information on the Apache Software Foundation, please see 6115N/A * Portions of this software are based upon public domain software 6115N/A * originally written at the National Center for Supercomputing Applications, 6115N/A * University of Illinois, Urbana-Champaign. * Various utility functions which are common to a whole lot of * script-type extensions mechanisms, and might as well be gathered * in one place (if only to avoid creating inter-module dependancies * where there don't have to be). /* use a temporary apr_table_t which we'll overlap onto * r->subprocess_env later /* First, add environment vars from headers... this is as per * CGI specs, though other sorts of scripting interfaces see /* A few headers are special cased --- Authorization to prevent * rogue scripts from capturing passwords; content-type and -length * for no particular reason. * You really don't want to disable this check, since it leaves you * wide open to CGIs stealing passwords and people viewing them * in the environment with "ps -e". But, if you must... /* Apache custom error responses. If we have redirected set two new vars */ /* This "cute" little function comes about because the path info on * filenames and URLs aren't always the same. So we take the two, * and find as much of the two that match as possible. /* Obtain the Request-URI from the original request-line, returning * a new string from the request pool containing the URI or "". ++
first;
/* skip over the method */ ++
first;
/* and the space(s) */ ++
last;
/* end at next whitespace */ /* Note that the code below special-cases scripts run from includes, * because it "knows" that the sub_request has been hacked to have the * args and path_info of the original request, and not any that may have * come with the script URI in the include command. Ugh. * To get PATH_TRANSLATED, treat PATH_INFO as a URI path. * Need to re-escape it for this, since the entire URI was * un-escaped before we determined where the PATH_INFO began. /* We need to make this a real Windows path name */ /* temporary place to hold headers to merge in later */ /* The HTTP specification says that it is legal to merge duplicate * headers into one. Some browsers that support Cookies don't like * merged headers and prefer that each Set-Cookie header is sent * separately. Lets humour those browsers by not merging. "Premature end of script headers: %s", r->
filename);
/* Delete terminal (CR?)LF */ /* Indeed, the host's '\n': '\012' for UNIX; '\015' for MacOS; '\025' for OS/390 -- whatever the script generates. if (p > 0 && w[p -
1] ==
'\n') {
if (p >
1 && w[p -
2] ==
CR) {
* If we've finished reading the headers, check to make sure any * HTTP/1.1 conditions are met. If so, we're done; normal processing * will handle the script's output. If not, just return the error. * The appropriate thing to do would be to send the script process a * SIGPIPE to let it know we're ignoring it, close the channel to the * script process, and *then* return the failed-to-meet-condition * error. Otherwise we'd be waiting for the script to finish * blithering before telling the client the output was no good. * However, we don't have the information to do that, so we have to * leave it to an upper layer. /* the cookies have already been copied to the cookie_table */ /* if we see a bogus header don't ignore it. Shout and scream */ /* Chances are that we received an ASCII header text instead of * the expected EBCDIC header lines. Try to auto-detect: for (
cp = w; *
cp !=
'\0'; ++
cp) {
"CGI Interface Error: Script headers apparently ASCII: (CGI = %s)",
#
endif /*CHARSET_EBCDIC*/ /* Soak up all the script output - may save an outright kill */ /* Nuke trailing whitespace */ * If the script returned a specific status, that's what * we'll use - otherwise we assume 200 OK. * If the script gave us a Last-Modified header, we can't just * pass it on blindly because of restrictions on future values. /* ap_scan_script_header_err_strs() accepts additional const char* args... * each is treated as one or more header lines, and the first non-header * character is returned to **arg, **data. (The first optional arg is /* XXX: this -1 thing is a gross hack */ else if (
size <
1048576) {
else if (
size <
103809024) {