mod_proxy.c revision ea8e3350cface61eda0d549bfba28755e09fc322
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb/* Licensed to the Apache Software Foundation (ASF) under one or more
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * contributor license agreements. See the NOTICE file distributed with
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * this work for additional information regarding copyright ownership.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * The ASF licenses this file to You under the Apache License, Version 2.0
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * (the "License"); you may not use this file except in compliance with
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * the License. You may obtain a copy of the License at
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * http://www.apache.org/licenses/LICENSE-2.0
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Unless required by applicable law or agreed to in writing, software
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * distributed under the License is distributed on an "AS IS" BASIS,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * See the License for the specific language governing permissions and
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * limitations under the License.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "mod_proxy.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "mod_core.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "apr_optional.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "scoreboard.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "mod_status.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "proxy_util.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#if (MODULE_MAGIC_NUMBER_MAJOR > 20020903)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#include "mod_ssl.h"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#else
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbAPR_DECLARE_OPTIONAL_FN(int, ssl_proxy_enable, (conn_rec *));
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbAPR_DECLARE_OPTIONAL_FN(int, ssl_engine_disable, (conn_rec *));
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbAPR_DECLARE_OPTIONAL_FN(int, ssl_is_https, (conn_rec *));
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbAPR_DECLARE_OPTIONAL_FN(char *, ssl_var_lookup,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb (apr_pool_t *, server_rec *,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb conn_rec *, request_rec *, char *));
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#endif
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#ifndef MAX
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#define MAX(x,y) ((x) >= (y) ? (x) : (y))
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#endif
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic const char * const proxy_id = "proxy";
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbapr_global_mutex_t *proxy_mutex = NULL;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb/*
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * A Web proxy module. Stages:
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * translate_name: set filename to proxy:<URL>
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * map_to_storage: run proxy_walk (rather than directory_walk/file_walk)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * can't trust directory_walk/file_walk since these are
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * not in our filesystem. Prevents mod_http from serving
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * the TRACE request we will set aside to handle later.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * fix_ups: convert the URL stored in the filename to the
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * canonical form.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * handler: handle proxy requests
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb/* -------------------------------------------------------------- */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb/* Translate the URL into a 'filename' */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic const char *set_worker_param(apr_pool_t *p,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb proxy_worker *worker,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb const char *key,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb const char *val)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb int ival;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb apr_interval_time_t timeout;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (!strcasecmp(key, "loadfactor")) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Normalized load factor. Used with BalancerMamber,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * it is a number between 1 and 100.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb worker->s->lbfactor = atoi(val);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (worker->s->lbfactor < 1 || worker->s->lbfactor > 100)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return "LoadFactor must be a number between 1..100";
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else if (!strcasecmp(key, "retry")) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* If set it will give the retry timeout for the worker
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * The default value is 60 seconds, meaning that if
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * in error state, it will be retried after that timeout.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ival = atoi(val);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (ival < 0)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return "Retry must be a positive value";
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb worker->s->retry = apr_time_from_sec(ival);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb worker->s->retry_set = 1;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else if (!strcasecmp(key, "ttl")) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Time in seconds that will destroy all the connections
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * that exceed the smax
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ival = atoi(val);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (ival < 1)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return "TTL must be at least one second";
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb worker->s->ttl = apr_time_from_sec(ival);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else if (!strcasecmp(key, "min")) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Initial number of connections to remote
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ival = atoi(val);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (ival < 0)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return "Min must be a positive number";
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb worker->s->min = ival;
b45c1c292ff1fa635004ae81fa691f8cb3cdda85rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else if (!strcasecmp(key, "max")) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Maximum number of connections to remote
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ival = atoi(val);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (ival < 0)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return "Max must be a positive number";
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb worker->s->hmax = ival;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* XXX: More inteligent naming needed */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else if (!strcasecmp(key, "smax")) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Maximum number of connections to remote that
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * will not be destroyed
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ival = atoi(val);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (ival < 0)
c3e342e5b0b9fea6617ee16d2da02c3ef2108126dougm return "Smax must be a positive number";
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb worker->s->smax = ival;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else if (!strcasecmp(key, "acquire")) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Acquire timeout in given unit (default is milliseconds).
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * If set this will be the maximum time to
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * wait for a free connection.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (ap_timeout_parameter_parse(val, &timeout, "ms") != APR_SUCCESS)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return "Acquire timeout has wrong format";
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (timeout < 1000)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return "Acquire must be at least one millisecond";
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb worker->s->acquire = timeout;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb worker->s->acquire_set = 1;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else if (!strcasecmp(key, "timeout")) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Connection timeout in seconds.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Defaults to server timeout.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ival = atoi(val);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (ival < 1)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return "Timeout must be at least one second";
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb worker->s->timeout = apr_time_from_sec(ival);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb worker->s->timeout_set = 1;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else if (!strcasecmp(key, "iobuffersize")) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb long s = atol(val);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (s < 512 && s) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return "IOBufferSize must be >= 512 bytes, or 0 for system default.";
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb worker->s->io_buffer_size = (s ? s : AP_IOBUFSIZE);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb worker->s->io_buffer_size_set = 1;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else if (!strcasecmp(key, "receivebuffersize")) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ival = atoi(val);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (ival < 512 && ival != 0) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return "ReceiveBufferSize must be >= 512 bytes, or 0 for system default.";
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
8aefbd756763807188d2e3ce336a8680e4893066wrowe worker->s->recv_buffer_size = ival;
8aefbd756763807188d2e3ce336a8680e4893066wrowe worker->s->recv_buffer_size_set = 1;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else if (!strcasecmp(key, "keepalive")) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (!strcasecmp(val, "on"))
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb worker->s->keepalive = 1;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else if (!strcasecmp(val, "off"))
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb worker->s->keepalive = 0;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return "KeepAlive must be On|Off";
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb worker->s->keepalive_set = 1;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else if (!strcasecmp(key, "disablereuse")) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (!strcasecmp(val, "on"))
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb worker->s->disablereuse = 1;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else if (!strcasecmp(val, "off"))
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb worker->s->disablereuse = 0;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return "DisableReuse must be On|Off";
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb worker->s->disablereuse_set = 1;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else if (!strcasecmp(key, "route")) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Worker route.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (strlen(val) >= sizeof(worker->s->route))
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return apr_psprintf(p, "Route length must be < %d characters",
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb (int)sizeof(worker->s->route));
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb PROXY_STRNCPY(worker->s->route, val);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else if (!strcasecmp(key, "redirect")) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Worker redirection route.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (strlen(val) >= sizeof(worker->s->redirect))
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return apr_psprintf(p, "Redirect length must be < %d characters",
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb (int)sizeof(worker->s->redirect));
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb PROXY_STRNCPY(worker->s->redirect, val);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else if (!strcasecmp(key, "status")) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb const char *v;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb int mode = 1;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb apr_status_t rv;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Worker status.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb for (v = val; *v; v++) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (*v == '+') {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb mode = 1;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb v++;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else if (*v == '-') {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb mode = 0;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb v++;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb rv = ap_proxy_set_wstatus(*v, mode, worker);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (rv != APR_SUCCESS)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return "Unknown status parameter option";
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else if (!strcasecmp(key, "flushpackets")) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (!strcasecmp(val, "on"))
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb worker->s->flush_packets = flush_on;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else if (!strcasecmp(val, "off"))
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb worker->s->flush_packets = flush_off;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else if (!strcasecmp(val, "auto"))
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb worker->s->flush_packets = flush_auto;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return "flushpackets must be on|off|auto";
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else if (!strcasecmp(key, "flushwait")) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ival = atoi(val);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (ival > 1000 || ival < 0) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return "flushwait must be <= 1000, or 0 for system default of 10 millseconds.";
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (ival == 0)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb worker->s->flush_wait = PROXY_FLUSH_WAIT;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb worker->s->flush_wait = ival * 1000; /* change to microseconds */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else if (!strcasecmp(key, "ping")) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Ping/Pong timeout in given unit (default is second).
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
4ca6cbe768b4e0917ac0b76333c26a7d5396d454trawick if (ap_timeout_parameter_parse(val, &timeout, "s") != APR_SUCCESS)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return "Ping/Pong timeout has wrong format";
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (timeout < 1000 && timeout >= 0)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return "Ping/Pong timeout must be at least one millisecond";
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb worker->s->ping_timeout = timeout;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb worker->s->ping_timeout_set = 1;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else if (!strcasecmp(key, "lbset")) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ival = atoi(val);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (ival < 0 || ival > 99)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return "lbset must be between 0 and 99";
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb worker->s->lbset = ival;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else if (!strcasecmp(key, "connectiontimeout")) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Request timeout in given unit (default is second).
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Defaults to connection timeout
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (ap_timeout_parameter_parse(val, &timeout, "s") != APR_SUCCESS)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return "Connectiontimeout has wrong format";
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (timeout < 1000)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return "Connectiontimeout must be at least one millisecond.";
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb worker->s->conn_timeout = timeout;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb worker->s->conn_timeout_set = 1;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else if (!strcasecmp(key, "flusher")) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (strlen(val) >= sizeof(worker->s->flusher))
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb apr_psprintf(p, "flusher name length must be < %d characters",
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb (int)sizeof(worker->s->flusher));
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb PROXY_STRNCPY(worker->s->flusher, val);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return "unknown Worker parameter";
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return NULL;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic const char *set_balancer_param(proxy_server_conf *conf,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb apr_pool_t *p,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb proxy_balancer *balancer,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb const char *key,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb const char *val)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb int ival;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (!strcasecmp(key, "stickysession")) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb char *path;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Balancer sticky session name.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Set to something like JSESSIONID or
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * PHPSESSIONID, etc..,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (strlen(val) >= sizeof(balancer->s->sticky_path))
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb apr_psprintf(p, "stickysession length must be < %d characters",
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb (int)sizeof(balancer->s->sticky_path));
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb PROXY_STRNCPY(balancer->s->sticky_path, val);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb PROXY_STRNCPY(balancer->s->sticky, val);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if ((path = strchr((char *)balancer->s->sticky, '|'))) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *path++ = '\0';
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb PROXY_STRNCPY(balancer->s->sticky_path, path);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else if (!strcasecmp(key, "stickysessionsep")) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* separator/delimiter for sessionid and route,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * normally '.'
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (strlen(val) != 1) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (!strcasecmp(val, "off"))
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb balancer->s->sticky_separator = 0;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return "stickysessionsep must be a single character or Off";
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb balancer->s->sticky_separator = *val;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else if (!strcasecmp(key, "nofailover")) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* If set to 'on' the session will break
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * if the worker is in error state or
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * disabled.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (!strcasecmp(val, "on"))
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb balancer->s->sticky_force = 1;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else if (!strcasecmp(val, "off"))
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb balancer->s->sticky_force = 0;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return "failover must be On|Off";
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else if (!strcasecmp(key, "timeout")) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Balancer timeout in seconds.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * If set this will be the maximum time to
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * wait for a free worker.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Default is not to wait.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ival = atoi(val);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (ival < 1)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return "timeout must be at least one second";
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb balancer->s->timeout = apr_time_from_sec(ival);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else if (!strcasecmp(key, "maxattempts")) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Maximum number of failover attempts before
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * giving up.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ival = atoi(val);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (ival < 0)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return "maximum number of attempts must be a positive number";
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb balancer->s->max_attempts = ival;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb balancer->s->max_attempts_set = 1;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else if (!strcasecmp(key, "lbmethod")) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb proxy_balancer_method *provider;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (strlen(val) > (sizeof(balancer->s->lbpname)-1))
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return "unknown lbmethod";
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb provider = ap_lookup_provider(PROXY_LBMETHOD, val, "0");
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (provider) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb balancer->lbmethod = provider;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (PROXY_STRNCPY(balancer->s->lbpname, val) == APR_SUCCESS) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return NULL;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return "lbmethod name too large";
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return "unknown lbmethod";
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else if (!strcasecmp(key, "scolonpathdelim")) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* If set to 'on' then ';' will also be
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * used as a session path separator/delim (ala
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * mod_jk)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (!strcasecmp(val, "on"))
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb balancer->s->scolonsep = 1;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else if (!strcasecmp(val, "off"))
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb balancer->s->scolonsep = 0;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return "scolonpathdelim must be On|Off";
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else if (!strcasecmp(key, "failonstatus")) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb char *val_split;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb char *status;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb char *tok_state;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb val_split = apr_pstrdup(p, val);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb balancer->errstatuses = apr_array_make(p, 1, sizeof(int));
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb status = apr_strtok(val_split, ", ", &tok_state);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb while (status != NULL) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ival = atoi(status);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (ap_is_HTTP_VALID_RESPONSE(ival)) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *(int *)apr_array_push(balancer->errstatuses) = ival;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return "failonstatus must be one or more HTTP response codes";
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb status = apr_strtok(NULL, ", ", &tok_state);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else if (!strcasecmp(key, "failontimeout")) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (!strcasecmp(val, "on"))
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb balancer->failontimeout = 1;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else if (!strcasecmp(val, "off"))
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb balancer->failontimeout = 0;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return "failontimeout must be On|Off";
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else if (!strcasecmp(key, "nonce")) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (!strcasecmp(val, "None")) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *balancer->s->nonce = '\0';
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (PROXY_STRNCPY(balancer->s->nonce, val) != APR_SUCCESS) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return "Provided nonce is too large";
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else if (!strcasecmp(key, "growth")) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ival = atoi(val);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (ival < 1 || ival > 100) /* arbitrary limit here */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return "growth must be between 1 and 100";
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb balancer->growth = ival;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else if (!strcasecmp(key, "forcerecovery")) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (!strcasecmp(val, "on"))
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb balancer->s->forcerecovery = 1;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else if (!strcasecmp(val, "off"))
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb balancer->s->forcerecovery = 0;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return "forcerecovery must be On|Off";
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return "unknown Balancer parameter";
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return NULL;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic int alias_match(const char *uri, const char *alias_fakename)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb const char *end_fakename = alias_fakename + strlen(alias_fakename);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb const char *aliasp = alias_fakename, *urip = uri;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb const char *end_uri = uri + strlen(uri);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb while (aliasp < end_fakename && urip < end_uri) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (*aliasp == '/') {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* any number of '/' in the alias matches any number in
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * the supplied URI, but there must be at least one...
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (*urip != '/')
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return 0;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb while (*aliasp == '/')
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ++aliasp;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb while (*urip == '/')
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ++urip;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Other characters are compared literally */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (*urip++ != *aliasp++)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return 0;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* fixup badly encoded stuff (e.g. % as last character) */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (aliasp > end_fakename) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb aliasp = end_fakename;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (urip > end_uri) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb urip = end_uri;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* We reach the end of the uri before the end of "alias_fakename"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * for example uri is "/" and alias_fakename "/examples"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (urip == end_uri && aliasp != end_fakename) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return 0;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Check last alias path component matched all the way */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (aliasp[-1] != '/' && *urip != '\0' && *urip != '/')
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return 0;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Return number of characters from URI which matched (may be
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * greater than length of alias, since we may have matched
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * doubled slashes)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return urip - uri;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb/* Detect if an absoluteURI should be proxied or not. Note that we
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * have to do this during this phase because later phases are
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * "short-circuiting"... i.e. translate_names will end when the first
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * module returns OK. So for example, if the request is something like:
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * GET http://othervhost/cgi-bin/printenv HTTP/1.0
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * mod_alias will notice the /cgi-bin part and ScriptAlias it and
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * short-circuit the proxy... just because of the ordering in the
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * configuration file.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic int proxy_detect(request_rec *r)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb void *sconf = r->server->module_config;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb proxy_server_conf *conf =
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb (proxy_server_conf *) ap_get_module_config(sconf, &proxy_module);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Ick... msvc (perhaps others) promotes ternary short results to int */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (conf->req && r->parsed_uri.scheme) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* but it might be something vhosted */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (!(r->parsed_uri.hostname
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb && !strcasecmp(r->parsed_uri.scheme, ap_http_scheme(r))
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb && ap_matches_request_vhost(r, r->parsed_uri.hostname,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb (apr_port_t)(r->parsed_uri.port_str ? r->parsed_uri.port
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb : ap_default_port(r))))) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb r->proxyreq = PROXYREQ_PROXY;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb r->uri = r->unparsed_uri;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb r->filename = apr_pstrcat(r->pool, "proxy:", r->uri, NULL);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb r->handler = "proxy-server";
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* We need special treatment for CONNECT proxying: it has no scheme part */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else if (conf->req && r->method_number == M_CONNECT
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb && r->parsed_uri.hostname
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb && r->parsed_uri.port_str) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb r->proxyreq = PROXYREQ_PROXY;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb r->uri = r->unparsed_uri;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb r->filename = apr_pstrcat(r->pool, "proxy:", r->uri, NULL);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb r->handler = "proxy-server";
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return DECLINED;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic const char *proxy_interpolate(request_rec *r, const char *str)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Interpolate an env str in a configuration string
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Syntax ${var} --> value_of(var)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Method: replace one var, and recurse on remainder of string
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Nothing clever here, and crap like nested vars may do silly things
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * but we'll at least avoid sending the unwary into a loop
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb const char *start;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb const char *end;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb const char *var;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb const char *val;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb const char *firstpart;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb start = ap_strstr_c(str, "${");
c4f311d9c637c74c57ef51a1a3a610bb48af1ce8wrowe if (start == NULL) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return str;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb end = ap_strchr_c(start+2, '}');
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (end == NULL) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return str;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* OK, this is syntax we want to interpolate. Is there such a var ? */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb var = apr_pstrndup(r->pool, start+2, end-(start+2));
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb val = apr_table_get(r->subprocess_env, var);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb firstpart = apr_pstrndup(r->pool, str, (start-str));
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (val == NULL) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return apr_pstrcat(r->pool, firstpart,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb proxy_interpolate(r, end+1), NULL);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return apr_pstrcat(r->pool, firstpart, val,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb proxy_interpolate(r, end+1), NULL);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic apr_array_header_t *proxy_vars(request_rec *r,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb apr_array_header_t *hdr)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb int i;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb apr_array_header_t *ret = apr_array_make(r->pool, hdr->nelts,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb sizeof (struct proxy_alias));
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb struct proxy_alias *old = (struct proxy_alias *) hdr->elts;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb for (i = 0; i < hdr->nelts; ++i) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb struct proxy_alias *newcopy = apr_array_push(ret);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb newcopy->fake = (old[i].flags & PROXYPASS_INTERPOLATE)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ? proxy_interpolate(r, old[i].fake) : old[i].fake;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb newcopy->real = (old[i].flags & PROXYPASS_INTERPOLATE)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ? proxy_interpolate(r, old[i].real) : old[i].real;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return ret;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbPROXY_DECLARE(int) ap_proxy_trans_match(request_rec *r, struct proxy_alias *ent,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb proxy_dir_conf *dconf)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb int len;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb const char *fake;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb const char *real;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_regmatch_t regm[AP_MAX_REG_MATCH];
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_regmatch_t reg1[AP_MAX_REG_MATCH];
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb char *found = NULL;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb int mismatch = 0;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb unsigned int nocanon = ent->flags & PROXYPASS_NOCANON;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb const char *use_uri = nocanon ? r->unparsed_uri : r->uri;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (dconf && (dconf->interpolate_env == 1) && (ent->flags & PROXYPASS_INTERPOLATE)) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb fake = proxy_interpolate(r, ent->fake);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb real = proxy_interpolate(r, ent->real);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb fake = ent->fake;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb real = ent->real;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (ent->regex) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (!ap_regexec(ent->regex, r->uri, AP_MAX_REG_MATCH, regm, 0)) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if ((real[0] == '!') && (real[1] == '\0')) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return DECLINED;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* test that we haven't reduced the URI */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (nocanon && ap_regexec(ent->regex, r->unparsed_uri,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb AP_MAX_REG_MATCH, reg1, 0)) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb mismatch = 1;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb use_uri = r->uri;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb found = ap_pregsub(r->pool, real, use_uri, AP_MAX_REG_MATCH,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb (use_uri == r->uri) ? regm : reg1);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (!found) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_log_rerror(APLOG_MARK, APLOG_CRIT, 0, r, APLOGNO(01135)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "Substitution in regular expression failed. "
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "Replacement too long?");
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return HTTP_INTERNAL_SERVER_ERROR;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Note: The strcmp() below catches cases where there
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * was no regex substitution. This is so cases like:
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * ProxyPassMatch \.gif balancer://foo
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * will work "as expected". The upshot is that the 2
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * directives below act the exact same way (ie: $1 is implied):
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * ProxyPassMatch ^(/.*\.gif)$ balancer://foo
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * ProxyPassMatch ^(/.*\.gif)$ balancer://foo$1
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * which may be confusing.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (strcmp(found, real) != 0) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb found = apr_pstrcat(r->pool, "proxy:", found, NULL);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb found = apr_pstrcat(r->pool, "proxy:", real, use_uri, NULL);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb len = alias_match(r->uri, fake);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (len != 0) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe if ((real[0] == '!') && (real[1] == '\0')) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe return DECLINED;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (nocanon && len != alias_match(r->unparsed_uri, ent->fake)) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe mismatch = 1;
8aefbd756763807188d2e3ce336a8680e4893066wrowe use_uri = r->uri;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe found = apr_pstrcat(r->pool, "proxy:", real, use_uri + len, NULL);
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (mismatch) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe /* We made a reducing transformation, so we can't safely use
8aefbd756763807188d2e3ce336a8680e4893066wrowe * unparsed_uri. Safe fallback is to ignore nocanon.
8aefbd756763807188d2e3ce336a8680e4893066wrowe */
8aefbd756763807188d2e3ce336a8680e4893066wrowe ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, APLOGNO(01136)
8aefbd756763807188d2e3ce336a8680e4893066wrowe "Unescaped URL path matched ProxyPass; ignoring unsafe nocanon");
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (found) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe r->filename = found;
8aefbd756763807188d2e3ce336a8680e4893066wrowe r->handler = "proxy-server";
8aefbd756763807188d2e3ce336a8680e4893066wrowe r->proxyreq = PROXYREQ_REVERSE;
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (nocanon && !mismatch) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe /* mod_proxy_http needs to be told. Different module. */
8aefbd756763807188d2e3ce336a8680e4893066wrowe apr_table_setn(r->notes, "proxy-nocanon", "1");
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (ent->flags & PROXYPASS_NOQUERY) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe apr_table_setn(r->notes, "proxy-noquery", "1");
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe return OK;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe return DONE;
8aefbd756763807188d2e3ce336a8680e4893066wrowe}
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowestatic int proxy_trans(request_rec *r)
8aefbd756763807188d2e3ce336a8680e4893066wrowe{
8aefbd756763807188d2e3ce336a8680e4893066wrowe int i;
8aefbd756763807188d2e3ce336a8680e4893066wrowe struct proxy_alias *ent;
8aefbd756763807188d2e3ce336a8680e4893066wrowe proxy_dir_conf *dconf;
8aefbd756763807188d2e3ce336a8680e4893066wrowe proxy_server_conf *conf;
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (r->proxyreq) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe /* someone has already set up the proxy, it was possibly ourselves
8aefbd756763807188d2e3ce336a8680e4893066wrowe * in proxy_detect
8aefbd756763807188d2e3ce336a8680e4893066wrowe */
8aefbd756763807188d2e3ce336a8680e4893066wrowe return OK;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe if ((r->unparsed_uri[0] == '*' && r->unparsed_uri[1] == '\0')
8aefbd756763807188d2e3ce336a8680e4893066wrowe || !r->uri || r->uri[0] != '/') {
8aefbd756763807188d2e3ce336a8680e4893066wrowe return DECLINED;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe /* XXX: since r->uri has been manipulated already we're not really
8aefbd756763807188d2e3ce336a8680e4893066wrowe * compliant with RFC1945 at this point. But this probably isn't
8aefbd756763807188d2e3ce336a8680e4893066wrowe * an issue because this is a hybrid proxy/origin server.
8aefbd756763807188d2e3ce336a8680e4893066wrowe */
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe dconf = ap_get_module_config(r->per_dir_config, &proxy_module);
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe /* short way - this location is reverse proxied? */
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (dconf->alias) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe int rv = ap_proxy_trans_match(r, dconf->alias, dconf);
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (DONE != rv) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe return rv;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe conf = (proxy_server_conf *) ap_get_module_config(r->server->module_config,
8aefbd756763807188d2e3ce336a8680e4893066wrowe &proxy_module);
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe /* long way - walk the list of aliases, find a match */
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (conf->aliases->nelts) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe ent = (struct proxy_alias *) conf->aliases->elts;
8aefbd756763807188d2e3ce336a8680e4893066wrowe for (i = 0; i < conf->aliases->nelts; i++) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe int rv = ap_proxy_trans_match(r, &ent[i], dconf);
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (DONE != rv) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe return rv;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe return DECLINED;
8aefbd756763807188d2e3ce336a8680e4893066wrowe}
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowestatic int proxy_walk(request_rec *r)
8aefbd756763807188d2e3ce336a8680e4893066wrowe{
8aefbd756763807188d2e3ce336a8680e4893066wrowe proxy_server_conf *sconf = ap_get_module_config(r->server->module_config,
8aefbd756763807188d2e3ce336a8680e4893066wrowe &proxy_module);
8aefbd756763807188d2e3ce336a8680e4893066wrowe ap_conf_vector_t *per_dir_defaults = r->server->lookup_defaults;
8aefbd756763807188d2e3ce336a8680e4893066wrowe ap_conf_vector_t **sec_proxy = (ap_conf_vector_t **) sconf->sec_proxy->elts;
8aefbd756763807188d2e3ce336a8680e4893066wrowe ap_conf_vector_t *entry_config;
8aefbd756763807188d2e3ce336a8680e4893066wrowe proxy_dir_conf *entry_proxy;
8aefbd756763807188d2e3ce336a8680e4893066wrowe int num_sec = sconf->sec_proxy->nelts;
8aefbd756763807188d2e3ce336a8680e4893066wrowe /* XXX: shouldn't we use URI here? Canonicalize it first?
8aefbd756763807188d2e3ce336a8680e4893066wrowe * Pass over "proxy:" prefix
8aefbd756763807188d2e3ce336a8680e4893066wrowe */
8aefbd756763807188d2e3ce336a8680e4893066wrowe const char *proxyname = r->filename + 6;
8aefbd756763807188d2e3ce336a8680e4893066wrowe int j;
8aefbd756763807188d2e3ce336a8680e4893066wrowe apr_pool_t *rxpool = NULL;
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe for (j = 0; j < num_sec; ++j)
8aefbd756763807188d2e3ce336a8680e4893066wrowe {
8aefbd756763807188d2e3ce336a8680e4893066wrowe int nmatch = 0;
8aefbd756763807188d2e3ce336a8680e4893066wrowe int i;
8aefbd756763807188d2e3ce336a8680e4893066wrowe ap_regmatch_t *pmatch = NULL;
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe entry_config = sec_proxy[j];
8aefbd756763807188d2e3ce336a8680e4893066wrowe entry_proxy = ap_get_module_config(entry_config, &proxy_module);
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (entry_proxy->r) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (entry_proxy->refs && entry_proxy->refs->nelts) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (!rxpool) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe apr_pool_create(&rxpool, r->pool);
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe nmatch = entry_proxy->refs->nelts;
8aefbd756763807188d2e3ce336a8680e4893066wrowe pmatch = apr_palloc(rxpool, nmatch*sizeof(ap_regmatch_t));
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (ap_regexec(entry_proxy->r, proxyname, nmatch, pmatch, 0)) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe continue;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe for (i = 0; i < nmatch; i++) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (pmatch[i].rm_so >= 0 && pmatch[i].rm_eo >= 0 &&
8aefbd756763807188d2e3ce336a8680e4893066wrowe ((const char **)entry_proxy->refs->elts)[i]) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe apr_table_setn(r->subprocess_env,
8aefbd756763807188d2e3ce336a8680e4893066wrowe ((const char **)entry_proxy->refs->elts)[i],
8aefbd756763807188d2e3ce336a8680e4893066wrowe apr_pstrndup(r->pool,
8aefbd756763807188d2e3ce336a8680e4893066wrowe proxyname + pmatch[i].rm_so,
8aefbd756763807188d2e3ce336a8680e4893066wrowe pmatch[i].rm_eo - pmatch[i].rm_so));
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe else if (
8aefbd756763807188d2e3ce336a8680e4893066wrowe /* XXX: What about case insensitive matching ???
8aefbd756763807188d2e3ce336a8680e4893066wrowe * Compare regex, fnmatch or string as appropriate
8aefbd756763807188d2e3ce336a8680e4893066wrowe * If the entry doesn't relate, then continue
8aefbd756763807188d2e3ce336a8680e4893066wrowe */
8aefbd756763807188d2e3ce336a8680e4893066wrowe entry_proxy->p_is_fnmatch ? apr_fnmatch(entry_proxy->p,
8aefbd756763807188d2e3ce336a8680e4893066wrowe proxyname, 0) :
8aefbd756763807188d2e3ce336a8680e4893066wrowe strncmp(proxyname, entry_proxy->p,
8aefbd756763807188d2e3ce336a8680e4893066wrowe strlen(entry_proxy->p))) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe continue;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe per_dir_defaults = ap_merge_per_dir_configs(r->pool, per_dir_defaults,
8aefbd756763807188d2e3ce336a8680e4893066wrowe entry_config);
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe r->per_dir_config = per_dir_defaults;
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (rxpool) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe apr_pool_destroy(rxpool);
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe return OK;
8aefbd756763807188d2e3ce336a8680e4893066wrowe}
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowestatic int proxy_map_location(request_rec *r)
8aefbd756763807188d2e3ce336a8680e4893066wrowe{
8aefbd756763807188d2e3ce336a8680e4893066wrowe int access_status;
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (!r->proxyreq || !r->filename || strncmp(r->filename, "proxy:", 6) != 0)
8aefbd756763807188d2e3ce336a8680e4893066wrowe return DECLINED;
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe /* Don't let the core or mod_http map_to_storage hooks handle this,
8aefbd756763807188d2e3ce336a8680e4893066wrowe * We don't need directory/file_walk, and we want to TRACE on our own.
8aefbd756763807188d2e3ce336a8680e4893066wrowe */
8aefbd756763807188d2e3ce336a8680e4893066wrowe if ((access_status = proxy_walk(r))) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe ap_die(access_status, r);
8aefbd756763807188d2e3ce336a8680e4893066wrowe return access_status;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe return OK;
8aefbd756763807188d2e3ce336a8680e4893066wrowe}
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe/* -------------------------------------------------------------- */
8aefbd756763807188d2e3ce336a8680e4893066wrowe/* Fixup the filename */
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe/*
8aefbd756763807188d2e3ce336a8680e4893066wrowe * Canonicalise the URL
8aefbd756763807188d2e3ce336a8680e4893066wrowe */
8aefbd756763807188d2e3ce336a8680e4893066wrowestatic int proxy_fixup(request_rec *r)
8aefbd756763807188d2e3ce336a8680e4893066wrowe{
8aefbd756763807188d2e3ce336a8680e4893066wrowe char *url, *p;
8aefbd756763807188d2e3ce336a8680e4893066wrowe int access_status;
8aefbd756763807188d2e3ce336a8680e4893066wrowe proxy_dir_conf *dconf = ap_get_module_config(r->per_dir_config,
8aefbd756763807188d2e3ce336a8680e4893066wrowe &proxy_module);
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (!r->proxyreq || !r->filename || strncmp(r->filename, "proxy:", 6) != 0)
8aefbd756763807188d2e3ce336a8680e4893066wrowe return DECLINED;
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe /* XXX: Shouldn't we try this before we run the proxy_walk? */
8aefbd756763807188d2e3ce336a8680e4893066wrowe url = &r->filename[6];
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe if ((dconf->interpolate_env == 1) && (r->proxyreq == PROXYREQ_REVERSE)) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe /* create per-request copy of reverse proxy conf,
8aefbd756763807188d2e3ce336a8680e4893066wrowe * and interpolate vars in it
8aefbd756763807188d2e3ce336a8680e4893066wrowe */
8aefbd756763807188d2e3ce336a8680e4893066wrowe proxy_req_conf *rconf = apr_palloc(r->pool, sizeof(proxy_req_conf));
8aefbd756763807188d2e3ce336a8680e4893066wrowe ap_set_module_config(r->request_config, &proxy_module, rconf);
8aefbd756763807188d2e3ce336a8680e4893066wrowe rconf->raliases = proxy_vars(r, dconf->raliases);
8aefbd756763807188d2e3ce336a8680e4893066wrowe rconf->cookie_paths = proxy_vars(r, dconf->cookie_paths);
8aefbd756763807188d2e3ce336a8680e4893066wrowe rconf->cookie_domains = proxy_vars(r, dconf->cookie_domains);
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe /* canonicalise each specific scheme */
8aefbd756763807188d2e3ce336a8680e4893066wrowe if ((access_status = proxy_run_canon_handler(r, url))) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe return access_status;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe p = strchr(url, ':');
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (p == NULL || p == url)
8aefbd756763807188d2e3ce336a8680e4893066wrowe return HTTP_BAD_REQUEST;
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe return OK; /* otherwise; we've done the best we can */
8aefbd756763807188d2e3ce336a8680e4893066wrowe}
8aefbd756763807188d2e3ce336a8680e4893066wrowe/* Send a redirection if the request contains a hostname which is not */
8aefbd756763807188d2e3ce336a8680e4893066wrowe/* fully qualified, i.e. doesn't have a domain name appended. Some proxy */
8aefbd756763807188d2e3ce336a8680e4893066wrowe/* servers like Netscape's allow this and access hosts from the local */
8aefbd756763807188d2e3ce336a8680e4893066wrowe/* domain in this case. I think it is better to redirect to a FQDN, since */
8aefbd756763807188d2e3ce336a8680e4893066wrowe/* these will later be found in the bookmarks files. */
8aefbd756763807188d2e3ce336a8680e4893066wrowe/* The "ProxyDomain" directive determines what domain will be appended */
8aefbd756763807188d2e3ce336a8680e4893066wrowestatic int proxy_needsdomain(request_rec *r, const char *url, const char *domain)
8aefbd756763807188d2e3ce336a8680e4893066wrowe{
8aefbd756763807188d2e3ce336a8680e4893066wrowe char *nuri;
8aefbd756763807188d2e3ce336a8680e4893066wrowe const char *ref;
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe /* We only want to worry about GETs */
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (!r->proxyreq || r->method_number != M_GET || !r->parsed_uri.hostname)
8aefbd756763807188d2e3ce336a8680e4893066wrowe return DECLINED;
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe /* If host does contain a dot already, or it is "localhost", decline */
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (strchr(r->parsed_uri.hostname, '.') != NULL /* has domain, or IPv4 literal */
8aefbd756763807188d2e3ce336a8680e4893066wrowe || strchr(r->parsed_uri.hostname, ':') != NULL /* IPv6 literal */
8aefbd756763807188d2e3ce336a8680e4893066wrowe || strcasecmp(r->parsed_uri.hostname, "localhost") == 0)
8aefbd756763807188d2e3ce336a8680e4893066wrowe return DECLINED; /* host name has a dot already */
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe ref = apr_table_get(r->headers_in, "Referer");
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe /* Reassemble the request, but insert the domain after the host name */
8aefbd756763807188d2e3ce336a8680e4893066wrowe /* Note that the domain name always starts with a dot */
8aefbd756763807188d2e3ce336a8680e4893066wrowe r->parsed_uri.hostname = apr_pstrcat(r->pool, r->parsed_uri.hostname,
8aefbd756763807188d2e3ce336a8680e4893066wrowe domain, NULL);
8aefbd756763807188d2e3ce336a8680e4893066wrowe nuri = apr_uri_unparse(r->pool,
8aefbd756763807188d2e3ce336a8680e4893066wrowe &r->parsed_uri,
8aefbd756763807188d2e3ce336a8680e4893066wrowe APR_URI_UNP_REVEALPASSWORD);
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe apr_table_setn(r->headers_out, "Location", nuri);
8aefbd756763807188d2e3ce336a8680e4893066wrowe ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, APLOGNO(01138)
8aefbd756763807188d2e3ce336a8680e4893066wrowe "Domain missing: %s sent to %s%s%s", r->uri,
8aefbd756763807188d2e3ce336a8680e4893066wrowe apr_uri_unparse(r->pool, &r->parsed_uri,
8aefbd756763807188d2e3ce336a8680e4893066wrowe APR_URI_UNP_OMITUSERINFO),
8aefbd756763807188d2e3ce336a8680e4893066wrowe ref ? " from " : "", ref ? ref : "");
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe return HTTP_MOVED_PERMANENTLY;
8aefbd756763807188d2e3ce336a8680e4893066wrowe}
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe/* -------------------------------------------------------------- */
8aefbd756763807188d2e3ce336a8680e4893066wrowe/* Invoke handler */
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowestatic int proxy_handler(request_rec *r)
8aefbd756763807188d2e3ce336a8680e4893066wrowe{
8aefbd756763807188d2e3ce336a8680e4893066wrowe char *uri, *scheme, *p;
8aefbd756763807188d2e3ce336a8680e4893066wrowe const char *p2;
8aefbd756763807188d2e3ce336a8680e4893066wrowe void *sconf = r->server->module_config;
8aefbd756763807188d2e3ce336a8680e4893066wrowe proxy_server_conf *conf = (proxy_server_conf *)
8aefbd756763807188d2e3ce336a8680e4893066wrowe ap_get_module_config(sconf, &proxy_module);
8aefbd756763807188d2e3ce336a8680e4893066wrowe apr_array_header_t *proxies = conf->proxies;
8aefbd756763807188d2e3ce336a8680e4893066wrowe struct proxy_remote *ents = (struct proxy_remote *) proxies->elts;
8aefbd756763807188d2e3ce336a8680e4893066wrowe int i, rc, access_status;
8aefbd756763807188d2e3ce336a8680e4893066wrowe int direct_connect = 0;
8aefbd756763807188d2e3ce336a8680e4893066wrowe const char *str;
8aefbd756763807188d2e3ce336a8680e4893066wrowe apr_int64_t maxfwd;
8aefbd756763807188d2e3ce336a8680e4893066wrowe proxy_balancer *balancer = NULL;
8aefbd756763807188d2e3ce336a8680e4893066wrowe proxy_worker *worker = NULL;
8aefbd756763807188d2e3ce336a8680e4893066wrowe int attempts = 0, max_attempts = 0;
8aefbd756763807188d2e3ce336a8680e4893066wrowe struct dirconn_entry *list = (struct dirconn_entry *)conf->dirconn->elts;
8aefbd756763807188d2e3ce336a8680e4893066wrowe int saved_status;
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe /* is this for us? */
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (!r->filename) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe return DECLINED;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (!r->proxyreq) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe /* We may have forced the proxy handler via config or .htaccess */
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (r->handler &&
8aefbd756763807188d2e3ce336a8680e4893066wrowe strncmp(r->handler, "proxy:", 6) == 0 &&
8aefbd756763807188d2e3ce336a8680e4893066wrowe strncmp(r->filename, "proxy:", 6) != 0) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe r->proxyreq = PROXYREQ_REVERSE;
8aefbd756763807188d2e3ce336a8680e4893066wrowe r->filename = apr_pstrcat(r->pool, r->handler, r->filename, NULL);
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe else {
8aefbd756763807188d2e3ce336a8680e4893066wrowe return DECLINED;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe } else if (strncmp(r->filename, "proxy:", 6) != 0) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe return DECLINED;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe /* handle max-forwards / OPTIONS / TRACE */
8aefbd756763807188d2e3ce336a8680e4893066wrowe if ((str = apr_table_get(r->headers_in, "Max-Forwards"))) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe char *end;
8aefbd756763807188d2e3ce336a8680e4893066wrowe maxfwd = apr_strtoi64(str, &end, 10);
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (maxfwd < 0 || maxfwd == APR_INT64_MAX || *end) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe return ap_proxyerror(r, HTTP_BAD_REQUEST,
8aefbd756763807188d2e3ce336a8680e4893066wrowe apr_psprintf(r->pool,
8aefbd756763807188d2e3ce336a8680e4893066wrowe "Max-Forwards value '%s' could not be parsed", str));
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe else if (maxfwd == 0) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe switch (r->method_number) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe case M_TRACE: {
8aefbd756763807188d2e3ce336a8680e4893066wrowe int access_status;
8aefbd756763807188d2e3ce336a8680e4893066wrowe r->proxyreq = PROXYREQ_NONE;
8aefbd756763807188d2e3ce336a8680e4893066wrowe if ((access_status = ap_send_http_trace(r)))
8aefbd756763807188d2e3ce336a8680e4893066wrowe ap_die(access_status, r);
8aefbd756763807188d2e3ce336a8680e4893066wrowe else
8aefbd756763807188d2e3ce336a8680e4893066wrowe ap_finalize_request_protocol(r);
8aefbd756763807188d2e3ce336a8680e4893066wrowe return OK;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe case M_OPTIONS: {
8aefbd756763807188d2e3ce336a8680e4893066wrowe int access_status;
8aefbd756763807188d2e3ce336a8680e4893066wrowe r->proxyreq = PROXYREQ_NONE;
8aefbd756763807188d2e3ce336a8680e4893066wrowe if ((access_status = ap_send_http_options(r)))
8aefbd756763807188d2e3ce336a8680e4893066wrowe ap_die(access_status, r);
8aefbd756763807188d2e3ce336a8680e4893066wrowe else
8aefbd756763807188d2e3ce336a8680e4893066wrowe ap_finalize_request_protocol(r);
8aefbd756763807188d2e3ce336a8680e4893066wrowe return OK;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe default: {
8aefbd756763807188d2e3ce336a8680e4893066wrowe return ap_proxyerror(r, HTTP_BAD_REQUEST,
8aefbd756763807188d2e3ce336a8680e4893066wrowe "Max-Forwards has reached zero - proxy loop?");
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe maxfwd = (maxfwd > 0) ? maxfwd - 1 : 0;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe else {
8aefbd756763807188d2e3ce336a8680e4893066wrowe /* set configured max-forwards */
8aefbd756763807188d2e3ce336a8680e4893066wrowe maxfwd = conf->maxfwd;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (maxfwd >= 0) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe apr_table_setn(r->headers_in, "Max-Forwards",
8aefbd756763807188d2e3ce336a8680e4893066wrowe apr_psprintf(r->pool, "%" APR_INT64_T_FMT, maxfwd));
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (r->method_number == M_TRACE) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe core_server_config *coreconf = (core_server_config *)
8aefbd756763807188d2e3ce336a8680e4893066wrowe ap_get_core_module_config(sconf);
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (coreconf->trace_enable == AP_TRACE_DISABLE)
8aefbd756763807188d2e3ce336a8680e4893066wrowe {
8aefbd756763807188d2e3ce336a8680e4893066wrowe /* Allow "error-notes" string to be printed by ap_send_error_response()
8aefbd756763807188d2e3ce336a8680e4893066wrowe * Note; this goes nowhere, canned error response need an overhaul.
8aefbd756763807188d2e3ce336a8680e4893066wrowe */
8aefbd756763807188d2e3ce336a8680e4893066wrowe apr_table_setn(r->notes, "error-notes",
8aefbd756763807188d2e3ce336a8680e4893066wrowe "TRACE forbidden by server configuration");
8aefbd756763807188d2e3ce336a8680e4893066wrowe apr_table_setn(r->notes, "verbose-error-to", "*");
8aefbd756763807188d2e3ce336a8680e4893066wrowe ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01139)
8aefbd756763807188d2e3ce336a8680e4893066wrowe "TRACE forbidden by server configuration");
8aefbd756763807188d2e3ce336a8680e4893066wrowe return HTTP_METHOD_NOT_ALLOWED;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe /* Can't test ap_should_client_block, we aren't ready to send
8aefbd756763807188d2e3ce336a8680e4893066wrowe * the client a 100 Continue response till the connection has
8aefbd756763807188d2e3ce336a8680e4893066wrowe * been established
8aefbd756763807188d2e3ce336a8680e4893066wrowe */
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (coreconf->trace_enable != AP_TRACE_EXTENDED
8aefbd756763807188d2e3ce336a8680e4893066wrowe && (r->read_length || r->read_chunked || r->remaining))
8aefbd756763807188d2e3ce336a8680e4893066wrowe {
8aefbd756763807188d2e3ce336a8680e4893066wrowe /* Allow "error-notes" string to be printed by ap_send_error_response()
8aefbd756763807188d2e3ce336a8680e4893066wrowe * Note; this goes nowhere, canned error response need an overhaul.
8aefbd756763807188d2e3ce336a8680e4893066wrowe */
8aefbd756763807188d2e3ce336a8680e4893066wrowe apr_table_setn(r->notes, "error-notes",
8aefbd756763807188d2e3ce336a8680e4893066wrowe "TRACE with request body is not allowed");
8aefbd756763807188d2e3ce336a8680e4893066wrowe apr_table_setn(r->notes, "verbose-error-to", "*");
8aefbd756763807188d2e3ce336a8680e4893066wrowe ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01140)
8aefbd756763807188d2e3ce336a8680e4893066wrowe "TRACE with request body is not allowed");
8aefbd756763807188d2e3ce336a8680e4893066wrowe return HTTP_REQUEST_ENTITY_TOO_LARGE;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe uri = r->filename + 6;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb p = strchr(uri, ':');
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (p == NULL) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01141)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "proxy_handler no URL in %s", r->filename);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return HTTP_BAD_REQUEST;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* If the host doesn't have a domain name, add one and redirect. */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (conf->domain != NULL) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb rc = proxy_needsdomain(r, uri, conf->domain);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (ap_is_HTTP_REDIRECT(rc))
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return HTTP_MOVED_PERMANENTLY;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb scheme = apr_pstrndup(r->pool, uri, p - uri);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Check URI's destination host against NoProxy hosts */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Bypass ProxyRemote server lookup if configured as NoProxy */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb for (direct_connect = i = 0; i < conf->dirconn->nelts &&
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb !direct_connect; i++) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb direct_connect = list[i].matcher(&list[i], r);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#if DEBUGGING
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb (direct_connect) ? "NoProxy for %s" : "UseProxy for %s",
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb r->uri);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#endif
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb do {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb char *url = uri;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Try to obtain the most suitable worker */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb access_status = ap_proxy_pre_request(&worker, &balancer, r, conf, &url);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (access_status != OK) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /*
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Only return if access_status is not HTTP_SERVICE_UNAVAILABLE
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * This gives other modules the chance to hook into the
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * request_status hook and decide what to do in this situation.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (access_status != HTTP_SERVICE_UNAVAILABLE)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return access_status;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /*
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Ensure that balancer is NULL if worker is NULL to prevent
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * potential problems in the post_request hook.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (!worker)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb balancer = NULL;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb goto cleanup;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Initialise worker if needed, note the shared area must be initialized by the balancer logic */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (balancer) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_proxy_initialize_worker(worker, r->server, conf->pool);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (balancer && balancer->s->max_attempts_set && !max_attempts)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb max_attempts = balancer->s->max_attempts;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* firstly, try a proxy, unless a NoProxy directive is active */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (!direct_connect) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb for (i = 0; i < proxies->nelts; i++) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb p2 = ap_strchr_c(ents[i].scheme, ':'); /* is it a partial URL? */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (strcmp(ents[i].scheme, "*") == 0 ||
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb (ents[i].use_regex &&
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_regexec(ents[i].regexp, url, 0, NULL, 0) == 0) ||
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb (p2 == NULL && strcasecmp(scheme, ents[i].scheme) == 0) ||
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb (p2 != NULL &&
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb strncasecmp(url, ents[i].scheme,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb strlen(ents[i].scheme)) == 0)) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* handle the scheme */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01142)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "Trying to run scheme_handler against proxy");
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb access_status = proxy_run_scheme_handler(r, worker,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb conf, url,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ents[i].hostname,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ents[i].port);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Did the scheme handler process the request? */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (access_status != DECLINED) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb const char *cl_a;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb char *end;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb apr_off_t cl;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /*
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * An fatal error or success, so no point in
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * retrying with a direct connection.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (access_status != HTTP_BAD_GATEWAY) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb goto cleanup;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb cl_a = apr_table_get(r->headers_in, "Content-Length");
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (cl_a) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb apr_strtoff(&cl, cl_a, &end, 10);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /*
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * The request body is of length > 0. We cannot
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * retry with a direct connection since we already
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * sent (parts of) the request body to the proxy
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * and do not have any longer.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (cl > 0) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb goto cleanup;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /*
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Transfer-Encoding was set as input header, so we had
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * a request body. We cannot retry with a direct
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * connection for the same reason as above.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (apr_table_get(r->headers_in, "Transfer-Encoding")) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb goto cleanup;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* otherwise, try it direct */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* N.B. what if we're behind a firewall, where we must use a proxy or
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * give up??
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* handle the scheme */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01143)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "Running scheme %s handler (attempt %d)",
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb scheme, attempts);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb AP_PROXY_RUN(r, worker, conf, url, attempts);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb access_status = proxy_run_scheme_handler(r, worker, conf,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb url, NULL, 0);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (access_status == OK)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb break;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else if (access_status == HTTP_INTERNAL_SERVER_ERROR) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Unrecoverable server error.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * We can not failover to another worker.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Mark the worker as unusable if member of load balancer
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (balancer) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb worker->s->status |= PROXY_WORKER_IN_ERROR;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb worker->s->error_time = apr_time_now();
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb break;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else if (access_status == HTTP_SERVICE_UNAVAILABLE) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Recoverable server error.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * We can failover to another worker
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Mark the worker as unusable if member of load balancer
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (balancer) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb worker->s->status |= PROXY_WORKER_IN_ERROR;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb worker->s->error_time = apr_time_now();
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Unrecoverable error.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * Return the origin status code to the client.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb break;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Try again if the worker is unusable and the service is
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * unavailable.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb } while (!PROXY_WORKER_IS_USABLE(worker) &&
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb max_attempts > attempts++);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe if (DECLINED == access_status) {
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, APLOGNO(01144)
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe "No protocol handler was valid for the URL %s. "
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe "If you are using a DSO version of mod_proxy, make sure "
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe "the proxy submodules are included in the configuration "
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe "using LoadModule.", r->uri);
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe access_status = HTTP_INTERNAL_SERVER_ERROR;
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe goto cleanup;
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe }
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowecleanup:
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe /*
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe * Save current r->status and set it to the value of access_status which
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe * might be different (e.g. r->status could be HTTP_OK if e.g. we override
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe * the error page on the proxy or if the error was not generated by the
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe * backend itself but by the proxy e.g. a bad gateway) in order to give
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe * ap_proxy_post_request a chance to act correctly on the status code.
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe */
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe saved_status = r->status;
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe r->status = access_status;
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe ap_proxy_post_request(worker, balancer, r, conf);
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe /*
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe * Only restore r->status if it has not been changed by
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe * ap_proxy_post_request as we assume that this change was intentional.
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe */
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe if (r->status == access_status) {
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe r->status = saved_status;
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe }
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe proxy_run_request_status(&access_status, r);
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe AP_PROXY_RUN_FINISHED(r, attempts, access_status);
1067418d9ed9ed9daeb3ca4f74e72db810c49833wrowe
1067418d9ed9ed9daeb3ca4f74e72db810c49833wrowe return access_status;
1067418d9ed9ed9daeb3ca4f74e72db810c49833wrowe}
1067418d9ed9ed9daeb3ca4f74e72db810c49833wrowe
1067418d9ed9ed9daeb3ca4f74e72db810c49833wrowe/* -------------------------------------------------------------- */
1067418d9ed9ed9daeb3ca4f74e72db810c49833wrowe/* Setup configurable data */
1067418d9ed9ed9daeb3ca4f74e72db810c49833wrowe
1067418d9ed9ed9daeb3ca4f74e72db810c49833wrowestatic void * create_proxy_config(apr_pool_t *p, server_rec *s)
1067418d9ed9ed9daeb3ca4f74e72db810c49833wrowe{
1067418d9ed9ed9daeb3ca4f74e72db810c49833wrowe proxy_server_conf *ps = apr_pcalloc(p, sizeof(proxy_server_conf));
1067418d9ed9ed9daeb3ca4f74e72db810c49833wrowe
1067418d9ed9ed9daeb3ca4f74e72db810c49833wrowe ps->sec_proxy = apr_array_make(p, 10, sizeof(ap_conf_vector_t *));
1067418d9ed9ed9daeb3ca4f74e72db810c49833wrowe ps->proxies = apr_array_make(p, 10, sizeof(struct proxy_remote));
1067418d9ed9ed9daeb3ca4f74e72db810c49833wrowe ps->aliases = apr_array_make(p, 10, sizeof(struct proxy_alias));
1067418d9ed9ed9daeb3ca4f74e72db810c49833wrowe ps->noproxies = apr_array_make(p, 10, sizeof(struct noproxy_entry));
1067418d9ed9ed9daeb3ca4f74e72db810c49833wrowe ps->dirconn = apr_array_make(p, 10, sizeof(struct dirconn_entry));
1067418d9ed9ed9daeb3ca4f74e72db810c49833wrowe ps->workers = apr_array_make(p, 10, sizeof(proxy_worker));
1067418d9ed9ed9daeb3ca4f74e72db810c49833wrowe ps->balancers = apr_array_make(p, 10, sizeof(proxy_balancer));
1067418d9ed9ed9daeb3ca4f74e72db810c49833wrowe ps->forward = NULL;
1067418d9ed9ed9daeb3ca4f74e72db810c49833wrowe ps->reverse = NULL;
1067418d9ed9ed9daeb3ca4f74e72db810c49833wrowe ps->domain = NULL;
1067418d9ed9ed9daeb3ca4f74e72db810c49833wrowe ps->id = apr_psprintf(p, "p%x", 1); /* simply for storage size */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ps->viaopt = via_off; /* initially backward compatible with 1.3.1 */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ps->viaopt_set = 0; /* 0 means default */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ps->req = 0;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ps->max_balancers = 0;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ps->bal_persist = 0;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ps->inherit = 1;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ps->inherit_set = 0;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ps->ppinherit = 1;
4ca6cbe768b4e0917ac0b76333c26a7d5396d454trawick ps->ppinherit_set = 0;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ps->bgrowth = 5;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ps->bgrowth_set = 0;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ps->req_set = 0;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ps->recv_buffer_size = 0; /* this default was left unset for some reason */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ps->recv_buffer_size_set = 0;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ps->io_buffer_size = AP_IOBUFSIZE;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ps->io_buffer_size_set = 0;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ps->maxfwd = DEFAULT_MAX_FORWARDS;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ps->maxfwd_set = 0;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ps->timeout = 0;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ps->timeout_set = 0;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ps->badopt = bad_error;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ps->badopt_set = 0;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ps->source_address = NULL;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ps->source_address_set = 0;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb apr_pool_create_ex(&ps->pool, p, NULL, NULL);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return ps;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic void * merge_proxy_config(apr_pool_t *p, void *basev, void *overridesv)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb proxy_server_conf *ps = apr_pcalloc(p, sizeof(proxy_server_conf));
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe proxy_server_conf *base = (proxy_server_conf *) basev;
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe proxy_server_conf *overrides = (proxy_server_conf *) overridesv;
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe ps->inherit = (overrides->inherit_set == 0) ? base->inherit : overrides->inherit;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ps->inherit_set = overrides->inherit_set || base->inherit_set;
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe ps->ppinherit = (overrides->ppinherit_set == 0) ? base->ppinherit : overrides->ppinherit;
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe ps->ppinherit_set = overrides->ppinherit_set || base->ppinherit_set;
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe if (ps->ppinherit) {
1b839c67d5c0e4b1f22b44a4217f9860b420d47cwrowe ps->proxies = apr_array_append(p, base->proxies, overrides->proxies);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe else {
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe ps->proxies = overrides->proxies;
b45c1c292ff1fa635004ae81fa691f8cb3cdda85rbb }
b45c1c292ff1fa635004ae81fa691f8cb3cdda85rbb ps->sec_proxy = apr_array_append(p, base->sec_proxy, overrides->sec_proxy);
b45c1c292ff1fa635004ae81fa691f8cb3cdda85rbb ps->aliases = apr_array_append(p, base->aliases, overrides->aliases);
b45c1c292ff1fa635004ae81fa691f8cb3cdda85rbb ps->noproxies = apr_array_append(p, base->noproxies, overrides->noproxies);
b45c1c292ff1fa635004ae81fa691f8cb3cdda85rbb ps->dirconn = apr_array_append(p, base->dirconn, overrides->dirconn);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (ps->inherit || ps->ppinherit) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ps->workers = apr_array_append(p, base->workers, overrides->workers);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ps->balancers = apr_array_append(p, base->balancers, overrides->balancers);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ps->workers = overrides->workers;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ps->balancers = overrides->balancers;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ps->forward = overrides->forward ? overrides->forward : base->forward;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ps->reverse = overrides->reverse ? overrides->reverse : base->reverse;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ps->domain = (overrides->domain == NULL) ? base->domain : overrides->domain;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ps->id = (overrides->id == NULL) ? base->id : overrides->id;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ps->viaopt = (overrides->viaopt_set == 0) ? base->viaopt : overrides->viaopt;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ps->viaopt_set = overrides->viaopt_set || base->viaopt_set;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ps->req = (overrides->req_set == 0) ? base->req : overrides->req;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ps->req_set = overrides->req_set || base->req_set;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ps->bgrowth = (overrides->bgrowth_set == 0) ? base->bgrowth : overrides->bgrowth;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ps->bgrowth_set = overrides->bgrowth_set || base->bgrowth_set;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ps->max_balancers = overrides->max_balancers || base->max_balancers;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ps->bal_persist = overrides->bal_persist;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ps->recv_buffer_size = (overrides->recv_buffer_size_set == 0) ? base->recv_buffer_size : overrides->recv_buffer_size;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ps->recv_buffer_size_set = overrides->recv_buffer_size_set || base->recv_buffer_size_set;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ps->io_buffer_size = (overrides->io_buffer_size_set == 0) ? base->io_buffer_size : overrides->io_buffer_size;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ps->io_buffer_size_set = overrides->io_buffer_size_set || base->io_buffer_size_set;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ps->maxfwd = (overrides->maxfwd_set == 0) ? base->maxfwd : overrides->maxfwd;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ps->maxfwd_set = overrides->maxfwd_set || base->maxfwd_set;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ps->timeout = (overrides->timeout_set == 0) ? base->timeout : overrides->timeout;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ps->timeout_set = overrides->timeout_set || base->timeout_set;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ps->badopt = (overrides->badopt_set == 0) ? base->badopt : overrides->badopt;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ps->badopt_set = overrides->badopt_set || base->badopt_set;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ps->proxy_status = (overrides->proxy_status_set == 0) ? base->proxy_status : overrides->proxy_status;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ps->proxy_status_set = overrides->proxy_status_set || base->proxy_status_set;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ps->source_address = (overrides->source_address_set == 0) ? base->source_address : overrides->source_address;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ps->source_address_set = overrides->source_address_set || base->source_address_set;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ps->pool = base->pool;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return ps;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic const char *set_source_address(cmd_parms *parms, void *dummy,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb const char *arg)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb proxy_server_conf *psf =
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_get_module_config(parms->server->module_config, &proxy_module);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb struct apr_sockaddr_t *addr;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
1067418d9ed9ed9daeb3ca4f74e72db810c49833wrowe if (APR_SUCCESS == apr_sockaddr_info_get(&addr, arg, APR_UNSPEC, 0, 0,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb psf->pool)) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb psf->source_address = addr;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb psf->source_address_set = 1;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return "ProxySourceAddress invalid value";
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return NULL;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic void *create_proxy_dir_config(apr_pool_t *p, char *dummy)
efa1a34b0a7785fc72863eff175b0cfc1ecb0e38wrowe{
117026201e6d8fe7d82416b8a7324830f5a87292wrowe proxy_dir_conf *new =
117026201e6d8fe7d82416b8a7324830f5a87292wrowe (proxy_dir_conf *) apr_pcalloc(p, sizeof(proxy_dir_conf));
117026201e6d8fe7d82416b8a7324830f5a87292wrowe
efa1a34b0a7785fc72863eff175b0cfc1ecb0e38wrowe /* Filled in by proxysection, when applicable */
117026201e6d8fe7d82416b8a7324830f5a87292wrowe
117026201e6d8fe7d82416b8a7324830f5a87292wrowe /* Put these in the dir config so they work inside <Location> */
117026201e6d8fe7d82416b8a7324830f5a87292wrowe new->raliases = apr_array_make(p, 10, sizeof(struct proxy_alias));
117026201e6d8fe7d82416b8a7324830f5a87292wrowe new->cookie_paths = apr_array_make(p, 10, sizeof(struct proxy_alias));
117026201e6d8fe7d82416b8a7324830f5a87292wrowe new->cookie_domains = apr_array_make(p, 10, sizeof(struct proxy_alias));
117026201e6d8fe7d82416b8a7324830f5a87292wrowe new->preserve_host_set = 0;
117026201e6d8fe7d82416b8a7324830f5a87292wrowe new->preserve_host = 0;
117026201e6d8fe7d82416b8a7324830f5a87292wrowe new->interpolate_env = -1; /* unset */
117026201e6d8fe7d82416b8a7324830f5a87292wrowe new->error_override = 0;
117026201e6d8fe7d82416b8a7324830f5a87292wrowe new->error_override_set = 0;
117026201e6d8fe7d82416b8a7324830f5a87292wrowe new->add_forwarded_headers = 1;
117026201e6d8fe7d82416b8a7324830f5a87292wrowe
117026201e6d8fe7d82416b8a7324830f5a87292wrowe return (void *) new;
117026201e6d8fe7d82416b8a7324830f5a87292wrowe}
117026201e6d8fe7d82416b8a7324830f5a87292wrowe
55eb5bb774cfb861542b827fbf4c30e6efbbfc44wrowestatic void *merge_proxy_dir_config(apr_pool_t *p, void *basev, void *addv)
117026201e6d8fe7d82416b8a7324830f5a87292wrowe{
117026201e6d8fe7d82416b8a7324830f5a87292wrowe proxy_dir_conf *new = (proxy_dir_conf *) apr_pcalloc(p, sizeof(proxy_dir_conf));
117026201e6d8fe7d82416b8a7324830f5a87292wrowe proxy_dir_conf *add = (proxy_dir_conf *) addv;
117026201e6d8fe7d82416b8a7324830f5a87292wrowe proxy_dir_conf *base = (proxy_dir_conf *) basev;
117026201e6d8fe7d82416b8a7324830f5a87292wrowe
117026201e6d8fe7d82416b8a7324830f5a87292wrowe new->p = add->p;
117026201e6d8fe7d82416b8a7324830f5a87292wrowe new->p_is_fnmatch = add->p_is_fnmatch;
117026201e6d8fe7d82416b8a7324830f5a87292wrowe new->r = add->r;
117026201e6d8fe7d82416b8a7324830f5a87292wrowe new->refs = add->refs;
117026201e6d8fe7d82416b8a7324830f5a87292wrowe
117026201e6d8fe7d82416b8a7324830f5a87292wrowe /* Put these in the dir config so they work inside <Location> */
117026201e6d8fe7d82416b8a7324830f5a87292wrowe new->raliases = apr_array_append(p, base->raliases, add->raliases);
117026201e6d8fe7d82416b8a7324830f5a87292wrowe new->cookie_paths
efa1a34b0a7785fc72863eff175b0cfc1ecb0e38wrowe = apr_array_append(p, base->cookie_paths, add->cookie_paths);
117026201e6d8fe7d82416b8a7324830f5a87292wrowe new->cookie_domains
117026201e6d8fe7d82416b8a7324830f5a87292wrowe = apr_array_append(p, base->cookie_domains, add->cookie_domains);
117026201e6d8fe7d82416b8a7324830f5a87292wrowe new->interpolate_env = (add->interpolate_env == -1) ? base->interpolate_env
117026201e6d8fe7d82416b8a7324830f5a87292wrowe : add->interpolate_env;
117026201e6d8fe7d82416b8a7324830f5a87292wrowe new->preserve_host = (add->preserve_host_set == 0) ? base->preserve_host
117026201e6d8fe7d82416b8a7324830f5a87292wrowe : add->preserve_host;
117026201e6d8fe7d82416b8a7324830f5a87292wrowe new->preserve_host_set = add->preserve_host_set || base->preserve_host_set;
efa1a34b0a7785fc72863eff175b0cfc1ecb0e38wrowe new->error_override = (add->error_override_set == 0) ? base->error_override
117026201e6d8fe7d82416b8a7324830f5a87292wrowe : add->error_override;
117026201e6d8fe7d82416b8a7324830f5a87292wrowe new->error_override_set = add->error_override_set || base->error_override_set;
117026201e6d8fe7d82416b8a7324830f5a87292wrowe new->alias = (add->alias_set == 0) ? base->alias : add->alias;
117026201e6d8fe7d82416b8a7324830f5a87292wrowe new->alias_set = add->alias_set || base->alias_set;
117026201e6d8fe7d82416b8a7324830f5a87292wrowe new->add_forwarded_headers = add->add_forwarded_headers;
117026201e6d8fe7d82416b8a7324830f5a87292wrowe return new;
117026201e6d8fe7d82416b8a7324830f5a87292wrowe}
117026201e6d8fe7d82416b8a7324830f5a87292wrowe
117026201e6d8fe7d82416b8a7324830f5a87292wrowestatic const char *
117026201e6d8fe7d82416b8a7324830f5a87292wrowe add_proxy(cmd_parms *cmd, void *dummy, const char *f1, const char *r1, int regex)
117026201e6d8fe7d82416b8a7324830f5a87292wrowe{
117026201e6d8fe7d82416b8a7324830f5a87292wrowe server_rec *s = cmd->server;
117026201e6d8fe7d82416b8a7324830f5a87292wrowe proxy_server_conf *conf =
117026201e6d8fe7d82416b8a7324830f5a87292wrowe (proxy_server_conf *) ap_get_module_config(s->module_config, &proxy_module);
117026201e6d8fe7d82416b8a7324830f5a87292wrowe struct proxy_remote *new;
117026201e6d8fe7d82416b8a7324830f5a87292wrowe char *p, *q;
117026201e6d8fe7d82416b8a7324830f5a87292wrowe char *r, *f, *scheme;
117026201e6d8fe7d82416b8a7324830f5a87292wrowe ap_regex_t *reg = NULL;
117026201e6d8fe7d82416b8a7324830f5a87292wrowe int port;
117026201e6d8fe7d82416b8a7324830f5a87292wrowe
117026201e6d8fe7d82416b8a7324830f5a87292wrowe r = apr_pstrdup(cmd->pool, r1);
117026201e6d8fe7d82416b8a7324830f5a87292wrowe scheme = apr_pstrdup(cmd->pool, r1);
117026201e6d8fe7d82416b8a7324830f5a87292wrowe f = apr_pstrdup(cmd->pool, f1);
117026201e6d8fe7d82416b8a7324830f5a87292wrowe p = strchr(r, ':');
117026201e6d8fe7d82416b8a7324830f5a87292wrowe if (p == NULL || p[1] != '/' || p[2] != '/' || p[3] == '\0') {
117026201e6d8fe7d82416b8a7324830f5a87292wrowe if (regex)
117026201e6d8fe7d82416b8a7324830f5a87292wrowe return "ProxyRemoteMatch: Bad syntax for a remote proxy server";
117026201e6d8fe7d82416b8a7324830f5a87292wrowe else
117026201e6d8fe7d82416b8a7324830f5a87292wrowe return "ProxyRemote: Bad syntax for a remote proxy server";
117026201e6d8fe7d82416b8a7324830f5a87292wrowe }
117026201e6d8fe7d82416b8a7324830f5a87292wrowe else {
117026201e6d8fe7d82416b8a7324830f5a87292wrowe scheme[p-r] = 0;
117026201e6d8fe7d82416b8a7324830f5a87292wrowe }
117026201e6d8fe7d82416b8a7324830f5a87292wrowe q = strchr(p + 3, ':');
117026201e6d8fe7d82416b8a7324830f5a87292wrowe if (q != NULL) {
117026201e6d8fe7d82416b8a7324830f5a87292wrowe if (sscanf(q + 1, "%u", &port) != 1 || port > 65535) {
117026201e6d8fe7d82416b8a7324830f5a87292wrowe if (regex)
117026201e6d8fe7d82416b8a7324830f5a87292wrowe return "ProxyRemoteMatch: Bad syntax for a remote proxy server (bad port number)";
117026201e6d8fe7d82416b8a7324830f5a87292wrowe else
117026201e6d8fe7d82416b8a7324830f5a87292wrowe return "ProxyRemote: Bad syntax for a remote proxy server (bad port number)";
117026201e6d8fe7d82416b8a7324830f5a87292wrowe }
117026201e6d8fe7d82416b8a7324830f5a87292wrowe *q = '\0';
1067418d9ed9ed9daeb3ca4f74e72db810c49833wrowe }
1067418d9ed9ed9daeb3ca4f74e72db810c49833wrowe else
1067418d9ed9ed9daeb3ca4f74e72db810c49833wrowe port = -1;
1067418d9ed9ed9daeb3ca4f74e72db810c49833wrowe *p = '\0';
1067418d9ed9ed9daeb3ca4f74e72db810c49833wrowe if (regex) {
117026201e6d8fe7d82416b8a7324830f5a87292wrowe reg = ap_pregcomp(cmd->pool, f, AP_REG_EXTENDED);
117026201e6d8fe7d82416b8a7324830f5a87292wrowe if (!reg)
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe return "Regular expression for ProxyRemoteMatch could not be compiled.";
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe }
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe else
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (strchr(f, ':') == NULL)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_str_tolower(f); /* lowercase scheme */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_str_tolower(p + 3); /* lowercase hostname */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (port == -1) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb port = apr_uri_port_of_scheme(scheme);
1b839c67d5c0e4b1f22b44a4217f9860b420d47cwrowe }
b45c1c292ff1fa635004ae81fa691f8cb3cdda85rbb
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe new = apr_array_push(conf->proxies);
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe new->scheme = f;
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe new->protocol = r;
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe new->hostname = p + 3;
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe new->port = port;
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe new->regexp = reg;
b45c1c292ff1fa635004ae81fa691f8cb3cdda85rbb new->use_regex = regex;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return NULL;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic const char *
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb add_proxy_noregex(cmd_parms *cmd, void *dummy, const char *f1, const char *r1)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return add_proxy(cmd, dummy, f1, r1, 0);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic const char *
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb add_proxy_regex(cmd_parms *cmd, void *dummy, const char *f1, const char *r1)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return add_proxy(cmd, dummy, f1, r1, 1);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic char *de_socketfy(apr_pool_t *p, char *url)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb char *ptr;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /*
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * We could be passed a URL during the config stage that contains
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * the UDS path... ignore it
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (!strncasecmp(url, "unix:", 5) &&
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ((ptr = ap_strchr(url, '|')) != NULL)) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* move past the 'unix:...|' UDS path info */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb char *ret, *c;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ret = ptr + 1;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* special case: "unix:....|scheme:" is OK, expand
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * to "unix:....|scheme://localhost"
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb c = ap_strchr(ret, ':');
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (c == NULL) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return NULL;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (c[1] == '\0') {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return apr_pstrcat(p, ret, "//localhost", NULL);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return ret;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return url;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic const char *
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb add_pass(cmd_parms *cmd, void *dummy, const char *arg, int is_regex)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb proxy_dir_conf *dconf = (proxy_dir_conf *)dummy;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb server_rec *s = cmd->server;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb proxy_server_conf *conf =
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb (proxy_server_conf *) ap_get_module_config(s->module_config, &proxy_module);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb struct proxy_alias *new;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb char *f = cmd->path;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb char *r = NULL;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb char *word;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb apr_table_t *params = apr_table_make(cmd->pool, 5);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb const apr_array_header_t *arr;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb const apr_table_entry_t *elts;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb int i;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb int use_regex = is_regex;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb unsigned int flags = 0;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb const char *err;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb err = ap_check_cmd_context(cmd, NOT_IN_DIRECTORY|NOT_IN_FILES);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (err) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return err;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb while (*arg) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb word = ap_getword_conf(cmd->pool, &arg);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (!f) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (!strcmp(word, "~")) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (is_regex) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return "ProxyPassMatch invalid syntax ('~' usage).";
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb use_regex = 1;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb continue;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb f = word;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else if (!r) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb r = word;
1067418d9ed9ed9daeb3ca4f74e72db810c49833wrowe }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else if (!strcasecmp(word,"nocanon")) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb flags |= PROXYPASS_NOCANON;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else if (!strcasecmp(word,"interpolate")) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb flags |= PROXYPASS_INTERPOLATE;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else if (!strcasecmp(word,"noquery")) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb flags |= PROXYPASS_NOQUERY;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb char *val = strchr(word, '=');
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (!val) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (cmd->path) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (*r == '/') {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return "ProxyPass|ProxyPassMatch can not have a path when defined in "
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "a location.";
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return "Invalid ProxyPass|ProxyPassMatch parameter. Parameter must "
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "be in the form 'key=value'.";
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return "Invalid ProxyPass|ProxyPassMatch parameter. Parameter must be "
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "in the form 'key=value'.";
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb *val++ = '\0';
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb apr_table_setn(params, word, val);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb };
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (r == NULL) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return "ProxyPass|ProxyPassMatch needs a path when not defined in a location";
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* if per directory, save away the single alias */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (cmd->path) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb dconf->alias = apr_pcalloc(cmd->pool, sizeof(struct proxy_alias));
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb dconf->alias_set = 1;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb new = dconf->alias;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (apr_fnmatch_test(f)) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb use_regex = 1;
}
}
/* if per server, add to the alias array */
else {
new = apr_array_push(conf->aliases);
}
new->fake = apr_pstrdup(cmd->pool, f);
new->real = apr_pstrdup(cmd->pool, de_socketfy(cmd->pool, r));
new->flags = flags;
if (use_regex) {
new->regex = ap_pregcomp(cmd->pool, f, AP_REG_EXTENDED);
if (new->regex == NULL)
return "Regular expression could not be compiled.";
}
else {
new->regex = NULL;
}
if (r[0] == '!' && r[1] == '\0')
return NULL;
arr = apr_table_elts(params);
elts = (const apr_table_entry_t *)arr->elts;
/* Distinguish the balancer from worker */
if (ap_proxy_valid_balancer_name(r, 9)) {
proxy_balancer *balancer = ap_proxy_get_balancer(cmd->pool, conf, r, 0);
char *fake_copy;
/*
* In the regex case supplying a fake URL doesn't make sense as it
* cannot be parsed anyway with apr_uri_parse later on in
* ap_proxy_define_balancer / ap_proxy_update_balancer
*/
if (use_regex) {
fake_copy = NULL;
}
else {
fake_copy = f;
}
if (!balancer) {
const char *err = ap_proxy_define_balancer(cmd->pool, &balancer, conf, r, fake_copy, 0);
if (err)
return apr_pstrcat(cmd->temp_pool, "ProxyPass ", err, NULL);
}
else {
ap_proxy_update_balancer(cmd->pool, balancer, fake_copy);
}
for (i = 0; i < arr->nelts; i++) {
const char *err = set_balancer_param(conf, cmd->pool, balancer, elts[i].key,
elts[i].val);
if (err)
return apr_pstrcat(cmd->temp_pool, "ProxyPass ", err, NULL);
}
new->balancer = balancer;
}
else {
proxy_worker *worker = ap_proxy_get_worker(cmd->temp_pool, NULL, conf, de_socketfy(cmd->pool, r));
int reuse = 0;
if (!worker) {
const char *err = ap_proxy_define_worker(cmd->pool, &worker, NULL, conf, r, 0);
if (err)
return apr_pstrcat(cmd->temp_pool, "ProxyPass ", err, NULL);
PROXY_COPY_CONF_PARAMS(worker, conf);
} else {
reuse = 1;
ap_log_error(APLOG_MARK, APLOG_INFO, 0, cmd->server, APLOGNO(01145)
"Sharing worker '%s' instead of creating new worker '%s'",
ap_proxy_worker_name(cmd->pool, worker), new->real);
}
for (i = 0; i < arr->nelts; i++) {
if (reuse) {
ap_log_error(APLOG_MARK, APLOG_WARNING, 0, cmd->server, APLOGNO(01146)
"Ignoring parameter '%s=%s' for worker '%s' because of worker sharing",
elts[i].key, elts[i].val, ap_proxy_worker_name(cmd->pool, worker));
} else {
const char *err = set_worker_param(cmd->pool, worker, elts[i].key,
elts[i].val);
if (err)
return apr_pstrcat(cmd->temp_pool, "ProxyPass ", err, NULL);
}
}
}
return NULL;
}
static const char *
add_pass_noregex(cmd_parms *cmd, void *dummy, const char *arg)
{
return add_pass(cmd, dummy, arg, 0);
}
static const char *
add_pass_regex(cmd_parms *cmd, void *dummy, const char *arg)
{
return add_pass(cmd, dummy, arg, 1);
}
static const char * add_pass_reverse(cmd_parms *cmd, void *dconf, const char *f,
const char *r, const char *i)
{
proxy_dir_conf *conf = dconf;
struct proxy_alias *new;
const char *fake;
const char *real;
const char *interp;
const char *err;
err = ap_check_cmd_context(cmd, NOT_IN_DIRECTORY|NOT_IN_FILES);
if (err) {
return err;
}
if (cmd->path == NULL) {
if (r == NULL || !strcasecmp(r, "interpolate")) {
return "ProxyPassReverse needs a path when not defined in a location";
}
fake = f;
real = r;
interp = i;
}
else {
if (r && strcasecmp(r, "interpolate")) {
return "ProxyPassReverse can not have a path when defined in a location";
}
fake = cmd->path;
real = f;
interp = r;
}
new = apr_array_push(conf->raliases);
new->fake = fake;
new->real = real;
new->flags = interp ? PROXYPASS_INTERPOLATE : 0;
return NULL;
}
static const char* cookie_path(cmd_parms *cmd, void *dconf, const char *f,
const char *r, const char *interp)
{
proxy_dir_conf *conf = dconf;
struct proxy_alias *new;
new = apr_array_push(conf->cookie_paths);
new->fake = f;
new->real = r;
new->flags = interp ? PROXYPASS_INTERPOLATE : 0;
return NULL;
}
static const char* cookie_domain(cmd_parms *cmd, void *dconf, const char *f,
const char *r, const char *interp)
{
proxy_dir_conf *conf = dconf;
struct proxy_alias *new;
new = apr_array_push(conf->cookie_domains);
new->fake = f;
new->real = r;
new->flags = interp ? PROXYPASS_INTERPOLATE : 0;
return NULL;
}
static const char *
set_proxy_exclude(cmd_parms *parms, void *dummy, const char *arg)
{
server_rec *s = parms->server;
proxy_server_conf *conf =
ap_get_module_config(s->module_config, &proxy_module);
struct noproxy_entry *new;
struct noproxy_entry *list = (struct noproxy_entry *) conf->noproxies->elts;
struct apr_sockaddr_t *addr;
int found = 0;
int i;
/* Don't duplicate entries */
for (i = 0; i < conf->noproxies->nelts; i++) {
if (strcasecmp(arg, list[i].name) == 0) { /* ignore case for host names */
found = 1;
break;
}
}
if (!found) {
new = apr_array_push(conf->noproxies);
new->name = arg;
if (APR_SUCCESS == apr_sockaddr_info_get(&addr, new->name, APR_UNSPEC, 0, 0, parms->pool)) {
new->addr = addr;
}
else {
new->addr = NULL;
}
}
return NULL;
}
/* Similar to set_proxy_exclude(), but defining directly connected hosts,
* which should never be accessed via the configured ProxyRemote servers
*/
static const char *
set_proxy_dirconn(cmd_parms *parms, void *dummy, const char *arg)
{
server_rec *s = parms->server;
proxy_server_conf *conf =
ap_get_module_config(s->module_config, &proxy_module);
struct dirconn_entry *New;
struct dirconn_entry *list = (struct dirconn_entry *) conf->dirconn->elts;
int found = 0;
int i;
/* Don't duplicate entries */
for (i = 0; i < conf->dirconn->nelts; i++) {
if (strcasecmp(arg, list[i].name) == 0) {
found = 1;
break;
}
}
if (!found) {
New = apr_array_push(conf->dirconn);
New->name = apr_pstrdup(parms->pool, arg);
New->hostaddr = NULL;
if (ap_proxy_is_ipaddr(New, parms->pool)) {
#if DEBUGGING
ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
"Parsed addr %s", inet_ntoa(New->addr));
ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
"Parsed mask %s", inet_ntoa(New->mask));
#endif
}
else if (ap_proxy_is_domainname(New, parms->pool)) {
ap_str_tolower(New->name);
#if DEBUGGING
ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
"Parsed domain %s", New->name);
#endif
}
else if (ap_proxy_is_hostname(New, parms->pool)) {
ap_str_tolower(New->name);
#if DEBUGGING
ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
"Parsed host %s", New->name);
#endif
}
else {
ap_proxy_is_word(New, parms->pool);
#if DEBUGGING
fprintf(stderr, "Parsed word %s\n", New->name);
#endif
}
}
return NULL;
}
static const char *
set_proxy_domain(cmd_parms *parms, void *dummy, const char *arg)
{
proxy_server_conf *psf =
ap_get_module_config(parms->server->module_config, &proxy_module);
if (arg[0] != '.')
return "ProxyDomain: domain name must start with a dot.";
psf->domain = arg;
return NULL;
}
static const char *
set_proxy_req(cmd_parms *parms, void *dummy, int flag)
{
proxy_server_conf *psf =
ap_get_module_config(parms->server->module_config, &proxy_module);
psf->req = flag;
psf->req_set = 1;
return NULL;
}
static const char *
set_proxy_error_override(cmd_parms *parms, void *dconf, int flag)
{
proxy_dir_conf *conf = dconf;
conf->error_override = flag;
conf->error_override_set = 1;
return NULL;
}
static const char *
add_proxy_http_headers(cmd_parms *parms, void *dconf, int flag)
{
proxy_dir_conf *conf = dconf;
conf->add_forwarded_headers = flag;
return NULL;
}
static const char *
set_preserve_host(cmd_parms *parms, void *dconf, int flag)
{
proxy_dir_conf *conf = dconf;
conf->preserve_host = flag;
conf->preserve_host_set = 1;
return NULL;
}
static const char *
set_recv_buffer_size(cmd_parms *parms, void *dummy, const char *arg)
{
proxy_server_conf *psf =
ap_get_module_config(parms->server->module_config, &proxy_module);
int s = atoi(arg);
if (s < 512 && s != 0) {
return "ProxyReceiveBufferSize must be >= 512 bytes, or 0 for system default.";
}
psf->recv_buffer_size = s;
psf->recv_buffer_size_set = 1;
return NULL;
}
static const char *
set_io_buffer_size(cmd_parms *parms, void *dummy, const char *arg)
{
proxy_server_conf *psf =
ap_get_module_config(parms->server->module_config, &proxy_module);
long s = atol(arg);
if (s < 512 && s) {
return "ProxyIOBufferSize must be >= 512 bytes, or 0 for system default.";
}
psf->io_buffer_size = (s ? s : AP_IOBUFSIZE);
psf->io_buffer_size_set = 1;
return NULL;
}
static const char *
set_max_forwards(cmd_parms *parms, void *dummy, const char *arg)
{
proxy_server_conf *psf =
ap_get_module_config(parms->server->module_config, &proxy_module);
long s = atol(arg);
psf->maxfwd = s;
psf->maxfwd_set = 1;
return NULL;
}
static const char*
set_proxy_timeout(cmd_parms *parms, void *dummy, const char *arg)
{
proxy_server_conf *psf =
ap_get_module_config(parms->server->module_config, &proxy_module);
int timeout;
timeout = atoi(arg);
if (timeout<1) {
return "Proxy Timeout must be at least 1 second.";
}
psf->timeout_set = 1;
psf->timeout = apr_time_from_sec(timeout);
return NULL;
}
static const char*
set_via_opt(cmd_parms *parms, void *dummy, const char *arg)
{
proxy_server_conf *psf =
ap_get_module_config(parms->server->module_config, &proxy_module);
if (strcasecmp(arg, "Off") == 0)
psf->viaopt = via_off;
else if (strcasecmp(arg, "On") == 0)
psf->viaopt = via_on;
else if (strcasecmp(arg, "Block") == 0)
psf->viaopt = via_block;
else if (strcasecmp(arg, "Full") == 0)
psf->viaopt = via_full;
else {
return "ProxyVia must be one of: "
"off | on | full | block";
}
psf->viaopt_set = 1;
return NULL;
}
static const char*
set_bad_opt(cmd_parms *parms, void *dummy, const char *arg)
{
proxy_server_conf *psf =
ap_get_module_config(parms->server->module_config, &proxy_module);
if (strcasecmp(arg, "IsError") == 0)
psf->badopt = bad_error;
else if (strcasecmp(arg, "Ignore") == 0)
psf->badopt = bad_ignore;
else if (strcasecmp(arg, "StartBody") == 0)
psf->badopt = bad_body;
else {
return "ProxyBadHeader must be one of: "
"IsError | Ignore | StartBody";
}
psf->badopt_set = 1;
return NULL;
}
static const char*
set_status_opt(cmd_parms *parms, void *dummy, const char *arg)
{
proxy_server_conf *psf =
ap_get_module_config(parms->server->module_config, &proxy_module);
if (strcasecmp(arg, "Off") == 0)
psf->proxy_status = status_off;
else if (strcasecmp(arg, "On") == 0)
psf->proxy_status = status_on;
else if (strcasecmp(arg, "Full") == 0)
psf->proxy_status = status_full;
else {
return "ProxyStatus must be one of: "
"off | on | full";
}
psf->proxy_status_set = 1;
return NULL;
}
static const char *set_bgrowth(cmd_parms *parms, void *dummy, const char *arg)
{
proxy_server_conf *psf =
ap_get_module_config(parms->server->module_config, &proxy_module);
int growth = atoi(arg);
if (growth < 0 || growth > 1000) {
return "BalancerGrowth must be between 0 and 1000";
}
psf->bgrowth = growth;
psf->bgrowth_set = 1;
return NULL;
}
static const char *set_persist(cmd_parms *parms, void *dummy, int flag)
{
proxy_server_conf *psf =
ap_get_module_config(parms->server->module_config, &proxy_module);
psf->bal_persist = flag;
return NULL;
}
static const char *set_inherit(cmd_parms *parms, void *dummy, int flag)
{
proxy_server_conf *psf =
ap_get_module_config(parms->server->module_config, &proxy_module);
psf->inherit = flag;
psf->inherit_set = 1;
return NULL;
}
static const char *set_ppinherit(cmd_parms *parms, void *dummy, int flag)
{
proxy_server_conf *psf =
ap_get_module_config(parms->server->module_config, &proxy_module);
psf->ppinherit = flag;
psf->ppinherit_set = 1;
return NULL;
}
static const char *add_member(cmd_parms *cmd, void *dummy, const char *arg)
{
server_rec *s = cmd->server;
proxy_server_conf *conf =
ap_get_module_config(s->module_config, &proxy_module);
proxy_balancer *balancer;
proxy_worker *worker;
char *path = cmd->path;
char *name = NULL;
char *word;
apr_table_t *params = apr_table_make(cmd->pool, 5);
const apr_array_header_t *arr;
const apr_table_entry_t *elts;
int reuse = 0;
int i;
/* XXX: Should this be NOT_IN_DIRECTORY|NOT_IN_FILES? */
const char *err = ap_check_cmd_context(cmd, NOT_IN_HTACCESS);
if (err)
return err;
if (cmd->path)
path = apr_pstrdup(cmd->pool, cmd->path);
while (*arg) {
char *val;
word = ap_getword_conf(cmd->pool, &arg);
val = strchr(word, '=');
if (!val) {
if (!path)
path = word;
else if (!name)
name = word;
else {
if (cmd->path)
return "BalancerMember can not have a balancer name when defined in a location";
else
return "Invalid BalancerMember parameter. Parameter must "
"be in the form 'key=value'";
}
} else {
*val++ = '\0';
apr_table_setn(params, word, val);
}
}
if (!path)
return "BalancerMember must define balancer name when outside <Proxy > section";
if (!name)
return "BalancerMember must define remote proxy server";
ap_str_tolower(path); /* lowercase scheme://hostname */
/* Try to find the balancer */
balancer = ap_proxy_get_balancer(cmd->temp_pool, conf, path, 0);
if (!balancer) {
err = ap_proxy_define_balancer(cmd->pool, &balancer, conf, path, "/", 0);
if (err)
return apr_pstrcat(cmd->temp_pool, "BalancerMember ", err, NULL);
}
/* Try to find existing worker */
worker = ap_proxy_get_worker(cmd->temp_pool, balancer, conf, de_socketfy(cmd->temp_pool, name));
if (!worker) {
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, cmd->server, APLOGNO(01147)
"Defining worker '%s' for balancer '%s'",
name, balancer->s->name);
if ((err = ap_proxy_define_worker(cmd->pool, &worker, balancer, conf, name, 0)) != NULL)
return apr_pstrcat(cmd->temp_pool, "BalancerMember ", err, NULL);
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, cmd->server, APLOGNO(01148)
"Defined worker '%s' for balancer '%s'",
ap_proxy_worker_name(cmd->pool, worker), balancer->s->name);
PROXY_COPY_CONF_PARAMS(worker, conf);
} else {
reuse = 1;
ap_log_error(APLOG_MARK, APLOG_INFO, 0, cmd->server, APLOGNO(01149)
"Sharing worker '%s' instead of creating new worker '%s'",
ap_proxy_worker_name(cmd->pool, worker), name);
}
arr = apr_table_elts(params);
elts = (const apr_table_entry_t *)arr->elts;
for (i = 0; i < arr->nelts; i++) {
if (reuse) {
ap_log_error(APLOG_MARK, APLOG_WARNING, 0, cmd->server, APLOGNO(01150)
"Ignoring parameter '%s=%s' for worker '%s' because of worker sharing",
elts[i].key, elts[i].val, ap_proxy_worker_name(cmd->pool, worker));
} else {
err = set_worker_param(cmd->pool, worker, elts[i].key,
elts[i].val);
if (err)
return apr_pstrcat(cmd->temp_pool, "BalancerMember ", err, NULL);
}
}
return NULL;
}
static const char *
set_proxy_param(cmd_parms *cmd, void *dummy, const char *arg)
{
server_rec *s = cmd->server;
proxy_server_conf *conf =
(proxy_server_conf *) ap_get_module_config(s->module_config, &proxy_module);
char *name = NULL;
char *word, *val;
proxy_balancer *balancer = NULL;
proxy_worker *worker = NULL;
int in_proxy_section = 0;
/* XXX: Should this be NOT_IN_DIRECTORY|NOT_IN_FILES? */
const char *err = ap_check_cmd_context(cmd, NOT_IN_HTACCESS);
if (err)
return err;
if (cmd->directive->parent &&
strncasecmp(cmd->directive->parent->directive,
"<Proxy", 6) == 0) {
const char *pargs = cmd->directive->parent->args;
/* Directive inside <Proxy section
* Parent directive arg is the worker/balancer name.
*/
name = ap_getword_conf(cmd->temp_pool, &pargs);
if ((word = ap_strchr(name, '>')))
*word = '\0';
in_proxy_section = 1;
}
else {
/* Standard set directive with worker/balancer
* name as first param.
*/
name = ap_getword_conf(cmd->temp_pool, &arg);
}
if (ap_proxy_valid_balancer_name(name, 9)) {
balancer = ap_proxy_get_balancer(cmd->pool, conf, name, 0);
if (!balancer) {
if (in_proxy_section) {
err = ap_proxy_define_balancer(cmd->pool, &balancer, conf, name, "/", 0);
if (err)
return apr_pstrcat(cmd->temp_pool, "ProxySet ",
err, NULL);
}
else
return apr_pstrcat(cmd->temp_pool, "ProxySet can not find '",
name, "' Balancer.", NULL);
}
}
else {
worker = ap_proxy_get_worker(cmd->temp_pool, NULL, conf, de_socketfy(cmd->temp_pool, name));
if (!worker) {
if (in_proxy_section) {
err = ap_proxy_define_worker(cmd->pool, &worker, NULL,
conf, name, 0);
if (err)
return apr_pstrcat(cmd->temp_pool, "ProxySet ",
err, NULL);
}
else
return apr_pstrcat(cmd->temp_pool, "ProxySet can not find '",
name, "' Worker.", NULL);
}
}
while (*arg) {
word = ap_getword_conf(cmd->pool, &arg);
val = strchr(word, '=');
if (!val) {
return "Invalid ProxySet parameter. Parameter must be "
"in the form 'key=value'";
}
else
*val++ = '\0';
if (worker)
err = set_worker_param(cmd->pool, worker, word, val);
else
err = set_balancer_param(conf, cmd->pool, balancer, word, val);
if (err)
return apr_pstrcat(cmd->temp_pool, "ProxySet: ", err, " ", word, "=", val, "; ", name, NULL);
}
return NULL;
}
static void ap_add_per_proxy_conf(server_rec *s, ap_conf_vector_t *dir_config)
{
proxy_server_conf *sconf = ap_get_module_config(s->module_config,
&proxy_module);
void **new_space = (void **)apr_array_push(sconf->sec_proxy);
*new_space = dir_config;
}
static const char *proxysection(cmd_parms *cmd, void *mconfig, const char *arg)
{
const char *errmsg;
const char *endp = ap_strrchr_c(arg, '>');
int old_overrides = cmd->override;
char *old_path = cmd->path;
proxy_dir_conf *conf;
ap_conf_vector_t *new_dir_conf = ap_create_per_dir_config(cmd->pool);
ap_regex_t *r = NULL;
const command_rec *thiscmd = cmd->cmd;
char *word, *val;
proxy_balancer *balancer = NULL;
proxy_worker *worker = NULL;
const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE);
proxy_server_conf *sconf =
(proxy_server_conf *) ap_get_module_config(cmd->server->module_config, &proxy_module);
if (err != NULL) {
return err;
}
if (endp == NULL) {
return apr_pstrcat(cmd->pool, cmd->cmd->name,
"> directive missing closing '>'", NULL);
}
arg = apr_pstrndup(cmd->pool, arg, endp-arg);
if (!arg) {
if (thiscmd->cmd_data)
return "<ProxyMatch > block must specify a path";
else
return "<Proxy > block must specify a path";
}
cmd->path = ap_getword_conf(cmd->pool, &arg);
cmd->override = OR_ALL|ACCESS_CONF;
if (!strncasecmp(cmd->path, "proxy:", 6))
cmd->path += 6;
/* XXX Ignore case? What if we proxy a case-insensitive server?!?
* While we are at it, shouldn't we also canonicalize the entire
* scheme? See proxy_fixup()
*/
if (thiscmd->cmd_data) { /* <ProxyMatch> */
r = ap_pregcomp(cmd->pool, cmd->path, AP_REG_EXTENDED);
if (!r) {
return "Regex could not be compiled";
}
}
/* initialize our config and fetch it */
conf = ap_set_config_vectors(cmd->server, new_dir_conf, cmd->path,
&proxy_module, cmd->pool);
errmsg = ap_walk_config(cmd->directive->first_child, cmd, new_dir_conf);
if (errmsg != NULL)
return errmsg;
conf->r = r;
conf->p = cmd->path;
conf->p_is_fnmatch = apr_fnmatch_test(conf->p);
if (r) {
conf->refs = apr_array_make(cmd->pool, 8, sizeof(char *));
ap_regname(r, conf->refs, AP_REG_MATCH, 1);
}
ap_add_per_proxy_conf(cmd->server, new_dir_conf);
if (*arg != '\0') {
if (thiscmd->cmd_data)
return "Multiple <ProxyMatch> arguments not (yet) supported.";
if (conf->p_is_fnmatch)
return apr_pstrcat(cmd->pool, thiscmd->name,
"> arguments are not supported for wildchar url.",
NULL);
if (!ap_strchr_c(conf->p, ':'))
return apr_pstrcat(cmd->pool, thiscmd->name,
"> arguments are not supported for non url.",
NULL);
if (ap_proxy_valid_balancer_name((char *)conf->p, 9)) {
balancer = ap_proxy_get_balancer(cmd->pool, sconf, conf->p, 0);
if (!balancer) {
err = ap_proxy_define_balancer(cmd->pool, &balancer,
sconf, conf->p, "/", 0);
if (err)
return apr_pstrcat(cmd->temp_pool, thiscmd->name,
" ", err, NULL);
}
}
else {
worker = ap_proxy_get_worker(cmd->temp_pool, NULL, sconf,
de_socketfy(cmd->temp_pool, (char*)conf->p));
if (!worker) {
err = ap_proxy_define_worker(cmd->pool, &worker, NULL,
sconf, conf->p, 0);
if (err)
return apr_pstrcat(cmd->temp_pool, thiscmd->name,
" ", err, NULL);
}
}
if (worker == NULL && balancer == NULL) {
return apr_pstrcat(cmd->pool, thiscmd->name,
"> arguments are supported only for workers.",
NULL);
}
while (*arg) {
word = ap_getword_conf(cmd->pool, &arg);
val = strchr(word, '=');
if (!val) {
return "Invalid Proxy parameter. Parameter must be "
"in the form 'key=value'";
}
else
*val++ = '\0';
if (worker)
err = set_worker_param(cmd->pool, worker, word, val);
else
err = set_balancer_param(sconf, cmd->pool, balancer,
word, val);
if (err)
return apr_pstrcat(cmd->temp_pool, thiscmd->name, " ", err, " ",
word, "=", val, "; ", conf->p, NULL);
}
}
cmd->path = old_path;
cmd->override = old_overrides;
return NULL;
}
static const command_rec proxy_cmds[] =
{
AP_INIT_RAW_ARGS("<Proxy", proxysection, NULL, RSRC_CONF,
"Container for directives affecting resources located in the proxied "
"location"),
AP_INIT_RAW_ARGS("<ProxyMatch", proxysection, (void*)1, RSRC_CONF,
"Container for directives affecting resources located in the proxied "
"location, in regular expression syntax"),
AP_INIT_FLAG("ProxyRequests", set_proxy_req, NULL, RSRC_CONF,
"on if the true proxy requests should be accepted"),
AP_INIT_TAKE2("ProxyRemote", add_proxy_noregex, NULL, RSRC_CONF,
"a scheme, partial URL or '*' and a proxy server"),
AP_INIT_TAKE2("ProxyRemoteMatch", add_proxy_regex, NULL, RSRC_CONF,
"a regex pattern and a proxy server"),
AP_INIT_FLAG("ProxyPassInterpolateEnv", ap_set_flag_slot_char,
(void*)APR_OFFSETOF(proxy_dir_conf, interpolate_env),
RSRC_CONF|ACCESS_CONF, "Interpolate Env Vars in reverse Proxy") ,
AP_INIT_RAW_ARGS("ProxyPass", add_pass_noregex, NULL, RSRC_CONF|ACCESS_CONF,
"a virtual path and a URL"),
AP_INIT_RAW_ARGS("ProxyPassMatch", add_pass_regex, NULL, RSRC_CONF|ACCESS_CONF,
"a virtual path and a URL"),
AP_INIT_TAKE123("ProxyPassReverse", add_pass_reverse, NULL, RSRC_CONF|ACCESS_CONF,
"a virtual path and a URL for reverse proxy behaviour"),
AP_INIT_TAKE23("ProxyPassReverseCookiePath", cookie_path, NULL,
RSRC_CONF|ACCESS_CONF, "Path rewrite rule for proxying cookies"),
AP_INIT_TAKE23("ProxyPassReverseCookieDomain", cookie_domain, NULL,
RSRC_CONF|ACCESS_CONF, "Domain rewrite rule for proxying cookies"),
AP_INIT_ITERATE("ProxyBlock", set_proxy_exclude, NULL, RSRC_CONF,
"A list of names, hosts or domains to which the proxy will not connect"),
AP_INIT_TAKE1("ProxyReceiveBufferSize", set_recv_buffer_size, NULL, RSRC_CONF,
"Receive buffer size for outgoing HTTP and FTP connections in bytes"),
AP_INIT_TAKE1("ProxyIOBufferSize", set_io_buffer_size, NULL, RSRC_CONF,
"IO buffer size for outgoing HTTP and FTP connections in bytes"),
AP_INIT_TAKE1("ProxyMaxForwards", set_max_forwards, NULL, RSRC_CONF,
"The maximum number of proxies a request may be forwarded through."),
AP_INIT_ITERATE("NoProxy", set_proxy_dirconn, NULL, RSRC_CONF,
"A list of domains, hosts, or subnets to which the proxy will connect directly"),
AP_INIT_TAKE1("ProxyDomain", set_proxy_domain, NULL, RSRC_CONF,
"The default intranet domain name (in absence of a domain in the URL)"),
AP_INIT_TAKE1("ProxyVia", set_via_opt, NULL, RSRC_CONF,
"Configure Via: proxy header header to one of: on | off | block | full"),
AP_INIT_FLAG("ProxyErrorOverride", set_proxy_error_override, NULL, RSRC_CONF|ACCESS_CONF,
"use our error handling pages instead of the servers' we are proxying"),
AP_INIT_FLAG("ProxyPreserveHost", set_preserve_host, NULL, RSRC_CONF|ACCESS_CONF,
"on if we should preserve host header while proxying"),
AP_INIT_TAKE1("ProxyTimeout", set_proxy_timeout, NULL, RSRC_CONF,
"Set the timeout (in seconds) for a proxied connection. "
"This overrides the server timeout"),
AP_INIT_TAKE1("ProxyBadHeader", set_bad_opt, NULL, RSRC_CONF,
"How to handle bad header line in response: IsError | Ignore | StartBody"),
AP_INIT_RAW_ARGS("BalancerMember", add_member, NULL, RSRC_CONF|ACCESS_CONF,
"A balancer name and scheme with list of params"),
AP_INIT_TAKE1("BalancerGrowth", set_bgrowth, NULL, RSRC_CONF,
"Number of additional Balancers that can be added post-config"),
AP_INIT_FLAG("BalancerPersist", set_persist, NULL, RSRC_CONF,
"on if the balancer should persist changes on reboot/restart made via the Balancer Manager"),
AP_INIT_FLAG("BalancerInherit", set_inherit, NULL, RSRC_CONF,
"on if this server should inherit Balancers and Workers defined in the main server "
"(Setting to off recommended if using the Balancer Manager)"),
AP_INIT_FLAG("ProxyPassInherit", set_ppinherit, NULL, RSRC_CONF,
"on if this server should inherit all ProxyPass directives defined in the main server "
"(Setting to off recommended if using the Balancer Manager)"),
AP_INIT_TAKE1("ProxyStatus", set_status_opt, NULL, RSRC_CONF,
"Configure Status: proxy status to one of: on | off | full"),
AP_INIT_RAW_ARGS("ProxySet", set_proxy_param, NULL, RSRC_CONF|ACCESS_CONF,
"A balancer or worker name with list of params"),
AP_INIT_TAKE1("ProxySourceAddress", set_source_address, NULL, RSRC_CONF,
"Configure local source IP used for request forward"),
AP_INIT_FLAG("ProxyAddHeaders", add_proxy_http_headers, NULL, RSRC_CONF|ACCESS_CONF,
"on if X-Forwarded-* headers should be added or completed"),
{NULL}
};
static APR_OPTIONAL_FN_TYPE(ssl_proxy_enable) *proxy_ssl_enable = NULL;
static APR_OPTIONAL_FN_TYPE(ssl_engine_disable) *proxy_ssl_disable = NULL;
static APR_OPTIONAL_FN_TYPE(ssl_is_https) *proxy_is_https = NULL;
static APR_OPTIONAL_FN_TYPE(ssl_var_lookup) *proxy_ssl_val = NULL;
PROXY_DECLARE(int) ap_proxy_ssl_enable(conn_rec *c)
{
/*
* if c == NULL just check if the optional function was imported
* else run the optional function so ssl filters are inserted
*/
if (proxy_ssl_enable) {
return c ? proxy_ssl_enable(c) : 1;
}
return 0;
}
PROXY_DECLARE(int) ap_proxy_ssl_disable(conn_rec *c)
{
if (proxy_ssl_disable) {
return proxy_ssl_disable(c);
}
return 0;
}
PROXY_DECLARE(int) ap_proxy_conn_is_https(conn_rec *c)
{
if (proxy_is_https) {
return proxy_is_https(c);
}
else
return 0;
}
PROXY_DECLARE(const char *) ap_proxy_ssl_val(apr_pool_t *p, server_rec *s,
conn_rec *c, request_rec *r,
const char *var)
{
if (proxy_ssl_val) {
/* XXX Perhaps the casting useless */
return (const char *)proxy_ssl_val(p, s, c, r, (char *)var);
}
else
return NULL;
}
static int proxy_post_config(apr_pool_t *pconf, apr_pool_t *plog,
apr_pool_t *ptemp, server_rec *s)
{
apr_status_t rv = ap_global_mutex_create(&proxy_mutex, NULL,
proxy_id, NULL, s, pconf, 0);
if (rv != APR_SUCCESS) {
ap_log_perror(APLOG_MARK, APLOG_CRIT, rv, plog, APLOGNO(02478)
"failed to create %s mutex", proxy_id);
return rv;
}
proxy_ssl_enable = APR_RETRIEVE_OPTIONAL_FN(ssl_proxy_enable);
proxy_ssl_disable = APR_RETRIEVE_OPTIONAL_FN(ssl_engine_disable);
proxy_is_https = APR_RETRIEVE_OPTIONAL_FN(ssl_is_https);
proxy_ssl_val = APR_RETRIEVE_OPTIONAL_FN(ssl_var_lookup);
ap_proxy_strmatch_path = apr_strmatch_precompile(pconf, "path=", 0);
ap_proxy_strmatch_domain = apr_strmatch_precompile(pconf, "domain=", 0);
return OK;
}
/*
* proxy Extension to mod_status
*/
static int proxy_status_hook(request_rec *r, int flags)
{
int i, n;
void *sconf = r->server->module_config;
proxy_server_conf *conf = (proxy_server_conf *)
ap_get_module_config(sconf, &proxy_module);
proxy_balancer *balancer = NULL;
proxy_worker **worker = NULL;
if ((flags & AP_STATUS_SHORT) || conf->balancers->nelts == 0 ||
conf->proxy_status == status_off)
return OK;
balancer = (proxy_balancer *)conf->balancers->elts;
for (i = 0; i < conf->balancers->nelts; i++) {
ap_rputs("<hr />\n<h1>Proxy LoadBalancer Status for ", r);
ap_rvputs(r, balancer->s->name, "</h1>\n\n", NULL);
ap_rputs("\n\n<table border=\"0\"><tr>"
"<th>SSes</th><th>Timeout</th><th>Method</th>"
"</tr>\n<tr>", r);
if (*balancer->s->sticky) {
if (strcmp(balancer->s->sticky, balancer->s->sticky_path)) {
ap_rvputs(r, "<td>", balancer->s->sticky, " | ",
balancer->s->sticky_path, NULL);
}
else {
ap_rvputs(r, "<td>", balancer->s->sticky, NULL);
}
}
else {
ap_rputs("<td> - ", r);
}
ap_rprintf(r, "</td><td>%" APR_TIME_T_FMT "</td>",
apr_time_sec(balancer->s->timeout));
ap_rprintf(r, "<td>%s</td>\n",
balancer->lbmethod->name);
ap_rputs("</table>\n", r);
ap_rputs("\n\n<table border=\"0\"><tr>"
"<th>Sch</th><th>Host</th><th>Stat</th>"
"<th>Route</th><th>Redir</th>"
"<th>F</th><th>Set</th><th>Acc</th><th>Wr</th><th>Rd</th>"
"</tr>\n", r);
worker = (proxy_worker **)balancer->workers->elts;
for (n = 0; n < balancer->workers->nelts; n++) {
char fbuf[50];
ap_rvputs(r, "<tr>\n<td>", (*worker)->s->scheme, "</td>", NULL);
ap_rvputs(r, "<td>", (*worker)->s->hostname, "</td><td>", NULL);
ap_rvputs(r, ap_proxy_parse_wstatus(r->pool, *worker), NULL);
ap_rvputs(r, "</td><td>", (*worker)->s->route, NULL);
ap_rvputs(r, "</td><td>", (*worker)->s->redirect, NULL);
ap_rprintf(r, "</td><td>%d</td>", (*worker)->s->lbfactor);
ap_rprintf(r, "<td>%d</td>", (*worker)->s->lbset);
ap_rprintf(r, "<td>%" APR_SIZE_T_FMT "</td><td>", (*worker)->s->elected);
ap_rputs(apr_strfsize((*worker)->s->transferred, fbuf), r);
ap_rputs("</td><td>", r);
ap_rputs(apr_strfsize((*worker)->s->read, fbuf), r);
ap_rputs("</td>\n", r);
/* TODO: Add the rest of dynamic worker data */
ap_rputs("</tr>\n", r);
++worker;
}
ap_rputs("</table>\n", r);
++balancer;
}
ap_rputs("<hr /><table>\n"
"<tr><th>SSes</th><td>Sticky session name</td></tr>\n"
"<tr><th>Timeout</th><td>Balancer Timeout</td></tr>\n"
"<tr><th>Sch</th><td>Connection scheme</td></tr>\n"
"<tr><th>Host</th><td>Backend Hostname</td></tr>\n"
"<tr><th>Stat</th><td>Worker status</td></tr>\n"
"<tr><th>Route</th><td>Session Route</td></tr>\n"
"<tr><th>Redir</th><td>Session Route Redirection</td></tr>\n"
"<tr><th>F</th><td>Load Balancer Factor</td></tr>\n"
"<tr><th>Acc</th><td>Number of uses</td></tr>\n"
"<tr><th>Wr</th><td>Number of bytes transferred</td></tr>\n"
"<tr><th>Rd</th><td>Number of bytes read</td></tr>\n"
"</table>", r);
return OK;
}
static void child_init(apr_pool_t *p, server_rec *s)
{
proxy_worker *reverse = NULL;
apr_status_t rv = apr_global_mutex_child_init(&proxy_mutex,
apr_global_mutex_lockfile(proxy_mutex),
p);
if (rv != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_CRIT, rv, s, APLOGNO(02479)
"could not init proxy_mutex in child");
exit(1); /* Ugly, but what else? */
}
/* TODO */
while (s) {
void *sconf = s->module_config;
proxy_server_conf *conf;
proxy_worker *worker;
int i;
conf = (proxy_server_conf *)ap_get_module_config(sconf, &proxy_module);
/*
* NOTE: non-balancer members don't use shm at all...
* after all, why should they?
*/
worker = (proxy_worker *)conf->workers->elts;
for (i = 0; i < conf->workers->nelts; i++, worker++) {
ap_proxy_initialize_worker(worker, s, conf->pool);
}
/* Create and initialize forward worker if defined */
if (conf->req_set && conf->req) {
proxy_worker *forward;
ap_proxy_define_worker(p, &forward, NULL, NULL, "http://www.apache.org", 0);
conf->forward = forward;
PROXY_STRNCPY(conf->forward->s->name, "proxy:forward");
PROXY_STRNCPY(conf->forward->s->hostname, "*");
PROXY_STRNCPY(conf->forward->s->scheme, "*");
conf->forward->hash.def = conf->forward->s->hash.def =
ap_proxy_hashfunc(conf->forward->s->name, PROXY_HASHFUNC_DEFAULT);
conf->forward->hash.fnv = conf->forward->s->hash.fnv =
ap_proxy_hashfunc(conf->forward->s->name, PROXY_HASHFUNC_FNV);
/* Do not disable worker in case of errors */
conf->forward->s->status |= PROXY_WORKER_IGNORE_ERRORS;
/* Mark as the "generic" worker */
conf->forward->s->status |= PROXY_WORKER_GENERIC;
ap_proxy_initialize_worker(conf->forward, s, conf->pool);
/* Disable address cache for generic forward worker */
conf->forward->s->is_address_reusable = 0;
}
if (!reverse) {
ap_proxy_define_worker(p, &reverse, NULL, NULL, "http://www.apache.org", 0);
PROXY_STRNCPY(reverse->s->name, "proxy:reverse");
PROXY_STRNCPY(reverse->s->hostname, "*");
PROXY_STRNCPY(reverse->s->scheme, "*");
reverse->hash.def = reverse->s->hash.def =
ap_proxy_hashfunc(reverse->s->name, PROXY_HASHFUNC_DEFAULT);
reverse->hash.fnv = reverse->s->hash.fnv =
ap_proxy_hashfunc(reverse->s->name, PROXY_HASHFUNC_FNV);
/* Do not disable worker in case of errors */
reverse->s->status |= PROXY_WORKER_IGNORE_ERRORS;
/* Mark as the "generic" worker */
reverse->s->status |= PROXY_WORKER_GENERIC;
conf->reverse = reverse;
ap_proxy_initialize_worker(conf->reverse, s, conf->pool);
/* Disable address cache for generic reverse worker */
reverse->s->is_address_reusable = 0;
}
conf->reverse = reverse;
s = s->next;
}
}
/*
* This routine is called before the server processes the configuration
* files.
*/
static int proxy_pre_config(apr_pool_t *pconf, apr_pool_t *plog,
apr_pool_t *ptemp)
{
apr_status_t rv = ap_mutex_register(pconf, proxy_id, NULL,
APR_LOCK_DEFAULT, 0);
if (rv != APR_SUCCESS) {
ap_log_perror(APLOG_MARK, APLOG_CRIT, rv, plog, APLOGNO(02480)
"failed to register %s mutex", proxy_id);
return 500; /* An HTTP status would be a misnomer! */
}
APR_OPTIONAL_HOOK(ap, status_hook, proxy_status_hook, NULL, NULL,
APR_HOOK_MIDDLE);
/* Reset workers count on gracefull restart */
proxy_lb_workers = 0;
return OK;
}
static void register_hooks(apr_pool_t *p)
{
/* fixup before mod_rewrite, so that the proxied url will not
* escaped accidentally by our fixup.
*/
static const char * const aszSucc[] = { "mod_rewrite.c", NULL};
/* Only the mpm_winnt has child init hook handler.
* make sure that we are called after the mpm
* initializes.
*/
static const char *const aszPred[] = { "mpm_winnt.c", "mod_proxy_balancer.c", NULL};
/* handler */
ap_hook_handler(proxy_handler, NULL, NULL, APR_HOOK_FIRST);
/* filename-to-URI translation */
ap_hook_translate_name(proxy_trans, aszSucc, NULL, APR_HOOK_FIRST);
/* walk <Proxy > entries and suppress default TRACE behavior */
ap_hook_map_to_storage(proxy_map_location, NULL,NULL, APR_HOOK_FIRST);
/* fixups */
ap_hook_fixups(proxy_fixup, NULL, aszSucc, APR_HOOK_FIRST);
/* post read_request handling */
ap_hook_post_read_request(proxy_detect, NULL, NULL, APR_HOOK_FIRST);
/* pre config handling */
ap_hook_pre_config(proxy_pre_config, NULL, NULL, APR_HOOK_MIDDLE);
/* post config handling */
ap_hook_post_config(proxy_post_config, NULL, NULL, APR_HOOK_MIDDLE);
/* child init handling */
ap_hook_child_init(child_init, aszPred, NULL, APR_HOOK_MIDDLE);
/* register optional functions within proxy_util.c */
proxy_util_register_hooks(p);
}
AP_DECLARE_MODULE(proxy) =
{
STANDARD20_MODULE_STUFF,
create_proxy_dir_config, /* create per-directory config structure */
merge_proxy_dir_config, /* merge per-directory config structures */
create_proxy_config, /* create per-server config structure */
merge_proxy_config, /* merge per-server config structures */
proxy_cmds, /* command table */
register_hooks
};
APR_HOOK_STRUCT(
APR_HOOK_LINK(scheme_handler)
APR_HOOK_LINK(canon_handler)
APR_HOOK_LINK(pre_request)
APR_HOOK_LINK(post_request)
APR_HOOK_LINK(request_status)
)
APR_IMPLEMENT_EXTERNAL_HOOK_RUN_FIRST(proxy, PROXY, int, scheme_handler,
(request_rec *r, proxy_worker *worker,
proxy_server_conf *conf,
char *url, const char *proxyhost,
apr_port_t proxyport),(r,worker,conf,
url,proxyhost,proxyport),DECLINED)
APR_IMPLEMENT_EXTERNAL_HOOK_RUN_FIRST(proxy, PROXY, int, canon_handler,
(request_rec *r, char *url),(r,
url),DECLINED)
APR_IMPLEMENT_EXTERNAL_HOOK_RUN_FIRST(proxy, PROXY, int, pre_request, (
proxy_worker **worker,
proxy_balancer **balancer,
request_rec *r,
proxy_server_conf *conf,
char **url),(worker,balancer,
r,conf,url),DECLINED)
APR_IMPLEMENT_EXTERNAL_HOOK_RUN_FIRST(proxy, PROXY, int, post_request,
(proxy_worker *worker,
proxy_balancer *balancer,
request_rec *r,
proxy_server_conf *conf),(worker,
balancer,r,conf),DECLINED)
APR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(proxy, PROXY, int, fixups,
(request_rec *r), (r),
OK, DECLINED)
APR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(proxy, PROXY, int, request_status,
(int *status, request_rec *r),
(status, r),
OK, DECLINED)
APR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(proxy, PROXY, int, detach_backend,
(request_rec *r, proxy_conn_rec *backend),
(r, backend), OK, DECLINED)