util_script.c revision c13d541615044010381184f9edf948c0a4c6723e
2d2eda71267231c2526be701fe655db125852c1ffielding/* ====================================================================
f062ed7bd262a37a909dd77ce5fc23b446818823fielding * The Apache Software License, Version 1.1
f062ed7bd262a37a909dd77ce5fc23b446818823fielding *
bc8fd1b0b1afdf89b8d28eefa8cd74e26ba97986fielding * Copyright (c) 2000-2001 The Apache Software Foundation. All rights
f062ed7bd262a37a909dd77ce5fc23b446818823fielding * reserved.
2d2eda71267231c2526be701fe655db125852c1ffielding *
2d2eda71267231c2526be701fe655db125852c1ffielding * Redistribution and use in source and binary forms, with or without
2d2eda71267231c2526be701fe655db125852c1ffielding * modification, are permitted provided that the following conditions
2d2eda71267231c2526be701fe655db125852c1ffielding * are met:
2d2eda71267231c2526be701fe655db125852c1ffielding *
2d2eda71267231c2526be701fe655db125852c1ffielding * 1. Redistributions of source code must retain the above copyright
2d2eda71267231c2526be701fe655db125852c1ffielding * notice, this list of conditions and the following disclaimer.
2d2eda71267231c2526be701fe655db125852c1ffielding *
2d2eda71267231c2526be701fe655db125852c1ffielding * 2. Redistributions in binary form must reproduce the above copyright
2d2eda71267231c2526be701fe655db125852c1ffielding * notice, this list of conditions and the following disclaimer in
2d2eda71267231c2526be701fe655db125852c1ffielding * the documentation and/or other materials provided with the
2d2eda71267231c2526be701fe655db125852c1ffielding * distribution.
2d2eda71267231c2526be701fe655db125852c1ffielding *
f062ed7bd262a37a909dd77ce5fc23b446818823fielding * 3. The end-user documentation included with the redistribution,
f062ed7bd262a37a909dd77ce5fc23b446818823fielding * if any, must include the following acknowledgment:
f062ed7bd262a37a909dd77ce5fc23b446818823fielding * "This product includes software developed by the
f062ed7bd262a37a909dd77ce5fc23b446818823fielding * Apache Software Foundation (http://www.apache.org/)."
f062ed7bd262a37a909dd77ce5fc23b446818823fielding * Alternately, this acknowledgment may appear in the software itself,
f062ed7bd262a37a909dd77ce5fc23b446818823fielding * if and wherever such third-party acknowledgments normally appear.
2d2eda71267231c2526be701fe655db125852c1ffielding *
f062ed7bd262a37a909dd77ce5fc23b446818823fielding * 4. The names "Apache" and "Apache Software Foundation" must
f062ed7bd262a37a909dd77ce5fc23b446818823fielding * not be used to endorse or promote products derived from this
f062ed7bd262a37a909dd77ce5fc23b446818823fielding * software without prior written permission. For written
f062ed7bd262a37a909dd77ce5fc23b446818823fielding * permission, please contact apache@apache.org.
2d2eda71267231c2526be701fe655db125852c1ffielding *
f062ed7bd262a37a909dd77ce5fc23b446818823fielding * 5. Products derived from this software may not be called "Apache",
f062ed7bd262a37a909dd77ce5fc23b446818823fielding * nor may "Apache" appear in their name, without prior written
64185f9824e42f21ca7b9ae6c004484215c031a7rbb * permission of the Apache Software Foundation.
2d2eda71267231c2526be701fe655db125852c1ffielding *
f062ed7bd262a37a909dd77ce5fc23b446818823fielding * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
f062ed7bd262a37a909dd77ce5fc23b446818823fielding * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
f062ed7bd262a37a909dd77ce5fc23b446818823fielding * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
f062ed7bd262a37a909dd77ce5fc23b446818823fielding * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
2d2eda71267231c2526be701fe655db125852c1ffielding * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
f062ed7bd262a37a909dd77ce5fc23b446818823fielding * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
f062ed7bd262a37a909dd77ce5fc23b446818823fielding * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
f062ed7bd262a37a909dd77ce5fc23b446818823fielding * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
f062ed7bd262a37a909dd77ce5fc23b446818823fielding * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
f062ed7bd262a37a909dd77ce5fc23b446818823fielding * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
f062ed7bd262a37a909dd77ce5fc23b446818823fielding * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
f062ed7bd262a37a909dd77ce5fc23b446818823fielding * SUCH DAMAGE.
2d2eda71267231c2526be701fe655db125852c1ffielding * ====================================================================
2d2eda71267231c2526be701fe655db125852c1ffielding *
2d2eda71267231c2526be701fe655db125852c1ffielding * This software consists of voluntary contributions made by many
f062ed7bd262a37a909dd77ce5fc23b446818823fielding * individuals on behalf of the Apache Software Foundation. For more
f062ed7bd262a37a909dd77ce5fc23b446818823fielding * information on the Apache Software Foundation, please see
f062ed7bd262a37a909dd77ce5fc23b446818823fielding * <http://www.apache.org/>.
2d2eda71267231c2526be701fe655db125852c1ffielding *
f062ed7bd262a37a909dd77ce5fc23b446818823fielding * Portions of this software are based upon public domain software
f062ed7bd262a37a909dd77ce5fc23b446818823fielding * originally written at the National Center for Supercomputing Applications,
f062ed7bd262a37a909dd77ce5fc23b446818823fielding * University of Illinois, Urbana-Champaign.
2d2eda71267231c2526be701fe655db125852c1ffielding */
2d2eda71267231c2526be701fe655db125852c1ffielding
2d2eda71267231c2526be701fe655db125852c1ffielding#include "apr.h"
2d2eda71267231c2526be701fe655db125852c1ffielding#include "apr_lib.h"
2d2eda71267231c2526be701fe655db125852c1ffielding#include "apr_strings.h"
fcc25eda7b150e226d3c1cdaea66a943d3fdee4erbb
b980ad7fdc218b4855cde9f75a747527f50c554dwrowe#define APR_WANT_STRFUNC
ab5581cc78e9d865b0a6ab1404c53347b3276968rbb#include "apr_want.h"
92f3af936ce61f25358a3ee4f28df2f6d62040dfdreid
fcc25eda7b150e226d3c1cdaea66a943d3fdee4erbb#if APR_HAVE_STDLIB_H
c9a95767fbf0f5fb0976a06b97a256033925e433rbb#include <stdlib.h>
fd0edaa8e3d4dd67d0604ccef2e96b071db96643fielding#endif
2d2eda71267231c2526be701fe655db125852c1ffielding
2d2eda71267231c2526be701fe655db125852c1ffielding#define CORE_PRIVATE
2d2eda71267231c2526be701fe655db125852c1ffielding#include "ap_config.h"
2d2eda71267231c2526be701fe655db125852c1ffielding#include "httpd.h"
61fd0cab072a05b855cbef9c585702401ac5ae29rbb#include "http_config.h"
61fd0cab072a05b855cbef9c585702401ac5ae29rbb#include "http_main.h"
61fd0cab072a05b855cbef9c585702401ac5ae29rbb#include "http_log.h"
61fd0cab072a05b855cbef9c585702401ac5ae29rbb#include "http_core.h"
fd492f9543f14fb5bae78e04b135c3448eb9cc56rbb#include "http_protocol.h"
fd492f9543f14fb5bae78e04b135c3448eb9cc56rbb#include "http_request.h" /* for sub_req_lookup_uri() */
fd492f9543f14fb5bae78e04b135c3448eb9cc56rbb#include "util_script.h"
fd492f9543f14fb5bae78e04b135c3448eb9cc56rbb#include "apr_date.h" /* For apr_date_parse_http() */
fd492f9543f14fb5bae78e04b135c3448eb9cc56rbb#include "util_ebcdic.h"
2d2eda71267231c2526be701fe655db125852c1ffielding
2d2eda71267231c2526be701fe655db125852c1ffielding#ifdef OS2
2d2eda71267231c2526be701fe655db125852c1ffielding#define INCL_DOS
2d2eda71267231c2526be701fe655db125852c1ffielding#include <os2.h>
2d2eda71267231c2526be701fe655db125852c1ffielding#endif
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb/*
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * Various utility functions which are common to a whole lot of
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * script-type extensions mechanisms, and might as well be gathered
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * in one place (if only to avoid creating inter-module dependancies
2d2eda71267231c2526be701fe655db125852c1ffielding * where there don't have to be).
2d2eda71267231c2526be701fe655db125852c1ffielding */
8af88bd6958b80c224e964892b8237720b13ab1ajerenkrantz
8af88bd6958b80c224e964892b8237720b13ab1ajerenkrantz#define MALFORMED_MESSAGE "malformed header from script. Bad header="
8af88bd6958b80c224e964892b8237720b13ab1ajerenkrantz#define MALFORMED_HEADER_LENGTH_TO_SHOW 30
8af88bd6958b80c224e964892b8237720b13ab1ajerenkrantz
8af88bd6958b80c224e964892b8237720b13ab1ajerenkrantzstatic char *http2env(apr_pool_t *a, char *w)
8af88bd6958b80c224e964892b8237720b13ab1ajerenkrantz{
bfb62a96023822c56c9120e4ee627d4091cc59c2rbb char *res = apr_pstrcat(a, "HTTP_", w, NULL);
bfb62a96023822c56c9120e4ee627d4091cc59c2rbb char *cp = res;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb while (*++cp) {
61fd0cab072a05b855cbef9c585702401ac5ae29rbb if (!apr_isalnum(*cp) && *cp != '_') {
61fd0cab072a05b855cbef9c585702401ac5ae29rbb *cp = '_';
61fd0cab072a05b855cbef9c585702401ac5ae29rbb }
61fd0cab072a05b855cbef9c585702401ac5ae29rbb else {
3d96ee83babeec32482c9082c9426340cee8c44dwrowe *cp = apr_toupper(*cp);
2d2eda71267231c2526be701fe655db125852c1ffielding }
61fd0cab072a05b855cbef9c585702401ac5ae29rbb }
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb return res;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb}
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbbAP_DECLARE(char **) ap_create_environment(apr_pool_t *p, apr_table_t *t)
61fd0cab072a05b855cbef9c585702401ac5ae29rbb{
61fd0cab072a05b855cbef9c585702401ac5ae29rbb apr_array_header_t *env_arr = apr_table_elts(t);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb apr_table_entry_t *elts = (apr_table_entry_t *) env_arr->elts;
2d2eda71267231c2526be701fe655db125852c1ffielding char **env = (char **) apr_palloc(p, (env_arr->nelts + 2) * sizeof(char *));
3d96ee83babeec32482c9082c9426340cee8c44dwrowe int i, j;
2d2eda71267231c2526be701fe655db125852c1ffielding char *tz;
2d2eda71267231c2526be701fe655db125852c1ffielding char *whack;
2d2eda71267231c2526be701fe655db125852c1ffielding
2d2eda71267231c2526be701fe655db125852c1ffielding j = 0;
000b67449410515eac43e76ef6667915bfd4d2abgstein if (!apr_table_get(t, "TZ")) {
2d2eda71267231c2526be701fe655db125852c1ffielding tz = getenv("TZ");
2d2eda71267231c2526be701fe655db125852c1ffielding if (tz != NULL) {
2d2eda71267231c2526be701fe655db125852c1ffielding env[j++] = apr_pstrcat(p, "TZ=", tz, NULL);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb }
61fd0cab072a05b855cbef9c585702401ac5ae29rbb }
61fd0cab072a05b855cbef9c585702401ac5ae29rbb for (i = 0; i < env_arr->nelts; ++i) {
61fd0cab072a05b855cbef9c585702401ac5ae29rbb if (!elts[i].key) {
7bdef86e15d47d16dcbe7a5611683191774bd5fbgstein continue;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb }
7bdef86e15d47d16dcbe7a5611683191774bd5fbgstein env[j] = apr_pstrcat(p, elts[i].key, "=", elts[i].val, NULL);
7bdef86e15d47d16dcbe7a5611683191774bd5fbgstein whack = env[j];
61fd0cab072a05b855cbef9c585702401ac5ae29rbb if (apr_isdigit(*whack)) {
61fd0cab072a05b855cbef9c585702401ac5ae29rbb *whack++ = '_';
61fd0cab072a05b855cbef9c585702401ac5ae29rbb }
61fd0cab072a05b855cbef9c585702401ac5ae29rbb while (*whack != '=') {
61fd0cab072a05b855cbef9c585702401ac5ae29rbb if (!apr_isalnum(*whack) && *whack != '_') {
61fd0cab072a05b855cbef9c585702401ac5ae29rbb *whack = '_';
3d96ee83babeec32482c9082c9426340cee8c44dwrowe }
7bdef86e15d47d16dcbe7a5611683191774bd5fbgstein ++whack;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb }
61fd0cab072a05b855cbef9c585702401ac5ae29rbb ++j;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb }
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb env[j] = NULL;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb return env;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb}
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
3d96ee83babeec32482c9082c9426340cee8c44dwroweAP_DECLARE(void) ap_add_common_vars(request_rec *r)
7bdef86e15d47d16dcbe7a5611683191774bd5fbgstein{
c9a95767fbf0f5fb0976a06b97a256033925e433rbb apr_table_t *e;
c9a95767fbf0f5fb0976a06b97a256033925e433rbb server_rec *s = r->server;
c9a95767fbf0f5fb0976a06b97a256033925e433rbb conn_rec *c = r->connection;
c9a95767fbf0f5fb0976a06b97a256033925e433rbb const char *rem_logname;
c9a95767fbf0f5fb0976a06b97a256033925e433rbb char *env_path;
c9a95767fbf0f5fb0976a06b97a256033925e433rbb#if defined(WIN32) || defined(OS2)
c9a95767fbf0f5fb0976a06b97a256033925e433rbb char *env_temp;
c9a95767fbf0f5fb0976a06b97a256033925e433rbb#endif
c9a95767fbf0f5fb0976a06b97a256033925e433rbb const char *host;
c9a95767fbf0f5fb0976a06b97a256033925e433rbb apr_array_header_t *hdrs_arr = apr_table_elts(r->headers_in);
c9a95767fbf0f5fb0976a06b97a256033925e433rbb apr_table_entry_t *hdrs = (apr_table_entry_t *) hdrs_arr->elts;
c9a95767fbf0f5fb0976a06b97a256033925e433rbb int i;
c9a95767fbf0f5fb0976a06b97a256033925e433rbb apr_port_t rport;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb apr_sockaddr_t *remotesa;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb /* use a temporary apr_table_t which we'll overlap onto
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * r->subprocess_env later
61fd0cab072a05b855cbef9c585702401ac5ae29rbb */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb e = apr_table_make(r->pool, 25 + hdrs_arr->nelts);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb /* First, add environment vars from headers... this is as per
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * CGI specs, though other sorts of scripting interfaces see
3d96ee83babeec32482c9082c9426340cee8c44dwrowe * the same vars...
7bdef86e15d47d16dcbe7a5611683191774bd5fbgstein */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb for (i = 0; i < hdrs_arr->nelts; ++i) {
61fd0cab072a05b855cbef9c585702401ac5ae29rbb if (!hdrs[i].key) {
61fd0cab072a05b855cbef9c585702401ac5ae29rbb continue;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb }
3d96ee83babeec32482c9082c9426340cee8c44dwrowe
7bdef86e15d47d16dcbe7a5611683191774bd5fbgstein /* A few headers are special cased --- Authorization to prevent
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * rogue scripts from capturing passwords; content-type and -length
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * for no particular reason.
61fd0cab072a05b855cbef9c585702401ac5ae29rbb */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb if (!strcasecmp(hdrs[i].key, "Content-type")) {
3d96ee83babeec32482c9082c9426340cee8c44dwrowe apr_table_addn(e, "CONTENT_TYPE", hdrs[i].val);
7bdef86e15d47d16dcbe7a5611683191774bd5fbgstein }
61fd0cab072a05b855cbef9c585702401ac5ae29rbb else if (!strcasecmp(hdrs[i].key, "Content-length")) {
61fd0cab072a05b855cbef9c585702401ac5ae29rbb apr_table_addn(e, "CONTENT_LENGTH", hdrs[i].val);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb }
61fd0cab072a05b855cbef9c585702401ac5ae29rbb /*
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * You really don't want to disable this check, since it leaves you
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * wide open to CGIs stealing passwords and people viewing them
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * in the environment with "ps -e". But, if you must...
61fd0cab072a05b855cbef9c585702401ac5ae29rbb */
3d96ee83babeec32482c9082c9426340cee8c44dwrowe#ifndef SECURITY_HOLE_PASS_AUTHORIZATION
2d2eda71267231c2526be701fe655db125852c1ffielding else if (!strcasecmp(hdrs[i].key, "Authorization")
2d2eda71267231c2526be701fe655db125852c1ffielding || !strcasecmp(hdrs[i].key, "Proxy-Authorization")) {
2d2eda71267231c2526be701fe655db125852c1ffielding continue;
2d2eda71267231c2526be701fe655db125852c1ffielding }
2d2eda71267231c2526be701fe655db125852c1ffielding#endif
2d2eda71267231c2526be701fe655db125852c1ffielding else {
2d2eda71267231c2526be701fe655db125852c1ffielding apr_table_addn(e, http2env(r->pool, hdrs[i].key), hdrs[i].val);
2d2eda71267231c2526be701fe655db125852c1ffielding }
2d2eda71267231c2526be701fe655db125852c1ffielding }
2d2eda71267231c2526be701fe655db125852c1ffielding
2d2eda71267231c2526be701fe655db125852c1ffielding if (!(env_path = getenv("PATH"))) {
2d2eda71267231c2526be701fe655db125852c1ffielding env_path = DEFAULT_PATH;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb }
61fd0cab072a05b855cbef9c585702401ac5ae29rbb apr_table_addn(e, "PATH", apr_pstrdup(r->pool, env_path));
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb#ifdef WIN32
61fd0cab072a05b855cbef9c585702401ac5ae29rbb if (env_temp = getenv("SystemRoot")) {
61fd0cab072a05b855cbef9c585702401ac5ae29rbb apr_table_addn(e, "SystemRoot", env_temp);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb }
61fd0cab072a05b855cbef9c585702401ac5ae29rbb if (env_temp = getenv("COMSPEC")) {
61fd0cab072a05b855cbef9c585702401ac5ae29rbb apr_table_addn(e, "COMSPEC", env_temp);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb }
3d96ee83babeec32482c9082c9426340cee8c44dwrowe if (env_temp = getenv("WINDIR")) {
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm apr_table_addn(e, "WINDIR", env_temp);
7bdef86e15d47d16dcbe7a5611683191774bd5fbgstein }
23ff73a56371e21f16744cb94d06399b877829f1rbb#endif
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb#ifdef OS2
61fd0cab072a05b855cbef9c585702401ac5ae29rbb if ((env_temp = getenv("COMSPEC")) != NULL) {
61fd0cab072a05b855cbef9c585702401ac5ae29rbb apr_table_addn(e, "COMSPEC", env_temp);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb }
61fd0cab072a05b855cbef9c585702401ac5ae29rbb if ((env_temp = getenv("ETC")) != NULL) {
61fd0cab072a05b855cbef9c585702401ac5ae29rbb apr_table_addn(e, "ETC", env_temp);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb }
61fd0cab072a05b855cbef9c585702401ac5ae29rbb if ((env_temp = getenv("DPATH")) != NULL) {
3d96ee83babeec32482c9082c9426340cee8c44dwrowe apr_table_addn(e, "DPATH", env_temp);
2d2eda71267231c2526be701fe655db125852c1ffielding }
23ff73a56371e21f16744cb94d06399b877829f1rbb if ((env_temp = getenv("PERLLIB_PREFIX")) != NULL) {
2d2eda71267231c2526be701fe655db125852c1ffielding apr_table_addn(e, "PERLLIB_PREFIX", env_temp);
62db15de4c1f335a64d45821796ae197cff94ef8rbb }
62db15de4c1f335a64d45821796ae197cff94ef8rbb#endif
62db15de4c1f335a64d45821796ae197cff94ef8rbb
62db15de4c1f335a64d45821796ae197cff94ef8rbb apr_table_addn(e, "SERVER_SIGNATURE", ap_psignature("", r));
62db15de4c1f335a64d45821796ae197cff94ef8rbb apr_table_addn(e, "SERVER_SOFTWARE", ap_get_server_version());
62db15de4c1f335a64d45821796ae197cff94ef8rbb apr_table_addn(e, "SERVER_NAME", ap_get_server_name(r));
62db15de4c1f335a64d45821796ae197cff94ef8rbb apr_table_addn(e, "SERVER_ADDR", r->connection->local_ip); /* Apache */
62db15de4c1f335a64d45821796ae197cff94ef8rbb apr_table_addn(e, "SERVER_PORT",
62db15de4c1f335a64d45821796ae197cff94ef8rbb apr_psprintf(r->pool, "%u", ap_get_server_port(r)));
48d2edbfb84e5559b5da0f8d614ccab805cc67a8rbb host = ap_get_remote_host(c, r->per_dir_config, REMOTE_HOST, NULL);
62db15de4c1f335a64d45821796ae197cff94ef8rbb if (host) {
62db15de4c1f335a64d45821796ae197cff94ef8rbb apr_table_addn(e, "REMOTE_HOST", host);
62db15de4c1f335a64d45821796ae197cff94ef8rbb }
62db15de4c1f335a64d45821796ae197cff94ef8rbb apr_table_addn(e, "REMOTE_ADDR", c->remote_ip);
62db15de4c1f335a64d45821796ae197cff94ef8rbb apr_table_addn(e, "DOCUMENT_ROOT", ap_document_root(r)); /* Apache */
62db15de4c1f335a64d45821796ae197cff94ef8rbb apr_table_addn(e, "SERVER_ADMIN", s->server_admin); /* Apache */
62db15de4c1f335a64d45821796ae197cff94ef8rbb apr_table_addn(e, "SCRIPT_FILENAME", r->filename); /* Apache */
62db15de4c1f335a64d45821796ae197cff94ef8rbb
62db15de4c1f335a64d45821796ae197cff94ef8rbb apr_socket_addr_get(&remotesa, APR_REMOTE, c->client_socket);
62db15de4c1f335a64d45821796ae197cff94ef8rbb apr_sockaddr_port_get(&rport, remotesa);
62db15de4c1f335a64d45821796ae197cff94ef8rbb apr_table_addn(e, "REMOTE_PORT", apr_psprintf(r->pool, "%d", rport));
62db15de4c1f335a64d45821796ae197cff94ef8rbb
48d2edbfb84e5559b5da0f8d614ccab805cc67a8rbb if (r->user) {
48d2edbfb84e5559b5da0f8d614ccab805cc67a8rbb apr_table_addn(e, "REMOTE_USER", r->user);
62db15de4c1f335a64d45821796ae197cff94ef8rbb }
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar if (r->ap_auth_type) {
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar apr_table_addn(e, "AUTH_TYPE", r->ap_auth_type);
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar }
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar rem_logname = ap_get_remote_logname(r);
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar if (rem_logname) {
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar apr_table_addn(e, "REMOTE_IDENT", apr_pstrdup(r->pool, rem_logname));
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar }
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar /* Apache custom error responses. If we have redirected set two new vars */
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar
3d96ee83babeec32482c9082c9426340cee8c44dwrowe if (r->prev) {
3d96ee83babeec32482c9082c9426340cee8c44dwrowe if (r->prev->args) {
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar apr_table_addn(e, "REDIRECT_QUERY_STRING", r->prev->args);
3d96ee83babeec32482c9082c9426340cee8c44dwrowe }
a19698aebe10b9d41574e4a73794ba7d4cecd78btrawick if (r->prev->uri) {
a19698aebe10b9d41574e4a73794ba7d4cecd78btrawick apr_table_addn(e, "REDIRECT_URL", r->prev->uri);
a19698aebe10b9d41574e4a73794ba7d4cecd78btrawick }
3d96ee83babeec32482c9082c9426340cee8c44dwrowe }
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar apr_table_overlap(r->subprocess_env, e, APR_OVERLAP_TABLES_SET);
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar}
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar/* This "cute" little function comes about because the path info on
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar * filenames and URLs aren't always the same. So we take the two,
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar * and find as much of the two that match as possible.
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar */
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coarAP_DECLARE(int) ap_find_path_info(const char *uri, const char *path_info)
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar{
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar int lu = strlen(uri);
3d96ee83babeec32482c9082c9426340cee8c44dwrowe int lp = strlen(path_info);
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar while (lu-- && lp-- && uri[lu] == path_info[lp]);
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar if (lu == -1) {
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar lu = 0;
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar }
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar while (uri[lu] != '\0' && uri[lu] != '/') {
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar lu++;
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar }
3d96ee83babeec32482c9082c9426340cee8c44dwrowe return lu;
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar}
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coarAP_DECLARE(void) ap_add_cgi_vars(request_rec *r)
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar{
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar apr_table_t *e = r->subprocess_env;
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar apr_table_setn(e, "GATEWAY_INTERFACE", "CGI/1.1");
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar apr_table_setn(e, "SERVER_PROTOCOL", r->protocol);
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar apr_table_setn(e, "REQUEST_METHOD", r->method);
3d96ee83babeec32482c9082c9426340cee8c44dwrowe apr_table_setn(e, "QUERY_STRING", r->args ? r->args : "");
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar apr_table_setn(e, "REQUEST_URI", r->unparsed_uri);
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar /* Note that the code below special-cases scripts run from includes,
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar * because it "knows" that the sub_request has been hacked to have the
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar * args and path_info of the original request, and not any that may have
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar * come with the script URI in the include command. Ugh.
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar */
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar if (!strcmp(r->protocol, "INCLUDED")) {
3d96ee83babeec32482c9082c9426340cee8c44dwrowe apr_table_setn(e, "SCRIPT_NAME", r->uri);
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar if (r->path_info && *r->path_info) {
2864362ca8266097928e84f101010bdf814ffa08stoddard apr_table_setn(e, "PATH_INFO", r->path_info);
db08da9ddcd65c31f9ea44b823898b72a1b24fbestoddard }
db08da9ddcd65c31f9ea44b823898b72a1b24fbestoddard }
db08da9ddcd65c31f9ea44b823898b72a1b24fbestoddard else if (!r->path_info || !*r->path_info) {
db08da9ddcd65c31f9ea44b823898b72a1b24fbestoddard apr_table_setn(e, "SCRIPT_NAME", r->uri);
db08da9ddcd65c31f9ea44b823898b72a1b24fbestoddard }
db08da9ddcd65c31f9ea44b823898b72a1b24fbestoddard else {
db08da9ddcd65c31f9ea44b823898b72a1b24fbestoddard int path_info_start = ap_find_path_info(r->uri, r->path_info);
2864362ca8266097928e84f101010bdf814ffa08stoddard
db08da9ddcd65c31f9ea44b823898b72a1b24fbestoddard apr_table_setn(e, "SCRIPT_NAME",
2864362ca8266097928e84f101010bdf814ffa08stoddard apr_pstrndup(r->pool, r->uri, path_info_start));
2d2eda71267231c2526be701fe655db125852c1ffielding
2d2eda71267231c2526be701fe655db125852c1ffielding apr_table_setn(e, "PATH_INFO", r->path_info);
2d2eda71267231c2526be701fe655db125852c1ffielding }
2d2eda71267231c2526be701fe655db125852c1ffielding
61fd0cab072a05b855cbef9c585702401ac5ae29rbb if (r->path_info && r->path_info[0]) {
61fd0cab072a05b855cbef9c585702401ac5ae29rbb /*
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * To get PATH_TRANSLATED, treat PATH_INFO as a URI path.
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * Need to re-escape it for this, since the entire URI was
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * un-escaped before we determined where the PATH_INFO began.
61fd0cab072a05b855cbef9c585702401ac5ae29rbb */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb request_rec *pa_req;
3d96ee83babeec32482c9082c9426340cee8c44dwrowe
a6b9ed64fdf548c61de9714e2cfb999ec59d149cgstein pa_req = ap_sub_req_lookup_uri(ap_escape_uri(r->pool, r->path_info), r,
61fd0cab072a05b855cbef9c585702401ac5ae29rbb NULL);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb if (pa_req->filename) {
61fd0cab072a05b855cbef9c585702401ac5ae29rbb#ifdef WIN32
61fd0cab072a05b855cbef9c585702401ac5ae29rbb char buffer[HUGE_STRING_LEN];
61fd0cab072a05b855cbef9c585702401ac5ae29rbb#endif
61fd0cab072a05b855cbef9c585702401ac5ae29rbb char *pt = apr_pstrcat(r->pool, pa_req->filename, pa_req->path_info,
3d96ee83babeec32482c9082c9426340cee8c44dwrowe NULL);
a6b9ed64fdf548c61de9714e2cfb999ec59d149cgstein#ifdef WIN32
61fd0cab072a05b855cbef9c585702401ac5ae29rbb /* We need to make this a real Windows path name */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb GetFullPathName(pt, HUGE_STRING_LEN, buffer, NULL);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb apr_table_setn(e, "PATH_TRANSLATED", apr_pstrdup(r->pool, buffer));
61fd0cab072a05b855cbef9c585702401ac5ae29rbb#else
61fd0cab072a05b855cbef9c585702401ac5ae29rbb apr_table_setn(e, "PATH_TRANSLATED", pt);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb#endif
61fd0cab072a05b855cbef9c585702401ac5ae29rbb }
61fd0cab072a05b855cbef9c585702401ac5ae29rbb ap_destroy_sub_req(pa_req);
3d96ee83babeec32482c9082c9426340cee8c44dwrowe }
a6b9ed64fdf548c61de9714e2cfb999ec59d149cgstein}
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbbstatic int set_cookie_doo_doo(void *v, const char *key, const char *val)
61fd0cab072a05b855cbef9c585702401ac5ae29rbb{
61fd0cab072a05b855cbef9c585702401ac5ae29rbb apr_table_addn(v, key, val);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb return 1;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb}
3d96ee83babeec32482c9082c9426340cee8c44dwrowe
a6b9ed64fdf548c61de9714e2cfb999ec59d149cgsteinAP_DECLARE(int) ap_scan_script_header_err_core(request_rec *r, char *buffer,
61fd0cab072a05b855cbef9c585702401ac5ae29rbb int (*getsfunc) (char *, int, void *),
61fd0cab072a05b855cbef9c585702401ac5ae29rbb void *getsfunc_data)
61fd0cab072a05b855cbef9c585702401ac5ae29rbb{
61fd0cab072a05b855cbef9c585702401ac5ae29rbb char x[MAX_STRING_LEN];
61fd0cab072a05b855cbef9c585702401ac5ae29rbb char *w, *l;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb int p;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb int cgi_status = HTTP_OK;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb apr_table_t *merge;
3d96ee83babeec32482c9082c9426340cee8c44dwrowe apr_table_t *cookie_table;
a6b9ed64fdf548c61de9714e2cfb999ec59d149cgstein
61fd0cab072a05b855cbef9c585702401ac5ae29rbb if (buffer) {
61fd0cab072a05b855cbef9c585702401ac5ae29rbb *buffer = '\0';
61fd0cab072a05b855cbef9c585702401ac5ae29rbb }
61fd0cab072a05b855cbef9c585702401ac5ae29rbb w = buffer ? buffer : x;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb /* temporary place to hold headers to merge in later */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb merge = apr_table_make(r->pool, 10);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
3d96ee83babeec32482c9082c9426340cee8c44dwrowe /* The HTTP specification says that it is legal to merge duplicate
2d2eda71267231c2526be701fe655db125852c1ffielding * headers into one. Some browsers that support Cookies don't like
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * merged headers and prefer that each Set-Cookie header is sent
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * separately. Lets humour those browsers by not merging.
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * Oh what a pain it is.
61fd0cab072a05b855cbef9c585702401ac5ae29rbb */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb cookie_table = apr_table_make(r->pool, 2);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb apr_table_do(set_cookie_doo_doo, cookie_table, r->err_headers_out, "Set-Cookie", NULL);
3d96ee83babeec32482c9082c9426340cee8c44dwrowe
2d2eda71267231c2526be701fe655db125852c1ffielding while (1) {
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
2d2eda71267231c2526be701fe655db125852c1ffielding if ((*getsfunc) (w, MAX_STRING_LEN - 1, getsfunc_data) == 0) {
2d2eda71267231c2526be701fe655db125852c1ffielding ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
61fd0cab072a05b855cbef9c585702401ac5ae29rbb "Premature end of script headers: %s", r->filename);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb return HTTP_INTERNAL_SERVER_ERROR;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb }
2d2eda71267231c2526be701fe655db125852c1ffielding
3d96ee83babeec32482c9082c9426340cee8c44dwrowe /* Delete terminal (CR?)LF */
2d2eda71267231c2526be701fe655db125852c1ffielding
61fd0cab072a05b855cbef9c585702401ac5ae29rbb p = strlen(w);
d839a9822ee53ce00da24c15f2d9fe054233d342gstein /* Indeed, the host's '\n':
d839a9822ee53ce00da24c15f2d9fe054233d342gstein '\012' for UNIX; '\015' for MacOS; '\025' for OS/390
d839a9822ee53ce00da24c15f2d9fe054233d342gstein -- whatever the script generates.
61fd0cab072a05b855cbef9c585702401ac5ae29rbb */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb if (p > 0 && w[p - 1] == '\n') {
61fd0cab072a05b855cbef9c585702401ac5ae29rbb if (p > 1 && w[p - 2] == CR) {
d839a9822ee53ce00da24c15f2d9fe054233d342gstein w[p - 2] = '\0';
3d96ee83babeec32482c9082c9426340cee8c44dwrowe }
d839a9822ee53ce00da24c15f2d9fe054233d342gstein else {
2d2eda71267231c2526be701fe655db125852c1ffielding w[p - 1] = '\0';
2d2eda71267231c2526be701fe655db125852c1ffielding }
61fd0cab072a05b855cbef9c585702401ac5ae29rbb }
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb /*
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * If we've finished reading the headers, check to make sure any
346029f34d03eb20d84fc35664426d3874b00f9ewrowe * HTTP/1.1 conditions are met. If so, we're done; normal processing
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * will handle the script's output. If not, just return the error.
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * The appropriate thing to do would be to send the script process a
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * SIGPIPE to let it know we're ignoring it, close the channel to the
346029f34d03eb20d84fc35664426d3874b00f9ewrowe * script process, and *then* return the failed-to-meet-condition
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * error. Otherwise we'd be waiting for the script to finish
eda25307d712abd132e100e2b40ae1de5497d3e2trawick * blithering before telling the client the output was no good.
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * However, we don't have the information to do that, so we have to
3d96ee83babeec32482c9082c9426340cee8c44dwrowe * leave it to an upper layer.
a6b9ed64fdf548c61de9714e2cfb999ec59d149cgstein */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb if (w[0] == '\0') {
61fd0cab072a05b855cbef9c585702401ac5ae29rbb int cond_status = OK;
face099b681c052cb1f52176a5499661c44b2982trawick
61fd0cab072a05b855cbef9c585702401ac5ae29rbb if ((cgi_status == HTTP_OK) && (r->method_number == M_GET)) {
61fd0cab072a05b855cbef9c585702401ac5ae29rbb cond_status = ap_meets_conditions(r);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb }
61fd0cab072a05b855cbef9c585702401ac5ae29rbb apr_table_overlap(r->err_headers_out, merge,
61fd0cab072a05b855cbef9c585702401ac5ae29rbb APR_OVERLAP_TABLES_MERGE);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb if (!apr_is_empty_table(cookie_table)) {
3d96ee83babeec32482c9082c9426340cee8c44dwrowe /* the cookies have already been copied to the cookie_table */
a6b9ed64fdf548c61de9714e2cfb999ec59d149cgstein apr_table_unset(r->err_headers_out, "Set-Cookie");
61fd0cab072a05b855cbef9c585702401ac5ae29rbb r->err_headers_out = apr_table_overlay(r->pool,
61fd0cab072a05b855cbef9c585702401ac5ae29rbb r->err_headers_out, cookie_table);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb }
61fd0cab072a05b855cbef9c585702401ac5ae29rbb return cond_status;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb }
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb /* if we see a bogus header don't ignore it. Shout and scream */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
11a7b0dff22d26770b532c174d1cf2e7b56ec244wrowe#if APR_CHARSET_EBCDIC
61fd0cab072a05b855cbef9c585702401ac5ae29rbb /* Chances are that we received an ASCII header text instead of
11a7b0dff22d26770b532c174d1cf2e7b56ec244wrowe * the expected EBCDIC header lines. Try to auto-detect:
a6b9ed64fdf548c61de9714e2cfb999ec59d149cgstein */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb if (!(l = strchr(w, ':'))) {
61fd0cab072a05b855cbef9c585702401ac5ae29rbb int maybeASCII = 0, maybeEBCDIC = 0;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb unsigned char *cp, native;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb apr_size_t inbytes_left, outbytes_left;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb for (cp = w; *cp != '\0'; ++cp) {
61fd0cab072a05b855cbef9c585702401ac5ae29rbb native = apr_xlate_conv_byte(ap_hdrs_from_ascii, *cp);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb if (isprint(*cp) && !isprint(native))
61fd0cab072a05b855cbef9c585702401ac5ae29rbb ++maybeEBCDIC;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb if (!isprint(*cp) && isprint(native))
61fd0cab072a05b855cbef9c585702401ac5ae29rbb ++maybeASCII;
3d96ee83babeec32482c9082c9426340cee8c44dwrowe }
2d2eda71267231c2526be701fe655db125852c1ffielding if (maybeASCII > maybeEBCDIC) {
a6b9ed64fdf548c61de9714e2cfb999ec59d149cgstein ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r->server,
61fd0cab072a05b855cbef9c585702401ac5ae29rbb "CGI Interface Error: Script headers apparently ASCII: (CGI = %s)",
61fd0cab072a05b855cbef9c585702401ac5ae29rbb r->filename);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb inbytes_left = outbytes_left = cp - w;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb apr_xlate_conv_buffer(ap_hdrs_from_ascii,
61fd0cab072a05b855cbef9c585702401ac5ae29rbb w, &inbytes_left, w, &outbytes_left);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb }
61fd0cab072a05b855cbef9c585702401ac5ae29rbb }
3d96ee83babeec32482c9082c9426340cee8c44dwrowe#endif /*APR_CHARSET_EBCDIC*/
a6b9ed64fdf548c61de9714e2cfb999ec59d149cgstein if (!(l = strchr(w, ':'))) {
61fd0cab072a05b855cbef9c585702401ac5ae29rbb char malformed[(sizeof MALFORMED_MESSAGE) + 1
61fd0cab072a05b855cbef9c585702401ac5ae29rbb + MALFORMED_HEADER_LENGTH_TO_SHOW];
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb strcpy(malformed, MALFORMED_MESSAGE);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb strncat(malformed, w, MALFORMED_HEADER_LENGTH_TO_SHOW);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb if (!buffer) {
3d96ee83babeec32482c9082c9426340cee8c44dwrowe /* Soak up all the script output - may save an outright kill */
a6b9ed64fdf548c61de9714e2cfb999ec59d149cgstein while ((*getsfunc) (w, MAX_STRING_LEN - 1, getsfunc_data)) {
61fd0cab072a05b855cbef9c585702401ac5ae29rbb continue;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb }
61fd0cab072a05b855cbef9c585702401ac5ae29rbb }
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
61fd0cab072a05b855cbef9c585702401ac5ae29rbb "%s: %s", malformed, r->filename);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb return HTTP_INTERNAL_SERVER_ERROR;
3d96ee83babeec32482c9082c9426340cee8c44dwrowe }
a6b9ed64fdf548c61de9714e2cfb999ec59d149cgstein
61fd0cab072a05b855cbef9c585702401ac5ae29rbb *l++ = '\0';
61fd0cab072a05b855cbef9c585702401ac5ae29rbb while (*l && apr_isspace(*l)) {
61fd0cab072a05b855cbef9c585702401ac5ae29rbb ++l;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb }
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb if (!strcasecmp(w, "Content-type")) {
61fd0cab072a05b855cbef9c585702401ac5ae29rbb char *tmp;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb /* Nuke trailing whitespace */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb char *endp = l + strlen(l) - 1;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb while (endp > l && apr_isspace(*endp)) {
61fd0cab072a05b855cbef9c585702401ac5ae29rbb *endp-- = '\0';
3d96ee83babeec32482c9082c9426340cee8c44dwrowe }
2d2eda71267231c2526be701fe655db125852c1ffielding
61fd0cab072a05b855cbef9c585702401ac5ae29rbb tmp = apr_pstrdup(r->pool, l);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb ap_content_type_tolower(tmp);
346029f34d03eb20d84fc35664426d3874b00f9ewrowe r->content_type = tmp;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb }
61fd0cab072a05b855cbef9c585702401ac5ae29rbb /*
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * If the script returned a specific status, that's what
346029f34d03eb20d84fc35664426d3874b00f9ewrowe * we'll use - otherwise we assume 200 OK.
61fd0cab072a05b855cbef9c585702401ac5ae29rbb */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb else if (!strcasecmp(w, "Status")) {
61fd0cab072a05b855cbef9c585702401ac5ae29rbb r->status = cgi_status = atoi(l);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb r->status_line = apr_pstrdup(r->pool, l);
3d96ee83babeec32482c9082c9426340cee8c44dwrowe }
2d2eda71267231c2526be701fe655db125852c1ffielding else if (!strcasecmp(w, "Location")) {
fd8b91502bc200ed4cca3810560a2a570522b3debrianp apr_table_set(r->headers_out, w, l);
fd8b91502bc200ed4cca3810560a2a570522b3debrianp }
fd8b91502bc200ed4cca3810560a2a570522b3debrianp else if (!strcasecmp(w, "Content-Length")) {
fd8b91502bc200ed4cca3810560a2a570522b3debrianp apr_table_set(r->headers_out, w, l);
fd8b91502bc200ed4cca3810560a2a570522b3debrianp }
fd8b91502bc200ed4cca3810560a2a570522b3debrianp else if (!strcasecmp(w, "Transfer-Encoding")) {
fd8b91502bc200ed4cca3810560a2a570522b3debrianp apr_table_set(r->headers_out, w, l);
fd8b91502bc200ed4cca3810560a2a570522b3debrianp }
fd8b91502bc200ed4cca3810560a2a570522b3debrianp /*
fd8b91502bc200ed4cca3810560a2a570522b3debrianp * If the script gave us a Last-Modified header, we can't just
fd8b91502bc200ed4cca3810560a2a570522b3debrianp * pass it on blindly because of restrictions on future values.
aa4af3da5c68fe5dbd9d2c3fd7b2fe7103daa2b7dougm */
e351a4349a3dcc2e8d9c27bcdf72414bdde0942frbb else if (!strcasecmp(w, "Last-Modified")) {
fd8b91502bc200ed4cca3810560a2a570522b3debrianp ap_update_mtime(r, apr_date_parse_http(l));
fd8b91502bc200ed4cca3810560a2a570522b3debrianp ap_set_last_modified(r);
4111de96e9f75c58e77c2bdda23be83b8ebf81ccgregames }
4111de96e9f75c58e77c2bdda23be83b8ebf81ccgregames else if (!strcasecmp(w, "Set-Cookie")) {
4111de96e9f75c58e77c2bdda23be83b8ebf81ccgregames apr_table_add(cookie_table, w, l);
4111de96e9f75c58e77c2bdda23be83b8ebf81ccgregames }
4111de96e9f75c58e77c2bdda23be83b8ebf81ccgregames else {
4111de96e9f75c58e77c2bdda23be83b8ebf81ccgregames apr_table_add(merge, w, l);
4111de96e9f75c58e77c2bdda23be83b8ebf81ccgregames }
4111de96e9f75c58e77c2bdda23be83b8ebf81ccgregames }
fd8b91502bc200ed4cca3810560a2a570522b3debrianp
fd8b91502bc200ed4cca3810560a2a570522b3debrianp return OK;
fd8b91502bc200ed4cca3810560a2a570522b3debrianp}
fd8b91502bc200ed4cca3810560a2a570522b3debrianp
45613d36b9466a48def0498cffa07f48980720f8jerenkrantzstatic int getsfunc_FILE(char *buf, int len, void *f)
fd8b91502bc200ed4cca3810560a2a570522b3debrianp{
fd8b91502bc200ed4cca3810560a2a570522b3debrianp return apr_file_gets(buf, len, (apr_file_t *) f) == APR_SUCCESS;
45613d36b9466a48def0498cffa07f48980720f8jerenkrantz}
45613d36b9466a48def0498cffa07f48980720f8jerenkrantz
45613d36b9466a48def0498cffa07f48980720f8jerenkrantzAP_DECLARE(int) ap_scan_script_header_err(request_rec *r, apr_file_t *f,
fd8b91502bc200ed4cca3810560a2a570522b3debrianp char *buffer)
4111de96e9f75c58e77c2bdda23be83b8ebf81ccgregames{
4111de96e9f75c58e77c2bdda23be83b8ebf81ccgregames return ap_scan_script_header_err_core(r, buffer, getsfunc_FILE, f);
4111de96e9f75c58e77c2bdda23be83b8ebf81ccgregames}
45613d36b9466a48def0498cffa07f48980720f8jerenkrantz
4111de96e9f75c58e77c2bdda23be83b8ebf81ccgregamesstruct vastrs {
4111de96e9f75c58e77c2bdda23be83b8ebf81ccgregames va_list args;
4111de96e9f75c58e77c2bdda23be83b8ebf81ccgregames int arg;
4111de96e9f75c58e77c2bdda23be83b8ebf81ccgregames const char *curpos;
4111de96e9f75c58e77c2bdda23be83b8ebf81ccgregames};
4111de96e9f75c58e77c2bdda23be83b8ebf81ccgregames
4111de96e9f75c58e77c2bdda23be83b8ebf81ccgregamesstatic int getsfunc_STRING(char *w, int len, void *pvastrs)
5a9667916c79d8c699b069068e5570aa1c331c80gstein{
61fd0cab072a05b855cbef9c585702401ac5ae29rbb struct vastrs *strs = (struct vastrs*) pvastrs;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb const char *p;
2d2eda71267231c2526be701fe655db125852c1ffielding int t;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb if (!strs->curpos || !*strs->curpos)
2d2eda71267231c2526be701fe655db125852c1ffielding return 0;
3d96ee83babeec32482c9082c9426340cee8c44dwrowe p = ap_strchr_c(strs->curpos, '\n');
2d2eda71267231c2526be701fe655db125852c1ffielding if (p)
344f3bc38dfccf6261d5bb8d689794cde113b3d6coar ++p;
344f3bc38dfccf6261d5bb8d689794cde113b3d6coar else
344f3bc38dfccf6261d5bb8d689794cde113b3d6coar p = ap_strchr_c(strs->curpos, '\0');
5a9667916c79d8c699b069068e5570aa1c331c80gstein t = p - strs->curpos;
344f3bc38dfccf6261d5bb8d689794cde113b3d6coar if (t > len)
344f3bc38dfccf6261d5bb8d689794cde113b3d6coar t = len;
344f3bc38dfccf6261d5bb8d689794cde113b3d6coar strncpy (w, strs->curpos, t);
5a9667916c79d8c699b069068e5570aa1c331c80gstein w[t] = '\0';
344f3bc38dfccf6261d5bb8d689794cde113b3d6coar if (!strs->curpos[t]) {
d5df46b7972c0c4a5ca0ba5068e238f6053c2e6ftrawick ++strs->arg;
fd0edaa8e3d4dd67d0604ccef2e96b071db96643fielding strs->curpos = va_arg(strs->args, const char *);
fd0edaa8e3d4dd67d0604ccef2e96b071db96643fielding }
fd0edaa8e3d4dd67d0604ccef2e96b071db96643fielding else
fd0edaa8e3d4dd67d0604ccef2e96b071db96643fielding strs->curpos += t;
fd0edaa8e3d4dd67d0604ccef2e96b071db96643fielding return t;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb}
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb/* ap_scan_script_header_err_strs() accepts additional const char* args...
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * each is treated as one or more header lines, and the first non-header
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * character is returned to **arg, **data. (The first optional arg is
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * counted as 0.)
61fd0cab072a05b855cbef9c585702401ac5ae29rbb */
61fd0cab072a05b855cbef9c585702401ac5ae29rbbAP_DECLARE_NONSTD(int) ap_scan_script_header_err_strs(request_rec *r,
42ce672c516baf6e4eaed18ccc1647de2d456d8edougm char *buffer,
a6b9ed64fdf548c61de9714e2cfb999ec59d149cgstein const char **termch,
61fd0cab072a05b855cbef9c585702401ac5ae29rbb int *termarg, ...)
61fd0cab072a05b855cbef9c585702401ac5ae29rbb{
61fd0cab072a05b855cbef9c585702401ac5ae29rbb struct vastrs strs;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb int res;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb va_start(strs.args, termarg);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb strs.arg = 0;
42ce672c516baf6e4eaed18ccc1647de2d456d8edougm strs.curpos = va_arg(strs.args, char*);
a6b9ed64fdf548c61de9714e2cfb999ec59d149cgstein res = ap_scan_script_header_err_core(r, buffer, getsfunc_STRING, (void *) &strs);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb if (termch)
61fd0cab072a05b855cbef9c585702401ac5ae29rbb *termch = strs.curpos;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb if (termarg)
61fd0cab072a05b855cbef9c585702401ac5ae29rbb *termarg = strs.arg;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb va_end(strs.args);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb return res;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb}
42ce672c516baf6e4eaed18ccc1647de2d456d8edougm
a6b9ed64fdf548c61de9714e2cfb999ec59d149cgsteinAP_DECLARE(void) ap_send_size(apr_ssize_t size, request_rec *r)
61fd0cab072a05b855cbef9c585702401ac5ae29rbb{
61fd0cab072a05b855cbef9c585702401ac5ae29rbb /* XXX: this -1 thing is a gross hack */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb if (size == (apr_ssize_t)-1) {
61fd0cab072a05b855cbef9c585702401ac5ae29rbb ap_rputs(" -", r);
dad234382d8424e1c5a30af2838e172aec9d6d1bdreid }
61fd0cab072a05b855cbef9c585702401ac5ae29rbb else if (!size) {
42ce672c516baf6e4eaed18ccc1647de2d456d8edougm ap_rputs(" 0k", r);
fd0edaa8e3d4dd67d0604ccef2e96b071db96643fielding }
fcc25eda7b150e226d3c1cdaea66a943d3fdee4erbb else if (size < 1024) {
a6b9ed64fdf548c61de9714e2cfb999ec59d149cgstein ap_rputs(" 1k", r);
fcc25eda7b150e226d3c1cdaea66a943d3fdee4erbb }
fcc25eda7b150e226d3c1cdaea66a943d3fdee4erbb else if (size < 1048576) {
fcc25eda7b150e226d3c1cdaea66a943d3fdee4erbb ap_rprintf(r, "%4" APR_SSIZE_T_FMT "k", (size + 512) / 1024);
fcc25eda7b150e226d3c1cdaea66a943d3fdee4erbb }
fcc25eda7b150e226d3c1cdaea66a943d3fdee4erbb else if (size < 103809024) {
fcc25eda7b150e226d3c1cdaea66a943d3fdee4erbb ap_rprintf(r, "%4.1fM", size / 1048576.0);
fcc25eda7b150e226d3c1cdaea66a943d3fdee4erbb }
fcc25eda7b150e226d3c1cdaea66a943d3fdee4erbb else {
8b7047e519340545e6807c9749576a40a76b6d3frbb ap_rprintf(r, "%4" APR_SSIZE_T_FMT "M", (size + 524288) / 1048576);
8b7047e519340545e6807c9749576a40a76b6d3frbb }
8b7047e519340545e6807c9749576a40a76b6d3frbb}
6d00a43be9ab145c89e8cc22bad59e3aa746f761jwoolley
fcc25eda7b150e226d3c1cdaea66a943d3fdee4erbb