mod_setenvif.c revision 3e976e5310058fce42ae8a5db9f1eb14d45707fa
842ae4bd224140319ae7feec1872b93dfd491143fielding/* Copyright 1999-2005 The Apache Software Foundation or its licensors, as
842ae4bd224140319ae7feec1872b93dfd491143fielding * applicable.
842ae4bd224140319ae7feec1872b93dfd491143fielding * Licensed under the Apache License, Version 2.0 (the "License");
842ae4bd224140319ae7feec1872b93dfd491143fielding * you may not use this file except in compliance with the License.
842ae4bd224140319ae7feec1872b93dfd491143fielding * You may obtain a copy of the License at
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * Unless required by applicable law or agreed to in writing, software
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * distributed under the License is distributed on an "AS IS" BASIS,
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * See the License for the specific language governing permissions and
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * limitations under the License.
9d129b55f5a43abf43865c6b0eb6dd19bc22aba8ianh * Set environment variables based on matching request headers or
9d129b55f5a43abf43865c6b0eb6dd19bc22aba8ianh * attributes against regex strings
9d129b55f5a43abf43865c6b0eb6dd19bc22aba8ianh * Paul Sutton <paul@ukweb.com> 27 Oct 1996
9d129b55f5a43abf43865c6b0eb6dd19bc22aba8ianh * Based on mod_browser by Alexei Kosut <akosut@organic.com>
b1627fe7e2cb3809dcdfdf1fcbbb6dbccaf788c6rbb * Used to set environment variables based on the incoming request headers,
b1627fe7e2cb3809dcdfdf1fcbbb6dbccaf788c6rbb * or some selected other attributes of the request (e.g., the remote host
64ff1949093e64474a00badd61a3495e35fa192daaron * SetEnvIf name regex var ...
52fc962d27921f20981eef91d6236e9024c604d7wrowe * where name is either a HTTP request header name, or one of the
b1627fe7e2cb3809dcdfdf1fcbbb6dbccaf788c6rbb * special values (see below). 'name' may be a regex when it is used
52fc962d27921f20981eef91d6236e9024c604d7wrowe * to specify an HTTP request header name. The 'value' of the header
e00ae6859667e293a4c40108f524408ae1289f2frbb & (or the value of the special value from below) are compared against
b1627fe7e2cb3809dcdfdf1fcbbb6dbccaf788c6rbb * the regex argument. If this is a simple string, a simple sub-string
7d37dff338a52aa8836d78e4f1a67b76911da66caaron * match is performed. Otherwise, a request expression match is
7d37dff338a52aa8836d78e4f1a67b76911da66caaron * done. If the value matches the string or regular expression, the
7d37dff338a52aa8836d78e4f1a67b76911da66caaron * environment variables listed as var ... are set. Each var can
5d5d5ca04c57c7ab865924f4648e8f80de27adfebrianp * be in one of three formats: var, which sets the named variable
5d5d5ca04c57c7ab865924f4648e8f80de27adfebrianp * (the value value "1"); var=value, which sets the variable to
5d5d5ca04c57c7ab865924f4648e8f80de27adfebrianp * the given value; or !var, which unsets the variable is it has
5d5d5ca04c57c7ab865924f4648e8f80de27adfebrianp * been previously set.
7d37dff338a52aa8836d78e4f1a67b76911da66caaron * Normally the strings are compared with regard to case. To ignore
7d37dff338a52aa8836d78e4f1a67b76911da66caaron * case, use the directive SetEnvIfNoCase instead.
e00ae6859667e293a4c40108f524408ae1289f2frbb * Special values for 'name' are:
e00ae6859667e293a4c40108f524408ae1289f2frbb * server_addr IP address of interface on which request arrived
e00ae6859667e293a4c40108f524408ae1289f2frbb * (analogous to SERVER_ADDR set in ap_add_common_vars())
b1627fe7e2cb3809dcdfdf1fcbbb6dbccaf788c6rbb * remote_host Remote host name (if available)
e00ae6859667e293a4c40108f524408ae1289f2frbb * remote_addr Remote IP address
64ff1949093e64474a00badd61a3495e35fa192daaron * request_method Request method (GET, POST, etc)
8639a789ef8a4adec121d5b26b4d66c5cf8989ccjim * request_uri Requested URI
8639a789ef8a4adec121d5b26b4d66c5cf8989ccjim * Examples:
64ff1949093e64474a00badd61a3495e35fa192daaron * To set the enviroment variable LOCALHOST if the client is the local
e00ae6859667e293a4c40108f524408ae1289f2frbb * SetEnvIf remote_addr 127.0.0.1 LOCALHOST
b1627fe7e2cb3809dcdfdf1fcbbb6dbccaf788c6rbb * To set LOCAL if the client is the local host, or within our company's
a322a82f79b790fb7ddcd7df4459d20725450fa7trawick * domain (192.168.10):
5d5d5ca04c57c7ab865924f4648e8f80de27adfebrianp * SetEnvIf remote_addr 192.168.10. LOCAL
e00ae6859667e293a4c40108f524408ae1289f2frbb * SetEnvIf remote_addr 127.0.0.1 LOCALHOST
b1627fe7e2cb3809dcdfdf1fcbbb6dbccaf788c6rbb * This could be written as:
9d129b55f5a43abf43865c6b0eb6dd19bc22aba8ianh * SetEnvIf remote_addr (127.0.0.1|192.168.10.) LOCAL
#include "apr.h"
#include "apr_strings.h"
#include "apr_strmatch.h"
#define APR_WANT_STRFUNC
#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"
#include "mod_ssl.h"
enum special {
} sei_entry;
} sei_cfg_rec;
return (void *) new;
return create_setenvif_config(p);
return create_setenvif_config(p);
const char *src = s;
int escapes_found = 0;
int in_escape = 0;
while (*src) {
switch (*src) {
if (!in_escape) {
return NULL;
in_escape = 0;
if (!in_escape) {
in_escape = 0;
if (in_escape) {
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) {
| AP_REG_ICASE));
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_REQUEST_URI:
case SPECIAL_REQUEST_METHOD:
case SPECIAL_REQUEST_PROTOCOL:
case SPECIAL_OID_VALUE:
char **oid_value;
int j, len = 0;
case SPECIAL_NOT:
if (b->pnamereg) {
const apr_array_header_t
val_len = 0;
if (!b->pattern) {
if (replaced) {
replaced);
return DECLINED;
return OK;