util_script.c revision 33510984c759eb3da154ceb0db9b75fa0031d3b4
369N/A/* Licensed to the Apache Software Foundation (ASF) under one or more 369N/A * contributor license agreements. See the NOTICE file distributed with 369N/A * this work for additional information regarding copyright ownership. 369N/A * The ASF licenses this file to You under the Apache License, Version 2.0 369N/A * (the "License"); you may not use this file except in compliance with 369N/A * the License. You may obtain a copy of the License at 369N/A * Unless required by applicable law or agreed to in writing, software 369N/A * distributed under the License is distributed on an "AS IS" BASIS, 369N/A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 369N/A * See the License for the specific language governing permissions and 369N/A * limitations under the License. * 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). while ((c = *w++) != 0) {
"Not exporting header with invalid name as envvar: %s",
/* use a temporary apr_table_t which we'll overlap onto * r->subprocess_env later * (exception: if r->subprocess_env is empty at the start, * write directly into it) /* 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... /* HPUX PARISC 2.0W knows both, otherwise redundancy is harmless */ /* 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",
"Script timed out before returning headers: %s",
/* 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. /* PR#38070: This fails because it gets confused when a * CGI Status header overrides ap_meets_conditions. * We can fix that by dropping ap_meets_conditions when * Status has been set. Since this is the only place * cgi_status gets used, let's test it explicitly. * The alternative would be to ignore CGI Status when * ap_meets_conditions returns anything interesting. * That would be safer wrt HTTP, but would break CGI. /* 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 /*APR_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. /* never reached - we leave this function within the while loop above */ const char *
dst_end =
buf +
len -
1;
/* leave room for terminating null */ /* 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 *
value =
'\0';
/* Split the string in two */ value++;
/* Skip passed the = */