******************************************
0. Changes...
******************************************
1999-11-17
  change mylog_server, mypass_server args.

  takeshi@SoftAgency.co.jp


1999-11-15
  for wu-ftpd-2.6.0

  takeshi@SoftAgency.co.jp


1999-09-06
  fix : for FreeBSD

  takeshi@SoftAgency.co.jp


1999-09-04
  fix : type miss

  takeshi@SoftAgency.co.jp


1999-08-26
  fix : cannnot open logfile error.

  takeshi@SoftAgency.co.jp


1999-08-20
  fix : `realpath' call : in src/ftpd.c , retrieve()

  takeshi@SoftAgency.co.jp


1999-06-16
  fix up for wu-ftpd-2.5.0 & mysql-3.22.x
  many changes..

  takeshi@SoftAgency.co.jp


1999-03-01
  fix incoming file name was incorrected on mysql logging.

  takeshi@SoftAgency.co.jp


1999-02-26
  fix up for wu-ftpd-2.4.2-beta-18-VR14
  change ftpaccess keyword;
       mypassdb, mypasstable -> mysqlauth
       see section 4 below.

  takeshi@SoftAgency.co.jp


1998-?
  fixed up for wu-ftpd-2.4.2-beta-18
  add Authentication function.

  takeshi@SoftAgency.co.jp


199?
  tcx contrib wuftpd-2.4.2b12
  by Zeev Suraski <bourbon@netvision.net.il>

******************************************
1. OverView
******************************************
This patches add functions to wu-ftpd-2.6.0:
  * enable transfer logging to MySQL
  * enable authentication by using MySQL

I archive old patch to
wu-ftpd-2.4.2-beta-18.patches.tgz

README.2.4 file is ORIGINAL wuftpd-2.4.2b12's README
please read this original README.


this patch from:
http://www.softagency.co.jp/mysql/


******************************************
2. patch & make
******************************************
wu-ftpd-2.6.0+mysql.patch

How to apply this patch

  % patch -p1 < wu-ftpd-2.6.0+mysql.patch


How to build:
A. traditional way:

  edit 'src/makefiles/common' : change below:
    MYSQL_LIBS = -L/usr/lib/mysql -lmysqlclient -lm -lz -ldl
    MYSQL_INCLUDE = -I/usr/include

  edit 'config.h' :
/*
 * MYSQL
 */
#define USE_MYSQL_AUTH
#define USE_MYSQL_LOG

    if you don't use mysql authentication function,
   please comment out `#define USE_MYSQL_AUTH'

    if you don't use mysql logging function,
   please comment out `#define USE_MYSQL_LOG'


  % ./build <your_platform>


B. use ./configure
 I didn't make this patch to support configure script.
 so, please edit config.h, src/Makefile file after ./configure

 % ./configure .....
 % vi vonfig.h
 % vi src/Makefile
 % make


**********************************************
3. Logging
**********************************************

to logging,
1. edit ftpaccess file
2. create table
3. grant logging user to mysql


-------------------
3-1.ftpaccess file
-------------------
Example:
  # log mysql
  mylog_server localhost
  mylog_user logging_user
  mylog_pass users_pass
  mylog_db ftp_logs
  mylog_table main_ip


Desc. Keyword & Values:
 mylog_server <server_name> <server_port server_socket>
        <server_name> : is mysql server host.
             default : localhost
        <server_port  server_socket> :
             server's port number or server's socket-file.
             you can skip these.
             default : server_port=3306
                       server_socket=/tmp/mysql.sock

              ex. mylog_server localhost 3333 /tmp/my.sock

 mylog_user <db user name>
         <db user name> : database user name
             default : 

 mylog_pass <db user passwd>
         <db user passwd> : database user password
             default : 

 mylog_db <database name>
         <database name> : database name
             default : ftp_logs

 mylog_table <table name>
         <table name> : table name
             default : main_ip


---------------------
When you want to use this for virtual domain
ex. (ftpaccess file)

virtual 10.10.10.1 mylog_table virtual1

virtual 10.10.10.2 mylog_server other
virtual 10.10.10.2 mylog_db     ftp
virtual 10.10.10.2 mylog_table virtual2
virtual 10.10.10.2 mylog_user  uname2
virtual 10.10.10.2 mylog_pass  pass2

In this example,
case 10.10.10.1 :
  change `mylog_table' only.
  other parameters(mylog_server,mylog_db,...) is same main server's one.

case 10.10.10.2
  change all parameters for MySQL.


------------------
3-2. create table
------------------

Creation TABLE:
/usr/bin/mysql ftp_logs <<EOF
CREATE TABLE main_ip (
  time_stamp int not null,
  xfertime int not null,
  address char(100) not null,
  filesize int not null,
  file char(255) not null,
  transfer_type char(1) not null,
  login_type char(1) not null,
  anon_passwd char(32) not null,
  directions char(1)
);
EOF


