Apache SetSysEnv Brian Shire & Facebook Inc. Add option to mod_env that allows setting of system environment variables. SetEnv allows you to set environment variables within the SAPI environment, in the case of Apache/PHP this means that a system getenv() call will fail to get any variable set with SetEnv. SetSysEnv gives you the ability to set system environment variables that can be fetched using getenv(). Tested against Apache-1.3.37 To use: Apply the patch with the following commands: cd apache-1.3.x patch -p1 -i apache_1.3.37.setsysenv.patch Configure apache to build the mod_env module. Recompile and install apache. Add SetSysEnv directives to your Apache configuration files with the format: SetSysEnv Provide feedback to diff --git a/src/modules/standard/mod_env.c b/src/modules/standard/mod_env.c index b3889b8..0dc151c 100644 --- a/src/modules/standard/mod_env.c +++ b/src/modules/standard/mod_env.c @@ -169,6 +169,32 @@ static const char *add_env_module_vars_set(cmd_parms *cmd, return NULL; } +/*** BEGIN Patch: SetSysEnv ***/ +static const char *add_sysenv_module_vars_set(cmd_parms *cmd, + env_dir_config_rec *sconf, + const char *arg) +{ + table *vars = sconf->vars; + char *name, *value; + + name = ap_getword_conf(cmd->pool, &arg); + value = ap_getword_conf(cmd->pool, &arg); + + /* name is mandatory, value is optional. no value means + * set the variable to an empty string + */ + + + if ((*name == '\0') || (*arg != '\0')) { + return "SetSysEnv takes one or two arguments. An environment variable name and an optional value to pass to CGI."; + } + + setenv(name, value, 1); + + return NULL; +} +/*** END Patch: SetSysEnv ***/ + static const char *add_env_module_vars_unset(cmd_parms *cmd, env_dir_config_rec *sconf, char *arg) @@ -194,6 +220,10 @@ static const command_rec env_module_cmds[] = OR_FILEINFO, RAW_ARGS, "a list of environment variables to pass to CGI."}, {"SetEnv", add_env_module_vars_set, NULL, OR_FILEINFO, RAW_ARGS, "an environment variable name and a value to pass to CGI."}, +/*** BEGIN Patch: SetSysEnv ***/ + {"SetSysEnv", add_sysenv_module_vars_set, NULL, + OR_FILEINFO, RAW_ARGS, "an environment variable name and a value set in the system environment."}, +/*** END Patch: SetSysEnv ***/ {"UnsetEnv", add_env_module_vars_unset, NULL, OR_FILEINFO, RAW_ARGS, "a list of variables to remove from the CGI environment."}, {NULL},