util_script.c revision 842ae4bd224140319ae7feec1872b93dfd491143
fae04f4a69922eb1ddf0f46b34fa15a5a080b693Felix Gabriel Mance/* Licensed to the Apache Software Foundation (ASF) under one or more
fae04f4a69922eb1ddf0f46b34fa15a5a080b693Felix Gabriel Mance * contributor license agreements. See the NOTICE file distributed with
fae04f4a69922eb1ddf0f46b34fa15a5a080b693Felix Gabriel Mance * this work for additional information regarding copyright ownership.
fae04f4a69922eb1ddf0f46b34fa15a5a080b693Felix Gabriel Mance * The ASF licenses this file to You under the Apache License, Version 2.0
fae04f4a69922eb1ddf0f46b34fa15a5a080b693Felix Gabriel Mance * (the "License"); you may not use this file except in compliance with
fae04f4a69922eb1ddf0f46b34fa15a5a080b693Felix Gabriel Mance * the License. You may obtain a copy of the License at
fae04f4a69922eb1ddf0f46b34fa15a5a080b693Felix Gabriel Mance *
fae04f4a69922eb1ddf0f46b34fa15a5a080b693Felix Gabriel Mance * http://www.apache.org/licenses/LICENSE-2.0
fae04f4a69922eb1ddf0f46b34fa15a5a080b693Felix Gabriel Mance *
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance * Unless required by applicable law or agreed to in writing, software
fae04f4a69922eb1ddf0f46b34fa15a5a080b693Felix Gabriel Mance * distributed under the License is distributed on an "AS IS" BASIS,
fae04f4a69922eb1ddf0f46b34fa15a5a080b693Felix Gabriel Mance * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
fae04f4a69922eb1ddf0f46b34fa15a5a080b693Felix Gabriel Mance * See the License for the specific language governing permissions and
fae04f4a69922eb1ddf0f46b34fa15a5a080b693Felix Gabriel Mance * limitations under the License.
fae04f4a69922eb1ddf0f46b34fa15a5a080b693Felix Gabriel Mance */
fae04f4a69922eb1ddf0f46b34fa15a5a080b693Felix Gabriel Mance
fae04f4a69922eb1ddf0f46b34fa15a5a080b693Felix Gabriel Mance#include "apr.h"
fae04f4a69922eb1ddf0f46b34fa15a5a080b693Felix Gabriel Mance#include "apr_lib.h"
fae04f4a69922eb1ddf0f46b34fa15a5a080b693Felix Gabriel Mance#include "apr_strings.h"
fae04f4a69922eb1ddf0f46b34fa15a5a080b693Felix Gabriel Mance
fae04f4a69922eb1ddf0f46b34fa15a5a080b693Felix Gabriel Mance#define APR_WANT_STRFUNC
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance#include "apr_want.h"
ae2e84ab0a53874417f01b792cbc6907ee6d09f6Felix Gabriel Mance
ae2e84ab0a53874417f01b792cbc6907ee6d09f6Felix Gabriel Mance#if APR_HAVE_STDLIB_H
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance#include <stdlib.h>
ae2e84ab0a53874417f01b792cbc6907ee6d09f6Felix Gabriel Mance#endif
808e2693447ecc5a311a2b9de6b81ca07f193778Felix Gabriel Mance
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance#define CORE_PRIVATE
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance#include "ap_config.h"
ae2e84ab0a53874417f01b792cbc6907ee6d09f6Felix Gabriel Mance#include "httpd.h"
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance#include "http_config.h"
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance#include "http_main.h"
ae2e84ab0a53874417f01b792cbc6907ee6d09f6Felix Gabriel Mance#include "http_log.h"
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance#include "http_core.h"
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance#include "http_protocol.h"
ae2e84ab0a53874417f01b792cbc6907ee6d09f6Felix Gabriel Mance#include "http_request.h" /* for sub_req_lookup_uri() */
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance#include "util_script.h"
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance#include "apr_date.h" /* For apr_date_parse_http() */
ae2e84ab0a53874417f01b792cbc6907ee6d09f6Felix Gabriel Mance#include "util_ebcdic.h"
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance#ifdef OS2
ae2e84ab0a53874417f01b792cbc6907ee6d09f6Felix Gabriel Mance#define INCL_DOS
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance#include <os2.h>
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance#endif
ae2e84ab0a53874417f01b792cbc6907ee6d09f6Felix Gabriel Mance
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance/*
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance * Various utility functions which are common to a whole lot of
ae2e84ab0a53874417f01b792cbc6907ee6d09f6Felix Gabriel Mance * script-type extensions mechanisms, and might as well be gathered
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance * in one place (if only to avoid creating inter-module dependancies
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance * where there don't have to be).
ae2e84ab0a53874417f01b792cbc6907ee6d09f6Felix Gabriel Mance */
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance#define MALFORMED_MESSAGE "malformed header from script. Bad header="
ae2e84ab0a53874417f01b792cbc6907ee6d09f6Felix Gabriel Mance#define MALFORMED_HEADER_LENGTH_TO_SHOW 30
45e34c7696f9dd6163686ff6798b33a126590fa2Felix Gabriel Mance
45e34c7696f9dd6163686ff6798b33a126590fa2Felix Gabriel Mancestatic char *http2env(apr_pool_t *a, const char *w)
45e34c7696f9dd6163686ff6798b33a126590fa2Felix Gabriel Mance{
45e34c7696f9dd6163686ff6798b33a126590fa2Felix Gabriel Mance char *res = (char *)apr_palloc(a, sizeof("HTTP_") + strlen(w));
45e34c7696f9dd6163686ff6798b33a126590fa2Felix Gabriel Mance char *cp = res;
45e34c7696f9dd6163686ff6798b33a126590fa2Felix Gabriel Mance char c;
45e34c7696f9dd6163686ff6798b33a126590fa2Felix Gabriel Mance
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance *cp++ = 'H';
ae2e84ab0a53874417f01b792cbc6907ee6d09f6Felix Gabriel Mance *cp++ = 'T';
ae2e84ab0a53874417f01b792cbc6907ee6d09f6Felix Gabriel Mance *cp++ = 'T';
ae2e84ab0a53874417f01b792cbc6907ee6d09f6Felix Gabriel Mance *cp++ = 'P';
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance *cp++ = '_';
ae2e84ab0a53874417f01b792cbc6907ee6d09f6Felix Gabriel Mance
808e2693447ecc5a311a2b9de6b81ca07f193778Felix Gabriel Mance while ((c = *w++) != 0) {
a57de3f6b0a0c904523910869eedc7428e5e17a3Felix Gabriel Mance if (!apr_isalnum(c)) {
a57de3f6b0a0c904523910869eedc7428e5e17a3Felix Gabriel Mance *cp++ = '_';
a57de3f6b0a0c904523910869eedc7428e5e17a3Felix Gabriel Mance }
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance else {
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance *cp++ = apr_toupper(c);
808e2693447ecc5a311a2b9de6b81ca07f193778Felix Gabriel Mance }
a57de3f6b0a0c904523910869eedc7428e5e17a3Felix Gabriel Mance }
fc05327b875b5723b6c17849b83477f29ec12c90Felix Gabriel Mance *cp = 0;
4440f5c4ab1cb6dfd445da97f87a72d87d24c25aFelix Gabriel Mance
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance return res;
fc05327b875b5723b6c17849b83477f29ec12c90Felix Gabriel Mance}
808e2693447ecc5a311a2b9de6b81ca07f193778Felix Gabriel Mance
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel ManceAP_DECLARE(char **) ap_create_environment(apr_pool_t *p, apr_table_t *t)
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance{
c92573b85930868b709024284c0f13dbcaec9554Felix Gabriel Mance const apr_array_header_t *env_arr = apr_table_elts(t);
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance const apr_table_entry_t *elts = (const apr_table_entry_t *) env_arr->elts;
c92573b85930868b709024284c0f13dbcaec9554Felix Gabriel Mance char **env = (char **) apr_palloc(p, (env_arr->nelts + 2) * sizeof(char *));
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance int i, j;
ae2e84ab0a53874417f01b792cbc6907ee6d09f6Felix Gabriel Mance char *tz;
ce5d83770556362fe2c8b567975c2a3758888358Felix Gabriel Mance char *whack;
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance
ae2e84ab0a53874417f01b792cbc6907ee6d09f6Felix Gabriel Mance j = 0;
ce5d83770556362fe2c8b567975c2a3758888358Felix Gabriel Mance if (!apr_table_get(t, "TZ")) {
a57de3f6b0a0c904523910869eedc7428e5e17a3Felix Gabriel Mance tz = getenv("TZ");
ce5d83770556362fe2c8b567975c2a3758888358Felix Gabriel Mance if (tz != NULL) {
ce5d83770556362fe2c8b567975c2a3758888358Felix Gabriel Mance env[j++] = apr_pstrcat(p, "TZ=", tz, NULL);
31f536d7b9e901779ab6de28d804f53d5eb4b908Felix Gabriel Mance }
ee87c7423bf599b4f29e9b31945e00482a8b31caFelix Gabriel Mance }
31f536d7b9e901779ab6de28d804f53d5eb4b908Felix Gabriel Mance for (i = 0; i < env_arr->nelts; ++i) {
ce5d83770556362fe2c8b567975c2a3758888358Felix Gabriel Mance if (!elts[i].key) {
ce5d83770556362fe2c8b567975c2a3758888358Felix Gabriel Mance continue;
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance }
ce5d83770556362fe2c8b567975c2a3758888358Felix Gabriel Mance env[j] = apr_pstrcat(p, elts[i].key, "=", elts[i].val, NULL);
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance whack = env[j];
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance if (apr_isdigit(*whack)) {
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance *whack++ = '_';
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance }
31f536d7b9e901779ab6de28d804f53d5eb4b908Felix Gabriel Mance while (*whack != '=') {
ee87c7423bf599b4f29e9b31945e00482a8b31caFelix Gabriel Mance if (!apr_isalnum(*whack) && *whack != '_') {
31f536d7b9e901779ab6de28d804f53d5eb4b908Felix Gabriel Mance *whack = '_';
31f536d7b9e901779ab6de28d804f53d5eb4b908Felix Gabriel Mance }
ce5d83770556362fe2c8b567975c2a3758888358Felix Gabriel Mance ++whack;
ce5d83770556362fe2c8b567975c2a3758888358Felix Gabriel Mance }
ce5d83770556362fe2c8b567975c2a3758888358Felix Gabriel Mance ++j;
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance }
ce5d83770556362fe2c8b567975c2a3758888358Felix Gabriel Mance
ce5d83770556362fe2c8b567975c2a3758888358Felix Gabriel Mance env[j] = NULL;
ce5d83770556362fe2c8b567975c2a3758888358Felix Gabriel Mance return env;
ce5d83770556362fe2c8b567975c2a3758888358Felix Gabriel Mance}
ce5d83770556362fe2c8b567975c2a3758888358Felix Gabriel Mance
ce5d83770556362fe2c8b567975c2a3758888358Felix Gabriel ManceAP_DECLARE(void) ap_add_common_vars(request_rec *r)
ce5d83770556362fe2c8b567975c2a3758888358Felix Gabriel Mance{
ce5d83770556362fe2c8b567975c2a3758888358Felix Gabriel Mance apr_table_t *e;
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance server_rec *s = r->server;
e615997caa046409fc68114cd72e10a528a4bb71Felix Gabriel Mance conn_rec *c = r->connection;
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance const char *rem_logname;
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance char *env_path;
e615997caa046409fc68114cd72e10a528a4bb71Felix Gabriel Mance#if defined(WIN32) || defined(OS2) || defined(BEOS)
31f536d7b9e901779ab6de28d804f53d5eb4b908Felix Gabriel Mance char *env_temp;
ee87c7423bf599b4f29e9b31945e00482a8b31caFelix Gabriel Mance#endif
31f536d7b9e901779ab6de28d804f53d5eb4b908Felix Gabriel Mance const char *host;
31f536d7b9e901779ab6de28d804f53d5eb4b908Felix Gabriel Mance const apr_array_header_t *hdrs_arr = apr_table_elts(r->headers_in);
e615997caa046409fc68114cd72e10a528a4bb71Felix Gabriel Mance const apr_table_entry_t *hdrs = (const apr_table_entry_t *) hdrs_arr->elts;
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance int i;
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance apr_port_t rport;
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance /* use a temporary apr_table_t which we'll overlap onto
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance * r->subprocess_env later
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance * (exception: if r->subprocess_env is empty at the start,
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance * write directly into it)
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance */
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance if (apr_is_empty_table(r->subprocess_env)) {
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance e = r->subprocess_env;
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance }
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance else {
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance e = apr_table_make(r->pool, 25 + hdrs_arr->nelts);
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance }
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance /* First, add environment vars from headers... this is as per
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance * CGI specs, though other sorts of scripting interfaces see
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance * the same vars...
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance */
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance for (i = 0; i < hdrs_arr->nelts; ++i) {
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance if (!hdrs[i].key) {
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance continue;
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance }
ce5d83770556362fe2c8b567975c2a3758888358Felix Gabriel Mance
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance /* A few headers are special cased --- Authorization to prevent
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance * rogue scripts from capturing passwords; content-type and -length
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance * for no particular reason.
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance */
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance if (!strcasecmp(hdrs[i].key, "Content-type")) {
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance apr_table_addn(e, "CONTENT_TYPE", hdrs[i].val);
ce5d83770556362fe2c8b567975c2a3758888358Felix Gabriel Mance }
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance else if (!strcasecmp(hdrs[i].key, "Content-length")) {
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance apr_table_addn(e, "CONTENT_LENGTH", hdrs[i].val);
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance }
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance /*
4440f5c4ab1cb6dfd445da97f87a72d87d24c25aFelix Gabriel Mance * You really don't want to disable this check, since it leaves you
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance * wide open to CGIs stealing passwords and people viewing them
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance * in the environment with "ps -e". But, if you must...
e615997caa046409fc68114cd72e10a528a4bb71Felix Gabriel Mance */
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance#ifndef SECURITY_HOLE_PASS_AUTHORIZATION
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance else if (!strcasecmp(hdrs[i].key, "Authorization")
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance || !strcasecmp(hdrs[i].key, "Proxy-Authorization")) {
fae04f4a69922eb1ddf0f46b34fa15a5a080b693Felix Gabriel Mance continue;
fae04f4a69922eb1ddf0f46b34fa15a5a080b693Felix Gabriel Mance }
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance#endif
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance else {
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance apr_table_addn(e, http2env(r->pool, hdrs[i].key), hdrs[i].val);
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance }
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance }
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance if (!(env_path = getenv("PATH"))) {
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance env_path = DEFAULT_PATH;
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance }
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance apr_table_addn(e, "PATH", apr_pstrdup(r->pool, env_path));
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance#ifdef WIN32
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance if (env_temp = getenv("SystemRoot")) {
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance apr_table_addn(e, "SystemRoot", env_temp);
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance }
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance if (env_temp = getenv("COMSPEC")) {
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance apr_table_addn(e, "COMSPEC", env_temp);
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance }
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance if (env_temp = getenv("PATHEXT")) {
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance apr_table_addn(e, "PATHEXT", env_temp);
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance }
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance if (env_temp = getenv("WINDIR")) {
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance apr_table_addn(e, "WINDIR", env_temp);
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance }
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance#endif
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance#ifdef OS2
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance if ((env_temp = getenv("COMSPEC")) != NULL) {
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance apr_table_addn(e, "COMSPEC", env_temp);
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance }
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance if ((env_temp = getenv("ETC")) != NULL) {
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance apr_table_addn(e, "ETC", env_temp);
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance }
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance if ((env_temp = getenv("DPATH")) != NULL) {
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance apr_table_addn(e, "DPATH", env_temp);
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance }
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance if ((env_temp = getenv("PERLLIB_PREFIX")) != NULL) {
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance apr_table_addn(e, "PERLLIB_PREFIX", env_temp);
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance }
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance#endif
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance#ifdef BEOS
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance if ((env_temp = getenv("LIBRARY_PATH")) != NULL) {
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance apr_table_addn(e, "LIBRARY_PATH", env_temp);
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance }
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance#endif
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance apr_table_addn(e, "SERVER_SIGNATURE", ap_psignature("", r));
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance apr_table_addn(e, "SERVER_SOFTWARE", ap_get_server_version());
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance apr_table_addn(e, "SERVER_NAME",
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance ap_escape_html(r->pool, ap_get_server_name(r)));
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance apr_table_addn(e, "SERVER_ADDR", r->connection->local_ip); /* Apache */
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance apr_table_addn(e, "SERVER_PORT",
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance apr_psprintf(r->pool, "%u", ap_get_server_port(r)));
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance host = ap_get_remote_host(c, r->per_dir_config, REMOTE_HOST, NULL);
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance if (host) {
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance apr_table_addn(e, "REMOTE_HOST", host);
61c1a9c658ddc79ef33b01c14ee8cf5039430dd8Felix Gabriel Mance }
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance apr_table_addn(e, "REMOTE_ADDR", c->remote_ip);
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance apr_table_addn(e, "DOCUMENT_ROOT", ap_document_root(r)); /* Apache */
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance apr_table_addn(e, "SERVER_ADMIN", s->server_admin); /* Apache */
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance apr_table_addn(e, "SCRIPT_FILENAME", r->filename); /* Apache */
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance rport = c->remote_addr->port;
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance apr_table_addn(e, "REMOTE_PORT", apr_itoa(r->pool, rport));
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance if (r->user) {
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance apr_table_addn(e, "REMOTE_USER", r->user);
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance }
61c1a9c658ddc79ef33b01c14ee8cf5039430dd8Felix Gabriel Mance else if (r->prev) {
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance request_rec *back = r->prev;
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance while (back) {
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance if (back->user) {
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance apr_table_addn(e, "REDIRECT_REMOTE_USER", back->user);
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance break;
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance }
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance back = back->prev;
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance }
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance }
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance if (r->ap_auth_type) {
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance apr_table_addn(e, "AUTH_TYPE", r->ap_auth_type);
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance }
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance rem_logname = ap_get_remote_logname(r);
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance if (rem_logname) {
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance apr_table_addn(e, "REMOTE_IDENT", apr_pstrdup(r->pool, rem_logname));
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance }
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance /* Apache custom error responses. If we have redirected set two new vars */
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance if (r->prev) {
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance if (r->prev->args) {
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance apr_table_addn(e, "REDIRECT_QUERY_STRING", r->prev->args);
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance }
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance if (r->prev->uri) {
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance apr_table_addn(e, "REDIRECT_URL", r->prev->uri);
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance }
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance }
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance if (e != r->subprocess_env) {
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance apr_table_overlap(r->subprocess_env, e, APR_OVERLAP_TABLES_SET);
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance }
28b76e08d15cd924bb672449613c410a33361b6eFelix Gabriel Mance}
fae04f4a69922eb1ddf0f46b34fa15a5a080b693Felix Gabriel Mance
a57de3f6b0a0c904523910869eedc7428e5e17a3Felix Gabriel Mance/* This "cute" little function comes about because the path info on
a57de3f6b0a0c904523910869eedc7428e5e17a3Felix Gabriel Mance * filenames and URLs aren't always the same. So we take the two,
a57de3f6b0a0c904523910869eedc7428e5e17a3Felix Gabriel Mance * and find as much of the two that match as possible.
a57de3f6b0a0c904523910869eedc7428e5e17a3Felix Gabriel Mance */
a57de3f6b0a0c904523910869eedc7428e5e17a3Felix Gabriel Mance
a57de3f6b0a0c904523910869eedc7428e5e17a3Felix Gabriel ManceAP_DECLARE(int) ap_find_path_info(const char *uri, const char *path_info)
61c1a9c658ddc79ef33b01c14ee8cf5039430dd8Felix Gabriel Mance{
a57de3f6b0a0c904523910869eedc7428e5e17a3Felix Gabriel Mance int lu = strlen(uri);
a57de3f6b0a0c904523910869eedc7428e5e17a3Felix Gabriel Mance int lp = strlen(path_info);
a57de3f6b0a0c904523910869eedc7428e5e17a3Felix Gabriel Mance
a57de3f6b0a0c904523910869eedc7428e5e17a3Felix Gabriel Mance while (lu-- && lp-- && uri[lu] == path_info[lp]) {
a57de3f6b0a0c904523910869eedc7428e5e17a3Felix Gabriel Mance if (path_info[lp] == '/') {
a57de3f6b0a0c904523910869eedc7428e5e17a3Felix Gabriel Mance while (lu && uri[lu-1] == '/') lu--;
a57de3f6b0a0c904523910869eedc7428e5e17a3Felix Gabriel Mance }
a57de3f6b0a0c904523910869eedc7428e5e17a3Felix Gabriel Mance }
a57de3f6b0a0c904523910869eedc7428e5e17a3Felix Gabriel Mance
a57de3f6b0a0c904523910869eedc7428e5e17a3Felix Gabriel Mance if (lu == -1) {
a57de3f6b0a0c904523910869eedc7428e5e17a3Felix Gabriel Mance lu = 0;
a57de3f6b0a0c904523910869eedc7428e5e17a3Felix Gabriel Mance }
a57de3f6b0a0c904523910869eedc7428e5e17a3Felix Gabriel Mance
a57de3f6b0a0c904523910869eedc7428e5e17a3Felix Gabriel Mance while (uri[lu] != '\0' && uri[lu] != '/') {
a57de3f6b0a0c904523910869eedc7428e5e17a3Felix Gabriel Mance lu++;
a57de3f6b0a0c904523910869eedc7428e5e17a3Felix Gabriel Mance }
a57de3f6b0a0c904523910869eedc7428e5e17a3Felix Gabriel Mance return lu;
a57de3f6b0a0c904523910869eedc7428e5e17a3Felix Gabriel Mance}
a57de3f6b0a0c904523910869eedc7428e5e17a3Felix Gabriel Mance
a57de3f6b0a0c904523910869eedc7428e5e17a3Felix Gabriel Mance/* Obtain the Request-URI from the original request-line, returning
a57de3f6b0a0c904523910869eedc7428e5e17a3Felix Gabriel Mance * a new string from the request pool containing the URI or "".
a57de3f6b0a0c904523910869eedc7428e5e17a3Felix Gabriel Mance */
a57de3f6b0a0c904523910869eedc7428e5e17a3Felix Gabriel Mancestatic char *original_uri(request_rec *r)
a57de3f6b0a0c904523910869eedc7428e5e17a3Felix Gabriel Mance{
a57de3f6b0a0c904523910869eedc7428e5e17a3Felix Gabriel Mance char *first, *last;
61c1a9c658ddc79ef33b01c14ee8cf5039430dd8Felix Gabriel Mance
61c1a9c658ddc79ef33b01c14ee8cf5039430dd8Felix Gabriel Mance if (r->the_request == NULL) {
61c1a9c658ddc79ef33b01c14ee8cf5039430dd8Felix Gabriel Mance return (char *) apr_pcalloc(r->pool, 1);
61c1a9c658ddc79ef33b01c14ee8cf5039430dd8Felix Gabriel Mance }
61c1a9c658ddc79ef33b01c14ee8cf5039430dd8Felix Gabriel Mance
61c1a9c658ddc79ef33b01c14ee8cf5039430dd8Felix Gabriel Mance first = r->the_request; /* use the request-line */
61c1a9c658ddc79ef33b01c14ee8cf5039430dd8Felix Gabriel Mance
61c1a9c658ddc79ef33b01c14ee8cf5039430dd8Felix Gabriel Mance while (*first && !apr_isspace(*first)) {
61c1a9c658ddc79ef33b01c14ee8cf5039430dd8Felix Gabriel Mance ++first; /* skip over the method */
58231c02ba63cd573b7d523e938acdb0798983c4Felix Gabriel Mance }
58231c02ba63cd573b7d523e938acdb0798983c4Felix Gabriel Mance while (apr_isspace(*first)) {
++first; /* and the space(s) */
}
last = first;
while (*last && !apr_isspace(*last)) {
++last; /* end at next whitespace */
}
return apr_pstrmemdup(r->pool, first, last - first);
}
AP_DECLARE(void) ap_add_cgi_vars(request_rec *r)
{
apr_table_t *e = r->subprocess_env;
apr_table_setn(e, "GATEWAY_INTERFACE", "CGI/1.1");
apr_table_setn(e, "SERVER_PROTOCOL", r->protocol);
apr_table_setn(e, "REQUEST_METHOD", r->method);
apr_table_setn(e, "QUERY_STRING", r->args ? r->args : "");
apr_table_setn(e, "REQUEST_URI", original_uri(r));
/* 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.
*/
if (!strcmp(r->protocol, "INCLUDED")) {
apr_table_setn(e, "SCRIPT_NAME", r->uri);
if (r->path_info && *r->path_info) {
apr_table_setn(e, "PATH_INFO", r->path_info);
}
}
else if (!r->path_info || !*r->path_info) {
apr_table_setn(e, "SCRIPT_NAME", r->uri);
}
else {
int path_info_start = ap_find_path_info(r->uri, r->path_info);
apr_table_setn(e, "SCRIPT_NAME",
apr_pstrndup(r->pool, r->uri, path_info_start));
apr_table_setn(e, "PATH_INFO", r->path_info);
}
if (r->path_info && r->path_info[0]) {
/*
* 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.
*/
request_rec *pa_req;
pa_req = ap_sub_req_lookup_uri(ap_escape_uri(r->pool, r->path_info), r,
NULL);
if (pa_req->filename) {
char *pt = apr_pstrcat(r->pool, pa_req->filename, pa_req->path_info,
NULL);
#ifdef WIN32
/* We need to make this a real Windows path name */
apr_filepath_merge(&pt, "", pt, APR_FILEPATH_NATIVE, r->pool);
#endif
apr_table_setn(e, "PATH_TRANSLATED", pt);
}
ap_destroy_sub_req(pa_req);
}
}
static int set_cookie_doo_doo(void *v, const char *key, const char *val)
{
apr_table_addn(v, key, val);
return 1;
}
#define HTTP_UNSET (-HTTP_OK)
AP_DECLARE(int) ap_scan_script_header_err_core(request_rec *r, char *buffer,
int (*getsfunc) (char *, int, void *),
void *getsfunc_data)
{
char x[MAX_STRING_LEN];
char *w, *l;
int p;
int cgi_status = HTTP_UNSET;
apr_table_t *merge;
apr_table_t *cookie_table;
if (buffer) {
*buffer = '\0';
}
w = buffer ? buffer : x;
/* temporary place to hold headers to merge in later */
merge = apr_table_make(r->pool, 10);
/* 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.
* Oh what a pain it is.
*/
cookie_table = apr_table_make(r->pool, 2);
apr_table_do(set_cookie_doo_doo, cookie_table, r->err_headers_out, "Set-Cookie", NULL);
while (1) {
if ((*getsfunc) (w, MAX_STRING_LEN - 1, getsfunc_data) == 0) {
ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_TOCLIENT, 0, r,
"Premature end of script headers: %s",
apr_filepath_name_get(r->filename));
return HTTP_INTERNAL_SERVER_ERROR;
}
/* Delete terminal (CR?)LF */
p = strlen(w);
/* 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) {
w[p - 2] = '\0';
}
else {
w[p - 1] = '\0';
}
}
/*
* 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.
*/
if (w[0] == '\0') {
int cond_status = OK;
/* 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.
*/
if ((cgi_status == HTTP_UNSET) && (r->method_number == M_GET)) {
cond_status = ap_meets_conditions(r);
}
apr_table_overlap(r->err_headers_out, merge,
APR_OVERLAP_TABLES_MERGE);
if (!apr_is_empty_table(cookie_table)) {
/* the cookies have already been copied to the cookie_table */
apr_table_unset(r->err_headers_out, "Set-Cookie");
r->err_headers_out = apr_table_overlay(r->pool,
r->err_headers_out, cookie_table);
}
return cond_status;
}
/* if we see a bogus header don't ignore it. Shout and scream */
#if APR_CHARSET_EBCDIC
/* Chances are that we received an ASCII header text instead of
* the expected EBCDIC header lines. Try to auto-detect:
*/
if (!(l = strchr(w, ':'))) {
int maybeASCII = 0, maybeEBCDIC = 0;
unsigned char *cp, native;
apr_size_t inbytes_left, outbytes_left;
for (cp = w; *cp != '\0'; ++cp) {
native = apr_xlate_conv_byte(ap_hdrs_from_ascii, *cp);
if (apr_isprint(*cp) && !apr_isprint(native))
++maybeEBCDIC;
if (!apr_isprint(*cp) && apr_isprint(native))
++maybeASCII;
}
if (maybeASCII > maybeEBCDIC) {
ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
"CGI Interface Error: Script headers apparently ASCII: (CGI = %s)",
r->filename);
inbytes_left = outbytes_left = cp - w;
apr_xlate_conv_buffer(ap_hdrs_from_ascii,
w, &inbytes_left, w, &outbytes_left);
}
}
#endif /*APR_CHARSET_EBCDIC*/
if (!(l = strchr(w, ':'))) {
char malformed[(sizeof MALFORMED_MESSAGE) + 1
+ MALFORMED_HEADER_LENGTH_TO_SHOW];
strcpy(malformed, MALFORMED_MESSAGE);
strncat(malformed, w, MALFORMED_HEADER_LENGTH_TO_SHOW);
if (!buffer) {
/* Soak up all the script output - may save an outright kill */
while ((*getsfunc) (w, MAX_STRING_LEN - 1, getsfunc_data)) {
continue;
}
}
ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_TOCLIENT, 0, r,
"%s: %s", malformed,
apr_filepath_name_get(r->filename));
return HTTP_INTERNAL_SERVER_ERROR;
}
*l++ = '\0';
while (*l && apr_isspace(*l)) {
++l;
}
if (!strcasecmp(w, "Content-type")) {
char *tmp;
/* Nuke trailing whitespace */
char *endp = l + strlen(l) - 1;
while (endp > l && apr_isspace(*endp)) {
*endp-- = '\0';
}
tmp = apr_pstrdup(r->pool, l);
ap_content_type_tolower(tmp);
ap_set_content_type(r, tmp);
}
/*
* If the script returned a specific status, that's what
* we'll use - otherwise we assume 200 OK.
*/
else if (!strcasecmp(w, "Status")) {
r->status = cgi_status = atoi(l);
r->status_line = apr_pstrdup(r->pool, l);
}
else if (!strcasecmp(w, "Location")) {
apr_table_set(r->headers_out, w, l);
}
else if (!strcasecmp(w, "Content-Length")) {
apr_table_set(r->headers_out, w, l);
}
else if (!strcasecmp(w, "Content-Range")) {
apr_table_set(r->headers_out, w, l);
}
else if (!strcasecmp(w, "Transfer-Encoding")) {
apr_table_set(r->headers_out, w, l);
}
/*
* If the script gave us a Last-Modified header, we can't just
* pass it on blindly because of restrictions on future values.
*/
else if (!strcasecmp(w, "Last-Modified")) {
ap_update_mtime(r, apr_date_parse_http(l));
ap_set_last_modified(r);
}
else if (!strcasecmp(w, "Set-Cookie")) {
apr_table_add(cookie_table, w, l);
}
else {
apr_table_add(merge, w, l);
}
}
return OK;
}
static int getsfunc_FILE(char *buf, int len, void *f)
{
return apr_file_gets(buf, len, (apr_file_t *) f) == APR_SUCCESS;
}
AP_DECLARE(int) ap_scan_script_header_err(request_rec *r, apr_file_t *f,
char *buffer)
{
return ap_scan_script_header_err_core(r, buffer, getsfunc_FILE, f);
}
static int getsfunc_BRIGADE(char *buf, int len, void *arg)
{
apr_bucket_brigade *bb = (apr_bucket_brigade *)arg;
const char *dst_end = buf + len - 1; /* leave room for terminating null */
char *dst = buf;
apr_bucket *e = APR_BRIGADE_FIRST(bb);
apr_status_t rv;
int done = 0;
while ((dst < dst_end) && !done && !APR_BUCKET_IS_EOS(e)) {
const char *bucket_data;
apr_size_t bucket_data_len;
const char *src;
const char *src_end;
apr_bucket * next;
rv = apr_bucket_read(e, &bucket_data, &bucket_data_len,
APR_BLOCK_READ);
if (rv != APR_SUCCESS || (bucket_data_len == 0)) {
return 0;
}
src = bucket_data;
src_end = bucket_data + bucket_data_len;
while ((src < src_end) && (dst < dst_end) && !done) {
if (*src == '\n') {
done = 1;
}
else if (*src != '\r') {
*dst++ = *src;
}
src++;
}
if (src < src_end) {
apr_bucket_split(e, src - bucket_data);
}
next = APR_BUCKET_NEXT(e);
APR_BUCKET_REMOVE(e);
apr_bucket_destroy(e);
e = next;
}
*dst = 0;
return 1;
}
AP_DECLARE(int) ap_scan_script_header_err_brigade(request_rec *r,
apr_bucket_brigade *bb,
char *buffer)
{
return ap_scan_script_header_err_core(r, buffer, getsfunc_BRIGADE, bb);
}
struct vastrs {
va_list args;
int arg;
const char *curpos;
};
static int getsfunc_STRING(char *w, int len, void *pvastrs)
{
struct vastrs *strs = (struct vastrs*) pvastrs;
const char *p;
int t;
if (!strs->curpos || !*strs->curpos)
return 0;
p = ap_strchr_c(strs->curpos, '\n');
if (p)
++p;
else
p = ap_strchr_c(strs->curpos, '\0');
t = p - strs->curpos;
if (t > len)
t = len;
strncpy (w, strs->curpos, t);
w[t] = '\0';
if (!strs->curpos[t]) {
++strs->arg;
strs->curpos = va_arg(strs->args, const char *);
}
else
strs->curpos += t;
return t;
}
/* 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
* counted as 0.)
*/
AP_DECLARE_NONSTD(int) ap_scan_script_header_err_strs(request_rec *r,
char *buffer,
const char **termch,
int *termarg, ...)
{
struct vastrs strs;
int res;
va_start(strs.args, termarg);
strs.arg = 0;
strs.curpos = va_arg(strs.args, char*);
res = ap_scan_script_header_err_core(r, buffer, getsfunc_STRING, (void *) &strs);
if (termch)
*termch = strs.curpos;
if (termarg)
*termarg = strs.arg;
va_end(strs.args);
return res;
}