mod_env.c revision fd0edaa8e3d4dd67d0604ccef2e96b071db96643
8a77240a809197c92c0736c431b4b88947a7bac1Christian Maeder/* ====================================================================
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * Copyright (c) 1995-1999 The Apache Group. All rights reserved.
ece3b1a5353a9af3c966a1d5453594ed35334f7bJonathan von Schroeder * Redistribution and use in source and binary forms, with or without
ece3b1a5353a9af3c966a1d5453594ed35334f7bJonathan von Schroeder * modification, are permitted provided that the following conditions
98890889ffb2e8f6f722b00e265a211f13b5a861Corneliu-Claudiu Prodescu * 1. Redistributions of source code must retain the above copyright
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * notice, this list of conditions and the following disclaimer.
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * 2. Redistributions in binary form must reproduce the above copyright
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * notice, this list of conditions and the following disclaimer in
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * the documentation and/or other materials provided with the
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * distribution.
6820f0de92751e29d73d64db48e776591f529a76Christian Maeder * 3. All advertising materials mentioning features or use of this
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * software must display the following acknowledgment:
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * "This product includes software developed by the Apache Group
6820f0de92751e29d73d64db48e776591f529a76Christian Maeder * for use in the Apache HTTP server project (http://www.apache.org/)."
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * 4. The names "Apache Server" and "Apache Group" must not be used to
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * endorse or promote products derived from this software without
6820f0de92751e29d73d64db48e776591f529a76Christian Maeder * prior written permission. For written permission, please contact
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * apache@apache.org.
6820f0de92751e29d73d64db48e776591f529a76Christian Maeder * 5. Products derived from this software may not be called "Apache"
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * nor may "Apache" appear in their names without prior written
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * permission of the Apache Group.
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * 6. Redistributions of any form whatsoever must retain the following
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * acknowledgment:
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * "This product includes software developed by the Apache Group
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * for use in the Apache HTTP server project (http://www.apache.org/)."
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE GROUP OR
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * IT'S CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
c56a356d3fcc5e123efa790aab320781d94df3c7Jonathan von Schroeder * OF THE POSSIBILITY OF SUCH DAMAGE.
c56a356d3fcc5e123efa790aab320781d94df3c7Jonathan von Schroeder * ====================================================================
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * This software consists of voluntary contributions made by many
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * individuals on behalf of the Apache Group and was originally based
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * on public domain software written at the National Center for
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * Supercomputing Applications, University of Illinois, Urbana-Champaign.
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * For more information on the Apache Group and the Apache HTTP server
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * project, please see <http://www.apache.org/>.
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * version 0.0.5
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * Pass environment variables to CGI/SSI scripts.
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * Andrew Wilson <Andrew.Wilson@cm.cf.ac.uk> 06.Dec.95
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * 08.Dec.95 Now allows PassEnv directive to appear more than once in
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * 10.Dec.95 optimisation. getenv() only called at startup and used
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * to build a fast-to-access table. table used to build
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * per-server environment for each request.
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * robustness. better able to handle errors in configuration
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * 1) PassEnv directive present, but no environment variable listed
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * 2) PassEnv FOO present, but $FOO not present in environment
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * 3) no PassEnv directive present
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * 23.Dec.95 Now allows SetEnv directive with same semantics as 'sh' setenv:
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * SetEnv Var sets Var to the empty string
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * SetEnv Var Val sets Var to the value Val
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * Values containing whitespace should be quoted, eg:
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * SetEnv Var "this is some text"
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * Environment variables take their value from the last instance
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * of PassEnv / SetEnv to be reached in the configuration file.
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * For example, the sequence:
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * SetEnv FOO override
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * Causes FOO to take the value 'override'.
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * 23.Feb.96 Added UnsetEnv directive to allow environment variables
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * to be removed.
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * Virtual hosts now 'inherit' parent server environment which
ece3b1a5353a9af3c966a1d5453594ed35334f7bJonathan von Schroeder * they're able to overwrite with their own directives or
ece3b1a5353a9af3c966a1d5453594ed35334f7bJonathan von Schroeder * selectively ignore with UnsetEnv.
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * *** IMPORTANT - the way that virtual hosts inherit their ***
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * *** environment variables from the default server's ***
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * *** configuration has changed. You should test your ***
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * *** configuration carefully before accepting this ***
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * *** version of the module in a live webserver which used ***
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * *** older versions of the module. ***
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroedertypedef struct {
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroederstatic void *create_env_dir_config(pool *p, char *dummy)
c56a356d3fcc5e123efa790aab320781d94df3c7Jonathan von Schroeder (env_dir_config_rec *) ap_palloc(p, sizeof(env_dir_config_rec));
ece3b1a5353a9af3c966a1d5453594ed35334f7bJonathan von Schroeder return (void *) new;
ece3b1a5353a9af3c966a1d5453594ed35334f7bJonathan von Schroederstatic void *merge_env_dir_configs(pool *p, void *basev, void *addv)
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder env_dir_config_rec *base = (env_dir_config_rec *) basev;
ece3b1a5353a9af3c966a1d5453594ed35334f7bJonathan von Schroeder env_dir_config_rec *add = (env_dir_config_rec *) addv;
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder (env_dir_config_rec *) ap_palloc(p, sizeof(env_dir_config_rec));
80d2ec8f37d5ddec13c14b17b1bab01e9c94630aChristian Maeder * new_table = copy_table( p, base->vars );
a669e4685b32ff5ca1bca785eacc5e30a545b010Christian Maeder * foreach $element ( @add->vars ) {
ece3b1a5353a9af3c966a1d5453594ed35334f7bJonathan von Schroeder * table_set( new_table, $element.key, $element.val );
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder * foreach $unsetenv ( @UNSETENV ) {
ece3b1a5353a9af3c966a1d5453594ed35334f7bJonathan von Schroeder * table_unset( new_table, $unsetenv );
ece3b1a5353a9af3c966a1d5453594ed35334f7bJonathan von Schroeder new_table = ap_copy_table(p, base->vars);
d71447e45047d07006b4c20409fbd8ea287df01fJonathan von Schroeder ap_table_setn(new_table, elts[i].key, elts[i].val);
d71447e45047d07006b4c20409fbd8ea287df01fJonathan von Schroeder new->vars_present = base->vars_present || add->vars_present;
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroederstatic const char *add_env_module_vars_passed(cmd_parms *cmd,
b35e053c2c5a5ea0f13decfd0303894861d82b4dJonathan von Schroeder name_ptr = ap_getword_conf(cmd->pool, &arg);
d71447e45047d07006b4c20409fbd8ea287df01fJonathan von Schroeder ap_table_setn(vars, name_ptr, ap_pstrdup(cmd->pool, env_var));
d71447e45047d07006b4c20409fbd8ea287df01fJonathan von Schroederstatic const char *add_env_module_vars_set(cmd_parms *cmd,
return "SetEnv takes one or two arguments. An environment variable name and an optional value to pass to CGI.";
return NULL;
char *arg)
arg;
return NULL;
{NULL},
&env_module);
return DECLINED;
return OK;
static void register_hooks(void)