Chapter 21. Compatibility and Integration

Table of Contents
SQL
Hints
sendfile()
Regular expressions

SQL

Authentication and persistant ratio support for the mod_ratio module are provided using SQL databases. The official documentation for this feature is currently a little thin on the ground. At the moment unless SQL support is provided for mod_ratio the ratios are only considered within a single connection with no persistance of credits recorded.

Compilation and support

To include support for sql the appropriate module has to be added prior to building the binary for the host system

./configure --with-modules=mod_sqlpw:mod_mysql
make 
make install
This should ensure that support is properly enabled, in addiiton to this a local MySQL (or similar) server should be installed and configured with the appropriate accesses and tables for yor setup. This is covered in later sections of this chapter.

Format of SQL tables

Example 21-1.

mysql> show fields from proftp;
+----------+-------------+------+-----+---------+-------+
| Field    | Type        | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| username | varchar(30) | YES  |     | NULL    |       |
| uid      | int(11)     | YES  |     | NULL    |       |
| gid      | int(11)     | YES  |     | NULL    |       |
| password | varchar(30) | YES  |     | NULL    |       |
| homedir  | varchar(50) | YES  |     | NULL    |       |
| count    | int(11)     | YES  |     | NULL    |       |
+----------+-------------+------+-----+---------+-------+

Example 21-2. Contents

mysql> select * from proftp;
+----------+------+------+----------+----------+-------+
| username | uid  | gid  | password | homedir  | count |
+----------+------+------+----------+----------+-------+
| oli      |  500 |  500 | test     | /home/om |     2 |
| oli2     |  500 |  500 | test     | /        |     1 |
+----------+------+------+----------+----------+-------+

(take care : uid and gid must be > 500. or change the source code of the module).

Authentication and persistant ratio support for the mod_ratio module are provided using SQL databases. The official documentation for this feature is currently a little thin on the ground. At the moment unless SQL support is provided for mod_ratio the ratios are only considered within a single connection with no persistance of credits recorded.

Compilation and support

To include support for sql the appropriate module has to be added prior to building the binary for the host system

./configure --with-modules=mod_mysql
make 
make install
This should ensure that support is properly enabled, in addiiton to this a local MySQL (or similar) server should be installed and configured with the appropriate accesses and tables for yor setup. This is covered in later sections of this chapter.

SQL Authentication

o Install MySQL o Compile Proftpd with the --with-modules=mod_sqlpw:mod_mysql flags

Note: I had to alter the path slighly so the modules got mysql.h from the rightplace.

Detailing how to use MySQL is outside the scope of this document, so here's some links.

o http://www.devshed.com/Server_Side/MySQL/Administration/ o http://www.devshed.com/Server_Side/MySQL/Intro/

Quick rundown of what's needed to make a databae

o create a user for proftpd to access the database as o create permissions for this user o create new database (mine is called proftpd) o reload as required to make this live o create a table within proftpd (mine is ftp)

Example 21-3. SQL database layout

mysql> use proftpd;
Database changed
mysql> show tables;
+-------------------+
| Tables in proftpd |
+-------------------+
| ftp               |
+-------------------+
1 row in set (0.02 sec)

mysql> show columns from ftp ;
+----------+-------------+------+-----+---------+-------+
| Field    | Type        | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| username | varchar(60) | YES  |     | NULL    |       |
| uid      | int(11)     | YES  |     | NULL    |       |
| gid      | int(11)     | YES  |     | NULL    |       |
| password | varchar(30) | YES  |     | NULL    |       |
| homedir  | varchar(50) | YES  |     | NULL    |       |
| count    | int(11)     | YES  |     | NULL    |       |
+----------+-------------+------+-----+---------+-------+
6 rows in set (0.00 sec)

Example 21-4. Configuration fragment for SQL

--[ proftpd.conf ]--
# auth using mysql            host      login   pass    db
MySQLInfo                     localhost hamster *****   proftpd
SQLUserTable                  ftp
SQLUsernameField              username
SQLUidField                   uid
SQLGidField                   gid
SQLPasswordField              password
SQLHomedirField               homedir
SQLLoginCountField            count
SQLAuthoritative              on
SQLPlaintextPasswords         on
--[ proftpd.conf ]--

Gotcha's

421 Service not availible Make sure that the home directory of the user concerned actually exists and has the right ownerships/permissions Can't connect to the database Is it running? Is it listening? Does the user proftpd is using have the right permissions?

Format of SQL tables

Example 21-5.

