From: Jeff Trawick Date: Thu, 18 Jul 2002 12:25:24 +0000 (+0000) Subject: mod_ext_filter: Set up environment variables for external programs. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=48591275804983920ea4679138a9996da2e87086;p=apache mod_ext_filter: Set up environment variables for external programs. Submitted by: Craig Sebenik Reviewed by: Jeff Trawick git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@96111 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index dcdb1ecad9..06cb6cb8fa 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,8 @@ Changes with Apache 2.0.40 + *) mod_ext_filter: Set up environment variables for external programs. + [Craig Sebenik ] + *) Modified the HTTP_IN filter to immediately append the EOS (end of stream) bucket for C-L POST bodies, saving a roundtrip and allowing the caller to determine that no content remains without prefetching diff --git a/docs/manual/mod/mod_ext_filter.html.en b/docs/manual/mod/mod_ext_filter.html.en index ebf0d1bb7e..3f6f552d78 100644 --- a/docs/manual/mod/mod_ext_filter.html.en +++ b/docs/manual/mod/mod_ext_filter.html.en @@ -148,7 +148,10 @@ program name, the command line should be surrounded in quotation marks (e.g., cmd="/bin/mypgm arg1 arg2". Normal shell quoting is not necessary since the program is - run directly, bypassing the shell. + run directly, bypassing the shell. In addition to the + standard CGI environment variables, DOCUMENT_URI, + DOCUMENT_PATH_INFO, and QUERY_STRING_UNESCAPED will also be set + for the program.
mode=mode
diff --git a/docs/manual/mod/mod_ext_filter.xml b/docs/manual/mod/mod_ext_filter.xml index 0899a29813..de26a30319 100644 --- a/docs/manual/mod/mod_ext_filter.xml +++ b/docs/manual/mod/mod_ext_filter.xml @@ -164,7 +164,10 @@ program name, the command line should be surrounded in quotation marks (e.g., cmd="/bin/mypgm arg1 arg2". Normal shell quoting is not necessary since the program is - run directly, bypassing the shell. + run directly, bypassing the shell. In addition to the + standard CGI environment variables, DOCUMENT_URI, + DOCUMENT_PATH_INFO, and QUERY_STRING_UNESCAPED will also be set + for the program.
mode=mode
diff --git a/modules/experimental/mod_ext_filter.c b/modules/experimental/mod_ext_filter.c index 37fa4137b1..0ce3832c79 100644 --- a/modules/experimental/mod_ext_filter.c +++ b/modules/experimental/mod_ext_filter.c @@ -68,6 +68,7 @@ #include "http_core.h" #include "apr_buckets.h" #include "util_filter.h" +#include "util_script.h" #include "apr_strings.h" #include "apr_hash.h" #include "apr_lib.h" @@ -395,6 +396,7 @@ static apr_status_t init_ext_filter_process(ap_filter_t *f) ef_ctx_t *ctx = f->ctx; apr_status_t rc; ef_dir_t *dc = ctx->dc; + const char * const *env; ctx->proc = apr_pcalloc(ctx->p, sizeof(*ctx->proc)); @@ -416,11 +418,28 @@ static apr_status_t init_ext_filter_process(ap_filter_t *f) NULL); ap_assert(rc == APR_SUCCESS); } - + + /* add standard CGI variables as well as DOCUMENT_URI, DOCUMENT_PATH_INFO, + * and QUERY_STRING_UNESCAPED + */ + ap_add_cgi_vars(f->r); + apr_table_setn(f->r->subprocess_env, "DOCUMENT_URI", f->r->uri); + apr_table_setn(f->r->subprocess_env, "DOCUMENT_PATH_INFO", f->r->path_info); + if (f->r->args) { + /* QUERY_STRING is added by ap_add_cgi_vars */ + char *arg_copy = apr_pstrdup(f->r->pool, f->r->args); + ap_unescape_url(arg_copy); + apr_table_setn(f->r->subprocess_env, "QUERY_STRING_UNESCAPED", + ap_escape_shell_cmd(f->r->pool, arg_copy)); + } + + env = (const char * const *) ap_create_environment(ctx->p, + f->r->subprocess_env); + rc = apr_proc_create(ctx->proc, ctx->filter->command, (const char * const *)ctx->filter->args, - NULL, /* environment */ + env, /* environment */ ctx->procattr, ctx->p); if (rc != APR_SUCCESS) {