You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by "David (Dave) Donnan" <da...@thalesgroup.com> on 2010/09/28 16:02:22 UTC

[users@httpd] Setting CGI environment variables, dynamically, from httpd.conf leveraging exising variables

OS: Windoze httpd: 2.2.1.6

Hello everybody and thanks for taking the time to read this posting.

I apologize, in advance, if I'm a novice. I've looked extensively and 
have not found a solution -- perhaps I've completely misunderstood.

I need to instantiate a CGI environment variable $SMUSER with the 
contents of
an existing environment variable, say, $REMOTE_USER.

I'm testing with setenv.pl to display the CGI environment.

I've tried 3 techniques:

Technique 1: Rewrite
--------------------

RewriteEngine on

RewriteRule .* - [E=SMUSER:%{$REMOTE_USER}]
RequestHeader set my_new_header %{SMUSER}e

        Result from my browser (setenv.pl):

        SMUSER=""

Question 1: The syntax is incredibly cryptic. Where might I look to help 
me understand the %, e, {} etc.

Mind you, it works for simple text:

    RewriteRule .* - [E=SMUSER:test]

    Result: SMUSER="test"

2. Technique 2: setenv DAVESETENV "text"
----------------------------------------------

    Result: DAVESETENV="text"
 
But, I've read that this is only a static string.

http://www.usenet-forums.com/apache-web-server/10179-setenv-dynamic-variable.html


Technique 3. JkEnvVar.
-----------------------

If I've understood correctly, we can 'fool' HTTPD into thinking there
is a Tomcat behind and, therefore, use mod_jk.

Question 2: Am I correct ?

JkWorkersFile conf/workers.properties
JkEnvVar DAVEJKENVVAR "test"
JkLogFile "logs/mod_jk.log"
JkLogLevel debug

Result: nothing related to DAVE in the browser

Question 3: Which technique do you recommend and can you please give me 
a nudge in the right direction ?

Cdlt, Dave
--------


[users@httpd] RewriteRule E=SMUSER:%{LA-U:REMOTE_USER} works but not E=SMUSER:%{LA-U:SSL_CLIENT_S_DN_EMAIL}

Posted by "David (Dave) Donnan" <da...@thalesgroup.com>.
Hello again. I hope I've not overstayed my welcome.

    RewriteRule .* - [E=SMUSER:%{LA-U:REMOTE_USER}] works for both 80
    and 443 (SSL)

However, the following doesn't work for either (I understand why it 
doesn't work for port 80 :-)

    RewriteRule .* - [E=SMUSER:%{LA-U:SSL_CLIENT_S_DN_EMAIL}]

Nor the following:

    RewriteRule .* - [E=SMUSER:%{LA-F:SSL_CLIENT_S_DN_EMAIL}]      #
    note L A-F, not LA-U

I've done my reading but have not found the definitive list of supported 
variables.

I found a table at the following link, search for %{ NAME_OF_VARIABLE  } 

    http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule

Is SSL_CLIENT_S_DN_EMAIL not supported or am I, perhaps, missing something ?

Any help would be greatly appreciated, Dave
-------

David (Dave) Donnan wrote:
> Hello everybody.
>
> Eric, thanks for the rapide response. I took the $PATH of least 
> resistance, corrected Technique #1, and now it WORKS !
>
> httpd.conf:
>     RewriteEngine on
>     RewriteRule .* - [E=SMUSER:%{LA-U:REMOTE_USER}]
>
> Result (setenv.pl):
>     ...
>     SMUSER="<my-LDAP-userid :-) >"
>     ...
> Thanks again, Dave
>
> PS: I had no luck with setenvif but I'm more than happy with the 
> RewriteRule.
> ------
>
> Eric Covener wrote:
>> On Tue, Sep 28, 2010 at 10:02 AM, David (Dave) Donnan
>> <da...@thalesgroup.com> wrote:
>>   
>>> RewriteEngine on
>>>
>>> RewriteRule .* - [E=SMUSER:%{$REMOTE_USER}]
>>> RequestHeader set my_new_header %{SMUSER}e
>>>
>>>         Result from my browser (setenv.pl):
>>>
>>>         SMUSER=""
>>>     
>>
>> I think the $ is extraneous and causing problems. Another potential
>> problem --  See the "lookahead" feature to figure out REMOTE_USER when
>> your RewriteRules are running in a phase before REMOTE_USER is set!
>>
>> You may be able to wrap your rules in <Directory>, which makes the
>> Rewrite occur a little bit later, and might let some rules like this
>> work better.
>>
>> Finally, why do you want to set the environment variable in a request
>> header? Is this just some debug you added along the way, or your
>> ultimate goal?
>>
>>   
>>> Question 1: The syntax is incredibly cryptic. Where might I look to help me
>>> understand the %, e, {} etc.
>>>     
>> The variable syntax for RequestHeader is defined in a table at the
>> bottom of the Header directive:
>>
>> http://httpd.apache.org/docs/current/mod/mod_headers.html#header
>>
>> The syntax for mod_rewrite is midway down in the doc for RewriteRule:
>> http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule
>>
>>   
>>> Mind you, it works for simple text:
>>>
>>> RewriteRule .* - [E=SMUSER:test]
>>>
>>> Result: SMUSER="test"
>>>
>>> 2. Technique 2: setenv DAVESETENV "text"
>>> ----------------------------------------------
>>>
>>>     Result: DAVESETENV="text"
>>>
>>> But, I've read that this is only a static string.
>>>
>>> http://www.usenet-forums.com/apache-web-server/10179-setenv-dynamic-variable.html
>>>     
>>
>> setenvif is a bit more flexible:
>> http://httpd.apache.org/docs/current/mod/mod_setenvif.html#setenvif
>>
>>   
>