mysql> show fields from proftp;
+----------+-------------+------+-----+---------+-------+
| Field    | Type        | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| username | varchar(30) | YES  |     | NULL    |       |
| uid      | int(11)     | YES  |     | NULL    |       |
| gid      | int(11)     | YES  |     | NULL    |       |
| password | varchar(30) | YES  |     | NULL    |       |
| homedir  | varchar(50) | YES  |     | NULL    |       |
| count    | int(11)     | YES  |     | NULL    |       |
+----------+-------------+------+-----+---------+-------+

Example 21-6. Contents

mysql> select * from proftp;
+----------+------+------+----------+----------+-------+
| username | uid  | gid  | password | homedir  | count |
+----------+------+------+----------+----------+-------+
| oli      |  500 |  500 | test     | /home/om |     2 |
| oli2     |  500 |  500 | test     | /        |     1 |
+----------+------+------+----------+----------+-------+

(take care : uid and gid must be > 500. or change the source code of the module).

Configuration details

The following configuration is needed in the proftpd.conf file to enable sql support

Example 21-7. proftpd.conf

MySQLInfo                       localhost test "" test
                                # HOST login password database
MySQLUserTable                  proftp
MySQLUsernameField              username
MySQLUidField                   uid
MySQLGidField                   gid
MySQLPasswordField              password
MySQLHomedirField               homedir 
MySQLLoginCountField            count   
MySQLAuthoritative              on      
MySQLPlaintextPasswords         on      

SQL Logging

Example 21-8. Updated authentication table

mysql> show columns from ftpusers;
+----------+---------------+------+-----+---------+-------+
| Field    | Type          | Null | Key | Default | Extra |
+----------+---------------+------+-----+---------+-------+
| username | varchar(60)   | YES  |     | NULL    |       |
| uid      | int(11)       | YES  |     | NULL    |       |
| gid      | int(11)       | YES  |     | NULL    |       |
| password | varchar(30)   | YES  |     | NULL    |       |
| homedir  | varchar(50)   | YES  |     | NULL    |       |
| count    | int(11)       | YES  |     | NULL    |       |
| fretr    | int(10)       | YES  |     | NULL    |       |
| bretr    | int(10)       | YES  |     | NULL    |       |
| bstor    | int(10)       | YES  |     | NULL    |       |
| fstor    | int(10)       | YES  |     | NULL    |       |
| ftime    | timestamp(14) | YES  |     | NULL    |       |
| faddr    | varchar(255)  | YES  |     | NULL    |       |
| fhost    | varchar(255)  | YES  |     | NULL    |       |
| fcdir    | varchar(255)  | YES  |     | NULL    |       |
+----------+---------------+------+-----+---------+-------+
14 rows in set (0.01 sec)

Example 21-9. File tracking table

mysql> show columns from logging2;
+----------+--------------+------+-----+---------+-------+
| Field    | Type         | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+-------+
| fstor    | int(11)      | YES  |     | NULL    |       |
| fretr    | int(11)      | YES  |     | NULL    |       |
| bstor    | int(11)      | YES  |     | NULL    |       |
| bretr    | int(11)      | YES  |     | NULL    |       |
| fcdir    | varchar(255) | YES  |     | NULL    |       |
| fhost    | varchar(255) | YES  |     | NULL    |       |
| faddr    | varchar(255) | YES  |     | NULL    |       |
| ftime    | varchar(255) | YES  |     | NULL    |       |
| count    | int(11)      | YES  |     | NULL    |       |
| filename | varchar(255) | YES  |     | NULL    |       |
+----------+--------------+------+-----+---------+-------+
10 rows in set (0.01 sec)
There's definately some cruft in the logging2 table which I need to clean out but I thought I'd make this post first >:) # auth using mysql host login pass db MySQLInfo bat.vom.org.uk hamster Ma3ros proftpd # SQLUserTable ftpusers SQLUsernameField username SQLUidField uid SQLGidField gid SQLPasswordField password SQLHomedirField homedir SQLLoginCountField count # # SQL Logging # SQLLogStats on # SQLLogHits "requires a table or table plus 3 fields: " "[table] filename count dir" SQLLogHits logging2 # SQLLogDirs fcdir SQLLogDirs fcdir # SQLLogHosts <host> <IP> <time> SQLLogHosts fhost faddr ftime Which results in authentication happening from the ftpusers table, and running totals of the number of files up/download and the byte counts. fcdir appears to hold the last directory change made (not sure what use it is...) and fhost, faddr, ftime appear to hold details of the last person to connect. logging2 holds a list of files downloaded and the number of times they have been collected. Notes: the logging table only works properly if it's pre-populated with filenames ie insert into logging2 (filename) values ('/full/dir/fromroot/filename'); Also with both tables the counters don't appear to work properly unless zeroed before use. Will ponder on this.

Рейтинг@Mail.ru