--- fpexec.c.orig Tue Aug 2 14:38:31 2005 +++ fpexec.c Wed Aug 3 11:23:41 2005 @@ -125,6 +125,9 @@ "FILEPATH_INFO", "GATEWAY_INTERFACE", "LAST_MODIFIED", +#if 0 + "NEW_DOCUMENT_ROOT", +#endif "PATH_INFO", "PATH_TRANSLATED", "QUERY_STRING", @@ -768,6 +771,53 @@ clean_env(); + /* fixup environment */ + { + char *e = getenv("HTTP_X_FORWARDED_HOST"); + if (e) + setenv("HTTP_HOST", e, 1); + else + e = getenv("HTTP_HOST"); + if (e) { + char tmp[256]; + char *pp; + snprintf(tmp, sizeof(tmp), "%s", e); + pp = strchr(tmp, ':'); + if (pp) *pp = '\0'; + setenv("SERVER_NAME", tmp, 1); + } +#if 0 + e = getenv("NEW_DOCUMENT_ROOT"); + if(e) { + setenv("DOCUMENT_ROOT", e, 1); + unsetenv("NEW_DOCUMENT_ROOT"); + } + + unsetenv("SCRIPT_URL"); + unsetenv("SCRIPT_URI"); +#endif + } + +#if 0 + /* debugging of script environment */ + { + char **ep; + log_msg("cwd: %s\n", cwd); + log_msg("fpd (new argv[0]): %s\n", fpd); + ep = argv; + while (*ep) { + log_msg("arg: %s\n", *ep); + ep++; + } + log_msg("arg count: %d\n", ep - argv); + ep = environ; + while (*ep) { + log_msg("%s\n", *ep); + ep++; + } + } +#endif + /* * Be sure to close the log file so the CGI can't * mess with it. If the exec fails, it will be reopened @@ -803,6 +853,52 @@ printf("Content-Type: text/html\n"); fflush(stdout); } + +#if 0 + /* + * Execute the command in a subprocess; sometimes we get + * without a header, so fake one up. + */ + { + pid_t pid; + int status, first; + int rpipe[2]; + FILE *cdata; + char buf[256]; + + if (pipe(rpipe) < 0) { + log_err("pipe failed"); + exit(255); + } + + pid = fork(); + if (pid < 0) { + log_err("fork failed"); + exit(255); + } + if (pid == 0) { /* child */ + close(rpipe[0]); + dup2(rpipe[1], 1); + execv(fpd, &argv[0]); + } + close(rpipe[1]); + cdata = fdopen(rpipe[0], "r"); + if (cdata == 0) { + log_err("fdopen failed"); + exit(255); + } + first = 1; + while (fgets(buf, sizeof(buf), cdata) != 0) { + if (first && !strncasecmp(buf, "", 6)) { + fputs("Content-Type: text/html\r\n\r\n", stdout); + } + first = 0; + fputs(buf, stdout); + } + waitpid(pid, &status, 0); + exit(WEXITSTATUS(status)); + } +#endif /* * Execute the command, replacing our image with its own.