mod_setenvif.c revision 4fca72b7b53b5419325e06837c98266148111b52
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen/* Licensed to the Apache Software Foundation (ASF) under one or more
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * contributor license agreements. See the NOTICE file distributed with
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * this work for additional information regarding copyright ownership.
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * The ASF licenses this file to You under the Apache License, Version 2.0
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * (the "License"); you may not use this file except in compliance with
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * the License. You may obtain a copy of the License at
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * Unless required by applicable law or agreed to in writing, software
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * distributed under the License is distributed on an "AS IS" BASIS,
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * See the License for the specific language governing permissions and
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * limitations under the License.
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * Set environment variables based on matching request headers or
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * attributes against regex strings
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * Paul Sutton <paul@ukweb.com> 27 Oct 1996
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * Based on mod_browser by Alexei Kosut <akosut@organic.com>
39d8db043b599a7382f94bfc904d5e108af438bdLennart Poettering * Used to set environment variables based on the incoming request headers,
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering * or some selected other attributes of the request (e.g., the remote host
682265d5e2157882861b0091c6b81fa92699b72aTom Gundersen * SetEnvIf name regex var ...
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * where name is either a HTTP request header name, or one of the
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * special values (see below). 'name' may be a regex when it is used
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * to specify an HTTP request header name. The 'value' of the header
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen & (or the value of the special value from below) are compared against
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * the regex argument. If this is a simple string, a simple sub-string
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * match is performed. Otherwise, a request expression match is
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * done. If the value matches the string or regular expression, the
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * environment variables listed as var ... are set. Each var can
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * be in one of three formats: var, which sets the named variable
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * (the value value "1"); var=value, which sets the variable to
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * the given value; or !var, which unsets the variable is it has
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * been previously set.
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * Normally the strings are compared with regard to case. To ignore
682265d5e2157882861b0091c6b81fa92699b72aTom Gundersen * case, use the directive SetEnvIfNoCase instead.
682265d5e2157882861b0091c6b81fa92699b72aTom Gundersen * Special values for 'name' are:
682265d5e2157882861b0091c6b81fa92699b72aTom Gundersen * server_addr IP address of interface on which request arrived
682265d5e2157882861b0091c6b81fa92699b72aTom Gundersen * (analogous to SERVER_ADDR set in ap_add_common_vars())
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * remote_host Remote host name (if available)
682265d5e2157882861b0091c6b81fa92699b72aTom Gundersen * remote_addr Remote IP address
682265d5e2157882861b0091c6b81fa92699b72aTom Gundersen * request_method Request method (GET, POST, etc)
4e945a6f7971fd7d1f6b2c62ee3afdaff3c95ce4Lennart Poettering * request_uri Requested URI
682265d5e2157882861b0091c6b81fa92699b72aTom Gundersen * To set the environment variable LOCALHOST if the client is the local
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * SetEnvIf remote_addr 127.0.0.1 LOCALHOST
b9e7a9d870ac41d4db954edd52a1f5dd7d153389Lennart Poettering * To set LOCAL if the client is the local host, or within our company's
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * domain (192.168.10):
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * SetEnvIf remote_addr 192.168.10. LOCAL
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * SetEnvIf remote_addr 127.0.0.1 LOCALHOST
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * This could be written as:
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * SetEnvIf remote_addr (127.0.0.1|192.168.10.) LOCAL
091a364c802e34a58f3260c9cb5db9b75c62215cTom Gundersen * To set HAVE_TS if the client request contains any header beginning
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering * with "TS" with a value beginning with a lower case alphabet:
edc501d4674dadc304d45a7e1c5b69e207eb8cd4Lennart Poettering * SetEnvIf ^TS* ^[a-z].* HAVE_TS
} 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;
const char *feature;
int beenhere = 0;
char *var;
if (!*feature) {
beenhere++;
if (*feature) {
if (!beenhere) {
return NULL;
char *regex;
const char *simple_pattern;
int icase;
if (!*regex) {
| AP_REG_ICASE));
const char *args)
char *fname;
if (!*fname) {
const char *args)
char *expr;
const char *err;
if (!*expr) {
if (err)
{ NULL },
char *last_name;
if (!b->expr) {
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;