[users@httpd] Re: RewriteRule E=SMUSER:%{LA-U:REMOTE_USER} works but not E=SMUSER:%{LA-U:SSL_CLIENT_S_DN_EMAIL}

Posted by "David (Dave) Donnan" <da...@thalesgroup.com>.
My bad, it works as follows (worth noting for the archives).

    RewriteRule .* - [E=SMUSER:%{SSL:SSL_CLIENT_S_DN_Email}]

Cdlt, Dave
------
David (Dave) Donnan wrote:
> Hello again. I hope I've not overstayed my welcome.
>
>     RewriteRule .* - [E=SMUSER:%{LA-U:REMOTE_USER}] works for both 80
>     and 443 (SSL)
>
> However, the following doesn't work for either (I understand why it 
> doesn't work for port 80 :-)
>
>     RewriteRule .* - [E=SMUSER:%{LA-U:SSL_CLIENT_S_DN_EMAIL}]
>
> Nor the following:
>
>     RewriteRule .* - [E=SMUSER:%{LA-F:SSL_CLIENT_S_DN_EMAIL}]      #
>     note L A-F, not LA-U
>
> I've done my reading but have not found the definitive list of 
> supported variables.
>
> I found a table at the following link, search for %{ NAME_OF_VARIABLE  } 
>
>     http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule
>
> Is SSL_CLIENT_S_DN_EMAIL not supported or am I, perhaps, missing 
> something ?
>
> Any help would be greatly appreciated, Dave
> -------
>
> David (Dave) Donnan wrote:
>> Hello everybody.
>>
>> Eric, thanks for the rapide response. I took the $PATH of least 
>> resistance, corrected Technique #1, and now it WORKS !
>>
>> httpd.conf:
>>     RewriteEngine on
>>     RewriteRule .* - [E=SMUSER:%{LA-U:REMOTE_USER}]
>>
>> Result (setenv.pl):
>>     ...
>>     SMUSER="<my-LDAP-userid :-) >"
>>     ...
>> Thanks again, Dave
>>
>> PS: I had no luck with setenvif but I'm more than happy with the 
>> RewriteRule.
>> ------
>>
>> Eric Covener wrote:
>>> On Tue, Sep 28, 2010 at 10:02 AM, David (Dave) Donnan
>>> <da...@thalesgroup.com> wrote:
>>>   
>>>> RewriteEngine on
>>>>
>>>> RewriteRule .* - [E=SMUSER:%{$REMOTE_USER}]
>>>> RequestHeader set my_new_header %{SMUSER}e
>>>>
>>>>         Result from my browser (setenv.pl):
>>>>
>>>>         SMUSER=""
>>>>     
>>>
>>> I think the $ is extraneous and causing problems. Another potential
>>> problem --  See the "lookahead" feature to figure out REMOTE_USER when
>>> your RewriteRules are running in a phase before REMOTE_USER is set!
>>>
>>> You may be able to wrap your rules in <Directory>, which makes the
>>> Rewrite occur a little bit later, and might let some rules like this
>>> work better.
>>>
>>> Finally, why do you want to set the environment variable in a request
>>> header? Is this just some debug you added along the way, or your
>>> ultimate goal?
>>>
>>>   
>>>> Question 1: The syntax is incredibly cryptic. Where might I look to help me
>>>> understand the %, e, {} etc.
>>>>     
>>> The variable syntax for RequestHeader is defined in a table at the
>>> bottom of the Header directive:
>>>
>>> http://httpd.apache.org/docs/current/mod/mod_headers.html#header
>>>
>>> The syntax for mod_rewrite is midway down in the doc for RewriteRule:
>>> http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule
>>>
>>>   
>>>> Mind you, it works for simple text:
>>>>
>>>> RewriteRule .* - [E=SMUSER:test]
>>>>
>>>> Result: SMUSER="test"
>>>>
>>>> 2. Technique 2: setenv DAVESETENV "text"
>>>> ----------------------------------------------
>>>>
>>>>     Result: DAVESETENV="text"
>>>>
>>>> But, I've read that this is only a static string.
>>>>
>>>> http://www.usenet-forums.com/apache-web-server/10179-setenv-dynamic-variable.html
>>>>     
>>>
>>> setenvif is a bit more flexible:
>>> http://httpd.apache.org/docs/current/mod/mod_setenvif.html#setenvif
>>>
>>>   
>>
>


