So I wanted to test out nginx and slowcgi. I started everything up and
hit up localhost/cgi-bin/test-cgi. Whoops forgot to move /bin/sh into
the chroot. Try again, shit forgot to chmod 555 test-cgi.
I was complaining on IRC and tbert suggested I write a simple statically
linked testcgi.c so people can easily verify cgi is up and working.
That is what is attached. It just prints out the environment like
test-cgi and printenv but is statically linked and doesn't require
anything to be copied into the chroot. Also it's 555 by default so it
just works. Is this so bad?
The BINDIR is set since I have no idea where in /usr/src this should
live or if this is even anything we want in source but here it is for
those who don't want to mess around with moving things into the www
chroot and just want to verify cgi (slowcgi in my case) is working.
Tested with both nginx + slowcgi and httpd.
--
James Turner
diff -u -p -N Makefile Makefile
--- Makefile Wed Dec 31 19:00:00 1969
+++ Makefile Sat Mar 1 14:06:39 2014
@@ -0,0 +1,7 @@
+PROG= testcgi
+SRCS= testcgi.c
+LDSTATIC= -static
+NOMAN= 1
+BINDIR= /var/www/cgi-bin
+
+.include <bsd.prog.mk>
diff -u -p -N testcgi.c testcgi.c
--- testcgi.c Wed Dec 31 19:00:00 1969
+++ testcgi.c Sat Mar 1 14:15:25 2014
@@ -0,0 +1,42 @@
+/*
+ * This is free and unencumbered software released into the public domain.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+static char *
+cleanenv(char *name)
+{
+ char *env;
+
+ if ((env = getenv(name)) == NULL)
+ return "";
+
+ return env;
+}
+
+int
+main(void)
+{
+ printf("Content-type: text/plain\r\n\r\n");
+ printf("CGI/1.1 test script report:\n\n");
+ printf("GATEWAY_INTERFACE = %s\n", cleanenv("GATEWAY_INTERFACE"));
+ printf("SERVER_SOFTWARE = %s\n", cleanenv("SERVER_SOFTWARE"));
+ printf("SERVER_PROTOCOL = %s\n", cleanenv("SERVER_PROTOCOL"));
+ printf("SERVER_NAME = %s\n", cleanenv("SERVER_NAME"));
+ printf("SERVER_ADDR = %s\n", cleanenv("SERVER_ADDR"));
+ printf("SERVER_PORT = %s\n", cleanenv("SERVER_PORT"));
+ printf("REQUEST_METHOD = %s\n", cleanenv("REQUEST_METHOD"));
+ printf("HTTP_ACCEPT = %s\n", cleanenv("HTTP_ACCEPT"));
+ printf("SCRIPT_NAME = %s\n", cleanenv("SCRIPT_NAME"));
+ printf("REQUEST_URI = %s\n", cleanenv("REQUEST_URI"));
+ printf("PATH_INFO = %s\n", cleanenv("PATH_INFO"));
+ printf("QUERY_STRING = %s\n", cleanenv("QUERY_STRING"));
+ printf("REMOTE_ADDR = %s\n", cleanenv("REMOTE_ADDR"));
+ printf("REMOTE_PORT = %s\n", cleanenv("REMOTE_PORT"));
+ printf("CONTENT_TYPE = %s\n", cleanenv("CONTENT_TYPE"));
+ printf("CONTENT_LENGTH = %s\n", cleanenv("CONTENT_LENGTH"));
+
+ return (0);
+}