httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c...@hyperreal.org
Subject cvs commit: apache-1.3/src/modules/standard mod_env.c
Date Sat, 20 Mar 1999 21:51:41 GMT
coar        99/03/20 13:51:40

  Modified:    htdocs/manual/mod mod_env.html
               src      CHANGES
               src/modules/standard mod_env.c
  Log:
  	Add PassAllEnv to make all of the server's environment variables
  	available to CGIs and SSIs within the directive's scope.  NOT
  	recommended for general use, but eases the transition for IBM's
  	current LDGW customers to Apache.
  
  Revision  Changes    Path
  1.13      +47 -0     apache-1.3/htdocs/manual/mod/mod_env.html
  
  Index: mod_env.html
  ===================================================================
  RCS file: /home/cvs/apache-1.3/htdocs/manual/mod/mod_env.html,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- mod_env.html	1999/01/02 13:24:41	1.12
  +++ mod_env.html	1999/03/20 21:51:37	1.13
  @@ -30,11 +30,58 @@
   
   <H2>Directives</H2>
   <UL>
  +<LI><A HREF="#passallenv">PassAllEnv</A>
   <LI><A HREF="#passenv">PassEnv</A>
   <LI><A HREF="#setenv">SetEnv</A>
   <LI><A HREF="#unsetenv">UnsetEnv</A>
   </UL>
   
  +<HR>
  +
  +<H2><A NAME="passallenv">PassAllEnv</A></H2>
  +<A
  + HREF="directive-dict.html#Syntax"
  + REL="Help"
  +><STRONG>Syntax:</STRONG></A> PassAllEnv <EM>On | Off</EM><BR>
  +<A
  + HREF="directive-dict.html#Default"
  + REL="Help"
  +><STRONG>Default:</STRONG></A> <EM>Off</EM>
  +<BR>
  +<A
  + HREF="directive-dict.html#Context"
  + REL="Help"
  +><STRONG>Context:</STRONG></A> directory<BR>
  +<A
  + HREF="directive-dict.html#Status"
  + REL="Help"
  +><STRONG>Status:</STRONG></A> Base<BR>
  +<A
  + HREF="directive-dict.html#Module"
  + REL="Help"
  +><STRONG>Module:</STRONG></A> mod_env<BR>
  +<A
  + HREF="directive-dict.html#Compatibility"
  + REL="Help"
  +><STRONG>Compatibility:</STRONG></A> PassAllEnv is only available
in
  +Apache 1.3.5 and later.
  +<P>
  +This directive controls whether <EM>all</EM> of the server's environment
  +variables should be made available to CGI scripts and SSI documents,
  +or only those explicitly named by
  +<A HREF="#passenv"><CODE>PassEnv</CODE></A> directives or otherwise
  +created by the server itself.
  +</P>
  +<BLOCKQUOTE><STRONG>It is highly recommended that this functionality
  +be enabled only with extreme caution and after careful examination
  +of whether the entire environment is needed.</STRONG></BLOCKQUOTE>
  +<P>
  +Because of security considerations, <CODE>PassAllEnv</CODE> may
  +only appear inside
  +<A HREF="core.html#directory"><SAMP>&lt;Directory&gt;</SAMP></A>
