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