Mandrake 9.2 + Proftpd + MySQL authentication + Quotas Howto
Author: Stephen Khoo (stephen@khoosys.net)
Acknowledgements: This howto borrows almost entirely from Proftpd auth/quota/(simple)log <-> postgresql (mysql) mini howto by Martijn van Buytene (martijn@sigterm.nl).
Updated: 6 April 2004
libmysql12-4.0.16-1mdk
libmysql12-devel-4.0.16-1mdk
MySQL-Max-4.0.16-1mdk
MySQL-common-4.0.16-1mdk
Installation
Make sure you do not have the RPM version of proftpd installed. Remove if necessary using drakconf or rpm -e proftpd. Log in as your user account to do the installation. Instructions in bold should be done as root.
You should be able to copy and paste the text in the yellow boxes straight into your Mandrake PC. We have tested this on a clean server and it all seems to work fine. If you have any problems use the Contact form or Guestbook on this site to let us know. You can always let us know if this is useful anyway!
Get the sources
|
# as user # Proftpd source - note that this contains mod_sql # Module: quotatab source |
Note: make sure that your path to the installation directory does not contain spaces in any of the directory names as this confuses the ./configure script totally!
Unpack sources
|
# as user # Unpack sources # copy quotatab sources to proftpd contrib folder |
Compile and install
This assumes that the MySQL libraries and headers are placed where Mandrake puts them (i.e. /usr/lib and /usr/include/mysql respectively). If you have used a different MySQL installation you just need to check that you get the path to these MySQL files correct.
|
cd proftpd-1.2.9 make # make a symbolic link to the installed binary in /usr/sbin ln -s /usr/local/sbin/proftpd /usr/sbin/proftpd |
Unix Configuration
As far as UNIX is concerned we use one real group account ftpgroup (id 5500) as every user will be jailed to their home directory using the 'DefaultRoot ~/' directive. We set up one main ftpuser account (id: 5500) with this group and a guest account ftpguest (id 5501).
|
groupadd -g 5500 ftpgroup |
|
Note: I also add a guest user so that your client sites can have a place for their guest users to transfer files. Just run: adduser -u 5501 -s /bin/false -d /bin/null -c "proftpd guest" -g ftpgroup ftpguest add a password and then remember to add them to your database as members of the ftpgroup by adding a new record there. To add a guest user, add a record for a user with userid of 5501 and set the permissions on the folders you want to share like this: Their clients will now only be able to download from the From_folder and drop files, but not list files in the To_folder. |
MySQL Configuration
Create the database tables in MySQL for authentication and logging.
We use a database called ftpdb which we access using a MySQL user proftpd with password 'password'. (Clearly substitute your own password in here).
You need to log into MySQL using your root account and password.
|
mysql -uroot -ppassword use ftpdb; # CREATE TABLE `ftpgroup` ( INSERT INTO `ftpgroup` VALUES ('ftpgroup', 5500, 'ftpuser'); # -------------------------------------------------------- # CREATE TABLE `ftpquotalimits` ( # CREATE TABLE `ftpquotatallies` ( # -------------------------------------------------------- # CREATE TABLE `ftpuser` ( INSERT INTO `ftpuser` VALUES (1, 'testaccount', 'ftppasswd', 5500, 5500, '/home/testdomain.com', '/sbin/nologin',0,'',''); |
Notes:
- The group table lists the members of each group. This does not need any records for a simple setup.
- The user table lists each of your ftp users and records their stats and is used for authentication and pointing proftpd to the correct home directory. Using the directive 'asdfasf' we make proftpd create the home directory if one does not already exist.
- The quotalimits table is used to se the current quota for the user matching its entry.
- The quotatallies table is used by proftpd to keep track of the user's quotas and will be filled if there is a matching userfield 'name' when a user logs in.
- We have added a user test account just called "testaccount" to check things are working ok.
Field Explanations:
quotalimits
| name | - username |
| quota_type | - user, group, class, all (we use user) |
| per_session | - true or false (we use true) |
| limit_type | - quota limit type - hard or soft (we use hard) |
| bytes_in_avail | - upload limit in bytes - allowed bytes on disk (eg diskquota) |
| bytes_out_avail | - download limit in bytes - allowed bytes a user can download |
| bytes_xfer_avail | - allowed bytes a user can transfer in/out |
| files_in_avail | - upload limit in files - allowed number of uploaded files |
| files_out_avail | - allowed number of downloaded files |
| files_xfer_avail | - allowed number of files a user can transfer in/out |
quotatallies
| name | |
| quota_type | |
| bytes_in_used | - upload tally in bytes |
| bytes_out_used | - download tally in bytes |
| bytes_xfer_used | - transfer tally in bytes |
| files_in_used | - upload tally in files |
| files_out_used | - download tally in files |
| files_xfer_used | - transfer tally in files |
If a value of any limit field is set to '0' it is unlimited.
You can read the documentation that comes with mod_quotatab for mysql here.
Author's Note:You can test a 15MB quota limit on 'testaccount' by inserting this record into 'quotalimits': |
Proftpd Config File
Here is our complete configuration file setup with MySQL and quota support. Keep a copy of the installation one in /usr/local/etc/ and replace with one like this - change to suit your ServerName and ServerAdmin.
|
ServerName "Khoosys Proftpd Server" # Hide as much as possible to outside users DefaultServer on # Allow FTP resuming. # Port 21 is the standard FTP port. # Umask 022 is a good standard umask to prevent new dirs and files # To prevent DoS attacks, set the maximum number of child processes # Set the user and group under which the server will run. # To cause every FTP user to be "jailed" (chrooted) into their home # Normally, we want files to be overwriteable. # The passwords in MySQL are encrypted using CRYPT # used to connect to the database # Here we tell ProFTPd the names of the database columns in the "usertable" # Here we tell ProFTPd the names of the database columns in the "grouptable" # set min UID and GID - otherwise these are 999 each # create a user's home directory on demand if it doesn't exist # Update count every time user logs in # Update modified everytime user uploads or deletes a file # User quotas SQLNamedQuery get-quota-limit SELECT "name, quota_type, per_session, limit_type, bytes_in_avail, bytes_out_avail, bytes_xfer_avail, files_in_avail, files_out_avail, files_xfer_avail FROM ftpquotalimits WHERE name = '%' AND quota_type = '%'" SQLNamedQuery get-quota-tally SELECT "name, quota_type, bytes_in_used, bytes_out_used, bytes_xfer_used, files_in_used, files_out_used, files_xfer_used FROM ftpquotatallies WHERE name = '%' AND quota_type = '%'" SQLNamedQuery update-quota-tally UPDATE "bytes_in_used = bytes_in_used + %, bytes_out_used = bytes_out_used + %, bytes_xfer_used = bytes_xfer_used + %, files_in_used = files_in_used + %, files_out_used = files_out_used + %, files_xfer_used = files_xfer_used + % WHERE name = '%' AND quota_type = '%'" ftpquotatallies SQLNamedQuery insert-quota-tally INSERT "%, %, %, %, %, %, %, %" ftpquotatallies QuotaLimitTable sql:/get-quota-limit
|
Proftpd startup file
As you can see we start proftpd as a standalone process and not as an xinetd service. We use the proftpd startup script provided by the rpm distribution. You can download it here.
Testing
Start the service using /etc/rc.d/init.d/proftpd and login to the ftp server using 'testaccount' and 'ftppasswd'.
If the home directory '/home/testdomain.com' does not already exist it will be created.
Have fun!!
A few useful tips
If you want to check that queries are coming through to MySQL, turn on logging by adding a line to your MySQL configuration file such as: log=/var/lib/mysql/mysql.log
Remember to turn off logging when you are done as it will slow things down with it on!
(Note that the MySQL config file is usually '/etc/my.cnf'. If you don't have one MySQL usually provides a set which you can copy according to the size of server you want to run. For example, a huge server can use : '/usr/share/mysql/my-huge.cnf')