Simplified.

On Sat, Mar 01, 2014 at 02:27:44PM -0500, James Turner wrote:
> 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:41:15 2014
@@ -0,0 +1,43 @@
+/*
+ * This is free and unencumbered software released into the public domain.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+static void
+printenv(char *name)
+{
+       char *env;
+
+       if ((env = getenv(name)) == NULL)
+               env = "";
+
+       printf("%s = %s\n", name, env);
+}
+
+int
+main(void)
+{
+       printf("Content-type: text/plain\r\n\r\n");
+       printf("CGI/1.1 test script report:\n\n");
+
+       printenv("GATEWAY_INTERFACE");
+       printenv("SERVER_SOFTWARE");
+       printenv("SERVER_PROTOCOL");
+       printenv("SERVER_NAME");
+       printenv("SERVER_ADDR");
+       printenv("SERVER_PORT");
+       printenv("REQUEST_METHOD");
+       printenv("HTTP_ACCEPT");
+       printenv("SCRIPT_NAME");
+       printenv("REQUEST_URI");
+       printenv("PATH_INFO");
+       printenv("QUERY_STRING");
+       printenv("REMOTE_ADDR");
+       printenv("REMOTE_PORT");
+       printenv("CONTENT_TYPE");
+       printenv("CONTENT_LENGTH");
+
+       return (0);
+}

Reply via email to