summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhil Pennock <phil+git@apcera.com>2014-03-09 12:44:59 -0400
committerPhil Pennock <phil+git@apcera.com>2014-03-09 12:44:59 -0400
commitd6095c7d9ed4a182734eb080776d37d7f730f7d9 (patch)
tree44aee285971c150a28be916396cc179df681cf96
parent66e7b7d978185db7e19f21caf1da55850490046a (diff)
downloadfcgiwrap-d6095c7d9ed4a182734eb080776d37d7f730f7d9.tar.xz
fcgiwrap-d6095c7d9ed4a182734eb080776d37d7f730f7d9.zip
Let chdir be overriden with FCGI_CHDIR
chdir to directory which holds scripts doesn't work well with some CGIs. Let the FastCGI invoker provide `FCGI_CHDIR` which can be `-` to inhibit chdir, or another place to chdir to.
-rw-r--r--fcgiwrap.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/fcgiwrap.c b/fcgiwrap.c
index d4f7901..458b6d4 100644
--- a/fcgiwrap.c
+++ b/fcgiwrap.c
@@ -521,6 +521,7 @@ static void handle_fcgi_request(void)
int pipe_err[2];
char *filename;
char *last_slash;
+ char *p;
pid_t pid;
struct fcgi_context fc;
@@ -559,15 +560,22 @@ static void handle_fcgi_request(void)
if (!is_allowed_program(filename))
cgi_error("403 Forbidden", "The given script is not allowed to execute", filename);
- last_slash = strrchr(filename, '/');
- if (!last_slash)
- cgi_error("403 Forbidden", "Script name must be a fully qualified path", filename);
+ p = getenv("FCGI_CHDIR");
+ if (p == NULL) {
+ last_slash = strrchr(filename, '/');
+ if (!last_slash)
+ cgi_error("403 Forbidden", "Script name must be a fully qualified path", filename);
- *last_slash = 0;
- if (chdir(filename) < 0)
- cgi_error("403 Forbidden", "Cannot chdir to script directory", filename);
+ *last_slash = 0;
+ if (chdir(filename) < 0)
+ cgi_error("403 Forbidden", "Cannot chdir to script directory", filename);
- *last_slash = '/';
+ *last_slash = '/';
+ } else if (strcmp(p, "-") != 0) {
+ if (chdir(p) < 0) {
+ cgi_error("403 Forbidden", "Cannot chdir to FCGI_CHDIR directory", p);
+ }
+ }
execl(filename, filename, (void *)NULL);
cgi_error("502 Bad Gateway", "Cannot execute script", filename);