Re: Simple static testcgi.c
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. heh, been there, done that :) 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? yes, it's 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. I would put it somewhere in a directory under usr.sbin/nginx/ and add a SUBDIR to Makefile.bsd-wrapper. So with httpd gone test-cgi is gone, too. I was thinking, cool, let's get this static C cgi program in. However, turns out we already have one in base, it's called bgplg. So to test if slowcgi is working chmod 555 /var/www/cgi-bin/bgplg and point your browser to http://localhost/cgi-bin/bgplg. It works perfectly fine for this scenario without a bgpd running. Make sure to chmod 000 it afterwards. -- I'm not entirely sure you are real.
Simple static testcgi.c
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 --- MakefileWed Dec 31 19:00:00 1969 +++ MakefileSat 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); +}
Re: Simple static testcgi.c
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 --- MakefileWed Dec 31 19:00:00 1969 +++ MakefileSat 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); +}