You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Hynek Schlawack <hy...@hys.in-berlin.de> on 2004/07/27 11:30:49 UTC
[users@httpd] Patching mod_cgi to prepend commandlines in Apache 2/Linux
Hi,
I'm afraid that I'm going to embarass myself but I simply can't work it
out:
I'm trying to patch mod_cgi of Apache 2 running on Linux so that it
prepends the commandline with another command (notably a wrapper that
does some stuff we need). I mostly only modificated
default_build_command (unfortunatly there will be more changes
necessary, so I can't just write an own build_command()), the result is
the following diff:
--- /home/hynek/src/httpd-2.0.49/modules/generators/mod_cgi.c 2004-02-09 21:53:17.000000000 +0100
+++ mod_vm_cgiwrap.c 2004-07-27 11:07:29.500405784 +0200
@@ -26,6 +26,8 @@
* they fail.
*/
+#define WRAP_BIN "/home/hynek/t"
+
+
#include "apr.h"
#include "apr_strings.h"
#include "apr_thread_proc.h" /* for RLIMIT stuff */
@@ -485,7 +487,8 @@
const char *args = NULL;
if (e_info->process_cgi) {
- *cmd = r->filename;
+ *cmd = apr_pstrdup(p, WRAP_BIN);
+
/* Do not process r->args if they contain an '=' assignment
*/
if (r->args && r->args[0] && !ap_strchr_c(r->args, '=')) {
@@ -494,25 +497,26 @@
}
if (!args) {
- numwords = 1;
+ numwords = 2;
}
else {
/* count the number of keywords */
- for (x = 0, numwords = 2; args[x]; x++) {
+ for (x = 0, numwords = 3; args[x]; x++) {
if (args[x] == '+') {
++numwords;
}
}
}
- /* Everything is - 1 to account for the first parameter
- * which is the program name.
+ /* Everything is - 2 to account for the first parameters
+ * which are the wrapper and the program name.
*/
- if (numwords > APACHE_ARG_MAX - 1) {
- numwords = APACHE_ARG_MAX - 1; /* Truncate args to prevent overrun */
+ if (numwords > APACHE_ARG_MAX - 2) {
+ numwords = APACHE_ARG_MAX - 2; /* Truncate args to prevent overrun */
}
*argv = apr_palloc(p, (numwords + 2) * sizeof(char *));
(*argv)[0] = *cmd;
- for (x = 1, idx = 1; x < numwords; x++) {
+ (*argv)[1] = r->filename;
+ for (x = 2, idx = 2; x < numwords; x++) {
w = ap_getword_nulls(p, &args, '+');
ap_unescape_url(w);
(*argv)[idx++] = ap_escape_shell_cmd(p, w);
@@ -1043,7 +1047,7 @@
ap_hook_post_config(cgi_post_config, aszPre, NULL, APR_HOOK_REALLY_FIRST);
}
-module AP_MODULE_DECLARE_DATA cgi_module =
+module AP_MODULE_DECLARE_DATA cgi_wrap_module =
{
STANDARD20_MODULE_STUFF,
NULL, /* dir config creater */
t is in this case a binary that just prints "Content-Type:
text/html\n\nfoobar\n".
This modification works perfectly when the script is in a directory
defined by ScriptAlias(Match). However when I start it in a "normal"
directory that has +ExecCGI, I get a "[error] [client 127.0.0.1]
Premature end of script headers: test.pl" in the error_log.
I've been able to trace that the program is sucessfully "started" by the
module in run_cgi_child() (ie. the call to
ap_os_create_privileged_process() doesn't fail) however the program is
never started.
Could anyone give a a pointer where to look at? I'm starting to get
desperate as it seem trivial to me but it doesn't work. :( Google and
the other obvious ressources failed (or my imagination of
searching-keywords).
TIA,
Hynek
P.S. The setup is pretty vanilla, only mod_cgi is commented out. I'm certainly
not testing on a production server.
---------------------------------------------------------------------
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