mod_proxy.c revision 2dbd6146bf47e7eafb45bf3b79b242aa45f6f8ca
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#define CORE_PRIVATE
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
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
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb/* return the sizeof of one lb_worker in scoreboard. */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic int ap_proxy_lb_worker_size(void)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return sizeof(proxy_worker_stat);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
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 * type_checker: set type to PROXY_MAGIC_TYPE if filename begins proxy:
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
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb#define PROXY_COPY_CONF_PARAMS(w, c) \
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb do { \
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb (w)->timeout = (c)->timeout; \
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb (w)->timeout_set = (c)->timeout_set; \
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb (w)->recv_buffer_size = (c)->recv_buffer_size; \
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb (w)->recv_buffer_size_set = (c)->recv_buffer_size_set; \
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb (w)->io_buffer_size = (c)->io_buffer_size; \
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb (w)->io_buffer_size_set = (c)->io_buffer_size_set; \
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb } while (0)
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 if (!strcasecmp(key, "loadfactor")) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Normalized load factor. Used with BalancerMamber,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb * it is a number between 1 and 100.
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb worker->lbfactor = atoi(val);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (worker->lbfactor < 1 || worker->lbfactor > 100)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return "LoadFactor must be 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);
a2a0abd88b19e042a3eb2a9fa1702c25ad51303dwrowe if (ival < 0)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return "Retry must be a positive value";
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb worker->retry = apr_time_from_sec(ival);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb worker->retry_set = 1;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else if (!strcasecmp(key, "ttl")) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Time in seconds that will destroy all the connections
b45c1c292ff1fa635004ae81fa691f8cb3cdda85rbb * that exced the smax
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ival = atoi(val);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (ival < 1)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return "TTL must be at least one second";
a2a0abd88b19e042a3eb2a9fa1702c25ad51303dwrowe worker->ttl = apr_time_from_sec(ival);
a2a0abd88b19e042a3eb2a9fa1702c25ad51303dwrowe }
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->min = ival;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else if (!strcasecmp(key, "max")) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Maximum number of connections to remote
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb */
c3e342e5b0b9fea6617ee16d2da02c3ef2108126dougm ival = atoi(val);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (ival < 0)
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe return "Max must be a positive number";
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe worker->hmax = ival;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe /* XXX: More inteligent naming needed */
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe else if (!strcasecmp(key, "smax")) {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe /* Maximum number of connections to remote that
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe * will not be destroyed
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe */
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe ival = atoi(val);
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if (ival < 0)
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe return "Smax must be a positive number";
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe worker->smax = ival;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe else if (!strcasecmp(key, "acquire")) {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe /* Acquire timeout in milliseconds.
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe * If set this will be the maximum time to
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe * wait for a free connection.
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe */
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe ival = atoi(val);
3e392a5afd51526de3cb15d57ee46d8cb160ae65gregames if (ival < 1)
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe return "Acquire must be at least one mili second";
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe worker->acquire = apr_time_make(0, ival * 1000);
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe worker->acquire_set = 1;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe else if (!strcasecmp(key, "timeout")) {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe /* Connection timeout in seconds.
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe * Defaults to server timeout.
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe */
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe ival = atoi(val);
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if (ival < 1)
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe return "Timeout must be at least one second";
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe worker->timeout = apr_time_from_sec(ival);
3e392a5afd51526de3cb15d57ee46d8cb160ae65gregames worker->timeout_set = 1;
3e392a5afd51526de3cb15d57ee46d8cb160ae65gregames }
3e392a5afd51526de3cb15d57ee46d8cb160ae65gregames else if (!strcasecmp(key, "iobuffersize")) {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe long s = atol(val);
3e392a5afd51526de3cb15d57ee46d8cb160ae65gregames worker->io_buffer_size = ((s > AP_IOBUFSIZE) ? s : AP_IOBUFSIZE);
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe worker->io_buffer_size_set = 1;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe }
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe else if (!strcasecmp(key, "receivebuffersize")) {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe ival = atoi(val);
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if (ival < 512 && ival != 0) {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe return "ReceiveBufferSize must be >= 512 bytes, or 0 for system default.";
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe }
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe worker->recv_buffer_size = ival;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe worker->recv_buffer_size_set = 1;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe else if (!strcasecmp(key, "keepalive")) {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe if (!strcasecmp(val, "on"))
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe worker->keepalive = 1;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe else if (!strcasecmp(val, "off"))
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe worker->keepalive = 0;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe else
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe return "KeepAlive must be On|Off";
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe worker->keepalive_set = 1;
4775dfc34c90fada8c7c4d6a57ed8a3114d55c2dtrawick }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe else if (!strcasecmp(key, "route")) {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe /* Worker route.
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe */
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe if (strlen(val) > PROXY_WORKER_MAX_ROUTE_SIZ)
3e392a5afd51526de3cb15d57ee46d8cb160ae65gregames return "Route length must be < 64 characters";
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe worker->route = apr_pstrdup(p, val);
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe }
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe else if (!strcasecmp(key, "redirect")) {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe /* Worker redirection route.
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe */
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe if (strlen(val) > PROXY_WORKER_MAX_ROUTE_SIZ)
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe return "Redirect length must be < 64 characters";
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe worker->redirect = apr_pstrdup(p, val);
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe else if (!strcasecmp(key, "status")) {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe const char *v;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe int mode = 1;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe /* Worker status.
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe */
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe for (v = val; *v; v++) {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe if (*v == '+') {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe mode = 1;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe v++;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe }
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe else if (*v == '-') {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe mode = 0;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe v++;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe }
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe if (*v == 'D' || *v == 'd') {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe if (mode)
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe worker->status |= PROXY_WORKER_DISABLED;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe else
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe worker->status &= ~PROXY_WORKER_DISABLED;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe }
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe else if (*v == 'S' || *v == 's') {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe if (mode)
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe worker->status |= PROXY_WORKER_STOPPED;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe else
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe worker->status &= ~PROXY_WORKER_STOPPED;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe else if (*v == 'E' || *v == 'e') {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe if (mode)
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe worker->status |= PROXY_WORKER_IN_ERROR;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe else
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe worker->status &= ~PROXY_WORKER_IN_ERROR;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe }
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe else if (*v == 'H' || *v == 'h') {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe if (mode)
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe worker->status |= PROXY_WORKER_HOT_STANDBY;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe else
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe worker->status &= ~PROXY_WORKER_HOT_STANDBY;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe else if (*v == 'I' || *v == 'i') {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe if (mode)
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe worker->status |= PROXY_WORKER_IGNORE_ERRORS;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe else
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe worker->status &= ~PROXY_WORKER_IGNORE_ERRORS;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe }
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe else {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe return "Unknown status parameter option";
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe }
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe }
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe }
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe else if (!strcasecmp(key, "flushpackets")) {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe if (!strcasecmp(val, "on"))
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe worker->flush_packets = flush_on;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe else if (!strcasecmp(val, "off"))
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe worker->flush_packets = flush_off;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe else if (!strcasecmp(val, "auto"))
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe worker->flush_packets = flush_auto;
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe else
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe return "flushpackets must be on|off|auto";
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe else if (!strcasecmp(key, "flushwait")) {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe ival = atoi(val);
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if (ival > 1000 || ival < 0) {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe return "flushwait must be <= 1000, or 0 for system default of 10 millseconds.";
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if (ival == 0)
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe worker->flush_wait = PROXY_FLUSH_WAIT;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe else
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe worker->flush_wait = ival * 1000; /* change to microseconds */
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe else if (!strcasecmp(key, "ping")) {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe /* Ping/Pong timeout in seconds.
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe */
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe ival = atoi(val);
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if (ival < 1)
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe return "Ping/Pong timeout must be at least one second";
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe worker->ping_timeout = apr_time_from_sec(ival);
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe worker->ping_timeout_set = 1;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe else if (!strcasecmp(key, "lbset")) {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe ival = atoi(val);
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if (ival < 0 || ival > 99)
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe return "lbset must be between 0 and 99";
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe worker->lbset = ival;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe }
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe else {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe return "unknown Worker parameter";
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe }
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe return NULL;
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe}
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowestatic const char *set_balancer_param(proxy_server_conf *conf,
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe apr_pool_t *p,
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe proxy_balancer *balancer,
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe const char *key,
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe const char *val)
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe{
0540a0b469147b52e858587270dba31c2aaa9e09wrowe
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe int ival;
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe if (!strcasecmp(key, "stickysession")) {
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe char *path;
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe /* Balancer sticky session name.
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe * Set to something like JSESSIONID or
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe * PHPSESSIONID, etc..,
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe */
0f6fdc73136a064819585afe03bc3503826ee592wrowe path = apr_pstrdup(p, val);
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe balancer->sticky = balancer->sticky_path = path;
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe if ((path = strchr(path, '|'))) {
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe *path++ = '\0';
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe balancer->sticky_path = path;
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe }
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe }
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe else if (!strcasecmp(key, "nofailover")) {
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe /* If set to 'on' the session will break
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe * if the worker is in error state or
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe * disabled.
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe */
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe if (!strcasecmp(val, "on"))
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe balancer->sticky_force = 1;
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe else if (!strcasecmp(val, "off"))
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe balancer->sticky_force = 0;
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe else
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe return "failover must be On|Off";
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe }
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe else if (!strcasecmp(key, "timeout")) {
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe /* Balancer timeout in seconds.
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe * If set this will be the maximum time to
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe * wait for a free worker.
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe * Default is not to wait.
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe */
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe ival = atoi(val);
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe if (ival < 1)
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe return "timeout must be at least one second";
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe balancer->timeout = apr_time_from_sec(ival);
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe }
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe else if (!strcasecmp(key, "maxattempts")) {
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe /* Maximum number of failover attempts before
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe * giving up.
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe */
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe ival = atoi(val);
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe if (ival < 0)
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe return "maximum number of attempts must be a positive number";
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe balancer->max_attempts = ival;
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe balancer->max_attempts_set = 1;
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else if (!strcasecmp(key, "lbmethod")) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb proxy_balancer_method *provider;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb provider = ap_lookup_provider(PROXY_LBMETHOD, val, "0");
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (provider) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb balancer->lbmethod = provider;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return NULL;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return "unknown lbmethod";
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 {
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe /* Other characters are compared literally */
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe if (*urip++ != *aliasp++)
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe return 0;
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe }
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe }
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe /* fixup badly encoded stuff (e.g. % as last character) */
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe if (aliasp > end_fakename) {
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe aliasp = end_fakename;
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe }
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe if (urip > end_uri) {
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe urip = end_uri;
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe }
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe /* We reach the end of the uri before the end of "alias_fakename"
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe * for example uri is "/" and alias_fakename "/examples"
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe */
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe if (urip == end_uri && aliasp!=end_fakename) {
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe return 0;
2f1949bb0e3c209db94c8d521cba7380b9d11421trawick }
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe /* Check last alias path component matched all the way */
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe if (aliasp[-1] != '/' && *urip != '\0' && *urip != '/')
2f1949bb0e3c209db94c8d521cba7380b9d11421trawick return 0;
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe
11fb2f3611e6ff9a541e10b13e3108934f828141gregames /* Return number of characters from URI which matched (may be
11fb2f3611e6ff9a541e10b13e3108934f828141gregames * greater than length of alias, since we may have matched
11fb2f3611e6ff9a541e10b13e3108934f828141gregames * doubled slashes)
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe */
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe return urip - uri;
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe}
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe/* Detect if an absoluteURI should be proxied or not. Note that we
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe * have to do this during this phase because later phases are
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe * "short-circuiting"... i.e. translate_names will end when the first
2f1949bb0e3c209db94c8d521cba7380b9d11421trawick * module returns OK. So for example, if the request is something like:
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe *
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe * GET http://othervhost/cgi-bin/printenv HTTP/1.0
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe *
2f1949bb0e3c209db94c8d521cba7380b9d11421trawick * mod_alias will notice the /cgi-bin part and ScriptAlias it and
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe * short-circuit the proxy... just because of the ordering in the
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe * configuration file.
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe */
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowestatic int proxy_detect(request_rec *r)
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe{
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe void *sconf = r->server->module_config;
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe proxy_server_conf *conf =
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe (proxy_server_conf *) ap_get_module_config(sconf, &proxy_module);
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Ick... msvc (perhaps others) promotes ternary short results to int */
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (conf->req && r->parsed_uri.scheme) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe /* but it might be something vhosted */
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (!(r->parsed_uri.hostname
8aefbd756763807188d2e3ce336a8680e4893066wrowe && !strcasecmp(r->parsed_uri.scheme, ap_http_scheme(r))
8aefbd756763807188d2e3ce336a8680e4893066wrowe && ap_matches_request_vhost(r, r->parsed_uri.hostname,
8aefbd756763807188d2e3ce336a8680e4893066wrowe (apr_port_t)(r->parsed_uri.port_str ? r->parsed_uri.port
8aefbd756763807188d2e3ce336a8680e4893066wrowe : ap_default_port(r))))) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe r->proxyreq = PROXYREQ_PROXY;
8aefbd756763807188d2e3ce336a8680e4893066wrowe r->uri = r->unparsed_uri;
8aefbd756763807188d2e3ce336a8680e4893066wrowe r->filename = apr_pstrcat(r->pool, "proxy:", r->uri, NULL);
8aefbd756763807188d2e3ce336a8680e4893066wrowe r->handler = "proxy-server";
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe /* We need special treatment for CONNECT proxying: it has no scheme part */
8aefbd756763807188d2e3ce336a8680e4893066wrowe else if (conf->req && r->method_number == M_CONNECT
a2a0abd88b19e042a3eb2a9fa1702c25ad51303dwrowe && r->parsed_uri.hostname
8aefbd756763807188d2e3ce336a8680e4893066wrowe && r->parsed_uri.port_str) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe r->proxyreq = PROXYREQ_PROXY;
8aefbd756763807188d2e3ce336a8680e4893066wrowe r->uri = r->unparsed_uri;
8aefbd756763807188d2e3ce336a8680e4893066wrowe r->filename = apr_pstrcat(r->pool, "proxy:", r->uri, NULL);
2fa5b5878e7567e2875807c3e2a2b3b0d3ef74bewrowe r->handler = "proxy-server";
2fa5b5878e7567e2875807c3e2a2b3b0d3ef74bewrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe return DECLINED;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe}
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowestatic const char *proxy_interpolate(request_rec *r, const char *str)
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe{
a8d11d78181478da6a672f7fbc58b8d523351f49wrowe /* Interpolate an env str in a configuration string
8aa5ca8ff2a4d8e56f62ea3d461e2799136da085trawick * Syntax ${var} --> value_of(var)
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe * Method: replace one var, and recurse on remainder of string
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe * Nothing clever here, and crap like nested vars may do silly things
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe * but we'll at least avoid sending the unwary into a loop
8aefbd756763807188d2e3ce336a8680e4893066wrowe */
a8d11d78181478da6a672f7fbc58b8d523351f49wrowe const char *start;
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe const char *end;
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe const char *var;
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe const char *val;
ac06e54654494445fd3d39e90bd23b436b4f84ccwrowe const char *firstpart;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe start = ap_strstr_c(str, "${");
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (start == NULL) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe return str;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe end = ap_strchr_c(start+2, '}');
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (end == NULL) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe return str;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe /* OK, this is syntax we want to interpolate. Is there such a var ? */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe var = apr_pstrndup(r->pool, start+2, end-(start+2));
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe val = apr_table_get(r->subprocess_env, var);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe firstpart = apr_pstrndup(r->pool, str, (start-str));
a8d11d78181478da6a672f7fbc58b8d523351f49wrowe
a8d11d78181478da6a672f7fbc58b8d523351f49wrowe if (val == NULL) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe return apr_pstrcat(r->pool, firstpart,
8aefbd756763807188d2e3ce336a8680e4893066wrowe proxy_interpolate(r, end+1), NULL);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe else {
8aefbd756763807188d2e3ce336a8680e4893066wrowe return apr_pstrcat(r->pool, firstpart, val,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe proxy_interpolate(r, end+1), NULL);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe}
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowestatic apr_array_header_t *proxy_vars(request_rec *r,
8aefbd756763807188d2e3ce336a8680e4893066wrowe apr_array_header_t *hdr)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe{
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe int i;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe apr_array_header_t *ret = apr_array_make(r->pool, hdr->nelts,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe sizeof (struct proxy_alias));
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe struct proxy_alias *old = (struct proxy_alias *) hdr->elts;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe for (i = 0; i < hdr->nelts; ++i) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe struct proxy_alias *newcopy = apr_array_push(ret);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe newcopy->fake = proxy_interpolate(r, old[i].fake);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe newcopy->real = proxy_interpolate(r, old[i].real);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe return ret;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe}
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowestatic int proxy_trans(request_rec *r)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe{
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe void *sconf = r->server->module_config;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe proxy_server_conf *conf =
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe (proxy_server_conf *) ap_get_module_config(sconf, &proxy_module);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe int i, len;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe struct proxy_alias *ent = (struct proxy_alias *) conf->aliases->elts;
a9a4544168a37b43bd180b3703ccee995f27a80awrowe proxy_dir_conf *dconf = ap_get_module_config(r->per_dir_config,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe &proxy_module);
a9a4544168a37b43bd180b3703ccee995f27a80awrowe const char *fake;
a9a4544168a37b43bd180b3703ccee995f27a80awrowe const char *real;
a9a4544168a37b43bd180b3703ccee995f27a80awrowe ap_regmatch_t regm[AP_MAX_REG_MATCH];
a9a4544168a37b43bd180b3703ccee995f27a80awrowe char *found = NULL;
a9a4544168a37b43bd180b3703ccee995f27a80awrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (r->proxyreq) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* someone has already set up the proxy, it was possibly ourselves
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * in proxy_detect
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe return OK;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe /* XXX: since r->uri has been manipulated already we're not really
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * compliant with RFC1945 at this point. But this probably isn't
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * an issue because this is a hybrid proxy/origin server.
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe for (i = 0; i < conf->aliases->nelts; i++) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (dconf->interpolate_env == 1) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe fake = proxy_interpolate(r, ent[i].fake);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe real = proxy_interpolate(r, ent[i].real);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe else {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe fake = ent[i].fake;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe real = ent[i].real;
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (ent[i].regex) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (!ap_regexec(ent[i].regex, r->uri, AP_MAX_REG_MATCH, regm, 0)) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if ((real[0] == '!') && (real[1] == '\0')) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe return DECLINED;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe found = ap_pregsub(r->pool, real, r->uri, AP_MAX_REG_MATCH,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe regm);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* Note: The strcmp() below catches cases where there
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * was no regex substitution. This is so cases like:
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe *
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * ProxyPassMatch \.gif balancer://foo
8aefbd756763807188d2e3ce336a8680e4893066wrowe *
59513b1275fdc2021d4949ee03ae8229469abb86wrowe * will work "as expected". The upshot is that the 2
59513b1275fdc2021d4949ee03ae8229469abb86wrowe * directives below act the exact same way (ie: $1 is implied):
59513b1275fdc2021d4949ee03ae8229469abb86wrowe *
59513b1275fdc2021d4949ee03ae8229469abb86wrowe * ProxyPassMatch ^(/.*\.gif)$ balancer://foo
59513b1275fdc2021d4949ee03ae8229469abb86wrowe * ProxyPassMatch ^(/.*\.gif)$ balancer://foo$1
85bb5b92490e4f095aae394118fc588a8f4c486fwrowe *
85bb5b92490e4f095aae394118fc588a8f4c486fwrowe * which may be confusing.
38bcc87d9a06e8ba81165421403f275eca4e313btrawick */
38bcc87d9a06e8ba81165421403f275eca4e313btrawick if (found && strcmp(found, real)) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe found = apr_pstrcat(r->pool, "proxy:", found, NULL);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe else {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe found = apr_pstrcat(r->pool, "proxy:", real, r->uri,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe NULL);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe else {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe len = alias_match(r->uri, fake);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (len != 0) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if ((real[0] == '!') && (real[1] == '\0')) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe return DECLINED;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe found = apr_pstrcat(r->pool, "proxy:", real,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe r->uri + len, NULL);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe if (found) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe r->filename = found;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe r->handler = "proxy-server";
8aefbd756763807188d2e3ce336a8680e4893066wrowe r->proxyreq = PROXYREQ_REVERSE;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe return OK;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
4fca95918a9c0ae93593806544b425d0adc2fcc3wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe return DECLINED;
8aefbd756763807188d2e3ce336a8680e4893066wrowe}
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowestatic int proxy_walk(request_rec *r)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe{
8aefbd756763807188d2e3ce336a8680e4893066wrowe proxy_server_conf *sconf = ap_get_module_config(r->server->module_config,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe &proxy_module);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_conf_vector_t *per_dir_defaults = r->server->lookup_defaults;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_conf_vector_t **sec_proxy = (ap_conf_vector_t **) sconf->sec_proxy->elts;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_conf_vector_t *entry_config;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe proxy_dir_conf *entry_proxy;
8aefbd756763807188d2e3ce336a8680e4893066wrowe int num_sec = sconf->sec_proxy->nelts;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* XXX: shouldn't we use URI here? Canonicalize it first?
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * Pass over "proxy:" prefix
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe const char *proxyname = r->filename + 6;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe int j;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe for (j = 0; j < num_sec; ++j)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe entry_config = sec_proxy[j];
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe entry_proxy = ap_get_module_config(entry_config, &proxy_module);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe /* XXX: What about case insensitive matching ???
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * Compare regex, fnmatch or string as appropriate
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * If the entry doesn't relate, then continue
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (entry_proxy->r
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ? ap_regexec(entry_proxy->r, proxyname, 0, NULL, 0)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe : (entry_proxy->p_is_fnmatch
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ? apr_fnmatch(entry_proxy->p, proxyname, 0)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe : strncmp(proxyname, entry_proxy->p,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe strlen(entry_proxy->p)))) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe continue;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe per_dir_defaults = ap_merge_per_dir_configs(r->pool, per_dir_defaults,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe entry_config);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe r->per_dir_config = per_dir_defaults;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe return OK;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe}
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowestatic int proxy_map_location(request_rec *r)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe{
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe int access_status;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (!r->proxyreq || !r->filename || strncmp(r->filename, "proxy:", 6) != 0)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe return DECLINED;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* Don't let the core or mod_http map_to_storage hooks handle this,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * We don't need directory/file_walk, and we want to TRACE on our own.
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if ((access_status = proxy_walk(r))) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_die(access_status, r);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe return access_status;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe return OK;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe}
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe/* -------------------------------------------------------------- */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe/* Fixup the filename */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe/*
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * Canonicalise the URL
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowestatic int proxy_fixup(request_rec *r)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe{
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe char *url, *p;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe int access_status;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe proxy_dir_conf *dconf = ap_get_module_config(r->per_dir_config,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe &proxy_module);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (!r->proxyreq || !r->filename || strncmp(r->filename, "proxy:", 6) != 0)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe return DECLINED;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe /* XXX: Shouldn't we try this before we run the proxy_walk? */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe url = &r->filename[6];
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe if ((dconf->interpolate_env == 1) && (r->proxyreq == PROXYREQ_REVERSE)) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* create per-request copy of reverse proxy conf,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * and interpolate vars in it
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe proxy_req_conf *rconf = apr_palloc(r->pool, sizeof(proxy_req_conf));
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_set_module_config(r->request_config, &proxy_module, rconf);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe rconf->raliases = proxy_vars(r, dconf->raliases);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe rconf->cookie_paths = proxy_vars(r, dconf->cookie_paths);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe rconf->cookie_domains = proxy_vars(r, dconf->cookie_domains);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* canonicalise each specific scheme */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if ((access_status = proxy_run_canon_handler(r, url))) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe return access_status;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe p = strchr(url, ':');
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (p == NULL || p == url)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe return HTTP_BAD_REQUEST;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe return OK; /* otherwise; we've done the best we can */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe}
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe/* Send a redirection if the request contains a hostname which is not */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe/* fully qualified, i.e. doesn't have a domain name appended. Some proxy */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe/* servers like Netscape's allow this and access hosts from the local */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe/* domain in this case. I think it is better to redirect to a FQDN, since */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe/* these will later be found in the bookmarks files. */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe/* The "ProxyDomain" directive determines what domain will be appended */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowestatic int proxy_needsdomain(request_rec *r, const char *url, const char *domain)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe{
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe char *nuri;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe const char *ref;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* We only want to worry about GETs */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (!r->proxyreq || r->method_number != M_GET || !r->parsed_uri.hostname)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe return DECLINED;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* If host does contain a dot already, or it is "localhost", decline */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (strchr(r->parsed_uri.hostname, '.') != NULL
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe || strcasecmp(r->parsed_uri.hostname, "localhost") == 0)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe return DECLINED; /* host name has a dot already */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ref = apr_table_get(r->headers_in, "Referer");
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* Reassemble the request, but insert the domain after the host name */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* Note that the domain name always starts with a dot */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe r->parsed_uri.hostname = apr_pstrcat(r->pool, r->parsed_uri.hostname,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe domain, NULL);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe nuri = apr_uri_unparse(r->pool,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe &r->parsed_uri,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe APR_URI_UNP_REVEALPASSWORD);
2787ef5edc27fa4f6777ba8d51aa48fd9fdf54bbwrowe
2787ef5edc27fa4f6777ba8d51aa48fd9fdf54bbwrowe apr_table_set(r->headers_out, "Location", nuri);
2787ef5edc27fa4f6777ba8d51aa48fd9fdf54bbwrowe ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r,
2787ef5edc27fa4f6777ba8d51aa48fd9fdf54bbwrowe "Domain missing: %s sent to %s%s%s", r->uri,
2787ef5edc27fa4f6777ba8d51aa48fd9fdf54bbwrowe apr_uri_unparse(r->pool, &r->parsed_uri,
2787ef5edc27fa4f6777ba8d51aa48fd9fdf54bbwrowe APR_URI_UNP_OMITUSERINFO),
2787ef5edc27fa4f6777ba8d51aa48fd9fdf54bbwrowe ref ? " from " : "", ref ? ref : "");
2787ef5edc27fa4f6777ba8d51aa48fd9fdf54bbwrowe
2787ef5edc27fa4f6777ba8d51aa48fd9fdf54bbwrowe return HTTP_MOVED_PERMANENTLY;
2787ef5edc27fa4f6777ba8d51aa48fd9fdf54bbwrowe}
2787ef5edc27fa4f6777ba8d51aa48fd9fdf54bbwrowe
2787ef5edc27fa4f6777ba8d51aa48fd9fdf54bbwrowe/* -------------------------------------------------------------- */
2787ef5edc27fa4f6777ba8d51aa48fd9fdf54bbwrowe/* Invoke handler */
2787ef5edc27fa4f6777ba8d51aa48fd9fdf54bbwrowe
2787ef5edc27fa4f6777ba8d51aa48fd9fdf54bbwrowestatic int proxy_handler(request_rec *r)
2787ef5edc27fa4f6777ba8d51aa48fd9fdf54bbwrowe{
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe char *uri, *scheme, *p;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe const char *p2;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe void *sconf = r->server->module_config;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe proxy_server_conf *conf = (proxy_server_conf *)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_get_module_config(sconf, &proxy_module);
8aefbd756763807188d2e3ce336a8680e4893066wrowe apr_array_header_t *proxies = conf->proxies;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe struct proxy_remote *ents = (struct proxy_remote *) proxies->elts;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe int i, rc, access_status;
8aefbd756763807188d2e3ce336a8680e4893066wrowe int direct_connect = 0;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe const char *str;
8aefbd756763807188d2e3ce336a8680e4893066wrowe long maxfwd;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe proxy_balancer *balancer = NULL;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe proxy_worker *worker = NULL;
8aefbd756763807188d2e3ce336a8680e4893066wrowe int attempts = 0, max_attempts = 0;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe struct dirconn_entry *list = (struct dirconn_entry *)conf->dirconn->elts;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* is this for us? */
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (!r->proxyreq || !r->filename || strncmp(r->filename, "proxy:", 6) != 0)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe return DECLINED;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* handle max-forwards / OPTIONS / TRACE */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if ((str = apr_table_get(r->headers_in, "Max-Forwards"))) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe maxfwd = strtol(str, NULL, 10);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (maxfwd < 1) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe switch (r->method_number) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe case M_TRACE: {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe int access_status;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe r->proxyreq = PROXYREQ_NONE;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if ((access_status = ap_send_http_trace(r)))
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_die(access_status, r);
8aefbd756763807188d2e3ce336a8680e4893066wrowe else
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_finalize_request_protocol(r);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe return OK;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe case M_OPTIONS: {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe int access_status;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe r->proxyreq = PROXYREQ_NONE;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if ((access_status = ap_send_http_options(r)))
8aefbd756763807188d2e3ce336a8680e4893066wrowe ap_die(access_status, r);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe else
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_finalize_request_protocol(r);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe return OK;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe default: {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe return ap_proxyerror(r, HTTP_BAD_GATEWAY,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe "Max-Forwards has reached zero - proxy loop?");
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe maxfwd = (maxfwd > 0) ? maxfwd - 1 : 0;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe else {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* set configured max-forwards */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe maxfwd = conf->maxfwd;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe apr_table_set(r->headers_in, "Max-Forwards",
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe apr_psprintf(r->pool, "%ld", (maxfwd > 0) ? maxfwd : 0));
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (r->method_number == M_TRACE) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe core_server_config *coreconf = (core_server_config *)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_get_module_config(sconf, &core_module);
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (coreconf->trace_enable == AP_TRACE_DISABLE)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* Allow "error-notes" string to be printed by ap_send_error_response()
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * Note; this goes nowhere, canned error response need an overhaul.
8aefbd756763807188d2e3ce336a8680e4893066wrowe */
8aefbd756763807188d2e3ce336a8680e4893066wrowe apr_table_setn(r->notes, "error-notes",
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe "TRACE forbidden by server configuration");
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe apr_table_setn(r->notes, "verbose-error-to", "*");
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe "proxy: TRACE forbidden by server configuration");
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe return HTTP_METHOD_NOT_ALLOWED;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* Can't test ap_should_client_block, we aren't ready to send
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * the client a 100 Continue response till the connection has
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * been established
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (coreconf->trace_enable != AP_TRACE_EXTENDED
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe && (r->read_length || r->read_chunked || r->remaining))
8aefbd756763807188d2e3ce336a8680e4893066wrowe {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* Allow "error-notes" string to be printed by ap_send_error_response()
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * Note; this goes nowhere, canned error response need an overhaul.
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe apr_table_setn(r->notes, "error-notes",
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe "TRACE with request body is not allowed");
cadddb2c31d24d48f4017db4df0a29687432326cwrowe apr_table_setn(r->notes, "verbose-error-to", "*");
cadddb2c31d24d48f4017db4df0a29687432326cwrowe ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe "proxy: TRACE with request body is not allowed");
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe return HTTP_REQUEST_ENTITY_TOO_LARGE;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe uri = r->filename + 6;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe p = strchr(uri, ':');
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (p == NULL) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe "proxy_handler no URL in %s", r->filename);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe return HTTP_BAD_REQUEST;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* If the host doesn't have a domain name, add one and redirect. */
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (conf->domain != NULL) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe rc = proxy_needsdomain(r, uri, conf->domain);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (ap_is_HTTP_REDIRECT(rc))
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe return HTTP_MOVED_PERMANENTLY;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe scheme = apr_pstrndup(r->pool, uri, p - uri);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* Check URI's destination host against NoProxy hosts */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* Bypass ProxyRemote server lookup if configured as NoProxy */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe for (direct_connect = i = 0; i < conf->dirconn->nelts &&
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe !direct_connect; i++) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe direct_connect = list[i].matcher(&list[i], r);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe#if DEBUGGING
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
8aefbd756763807188d2e3ce336a8680e4893066wrowe (direct_connect) ? "NoProxy for %s" : "UseProxy for %s",
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe r->uri);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe#endif
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe do {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe char *url = uri;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* Try to obtain the most suitable worker */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe access_status = ap_proxy_pre_request(&worker, &balancer, r, conf, &url);
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (access_status != OK) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /*
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * Only return if access_status is not HTTP_SERVICE_UNAVAILABLE
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * This gives other modules the chance to hook into the
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * request_status hook and decide what to do in this situation.
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (access_status != HTTP_SERVICE_UNAVAILABLE)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe return access_status;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /*
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * Ensure that balancer is NULL if worker is NULL to prevent
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe * potential problems in the post_request hook.
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (!worker)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe balancer = NULL;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe goto cleanup;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (balancer && balancer->max_attempts_set && !max_attempts)
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe max_attempts = balancer->max_attempts;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* firstly, try a proxy, unless a NoProxy directive is active */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (!direct_connect) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe for (i = 0; i < proxies->nelts; i++) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe p2 = ap_strchr_c(ents[i].scheme, ':'); /* is it a partial URL? */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (strcmp(ents[i].scheme, "*") == 0 ||
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe (ents[i].use_regex &&
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_regexec(ents[i].regexp, url, 0, NULL, 0) == 0) ||
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe (p2 == NULL && strcasecmp(scheme, ents[i].scheme) == 0) ||
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe (p2 != NULL &&
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe strncasecmp(url, ents[i].scheme,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe strlen(ents[i].scheme)) == 0)) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* handle the scheme */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe "Trying to run scheme_handler against proxy");
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe access_status = proxy_run_scheme_handler(r, worker,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe conf, url,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ents[i].hostname,
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe ents[i].port);
8aefbd756763807188d2e3ce336a8680e4893066wrowe
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* an error or success */
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe if (access_status != DECLINED &&
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe access_status != HTTP_BAD_GATEWAY) {
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe goto cleanup;
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe }
e4a3f3c2f080cac75a15a6454cca429b8161c050wrowe /* we failed to talk to the upstream proxy */
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe /* otherwise, try it direct */
8aefbd756763807188d2e3ce336a8680e4893066wrowe /* N.B. what if we're behind a firewall, where we must use a proxy or
8aefbd756763807188d2e3ce336a8680e4893066wrowe * give up??
8aefbd756763807188d2e3ce336a8680e4893066wrowe */
8aefbd756763807188d2e3ce336a8680e4893066wrowe
8aefbd756763807188d2e3ce336a8680e4893066wrowe /* handle the scheme */
8aefbd756763807188d2e3ce336a8680e4893066wrowe ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
8aefbd756763807188d2e3ce336a8680e4893066wrowe "Running scheme %s handler (attempt %d)",
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe scheme, attempts);
8aefbd756763807188d2e3ce336a8680e4893066wrowe access_status = proxy_run_scheme_handler(r, worker, conf,
8aefbd756763807188d2e3ce336a8680e4893066wrowe url, NULL, 0);
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (access_status == OK)
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe break;
8aefbd756763807188d2e3ce336a8680e4893066wrowe else if (access_status == HTTP_INTERNAL_SERVER_ERROR) {
8aefbd756763807188d2e3ce336a8680e4893066wrowe /* Unrecoverable server error.
8aefbd756763807188d2e3ce336a8680e4893066wrowe * We can not failover to another worker.
8aefbd756763807188d2e3ce336a8680e4893066wrowe * Mark the worker as unusable if member of load balancer
8aefbd756763807188d2e3ce336a8680e4893066wrowe */
8aefbd756763807188d2e3ce336a8680e4893066wrowe if (balancer)
0540a0b469147b52e858587270dba31c2aaa9e09wrowe worker->s->status |= PROXY_WORKER_IN_ERROR;
0540a0b469147b52e858587270dba31c2aaa9e09wrowe break;
0540a0b469147b52e858587270dba31c2aaa9e09wrowe }
0540a0b469147b52e858587270dba31c2aaa9e09wrowe else if (access_status == HTTP_SERVICE_UNAVAILABLE) {
0540a0b469147b52e858587270dba31c2aaa9e09wrowe /* Recoverable server error.
0540a0b469147b52e858587270dba31c2aaa9e09wrowe * We can failover to another worker
a9a4544168a37b43bd180b3703ccee995f27a80awrowe * Mark the worker as unusable if member of load balancer
0540a0b469147b52e858587270dba31c2aaa9e09wrowe */
0540a0b469147b52e858587270dba31c2aaa9e09wrowe if (balancer) {
0540a0b469147b52e858587270dba31c2aaa9e09wrowe worker->s->status |= PROXY_WORKER_IN_ERROR;
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe }
0540a0b469147b52e858587270dba31c2aaa9e09wrowe }
0540a0b469147b52e858587270dba31c2aaa9e09wrowe else {
0540a0b469147b52e858587270dba31c2aaa9e09wrowe /* Unrecoverable error.
0540a0b469147b52e858587270dba31c2aaa9e09wrowe * Return the origin status code to the client.
0540a0b469147b52e858587270dba31c2aaa9e09wrowe */
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe break;
0540a0b469147b52e858587270dba31c2aaa9e09wrowe }
8aefbd756763807188d2e3ce336a8680e4893066wrowe /* Try again if the worker is unusable and the service is
8aefbd756763807188d2e3ce336a8680e4893066wrowe * unavailable.
0540a0b469147b52e858587270dba31c2aaa9e09wrowe */
a2a0abd88b19e042a3eb2a9fa1702c25ad51303dwrowe } while (!PROXY_WORKER_IS_USABLE(worker) &&
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb max_attempts > attempts++);
948096a99010fccf648814fecf38f75c689172d7wrowe
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (DECLINED == access_status) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_log_error(APLOG_MARK, APLOG_WARNING, 0, r->server,
0540a0b469147b52e858587270dba31c2aaa9e09wrowe "proxy: No protocol handler was valid for the URL %s. "
0540a0b469147b52e858587270dba31c2aaa9e09wrowe "If you are using a DSO version of mod_proxy, make sure "
948096a99010fccf648814fecf38f75c689172d7wrowe "the proxy submodules are included in the configuration "
948096a99010fccf648814fecf38f75c689172d7wrowe "using LoadModule.", r->uri);
948096a99010fccf648814fecf38f75c689172d7wrowe access_status = HTTP_FORBIDDEN;
cc9582e53aead2a044077c4a92f3dfc3605590b3wrowe goto cleanup;
3f5b4558f5410fdac5d6feed7aab0c3668f9cd13wrowe }
948096a99010fccf648814fecf38f75c689172d7wrowecleanup:
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe if (balancer) {
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe int post_status = proxy_run_post_request(worker, balancer, r, conf);
053497224246c4dbef9af594cacf5c00ed271e6cwrowe if (post_status == DECLINED) {
0540a0b469147b52e858587270dba31c2aaa9e09wrowe post_status = OK; /* no post_request handler available */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* TODO: recycle direct worker */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
948096a99010fccf648814fecf38f75c689172d7wrowe
948096a99010fccf648814fecf38f75c689172d7wrowe proxy_run_request_status(&access_status, r);
948096a99010fccf648814fecf38f75c689172d7wrowe
948096a99010fccf648814fecf38f75c689172d7wrowe return access_status;
948096a99010fccf648814fecf38f75c689172d7wrowe}
948096a99010fccf648814fecf38f75c689172d7wrowe
948096a99010fccf648814fecf38f75c689172d7wrowe/* -------------------------------------------------------------- */
948096a99010fccf648814fecf38f75c689172d7wrowe/* Setup configurable data */
948096a99010fccf648814fecf38f75c689172d7wrowe
948096a99010fccf648814fecf38f75c689172d7wrowestatic void * create_proxy_config(apr_pool_t *p, server_rec *s)
948096a99010fccf648814fecf38f75c689172d7wrowe{
948096a99010fccf648814fecf38f75c689172d7wrowe proxy_server_conf *ps = apr_pcalloc(p, sizeof(proxy_server_conf));
948096a99010fccf648814fecf38f75c689172d7wrowe
053497224246c4dbef9af594cacf5c00ed271e6cwrowe ps->sec_proxy = apr_array_make(p, 10, sizeof(ap_conf_vector_t *));
948096a99010fccf648814fecf38f75c689172d7wrowe ps->proxies = apr_array_make(p, 10, sizeof(struct proxy_remote));
948096a99010fccf648814fecf38f75c689172d7wrowe ps->aliases = apr_array_make(p, 10, sizeof(struct proxy_alias));
948096a99010fccf648814fecf38f75c689172d7wrowe ps->noproxies = apr_array_make(p, 10, sizeof(struct noproxy_entry));
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ps->dirconn = apr_array_make(p, 10, sizeof(struct dirconn_entry));
0540a0b469147b52e858587270dba31c2aaa9e09wrowe ps->allowed_connect_ports = apr_array_make(p, 10, sizeof(int));
948096a99010fccf648814fecf38f75c689172d7wrowe ps->workers = apr_array_make(p, 10, sizeof(proxy_worker));
948096a99010fccf648814fecf38f75c689172d7wrowe ps->balancers = apr_array_make(p, 10, sizeof(proxy_balancer));
948096a99010fccf648814fecf38f75c689172d7wrowe ps->forward = NULL;
948096a99010fccf648814fecf38f75c689172d7wrowe ps->reverse = NULL;
948096a99010fccf648814fecf38f75c689172d7wrowe ps->domain = NULL;
053497224246c4dbef9af594cacf5c00ed271e6cwrowe ps->viaopt = via_off; /* initially backward compatible with 1.3.1 */
a9a4544168a37b43bd180b3703ccee995f27a80awrowe ps->viaopt_set = 0; /* 0 means default */
948096a99010fccf648814fecf38f75c689172d7wrowe ps->req = 0;
a9a4544168a37b43bd180b3703ccee995f27a80awrowe ps->req_set = 0;
a9a4544168a37b43bd180b3703ccee995f27a80awrowe ps->recv_buffer_size = 0; /* this default was left unset for some reason */
a9a4544168a37b43bd180b3703ccee995f27a80awrowe ps->recv_buffer_size_set = 0;
a9a4544168a37b43bd180b3703ccee995f27a80awrowe ps->io_buffer_size = AP_IOBUFSIZE;
a9a4544168a37b43bd180b3703ccee995f27a80awrowe ps->io_buffer_size_set = 0;
948096a99010fccf648814fecf38f75c689172d7wrowe ps->maxfwd = DEFAULT_MAX_FORWARDS;
948096a99010fccf648814fecf38f75c689172d7wrowe ps->maxfwd_set = 0;
948096a99010fccf648814fecf38f75c689172d7wrowe ps->error_override = 0;
948096a99010fccf648814fecf38f75c689172d7wrowe ps->error_override_set = 0;
948096a99010fccf648814fecf38f75c689172d7wrowe ps->preserve_host_set = 0;
948096a99010fccf648814fecf38f75c689172d7wrowe ps->preserve_host = 0;
948096a99010fccf648814fecf38f75c689172d7wrowe ps->timeout = 0;
948096a99010fccf648814fecf38f75c689172d7wrowe ps->timeout_set = 0;
0540a0b469147b52e858587270dba31c2aaa9e09wrowe ps->badopt = bad_error;
948096a99010fccf648814fecf38f75c689172d7wrowe ps->badopt_set = 0;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ps->pool = p;
948096a99010fccf648814fecf38f75c689172d7wrowe
948096a99010fccf648814fecf38f75c689172d7wrowe return ps;
948096a99010fccf648814fecf38f75c689172d7wrowe}
948096a99010fccf648814fecf38f75c689172d7wrowe
948096a99010fccf648814fecf38f75c689172d7wrowestatic void * merge_proxy_config(apr_pool_t *p, void *basev, void *overridesv)
053497224246c4dbef9af594cacf5c00ed271e6cwrowe{
0540a0b469147b52e858587270dba31c2aaa9e09wrowe proxy_server_conf *ps = apr_pcalloc(p, sizeof(proxy_server_conf));
053497224246c4dbef9af594cacf5c00ed271e6cwrowe proxy_server_conf *base = (proxy_server_conf *) basev;
0540a0b469147b52e858587270dba31c2aaa9e09wrowe proxy_server_conf *overrides = (proxy_server_conf *) overridesv;
0540a0b469147b52e858587270dba31c2aaa9e09wrowe
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ps->proxies = apr_array_append(p, base->proxies, overrides->proxies);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ps->sec_proxy = apr_array_append(p, base->sec_proxy, overrides->sec_proxy);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ps->aliases = apr_array_append(p, base->aliases, overrides->aliases);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ps->noproxies = apr_array_append(p, base->noproxies, overrides->noproxies);
053497224246c4dbef9af594cacf5c00ed271e6cwrowe ps->dirconn = apr_array_append(p, base->dirconn, overrides->dirconn);
053497224246c4dbef9af594cacf5c00ed271e6cwrowe ps->allowed_connect_ports = apr_array_append(p, base->allowed_connect_ports, overrides->allowed_connect_ports);
053497224246c4dbef9af594cacf5c00ed271e6cwrowe ps->workers = apr_array_append(p, base->workers, overrides->workers);
053497224246c4dbef9af594cacf5c00ed271e6cwrowe ps->balancers = apr_array_append(p, base->balancers, overrides->balancers);
053497224246c4dbef9af594cacf5c00ed271e6cwrowe ps->forward = overrides->forward ? overrides->forward : base->forward;
053497224246c4dbef9af594cacf5c00ed271e6cwrowe ps->reverse = overrides->reverse ? overrides->reverse : base->reverse;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ps->domain = (overrides->domain == NULL) ? base->domain : overrides->domain;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ps->viaopt = (overrides->viaopt_set == 0) ? base->viaopt : overrides->viaopt;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ps->viaopt_set = overrides->viaopt_set || base->viaopt_set;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ps->req = (overrides->req_set == 0) ? base->req : overrides->req;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ps->req_set = overrides->req_set || base->req_set;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ps->recv_buffer_size = (overrides->recv_buffer_size_set == 0) ? base->recv_buffer_size : overrides->recv_buffer_size;
053497224246c4dbef9af594cacf5c00ed271e6cwrowe ps->recv_buffer_size_set = overrides->recv_buffer_size_set || base->recv_buffer_size_set;
053497224246c4dbef9af594cacf5c00ed271e6cwrowe 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;
948096a99010fccf648814fecf38f75c689172d7wrowe ps->maxfwd = (overrides->maxfwd_set == 0) ? base->maxfwd : overrides->maxfwd;
948096a99010fccf648814fecf38f75c689172d7wrowe ps->maxfwd_set = overrides->maxfwd_set || base->maxfwd_set;
948096a99010fccf648814fecf38f75c689172d7wrowe ps->error_override = (overrides->error_override_set == 0) ? base->error_override : overrides->error_override;
0540a0b469147b52e858587270dba31c2aaa9e09wrowe ps->error_override_set = overrides->error_override_set || base->error_override_set;
948096a99010fccf648814fecf38f75c689172d7wrowe ps->preserve_host = (overrides->preserve_host_set == 0) ? base->preserve_host : overrides->preserve_host;
948096a99010fccf648814fecf38f75c689172d7wrowe ps->preserve_host_set = overrides->preserve_host_set || base->preserve_host_set;
948096a99010fccf648814fecf38f75c689172d7wrowe ps->timeout= (overrides->timeout_set == 0) ? base->timeout : overrides->timeout;
948096a99010fccf648814fecf38f75c689172d7wrowe ps->timeout_set = overrides->timeout_set || base->timeout_set;
948096a99010fccf648814fecf38f75c689172d7wrowe ps->badopt = (overrides->badopt_set == 0) ? base->badopt : overrides->badopt;
948096a99010fccf648814fecf38f75c689172d7wrowe ps->badopt_set = overrides->badopt_set || base->badopt_set;
948096a99010fccf648814fecf38f75c689172d7wrowe ps->proxy_status = (overrides->proxy_status_set == 0) ? base->proxy_status : overrides->proxy_status;
948096a99010fccf648814fecf38f75c689172d7wrowe ps->proxy_status_set = overrides->proxy_status_set || base->proxy_status_set;
948096a99010fccf648814fecf38f75c689172d7wrowe ps->pool = p;
948096a99010fccf648814fecf38f75c689172d7wrowe return ps;
948096a99010fccf648814fecf38f75c689172d7wrowe}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
948096a99010fccf648814fecf38f75c689172d7wrowestatic void *create_proxy_dir_config(apr_pool_t *p, char *dummy)
948096a99010fccf648814fecf38f75c689172d7wrowe{
948096a99010fccf648814fecf38f75c689172d7wrowe proxy_dir_conf *new =
0540a0b469147b52e858587270dba31c2aaa9e09wrowe (proxy_dir_conf *) apr_pcalloc(p, sizeof(proxy_dir_conf));
948096a99010fccf648814fecf38f75c689172d7wrowe
0540a0b469147b52e858587270dba31c2aaa9e09wrowe /* Filled in by proxysection, when applicable */
696218c49632c863d18b25fa52ab63617088cb38wrowe
948096a99010fccf648814fecf38f75c689172d7wrowe /* Put these in the dir config so they work inside <Location> */
0540a0b469147b52e858587270dba31c2aaa9e09wrowe new->raliases = apr_array_make(p, 10, sizeof(struct proxy_alias));
948096a99010fccf648814fecf38f75c689172d7wrowe new->cookie_paths = apr_array_make(p, 10, sizeof(struct proxy_alias));
948096a99010fccf648814fecf38f75c689172d7wrowe new->cookie_domains = apr_array_make(p, 10, sizeof(struct proxy_alias));
948096a99010fccf648814fecf38f75c689172d7wrowe new->cookie_path_str = apr_strmatch_precompile(p, "path=", 0);
948096a99010fccf648814fecf38f75c689172d7wrowe new->cookie_domain_str = apr_strmatch_precompile(p, "domain=", 0);
053497224246c4dbef9af594cacf5c00ed271e6cwrowe new->interpolate_env = -1; /* unset */
948096a99010fccf648814fecf38f75c689172d7wrowe
948096a99010fccf648814fecf38f75c689172d7wrowe return (void *) new;
053497224246c4dbef9af594cacf5c00ed271e6cwrowe}
053497224246c4dbef9af594cacf5c00ed271e6cwrowe
a9a4544168a37b43bd180b3703ccee995f27a80awrowestatic void *merge_proxy_dir_config(apr_pool_t *p, void *basev, void *addv)
a9a4544168a37b43bd180b3703ccee995f27a80awrowe{
a9a4544168a37b43bd180b3703ccee995f27a80awrowe proxy_dir_conf *new = (proxy_dir_conf *) apr_pcalloc(p, sizeof(proxy_dir_conf));
948096a99010fccf648814fecf38f75c689172d7wrowe proxy_dir_conf *add = (proxy_dir_conf *) addv;
948096a99010fccf648814fecf38f75c689172d7wrowe proxy_dir_conf *base = (proxy_dir_conf *) basev;
053497224246c4dbef9af594cacf5c00ed271e6cwrowe
948096a99010fccf648814fecf38f75c689172d7wrowe new->p = add->p;
053497224246c4dbef9af594cacf5c00ed271e6cwrowe new->p_is_fnmatch = add->p_is_fnmatch;
053497224246c4dbef9af594cacf5c00ed271e6cwrowe new->r = add->r;
948096a99010fccf648814fecf38f75c689172d7wrowe
948096a99010fccf648814fecf38f75c689172d7wrowe /* Put these in the dir config so they work inside <Location> */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb new->raliases = apr_array_append(p, base->raliases, add->raliases);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb new->cookie_paths
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb = apr_array_append(p, base->cookie_paths, add->cookie_paths);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb new->cookie_domains
a2a0abd88b19e042a3eb2a9fa1702c25ad51303dwrowe = apr_array_append(p, base->cookie_domains, add->cookie_domains);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb new->cookie_path_str = base->cookie_path_str;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe new->cookie_domain_str = base->cookie_domain_str;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe new->interpolate_env = (add->interpolate_env == -1) ? base->interpolate_env
aa047239dedf0d26e8efecfade32e7337f35df19wrowe : add->interpolate_env;
0540a0b469147b52e858587270dba31c2aaa9e09wrowe return new;
0540a0b469147b52e858587270dba31c2aaa9e09wrowe}
aa047239dedf0d26e8efecfade32e7337f35df19wrowe
aa047239dedf0d26e8efecfade32e7337f35df19wrowe
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic const char *
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe add_proxy(cmd_parms *cmd, void *dummy, const char *f1, const char *r1, int regex)
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe{
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe server_rec *s = cmd->server;
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe proxy_server_conf *conf =
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe (proxy_server_conf *) ap_get_module_config(s->module_config, &proxy_module);
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe struct proxy_remote *new;
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe char *p, *q;
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe char *r, *f, *scheme;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ap_regex_t *reg = NULL;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe int port;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe
aa047239dedf0d26e8efecfade32e7337f35df19wrowe r = apr_pstrdup(cmd->pool, r1);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe scheme = apr_pstrdup(cmd->pool, r1);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe f = apr_pstrdup(cmd->pool, f1);
0540a0b469147b52e858587270dba31c2aaa9e09wrowe p = strchr(r, ':');
aa047239dedf0d26e8efecfade32e7337f35df19wrowe if (p == NULL || p[1] != '/' || p[2] != '/' || p[3] == '\0') {
aa047239dedf0d26e8efecfade32e7337f35df19wrowe if (regex)
aa047239dedf0d26e8efecfade32e7337f35df19wrowe return "ProxyRemoteMatch: Bad syntax for a remote proxy server";
aa047239dedf0d26e8efecfade32e7337f35df19wrowe else
aa047239dedf0d26e8efecfade32e7337f35df19wrowe return "ProxyRemote: Bad syntax for a remote proxy server";
aa047239dedf0d26e8efecfade32e7337f35df19wrowe }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb scheme[p-r] = 0;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb q = strchr(p + 3, ':');
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (q != NULL) {
aa047239dedf0d26e8efecfade32e7337f35df19wrowe if (sscanf(q + 1, "%u", &port) != 1 || port > 65535) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (regex)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return "ProxyRemoteMatch: Bad syntax for a remote proxy server (bad port number)";
aa047239dedf0d26e8efecfade32e7337f35df19wrowe else
aa047239dedf0d26e8efecfade32e7337f35df19wrowe return "ProxyRemote: Bad syntax for a remote proxy server (bad port number)";
aa047239dedf0d26e8efecfade32e7337f35df19wrowe }
aa047239dedf0d26e8efecfade32e7337f35df19wrowe *q = '\0';
0540a0b469147b52e858587270dba31c2aaa9e09wrowe }
aa047239dedf0d26e8efecfade32e7337f35df19wrowe else
aa047239dedf0d26e8efecfade32e7337f35df19wrowe port = -1;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe *p = '\0';
aa047239dedf0d26e8efecfade32e7337f35df19wrowe if (regex) {
aa047239dedf0d26e8efecfade32e7337f35df19wrowe reg = ap_pregcomp(cmd->pool, f, AP_REG_EXTENDED);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe if (!reg)
a9a4544168a37b43bd180b3703ccee995f27a80awrowe return "Regular expression for ProxyRemoteMatch could not be compiled.";
a9a4544168a37b43bd180b3703ccee995f27a80awrowe }
a9a4544168a37b43bd180b3703ccee995f27a80awrowe else
a9a4544168a37b43bd180b3703ccee995f27a80awrowe if (strchr(f, ':') == NULL)
a9a4544168a37b43bd180b3703ccee995f27a80awrowe ap_str_tolower(f); /* lowercase scheme */
aa047239dedf0d26e8efecfade32e7337f35df19wrowe ap_str_tolower(p + 3); /* lowercase hostname */
a9a4544168a37b43bd180b3703ccee995f27a80awrowe
aa047239dedf0d26e8efecfade32e7337f35df19wrowe if (port == -1) {
aa047239dedf0d26e8efecfade32e7337f35df19wrowe port = apr_uri_port_of_scheme(scheme);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe }
aa047239dedf0d26e8efecfade32e7337f35df19wrowe
aa047239dedf0d26e8efecfade32e7337f35df19wrowe new = apr_array_push(conf->proxies);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe new->scheme = f;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe new->protocol = r;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe new->hostname = p + 3;
0540a0b469147b52e858587270dba31c2aaa9e09wrowe new->port = port;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe new->regexp = reg;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe new->use_regex = regex;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe return NULL;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
aa047239dedf0d26e8efecfade32e7337f35df19wrowe
aa047239dedf0d26e8efecfade32e7337f35df19wrowestatic const char *
aa047239dedf0d26e8efecfade32e7337f35df19wrowe add_proxy_noregex(cmd_parms *cmd, void *dummy, const char *f1, const char *r1)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
0540a0b469147b52e858587270dba31c2aaa9e09wrowe return add_proxy(cmd, dummy, f1, r1, 0);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe}
0540a0b469147b52e858587270dba31c2aaa9e09wrowe
0540a0b469147b52e858587270dba31c2aaa9e09wrowestatic const char *
aa047239dedf0d26e8efecfade32e7337f35df19wrowe add_proxy_regex(cmd_parms *cmd, void *dummy, const char *f1, const char *r1)
aa047239dedf0d26e8efecfade32e7337f35df19wrowe{
aa047239dedf0d26e8efecfade32e7337f35df19wrowe return add_proxy(cmd, dummy, f1, r1, 1);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe}
aa047239dedf0d26e8efecfade32e7337f35df19wrowe
aa047239dedf0d26e8efecfade32e7337f35df19wrowestatic const char *
aa047239dedf0d26e8efecfade32e7337f35df19wrowe add_pass(cmd_parms *cmd, void *dummy, const char *arg, int is_regex)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
aa047239dedf0d26e8efecfade32e7337f35df19wrowe server_rec *s = cmd->server;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe proxy_server_conf *conf =
aa047239dedf0d26e8efecfade32e7337f35df19wrowe (proxy_server_conf *) ap_get_module_config(s->module_config, &proxy_module);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe struct proxy_alias *new;
0540a0b469147b52e858587270dba31c2aaa9e09wrowe char *f = cmd->path;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe char *r = NULL;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe char *word;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe apr_table_t *params = apr_table_make(cmd->pool, 5);
aa047239dedf0d26e8efecfade32e7337f35df19wrowe const apr_array_header_t *arr;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb const apr_table_entry_t *elts;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe int i;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe int use_regex = is_regex;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe
aa047239dedf0d26e8efecfade32e7337f35df19wrowe while (*arg) {
aa047239dedf0d26e8efecfade32e7337f35df19wrowe word = ap_getword_conf(cmd->pool, &arg);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (!f) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (!strcmp(word, "~")) {
aa047239dedf0d26e8efecfade32e7337f35df19wrowe if (is_regex) {
aa047239dedf0d26e8efecfade32e7337f35df19wrowe return "ProxyPassMatch invalid syntax ('~' usage).";
aa047239dedf0d26e8efecfade32e7337f35df19wrowe }
0540a0b469147b52e858587270dba31c2aaa9e09wrowe use_regex = 1;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe continue;
0540a0b469147b52e858587270dba31c2aaa9e09wrowe }
aa047239dedf0d26e8efecfade32e7337f35df19wrowe f = word;
aa047239dedf0d26e8efecfade32e7337f35df19wrowe }
0540a0b469147b52e858587270dba31c2aaa9e09wrowe else if (!r)
aa047239dedf0d26e8efecfade32e7337f35df19wrowe r = word;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else {
aa047239dedf0d26e8efecfade32e7337f35df19wrowe char *val = strchr(word, '=');
aa047239dedf0d26e8efecfade32e7337f35df19wrowe if (!val) {
aa047239dedf0d26e8efecfade32e7337f35df19wrowe if (cmd->path) {
aa047239dedf0d26e8efecfade32e7337f35df19wrowe if (*r == '/') {
aa047239dedf0d26e8efecfade32e7337f35df19wrowe return "ProxyPass|ProxyPassMatch can not have a path when defined in "
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "a location.";
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe }
a9a4544168a37b43bd180b3703ccee995f27a80awrowe else {
a9a4544168a37b43bd180b3703ccee995f27a80awrowe return "Invalid ProxyPass|ProxyPassMatch parameter. Parameter must "
a9a4544168a37b43bd180b3703ccee995f27a80awrowe "be in the form 'key=value'.";
aa047239dedf0d26e8efecfade32e7337f35df19wrowe }
aa047239dedf0d26e8efecfade32e7337f35df19wrowe }
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe else {
aa047239dedf0d26e8efecfade32e7337f35df19wrowe return "Invalid ProxyPass|ProxyPassMatch parameter. Parameter must be "
aa047239dedf0d26e8efecfade32e7337f35df19wrowe "in the form 'key=value'.";
aa047239dedf0d26e8efecfade32e7337f35df19wrowe }
aa047239dedf0d26e8efecfade32e7337f35df19wrowe }
aa047239dedf0d26e8efecfade32e7337f35df19wrowe else
dc8692c6c0ca616a09aa12dad005f2ef23baa1a0wrowe *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 new = apr_array_push(conf->aliases);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb new->fake = apr_pstrdup(cmd->pool, f);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb new->real = apr_pstrdup(cmd->pool, r);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (use_regex) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb new->regex = ap_pregcomp(cmd->pool, f, AP_REG_EXTENDED);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (new->regex == NULL)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return "Regular expression could not be compiled.";
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb new->regex = NULL;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (r[0] == '!' && r[1] == '\0')
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return NULL;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb arr = apr_table_elts(params);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb elts = (const apr_table_entry_t *)arr->elts;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Distinguish the balancer from worker */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (strncasecmp(r, "balancer:", 9) == 0) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb proxy_balancer *balancer = ap_proxy_get_balancer(cmd->pool, conf, r);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (!balancer) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb const char *err = ap_proxy_add_balancer(&balancer,
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb cmd->pool,
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe conf, r);
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe if (err)
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe return apr_pstrcat(cmd->temp_pool, "ProxyPass ", err, NULL);
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe }
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe for (i = 0; i < arr->nelts; i++) {
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe const char *err = set_balancer_param(conf, cmd->pool, balancer, elts[i].key,
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe elts[i].val);
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe if (err)
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe return apr_pstrcat(cmd->temp_pool, "ProxyPass ", err, NULL);
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe }
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe }
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe else {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe proxy_worker *worker = ap_proxy_get_worker(cmd->temp_pool, conf, r);
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe if (!worker) {
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe const char *err = ap_proxy_add_worker(&worker, cmd->pool, conf, r);
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe if (err)
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe return apr_pstrcat(cmd->temp_pool, "ProxyPass ", err, NULL);
fa06de8a28a737e8fbaad76d7f3ff67aaa5e4a09wrowe } else {
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe ap_log_error(APLOG_MARK, APLOG_WARNING, 0, cmd->server,
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe "worker %s already used by another worker", worker->name);
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe }
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe PROXY_COPY_CONF_PARAMS(worker, conf);
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe for (i = 0; i < arr->nelts; i++) {
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe const char *err = set_worker_param(cmd->pool, worker, elts[i].key,
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe elts[i].val);
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe if (err)
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe return apr_pstrcat(cmd->temp_pool, "ProxyPass ", err, NULL);
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe }
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe }
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe return NULL;
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe}
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowestatic const char *
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe add_pass_noregex(cmd_parms *cmd, void *dummy, const char *arg)
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe{
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe return add_pass(cmd, dummy, arg, 0);
e68544ae924174ca227ede8e2e722cefa00ea0d3wrowe}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic const char *
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb add_pass_regex(cmd_parms *cmd, void *dummy, const char *arg)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return add_pass(cmd, dummy, arg, 1);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
68b29bcadd6c46aecdc9fe14c93555a2238ad2aagregamesstatic const char *
68b29bcadd6c46aecdc9fe14c93555a2238ad2aagregames add_pass_reverse(cmd_parms *cmd, void *dconf, const char *f, const char *r)
68b29bcadd6c46aecdc9fe14c93555a2238ad2aagregames{
68b29bcadd6c46aecdc9fe14c93555a2238ad2aagregames proxy_dir_conf *conf = dconf;
68b29bcadd6c46aecdc9fe14c93555a2238ad2aagregames struct proxy_alias *new;
68b29bcadd6c46aecdc9fe14c93555a2238ad2aagregames
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (r!=NULL && cmd->path == NULL ) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb new = apr_array_push(conf->raliases);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb new->fake = f;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb new->real = r;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb } else if (r==NULL && cmd->path != NULL) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb new = apr_array_push(conf->raliases);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb new->fake = cmd->path;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb new->real = f;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb } else {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if ( r == NULL)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return "ProxyPassReverse needs a path when not defined in a location";
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return "ProxyPassReverse can not have a path when defined in a location";
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return NULL;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
48d2edbfb84e5559b5da0f8d614ccab805cc67a8rbbstatic const char*
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb cookie_path(cmd_parms *cmd, void *dconf, const char *f, const char *r)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb proxy_dir_conf *conf = dconf;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb struct proxy_alias *new;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe new = apr_array_push(conf->cookie_paths);
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe new->fake = f;
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe new->real = r;
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe return NULL;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowestatic const char*
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe cookie_domain(cmd_parms *cmd, void *dconf, const char *f, const char *r)
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe{
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe proxy_dir_conf *conf = dconf;
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe struct proxy_alias *new;
1b839c67d5c0e4b1f22b44a4217f9860b420d47cwrowe
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb new = apr_array_push(conf->cookie_domains);
1ab995011876f631740d68d960a6d729ddff5bfawrowe new->fake = f;
b45c1c292ff1fa635004ae81fa691f8cb3cdda85rbb new->real = r;
b45c1c292ff1fa635004ae81fa691f8cb3cdda85rbb
b45c1c292ff1fa635004ae81fa691f8cb3cdda85rbb return NULL;
b45c1c292ff1fa635004ae81fa691f8cb3cdda85rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic const char *
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb set_proxy_exclude(cmd_parms *parms, void *dummy, const char *arg)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb server_rec *s = parms->server;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb proxy_server_conf *conf =
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_get_module_config(s->module_config, &proxy_module);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb struct noproxy_entry *new;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb struct noproxy_entry *list = (struct noproxy_entry *) conf->noproxies->elts;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb struct apr_sockaddr_t *addr;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb int found = 0;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb int i;
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb /* Don't duplicate entries */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb for (i = 0; i < conf->noproxies->nelts; i++) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (strcasecmp(arg, list[i].name) == 0) { /* ignore case for host names */
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb found = 1;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (!found) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb new = apr_array_push(conf->noproxies);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb new->name = arg;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (APR_SUCCESS == apr_sockaddr_info_get(&addr, new->name, APR_UNSPEC, 0, 0, parms->pool)) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb new->addr = addr;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
efa1a34b0a7785fc72863eff175b0cfc1ecb0e38wrowe else {
117026201e6d8fe7d82416b8a7324830f5a87292wrowe new->addr = NULL;
117026201e6d8fe7d82416b8a7324830f5a87292wrowe }
117026201e6d8fe7d82416b8a7324830f5a87292wrowe }
117026201e6d8fe7d82416b8a7324830f5a87292wrowe return NULL;
117026201e6d8fe7d82416b8a7324830f5a87292wrowe}
117026201e6d8fe7d82416b8a7324830f5a87292wrowe
6c24fd6cfe148639988d5b335185ffb215662801wrowe/*
117026201e6d8fe7d82416b8a7324830f5a87292wrowe * Set the ports CONNECT can use
117026201e6d8fe7d82416b8a7324830f5a87292wrowe */
117026201e6d8fe7d82416b8a7324830f5a87292wrowestatic const char *
117026201e6d8fe7d82416b8a7324830f5a87292wrowe set_allowed_ports(cmd_parms *parms, void *dummy, const char *arg)
1ab995011876f631740d68d960a6d729ddff5bfawrowe{
117026201e6d8fe7d82416b8a7324830f5a87292wrowe server_rec *s = parms->server;
117026201e6d8fe7d82416b8a7324830f5a87292wrowe proxy_server_conf *conf =
117026201e6d8fe7d82416b8a7324830f5a87292wrowe ap_get_module_config(s->module_config, &proxy_module);
117026201e6d8fe7d82416b8a7324830f5a87292wrowe int *New;
cadddb2c31d24d48f4017db4df0a29687432326cwrowe
cadddb2c31d24d48f4017db4df0a29687432326cwrowe if (!apr_isdigit(arg[0]))
117026201e6d8fe7d82416b8a7324830f5a87292wrowe return "AllowCONNECT: port number must be numeric";
6c24fd6cfe148639988d5b335185ffb215662801wrowe
6c24fd6cfe148639988d5b335185ffb215662801wrowe New = apr_array_push(conf->allowed_connect_ports);
cadddb2c31d24d48f4017db4df0a29687432326cwrowe *New = atoi(arg);
117026201e6d8fe7d82416b8a7324830f5a87292wrowe return NULL;
e7505ba54ac56ae30e4e250f912f3dbaf92ca45fwrowe}
e7505ba54ac56ae30e4e250f912f3dbaf92ca45fwrowe
e7505ba54ac56ae30e4e250f912f3dbaf92ca45fwrowe/* Similar to set_proxy_exclude(), but defining directly connected hosts,
cadddb2c31d24d48f4017db4df0a29687432326cwrowe * which should never be accessed via the configured ProxyRemote servers
cadddb2c31d24d48f4017db4df0a29687432326cwrowe */
cadddb2c31d24d48f4017db4df0a29687432326cwrowestatic const char *
cadddb2c31d24d48f4017db4df0a29687432326cwrowe set_proxy_dirconn(cmd_parms *parms, void *dummy, const char *arg)
5b3abd2fecc712f08ad728114aa77137b9f67716wrowe{
85bb5b92490e4f095aae394118fc588a8f4c486fwrowe server_rec *s = parms->server;
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe proxy_server_conf *conf =
efa1a34b0a7785fc72863eff175b0cfc1ecb0e38wrowe ap_get_module_config(s->module_config, &proxy_module);
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe struct dirconn_entry *New;
beda1fb2f11c52ca4612460a5d5ba47398143efbwrowe struct dirconn_entry *list = (struct dirconn_entry *) conf->dirconn->elts;
beda1fb2f11c52ca4612460a5d5ba47398143efbwrowe int found = 0;
beda1fb2f11c52ca4612460a5d5ba47398143efbwrowe int i;
beda1fb2f11c52ca4612460a5d5ba47398143efbwrowe
beda1fb2f11c52ca4612460a5d5ba47398143efbwrowe /* Don't duplicate entries */
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe for (i = 0; i < conf->dirconn->nelts; i++) {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe if (strcasecmp(arg, list[i].name) == 0)
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe found = 1;
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe }
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe if (!found) {
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe New = apr_array_push(conf->dirconn);
117026201e6d8fe7d82416b8a7324830f5a87292wrowe New->name = apr_pstrdup(parms->pool, arg);
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe New->hostaddr = NULL;
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe if (ap_proxy_is_ipaddr(New, parms->pool)) {
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe#if DEBUGGING
290ecc1ddceca1ed49bc1a5338921264b5c3e07cwrowe ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
117026201e6d8fe7d82416b8a7324830f5a87292wrowe "Parsed addr %s", inet_ntoa(New->addr));
117026201e6d8fe7d82416b8a7324830f5a87292wrowe ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
efa1a34b0a7785fc72863eff175b0cfc1ecb0e38wrowe "Parsed mask %s", inet_ntoa(New->mask));
117026201e6d8fe7d82416b8a7324830f5a87292wrowe#endif
1067418d9ed9ed9daeb3ca4f74e72db810c49833wrowe }
cadddb2c31d24d48f4017db4df0a29687432326cwrowe else if (ap_proxy_is_domainname(New, parms->pool)) {
cadddb2c31d24d48f4017db4df0a29687432326cwrowe ap_str_tolower(New->name);
cadddb2c31d24d48f4017db4df0a29687432326cwrowe#if DEBUGGING
cadddb2c31d24d48f4017db4df0a29687432326cwrowe ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
85bb5b92490e4f095aae394118fc588a8f4c486fwrowe "Parsed domain %s", New->name);
85bb5b92490e4f095aae394118fc588a8f4c486fwrowe#endif
cadddb2c31d24d48f4017db4df0a29687432326cwrowe }
cadddb2c31d24d48f4017db4df0a29687432326cwrowe else if (ap_proxy_is_hostname(New, parms->pool)) {
cadddb2c31d24d48f4017db4df0a29687432326cwrowe ap_str_tolower(New->name);
cadddb2c31d24d48f4017db4df0a29687432326cwrowe#if DEBUGGING
cadddb2c31d24d48f4017db4df0a29687432326cwrowe ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
cadddb2c31d24d48f4017db4df0a29687432326cwrowe "Parsed host %s", New->name);
cadddb2c31d24d48f4017db4df0a29687432326cwrowe#endif
cadddb2c31d24d48f4017db4df0a29687432326cwrowe }
cadddb2c31d24d48f4017db4df0a29687432326cwrowe else {
cadddb2c31d24d48f4017db4df0a29687432326cwrowe ap_proxy_is_word(New, parms->pool);
85bb5b92490e4f095aae394118fc588a8f4c486fwrowe#if DEBUGGING
cadddb2c31d24d48f4017db4df0a29687432326cwrowe fprintf(stderr, "Parsed word %s\n", New->name);
85bb5b92490e4f095aae394118fc588a8f4c486fwrowe#endif
cadddb2c31d24d48f4017db4df0a29687432326cwrowe }
cadddb2c31d24d48f4017db4df0a29687432326cwrowe }
cadddb2c31d24d48f4017db4df0a29687432326cwrowe return NULL;
cadddb2c31d24d48f4017db4df0a29687432326cwrowe}
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe
1067418d9ed9ed9daeb3ca4f74e72db810c49833wrowestatic const char *
1067418d9ed9ed9daeb3ca4f74e72db810c49833wrowe set_proxy_domain(cmd_parms *parms, void *dummy, const char *arg)
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe{
1067418d9ed9ed9daeb3ca4f74e72db810c49833wrowe proxy_server_conf *psf =
117026201e6d8fe7d82416b8a7324830f5a87292wrowe ap_get_module_config(parms->server->module_config, &proxy_module);
117026201e6d8fe7d82416b8a7324830f5a87292wrowe
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe if (arg[0] != '.')
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe return "ProxyDomain: domain name must start with a dot.";
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb psf->domain = arg;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return NULL;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowestatic const char *
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb set_proxy_req(cmd_parms *parms, void *dummy, int flag)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
1b839c67d5c0e4b1f22b44a4217f9860b420d47cwrowe proxy_server_conf *psf =
b45c1c292ff1fa635004ae81fa691f8cb3cdda85rbb ap_get_module_config(parms->server->module_config, &proxy_module);
1ab995011876f631740d68d960a6d729ddff5bfawrowe
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe psf->req = flag;
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe psf->req_set = 1;
b67fb549910fa0faf4cdd8aeaf9aeab51d4b6a92wrowe
b45c1c292ff1fa635004ae81fa691f8cb3cdda85rbb if (flag && !psf->forward) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb psf->forward = ap_proxy_create_worker(parms->pool);
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe psf->forward->name = "proxy:forward";
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe psf->forward->hostname = "*";
ecc4a080f07af3fbc1b91bbd00997ec1d592c6f9wrowe psf->forward->scheme = "*";
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe }
2d2dadb81bf34e3bc9321eabcd971a738431b364wrowe return NULL;
2d2dadb81bf34e3bc9321eabcd971a738431b364wrowe}
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowestatic const char *
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe set_proxy_error_override(cmd_parms *parms, void *dummy, int flag)
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe{
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe proxy_server_conf *psf =
2d2dadb81bf34e3bc9321eabcd971a738431b364wrowe ap_get_module_config(parms->server->module_config, &proxy_module);
ecc4a080f07af3fbc1b91bbd00997ec1d592c6f9wrowe
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb psf->error_override = flag;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb psf->error_override_set = 1;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return NULL;
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe}
5b3abd2fecc712f08ad728114aa77137b9f67716wrowestatic const char *
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb set_preserve_host(cmd_parms *parms, void *dummy, int flag)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
af7e32b660b02a378e91d40987e59b28864db954jwoolley proxy_server_conf *psf =
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe ap_get_module_config(parms->server->module_config, &proxy_module);
0540a0b469147b52e858587270dba31c2aaa9e09wrowe
5bb29f57ae0184d2b3c1cdf35132f8ceb011f882wrowe psf->preserve_host = flag;
0540a0b469147b52e858587270dba31c2aaa9e09wrowe psf->preserve_host_set = 1;
0540a0b469147b52e858587270dba31c2aaa9e09wrowe return NULL;
0540a0b469147b52e858587270dba31c2aaa9e09wrowe}
0540a0b469147b52e858587270dba31c2aaa9e09wrowe
0540a0b469147b52e858587270dba31c2aaa9e09wrowestatic const char *
0540a0b469147b52e858587270dba31c2aaa9e09wrowe set_recv_buffer_size(cmd_parms *parms, void *dummy, const char *arg)
0540a0b469147b52e858587270dba31c2aaa9e09wrowe{
0540a0b469147b52e858587270dba31c2aaa9e09wrowe proxy_server_conf *psf =
0540a0b469147b52e858587270dba31c2aaa9e09wrowe ap_get_module_config(parms->server->module_config, &proxy_module);
0540a0b469147b52e858587270dba31c2aaa9e09wrowe int s = atoi(arg);
0540a0b469147b52e858587270dba31c2aaa9e09wrowe if (s < 512 && s != 0) {
0540a0b469147b52e858587270dba31c2aaa9e09wrowe return "ProxyReceiveBufferSize must be >= 512 bytes, or 0 for system default.";
0540a0b469147b52e858587270dba31c2aaa9e09wrowe }
7763a4beb8afca9c8f93db0cb6836124901af52awrowe
0540a0b469147b52e858587270dba31c2aaa9e09wrowe psf->recv_buffer_size = s;
0540a0b469147b52e858587270dba31c2aaa9e09wrowe psf->recv_buffer_size_set = 1;
0540a0b469147b52e858587270dba31c2aaa9e09wrowe return NULL;
0540a0b469147b52e858587270dba31c2aaa9e09wrowe}
0540a0b469147b52e858587270dba31c2aaa9e09wrowe
0540a0b469147b52e858587270dba31c2aaa9e09wrowestatic const char *
0540a0b469147b52e858587270dba31c2aaa9e09wrowe set_io_buffer_size(cmd_parms *parms, void *dummy, const char *arg)
0540a0b469147b52e858587270dba31c2aaa9e09wrowe{
0540a0b469147b52e858587270dba31c2aaa9e09wrowe proxy_server_conf *psf =
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_get_module_config(parms->server->module_config, &proxy_module);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb long s = atol(arg);
5b3abd2fecc712f08ad728114aa77137b9f67716wrowe
5b3abd2fecc712f08ad728114aa77137b9f67716wrowe psf->io_buffer_size = ((s > AP_IOBUFSIZE) ? s : AP_IOBUFSIZE);
5b3abd2fecc712f08ad728114aa77137b9f67716wrowe psf->io_buffer_size_set = 1;
5b3abd2fecc712f08ad728114aa77137b9f67716wrowe return NULL;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic const char *
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb set_max_forwards(cmd_parms *parms, void *dummy, const char *arg)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb proxy_server_conf *psf =
58097d7d8d1a394092374b9f6ddf76b7993724a4rbb ap_get_module_config(parms->server->module_config, &proxy_module);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb long s = atol(arg);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (s < 0) {
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe return "ProxyMaxForwards must be greater or equal to zero..";
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
83a8dc5a596a8a1b9d14f063268287d123b9ed7ewrowe psf->maxfwd = s;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb psf->maxfwd_set = 1;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return NULL;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic const char*
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb set_proxy_timeout(cmd_parms *parms, void *dummy, const char *arg)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb proxy_server_conf *psf =
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_get_module_config(parms->server->module_config, &proxy_module);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb int timeout;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb timeout=atoi(arg);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (timeout<1) {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return "Proxy Timeout must be at least 1 second.";
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb psf->timeout_set=1;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb psf->timeout=apr_time_from_sec(timeout);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return NULL;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb}
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbbstatic const char*
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb set_via_opt(cmd_parms *parms, void *dummy, const char *arg)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb{
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb proxy_server_conf *psf =
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb ap_get_module_config(parms->server->module_config, &proxy_module);
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb if (strcasecmp(arg, "Off") == 0)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb psf->viaopt = via_off;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else if (strcasecmp(arg, "On") == 0)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb psf->viaopt = via_on;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else if (strcasecmp(arg, "Block") == 0)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb psf->viaopt = via_block;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else if (strcasecmp(arg, "Full") == 0)
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb psf->viaopt = via_full;
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb else {
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb return "ProxyVia must be one of: "
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb "off | on | full | block";
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb }
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb
b38846b15c8891c6dec44dcc4f96ca40721bf663rbb 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 *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 i;
if (cmd->path)
path = apr_pstrdup(cmd->pool, cmd->path);
while (*arg) {
word = ap_getword_conf(cmd->pool, &arg);
if (!path)
path = word;
else if (!name)
name = word;
else {
char *val = strchr(word, '=');
if (!val)
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 existing worker */
worker = ap_proxy_get_worker(cmd->temp_pool, conf, name);
if (!worker) {
const char *err;
if ((err = ap_proxy_add_worker(&worker, cmd->pool, conf, name)) != NULL)
return apr_pstrcat(cmd->temp_pool, "BalancerMember ", err, NULL);
} else {
ap_log_error(APLOG_MARK, APLOG_WARNING, 0, cmd->server,
"worker %s already used by another worker", worker->name);
}
PROXY_COPY_CONF_PARAMS(worker, conf);
arr = apr_table_elts(params);
elts = (const apr_table_entry_t *)arr->elts;
for (i = 0; i < arr->nelts; i++) {
const char *err = set_worker_param(cmd->pool, worker, elts[i].key,
elts[i].val);
if (err)
return apr_pstrcat(cmd->temp_pool, "BalancerMember ", err, NULL);
}
/* Try to find the balancer */
balancer = ap_proxy_get_balancer(cmd->temp_pool, conf, path);
if (!balancer) {
const char *err = ap_proxy_add_balancer(&balancer,
cmd->pool,
conf, path);
if (err)
return apr_pstrcat(cmd->temp_pool, "BalancerMember ", err, NULL);
}
/* Add the worker to the load balancer */
ap_proxy_add_worker_to_balancer(cmd->pool, balancer, worker);
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;
const char *err;
int in_proxy_section = 0;
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 (strncasecmp(name, "balancer:", 9) == 0) {
balancer = ap_proxy_get_balancer(cmd->pool, conf, name);
if (!balancer) {
if (in_proxy_section) {
err = ap_proxy_add_balancer(&balancer,
cmd->pool,
conf, name);
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, conf, name);
if (!worker) {
if (in_proxy_section) {
err = ap_proxy_add_worker(&worker, cmd->pool,
conf, name);
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|NOT_IN_LIMIT);
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";
}
}
else if (!strcmp(cmd->path, "~")) {
cmd->path = ap_getword_conf(cmd->pool, &arg);
if (!cmd->path)
return "<Proxy ~ > block must specify a path";
if (strncasecmp(cmd->path, "proxy:", 6))
cmd->path += 6;
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);
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 (strncasecmp(conf->p, "balancer:", 9) == 0) {
balancer = ap_proxy_get_balancer(cmd->pool, sconf, conf->p);
if (!balancer) {
err = ap_proxy_add_balancer(&balancer,
cmd->pool,
sconf, conf->p);
if (err)
return apr_pstrcat(cmd->temp_pool, thiscmd->name,
" ", err, NULL);
}
}
else {
worker = ap_proxy_get_worker(cmd->temp_pool, sconf,
conf->p);
if (!worker) {
err = ap_proxy_add_worker(&worker, cmd->pool,
sconf, conf->p);
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,
(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_TAKE12("ProxyPassReverse", add_pass_reverse, NULL, RSRC_CONF|ACCESS_CONF,
"a virtual path and a URL for reverse proxy behaviour"),
AP_INIT_TAKE2("ProxyPassReverseCookiePath", cookie_path, NULL,
RSRC_CONF|ACCESS_CONF, "Path rewrite rule for proxying cookies"),
AP_INIT_TAKE2("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_ITERATE("AllowCONNECT", set_allowed_ports, NULL, RSRC_CONF,
"A list of ports which CONNECT may connect to"),
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,
"use our error handling pages instead of the servers' we are proxying"),
AP_INIT_FLAG("ProxyPreserveHost", set_preserve_host, NULL, RSRC_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("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"),
{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)
{
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);
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->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->sticky) {
if (strcmp(balancer->sticky, balancer->sticky_path)) {
ap_rvputs(r, "<td>", balancer->sticky, " | ",
balancer->sticky_path, NULL);
}
else {
ap_rvputs(r, "<td>", balancer->sticky, NULL);
}
}
else {
ap_rputs("<td> - ", r);
}
ap_rprintf(r, "</td><td>%" APR_TIME_T_FMT "</td>",
apr_time_sec(balancer->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->scheme, "</td>", NULL);
ap_rvputs(r, "<td>", worker->hostname, "</td><td>", NULL);
if (worker->s->status & PROXY_WORKER_DISABLED)
ap_rputs("Dis", r);
else if (worker->s->status & PROXY_WORKER_IN_ERROR)
ap_rputs("Err", r);
else if (worker->s->status & PROXY_WORKER_INITIALIZED)
ap_rputs("Ok", r);
else
ap_rputs("-", r);
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 in %</td></tr>\n"
"<tr><th>Acc</th><td>Number of requests</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;
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);
/* Initialize worker's shared scoreboard data */
worker = (proxy_worker *)conf->workers->elts;
for (i = 0; i < conf->workers->nelts; i++) {
ap_proxy_initialize_worker_share(conf, worker, s);
ap_proxy_initialize_worker(worker, s);
worker++;
}
/* Initialize forward worker if defined */
if (conf->forward) {
ap_proxy_initialize_worker_share(conf, conf->forward, s);
ap_proxy_initialize_worker(conf->forward, s);
/* Do not disable worker in case of errors */
conf->forward->s->status |= PROXY_WORKER_IGNORE_ERRORS;
/* Disable address cache for generic forward worker */
conf->forward->is_address_reusable = 0;
}
if (!reverse) {
reverse = ap_proxy_create_worker(p);
reverse->name = "proxy:reverse";
reverse->hostname = "*";
reverse->scheme = "*";
ap_proxy_initialize_worker_share(conf, reverse, s);
ap_proxy_initialize_worker(reverse, s);
/* Do not disable worker in case of errors */
reverse->s->status |= PROXY_WORKER_IGNORE_ERRORS;
/* Disable address cache for generic reverse worker */
reverse->is_address_reusable = 0;
}
conf->reverse = reverse;
s = s->next;
}
}
/*
* This routine is called before the server processes the configuration
* files. There is no return value.
*/
static int proxy_pre_config(apr_pool_t *pconf, apr_pool_t *plog,
apr_pool_t *ptemp)
{
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", NULL};
APR_REGISTER_OPTIONAL_FN(ap_proxy_lb_workers);
APR_REGISTER_OPTIONAL_FN(ap_proxy_lb_worker_size);
/* 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);
}
module AP_MODULE_DECLARE_DATA proxy_module =
{
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)