Author: markt
Date: Tue Sep 12 20:20:36 2017
New Revision: 1808156
URL: http://svn.apache.org/viewvc?rev=1808156&view=rev
Log:
Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=61189
Add the ability to set environment variables for individual CGI scripts. Based
on a patch by jm009.
Modified:
tomcat/trunk/conf/web.xml
tomcat/trunk/java/org/apache/catalina/servlets/CGIServlet.java
tomcat/trunk/java/org/apache/catalina/servlets/LocalStrings.properties
tomcat/trunk/webapps/docs/cgi-howto.xml
tomcat/trunk/webapps/docs/changelog.xml
Modified: tomcat/trunk/conf/web.xml
URL:
http://svn.apache.org/viewvc/tomcat/trunk/conf/web.xml?rev=1808156&r1=1808155&r2=1808156&view=diff
==============================================================================
--- tomcat/trunk/conf/web.xml (original)
+++ tomcat/trunk/conf/web.xml Tue Sep 12 20:20:36 2017
@@ -363,6 +363,15 @@
<!-- [ACCEPT[-0-9A-Z]*|CACHE-CONTROL|COOKIE|HOST| -->
<!-- IF-[-0-9A-Z]*|REFERER|USER-AGENT] -->
<!-- -->
+ <!-- environment-variable- An environment to be set for the execution -->
+ <!-- environment of the CGI script. The name of -->
+ <!-- variable is taken from the parameter name. -->
+ <!-- To configure an environment variable named -->
+ <!-- FOO, configure a parameter named -->
+ <!-- environment-variable-FOO. The parameter value -->
+ <!-- is used as the environment variable value. -->
+ <!-- The default is no environment variables. -->
+ <!-- -->
<!-- parameterEncoding Name of parameter encoding to be used with -->
<!-- CGI servlet. -->
<!-- [System.getProperty("file.encoding","UTF-8")] -->
Modified: tomcat/trunk/java/org/apache/catalina/servlets/CGIServlet.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/servlets/CGIServlet.java?rev=1808156&r1=1808155&r2=1808156&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/servlets/CGIServlet.java (original)
+++ tomcat/trunk/java/org/apache/catalina/servlets/CGIServlet.java Tue Sep 12
20:20:36 2017
@@ -318,6 +318,17 @@ public final class CGIServlet extends Ht
shellEnv.putAll(System.getenv());
}
+ Enumeration<String> e = config.getInitParameterNames();
+ while(e.hasMoreElements()) {
+ String initParamName = e.nextElement();
+ if (initParamName.startsWith("environment-variable-")) {
+ if (initParamName.length() == 21) {
+ throw new
ServletException(sm.getString("cgiServlet.emptyEnvVarName"));
+ }
+ shellEnv.put(initParamName.substring(21),
config.getInitParameter(initParamName));
+ }
+ }
+
if (getServletConfig().getInitParameter("executable") != null) {
cgiExecutable = getServletConfig().getInitParameter("executable");
}
Modified: tomcat/trunk/java/org/apache/catalina/servlets/LocalStrings.properties
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/servlets/LocalStrings.properties?rev=1808156&r1=1808155&r2=1808156&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/servlets/LocalStrings.properties
(original)
+++ tomcat/trunk/java/org/apache/catalina/servlets/LocalStrings.properties Tue
Sep 12 20:20:36 2017
@@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+cgiServlet.emptyEnvVarName=Empty environment variable name in initialisation
parameter [environment-variable-]
cgiServlet.expandCloseFail=Failed to close input stream for script at path
[{0}]
cgiServlet.expandCreateDirFail=Failed to create destination directory [{0}]
for script expansion
cgiServlet.expandDeleteFail=Failed to delete file at [{0}] after IOException
during expansion
Modified: tomcat/trunk/webapps/docs/cgi-howto.xml
URL:
http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/cgi-howto.xml?rev=1808156&r1=1808155&r2=1808156&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/cgi-howto.xml (original)
+++ tomcat/trunk/webapps/docs/cgi-howto.xml Tue Sep 12 20:20:36 2017
@@ -99,6 +99,11 @@ directory being used as the search path.
<li><strong>enableCmdLineArguments</strong> - Are command line parameters
generated from the query string as per section 4.4 of 3875 RFC? The default is
<code>false</code>.</li>
+<li><strong>environment-variable-</strong> - An environment to be set for the
+execution environment of the CGI script. The name of variable is taken from the
+parameter name. To configure an environment variable named FOO, configure a
+parameter named environment-variable-FOO. The parameter value is used as the
+environment variable value. The default is no environment variables.</li>
<li><strong>executable</strong> - The name of the executable to be used to
run the script. You may explicitly set this parameter to be an empty string
if your script is itself executable (e.g. an exe file). Default is
Modified: tomcat/trunk/webapps/docs/changelog.xml
URL:
http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1808156&r1=1808155&r2=1808156&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Tue Sep 12 20:20:36 2017
@@ -53,6 +53,10 @@
before generating the error page so that the page generation can be
skipped if the page is never going to be sent. (markt)
</fix>
+ <add>
+ <bug>61189</bug>: Add the ability to set environment variables for
+ individual CGI scripts. Based on a patch by jm009. (markt)
+ </add>
<fix>
<bug>61210</bug>: When running under a SecurityManager, do not print a
warning about not being able to read a logging configuration file when
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]