From 0d65af1b2bfd66ecc9120125dbb4dc1accd8d0e1 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Mon, 8 Jul 2024 13:11:00 -0700 Subject: [PATCH] Add unobfuscated code from @SirWumpus The entries 2004/hibachi and 2005/mynx have unobfuscated code now. 2004/hibachi has a configure script that is used along the lines of the original entry (with some adjustments and fixes) and the hibachi.alt.c had to have ctype.h included too. The directory src/localhost was copied to src-alt/localhost but the rest of src/ was from Anthony. The Makefile had to be updated to build this version. 2005/mynx does have a configure script but it is, just like the original entry, unused and so the unobfuscated (in source-alt/) is also unused. The mynx.alt.c was changed to mynx.alt2.c and the unobfuscated code was made mynx.alt.c. Updated manifest, rebuilt .entry.json and index.html files. After a question is answered and taken care of (in one of 199[1-3]/ant - not sure which one) issue #2513 can possibly be closed as complete (though the manifest updates will have to be looked at more when 2004 and 2005 are reviewed). --- 2004/hibachi/.entry.json | 330 +- 2004/hibachi/.gitignore | 7 + 2004/hibachi/Makefile | 22 +- 2004/hibachi/README.md | 29 + 2004/hibachi/hibachi.alt.c | 458 ++ 2004/hibachi/hibachi.c | 3 +- 2004/hibachi/index.html | 55 +- 2004/hibachi/src-alt/IOCCC-2004/mkentry.c | 1302 +++++ 2004/hibachi/src-alt/configure | 4303 +++++++++++++++++ 2004/hibachi/src-alt/configure.in | 138 + 2004/hibachi/src-alt/hibachi-start.sh | 185 + 2004/hibachi/src-alt/hibachi-start.sh.in | 185 + 2004/hibachi/src-alt/ioccc.c | 117 + 2004/hibachi/src-alt/localhost/CHANGELOG.TXT | 63 + .../src-alt/localhost/Img/cygwin-icon.gif | Bin 0 -> 132 bytes .../hibachi/src-alt/localhost/Img/freebsd.gif | Bin 0 -> 2384 bytes .../Img/hibachi-256-oc-nc-300x150.gif | Bin 0 -> 227717 bytes .../Img/hot-coal-edge-110-indent.png | Bin 0 -> 6547 bytes .../src-alt/localhost/Img/logosml.256.png | Bin 0 -> 2419 bytes .../localhost/Img/php-small-trans-light.gif | Bin 0 -> 1397 bytes .../Img/powered-by-hibachi-150x75.png | Bin 0 -> 5978 bytes .../localhost/Img/rectangle_power_perl.gif | Bin 0 -> 909 bytes .../src-alt/localhost/Img/sun_logo.gif | Bin 0 -> 1074 bytes 2004/hibachi/src-alt/localhost/Img/win.gif | Bin 0 -> 1387 bytes 2004/hibachi/src-alt/localhost/index.html | 438 ++ .../src-alt/localhost/reference/rfc2616.html | 23 + 2004/hibachi/src-alt/localhost/style.css | 110 + .../src-alt/localhost/test/perl/index.html | 66 + .../localhost/test/perl/yahoo-ticker.pl | 77 + .../localhost/test/perl/yahoo-ticker.pl.in | 77 + .../src-alt/localhost/test/php/Date.php | 557 +++ .../src-alt/localhost/test/php/index.php | 106 + .../src-alt/localhost/test/php/index_php.in | 106 + .../src-alt/localhost/test/php/info.php | 15 + .../src-alt/localhost/test/php/info.php.in | 15 + .../src-alt/localhost/test/php/sendform.html | 68 + .../src-alt/localhost/test/php/sendform.php | 81 + .../localhost/test/php/sendform.php.in | 81 + .../src-alt/localhost/test/ruby/LUHN.rb | 150 + .../src-alt/localhost/test/ruby/index.rb | 80 + .../src-alt/localhost/test/ruby/index_rb.in | 80 + .../src-alt/localhost/test/shell/dump.sh | 31 + .../src-alt/localhost/test/shell/test0.sh | 117 + .../src-alt/localhost/test/shell/test1.sh | 92 + .../src-alt/localhost/test/shell/test2.sh | 91 + 2004/hibachi/src-alt/makefile.in | 184 + 2004/hibachi/src-alt/transform.sed | 142 + 2005/mynx/.entry.json | 40 + 2005/mynx/.gitignore | 3 + 2005/mynx/Makefile | 4 +- 2005/mynx/README.md | 44 +- 2005/mynx/index.html | 45 +- 2005/mynx/mynx.alt.c | 504 +- 2005/mynx/mynx.alt2.c | 400 ++ 2005/mynx/source-alt/configure | 4227 ++++++++++++++++ 2005/mynx/source-alt/configure.in | 77 + 2005/mynx/source-alt/makefile.in | 52 + 2005/mynx/source-alt/transform.sed | 184 + thanks-for-help.html | 20 +- thanks-for-help.md | 23 +- tmp/manifest.csv | 50 +- tmp/manifest.numbers | Bin 1342605 -> 1359029 bytes tmp/path_list.found.txt | 46 + tmp/path_list.manifest.txt | 46 + tmp/path_list.required.txt | 46 + 65 files changed, 15578 insertions(+), 217 deletions(-) create mode 100644 2004/hibachi/hibachi.alt.c create mode 100644 2004/hibachi/src-alt/IOCCC-2004/mkentry.c create mode 100644 2004/hibachi/src-alt/configure create mode 100644 2004/hibachi/src-alt/configure.in create mode 100755 2004/hibachi/src-alt/hibachi-start.sh create mode 100644 2004/hibachi/src-alt/hibachi-start.sh.in create mode 100644 2004/hibachi/src-alt/ioccc.c create mode 100644 2004/hibachi/src-alt/localhost/CHANGELOG.TXT create mode 100644 2004/hibachi/src-alt/localhost/Img/cygwin-icon.gif create mode 100644 2004/hibachi/src-alt/localhost/Img/freebsd.gif create mode 100644 2004/hibachi/src-alt/localhost/Img/hibachi-256-oc-nc-300x150.gif create mode 100644 2004/hibachi/src-alt/localhost/Img/hot-coal-edge-110-indent.png create mode 100644 2004/hibachi/src-alt/localhost/Img/logosml.256.png create mode 100644 2004/hibachi/src-alt/localhost/Img/php-small-trans-light.gif create mode 100644 2004/hibachi/src-alt/localhost/Img/powered-by-hibachi-150x75.png create mode 100644 2004/hibachi/src-alt/localhost/Img/rectangle_power_perl.gif create mode 100644 2004/hibachi/src-alt/localhost/Img/sun_logo.gif create mode 100644 2004/hibachi/src-alt/localhost/Img/win.gif create mode 100644 2004/hibachi/src-alt/localhost/index.html create mode 100644 2004/hibachi/src-alt/localhost/reference/rfc2616.html create mode 100644 2004/hibachi/src-alt/localhost/style.css create mode 100644 2004/hibachi/src-alt/localhost/test/perl/index.html create mode 100755 2004/hibachi/src-alt/localhost/test/perl/yahoo-ticker.pl create mode 100644 2004/hibachi/src-alt/localhost/test/perl/yahoo-ticker.pl.in create mode 100644 2004/hibachi/src-alt/localhost/test/php/Date.php create mode 100755 2004/hibachi/src-alt/localhost/test/php/index.php create mode 100644 2004/hibachi/src-alt/localhost/test/php/index_php.in create mode 100755 2004/hibachi/src-alt/localhost/test/php/info.php create mode 100644 2004/hibachi/src-alt/localhost/test/php/info.php.in create mode 100644 2004/hibachi/src-alt/localhost/test/php/sendform.html create mode 100755 2004/hibachi/src-alt/localhost/test/php/sendform.php create mode 100644 2004/hibachi/src-alt/localhost/test/php/sendform.php.in create mode 100644 2004/hibachi/src-alt/localhost/test/ruby/LUHN.rb create mode 100755 2004/hibachi/src-alt/localhost/test/ruby/index.rb create mode 100644 2004/hibachi/src-alt/localhost/test/ruby/index_rb.in create mode 100755 2004/hibachi/src-alt/localhost/test/shell/dump.sh create mode 100755 2004/hibachi/src-alt/localhost/test/shell/test0.sh create mode 100755 2004/hibachi/src-alt/localhost/test/shell/test1.sh create mode 100755 2004/hibachi/src-alt/localhost/test/shell/test2.sh create mode 100644 2004/hibachi/src-alt/makefile.in create mode 100644 2004/hibachi/src-alt/transform.sed create mode 100644 2005/mynx/mynx.alt2.c create mode 100755 2005/mynx/source-alt/configure create mode 100644 2005/mynx/source-alt/configure.in create mode 100644 2005/mynx/source-alt/makefile.in create mode 100644 2005/mynx/source-alt/transform.sed diff --git a/2004/hibachi/.entry.json b/2004/hibachi/.entry.json index 252e033d77..e630258dfa 100644 --- a/2004/hibachi/.entry.json +++ b/2004/hibachi/.entry.json @@ -9,6 +9,14 @@ { "author_handle" : "Anthony_C_Howe" } ], "manifest" : [ + { + "file_path" : "hibachi.alt.c", + "inventory_order" : 20, + "OK_to_edit" : true, + "display_as" : "c", + "display_via_github" : true, + "entry_text" : "author provided unobfuscated code" + }, { "file_path" : "hibachi.c", "inventory_order" : 20, @@ -33,6 +41,22 @@ "display_via_github" : true, "entry_text" : "original source code" }, + { + "file_path" : "src-alt/configure", + "inventory_order" : 100, + "OK_to_edit" : true, + "display_as" : "shellscript", + "display_via_github" : true, + "entry_text" : "GNU Autoconf script for alt server" + }, + { + "file_path" : "src-alt/localhost/index.html", + "inventory_order" : 100, + "OK_to_edit" : true, + "display_as" : "html", + "display_via_github" : false, + "entry_text" : "home page of alt HIBACHI web server" + }, { "file_path" : "src/configure", "inventory_order" : 100, @@ -47,7 +71,63 @@ "OK_to_edit" : true, "display_as" : "html", "display_via_github" : false, - "entry_text" : "home page of HIBACHI web server" + "entry_text" : "home page of alt HIBACHI web server" + }, + { + "file_path" : "src-alt/IOCCC-2004/mkentry.c", + "inventory_order" : 120, + "OK_to_edit" : true, + "display_as" : "c", + "display_via_github" : true, + "entry_text" : "IOCCC tool of 2004 to package entries" + }, + { + "file_path" : "src-alt/ioccc.c", + "inventory_order" : 120, + "OK_to_edit" : true, + "display_as" : "c", + "display_via_github" : true, + "entry_text" : "IOCCC size tool" + }, + { + "file_path" : "src-alt/localhost/reference/rfc2616.html", + "inventory_order" : 125, + "OK_to_edit" : true, + "display_as" : "html", + "display_via_github" : false, + "entry_text" : "RFC 2616 - Hypertext Transfer Protocol - alt server" + }, + { + "file_path" : "src-alt/localhost/test/perl/index.html", + "inventory_order" : 125, + "OK_to_edit" : true, + "display_as" : "html", + "display_via_github" : false, + "entry_text" : "perl test page of alt HIBACHI server" + }, + { + "file_path" : "src-alt/localhost/test/php/index.php", + "inventory_order" : 125, + "OK_to_edit" : true, + "display_as" : "php", + "display_via_github" : true, + "entry_text" : "PHP making an ISO 8601:2000 calendar for alt server" + }, + { + "file_path" : "src-alt/localhost/test/ruby/index.rb", + "inventory_order" : 125, + "OK_to_edit" : true, + "display_as" : "ruby", + "display_via_github" : true, + "entry_text" : "ruby home page for alt server" + }, + { + "file_path" : "src-alt/localhost/test/shell/test0.sh", + "inventory_order" : 125, + "OK_to_edit" : true, + "display_as" : "shellscript", + "display_via_github" : true, + "entry_text" : "POSIX shell CGI home page for alt server" }, { "file_path" : "src/localhost/CHANGES-OBFUSCATED.TXT", @@ -97,6 +177,30 @@ "display_via_github" : true, "entry_text" : "POSIX shell CGI home page" }, + { + "file_path" : "src-alt/transform.sed", + "inventory_order" : 130, + "OK_to_edit" : true, + "display_as" : "sed", + "display_via_github" : true, + "entry_text" : "sed(1) script for building unobfuscated code" + }, + { + "file_path" : "src-alt/hibachi-start.sh", + "inventory_order" : 150, + "OK_to_edit" : true, + "display_as" : "shellscript", + "display_via_github" : true, + "entry_text" : "start the alt web server" + }, + { + "file_path" : "src-alt/localhost/test/perl/yahoo-ticker.pl", + "inventory_order" : 150, + "OK_to_edit" : true, + "display_as" : "perl", + "display_via_github" : true, + "entry_text" : "stock price fetch example in Perl for alt server" + }, { "file_path" : "src/hibachi-start.sh", "inventory_order" : 150, @@ -113,6 +217,30 @@ "display_via_github" : true, "entry_text" : "stock price fetch example in Perl" }, + { + "file_path" : "src-alt/configure.in", + "inventory_order" : 200, + "OK_to_edit" : true, + "display_as" : "shellscript", + "display_via_github" : true, + "entry_text" : "GNU Autoconf script for alt server" + }, + { + "file_path" : "src-alt/hibachi-start.sh.in", + "inventory_order" : 200, + "OK_to_edit" : true, + "display_as" : "shellscript", + "display_via_github" : true, + "entry_text" : "hibachi-start.sh declarations for alt server" + }, + { + "file_path" : "src-alt/localhost/CHANGELOG.TXT", + "inventory_order" : 200, + "OK_to_edit" : true, + "display_as" : "text", + "display_via_github" : false, + "entry_text" : "obfuscation change log for alt server" + }, { "file_path" : "src/configure.in", "inventory_order" : 200, @@ -177,6 +305,206 @@ "display_via_github" : true, "entry_text" : "markdown source for this web page" }, + { + "file_path" : "src-alt/localhost/Img/cygwin-icon.gif", + "inventory_order" : 4000000000, + "OK_to_edit" : true, + "display_as" : "image", + "display_via_github" : false, + "entry_text" : "image for home page for alt server" + }, + { + "file_path" : "src-alt/localhost/Img/freebsd.gif", + "inventory_order" : 4000000000, + "OK_to_edit" : true, + "display_as" : "image", + "display_via_github" : false, + "entry_text" : "image for home page for alt server" + }, + { + "file_path" : "src-alt/localhost/Img/hibachi-256-oc-nc-300x150.gif", + "inventory_order" : 4000000000, + "OK_to_edit" : true, + "display_as" : "image", + "display_via_github" : false, + "entry_text" : "image for home page for alt server" + }, + { + "file_path" : "src-alt/localhost/Img/hot-coal-edge-110-indent.png", + "inventory_order" : 4000000000, + "OK_to_edit" : true, + "display_as" : "image", + "display_via_github" : false, + "entry_text" : "image for home page for alt server" + }, + { + "file_path" : "src-alt/localhost/Img/logosml.256.png", + "inventory_order" : 4000000000, + "OK_to_edit" : true, + "display_as" : "image", + "display_via_github" : false, + "entry_text" : "image for home page for alt server" + }, + { + "file_path" : "src-alt/localhost/Img/php-small-trans-light.gif", + "inventory_order" : 4000000000, + "OK_to_edit" : true, + "display_as" : "image", + "display_via_github" : false, + "entry_text" : "image for home page for alt server" + }, + { + "file_path" : "src-alt/localhost/Img/powered-by-hibachi-150x75.png", + "inventory_order" : 4000000000, + "OK_to_edit" : true, + "display_as" : "image", + "display_via_github" : false, + "entry_text" : "image for home page for alt server" + }, + { + "file_path" : "src-alt/localhost/Img/rectangle_power_perl.gif", + "inventory_order" : 4000000000, + "OK_to_edit" : true, + "display_as" : "image", + "display_via_github" : false, + "entry_text" : "image for home page for alt server" + }, + { + "file_path" : "src-alt/localhost/Img/sun_logo.gif", + "inventory_order" : 4000000000, + "OK_to_edit" : true, + "display_as" : "image", + "display_via_github" : false, + "entry_text" : "image for home page for alt server" + }, + { + "file_path" : "src-alt/localhost/Img/win.gif", + "inventory_order" : 4000000000, + "OK_to_edit" : true, + "display_as" : "image", + "display_via_github" : false, + "entry_text" : "image for home page for alt server" + }, + { + "file_path" : "src-alt/localhost/style.css", + "inventory_order" : 4000000000, + "OK_to_edit" : true, + "display_as" : "css", + "display_via_github" : true, + "entry_text" : "CSS for home page for alt server" + }, + { + "file_path" : "src-alt/localhost/test/perl/yahoo-ticker.pl.in", + "inventory_order" : 4000000000, + "OK_to_edit" : true, + "display_as" : "perl", + "display_via_github" : true, + "entry_text" : "stock price fetch declarations for alt server" + }, + { + "file_path" : "src-alt/localhost/test/php/Date.php", + "inventory_order" : 4000000000, + "OK_to_edit" : true, + "display_as" : "php", + "display_via_github" : true, + "entry_text" : "PHP example page support file for alt server" + }, + { + "file_path" : "src-alt/localhost/test/php/index_php.in", + "inventory_order" : 4000000000, + "OK_to_edit" : true, + "display_as" : "php", + "display_via_github" : true, + "entry_text" : "PHP example page support file for alt server" + }, + { + "file_path" : "src-alt/localhost/test/php/info.php", + "inventory_order" : 4000000000, + "OK_to_edit" : true, + "display_as" : "php", + "display_via_github" : true, + "entry_text" : "PHP example support file for alt server" + }, + { + "file_path" : "src-alt/localhost/test/php/info.php.in", + "inventory_order" : 4000000000, + "OK_to_edit" : true, + "display_as" : "php", + "display_via_github" : true, + "entry_text" : "PHP example page support file for alt server" + }, + { + "file_path" : "src-alt/localhost/test/php/sendform.html", + "inventory_order" : 4000000000, + "OK_to_edit" : true, + "display_as" : "html", + "display_via_github" : false, + "entry_text" : "php example page support file for alt server" + }, + { + "file_path" : "src-alt/localhost/test/php/sendform.php", + "inventory_order" : 4000000000, + "OK_to_edit" : true, + "display_as" : "php", + "display_via_github" : true, + "entry_text" : "PHP example page support file for alt server" + }, + { + "file_path" : "src-alt/localhost/test/php/sendform.php.in", + "inventory_order" : 4000000000, + "OK_to_edit" : true, + "display_as" : "php", + "display_via_github" : true, + "entry_text" : "PHP example page support file for alt server" + }, + { + "file_path" : "src-alt/localhost/test/ruby/LUHN.rb", + "inventory_order" : 4000000000, + "OK_to_edit" : true, + "display_as" : "ruby", + "display_via_github" : true, + "entry_text" : "ruby example page support file for alt server" + }, + { + "file_path" : "src-alt/localhost/test/ruby/index_rb.in", + "inventory_order" : 4000000000, + "OK_to_edit" : true, + "display_as" : "ruby", + "display_via_github" : true, + "entry_text" : "ruby example page support file for alt server" + }, + { + "file_path" : "src-alt/localhost/test/shell/dump.sh", + "inventory_order" : 4000000000, + "OK_to_edit" : true, + "display_as" : "shellscript", + "display_via_github" : true, + "entry_text" : "POSIX shell script support file for alt server" + }, + { + "file_path" : "src-alt/localhost/test/shell/test1.sh", + "inventory_order" : 4000000000, + "OK_to_edit" : true, + "display_as" : "shellscript", + "display_via_github" : true, + "entry_text" : "POSIX shell script support file for alt server" + }, + { + "file_path" : "src-alt/localhost/test/shell/test2.sh", + "inventory_order" : 4000000000, + "OK_to_edit" : true, + "display_as" : "shellscript", + "display_via_github" : true, + "entry_text" : "POSIX shell script support file for alt server" + }, + { + "file_path" : "src-alt/makefile.in", + "inventory_order" : 4000000000, + "OK_to_edit" : true, + "display_as" : "man", + "display_via_github" : true, + "entry_text" : "makefile template for alt server" + }, { "file_path" : "src/localhost/Img/cygwin-icon.gif", "inventory_order" : 4000000000, diff --git a/2004/hibachi/.gitignore b/2004/hibachi/.gitignore index bcb5fc5d3c..46f0de5a30 100644 --- a/2004/hibachi/.gitignore +++ b/2004/hibachi/.gitignore @@ -2,6 +2,7 @@ # sort with: ../../bin/sgi.sh *.dSYM build +build-alt hibachi.orig indent indent.c @@ -12,3 +13,9 @@ src/config.status src/hibachi src/hibachi.c src/makefile +src-alt/config.log +src-alt/config.status +src-alt/hibachi +src-alt/hibachi.alt +src-alt/hibachi.alt.c +src-alt/makefile diff --git a/2004/hibachi/Makefile b/2004/hibachi/Makefile index aae938c8d0..c8e48aa4e8 100644 --- a/2004/hibachi/Makefile +++ b/2004/hibachi/Makefile @@ -116,8 +116,8 @@ OBJ= ${PROG}.o DATA= TARGET= build/${PROG} # -ALT_OBJ= -ALT_TARGET= +ALT_OBJ= ${PROG}.alt.o +ALT_TARGET= build-alt/${PROG}.alt ################# @@ -150,6 +150,20 @@ src/hibachi.c: hibachi.c alt: data ${ALT_TARGET} @${TRUE} +build-alt/${PROG}.alt: src-alt/hibachi.alt.c src-alt + ${RM} -rf build-alt + ${CP} -v -r src-alt build-alt + @echo "This next step may take some time to complete:" + cd build-alt; CFLAGS="${CSTD} ${CWARN} ${ARCH} ${CDEFINE} ${CINCLUDE} ${OPT}" \ + LDFLAGS="${LDFLAGS}" \ + CC="${CC}" \ + ${SHELL} ./configure + cd build-alt; ${MAKE} + +src-alt/hibachi.alt.c: hibachi.alt.c + ${CP} -f -v $? $@ + + # data files # data: ${DATA} @@ -216,9 +230,9 @@ clean: clobber: clean ${RM} -f ${TARGET} ${ALT_TARGET} - ${RM} -f src/hibachi.c src/config.log + ${RM} -f src/hibachi.c src/config.log src-alt/hibachi.c src-alt/hibachi.c ${RM} -rf *.dSYM - ${RM} -rf build + ${RM} -rf build build-alt @-if [ -e sandwich ]; then \ ${RM} -f sandwich; \ echo 'ate sandwich'; \ diff --git a/2004/hibachi/README.md b/2004/hibachi/README.md index d92d3ddcda..3b2200e92f 100644 --- a/2004/hibachi/README.md +++ b/2004/hibachi/README.md @@ -4,6 +4,9 @@ make ``` +There is an alternate version that is unobfuscated, provided by the author in +2024\. See [Alternate code](#alternate-code) below. + ## To use: @@ -18,6 +21,32 @@ NOTE: you must be in the `build` directory when running `hibachi-start.sh` for this to work right. +## Alternate code: + +This version, contained in `src-alt/`, is an unobfuscated version provided by +the author in 2024. + + +### Alternate build: + +``` + make alt +``` + +This will run the `configure` script and then compile and link in (in +`build-alt/`) the binary `hibachi`. + + +### Alternate use: + +``` + cd build-alt ; ./hibachi-start.sh & +``` + +Then with your browser do the same as for the original source. + + + ## Judges' remarks: This entry violates the [guidelines](../../2004/guidelines.txt) in so many ways! We diff --git a/2004/hibachi/hibachi.alt.c b/2004/hibachi/hibachi.alt.c new file mode 100644 index 0000000000..59b70604c5 --- /dev/null +++ b/2004/hibachi/hibachi.alt.c @@ -0,0 +1,458 @@ +/* + * hibachi.c + * + * Limited implementation of RFC 2616 & CGI/1.1 specification. + * + * Public Domain 2002, 2004 by Anthony Howe. + * + * From http://eat.epicurious.com/dictionary/food/index.ssf?DEF_ID=2150 + * + * [hih-BAH-chee] + * + * Japanese for "fire bowl", a hibachi is just that - a small + * (generally cast-iron) container made for holding fuel + * (usually charcoal). A grill that sits on top of the bowl + * is used to cook various foods. Hibachis come in square, + * oblong and round models. Because of their compact size, + * they're completely portable. + * + * Usage: SERVER_PORT= DOCUMENT_ROOT= hibachi + */ + +#define NDEBUG + +/*********************************************************************** + *** No configuration below this point. + ***********************************************************************/ + +#include +#include +#include +#include +#include +/* #include */ +#include +#include +#include +#include +#include +#include +#include + +#define Z 8192 + +FILE *LOG; + +char request[Z], query[Z], path[Z], droot[Z], *headers, *notfound = "404 Not Found", *error = "500 Error"; + +void +status(int client, char *u, long j) +{ + j = snprintf( + query, Z, +/* "HTTP/1.0 %s\r\nConnection: close\r\nContent-Length: %ld\r\n\r\n%s", */ + "HTTP/1.0 %s\r\nContent-Length: %ld\r\n\r\n%s", + u, j != 0 ? j : strcspn(u, ""), j != 0 ? "" : u + ); + (void) fprintf(LOG, "[%d] status length=%ld\n%s\n", getpid(), j, query); + send(client, query, j, 0); +} + +void +findAndSet(char *i, char *j) +{ + char *u; + + /* `i' is both a header name and an environment variable. Add +5 + * to `i' in order to skip over `HTTP_' metavariable prefix. This + * doesn't interfer with the search for other headers that don't + * have an `HTTP_' prefix like `CONTENT_TYPE' and `CONTENT_LENGTH', + * because there is sufficiently enough of the header string left + * that is unique for the purpose of searching. + */ + if ((u = strstr(headers, i + 5)) != (char *) 0) + sscanf(u + strcspn(u, ":") + 1, j, getenv(i)); + (void) fprintf(LOG, "[%d] %s=%s\n", getpid(), i, getenv(i)); +} + +int +main(int argc, char **argv) +{ + int fd, client, i; + struct stat finfo; + struct sockaddr_in addr; + char *value, *uri; + + if ((LOG = fopen("hibachi.log", "a")) == (FILE *) 0) + return 1; + + if ((value = getenv("SERVER_PORT")) == (char *) 0) { + (void) fprintf(LOG, "[%d] SERVER_PORT not defined in environment\n", getpid()); + return 4; + } + + i = (int) strtol(value, NULL, 10); + addr.sin_addr.s_addr = htonl(INADDR_ANY); + addr.sin_port = htons((unsigned short) i); + addr.sin_family = AF_INET; + + if ((fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) { + (void) fprintf(LOG, "[%d] failed to create socket\n", getpid()); + return 5; + } + + if (0 > bind(fd, /*(const struct sockaddr *) */ (void *) &addr, sizeof addr)) { + (void) fprintf(LOG, "[%d] failed to bind to port\n", getpid()); + return 6; + } + + if (0 > listen(fd, 10)) { + (void) fprintf(LOG, "[%d] failed to listen on port\n", getpid()); + return 7; + } + + (void) fprintf(LOG, "[%d] listening on port %s\n", getpid(), value); + + /* Use "kill" to terminate the parent server process. */ + for ( ; ; close(client)) { + /* Reap zombie child processes. */ + for ( ; waitpid(0, NULL, WNOHANG) > 0; ) + ; + + i = sizeof addr; + if ((client = accept(fd, /*(const struct sockaddr *) */ (void *) &addr, &i)) < 0) + continue; + +#ifdef NDEBUG + /* SunOS technique to avoid zombie processes. */ +/* signal(SIGCHLD, SIG_IGN); */ + + if (fork() != 0) + /* The parent can close the client connection on + * success to avoid leaking file handles and on + * error to refuse the client connection. + * + * Refuse the connection, RFC 2616 section 10.5.4 +---- +10.5.4 503 Service Unavailable + + The server is currently unable to handle the request due to a + temporary overloading or maintenance of the server. The implication + is that this is a temporary condition which will be alleviated after + some delay. If known, the length of the delay MAY be indicated in a + Retry-After header. If no Retry-After is given, the client SHOULD + handle the response as it would for a 500 response. + + Note: The existence of the 503 status code does not imply that a + server must use it when becoming overloaded. Some servers may wish + to simply refuse the connection. +---- + * Here we interpret "refuse the connection" as + * drop it without giving a reason. Amounts to + * the same. + */ + continue; + + /****************************************************** + *** Child process. + ******************************************************/ + + /* The child doesn't need a copy of the server port. */ +/* close(fd); */ +#endif + + /* Read request and headers. Stop if we see two newlines. */ + for (fd = i = 0; fd < 2 && i < Z; i++) { + if (recv(client, request + i, 1, 0) <= 0) + /* On error, drop the connection hard. */ + return 1; + + /* The HTTP protocol states that the header names + * are case insensitive. Most browsers send them + * exactly as shown in RFC 2616 (capitial letters + * for first letter of each word), but Lynx doesn't + * For example "Content-Length" is sent by Lynx as + * "Content-length". This section of code converts + * the header names to one case for matching. + */ + if (request[i] == '\n') + /* Count newlines AND lower case of header. */ + fd++; + if (request[i] == ':') + /* Don't touch header value. Doesn't work + * for headers spanning multiple lines. Rare. + */ + fd = 0; + if (fd != 0) + /* RFC 2616 BNF grammar for header field-name + * is defined to use the US-ASCII character set. + * However, we can't do "request[i] | 0x20" to + * fold uppper to lower case without testing + * to see if it is an alpha character. + */ + request[i] = request[i] == '-' ? '_' : toupper(request[i]); + } + + if (Z <= i) + /* Request buffer overflow, drop the connection. + * The request buffer should be large enough to + * hold all the headers and one full size Cookie. + * Cookies have a max. length of 4096 bytes. + * + * We really should return a 413, 500, or 503 error + * here. The fact that the buffer is full is like an + * "overloaded" server, so we take the shortcut + * offered by RFC 2616 section 10.5.4 paragraph 2. + */ + break; + + request[i] = '\0'; + (void) fprintf(LOG, "[%d] %s\n", getpid(), request); + + /* Identify the method by testing just one + * character position of the method name: + * + * OPTIONS O + * GET G + * HEAD H + * POST S + * PUT U + * DELETE D + * TRACE T + * CONNECT C + * + * Also make sure the request is NOT a + * proxy request. + */ + if (request[0] != 'G' && request[0] != 'H' && request[2] != 'S') { + (void) fprintf(LOG, "[%d] 501 Method not implemented\n", getpid()); + status(client, "501 Unsupported", 0); + break; + } + + /* Determine document root for the virtual host. */ + *path = '\0'; + if ((value = strstr(request, "HOST:")) != (char *) 0) + sscanf(value+5, " %255[^:\r\n]", path); + + snprintf(droot, Z, "DOCUMENT_ROOT" "=%s/%s", getenv("DOCUMENT_ROOT"), path); + (void) fprintf(LOG, "[%d] %s\n", getpid(), droot); + putenv(droot); +/* chdir(droot+14); */ + + /* Parse the request "METHOD /uri/pathinfo?query HTTP/1.1" */ + uri = request + 4 + (request[0] != 'G'); + + /* Disallow relative paths. A chroot() would be more + * effective, but that requires root privileges and is + * against IOCCC contest rules. + * + * NOTE that URI decoding of the path has NOT been + * performed, so paths with sequences like "%2e%2e%2f" + * won't be caught, but will fail below on the stat() + * and return a 404. + * + * We do not decode the URI path partly because of contest + * space issues, but there really is no good reason to + * encode characters that don't need an encoding, like dot + * and slash. Sites that use stupid characters in file paths + * and names like spaces, special punctuation, and accented + * characters deserve the trouble they get from such practices. + */ + if (*uri != '/' || strstr(uri, "../") != (char *) 0) { + (void) fprintf(LOG, "[%d] 403 Relative pathes and proxy requests forbidden [%s]\n", getpid(), uri); + /* RFC 2616 section 10.4.4 403 Forbidden: +---- +10.4.4 403 Forbidden + + The server understood the request, but is refusing to fulfill it. + Authorization will not help and the request SHOULD NOT be repeated. + If the request method was not HEAD and the server wishes to make + public why the request has not been fulfilled, it SHOULD describe the + reason for the refusal in the entity. If the server does not wish to + make this information available to the client, the status code 404 + (Not Found) can be used instead. +---- + * The last sentence is significant here. + */ + status(client, notfound, 0); + break; + } + + /* End of request URI on space delimiter. */ + uri[i = strcspn(uri, " ")] = '\0'; + headers = uri + i + 1; + + /* Find end of URI or query delimiter. */ + i = strcspn(uri, "?"); + if (uri[i] != '\0') { + snprintf(query, Z, "QUERY_STRING=%s", uri+i+1); + (void) fprintf(LOG, "[%d] %s\n", getpid(), query); + putenv(query); + uri[i] = '\0'; + } + + /* Prepare SCRIPT_FILENAME. This variable is required by + * PHP/CGI in order to find the input file. PHP/CLI does + * not require it and is more like nph-CGI behaviour, but + * is sufficiently different from typical web usage to + * confuse webmasters. + * + * Use the value after the equals sign to test for file + * or directory existance (path+16). + */ + snprintf(path, Z, "SCRIPT_FILENAME=%s%s", droot+14, uri); + (void) fprintf(LOG, "[%d] %s\n", getpid(), path); + value = path+16; + (void) fprintf(LOG, "[%d] %s\n", getpid(), value); + + if (stat(value, &finfo) < 0) { + (void) fprintf(LOG, "[%d] 404 File or directory %s does exist\n", getpid(), value); + status(client, notfound, 0); + break; + } + + /* When a directory, look for the "index" file. */ + if (S_ISDIR(finfo.st_mode)) { + struct dirent *d; + DIR *D = opendir(value); + for ( ; (d = readdir(D)) != (struct dirent *) 0; ) { + if (0 == strncmp(d->d_name, "index.", 6)) { + strncat(value, d->d_name, Z-16); + stat(value, &finfo); + break; + } + } + closedir(D); + + if (d == (struct dirent *) 0) { + /* We don't print directory listings. */ + (void) fprintf(LOG, "[%d] 404 Directory listing forbidden\n", getpid()); + /* RFC 2616 section 10.4.4 403 Forbidden, last sentence. */ + status(client, notfound, 0); + break; + } + (void) fprintf(LOG, "[%d] path=%s\n", getpid(), value); + } + + if (request[0] != 'H') { + (void) fprintf(LOG, "[%d] mode=%o\n", getpid(), finfo.st_mode); + if (finfo.st_mode & 0111) { + /* Execute CGI, which is responsible for sending + * back the HTTP response line and headers (see + * CGI/1.1 specification "nph" prefix). + */ + + /* Pass some of the request headers to the CGI. + * Overwrite in place the environment variables + * preallocated in the environment (see + * hibachi-start.sh). + */ + + putenv(path); + + /* Need this to identify type of request. */ + sscanf(request, "%4s", getenv("REQUEST_METHOD")); + (void) fprintf(LOG, "[%d] REQUEST_METHOD='%s'\n", getpid(), getenv("REQUEST_METHOD")); + + /* Not sure we need this for most CGIs. */ + sscanf(inet_ntoa(addr.sin_addr), "%15s", getenv("REMOTE_ADDR")); + (void) fprintf(LOG, "[%d] REMOTE_ADDR=%s\n", getpid(), getenv("REMOTE_ADDR")); + + /* These are needed if the CGI is to do anything + * useful. + */ + findAndSet("HTTP_COOKIE", "%*[ \t]%80[^\r\n]"); + findAndSet("CONTENT_LENGTH", "%20s"); + findAndSet("CONTENT_TYPE", "%60s"); + + /* Redirect standard I/O for the CGI. */ + dup2(client, 0); + dup2(client, 1); + + /* Call system() instead of execl() so that + * we come back here after the CGI call to + * properly close the connection. We don't + * need to escape shell meta characters, + * since the stat() above would have failed + * to find a file that did contained them. + * + * Of course anyone stupid enough to use + * shell meta characters for an executable + * filename should be shot. + */ + + /* Note that Cygwin appears to have a bogus + * initial \r\n waiting on stdin, which was + * never sent by the client. I've seen this + * in other programs under Cygwin. + */ + if (system(value) != 0) + status(client, error, 0); + break; + } + + if ((fd = open(value, O_RDONLY)) < 0) { + (void) fprintf(LOG, "[%d] 500 Internal server error\n", getpid()); + status(client, error, 0); + break; + } + } + + /* RFC 2616 section 7.2.1 paragraph 3 allows the Content-Type + * to be optional leaving the client to figure it out. +---- + Any HTTP/1.1 message containing an entity-body SHOULD include a + Content-Type header field defining the media type of that body. If + and only if the media type is not given by a Content-Type field, the + recipient MAY attempt to guess the media type via inspection of its + content and/or the name extension(s) of the URI used to identify the + resource. If the media type remains unknown, the recipient SHOULD + treat it as type "application/octet-stream". +---- + * RFC 2119 defines SHOULD as strongly recommended, but not + * absolutely required given sufficient reason. I treat it + * more like OPTIONAL. + */ + + status(client, "200 OK", finfo.st_size); + (void) fprintf(LOG, "[%d] %s\n", getpid(), query); + + if (request[0] != 'H') { + /* Send back a static file for GET or POST request. + * + * There may be input ready for a POST request, but + * it doesn't make any sense to read input and waste + * bandwidth for a non-CGI. + * + * Also RFC 2616 section 4.3 paragraph 4 makes reading + * a message body optional: +---- + The presence of a message-body in a request is signaled by the + inclusion of a Content-Length or Transfer-Encoding header field in + the request's message-headers. A message-body MUST NOT be included in + a request if the specification of the request method (section 5.1.1) + does not allow sending an entity-body in requests. A server SHOULD + read and forward a message-body on any request; if the request method + does not include defined semantics for an entity-body, then the + message-body SHOULD be ignored when handling the request. +---- + * RFC 2119 defines SHOULD as strongly recommended, but not + * absolutely required given sufficient reason. I treat it + * more like OPTIONAL. + */ + for ( ; 0 < (i = read(fd, request, Z)); ) + send(client, request, i, 0); + } +/* close(fd); */ + break; + } + + /* Clean termination of the TCP connection from our end. */ + shutdown(client, SHUT_WR); +/* close(client); */ + + (void) fprintf(LOG, "[%d] end child\n\n", getpid()); + + return 0; +} diff --git a/2004/hibachi/hibachi.c b/2004/hibachi/hibachi.c index e0fac7a0f8..3eeeda176f 100644 --- a/2004/hibachi/hibachi.c +++ b/2004/hibachi/hibachi.c @@ -10,13 +10,13 @@ #include #include #include +#include #include #include #include #include #include #include -#include #define Z 8192 char r[Z], q[Z], l[Z], w[Z], *o, *m = "404 Not Found", *e = "500 Error"; void @@ -43,6 +43,7 @@ main(int c, char **p) struct stat g; struct sockaddr_in a; char *v, *u; + R 1; Q (v = V "SERVER_PORT")) == 0) { R 4; } diff --git a/2004/hibachi/index.html b/2004/hibachi/index.html index 8dfc117a9a..8f8d986ee3 100644 --- a/2004/hibachi/index.html +++ b/2004/hibachi/index.html @@ -403,12 +403,24 @@

Author:

To build:

    make
+

There is an alternate version that is unobfuscated, provided by the author in +2024. See Alternate code below.

To use:

    cd build; ./hibachi-start.sh &

Then use your web browser to visit http://localhost:8008/. When you’re finished make sure to kill hibachi.

NOTE: you must be in the build directory when running hibachi-start.sh for this to work right.

+

Alternate code:

+

This version, contained in src-alt/, is an unobfuscated version provided by +the author in 2024.

+

Alternate build:

+
    make alt
+

This will run the configure script and then compile and link in (in +build-alt/) the binary hibachi.

+

Alternate use:

+
    cd build-alt ; ./hibachi-start.sh &
+

Then with your browser do the same as for the original source.

Judges’ remarks:

This entry violates the guidelines in so many ways! We are not exactly sure how many organisations will be upset with this entry, but @@ -534,19 +546,35 @@

Inventory for 2004/hibachi

Primary files