Logging Example:
+------------+----------+-----------+----------+------+---------------+------------+-------------+------------+
| time_stamp | xfertime | address   | filesize | file | transfer_type | login_type | anon_passwd | directions |
+------------+----------+-----------+----------+------+---------------+------------+-------------+------------+
|  896524857 |        1 | localhost |      493 | /h/a | b             | r          | takeshi     | o          |
|  906065626 |        4 | localhost |   539036 | /h/b | a             | r          | takeshi     | i          |



-------------
3-3. grant
-------------
Example:

# mysql mysql

mysql> grant insert on ftp_logs.* to log_user@localhost identified by 'user_pass';
mysql> FLUSH PRIVILEGES;



***********************************************
4. MySQL authentication
***********************************************
This patch can authentication with mysql!

to auth by using MySQL,
1. edit ftpaccess file
2. create table
3. grant logging user to mysql

-------------------
4-1.ftpaccess file
-------------------
Example:
  # auth mysql
  myauth_server localhost
  myauth_user auth_user
  myauth_pass users_pass
  myauth_db   service
  myauth_table users


Desc. Keyword & Values:
 myauth_server <server_name> <server_port  server_socket>
        <server_name> : is mysql server host.
             default : localhost
        <server_port  server_socket> :
             server's port number or server's socket-file.
             you can skip these.
             default : server_port=3306
                       server_socket=/tmp/mysql.sock

             ex. myauth_server host1 4444 /tmp/my2.sock

 myauth_user <db user name>
         <db user name> : database user name
             default : 

 myauth_pass <db user passwd>
         <db user passwd> : database user password
             default : 

 myauth_db <database name>
         <database name> : database name
             default : mypassdb

 myauth_table <table name>
         <table name> : table name
             default : mypasstable


------------
myauth_xxxx keywords don't work in 'virtual ......' clause.
only work main setting.


------------------
4-2. create table
------------------

Creation TABLE:
/usr/bin/mysql mypassdb <<EOF
CREATE TABLE mypasstable (
  id char(20),
  crypt char(32) binary,
  passwd char(32) binary,
  uid int(10) unsigned,
  gid int(10) unsigned,
  shell char(100) binary,
  home char(100) binary,
  active enum('Y','N') DEFAULT 'Y' NOT NULL,
  start_date date DEFAULT '0000-00-00' NOT NULL,
  expire_date date DEFAULT '2030-01-01' NOT NULL
);
EOF

 id : user name

 crypt : crypt password. (update mypasstable set crypt=ENCRYPT(passwd); )

 passwd : plain text password. this is not used.

 uid : uid number.

 gid : gid number.

 shell : shell

 home : home directory

 active : 'Y' : this user is active.
          'N' : this user is not active.
          default 'Y'
          active  must be enum.
          and must be enum('Y','N') , not enum('N','Y') !!

 start_date :
 expire_date :
    this account effective
       start_date <= effective < expire_date

----
mysql mypassdb
mysql> select * from mypasstable;
+-------+------------+------+-----+------------+-----------------------+
| name  | crypt      | uid  | gid | shell      | home                  |
+-------+------------+------+-----+------------+-----------------------+
| user1 | HGmd9843,J | 1234 | 567 | /bin/false | /home/ftponly/./user1 |


 -------+------------+-------------+
 active | start_date | expire_date |
 -------+------------+-------------+
   Y    | 1999-06-10 | 2000-06-09  |


---
 if you change field name, please edit config.h :

 #define FIELD_USER "id"
 #define FIELD_PASS "crypt"
 #define FIELD_UID  "uid"
 #define FIELD_GID  "gid"
 #define FIELD_SHELL "shell"
 #define FIELD_HOME  "home"


-------------
4-3. grant
-------------
Example:

# mysql mysql

mysql> grant select on mypassdb.mypasstable to auth_user@localhost identified by 'user_pass';
mysql> FLUSH PRIVILEGES;


*************************************************
Note.
*************************************************
Why I don't use pam_mysql?

I tried pam_mysql and wu-ftpd-pam (RedHat 4.2) first. (pam version 0.5)
But, wu-ftpd-pam check user name /etc/passwd first, and pam module called.
And, pam_mysql check user name only, don't return other parameter (uid,gid,shell,home directory).
I tried modifiy pam_mysql and wu-ftpd-pam, but it is some difficulty,
because it required modification libpwd and pam!
(modifiy pam_pwdb.so, pam_shells.so or create pam_mysql start all over again.. AGHHH!)
I have a little understanding of pam libpwdb mechanism and API interface, can't developped.
So, I modified wu-ftpd not use pam.

Anyone know, where is detailed PAM manual in Japanese ? ...
