MySQL Logging for WU-ftpd
=========================

Installation
------------

These patches are against WU-ftpd 2.4.2b12 (as taken from a source RPM from redhat 4.2).
Depending on your luck and computer's mood, they may work on other versions too.

This patch should compile clean under Linux.  Other platforms, namely, 
ones with broken sprintf()'s (the source suggests such platforms exist) 
will not work (if anybody feels like wrapping a couple of #ifdef's 
and getting this portable to broken platforms, go right ahead).  Also,
the SQL query uses snprintf() to avoid overflows, so there's a good 
chance it wouldn't compile under Solaris unless you have this function 
available (you can change the snprintf() to sprintf() and remove the 
bounds checking, but it's generally not a good idea).

If you fall into any of the above categories and can't get it to compile,
try compiling the snprintf() included in this package and link it in.
It seems to work fine under Solaris.

One change that is missing from the diffs is the change you have to 
apply to the Makefile that's copied to your ./src directory (after
you run ./build <platform>). 
You would have to add the following to the LIBES directive in the
./src/Makefile file.


-L/usr/local/lib/mysql -lmysqlclient
(assuming your mysql library files are located in /usr/local/lib/mysql).

E.g., if the LIBES directive looks like this:
LIBES    = -lsupport -lbsd # -lshadow

it should be changed to this:
LIBES    = -lsupport -lbsd -L/usr/local/lib/mysql -lmysqlclient -lm # -lshadow


Configuration
-------------

After you compile it, and replace your existing wuftpd 
with the new compiled binary, you'd have to:

a.  Create a database named "ftp_logs".  That specific name can only be changed in compile time.
b.  Create table(s) that would hold the logging information.
c.  Modify the ftpaccess file.


(a.) is straightforward (mysqladmin create ftp_logs), here's an example for (b.) and (c.):

Say you have ftpd running on your box, that handles the box's main IP and two more virtual IPs.
First, create tables for all of them, using make_ftp_sql_table <name>.  E.g.:
./make_ftp_sql_table main_ip
./make_ftp_sql_table first_virtual
./make_ftp_sql_table second_virtual

Afterwards, to enable SQL logging, add these lines to your ftpaccess file:

----
# Enable MySQL logging
logtable main_ip

logtable 10.0.0.1 logtable first_virtual
logtable 10.0.0.2 logtable second_virtual
----
(replace 10.0.0.1 and 10.0.0.2 with the actual virtual IPs of course).


From that point on, file transfers should get logged into the ftp_logs MySQL database.

Note:  Depending on what kind of queries you'd later want to make 
       on the tables, you may want to change make_ftp_sql_table to 
       add certain indices/keys (and of course, you can do so manually).


Notes and considerations:
-------------------------

1.  Just compiling the MySQL logging patch into the ftpd (without 
    changing the ftpaccess file) shouldn't cause any changes.
2.  You *can* log to both text logs and SQL logs.
    This time, I made sure it works in the best possible way I could
    think of:
    a.  No logtable and no logfile entries - keep logs in the compile-time
        defined log file.
    b.  logtable defined and logfile isn't - keep in SQL table only.
    c.  logfile defined and logtable isn't - keep in log file only.
    d.  both logtable and logfile defined - keep in both SQL and log file.
    Virtual servers would copy the non-virtual's server behavior, unless
    you explicitly override it with specificc logfile/logtable entries
    for them.
3.  Depending on how busy your ftp server is, you may want to allow more simultaneous connections to MySQL or
    reduce the 8 hour timeout to something shorter.
4.  It took me less time to actually hack in the patches, than to write this document.  That means it *might*
    be buggy (although if it is, it sure as hell fooled me as it seems to work fine here).  If you use it and
    notice any bug - please let me know.


Have fun and happy MySQLing,

Zeev Suraski <bourbon@netvision.net.il>
