mod_setenvif.c revision ba6c07204bd224fa5d4cd0e6b8bf256d6daffb74
b66914021bd429f41311d2909a7e9289866da7fdnd/* ====================================================================
b51bf223f42d43ca6b1b33c95124edcfa5a871a4nd * The Apache Software License, Version 1.1
b66914021bd429f41311d2909a7e9289866da7fdnd * Copyright (c) 2000-2003 The Apache Software Foundation. All rights
b66914021bd429f41311d2909a7e9289866da7fdnd * reserved.
08cb74ca432a8c24e39f17dedce527e6a47b8001jerenkrantz * Redistribution and use in source and binary forms, with or without
b66914021bd429f41311d2909a7e9289866da7fdnd * modification, are permitted provided that the following conditions
b66914021bd429f41311d2909a7e9289866da7fdnd * are met:
b66914021bd429f41311d2909a7e9289866da7fdnd * 1. Redistributions of source code must retain the above copyright
b66914021bd429f41311d2909a7e9289866da7fdnd * notice, this list of conditions and the following disclaimer.
b66914021bd429f41311d2909a7e9289866da7fdnd * 2. Redistributions in binary form must reproduce the above copyright
b66914021bd429f41311d2909a7e9289866da7fdnd * notice, this list of conditions and the following disclaimer in
b66914021bd429f41311d2909a7e9289866da7fdnd * the documentation and/or other materials provided with the
b66914021bd429f41311d2909a7e9289866da7fdnd * distribution.
b66914021bd429f41311d2909a7e9289866da7fdnd * 3. The end-user documentation included with the redistribution,
b66914021bd429f41311d2909a7e9289866da7fdnd * if any, must include the following acknowledgment:
b66914021bd429f41311d2909a7e9289866da7fdnd * "This product includes software developed by the
eed2a23d9b5986937f1e2b1c120be97744508a72nd * Apache Software Foundation (http://www.apache.org/)."
eed2a23d9b5986937f1e2b1c120be97744508a72nd * Alternately, this acknowledgment may appear in the software itself,
eed2a23d9b5986937f1e2b1c120be97744508a72nd * if and wherever such third-party acknowledgments normally appear.
eed2a23d9b5986937f1e2b1c120be97744508a72nd * 4. The names "Apache" and "Apache Software Foundation" must
eed2a23d9b5986937f1e2b1c120be97744508a72nd * not be used to endorse or promote products derived from this
eed2a23d9b5986937f1e2b1c120be97744508a72nd * software without prior written permission. For written
eed2a23d9b5986937f1e2b1c120be97744508a72nd * permission, please contact apache@apache.org.
eed2a23d9b5986937f1e2b1c120be97744508a72nd * 5. Products derived from this software may not be called "Apache",
eed2a23d9b5986937f1e2b1c120be97744508a72nd * nor may "Apache" appear in their name, without prior written
eed2a23d9b5986937f1e2b1c120be97744508a72nd * permission of the Apache Software Foundation.
eed2a23d9b5986937f1e2b1c120be97744508a72nd * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
eed2a23d9b5986937f1e2b1c120be97744508a72nd * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
eed2a23d9b5986937f1e2b1c120be97744508a72nd * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
eed2a23d9b5986937f1e2b1c120be97744508a72nd * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
eed2a23d9b5986937f1e2b1c120be97744508a72nd * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
eed2a23d9b5986937f1e2b1c120be97744508a72nd * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
eed2a23d9b5986937f1e2b1c120be97744508a72nd * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
eed2a23d9b5986937f1e2b1c120be97744508a72nd * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
eed2a23d9b5986937f1e2b1c120be97744508a72nd * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
eed2a23d9b5986937f1e2b1c120be97744508a72nd * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
eed2a23d9b5986937f1e2b1c120be97744508a72nd * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
eed2a23d9b5986937f1e2b1c120be97744508a72nd * SUCH DAMAGE.
eed2a23d9b5986937f1e2b1c120be97744508a72nd * ====================================================================
eed2a23d9b5986937f1e2b1c120be97744508a72nd * This software consists of voluntary contributions made by many
eed2a23d9b5986937f1e2b1c120be97744508a72nd * individuals on behalf of the Apache Software Foundation. For more
eed2a23d9b5986937f1e2b1c120be97744508a72nd * information on the Apache Software Foundation, please see
eed2a23d9b5986937f1e2b1c120be97744508a72nd * Portions of this software are based upon public domain software
eed2a23d9b5986937f1e2b1c120be97744508a72nd * originally written at the National Center for Supercomputing Applications,
eed2a23d9b5986937f1e2b1c120be97744508a72nd * University of Illinois, Urbana-Champaign.
eed2a23d9b5986937f1e2b1c120be97744508a72nd * Set environment variables based on matching request headers or
eed2a23d9b5986937f1e2b1c120be97744508a72nd * attributes against regex strings
eed2a23d9b5986937f1e2b1c120be97744508a72nd * Paul Sutton <paul@ukweb.com> 27 Oct 1996
eed2a23d9b5986937f1e2b1c120be97744508a72nd * Based on mod_browser by Alexei Kosut <akosut@organic.com>
eed2a23d9b5986937f1e2b1c120be97744508a72nd * Used to set environment variables based on the incoming request headers,
eed2a23d9b5986937f1e2b1c120be97744508a72nd * or some selected other attributes of the request (e.g., the remote host
eed2a23d9b5986937f1e2b1c120be97744508a72nd * SetEnvIf name regex var ...
eed2a23d9b5986937f1e2b1c120be97744508a72nd * where name is either a HTTP request header name, or one of the
eed2a23d9b5986937f1e2b1c120be97744508a72nd * special values (see below). 'name' may be a regex when it is used
eed2a23d9b5986937f1e2b1c120be97744508a72nd * to specify an HTTP request header name. The 'value' of the header
eed2a23d9b5986937f1e2b1c120be97744508a72nd & (or the value of the special value from below) are compared against
eed2a23d9b5986937f1e2b1c120be97744508a72nd * the regex argument. If this is a simple string, a simple sub-string
eed2a23d9b5986937f1e2b1c120be97744508a72nd * match is performed. Otherwise, a request expression match is
eed2a23d9b5986937f1e2b1c120be97744508a72nd * done. If the value matches the string or regular expression, the
eed2a23d9b5986937f1e2b1c120be97744508a72nd * environment variables listed as var ... are set. Each var can
eed2a23d9b5986937f1e2b1c120be97744508a72nd * be in one of three formats: var, which sets the named variable
eed2a23d9b5986937f1e2b1c120be97744508a72nd * (the value value "1"); var=value, which sets the variable to
eed2a23d9b5986937f1e2b1c120be97744508a72nd * the given value; or !var, which unsets the variable is it has
eed2a23d9b5986937f1e2b1c120be97744508a72nd * been previously set.
eed2a23d9b5986937f1e2b1c120be97744508a72nd * Normally the strings are compared with regard to case. To ignore
eed2a23d9b5986937f1e2b1c120be97744508a72nd * case, use the directive SetEnvIfNoCase instead.
eed2a23d9b5986937f1e2b1c120be97744508a72nd * Special values for 'name' are:
eed2a23d9b5986937f1e2b1c120be97744508a72nd * server_addr IP address of interface on which request arrived
9963f91528694fb21e93da8584c31f226c6de97akess * (analogous to SERVER_ADDR set in ap_add_common_vars())
bcf004854091600aa279525d6772e1827114d39dnd * remote_host Remote host name (if available)
9963f91528694fb21e93da8584c31f226c6de97akess * remote_addr Remote IP address
eed2a23d9b5986937f1e2b1c120be97744508a72nd * remote_user Remote authenticated user (if any)
eed2a23d9b5986937f1e2b1c120be97744508a72nd * request_method Request method (GET, POST, etc)
b51bf223f42d43ca6b1b33c95124edcfa5a871a4nd * request_uri Requested URI
eed2a23d9b5986937f1e2b1c120be97744508a72nd * Examples:
eed2a23d9b5986937f1e2b1c120be97744508a72nd * To set the enviroment variable LOCALHOST if the client is the local
eed2a23d9b5986937f1e2b1c120be97744508a72nd * machine:
eed2a23d9b5986937f1e2b1c120be97744508a72nd * SetEnvIf remote_addr 127.0.0.1 LOCALHOST
eed2a23d9b5986937f1e2b1c120be97744508a72nd * To set LOCAL if the client is the local host, or within our company's
eed2a23d9b5986937f1e2b1c120be97744508a72nd * domain (192.168.10):
eed2a23d9b5986937f1e2b1c120be97744508a72nd * SetEnvIf remote_addr 192.168.10. LOCAL
eed2a23d9b5986937f1e2b1c120be97744508a72nd * SetEnvIf remote_addr 127.0.0.1 LOCALHOST
eed2a23d9b5986937f1e2b1c120be97744508a72nd * This could be written as:
eed2a23d9b5986937f1e2b1c120be97744508a72nd * SetEnvIf remote_addr (127.0.0.1|192.168.10.) LOCAL
eed2a23d9b5986937f1e2b1c120be97744508a72nd * To set HAVE_TS if the client request contains any header beginning
eed2a23d9b5986937f1e2b1c120be97744508a72nd * with "TS" with a value beginning with a lower case alphabet:
eed2a23d9b5986937f1e2b1c120be97744508a72nd * SetEnvIf ^TS* ^[a-z].* HAVE_TS
#include "apr_want.h"
#include "ap_config.h"
#include "httpd.h"
#include "http_config.h"
#include "http_core.h"
#include "http_log.h"
#include "http_protocol.h"
enum special {
} sei_entry;
} sei_cfg_rec;
return (void *) new;
return create_setenvif_config(p);
return create_setenvif_config(p);
if (preg) {
const char *src = s;
int escapes_found = 0;
int in_escape = 0;
while (*src) {
if (in_escape) {
in_escape = 0;
switch (*src) {
return NULL;
src++;
if (!escapes_found) {
src = s;
src++;
return unescaped;
char *regex;
const char *simple_pattern;
const char *feature;
char *var;
int beenhere = 0;
int icase;
if (!*regex) {
if (!*feature) {
beenhere++;
if (*feature) {
if (!beenhere) {
return NULL;
const char *args)
char *fname;
if (!*fname) {
{ NULL },
const char *val;
char *last_name;
switch (b->special_type) {
case SPECIAL_REMOTE_ADDR:
case SPECIAL_SERVER_ADDR:
case SPECIAL_REMOTE_HOST:
case SPECIAL_REMOTE_USER:
case SPECIAL_REQUEST_URI:
case SPECIAL_REQUEST_METHOD:
case SPECIAL_REQUEST_PROTOCOL:
case SPECIAL_NOT:
if (b->pnamereg) {
const apr_array_header_t
val_len = 0;
regm, 0))) {
if (!b->pattern) {
if (replaced) {
replaced);
return DECLINED;