aboutsummaryrefslogtreecommitdiff
path: root/fcgi-cgi.c
diff options
context:
space:
mode:
authorStefan Bühler <stbuehler@web.de>2009-03-28 18:15:43 +0100
committerStefan Bühler <stbuehler@web.de>2009-03-28 18:15:43 +0100
commitf06a31313aac9e621954398483bd0e102ea4587b (patch)
tree4a783516078bcde4a8deb7eb0667289cbaa1d041 /fcgi-cgi.c
parentae457595a1fbf8275fe5a4f56969f521290d41b0 (diff)
downloadfcgi-cgi-f06a31313aac9e621954398483bd0e102ea4587b.tar.gz
fcgi-cgi-f06a31313aac9e621954398483bd0e102ea4587b.zip
Exec either INTERPRETER or SCRIPT_FILENAME
Diffstat (limited to 'fcgi-cgi.c')
-rw-r--r--fcgi-cgi.c46
1 files changed, 45 insertions, 1 deletions
diff --git a/fcgi-cgi.c b/fcgi-cgi.c
index 52824a6..9d60f62 100644
--- a/fcgi-cgi.c
+++ b/fcgi-cgi.c
@@ -10,9 +10,11 @@
#include <stdlib.h>
#include <fcntl.h>
#include <stropts.h>
+#include <sys/stat.h>
#define MAX_BUFFER_SIZE (64*1024)
+#define CONST_STR_LEN(x) (x), sizeof(x) - 1
#define GSTR_LEN(x) (x) ? (x)->str : "", (x) ? (x)->len : 0
#define UNUSED(x) ((void)(x))
@@ -405,12 +407,54 @@ error:
fcgi_cgi_child_error(cld);
}
+static void fcgi_cgi_direct_result(fastcgi_connection *fcon, int status) {
+ GString *s = g_string_new(0);
+ g_string_append_printf(s, "Status: %i\r\n\r\n", status);
+ fastcgi_send_out(fcon, s);
+ fastcgi_send_out(fcon, NULL);
+ fastcgi_send_err(fcon, NULL);
+ fastcgi_end_request(fcon, 0, FCGI_REQUEST_COMPLETE);
+}
+
static void fcgi_cgi_new_request(fastcgi_connection *fcon) {
fcgi_cgi_child *cld = (fcgi_cgi_child*) fcon->data;
+ gchar *binpath;
+ struct stat st;
if (cld) return;
+
+ binpath = fastcgi_connection_environ_lookup(fcon, CONST_STR_LEN("INTERPRETER"));
+ if (!binpath) binpath = fastcgi_connection_environ_lookup(fcon, CONST_STR_LEN("SCRIPT_FILENAME"));
+
+ if (!binpath) {
+ fcgi_cgi_direct_result(fcon, 500);
+ return;
+ }
+
+ if (-1 == stat(binpath, &st)) {
+ switch (errno) {
+ case EACCES:
+ case ENOTDIR:
+ fcgi_cgi_direct_result(fcon, 403);
+ break;
+ case ENOENT:
+ fcgi_cgi_direct_result(fcon, 404);
+ break;
+ default:
+ fcgi_cgi_direct_result(fcon, 500);
+ break;
+ }
+ return;
+ }
+
+ if (!S_ISREG(st.st_mode) || !((S_IXUSR | S_IXGRP | S_IXOTH) && st.st_mode)) {
+ fcgi_cgi_direct_result(fcon, 403);
+ return;
+ }
+
cld = fcgi_cgi_child_create(fcon->fsrv->data, fcon);
fcon->data = cld;
- fcgi_cgi_child_start(cld, "/usr/bin/php5-cgi");
+
+ fcgi_cgi_child_start(cld, binpath);
}
static void fcgi_cgi_wrote_data(fastcgi_connection *fcon) {