* Afghan Hound's Marvelous Quote of the Day server daemon and clients. *
or
- how to replace one line in inetd.conf with 3000+ lines of C *
This was originally written because just putting
"qotd stream tcp nowait nobody /usr/sbin/tcpd /usr/games/fortune"
in inetd.conf was too slow on my 386 - and, it turns out, that isn't
in accordance with the RFC defining the quote of the day service......
[This release has only been tested on Linux (i386/SPARC32) and Solaris (SPARC64) and probably doesn't work anywhere else. ahem. ]
This package builds a daemon and clients capable of being fully compliant with RFC865 "Quote of the Day Protocol".
Building procedure
See INSTALL. The main thing to do is set up the defaults in config.h,
after running configure:
The ones supplied are reasonable if you have root on
on the box you're installing on, otherwise:
Change DEF_TCP_PORT/DEF_UDP_PORT/DEF_QOTDPORT to
ones greater than 1024.
Change DEF_SYSLOG to 0. (To avoid annoying the
real admin.)
Change DEF_LOG_FILE to something you can
write to.
(These are all set if you use the
extra/aqotdd.non-root config file supplied)
Don't use tcpbench/udpbench over anything other
than loopback without asking - and then check
'who(1)' first. :)
Remember to start for the first time with the "-d" flag
to make sure everything is working properly - You don't
want to have to try to kill the server if it's going
wrong and it's in the background - Control-C is much
easier.
Adjust LOG_CONNECT and LOG_MESSAGE to taste.
Adjust DEF_MAX_TCP/DEF_MAX_UDP depending on how much
resources your server machine has.
Solaris Note: Use gmake not make.
Programs:
aqotdd : The main server program (Installed in PREFIX/sbin) fortune-tcp : A client using TCP/IP. (Installed in PREFIX/games) fortune-udp : A client using UDP. (Installed in PREFIX/games)
tcpbench : A benchmarking client using TCP. (not installed) udpbench : A benchmarking client using UDP. (not installed)
Testing without fortune- *:
Instead of fortune-tcp: telnet host port
nc host port
Instead of fortune-udp: nc -u host port, and press enter.
[nc == netcat, just so you know.]
Makefile Extra Targets
Extra (non-GNU standard) makefile targets are:
xemacs : Makes maintainer-clean and opens all the important
files in XEmacs.
rpm : Makes the src/binary rpms.
deb : Makes the deb package.
Extras
In the "extra" directory :
rfc865.txt - Just for information.
aqotdd - A start up script suitable for RedHat Linux. (and RH
based distributions - Mandrake/Definite/etc/etc.)
strfile.h - The definition of the .dat files, from the horse's mouth.
fortune.pl - A clone of fortune-tcp/fortune-udp in perl. strfile.pl - Perl program to create .dat files. (Note - The
arguments are different to strfile's - and the
sorting arguments sort in perls 'cmp' order on all
the characters in the quote, not just the first
alphabetical character(s). Do a 'strfile.pl -h' to
find out more.)
glibc-check.c - Some version of glibc (2.1.2-5, as distributed with
RedHat 6.0, for example) have a memory leak in the
getservbyname call. This little program checks for
this. Compile with gcc -o glibc-check glibc-check.c
(now automatically compilied by 'make' in the top level
directory) If your glibc does leak, then either upgrade to
a newer version, or don't use the ident lookup feature of
aqotdd.
aqotdd.conf.in- Made into aqotdd.conf by the Makefiles. Installed in
PREFIX/etc by default.
aqotdd.non-root-An aqotdd.conf file for non-root/testing use. Sets tcp/udp
ports to 3000, disables syslog, sets all log options to
largest values and sets the 'allow' variable to local nets
(127.x.x.x/192.168.x.x/10.x.x.x) only. NB - It still needs
the log_file option setting to a file you can write
to...use with aqotdd -f /path/aqotdd.non-root if you want.
process.sh - A text-file version of all the bits of cpp you need to
generate aqotdd.conf/aqotdd.8 and fortune-tcp.6 from
their .in files and config.h.
packages/ - Holds the package config files for (at the moment)
RPM and Solaris packages.
debian/ - Holds the package config files for deb packages.
Credits
NMAP - The code for ident lookups on the client came from nmap-2.12.
All the error checking was cut, since I only wanted it as
something that 'real' servers do...(of course, if you want
to try to destroy aqotdd, nmap is one of the places to
start.)
"The newest version of nmap can be obtained from
http://www.insecure.org/nmap . nmap is (C) 1997,1998,1999 by
Fyodor (fyodor@dhp.com, fyodor@insecure.org)" - from "man nmap"
unix programming FAQ -
http://www.erlenstar.demon.co.uk/unix/faq_toc.html
Daemonising code, get/setuid stuff - a gold mine.
unix socket FAQ -
http://kipper.york.ac.uk/~vic/sock-faq
Lots of bits ahem borrowed from here. All you ever wanted to
know about sockets in UNIX.
Beej's Guide to Network Programming - Using Internet Sockets
http://www.ecst.csuchico.edu/~beej/guide/net/
Another gold mine of code snippets.
Notes
The "-l" flag - Most (indeed all the ones I've seen) Linux distributions
that include 'fortune' call it from .profile/.bash_profile/.login
/.cshrc/.bashrc/etc/etc with
echo
fortune
echo
to give a bit of space round the fortune. The supplied clients
can add the preceeding/following blank line automatically, just
use the "-l" flag.
Speed - Under extensive[1] trials, the main bottleneck to speed isn't
the network code speed, it's finding the quote. However, fortune-tcp
runs within 0.1 of a second of fortune(6) with a P233 client/
386/16 server. :) (with 4MB ram, running Linux 2.2.16)
To improve speed:
1) Use less fortunes. Finding the right file/offset depends
on how many files there are. (TODO - would
"cat * > large_file" help?)
2) More CPU.
3) Turn off RFC compliance. (see below)
4) More CPU.
5) Faster Network? (Only got 10base2 round here)
6) More CPU.
7) <joke>Use Win2K as the server.</joke>
[1] With 2, count them, 2 machines. Mindcraft have nothing on
me....
Offensive - The server only checks to see if the quote is rot13 encoded.
It doesn't actually check /dev/brain to find out what you find
offensive, and certainly can't do that for the clients. Please
check the fortune database for offensiveness first, making sure
that offensive fortune files are not just marked with the
name-o convention.
RFC865 - Turning on full RFC compliance will slow the server down; not
only does it have to check the length is less than 512 bytes
(meaning it has to start looking for another quote.) but it
also has to check for non-printing, non-space, non-end-of-line
characters in the output. If you're only concerned about the
length of the quote, set abs_max/ABS_MAX to 512. (Most (?)
terminals can handle the '\a' (beep!) character anyway...
...so it shouldn't matter that much.)
Me
Afghan Hound : afghan@afghanhound.org.uk
http://www.afghanhound.org.uk/
http://www.uklinux.afghanhound.net/ - for the office
Quake statistics page.
***Afghan Hound Software***
M" " " " " " " " "o"
oo " " "o
"o" " " " " " " M
o" " " " " " " " " " " " "
oo" " " "o" " " "o" "oo
o" " " "o" " " " " " " "o o
o " " o" o" " " oM " " "oMo
M" " "oMoMo "o" " " " " "oM o"o"
o" oMo"oMo"o"oMoMoM " " "o" "oM
o" "oMo" "oMo"MMoMMMo"o"o"o"o" "o"
Mo" oMoMo"oM"oo""" "oMo"o"o"o"o oM
M "oMoM" " Mo oM Mo"o"o"o"o"o""
Mo"oMo" "" Mo"o"oMoMo"oM
MoM o"o"oMMMo"o"
o "" o"o" ""Mo"oM
oM o"o"oMM"o"o"
MM oooMM" o o"o"o"MMo"o"
"M ooo""" MM "o"o"o"o"o"M
"Mo oooMMM M "o" "o"o"o"o
""MMMMoMoM " "o"o"o"o"o
MMMMM" "oM "MMo"o"o
oMMM" MoMoMoMoMoM"
" "
***Delivering pointless software since 1999***
