Quick patch which allows ENV() variables in config files for the old old
apache 1.3 branch. Posted to stop a certain someone from bugging me about
it.
Have fun.
Dw
Index: src/ApacheCore.def
===================================================================
RCS file: /home/cvs/apache-1.3/src/ApacheCore.def,v
retrieving revision 1.35
diff -u -r1.35 ApacheCore.def
--- src/ApacheCore.def 18 Jun 2002 04:19:46 -0000 1.35
+++ src/ApacheCore.def 18 Dec 2003 14:05:51 -0000
@@ -447,3 +447,4 @@
ap_getline @439
ap_get_chunk_size @440
ap_escape_logitem @441
+ ap_resolve_env @442
Index: src/include/httpd.h
===================================================================
RCS file: /home/cvs/apache-1.3/src/include/httpd.h,v
retrieving revision 1.374
diff -u -r1.374 httpd.h
--- src/include/httpd.h 14 Dec 2003 18:16:49 -0000 1.374
+++ src/include/httpd.h 18 Dec 2003 14:05:52 -0000
@@ -1008,6 +1008,7 @@
API_EXPORT(char *) ap_getword_nulls_nc(pool *p, char **line, char stop);
API_EXPORT(char *) ap_getword_conf(pool *p, const char **line);
API_EXPORT(char *) ap_getword_conf_nc(pool *p, char **line);
+API_EXPORT(char *) ap_resolve_env(pool *p, const char * word);
API_EXPORT(const char *) ap_size_list_item(const char **field, int *len);
API_EXPORT(char *) ap_get_list_item(pool *p, const char **field);
Index: src/main/http_core.c
===================================================================
RCS file: /home/cvs/apache-1.3/src/main/http_core.c,v
retrieving revision 1.327
diff -u -r1.327 http_core.c
--- src/main/http_core.c 17 Nov 2003 17:14:53 -0000 1.327
+++ src/main/http_core.c 18 Dec 2003 14:05:54 -0000
@@ -1282,6 +1282,8 @@
w, NULL);
}
+ line = ap_resolve_env(cmd->pool,line);
+
/* The entry should be ignored if it is a full URL for a 401 error */
if (error_number == 401 &&
Index: src/main/util.c
===================================================================
RCS file: /home/cvs/apache-1.3/src/main/util.c,v
retrieving revision 1.208
diff -u -r1.208 util.c
--- src/main/util.c 14 Dec 2003 18:16:50 -0000 1.208
+++ src/main/util.c 18 Dec 2003 14:06:01 -0000
@@ -756,6 +756,49 @@
return res;
}
+/* Check a string for any ${ENV} environment variable
+ * construct and replace each them by the value of
+ * that environment variable, if it exists. If the
+ * environment value does not exist, replace by an
+ * empty string. Any unrecognized construct is not
+ * replaced and silently ignored. Apart from that
+ * simple ${ENV:=defaults} are also possible.
+ */
+API_EXPORT(char *) ap_resolve_env(pool *p, const char * word)
+{
+ char tmp[ MAX_STRING_LEN ];
+ char * s, * e;
+ tmp[0] = '\0';
+
+ if (!(s=strchr(word,'$')))
+ return (char *)word;
+
+ do {
+ /* XXX - relies on strncat() to add '\0'
+ */
+ strncat(tmp,word,s - word);
+
+ if ((s[1] == '{') && (e=strchr(s,'}'))) {
+ char * dfault = "";
+ *e = '\0';
+ if ((dfault = strchr(s,':')) && ((dfault[1] == '='))) {
+ *dfault = '\0';
+ dfault +=2;
+ }
+ word = e + 1;
+ e = getenv(s+2);
+ strcat(tmp,e ? e : dfault);
+ } else {
+ /* ignore invalid strings */
+ word = s+1;
+ strcat(tmp,"$");
+ };
+ } while ((s=strchr(word,'$')));
+ strcat(tmp,word);
+
+ return ap_pstrdup(p,tmp);
+}
+
/* Get a word, (new) config-file style --- quoted strings and backslashes
* all honored
*/
@@ -775,7 +818,7 @@
}
*resp++ = '\0';
- return result;
+ return ap_resolve_env(p, result);
}
API_EXPORT(char *) ap_getword_conf_nc(pool *p, char **line)
@@ -1469,54 +1512,90 @@
return where;
}
Index: src/support/httpd.exp
===================================================================
RCS file: /home/cvs/apache-1.3/src/support/httpd.exp,v
retrieving revision 1.41
diff -u -r1.41 httpd.exp
--- src/support/httpd.exp 17 Jan 2003 12:23:10 -0000 1.41
+++ src/support/httpd.exp 18 Dec 2003 14:06:03 -0000
@@ -107,6 +107,7 @@
ap_error_log2stderr
ap_escape_html
ap_escape_logitem
+ap_esolve_env
ap_escape_path_segment
ap_escape_quotes
ap_escape_shell_cmd