vhost.c revision 2d71630471d1c23f0137309e3c3957c633ecbfd6
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/* ====================================================================
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Copyright (c) 1995-1999 The Apache Group. All rights reserved.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Redistribution and use in source and binary forms, with or without
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * modification, are permitted provided that the following conditions
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * are met:
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * 1. Redistributions of source code must retain the above copyright
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * notice, this list of conditions and the following disclaimer.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * 2. Redistributions in binary form must reproduce the above copyright
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * notice, this list of conditions and the following disclaimer in
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * the documentation and/or other materials provided with the
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * distribution.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * 3. All advertising materials mentioning features or use of this
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * software must display the following acknowledgment:
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * "This product includes software developed by the Apache Group
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * for use in the Apache HTTP server project (http://www.apache.org/)."
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * 4. The names "Apache Server" and "Apache Group" must not be used to
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * endorse or promote products derived from this software without
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * prior written permission. For written permission, please contact
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * apache@apache.org.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * 5. Products derived from this software may not be called "Apache"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * nor may "Apache" appear in their names without prior written
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * permission of the Apache Group.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * 6. Redistributions of any form whatsoever must retain the following
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * acknowledgment:
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * "This product includes software developed by the Apache Group
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * for use in the Apache HTTP server project (http://www.apache.org/)."
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE GROUP OR
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * OF THE POSSIBILITY OF SUCH DAMAGE.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * ====================================================================
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * This software consists of voluntary contributions made by many
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * individuals on behalf of the Apache Group and was originally based
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * on public domain software written at the National Center for
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Supercomputing Applications, University of Illinois, Urbana-Champaign.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * For more information on the Apache Group and the Apache HTTP server
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * project, please see <http://www.apache.org/>.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/*
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * http_vhost.c: functions pertaining to virtual host addresses
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * (configuration and run-time)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define CORE_PRIVATE
2d71630471d1c23f0137309e3c3957c633ecbfd6rbb#include "ap_config.h"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#include "httpd.h"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#include "http_config.h"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#include "http_log.h"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#include "http_vhost.h"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#include "http_protocol.h"
51af95bb51b5084e883bad250b2afa2838e9ceebfielding#include "http_core.h"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/*
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * After all the definitions there's an explanation of how it's all put
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * together.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/* meta-list of name-vhosts. Each server_rec can be in possibly multiple
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * lists of name-vhosts.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingtypedef struct name_chain name_chain;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstruct name_chain {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding name_chain *next;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding server_addr_rec *sar; /* the record causing it to be in
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * this chain (needed for port comparisons) */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding server_rec *server; /* the server to use on a match */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding};
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/* meta-list of ip addresses. Each server_rec can be in possibly multiple
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * hash chains since it can have multiple ips.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingtypedef struct ipaddr_chain ipaddr_chain;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstruct ipaddr_chain {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ipaddr_chain *next;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding server_addr_rec *sar; /* the record causing it to be in
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * this chain (need for both ip addr and port
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * comparisons) */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding server_rec *server; /* the server to use if this matches */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding name_chain *names; /* if non-NULL then a list of name-vhosts
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * sharing this address */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding};
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
b4c8a80f7dbfc9b56dbe03bdc28f0b5eb5f23697rbb/* This defines the size of the hash ap_table_t used for hashing ip addresses
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * of virtual hosts. It must be a power of two.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#ifndef IPHASH_TABLE_SIZE
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define IPHASH_TABLE_SIZE 256
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/* A (n) bucket hash table, each entry has a pointer to a server rec and
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * a pointer to the other entries in that bucket. Each individual address,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * even for virtualhosts with multiple addresses, has an entry in this hash
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * table. There are extra buckets for _default_, and name-vhost entries.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Note that after config time this is constant, so it is thread-safe.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic ipaddr_chain *iphash_table[IPHASH_TABLE_SIZE];
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/* dump out statistics about the hash function */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/* #define IPHASH_STATISTICS */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/* list of the _default_ servers */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic ipaddr_chain *default_list;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/* list of the NameVirtualHost addresses */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic server_addr_rec *name_vhost_list;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic server_addr_rec **name_vhost_list_tail;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/*
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * How it's used:
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * The ip address determines which chain in iphash_table is interesting, then
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * a comparison is done down that chain to find the first ipaddr_chain whose
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * sar matches the address:port pair.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * If that ipaddr_chain has names == NULL then you're done, it's an ip-vhost.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Otherwise it's a name-vhost list, and the default is the server in the
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * ipaddr_chain record. We tuck away the ipaddr_chain record in the
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * conn_rec field vhost_lookup_data. Later on after the headers we get a
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * second chance, and we use the name_chain to figure out what name-vhost
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * matches the headers.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * If there was no ip address match in the iphash_table then do a lookup
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * in the default_list.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * How it's put together ... well you should be able to figure that out
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * from how it's used. Or something like that.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/* called at the beginning of the config */
b4c8a80f7dbfc9b56dbe03bdc28f0b5eb5f23697rbbvoid ap_init_vhost_config(ap_context_t *p)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding memset(iphash_table, 0, sizeof(iphash_table));
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding default_list = NULL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding name_vhost_list = NULL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding name_vhost_list_tail = &name_vhost_list;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/*
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Parses a host of the form <address>[:port]
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * paddr is used to create a list in the order of input
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * **paddr is the ->next pointer of the last entry (or s->addrs)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * *paddr is the variable used to keep track of **paddr between calls
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * port is the default port to assume
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
b4c8a80f7dbfc9b56dbe03bdc28f0b5eb5f23697rbbstatic const char *get_addresses(ap_context_t *p, char *w, server_addr_rec ***paddr,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding unsigned port)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding struct hostent *hep;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding unsigned long my_addr;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding server_addr_rec *sar;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding char *t;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding int i, is_an_ip_addr;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (*w == 0)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return NULL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding t = strchr(w, ':');
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (t) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (strcmp(t + 1, "*") == 0) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding port = 0;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if ((i = atoi(t + 1))) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding port = i;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return ":port must be numeric";
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *t = 0;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding is_an_ip_addr = 0;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (strcmp(w, "*") == 0) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding my_addr = htonl(INADDR_ANY);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding is_an_ip_addr = 1;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (strcasecmp(w, "_default_") == 0
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding || strcmp(w, "255.255.255.255") == 0) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding my_addr = DEFAULT_VHOST_ADDR;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding is_an_ip_addr = 1;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if ((my_addr = ap_inet_addr(w)) != INADDR_NONE) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding is_an_ip_addr = 1;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (is_an_ip_addr) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding sar = ap_pcalloc(p, sizeof(server_addr_rec));
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding **paddr = sar;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *paddr = &sar->next;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding sar->host_addr.s_addr = my_addr;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding sar->host_port = port;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding sar->virthost = ap_pstrdup(p, w);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (t != NULL)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *t = ':';
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return NULL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding hep = gethostbyname(w);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if ((!hep) || (hep->h_addrtype != AF_INET || !hep->h_addr_list[0])) {
0942697a9b5de44865676345a3828741c827efe6rbb ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, NULL,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "Cannot resolve host name %s --- ignoring!", w);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (t != NULL)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *t = ':';
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return NULL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding for (i = 0; hep->h_addr_list[i]; ++i) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding sar = ap_pcalloc(p, sizeof(server_addr_rec));
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding **paddr = sar;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *paddr = &sar->next;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding sar->host_addr = *(struct in_addr *) hep->h_addr_list[i];
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding sar->host_port = port;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding sar->virthost = ap_pstrdup(p, w);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (t != NULL)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *t = ':';
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return NULL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/* parse the <VirtualHost> addresses */
b4c8a80f7dbfc9b56dbe03bdc28f0b5eb5f23697rbbconst char *ap_parse_vhost_addrs(ap_context_t *p, const char *hostname, server_rec *s)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding server_addr_rec **addrs;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding const char *err;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* start the list of addreses */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding addrs = &s->addrs;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding while (hostname[0]) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding err = get_addresses(p, ap_getword_conf(p, &hostname), &addrs, s->port);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (err) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *addrs = NULL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return err;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* terminate the list */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *addrs = NULL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (s->addrs) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (s->addrs->host_port) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* override the default port which is inherited from main_server */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding s->port = s->addrs->host_port;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return NULL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingconst char *ap_set_name_virtual_host (cmd_parms *cmd, void *dummy, char *arg)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* use whatever port the main server has at this point */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return get_addresses(cmd->pool, arg, &name_vhost_list_tail,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding cmd->server->port);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
b4c8a80f7dbfc9b56dbe03bdc28f0b5eb5f23697rbb/* hash ap_table_t statistics, keep this in here for the beta period so
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * we can find out if the hash function is ok
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#ifdef IPHASH_STATISTICS
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic int iphash_compare(const void *a, const void *b)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return (*(const int *) b - *(const int *) a);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic void dump_iphash_statistics(server_rec *main_s)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding unsigned count[IPHASH_TABLE_SIZE];
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding int i;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ipaddr_chain *src;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding unsigned total;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding char buf[HUGE_STRING_LEN];
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding char *p;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding total = 0;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding for (i = 0; i < IPHASH_TABLE_SIZE; ++i) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding count[i] = 0;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding for (src = iphash_table[i]; src; src = src->next) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ++count[i];
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (i < IPHASH_TABLE_SIZE) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* don't count the slop buckets in the total */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ++total;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding qsort(count, IPHASH_TABLE_SIZE, sizeof(count[0]), iphash_compare);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding p = buf + ap_snprintf(buf, sizeof(buf),
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "iphash: total hashed = %u, avg chain = %u, "
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "chain lengths (count x len):",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding total, total / IPHASH_TABLE_SIZE);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding total = 1;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding for (i = 1; i < IPHASH_TABLE_SIZE; ++i) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (count[i - 1] != count[i]) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding p += ap_snprintf(p, sizeof(buf) - (p - buf), " %ux%u",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding total, count[i - 1]);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding total = 1;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ++total;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding p += ap_snprintf(p, sizeof(buf) - (p - buf), " %ux%u",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding total, count[IPHASH_TABLE_SIZE - 1]);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_DEBUG, main_s, buf);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/* This hashing function is designed to get good distribution in the cases
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * where the server is handling entire "networks" of servers. i.e. a
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * whack of /24s. This is probably the most common configuration for
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * ISPs with large virtual servers.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * NOTE: This function is symmetric (i.e. collapses all 4 octets
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * into one), so machine byte order (big/little endianness) does not matter.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Hash function provided by David Hankins.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic ap_inline unsigned hash_inaddr(unsigned key)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding key ^= (key >> 16);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return ((key >> 8) ^ key) % IPHASH_TABLE_SIZE;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
b4c8a80f7dbfc9b56dbe03bdc28f0b5eb5f23697rbbstatic ipaddr_chain *new_ipaddr_chain(ap_context_t *p,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding server_rec *s, server_addr_rec *sar)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ipaddr_chain *new;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new = ap_palloc(p, sizeof(*new));
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new->names = NULL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new->server = s;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new->sar = sar;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new->next = NULL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return new;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
b4c8a80f7dbfc9b56dbe03bdc28f0b5eb5f23697rbbstatic name_chain *new_name_chain(ap_context_t *p, server_rec *s, server_addr_rec *sar)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding name_chain *new;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new = ap_palloc(p, sizeof(*new));
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new->server = s;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new->sar = sar;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding new->next = NULL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return new;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic ap_inline ipaddr_chain *find_ipaddr(struct in_addr *server_ip,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding unsigned port)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding unsigned bucket;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ipaddr_chain *trav;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding unsigned addr;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
b4c8a80f7dbfc9b56dbe03bdc28f0b5eb5f23697rbb /* scan the hash ap_table_t for an exact match first */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding addr = server_ip->s_addr;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding bucket = hash_inaddr(addr);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding for (trav = iphash_table[bucket]; trav; trav = trav->next) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding server_addr_rec *sar = trav->sar;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if ((sar->host_addr.s_addr == addr)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding && (sar->host_port == 0 || sar->host_port == port
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding || port == 0)) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return trav;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return NULL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic ipaddr_chain *find_default_server(unsigned port)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding server_addr_rec *sar;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ipaddr_chain *trav;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding for (trav = default_list; trav; trav = trav->next) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding sar = trav->sar;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (sar->host_port == 0 || sar->host_port == port) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* match! */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return trav;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return NULL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
93b653492fb3b4b65006e95a435629d806a9e589rbbstatic void dump_vhost_config(ap_file_t *f)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding int i;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ipaddr_chain *ic;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding name_chain *nc;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding char buf[MAX_STRING_LEN];
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
93b653492fb3b4b65006e95a435629d806a9e589rbb ap_fprintf(f, "VirtualHost configuration:\n");
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding for (i = 0; i < IPHASH_TABLE_SIZE; ++i) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding for (ic = iphash_table[i]; ic; ic = ic->next) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (ic->sar->host_port == 0) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_snprintf(buf, sizeof(buf), "%pA:*", &ic->sar->host_addr);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_snprintf(buf, sizeof(buf), "%pA:%u", &ic->sar->host_addr,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ic->sar->host_port);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (ic->names == NULL) {
93b653492fb3b4b65006e95a435629d806a9e589rbb ap_fprintf(f, "%-22s %s (%s:%u)\n", buf,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ic->server->server_hostname, ic->server->defn_name,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ic->server->defn_line_number);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding continue;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
93b653492fb3b4b65006e95a435629d806a9e589rbb ap_fprintf(f, "%-22s is a NameVirtualHost\n"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "%22s default server %s (%s:%u)\n",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding buf, "", ic->server->server_hostname,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ic->server->defn_name, ic->server->defn_line_number);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding for (nc = ic->names; nc; nc = nc->next) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (nc->sar->host_port) {
93b653492fb3b4b65006e95a435629d806a9e589rbb ap_fprintf(f, "%22s port %u ", "", nc->sar->host_port);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else {
93b653492fb3b4b65006e95a435629d806a9e589rbb ap_fprintf(f, "%22s port * ", "");
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
93b653492fb3b4b65006e95a435629d806a9e589rbb ap_fprintf(f, "namevhost %s (%s:%u)\n",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding nc->server->server_hostname,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding nc->server->defn_name,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding nc->server->defn_line_number);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (default_list) {
93b653492fb3b4b65006e95a435629d806a9e589rbb ap_fprintf(f, "_default_ servers:\n");
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding for (ic = default_list; ic; ic = ic->next) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (ic->sar->host_port == 0) {
93b653492fb3b4b65006e95a435629d806a9e589rbb ap_fprintf(f, "port * ");
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else {
93b653492fb3b4b65006e95a435629d806a9e589rbb ap_fprintf(f, "port %u ", ic->sar->host_port);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
93b653492fb3b4b65006e95a435629d806a9e589rbb ap_fprintf(f, "server %s (%s:%u)\n",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ic->server->server_hostname, ic->server->defn_name,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ic->server->defn_line_number);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/* compile the tables and such we need to do the run-time vhost lookups */
b4c8a80f7dbfc9b56dbe03bdc28f0b5eb5f23697rbbvoid ap_fini_vhost_config(ap_context_t *p, server_rec *main_s)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding server_addr_rec *sar;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding int has_default_vhost_addr;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding server_rec *s;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding int i;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ipaddr_chain **iphash_table_tail[IPHASH_TABLE_SIZE];
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* terminate the name_vhost list */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *name_vhost_list_tail = NULL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* Main host first */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding s = main_s;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (!s->server_hostname) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding s->server_hostname = ap_get_local_host(p);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* initialize the tails */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding for (i = 0; i < IPHASH_TABLE_SIZE; ++i) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding iphash_table_tail[i] = &iphash_table[i];
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
b4c8a80f7dbfc9b56dbe03bdc28f0b5eb5f23697rbb /* The first things to go into the hash ap_table_t are the NameVirtualHosts
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Since name_vhost_list is in the same order that the directives
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * occured in the config file, we'll copy it in that order.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding for (sar = name_vhost_list; sar; sar = sar->next) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding unsigned bucket = hash_inaddr(sar->host_addr.s_addr);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ipaddr_chain *new = new_ipaddr_chain(p, NULL, sar);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *iphash_table_tail[bucket] = new;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding iphash_table_tail[bucket] = &new->next;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* Notice that what we've done is insert an ipaddr_chain with
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * both server and names NULL. Remember that.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
b4c8a80f7dbfc9b56dbe03bdc28f0b5eb5f23697rbb /* The next things to go into the hash ap_table_t are the virtual hosts
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * themselves. They're listed off of main_s->next in the reverse
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * order they occured in the config file, so we insert them at
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * the iphash_table_tail but don't advance the tail.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding for (s = main_s->next; s; s = s->next) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding has_default_vhost_addr = 0;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding for (sar = s->addrs; sar; sar = sar->next) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ipaddr_chain *ic;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (sar->host_addr.s_addr == DEFAULT_VHOST_ADDR
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding || sar->host_addr.s_addr == INADDR_ANY) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* add it to default bucket for each appropriate sar
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * since we need to do a port test
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ipaddr_chain *other;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding other = find_default_server(sar->host_port);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (other && other->sar->host_port != 0) {
0942697a9b5de44865676345a3828741c827efe6rbb ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING, 0, main_s,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "_default_ VirtualHost overlap on port %u,"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding " the first has precedence", sar->host_port);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding has_default_vhost_addr = 1;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ic = new_ipaddr_chain(p, s, sar);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ic->next = default_list;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding default_list = ic;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* see if it matches something we've already got */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ic = find_ipaddr(&sar->host_addr, sar->host_port);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* the first time we encounter a NameVirtualHost address
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * ic->server will be NULL, on subsequent encounters
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * ic->names will be non-NULL.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (ic && (ic->names || ic->server == NULL)) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding name_chain *nc = new_name_chain(p, s, sar);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding nc->next = ic->names;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ic->names = nc;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ic->server = s;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (sar->host_port != ic->sar->host_port) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* one of the two is a * port, the other isn't */
0942697a9b5de44865676345a3828741c827efe6rbb ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, main_s,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "VirtualHost %s:%u -- mixing * "
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "ports and non-* ports with "
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "a NameVirtualHost address is not supported,"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding " proceeding with undefined results",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding sar->virthost, sar->host_port);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (ic) {
0942697a9b5de44865676345a3828741c827efe6rbb ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING, 0, main_s,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "VirtualHost %s:%u overlaps with "
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "VirtualHost %s:%u, the first has precedence, "
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "perhaps you need a NameVirtualHost directive",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding sar->virthost, sar->host_port,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ic->sar->virthost, ic->sar->host_port);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ic->sar = sar;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ic->server = s;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding unsigned bucket = hash_inaddr(sar->host_addr.s_addr);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ic = new_ipaddr_chain(p, s, sar);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ic->next = *iphash_table_tail[bucket];
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *iphash_table_tail[bucket] = ic;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* Ok now we want to set up a server_hostname if the user was
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * silly enough to forget one.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * XXX: This is silly we should just crash and burn.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (!s->server_hostname) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (has_default_vhost_addr) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding s->server_hostname = main_s->server_hostname;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (!s->addrs) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* what else can we do? at this point this vhost has
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding no configured name, probably because they used
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding DNS in the VirtualHost statement. It's disabled
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding anyhow by the host matching code. -djg */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding s->server_hostname =
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_pstrdup(p, "bogus_host_without_forward_dns");
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding struct hostent *h;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if ((h = gethostbyaddr((char *) &(s->addrs->host_addr),
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding sizeof(struct in_addr), AF_INET))) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding s->server_hostname = ap_pstrdup(p, (char *) h->h_name);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* again, what can we do? They didn't specify a
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ServerName, and their DNS isn't working. -djg */
0942697a9b5de44865676345a3828741c827efe6rbb ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, main_s,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "Failed to resolve server name "
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "for %s (check DNS) -- or specify an explicit "
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "ServerName",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding inet_ntoa(s->addrs->host_addr));
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding s->server_hostname =
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_pstrdup(p, "bogus_host_without_reverse_dns");
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* now go through and delete any NameVirtualHosts that didn't have any
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * hosts associated with them. Lamers.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding for (i = 0; i < IPHASH_TABLE_SIZE; ++i) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ipaddr_chain **pic = &iphash_table[i];
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding while (*pic) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ipaddr_chain *ic = *pic;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (ic->server == NULL) {
0942697a9b5de44865676345a3828741c827efe6rbb ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING, 0, main_s,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "NameVirtualHost %s:%u has no VirtualHosts",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ic->sar->virthost, ic->sar->host_port);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *pic = ic->next;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (ic->names == NULL) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* if server != NULL and names == NULL then we're done
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * looking at NameVirtualHosts
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding break;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding pic = &ic->next;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#ifdef IPHASH_STATISTICS
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding dump_iphash_statistics(main_s);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif
51af95bb51b5084e883bad250b2afa2838e9ceebfielding if (getenv("DUMP_VHOSTS")) {
93b653492fb3b4b65006e95a435629d806a9e589rbb ap_file_t *thefile = NULL;
1be548ab863a87b6d82638bf41f8d323f3aa2c3arbb ap_open_stderr(&thefile, p);
93b653492fb3b4b65006e95a435629d806a9e589rbb dump_vhost_config(thefile);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/*****************************************************************************
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * run-time vhost matching functions
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
3926b3b7716683a1241c1ff6f8dd2f9c5073665afanf/* Lowercase and remove any trailing dot and/or :port from the hostname,
3926b3b7716683a1241c1ff6f8dd2f9c5073665afanf * and check that it is sane.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic void fix_hostname(request_rec *r)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
3926b3b7716683a1241c1ff6f8dd2f9c5073665afanf char *host = ap_palloc(r->pool, strlen(r->hostname) + 1);
3926b3b7716683a1241c1ff6f8dd2f9c5073665afanf const char *src;
3926b3b7716683a1241c1ff6f8dd2f9c5073665afanf char *dst;
3926b3b7716683a1241c1ff6f8dd2f9c5073665afanf
3926b3b7716683a1241c1ff6f8dd2f9c5073665afanf /* check and copy the host part */
3926b3b7716683a1241c1ff6f8dd2f9c5073665afanf src = r->hostname;
3926b3b7716683a1241c1ff6f8dd2f9c5073665afanf dst = host;
3926b3b7716683a1241c1ff6f8dd2f9c5073665afanf while (*src) {
6afe4c4dc334ef3e5001a1739e2336962f8d07febjh if (!ap_isalnum(*src) && *src != '.' && *src != '-') {
3926b3b7716683a1241c1ff6f8dd2f9c5073665afanf if (*src == ':')
3926b3b7716683a1241c1ff6f8dd2f9c5073665afanf break;
3926b3b7716683a1241c1ff6f8dd2f9c5073665afanf else
3926b3b7716683a1241c1ff6f8dd2f9c5073665afanf goto bad;
3926b3b7716683a1241c1ff6f8dd2f9c5073665afanf } else {
3926b3b7716683a1241c1ff6f8dd2f9c5073665afanf *dst++ = *src++;
3926b3b7716683a1241c1ff6f8dd2f9c5073665afanf }
3926b3b7716683a1241c1ff6f8dd2f9c5073665afanf }
3926b3b7716683a1241c1ff6f8dd2f9c5073665afanf /* check the port part */
3926b3b7716683a1241c1ff6f8dd2f9c5073665afanf if (*src++ == ':') {
3926b3b7716683a1241c1ff6f8dd2f9c5073665afanf while (*src) {
6afe4c4dc334ef3e5001a1739e2336962f8d07febjh if (!ap_isdigit(*src++)) {
3926b3b7716683a1241c1ff6f8dd2f9c5073665afanf goto bad;
3926b3b7716683a1241c1ff6f8dd2f9c5073665afanf }
3926b3b7716683a1241c1ff6f8dd2f9c5073665afanf }
3926b3b7716683a1241c1ff6f8dd2f9c5073665afanf }
3926b3b7716683a1241c1ff6f8dd2f9c5073665afanf /* strip trailing gubbins */
3926b3b7716683a1241c1ff6f8dd2f9c5073665afanf if (dst > host && dst[-1] == '.') {
3926b3b7716683a1241c1ff6f8dd2f9c5073665afanf dst[-1] = '\0';
3926b3b7716683a1241c1ff6f8dd2f9c5073665afanf } else {
3926b3b7716683a1241c1ff6f8dd2f9c5073665afanf dst[0] = '\0';
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding r->hostname = host;
3926b3b7716683a1241c1ff6f8dd2f9c5073665afanf return;
3926b3b7716683a1241c1ff6f8dd2f9c5073665afanf
3926b3b7716683a1241c1ff6f8dd2f9c5073665afanfbad:
3926b3b7716683a1241c1ff6f8dd2f9c5073665afanf r->status = HTTP_BAD_REQUEST;
5e4791fd54c10fdd77ca81bee8ac8398f16d6d6astoddard ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
3926b3b7716683a1241c1ff6f8dd2f9c5073665afanf "Client sent malformed Host header");
3926b3b7716683a1241c1ff6f8dd2f9c5073665afanf return;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/* return 1 if host matches ServerName or ServerAliases */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic int matches_aliases(server_rec *s, const char *host)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding int i;
b4c8a80f7dbfc9b56dbe03bdc28f0b5eb5f23697rbb ap_array_header_t *names;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* match ServerName */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (!strcasecmp(host, s->server_hostname)) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return 1;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* search all the aliases from ServerAlias directive */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding names = s->names;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (names) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding char **name = (char **) names->elts;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding for (i = 0; i < names->nelts; ++i) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if(!name[i]) continue;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (!strcasecmp(host, name[i]))
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return 1;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding names = s->wild_names;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (names) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding char **name = (char **) names->elts;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding for (i = 0; i < names->nelts; ++i) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if(!name[i]) continue;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (!ap_strcasecmp_match(host, name[i]))
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return 1;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return 0;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/* Suppose a request came in on the same socket as this r, and included
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * a header "Host: host:port", would it map to r->server? It's more
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * than just that though. When we do the normal matches for each request
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * we don't even bother considering Host: etc on non-namevirtualhosts,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * we just call it a match. But here we require the host:port to match
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * the ServerName and/or ServerAliases.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingAPI_EXPORT(int) ap_matches_request_vhost(request_rec *r, const char *host,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding unsigned port)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding server_rec *s;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding server_addr_rec *sar;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding s = r->server;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* search all the <VirtualHost> values */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* XXX: If this is a NameVirtualHost then we may not be doing the Right Thing
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * consider:
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * NameVirtualHost 10.1.1.1
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * <VirtualHost 10.1.1.1>
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * ServerName v1
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * </VirtualHost>
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * <VirtualHost 10.1.1.1>
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * ServerName v2
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * </VirtualHost>
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Suppose r->server is v2, and we're asked to match "10.1.1.1". We'll say
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * "yup it's v2", when really it isn't... if a request came in for 10.1.1.1
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * it would really go to v1.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding for (sar = s->addrs; sar; sar = sar->next) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if ((sar->host_port == 0 || port == sar->host_port)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding && !strcasecmp(host, sar->virthost)) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return 1;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* the Port has to match now, because the rest don't have ports associated
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * with them. */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (port != s->port) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return 0;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return matches_aliases(s, host);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic void check_hostalias(request_rec *r)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /*
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Even if the request has a Host: header containing a port we ignore
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * that port. We always use the physical port of the socket. There
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * are a few reasons for this:
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * - the default of 80 or 443 for SSL is easier to handle this way
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * - there is less of a possibility of a security problem
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * - it simplifies the data structure
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * - the client may have no idea that a proxy somewhere along the way
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * translated the request to another ip:port
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * - except for the addresses from the VirtualHost line, none of the other
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * names we'll match have ports associated with them
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding const char *host = r->hostname;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding unsigned port = ntohs(r->connection->local_addr.sin_port);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding server_rec *s;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding server_rec *last_s;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding name_chain *src;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding last_s = NULL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* Recall that the name_chain is a list of server_addr_recs, some of
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * whose ports may not match. Also each server may appear more than
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * once in the chain -- specifically, it will appear once for each
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * address from its VirtualHost line which matched. We only want to
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * do the full ServerName/ServerAlias comparisons once for each
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * server, fortunately we know that all the VirtualHost addresses for
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * a single server are adjacent to each other.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding for (src = r->connection->vhost_lookup_data; src; src = src->next) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding server_addr_rec *sar;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* We only consider addresses on the name_chain which have a matching
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * port
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding sar = src->sar;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (sar->host_port != 0 && port != sar->host_port) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding continue;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding s = src->server;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* does it match the virthost from the sar? */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (!strcasecmp(host, sar->virthost)) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding goto found;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (s == last_s) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* we've already done ServerName and ServerAlias checks for this
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * vhost
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding continue;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding last_s = s;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (matches_aliases(s, host)) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding goto found;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingfound:
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* s is the first matching server, we're done */
51af95bb51b5084e883bad250b2afa2838e9ceebfielding r->server = s;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic void check_serverpath(request_rec *r)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding server_rec *s;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding server_rec *last_s;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding name_chain *src;
061c3874622b67beff724876b9bd1b1f291f2eaafielding /* use AP func here. */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding unsigned port = ntohs(r->connection->local_addr.sin_port);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /*
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * This is in conjunction with the ServerPath code in http_core, so we
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * get the right host attached to a non- Host-sending request.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * See the comment in check_hostalias about how each vhost can be
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * listed multiple times.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding last_s = NULL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding for (src = r->connection->vhost_lookup_data; src; src = src->next) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* We only consider addresses on the name_chain which have a matching
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * port
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (src->sar->host_port != 0 && port != src->sar->host_port) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding continue;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding s = src->server;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (s == last_s) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding continue;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding last_s = s;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (s->path && !strncmp(r->uri, s->path, s->pathlen) &&
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding (s->path[s->pathlen - 1] == '/' ||
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding r->uri[s->pathlen] == '/' ||
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding r->uri[s->pathlen] == '\0')) {
51af95bb51b5084e883bad250b2afa2838e9ceebfielding r->server = s;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingvoid ap_update_vhost_from_headers(request_rec *r)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* must set this for HTTP/1.1 support */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (r->hostname || (r->hostname = ap_table_get(r->headers_in, "Host"))) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding fix_hostname(r);
3926b3b7716683a1241c1ff6f8dd2f9c5073665afanf if (r->status != HTTP_OK)
3926b3b7716683a1241c1ff6f8dd2f9c5073665afanf return;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* check if we tucked away a name_chain */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (r->connection->vhost_lookup_data) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (r->hostname)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding check_hostalias(r);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding check_serverpath(r);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/* Called for a new connection which has a known local_addr. Note that the
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * new connection is assumed to have conn->server == main server.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingvoid ap_update_vhost_given_ip(conn_rec *conn)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ipaddr_chain *trav;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding unsigned port = ntohs(conn->local_addr.sin_port);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
b4c8a80f7dbfc9b56dbe03bdc28f0b5eb5f23697rbb /* scan the hash ap_table_t for an exact match first */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding trav = find_ipaddr(&conn->local_addr.sin_addr, port);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (trav) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* save the name_chain for later in case this is a name-vhost */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding conn->vhost_lookup_data = trav->names;
51af95bb51b5084e883bad250b2afa2838e9ceebfielding conn->base_server = trav->server;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* There's certainly no name-vhosts with this address, they would have
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * been matched above.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding conn->vhost_lookup_data = NULL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* maybe there's a default server matching this port */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding trav = find_default_server(port);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (trav) {
51af95bb51b5084e883bad250b2afa2838e9ceebfielding conn->base_server = trav->server;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* otherwise we're stuck with just the main server */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}