and
  +<A HREF="core.html#location"><SAMP>&lt;Location&gt;</SAMP></A>
  +containers in the server configuration files.
  +</P>
   <HR>
   
   <H2><A NAME="passenv">PassEnv</A></H2>
  
  
  
  1.1286    +3 -0      apache-1.3/src/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/apache-1.3/src/CHANGES,v
  retrieving revision 1.1285
  retrieving revision 1.1286
  diff -u -r1.1285 -r1.1286
  --- CHANGES	1999/03/20 15:41:08	1.1285
  +++ CHANGES	1999/03/20 21:51:38	1.1286
  @@ -1,5 +1,8 @@
   Changes with Apache 1.3.5
   
  +  *) Added PassAllEnv; makes server's entire environment available
  +     to CGIs and SSIs executed within directive's scope.  [Ken Coar]
  +
     *) ap_uuencode() always added two trailing '='s and encoding of
        8 bit characters on a machine with signed char may produced
        incorrect results. Additionally ap_uuencode() should now
  
  
  
  1.26      +121 -20   apache-1.3/src/modules/standard/mod_env.c
  
  Index: mod_env.c
  ===================================================================
  RCS file: /home/cvs/apache-1.3/src/modules/standard/mod_env.c,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- mod_env.c	1999/01/01 19:05:09	1.25
  +++ mod_env.c	1999/03/20 21:51:40	1.26
  @@ -96,24 +96,52 @@
    *       *** configuration carefully before accepting this        ***
    *       *** version of the module in a live webserver which used ***
    *       *** older versions of the module.                        ***
  + * 20.Mar.1999 Added PassAllEnv to allow copying of the entire parent
  + *           process environment to CGIs and SSIs.
    */
   
   #include "httpd.h"
   #include "http_config.h"
   
  -typedef struct {
  +#include <unistd.h>
  +extern char **environ;
  +
  +/*
  + * Server-wide config info for this module
  + */
  +typedef struct env_server_config_rec {
       table *vars;
  +    table *parent_env;
       char *unsetenv;
       int vars_present;
   } env_server_config_rec;
   
  +/*
  + * Per-directory config info
  + */
  +typedef struct env_dir_config_rec {
  +    int passall;
  +} env_dir_config_rec;
  +
   module MODULE_VAR_EXPORT env_module;
   
  +static void *create_env_dir_config(pool *p, char *dspec)
  +{
  +    env_dir_config_rec *dconf;
  +
  +    dconf = ap_palloc(p, sizeof(env_dir_config_rec));
  +    dconf->passall = 0;
  +    return dconf;
  +}
  +
   static void *create_env_server_config(pool *p, server_rec *dummy)
   {
  -    env_server_config_rec *new =
  -    (env_server_config_rec *) ap_palloc(p, sizeof(env_server_config_rec));
  +    env_server_config_rec *new;
  +
  +    new = (env_server_config_rec *) ap_palloc(p,
  +					      sizeof(env_server_config_rec));
       new->vars = ap_make_table(p, 50);
  +    new->parent_env = NULL;
       new->unsetenv = "";
       new->vars_present = 0;
       return (void *) new;
  @@ -123,9 +151,7 @@
   {
       env_server_config_rec *base = (env_server_config_rec *) basev;
       env_server_config_rec *add = (env_server_config_rec *) addv;
  -    env_server_config_rec *new =
  -    (env_server_config_rec *) ap_palloc(p, sizeof(env_server_config_rec));
  -
  +    env_server_config_rec *new;
       table *new_table;
       table_entry *elts;
       array_header *arr;
  @@ -133,6 +159,8 @@
       int i;
       const char *uenv, *unset;
   
  +    new = (env_server_config_rec *) ap_palloc(p,
  +					      sizeof(env_server_config_rec));
       /* 
        * new_table = copy_table( p, base->vars );
        * foreach $element ( @add->vars ) {
  @@ -203,7 +231,8 @@
   
   
       if ((*name == '\0') || (*arg != '\0')) {
  -        return "SetEnv takes one or two arguments.  An environment variable name and an
optional value to pass to CGI.";
  +        return "SetEnv takes one or two arguments.  An environment "
  +	    "variable name and an optional value to pass to CGI.";
       }
   
       sconf->vars_present = 1;
  @@ -215,11 +244,64 @@
   static const char *add_env_module_vars_unset(cmd_parms *cmd, char *struct_ptr,
                                                char *arg)
   {
  -    env_server_config_rec *sconf =
  -    ap_get_module_config(cmd->server->module_config, &env_module);
  -    sconf->unsetenv = sconf->unsetenv ?
  -        ap_pstrcat(cmd->pool, sconf->unsetenv, " ", arg, NULL) :
  -         arg;
  +    env_server_config_rec *sconf;
  +
  +    sconf = ap_get_module_config(cmd->server->module_config, &env_module);
  +    sconf->unsetenv = sconf->unsetenv
  +	? ap_pstrcat(cmd->pool, sconf->unsetenv, " ", arg, NULL)
  +	: arg;
  +    return NULL;
  +}
  +
  +/*
  + * Set up to make the entire server environment available through
  + * r->subprocess_env.
  + */
  +static const char *add_env_module_passall(cmd_parms *cmd, void *mconfig,
  +					  int enable)
  +{
  +    env_dir_config_rec *dconf = (env_dir_config_rec *) mconfig;
  +
  +    dconf->passall = enable;
  +    if (enable) {
  +	env_server_config_rec *sconf;
  +
  +	sconf = (env_server_config_rec *) ap_get_module_config(cmd->server->module_config,
  +							       &env_module);
  +	/*
  +	 * If we've copied the entire server environment before, it's
  +	 * in the server config record.  Otherwise, do so now.
  +	 */
  +	if (sconf->parent_env == NULL) {
  +	    char **e = environ;
  +	    char *lhs;
  +	    char *rhs;
  +
  +	    sconf->parent_env = ap_make_table(cmd->pool, 30);
  +	    while (*e != NULL) {
  +		/*
  +		 * Make a copy of the environment entry so we can split
  +		 * it into a key/value pair with '\0'.
  +		 */
  +		lhs = ap_pstrdup(cmd->pool, *e);
  +		rhs = strchr(lhs, '=');
  +		if (rhs == NULL) {
  +		    rhs = "";
  +		}
  +		else {
  +		    *rhs = '\0';
  +		    rhs++;
  +		}
  +		ap_table_setn(sconf->parent_env, lhs, rhs);
  +		e++;
  +	    }
  +	}
  +	/*
  +	 * Note that there are variables to be copied during the fixup
  +	 * phase.
  +	 */
  +	sconf->vars_present++;
  +    }
       return NULL;
   }
   
  @@ -227,10 +309,12 @@
   {
       {"PassEnv", add_env_module_vars_passed, NULL,
        RSRC_CONF, RAW_ARGS, "a list of environment variables to pass to CGI."},
  -    {"SetEnv", add_env_module_vars_set, NULL,
  -     RSRC_CONF, RAW_ARGS, "an environment variable name and a value to pass to CGI."},
  -    {"UnsetEnv", add_env_module_vars_unset, NULL,
  -     RSRC_CONF, RAW_ARGS, "a list of variables to remove from the CGI environment."},
  +    {"SetEnv", add_env_module_vars_set, NULL, RSRC_CONF, RAW_ARGS,
  +     "an environment variable name and a value to pass to CGI."},
  +    {"UnsetEnv", add_env_module_vars_unset, NULL, RSRC_CONF, RAW_ARGS,
  +     "a list of variables to remove from the CGI environment."},
  +    {"PassAllEnv", add_env_module_passall, NULL, ACCESS_CONF, FLAG,
  +     "On or Off  to control passing of entire server environment."},
       {NULL},
   };
   
  @@ -239,13 +323,30 @@
       table *e = r->subprocess_env;
       server_rec *s = r->server;
       env_server_config_rec *sconf = ap_get_module_config(s->module_config,
  -                                                     &env_module);
  +							&env_module);
  +    env_dir_config_rec *dconf = ap_get_module_config(r->per_dir_config,
  +						     &env_module);
       table *vars = sconf->vars;
   
  -    if (!sconf->vars_present)
  +    if (!sconf->vars_present) {
           return DECLINED;
  +    }
   
  -    r->subprocess_env = ap_overlay_tables(r->pool, e, vars);
  +    /*
  +     * If the entire environment is supposed to be copied, do it.
  +     */
  +    if (dconf->passall) {
  +	r->subprocess_env = ap_overlay_tables(r->pool, r->subprocess_env,
  +					      sconf->parent_env);
  +    }
  +    else {
  +	/*
  +	 * If we just copied the entire environment, we don't need to
  +	 * deal with the PassEnv settings because they were automatically
  +	 * included.  Otherwise, do them now.
  +	 */
  +	r->subprocess_env = ap_overlay_tables(r->pool, e, vars);
  +    }
   
       return OK;
   }
  @@ -254,7 +355,7 @@
   {
       STANDARD_MODULE_STUFF,
       NULL,                       /* initializer */
  -    NULL,                       /* dir config creater */
  +    create_env_dir_config,      /* dir config creater */
       NULL,                       /* dir merger --- default is to override */
       create_env_server_config,   /* server config */
       merge_env_server_configs,   /* merge server configs */
  
  
  

Mime
View raw message