Return-Path: Delivered-To: apmail-httpd-dev-archive@www.apache.org Received: (qmail 11492 invoked from network); 4 Dec 2004 08:23:34 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 4 Dec 2004 08:23:34 -0000 Received: (qmail 967 invoked by uid 500); 4 Dec 2004 08:23:28 -0000 Delivered-To: apmail-httpd-dev-archive@httpd.apache.org Received: (qmail 915 invoked by uid 500); 4 Dec 2004 08:23:28 -0000 Mailing-List: contact dev-help@httpd.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@httpd.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list dev@httpd.apache.org Received: (qmail 889 invoked by uid 99); 4 Dec 2004 08:23:28 -0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=FORGED_RCVD_HELO X-Spam-Check-By: apache.org Received-SPF: neutral (hermes.apache.org: local policy) Received: from mail.xnet.hr (HELO pop.xnet.hr) (83.139.64.5) by apache.org (qpsmtpd/0.28) with ESMTP; Sat, 04 Dec 2004 00:23:26 -0800 Received: from [83.139.76.246] (dh76-246.xnet.hr [83.139.76.246]) by pop.xnet.hr (8.12.10/8.12.10) with ESMTP id iB48NmDV019284 for ; Sat, 4 Dec 2004 09:23:48 +0100 Message-ID: <41B17401.5000905@apache.org> Date: Sat, 04 Dec 2004 09:23:29 +0100 From: Mladen Turk User-Agent: Mozilla X-Accept-Language: en-us, en MIME-Version: 1.0 To: HTTPD Developers List Subject: mod_headers -- RequestHeader passing common vars. Content-Type: multipart/mixed; boundary="------------090209010309070406090705" X-Virus-Scanned: clamd / ClamAV version 0.71, clamav-milter version 0.71 X-Virus-Status: Clean X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N This is a multi-part message in MIME format. --------------090209010309070406090705 Content-Type: text/plain; charset=ISO-8859-2; format=flowed Content-Transfer-Encoding: 7bit Hi all, Is there any reason (RFC or security) that prevents using common vars within 'RequestHeader XX %{ENV_VAR}e'. Those can now be only set by SetEnv, SetEnvIf and PassEnv. A simple patch that calls ap_add_common_vars(r) before processing the variable from r->subprocess_env will do more then enough. It will allow to pass the REMOTE_USER for example down the reverse proxy backend as header. Second thing is setting the unknown value to string "(null)". I propose to not set anything if the header value is not present and to remove the value from headers_in if present and the required env var doesn't exists. As an example of current behavior: RequestHeader REMOTE_USER %{REMOTE_USER}e sets the header: HTTP_REMOTE_USER="(null)" Of course the '(null)' is far from being a valid user name. I have enclosed the patch. Regards, Mladen --------------090209010309070406090705 Content-Type: text/plain; name="mod_headers.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="mod_headers.patch" Index: mod_headers.c =================================================================== --- mod_headers.c (revision 109218) +++ mod_headers.c (working copy) @@ -77,6 +77,7 @@ #include "http_log.h" #include "util_filter.h" #include "http_protocol.h" +#include "util_script.h" #include "mod_ssl.h" /* for the ssl_var_lookup optional function defn */ @@ -177,12 +178,15 @@ static const char *header_request_env_var(request_rec *r, char *a) { - const char *s = apr_table_get(r->subprocess_env,a); + const char *s; + ap_add_common_vars(r); + s = apr_table_get(r->subprocess_env,a); + if (s) return unwrap_header(r->pool, s); else - return "(null)"; + return NULL; } static const char *header_request_ssl_var(request_rec *r, char *name) @@ -193,10 +197,10 @@ if (val && val[0]) return unwrap_header(r->pool, val); else - return "(null)"; + return NULL; } else { - return "(null)"; + return NULL; } } @@ -504,12 +508,14 @@ for (i = 0; i < hdr->ta->nelts; i++) { s = tag[i].func(r, tag[i].arg); - if (str == NULL) - str = apr_pstrdup(r->pool, s); - else - str = apr_pstrcat(r->pool, str, s, NULL); + if (s) { + if (str == NULL) + str = apr_pstrdup(r->pool, s); + else + str = apr_pstrcat(r->pool, str, s, NULL); + } } - return str ? str : ""; + return str; } static int echo_header(echo_do *v, const char *key, const char *val) @@ -532,7 +538,7 @@ for (i = 0; i < fixup->nelts; ++i) { header_entry *hdr = &((header_entry *) (fixup->elts))[i]; const char *envar = hdr->condition_var; - + char *tag; /* ignore early headers in late calls */ if (!early && (envar == condition_early)) { continue; @@ -555,13 +561,21 @@ switch (hdr->action) { case hdr_add: - apr_table_addn(headers, hdr->header, process_tags(hdr, r)); + tag = process_tags(hdr, r); + if (tag) + apr_table_addn(headers, hdr->header, tag); break; case hdr_append: - apr_table_mergen(headers, hdr->header, process_tags(hdr, r)); + tag = process_tags(hdr, r); + if (tag) + apr_table_mergen(headers, hdr->header, tag); break; case hdr_set: - apr_table_setn(headers, hdr->header, process_tags(hdr, r)); + tag = process_tags(hdr, r); + if (tag) + apr_table_setn(headers, hdr->header, tag); + else + apr_table_unset(headers, hdr->header); break; case hdr_unset: apr_table_unset(headers, hdr->header); --------------090209010309070406090705--