Re: [users@httpd] Setting CGI environment variables, dynamically, from httpd.conf leveraging exising variables

Posted by "David (Dave) Donnan" <da...@thalesgroup.com>.
Hello everybody.

Eric, thanks for the rapide response. I took the $PATH of least 
resistance, corrected Technique #1, and now it WORKS !

httpd.conf:
    RewriteEngine on
    RewriteRule .* - [E=SMUSER:%{LA-U:REMOTE_USER}]

Result (setenv.pl):
    ...
    SMUSER="<my-LDAP-userid :-) >"
    ...
Thanks again, Dave

PS: I had no luck with setenvif but I'm more than happy with the 
RewriteRule.
------

Eric Covener wrote:
> On Tue, Sep 28, 2010 at 10:02 AM, David (Dave) Donnan
> <da...@thalesgroup.com> wrote:
>   
>> RewriteEngine on
>>
>> RewriteRule .* - [E=SMUSER:%{$REMOTE_USER}]
>> RequestHeader set my_new_header %{SMUSER}e
>>
>>         Result from my browser (setenv.pl):
>>
>>         SMUSER=""
>>     
>
> I think the $ is extraneous and causing problems. Another potential
> problem --  See the "lookahead" feature to figure out REMOTE_USER when
> your RewriteRules are running in a phase before REMOTE_USER is set!
>
> You may be able to wrap your rules in <Directory>, which makes the
> Rewrite occur a little bit later, and might let some rules like this
> work better.
>
> Finally, why do you want to set the environment variable in a request
> header? Is this just some debug you added along the way, or your
> ultimate goal?
>
>   
>> Question 1: The syntax is incredibly cryptic. Where might I look to help me
>> understand the %, e, {} etc.
>>     
> The variable syntax for RequestHeader is defined in a table at the
> bottom of the Header directive:
>
> http://httpd.apache.org/docs/current/mod/mod_headers.html#header
>
> The syntax for mod_rewrite is midway down in the doc for RewriteRule:
> http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule
>
>   
>> Mind you, it works for simple text:
>>
>> RewriteRule .* - [E=SMUSER:test]
>>
>> Result: SMUSER="test"
>>
>> 2. Technique 2: setenv DAVESETENV "text"
>> ----------------------------------------------
>>
>>     Result: DAVESETENV="text"
>>
>> But, I've read that this is only a static string.
>>
>> http://www.usenet-forums.com/apache-web-server/10179-setenv-dynamic-variable.html
>>     
>
> setenvif is a bit more flexible:
> http://httpd.apache.org/docs/current/mod/mod_setenvif.html#setenvif
>
>   


Re: [users@httpd] Setting CGI environment variables, dynamically, from httpd.conf leveraging exising variables

Posted by Eric Covener <co...@gmail.com>.
On Tue, Sep 28, 2010 at 10:02 AM, David (Dave) Donnan
<da...@thalesgroup.com> wrote:
> RewriteEngine on
>
> RewriteRule .* - [E=SMUSER:%{$REMOTE_USER}]
> RequestHeader set my_new_header %{SMUSER}e
>
>         Result from my browser (setenv.pl):
>
>         SMUSER=""

I think the $ is extraneous and causing problems. Another potential
problem --  See the "lookahead" feature to figure out REMOTE_USER when
your RewriteRules are running in a phase before REMOTE_USER is set!

You may be able to wrap your rules in <Directory>, which makes the
Rewrite occur a little bit later, and might let some rules like this
work better.

Finally, why do you want to set the environment variable in a request
header? Is this just some debug you added along the way, or your
ultimate goal?

>
> Question 1: The syntax is incredibly cryptic. Where might I look to help me
> understand the %, e, {} etc.
The variable syntax for RequestHeader is defined in a table at the
bottom of the Header directive:

http://httpd.apache.org/docs/current/mod/mod_headers.html#header

The syntax for mod_rewrite is midway down in the doc for RewriteRule:
http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule

> Mind you, it works for simple text:
>
> RewriteRule .* - [E=SMUSER:test]
>
> Result: SMUSER="test"
>
> 2. Technique 2: setenv DAVESETENV "text"
> ----------------------------------------------
>
>     Result: DAVESETENV="text"
>
> But, I've read that this is only a static string.
>
> http://www.usenet-forums.com/apache-web-server/10179-setenv-dynamic-variable.html

setenvif is a bit more flexible:
http://httpd.apache.org/docs/current/mod/mod_setenvif.html#setenvif

-- 
Eric Covener
covener@gmail.com

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org