Monday, May 31, 2010

Virtual Mail And FTP Hosting With iRedMail And Pure-FTPd

iRedMail is a shell script that lets you quickly deploy a full-featured mail solution in less than 2 minutes. Since iRedMail 0.5, it supports Debian 5.0.1 and Ubuntu 8.04 & Ubuntu 9.04 (both i386 and x86_64). iRedMail supports both OpenLDAP and MySQL as backends for storing virtual domains and users.

The OpenLDAP backend of iRedMail allows you to integrate all kinds of applications. This guide shows you how to integrate pure-ftpd into the iRedMail ldap backend on CentOS 5.x, passwords will be stored in ldap and you can change the password through webmail.

This tutorial is based on CentOS 5.3, so I suggest you set up a minimum CentOS 5.3, install iRedMail 0.5 RC2 and choose OpenLDAP as backend, as shown in these tutorials:

    * iRedMail: Mail Server With LDAP, Postfix, RoundCube/SquirrelMail, Dovecot, ClamAV, SpamAssassin, Amavisd (Debian 5.0.1)
    * iRedMail: Build A Full-Featured Mail Server With LDAP, Postfix, RoundCube, Dovecot, ClamAV,SpamAssassin, DKIM, SPF On CentOS 5.x


1 Install Pure-FTPd

Use the rpmforge yum repository to install pure-ftpd.

rpm -Uhv http://apt.sw.be/redhat/el5/en/i386/rpmforge/RPMS/rpmforge-release-0.3.6-1.el5.rf.i386.rpm # <-- For i386
rpm -Uhv http://apt.sw.be/redhat/el5/en/x86_64/rpmforge/RPMS//rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm # <-- For x86_64

Install pure-ftpd:

yum install pure-ftpd


2 Configure Pure-FTPd

Default configuration files:

    * /etc/pure-ftpd/pure-ftpd.conf
    * /etc/pure-ftpd/pureftpd-ldap.conf


Basic settings in /etc/pure-ftpd/pure-ftpd.conf

Make sure that the CreateHomeDir and LDAPConfigFile options are enabled and look like this:

vi /etc/pure-ftpd/pure-ftpd.conf

CreateHomeDir               yes

LDAPConfigFile /etc/pure-ftpd/pureftpd-ldap.conf


Find cn=vmail password

vmail password was randomly created duiring the iredmail installation. You can find the password in /etc/postfix/ldap_virtual_mailbox_domains.cf:

vi /etc/postfix/ldap_virtual_mailbox_domains.cf

bind_dn         = cn=vmail,dc=example,dc=com
bind_pw         = kZ6uB29mViWKWI9lOH3cGnF7z3Dw3B #cn=vmail password


Click here to find out more!
Configure LDAP settings in /etc/pure-ftpd/pureftpd-ldap.conf

vi /etc/pure-ftpd/pureftpd-ldap.conf

LDAPServer localhost
LDAPPort 389
LDAPBaseDN o=domains,dc=example,dc=com
LDAPBindDN cn=vmail,dc=example,dc=com
LDAPBindPW kZ6uB29mViWKWI9lOH3cGnF7z3Dw3B #cn=vmail password
LDAPDefaultUID 500      # <- UID of 'vmail' user.
LDAPDefaultGID 500      # <- GID of 'vmail' user.
LDAPFilter (&(objectClass=PureFTPdUser)(mail=\L)(FTPStatus=enabled))
LDAPHomeDir FTPHomeDir  # <- This is new attribute, we will add it
LDAPVersion 3


3 Config LDAP
Get schema

You have two ways of getting the pureftpd schema. You only need to choose one.

    * Download the schema that has been modified by iredmail.
    * Get the schema shipped within pure-ftpd-1.0.22 and modify it.

Download the schema that has been modified by iredmail:

wget http://iredmail.googlecode.com/hg/extra/pureftpd.schema -P /etc/openldap/schema/

Get the schema shipped within pure-ftpd-1.0.22:

cd /tmp/
wget http://download.pureftpd.org/pub/pure-ftpd/releases/pure-ftpd-1.0.22.tar.bz2
tar xjf pure-ftpd-1.0.22.tar.bz2
cp pure-ftpd-1.0.22/pureftpd.schema /etc/openldap/schema/


Modify /etc/openldap/schema/pureftpd.schema

We need to add one more attribute 'FTPHomeDir' before the objectclass definition, used to store the user's FTP directory.

vi /etc/openldap/schema/pureftpd.schema

attributetype ( 1.3.6.1.4.1.6981.11.3.9 NAME 'FTPgid'
        DESC 'System uid (overrides gidNumber if present)'
        EQUALITY integerMatch
        SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 SINGLE-VALUE )
# Add new attributetype FTPHomeDir.
attributetype ( 1.3.6.1.4.1.6981.11.3.10 NAME 'FTPHomeDir'
        DESC 'FTP directory'
        EQUALITY caseIgnoreIA5Match
        SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 SINGLE-VALUE )
## New Pure-FTPd object type

objectclass ( 1.3.6.1.4.1.6981.11.2.3 NAME 'PureFTPdUser'
        DESC 'PureFTPd user with optional quota, throttling and ratio'
        SUP top AUXILIARY           # <-- Add this line.
        MAY ( FTPStatus $ FTPQuotaFiles $ FTPQuotaMBytes $ FTPUploadRatio $
              FTPDownloadRatio $ FTPUploadBandwidth $ FTPDownloadBandwidth $
              FTPuid $ FTPgid $ FTPHomeDir ) ) # <-- Add $ FTPHomeDir


Modify /etc/openldap/slapd.conf

vi /etc/openldap/slapd.conf

Include pureftpd.schema after iredmail.schema:

include /etc/openldap/schema/iredmail.schema
include /etc/openldap/schema/pureftpd.schema    # <-- Add this line.

Add index for attributes defined in pureftpd.schema:

# Default index.
#
index objectClass                                   eq,pres
index ou,cn,mail,surname,givenname,telephoneNumber  eq,pres,sub
index uidNumber,gidNumber,loginShell                eq,pres
index uid,memberUid                                 eq,pres,sub
index nisMapName,nisMapEntry                        eq,pres,sub
# <-- Add the below
#Index for FTP attrs.
index FTPQuotaFiles,FTPQuotaMBytes eq,pres
index FTPUploadRatio,FTPDownloadRatio eq,pres
index FTPUploadBandwidth,FTPDownloadBandwidth eq,pres
index FTPStatus,FTPuid,FTPgid,FTPHomeDir eq,pres


4 Create FTP Home Dir

FTP data are all stored in the /home/ftp/ directory. Create /home/ftp/, owner must be the root user.

mkdir /home/ftp/
ls -dl /home/ftp

drwxr-xr-x 3 root root 4096 Jun 7 20:18 /home/ftp/


5 Restart OpenLDAP service to make pureftpd.schema work

/etc/init.d/ldap restart
/etc/init.d/pure-ftpd restart

Make sure pure-ftpd is running:

netstat -ntlp | grep pure-ftpd

tcp 0 0 0.0.0.0:21 0.0.0.0:* LISTEN 2062/pure-ftpd (SERVER)
tcp 0 0 :::21 :::* LISTEN 2062/pure-ftpd (SERVER)

No comments: