Compare commits

...

43 Commits

Author SHA1 Message Date
Neale Pickett 16e32a6d59 break-fnord.sh work with busybox expr 2024-01-02 11:09:02 -07:00
Neale Pickett 49b1797df5
Merge pull request #2 from vaerksted/master
fix punctuation and typo; fixes #1
2022-12-15 16:01:05 -07:00
musvaage ce6b071398 punctuation and typo 2022-12-15 11:00:04 -06:00
Neale Pickett 2acfd4cf2d fnord 1.11 has all the same bugs 2020-12-07 14:06:23 -07:00
Neale Pickett d524cc02d5 Make github prettier 2018-09-14 16:17:30 +00:00
Neale Pickett 2e1a3eb867 Expose port 80 in dockerfile 2017-09-11 02:26:51 +00:00
Neale Pickett 48dbc0e8e0 Dockerize 2017-09-11 01:48:41 +00:00
Neale Pickett 673aed81a2 Modify dwarf planet link in README, so it's easier for humans to parse 2017-08-13 17:13:37 +00:00
Neale Pickett 855815099a Remove unused const days, months 2017-08-06 01:38:25 +00:00
Neale Pickett f63b3f1732 Version bump 2015-02-26 16:08:45 -07:00
Neale Pickett 6dd03561d6 Add stunnel logging test (duh) 2015-02-26 16:08:05 -07:00
Neale Pickett 48bb066488 Haha, I was generating that variable 2015-02-26 16:06:13 -07:00
Neale Pickett 77c3ed33dd Better way to do stunnel addr 2015-02-26 16:04:43 -07:00
Neale Pickett 86a75813e3 Use stunnel-provided combined addr 2015-02-26 16:01:56 -07:00
Neale Pickett c3ddfae1ff 2nd pass at stunnel vars 2015-02-26 15:59:51 -07:00
Neale Pickett bdb9f0ac05 Merge branch 'master' of woozle.org:projects/net/eris 2015-02-26 15:47:44 -07:00
Neale Pickett b3c4786482 Also work with stunnel 2015-02-26 15:47:37 -07:00
Neale Pickett 9de87a3e36 Add .webm 2014-12-19 22:45:18 +00:00
Neale Pickett ecad076ec6 Fix regression test 2014-12-08 14:37:54 -07:00
Neale Pickett 86757101eb Super dumb CONNECT handling 2014-12-08 14:26:48 -07:00
Neale Pickett 68452c56fa Tabify 2014-11-19 23:50:26 +00:00
Neale Pickett aab1b7496b Update to reflect ancient sslio 2014-11-19 23:49:48 +00:00
Neale Pickett 6121939bf0 Merge branch 'master' of /home/neale/projects/net/eris 2014-10-25 04:27:38 +00:00
Neale Pickett 7a4ac95441 Output blank line in badrequest 2014-10-25 04:27:21 +00:00
Neale Pickett 76c46f481e Oops, unrenamed a variable 2014-06-23 16:17:55 -06:00
Neale Pickett c329e9ad8a A couple bugfixes 2014-06-23 16:15:32 -06:00
Neale Pickett 8cb25b363d We do not do NPH either 2014-06-23 13:33:35 -06:00
Neale Pickett 502347d9df Oops, we do not do Accept 2014-06-23 13:29:44 -06:00
Neale Pickett 0b4f892169 More README expansion 2014-03-11 18:03:43 +00:00
Neale Pickett 297d6ec919 Describe Eris 2014-03-11 17:49:35 +00:00
Neale Pickett c968d41b16 Updated README 2014-03-11 17:39:36 +00:00
Neale Pickett eb9de7b610 Fix 0.9 not detected with query_string 2013-02-14 16:39:14 -07:00
Neale Pickett 4e2e46dfdb change strncpy to snprintf, in case PATH_MAX is ridiculously small 2013-02-11 12:15:52 -07:00
Neale Pickett 4b54e2b2f3 Fix merge fail 2013-02-11 11:28:56 -07:00
Neale Pickett e46094d637 Merge branch 'master' of fozzie:projects/eris
Conflicts:
	CHANGES
	eris.c
2013-02-11 11:09:19 -07:00
Neale Pickett d70528481f Proper credit in changelog 2013-02-11 11:04:49 -07:00
Neale Pickett 90660eae48 Fix directory traversal bug 2013-02-11 10:59:16 -07:00
Neale Pickett 78dec35acd Log on 304 2012-12-09 15:12:14 -07:00
Neale Pickett 47ab2f0833 Update changelog 2012-11-07 19:30:33 -07:00
Neale Pickett 1edc4dff77 Log directory indexes, add webfs script 2012-11-07 19:23:28 -07:00
Neale Pickett 747cd86e65 Remove -a option, add contrib directory
There wasn't actually any authentication code in eris.c.  I'll add it
back in if anybody asks.
2012-11-07 18:45:42 -07:00
Neale Pickett c73f0b6d0d Version bump 2012-10-30 19:15:49 -06:00
Neale Pickett b9d6c8ce98 Quit needing CFLAGS 2012-10-30 19:10:55 -06:00
16 changed files with 1265 additions and 929 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*.o
version.h

257
CHANGES
View File

@ -1,140 +1,175 @@
fix punctuation and typo
4.4:
Also log when called from stunnel
4.3.1:
Add .webm mime type
4.3:
Very stupid CONNECT handling mechanism.
4.2:
Remove some bugs in CGI's "Status:" code (reported by Alyssa Milburn).
Make extract_header_field less fragile (reported by Alyssa Milburn).
Possibly fix fake_sendfile (reported by Alyssa Milburn).
4.1:
Fix 0.9 not detected with query_string (Alyssa Milburn).
4.0:
Fix directory traversal vulnerability (Alyssa Milburn).
3.1.4:
Have 304 (Not Modified) responses generate a log entry.
3.1.3:
Have directory indexes generate a log entry.
Remove nop -a option.
Add some accessories in contrib/
3.1.2:
Change how version is extracted from CHANGES, to deal with
build systems that set CFLAGS.
Stop hating Ryan Finnie.
3.1.1:
Restructured code to make it easier to package for Debian.
I hate you so much right now, Ryan.
Restructure code to make it easier to package for Debian.
I hate you so much right now, Ryan Finnie.
3.1:
Add -. flag to disable vhosting
Support server push CGI
Handle busybox tcpsvd
Changed formatting of directory indexing
Handle read timeout
Fix if-modified-since bug with keepalive connections
Change to CGI's directory on exec
Add -. flag to disable vhosting
Support server push CGI
Handle busybox tcpsvd
Changed formatting of directory indexing
Handle read timeout
Fix if-modified-since bug with keepalive connections
Change to CGI's directory on exec
3.0:
More or less a ground-up rewrite. A few fnord parts remain
here and there.
More or less a ground-up rewrite. A few fnord parts remain
here and there.
2.0:
Replace poll with select, which is more portable and may be
slightly faster; however, it's only called for CGI and by
that point you've lost quite a bit in terms of speed
Remove Accept header parsing: it was broken and the result was
that the Accept header had no effect
Remove the .gz trick: I never used it, but I would not be averse
to adding it back if people liked it
Rename to "eris httpd" to acknowledge fork
Add regression test suite
Replace compile-time options with command-line ones
Fix segfault with directory listing of /
Replace buffer_1 and buffer_2 with stdio
Replace libowfat with libc
Add all patches from (defunct) Debian package
Fix if-modified-since date parsing
Make text content-types use charset=UTF-8
Change default content-type to application/octet-stream
Makefile no longer overrides CC and CPP from parent makes
Don't send Content-type if there's no content
New maintainer: Neale Pickett <neale@woozle.org>
Replace poll with select, which is more portable and may be
slightly faster; however, it's only called for CGI and by
that point you've lost quite a bit in terms of speed
Remove Accept header parsing: it was broken and the result was
that the Accept header had no effect
Remove the .gz trick: I never used it, but I would not be averse
to adding it back if people liked it
Rename to "eris httpd" to acknowledge fork
Add regression test suite
Replace compile-time options with command-line ones
Fix segfault with directory listing of /
Replace buffer_1 and buffer_2 with stdio
Replace libowfat with libc
Add all patches from (defunct) Debian package
Fix if-modified-since date parsing
Make text content-types use charset=UTF-8
Change default content-type to application/octet-stream
Makefile no longer overrides CC and CPP from parent makes
Don't send Content-type if there's no content
New maintainer: Neale Pickett <neale@woozle.org>
1.10:
have fallback in case sendfile fails
have fallback in case sendfile fails
1.9:
chdir to cgi's base dir (Kuba Winnicki)
set HTTP_ACCEPT_ENCODING environment variable (Kuba Winnicki)
We actually should export all HTTP headers as HTTP_[header]
Any takers?
Try not to send error message HTTP headers if we already sent the
headers from the CGI (Kuba Winnicki)
<ims -> <=ims (Gerrit Pape)
64-bit file I/O cleanliness
fix HTTP ranges (Joachim Berdal Haga via Gerrit Pape)
chdir to cgi's base dir (Kuba Winnicki)
set HTTP_ACCEPT_ENCODING environment variable (Kuba Winnicki)
We actually should export all HTTP headers as HTTP_[header]
Any takers?
Try not to send error message HTTP headers if we already sent the
headers from the CGI (Kuba Winnicki)
<ims -> <=ims (Gerrit Pape)
64-bit file I/O cleanliness
fix HTTP ranges (Joachim Berdal Haga via Gerrit Pape)
1.8:
keep current environment in CGI (Laurent Bercot)
make fnord-conf use the UID and not the user name (Fridtjof Busse)
fix typo in buffer_putulonglong (Gerrit Pape)
fix CGI POST off-by-two typo (Mark Hopf)
fix gif->png conversion (Thomas Seck)
remove == bashism from fnord-conf (Thomas Seck)
add bittorrent mime type
make authorization data available to CGIs for GET, too (Paul Jarc)
fix conversion of host name to lower case (Gerrit Pape)
add small test cgi: cgi-post.c
fix CGI POST bug (Moe Wibble)
fix CGI PATH_TRANSLATED bug (Nicolas George)
add optional authentication support (Nicolas George, see README.auth)
make sure error messages are text/html
move /. -> /: conversion before demangling so it can actually be
used as security measure for installations that don't use chroot
keep current environment in CGI (Laurent Bercot)
make fnord-conf use the UID and not the user name (Fridtjof Busse)
fix typo in buffer_putulonglong (Gerrit Pape)
fix CGI POST off-by-two typo (Mark Hopf)
fix gif->png conversion (Thomas Seck)
remove == bashism from fnord-conf (Thomas Seck)
add bittorrent mime type
make authorization data available to CGIs for GET, too (Paul Jarc)
fix conversion of host name to lower case (Gerrit Pape)
add small test cgi: cgi-post.c
fix CGI POST bug (Moe Wibble)
fix CGI PATH_TRANSLATED bug (Nicolas George)
add optional authentication support (Nicolas George, see README.auth)
make sure error messages are text/html
move /. -> /: conversion before demangling so it can actually be
used as security measure for installations that don't use chroot
1.7:
add .mov and .qt for quicktime, .mpg for video/mpeg and .wav for audio/x-wav
add mmap based file serving (should do zero-copy tcp just like sendfile)
add Pragma: no-cache to CGI responses
fix (apparently not exploitable) buffer overrun in do_cgi
This bug was found by Ralf Wildenhues. To my knowledge it is
impossible to exploit this bug on any platform known to me.
fix (harmless) access to uninitialized data
add .mov and .qt for quicktime, .mpg for video/mpeg and .wav for audio/x-wav
add mmap based file serving (should do zero-copy tcp just like sendfile)
add Pragma: no-cache to CGI responses
fix (apparently not exploitable) buffer overrun in do_cgi
This bug was found by Ralf Wildenhues. To my knowledge it is
impossible to exploit this bug on any platform known to me.
fix (harmless) access to uninitialized data
1.6:
add support for $PATH_INFO in CGI environment.
add .pac for netscape proxy autoconfig
add .sig for application/pgp-signature
add support for $PATH_INFO in CGI environment.
add .pac for netscape proxy autoconfig
add .sig for application/pgp-signature
1.5:
fix write timeout handling (found by Lukas Beeler)
fix fnord-conf to use the symbolic account name in run script
(Sebastian D.B. Krause)
fix write timeout handling (found by Lukas Beeler)
fix fnord-conf to use the symbolic account name in run script
(Sebastian D.B. Krause)
1.4:
add dangling symlink based whole-host redirection (see README). This
has the advantage that it can serve normal sites and redirect sites
on the same IP.
add support for non-TCP UCSPI environments (like ucspi-ssl). Please
get the latest version of my ucspi-tcp IPv6 patch as I violated the
UCSPI spec with all versions before 0.88-diff11.
change logging from "127.0.0.1 200 23 Links_(0.96;_Unix) none /index.html"
to "127.0.0.1 200 23 localhost Links_(0.96;_Unix) none /index.html"
(i.e. include the Host: header). Suggested by Thomas Bader.
add "immediate mode". If you give fnord a command line argument, it
will change to that directory and if no "default" directory is
given, it will assume there are no virtual hosts and serve from the
current directory. I have a shell script called "http" that does
tcpserver -RHl localhost 0 8000 /home/leitner/bin/fnord-idx .
to share some directory on my hard drive with some poor Windows
users without npoll (http://www.fefe.de/ncp/). fnord-idx is a new
target (a fnord with DIR_LIST) that is auto-built by make.
add dangling symlink based whole-host redirection (see README). This
has the advantage that it can serve normal sites and redirect sites
on the same IP.
add support for non-TCP UCSPI environments (like ucspi-ssl). Please
get the latest version of my ucspi-tcp IPv6 patch as I violated the
UCSPI spec with all versions before 0.88-diff11.
change logging from "127.0.0.1 200 23 Links_(0.96;_Unix) none /index.html"
to "127.0.0.1 200 23 localhost Links_(0.96;_Unix) none /index.html"
(i.e. include the Host: header). Suggested by Thomas Bader.
add "immediate mode". If you give fnord a command line argument, it
will change to that directory and if no "default" directory is
given, it will assume there are no virtual hosts and serve from the
current directory. I have a shell script called "http" that does
tcpserver -RHl localhost 0 8000 /home/leitner/bin/fnord-idx .
to share some directory on my hard drive with some poor Windows
users without npoll (http://www.fefe.de/ncp/). fnord-idx is a new
target (a fnord with DIR_LIST) that is auto-built by make.
1.3:
make directory listings use non-proportional fonts (thanks, Antonio Dias)
fnord will now optionally (default: enabled) normalize the incoming
host name, i.e. "www.domain.com" -> "www.domain.com:80". That
should cut down on the number of symbolic links. ;)
remove timeout error message. fnord will not drop the connection
without error message. Mozilla used to display the error message
when the user caused another request on the connection with the
timeout.
Uwe Ohse found two more compilation problems.
make directory listings use non-proportional fonts (thanks, Antonio Dias)
fnord will now optionally (default: enabled) normalize the incoming
host name, i.e. "www.domain.com" -> "www.domain.com:80". That
should cut down on the number of symbolic links. ;)
remove timeout error message. fnord will not drop the connection
without error message. Mozilla used to display the error message
when the user caused another request on the connection with the
timeout.
Uwe Ohse found two more compilation problems.
1.2:
Olaf: I changed my initial CGI-interface to NOT use the filesystem but
two pipes.
Add whole-host redirect (see README)
Olaf: added direcory-lists and "index.cgi" support (normal CGI only !
"nph-index.cgi" is not supported). Fixed some problematic parts in the
CGI-interface (\n -> \r\n converter for http-header and CGI crash
handling)
Fix gzip encoding bug that only happened with keep-alive
Olaf: I changed my initial CGI-interface to NOT use the filesystem but
two pipes.
Add whole-host redirect (see README)
Olaf: added directory-lists and "index.cgi" support (normal CGI only !
"nph-index.cgi" is not supported). Fixed some problematic parts in the
CGI-interface (\n -> \r\n converter for http-header and CGI crash
handling)
Fix gzip encoding bug that only happened with keep-alive
1.1:
ship with the parts from libowfat that we actually use
minor speed-up. sendfile is a drag for very small files, so those are
now sent through the same buffer the header is sent through. That
sends the whole answer in one TCP packet if you are lucky, even
without the TCP_CORK magic from Linux. Major speed-up for
benchmarks ;)
ship with the parts from libowfat that we actually use
minor speed-up. sendfile is a drag for very small files, so those are
now sent through the same buffer the header is sent through. That
sends the whole answer in one TCP packet if you are lucky, even
without the TCP_CORK magic from Linux. Major speed-up for
benchmarks ;)
1.0:
initial release
initial release

21
Dockerfile Normal file
View File

@ -0,0 +1,21 @@
FROM alpine
RUN apk --no-cache add s6-networking
RUN apk --no-cache add build-base
COPY . /usr/local/src/eris
RUN make -C /usr/local/src/eris
RUN cp /usr/local/src/eris/eris /usr/bin
RUN rm -rf /usr/local/src/eris
RUN apk --no-cache del build-base
RUN addgroup -S -g 800 www
RUN adduser -S -u 800 -G www www
RUN mkdir /www
WORKDIR /www
EXPOSE 80
CMD ["s6-tcpserver", "-u", "80", "-g", "80", "0.0.0.0", "80", "/usr/bin/eris", "-."]

34
HTTPS.md Normal file
View File

@ -0,0 +1,34 @@
SSL with eris
=============
Eris does not care what transport is in use: that job is left to the invoking
program (e.g. tcpserver).
In the past you could use `sslio` with `tcpsvd`,
but `sslio` has not been updated in a long time,
and won't work with (at least) Chrome 39.
I recommend using stunnel,
which also works with IPv6.
You can invoke it like so:
#! /bin/sh
cd /srv/www
HTTPS=enabled; export HTTPS
exec stunnel -fd 3 3<<EOD
foreground = yes
setuid = http
setgid = http
debug = 4
[https]
accept = ::443
cert = /path/to/yourserver.crt
key = /path/to/yourserver.key
exec = /path/to/eris
execargs = eris -c
EOD
I set the `HTTPS` environment variable,
so CGI can tell whether or not its connection is secure.

View File

@ -1,13 +1,15 @@
VERSION := $(shell head -n 1 CHANGES | tr -d :)
CFLAGS = -DFNORD='"eris/$(VERSION)"' -Wall -Werror
CFLAGS = -Wall -Werror
all: eris
eris: eris.o strings.o mime.o timerfc.o
eris.o: version.h
version.h: CHANGES
awk -F : 'NR==1 {printf("const char *FNORD = \"eris/%s\";\n", $$1);}' $< > $@
test: eris
sh ./test.sh
clean:
rm -f *.[oa] eris
rm -f *.[oa] version.h eris

81
README
View File

@ -1,81 +0,0 @@
Eris HTTPD is a part of Dirtbags Capture The Flag
(http://dirtbags.net/ctf/). As I was adding more and more patches
against fnord 1.10 (http://www.fefe.de/), I decided to fork fnord into
a new project. Fnord's author approved of the fork.
Significant differences between eris and fnord are:
* command-line arguments instead of compile-time defines
* eliminated use of libowfat
* no build dependency of dietlibc
* elimination of "old style symlink handling"
* elimination of user switching (you can use tcpserver -[ug])
* elimination of chroot code (you can use chroot)
* several bugfixes (sent to the fnord mail list)
* ignores Accept header (fnord does too)
----
Usage:
tcpserver -v -RHl localhost -u 1234 -g 1234 0 80 ./httpd
Will log to stderr in the form
127.0.0.1 200 23 localhost Links_(0.96;_Unix) none /index.html
where 127.0.0.1 is the client IP, 200 is the HTTP exit code, 23 is the
size of the content that was served (or 0 for unsuccessful exit codes),
localhost is the Host: header (the virtual host), the next token is the
user agent with spaces replaced by underscores, the next token (none) is
the Referer HTTP header or "none" if none was given, and the rest of
each line is the decoded requested URL.
eris does simple virtual hosting. If the Host: HTTP header is there,
eris will try to chdir to a directory of that name, i.e. if the client
asks for "/" on host "www.fefe.de", eris will look for
"www.fefe.de/index.html". Eris will also try the directory "default"
if no specific directory for the virtual host was there. If the
directory is a dangling symlink, eris will redirect the whole site.
Examples:
lrwxrwxrwx 1 leitner users 19 May 5 01:09 www.foo.de -> http://www.baz.de/
lrwxrwxrwx 1 leitner users 20 May 5 01:12 www.bar.de -> =http://www.baz.de/
http://www.foo.de/blub.html will be redirected to http://www.baz.de/blub.html.
http://www.bar.de/blub.html will be redirected to http://www.baz.de/.
eris implements el-cheapo HTTP ranges (only byte ranges and only of the
form x-y, not multiple ranges).
eris implements content type matching and Accepts: parsing, but the
content type table is compiled in, i.e. to change it, you have to change
the source code. Shouldn't be a problem because you _have_ the source
code ;)
eris implements HTTP redirection. If a file is not found, but a
dangling symlink is there under the same name, eris will issue a
redirection to the contents of that symlink. To be RFC compliant, the
symlink must point to a full URL, i.e.
ln -s ftp://foobar.math.fu-berlin.de/pub/dietlibc/dietlibc-0.11.tar.bz2 dietlibc-0.11.tar.bz2
eris will change dots at the start of file or directory names to colons
in the query before trying to answer them.
eris understands and implements keep-alive connections.
eris will use sendfile on Linux to enable zero-copy TCP.
If eris is given the -a option, it look for a file named ".http-auth"
in the root of the host directory. If it's found, eris will run it as
".http-auth $host $url" with the environment variable
"HTTP_AUTHORIZATION" set to the "Authorization" header sent by the
client. If the program returns 0, access will be granted; if it
returns 1, eris will return a 401 response.
If eris is given the -c option, it will regard files
whose names end with ".cgi" as CGI programs and try to execute them.
CGI programs starting with "nph-" will be handled as no-parse-header
CGIs. Please see http://hoohoo.ncsa.uiuc.edu/cgi/interface.html for the
CGI specification.

105
README.md Normal file
View File

@ -0,0 +1,105 @@
About
=====
Eris is an HTTP/1.1 web server with CGI.
It is very fast,
uses very little memory,
and has a tiny codebase which has been audited at least twice by gray-hat hackers.
It relies on an external program,
such as tcpserver or netcat,
to handle networking,
and expects to be run once for every connection.
This may sound horrible,
but it's actually pretty quick,
especially since this architecture makes it trivial to use the
`sendfile` call in Linux
(added in 2003 as a reaction to Apache losing to IIS in benchmarks),
which sends an open file directly to a socket,
without having to context switch into userspace.
It conforms to the parts of HTTP/1.1 that appear to be important to clients.
I have not found any HTTP/1.1 clients which have trouble with Eris,
including curl, which breaks with fnord (the reason I began work on Eris).
Eris HTTPD is a part of [Dirtbags Capture The Flag](http://dirtbags.net/ctf/).
After many patches against [fnord 1.10](http://www.fefe.de/),
I decided to fork fnord into a new project.
Fnord's author approved of the fork.
Differences with fnord
======================
Significant differences between eris and fnord are:
* command-line arguments instead of compile-time defines
* eliminated use of libowfat
* no build dependency of dietlibc
* elimination of "old style symlink handling"
* elimination of user switching (you can use tcpserver -[ug])
* elimination of chroot code (you can use chroot)
* several bugfixes (sent to the fnord mail list)
* ignores Accept header (fnord also ignores it, but claims not to)
Usage
=====
Start with:
tcpserver -v -RHl localhost -u 1234 -g 1234 0 80 ./eris
There are many other ways to start eris.
For example, you can run an HTTPS server with stunnel.
You just need something that launches eris with stdin and stdout connected to the client.
Logging
-------
Will log to stderr in the form
127.0.0.1 200 23 localhost Links_(0.96;_Unix) none /index.html
where 127.0.0.1 is the client IP, 200 is the HTTP exit code,
23 is the size of the content that was served (or 0 for unsuccessful exit codes),
localhost is the Host: header (the virtual host),
the next token is the user agent with spaces replaced by underscores,
the next token (none) is the Referer HTTP header or "none" if none was given,
and the rest of each line is the decoded requested URL.
Features
--------
eris does simple virtual hosting. If the `Host:` HTTP header is there,
eris will try to chdir to a directory of that name, i.e. if the client
asks for "/" on host "www.fefe.de", eris will look for
"www.fefe.de/index.html". Eris will also try the directory "default"
if no specific directory for the virtual host was there.
eris implements el-cheapo HTTP ranges (only byte ranges and only of the
form x-y, not multiple ranges).
eris will change dots at the start of file or directory names to colons
in the query before trying to answer them.
eris understands and implements keep-alive connections.
eris will use sendfile on Linux to enable zero-copy TCP.
If eris is given the -c option, it will regard files
whose names end with ".cgi" as CGI programs and try to execute them.
Please see <http://hoohoo.ncsa.uiuc.edu/cgi/interface.html> for the CGI specification.
About The Name
==============
[Eris](http://en.wikipedia.org/wiki/Eris_%28dwarf_planet%29)
is the most massive (heaviest) dwarf planet in the solar system.
It's heavier than Pluto!
Its discovery is what spurred astronomers to finally define the word "planet",
which resulted in Pluto being classified a dwarf planet.
Otherwise, we would have to count Eris as a tenth planet.

View File

@ -1,9 +1,9 @@
#! /bin/sh
## Breaking fnord 1.10
## Breaking fnord 1.11
if [ "$1" = "clean" ]; then
rm -rf fnord-1.10
rm -rf fnord-1.11
fi
# Set HTTPD= to test something else
@ -14,6 +14,7 @@ case ${HTTPD:=./fnord} in
;;
esac
tests=0
title() {
printf "%-50s: " "$1"
tests=$(expr $tests + 1)
@ -36,16 +37,16 @@ d () {
}
if [ ! -f fnord-1.10.tar.bz2 ]; then
wget http://www.fefe.de/fnord/fnord-1.10.tar.bz2
if [ ! -f fnord-1.11.tar.bz2 ]; then
wget http://www.fefe.de/fnord/fnord-1.11.tar.bz2
fi
if [ ! -f fnord-1.10/httpd.c ]; then
rm -rf fnord-1.10
bzcat fnord-1.10.tar.bz2 | tar xf -
if [ ! -f fnord-1.11/httpd.c ]; then
rm -rf fnord-1.11
bzcat fnord-1.11.tar.bz2 | tar xf -
fi
cd fnord-1.10
cd fnord-1.11
# Comment this out if you want to build with diet libc
make DIET=

9
contrib/README Normal file
View File

@ -0,0 +1,9 @@
This directory contains little wrappers to help make your life
running a full Internet-facing web server (such as woozle.org)
a little easier.
Quite a lot of web software these days is written to work with
Apache and nothing else. PHP is a notable example: even PHP-CGI,
as shipped on Debian, requires special environment variables that
only Apache sets, and doesn't work with, e.g. mathopd, boa, busybox
httpd, or eris.

31
contrib/g.cgi.c Normal file
View File

@ -0,0 +1,31 @@
/** g.cgi - CGI interface to cgit and git-http-backend
*
* This is a simple CGI to invoke cgit with a configuration
* file of your choice. It will also invoke git-http-backend
* if appropriate, which in my (very light) testing runs about
* twice as fast as plain HTTP with git-update-server-info.
*/
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
/* Set these to appropriate paths */
#define CGIT_CONFIG "/home/neale/public_html/cgitrc"
#define GIT_PROJECT_ROOT "/home/neale/projects"
int
main(int argc, char *argv[])
{
char *uri = getenv("REQUEST_URI");
if (uri && strstr(uri, "git-upload-pack")) {
/* Use git-http-backend for great speed! */
setenv("GIT_PROJECT_ROOT", GIT_PROJECT_ROOT, 1);
execlp("git", "git", "http-backend", NULL);
} else {
setenv("CGIT_CONFIG", CGIT_CONFIG, 1);
execlp("cgit", "cgit", NULL);
}
return 0;
}

14
contrib/webfs Executable file
View File

@ -0,0 +1,14 @@
#! /bin/sh
PORT=8888
if [ $# = 0 ]; then
ARGS=-d
fi
addr=$(ifconfig | awk -F '[: ]+' '/inet addr/ {print $4;}' \
| grep -Fv 127.0.0.1 | head -n 1)
echo Listening on http://$addr:$PORT/
tcpsvd 0 $PORT eris -. $ARGS "$@"

1555
eris.c

File diff suppressed because it is too large Load Diff

1
mime.c
View File

@ -19,6 +19,7 @@ static struct mimeentry {
"jpeg", "image/jpeg"}, {
"jpg", "image/jpeg"}, {
"svg", "image/svg+xml"}, {
"webm", "video/webm"}, {
"mpeg", "video/mpeg"}, {
"mpg", "video/mpeg"}, {
"avi", "video/x-msvideo"}, {

View File

@ -75,7 +75,7 @@ extract_header_field(char *buf, char **val, int cgi)
}
}
for (; (buf[len-1] == '\n') || (buf[len-1] == '\r'); len -= 1);
for (; (len > 0) && ((buf[len-1] == '\n') || (buf[len-1] == '\r')); len -= 1);
buf[len] = 0;
return len;

52
test.sh
View File

@ -4,6 +4,10 @@
: ${HTTPD_CGI:=./eris -c}
: ${HTTPD_IDX:=./eris -d}
tests=0
successes=0
failures=0
H () {
section="$*"
printf "\n%-20s " "$*"
@ -64,7 +68,18 @@ chmod +x default/redir.cgi
cat <<'EOD' > default/status.cgi
#! /bin/sh
echo "Status: 300 wat"
case "$PATH_INFO" in
/empty)
echo "Status"
exit 0
;;
/nostat)
echo "Status: "
;;
*)
echo "Status: 300 wat"
;;
esac
echo "Merf: merf"
echo
echo "james"
@ -112,6 +127,9 @@ printf 'GET / HTTP/1.0\n\n' | $HTTPD 2>/dev/null | grep -q 'james' && pass || fa
title "No trailing slash"
printf 'GET /empty HTTP/1.0\r\n\r\n' | $HTTPD 2>/dev/null | d | grep -q '301 Redirect#%.*Location: /empty/#%#%' && pass || fail
title "No version after query_string"
printf 'GET /?\r\n\r\n' | $HTTPD 2>/dev/null | d | grep -q 'HTTP/0.9' && pass || fail
title "Logging /"
(printf 'GET / HTTP/1.1\r\nHost: host\r\n\r\n' |
PROTO=TCP TCPREMOTEPORT=1234 TCPREMOTEIP=10.0.0.2 $HTTPD >/dev/null) 2>&1 | grep -q '^10.0.0.2:1234 200 6 host (null) (null) /$' && pass || fail
@ -124,6 +142,10 @@ title "Logging busybox"
(printf 'GET /index.html HTTP/1.1\r\nHost: host\r\n\r\n' |
PROTO=TCP TCPREMOTEADDR=[::1]:8765 $HTTPD >/dev/null) 2>&1 | grep -Fxq '[::1]:8765 200 6 host (null) (null) /index.html' && pass || fail
title "Logging stunnel"
(printf 'GET /index.html HTTP/1.1\r\nHost: host\r\n\r\n' |
REMOTE_HOST=::1 REMOTE_PORT=8765 $HTTPD >/dev/null) 2>&1 | grep -Fxq '::1:8765 200 6 host (null) (null) /index.html' && pass || fail
H "Options"
@ -149,6 +171,12 @@ title "Too many headers"
printf 'Header: val\r\n'
done
printf '\r\n') | $HTTPD 2>/dev/null | grep -q 'HTTP/1.. 431 ' && pass || fail
title "Directory traversal"
printf 'GET /../default/index.html HTTP/1.0\r\n\r\n' | $HTTPD 2>/dev/null | grep -q 'HTTP/1.. 404' && pass || fail
title "Escaped directory traversal"
printf 'GET /%%2e%%2e/default/index.html HTTP/1.0\r\n\r\n' | $HTTPD 2>/dev/null | grep -q 'HTTP/1.. 404' && pass || fail
H "If-Modified-Since"
@ -175,16 +203,21 @@ printf 'GET / HTTP/1.0\r\nIf-Modified-Since: Sun Feb 27 12:12:12 2030\r\n\r\n' |
title "ims persist"
printf 'GET / HTTP/1.1\r\nIf-Modified-Since: %s\r\n\r\nGET / HTTP/1.0\r\n\r\n' "$ims" | $HTTPD 2>/dev/null | d | grep -q 'HTTP/1.. 304.*HTTP/1.. 200' && pass || fail
title "Logging"
(printf 'GET / HTTP/1.0\r\nIf-Modified-Since: %s\r\n\r\n' "$ims" | $HTTPD > /dev/null) 2>&1 | grep -q '304' && pass || fail
H "Directory indexing"
title "Basic index"
printf 'GET /empty/ HTTP/1.0\r\n\r\n' | $HTTPD_IDX 2>/dev/null | d | grep -Fq '<h1>Directory Listing: /empty/</h1><pre><a href="../">Parent Directory</a>%</pre>' && pass || fail
printf 'GET /empty/ HTTP/1.0\r\n\r\n' | $HTTPD_IDX 2>/dev/null | d | grep -Fq '<h1>Directory Listing: /empty/</h1><pre>%<a href="../">Parent Directory</a>%</pre>' && pass || fail
title "Hidden file"
printf 'GET /subdir/ HTTP/1.0\r\n\r\n' | $HTTPD_IDX 2>/dev/null | grep -q 'hidden' && fail || pass
title "Logging"
(printf 'GET /empty/ HTTP/1.0\r\n\r\n' |
PROTO=TCP TCPREMOTEPORT=1234 TCPREMOTEIP=10.0.0.2 $HTTPD_IDX >/dev/null) 2>&1 | grep -q '^10.0.0.2:1234 200 0 (null) (null) (null) /empty/$' && pass || fail
H "CGI"
@ -226,7 +259,13 @@ title "Redirect"
printf 'GET /redir.cgi HTTP/1.0\r\n\r\n' | $HTTPD_CGI 2>/dev/null | grep -Fq 'Location: http://example.com/froot' && pass || fail
title "Status"
printf 'GET /status.cgi HTTP/1.0\r\n\r\n' | $HTTPD_CGI 2>/dev/null | d | grep -q '^HTTP/1.0 300 wat#%' && pass || fail
printf 'GET /status.cgi HTTP/1.0\r\n\r\n' | $HTTPD_CGI 2>&1 | d | grep -q '^HTTP/1.0 300 wat#%.*.null. 300 6' && pass || fail
title "Status bug"
printf 'GET /status.cgi/empty HTTP/1.0\r\n\r\n' | $HTTPD_CGI 2>/dev/null | d | grep -q '^HTTP/1.0 500 ' && pass || fail
title "No status"
printf 'GET /status.cgi/nostat HTTP/1.0\r\n\r\n' | $HTTPD_CGI 2>/dev/null | d | grep -q '^HTTP/1.0 500 ' && pass || fail
H "Timeouts"
@ -235,6 +274,11 @@ title "Read timeout"
(sleep 2.1; printf 'GET / HTTP/1.0\r\n\r\n') | $HTTPD 2>/dev/null | grep -q '.' && fail || pass
H "CONNECT handler"
title "Basic test"
printf 'CONNECT /etc HTTP/1.1\r\n\r\n' | $HTTPD -o /bin/ls | grep -q passwd && pass || fail
H "fnord bugs"

View File

@ -40,9 +40,6 @@
#include <string.h>
#include "timerfc.h"
static const char days[] = "SunMonTueWedThuFriSat";
static const char months[] = "JanFebMarAprMayJunJulAugSepOctNovDec";
time_t
timerfc(const char *s)
{