For qmail-ldap dubug how-to, refer to errata page.
What are we going to have on our server?- Install daemontools which is a collection of tools used for managing Unix/Linux services.
- Install ucspi-tcp which includes tcpserver and tcpclient. These are command-line tools for building TCP client-server applications.
- Install djbdns which is a lightweight, small, secure, and powerful DNS server and cache toolkit.
- qmail-ldap which gives you basic things along with core functionality of qmail along with ldap support
- SMTP authentication ( smtp-auth ) before sending mails. This is for our roaming users.
- SMTP with ssl/tls support
- POP3 with ssl support
- Provision to debug the installation if something goes wrong
- Download latest daemontools package from http://cr.yp.to/daemontools/ and follow the installation steps.
- Download latest ucspi-tcp package from http://cr.yp.to/ucspi-tcp/ and follow the installation steps.
- Download latest djbdns package from http://cr.yp.to/djbdns/ and follow the installation steps.
- Download qmail package, patch it with qmail-ldap patch and follow the installation steps
Daemontools installation
Few things you should note about this installation is that this installation is a little different than other source installations in a sense that it creates links in /command to the targets in your source location where you compiled the package. For this reason it is necessory that you gunzip the package on a location where you do not usually delete anything manually. Remember do NOT delete the source in fact DO NOT DELETE ANY SOURCE CODE after you install any qmail related package. It is wise to have a backup copy on your local machine or may be a CD burnt with the source code.
Follow the steps below: # mkdir /package# cd /package
# chmod 1755 /package
# wget http://cr.yp.to/daemontools/daemontools-0.76.tar.gz
# cd admin/daemontools-0.76
# package/install
This should be enough for this installation. Once installation is complete you should see two process started newly.
# ps -A | grep svscan7593 ? 00:00:00 svscanboot
7616 ? 00:00:00 svscan
For more information you may want to take a look at the author's page here
Back to main installation main.ucspi-tcp installation
In this installation first we are going to patch ucspi-tcp package for ssl/tls support and then follow the normal installation procedure. Download the ucspi-tcp package from the location mentioned above. Download the ucspi-tcp ssl/tls patch from www.nrg4u.com. Follow the instructions to install.
$ wget http://cr.yp.to/ucspi-tcp/ucspi-tcp-0.88.tar.gz$ wget http://www.nrg4u.com/qmail/ucspi-tcp-ssl-20050405.patch.gz
$ tar xzf ucspi-tcp-0.88.tar.gz
$ gunzip ucspi-tcp-ssl-20050405.patch.gz
$ cd ucspi-tcp-0.88
$ patch < ../ucspi-tcp-ssl-20050405.patch
$ make
$ make install
# make setup check
Note that make setup check is run as root. The ucspi-tcp is installed under /usr/local. All the tools are installed under /usr/local. You may take a close look at the documentation from author's web site here
Back to main installation main.djbdns installation
The installation of djbdns package is pretty straight. <Finish it later: Followed steps as per djb's directions>
qmail-ldap installation PrecautionsDownload and Patch qmail
Patching qmail-ldap source with qmail-queue-custom-error.patch
Editing Makefile
Creating necessory groups and users
Installing qmail-ldap
Configuring qmail-ldap
Disabling your existing MTA
Creating dirmaker script
Starting qmail-ldap
Starting qmail-smtpd
Authenticated SMTP with SMTP AUTH
Securing SMTP with TLS
POP3 support with qmail-pop3d
POP3 with SSL using qmail-pop3d-ssl
Precautions
We will be installing qmail on /var directory. Before you start installing qmail-ldap make sure that you have /var mounted without nosuid permissions if it is a seperate partition. This entry can be removed from /etc/fstab and by restarting the system. The following output of mount command is perfectly acceptable.
$ mount/dev/hda1 on / type ext3 (rw,errors=remount-ro)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
/dev/hda2 on /tmp type ext3 (rw)
/dev/hda4 on /var type ext3 (rw)
usbfs on /proc/bus/usb type usbfs (rw)
Whereas following output of mount command is sure indicates that the installation is going to create problem.
$ mount/dev/wd0a on / type ffs (local)
/dev/wd0h on /home type ffs (local, nodev, nosuid)
/dev/wd0d on /tmp type ffs (local, nodev, nosuid)
/dev/wd0g on /usr type ffs (local, nodev)
/dev/wd0e on /var type ffs (local, nodev, nosuid)
Back to qmail-ldap installation
Download and Patch qmail
Download a fresh qmail package from the author's site. Gunzip it and and untar it. Download the latest qmail-ldap patch and gunzip it. Once done this, change to qmail directory and patch the qmail with qmail-ldap patch.
$ wget http://cr.yp.to/software/qmail-1.03.tar.gz$ wget http://www.nrg4u.com/qmail/qmail-ldap-1.03-20050401a.patch.gz
$ tar xzf qmail-1.03.tar.gz
$ gunzip qmail-ldap-1.03-20050401a.patch.gz
$ cd qmail-1.03
$ patch < ../qmail-ldap-1.03-20050401a.patch
Back to qmail-ldap installation
Editing Makefile
Now that you have your qmail patched, you have an array of operations to execute. First we will modify the Makefile to include all the options that we want to have in our qmail-ldap installation.
The unedited Makefile looks like this..after you patched the qmail code with qmail-ldap. Below I have added two hashes extra to each comment to avoide confusion with root prompt.
----< snip >----LDAPLIBS=-L/usr/local/lib -lldap -llber
LDAPINCLUDES=-I/usr/local/include
###LDAPLIBS=-L/opt/OpenLDAP/lib -lldap -llber -lresolv -R/opt/OpenLDAP/lib
### for example on my Linux box I use:
###LDAPLIBS=-L/opt/OpenLDAP/lib -lldap -llber
### if you need a special include-directory for ldap headers enable this
###LDAPINCLUDES=-I/opt/OpenLDAP/include
### ZLIB needed for -DDATA_COMPRESS and -DQMQP_COMPRESS
###ZLIB=-lz
### or you installed zlib in a different path you can use something like this
###ZLIB=-L/opt/zlib/lib -lz
###ZINCLUDES=-I/opt/zlib/include
### TLS (SMTP encryption) in qmail-smtpd and qmail-remote, see TLS.readme
### You need OpenSSL for this
### use -DTLS_REMOTE to enable tls support in qmail-remote
### use -DTLS_SMTPD to enable tls support in qmail-smtpd
### use -DTLSDEBUG to enable additional tls debug information in qmail-remote
###TLS=-DTLS_REMOTE -DTLS_SMTPD
### Path to OpenSSL includes
###TLSINCLUDES=-I/usr/local/include
### Path to OpenSSL libraries
###TLSLIBS=-L/usr/local/lib -lssl -lcrypto
### Path to OpenSSL binary
###OPENSSLBIN=/usr/local/bin/openssl
###OPENSSLBIN=openssl
### to make the Netscape download progress bar work with qmail-pop3d
### uncomment the next line (allready done)
MNW=-DMAKE_NETSCAPE_WORK
### to enable the auto-maildir-make feature uncomment the next line
###MDIRMAKE=-DAUTOMAILDIRMAKE
### to enable the auto-homedir-make feature uncomment the next line
###HDIRMAKE=-DAUTOHOMEDIRMAKE
### on most systems we need this to make auth_pop and auth_imap
###SHADOWLIBS=-lcrypt
### OpenBSD and other Systems do not have libcrypt, so comment the line out
### if you get linking problems.
### To use shadow passwords under some Linux OS, uncomment the next two lines.
###SHADOWLIBS=-lcrypt -lshadow
###SHADOWOPTS=-DPW_SHADOW
### To use shadow passwords under Solaris, uncomment the SHADOWOPTS line.
### to enable the possibility to log and debug imap and pop uncoment the
### next line
###DEBUG=-DDEBUG
### WARNING: you need a NONE DEBUG auth_* to run with inetd
### for profiling ...
###INCTAI=../libtai-0.60
###LIBTAI=../libtai-0.60
### Just for me, make from time to time a backup
BACKUPPATH=/backup/qmail-backup/qmail-ldap.`date "+%Y%m%d-%H%M"`.tar
### STOP editing HERE !!!
-----< /snip >----- After all comments removed our makefile looks like this. Besides default enabled options some of the options that we have modified are listed below minus comments. LDAPFLAGS=-DALTQUEUE -DBIGBROTHER -DBIGTODO -DIGNOREVESISIGN -DQUOTATRASH -DQLDAP_CLUSTER -DEXTERNAL_TODO -DDASH_EXT -DDATA_COMPRESS -DQMQP_COMPRESS -DSMTPEXECCHECK
LDAPLIBS=-L/usr/local/lib -lldap -llber
LDAPINCLUDES=-I/usr/local/include
ZLIB=-lz
TLS=-DTLS_REMOTE -DTLS_SMTPD -DTLSDEBUG
TLSINCLUDES=-I/usr/local/include
TLSLIBS=-L/usr/local/lib -lssl -lcrypto
OPENSSLBIN=/usr/bin/openssl
MNW=-DMAKE_NETSCAPE_WORK
MDIRMAKE=-DAUTOMAILDIRMAKE
HDIRMAKE=-DAUTOHOMEDIRMAKE
SHADOWLIBS=-lcrypt
DEBUG=-DDEBUG
Back to qmail-ldap installation
Patching qmail-ldap source with qmail-queue-custom-error.patch
This patch is necessory only if you are planning to return appropriate message for each e-mail simscan refuses to deliver. For more information on qmail-queue-custom-error.patch refer to simscan page. This patch requires to be patched on fresh qmail-1.03 source which in this case is not true. So you are sure going to to get a few rejects. Aparently you have to manually patch the code after you apply ldap patch. For more on manually patching sources, refer to manually patching source code page.
You can find this patch in ~/contrib directory in simscan sources.
Back to qmail-ldap installation
Creating necessory groups and users
Now we will create different users and groups that qmail needs. The group vmail will be used for writing the mails to disk.
# groupadd nofiles# useradd -g nofiles -d /var/qmail/alias alias
# useradd -g nofiles -d /var/qmail qmaild
# useradd -g nofiles -d /var/qmail qmaill
# useradd -g nofiles -d /var/qmail qmailp
# groupadd qmail
# useradd -g qmail -d /var/qmail qmailq
# useradd -g qmail -d /var/qmail qmailr
# useradd -g qmail -d /var/qmail qmails
# groupadd vmail
# useradd -g vmail -d /var/vmail -m vmail
# rm /var/vmail/.*
Back to qmail-ldap installation
Installing qmail-ldap
Now its time to issue the command (as root) to install the qmail.
# make setup checkIf above command executes without any errors, qmail-ldap is installed on your server in /var/qmail. All binaries are installed in /var/qmail/bin. Documentation is installed in /var/qmail/doc. Man pages are installed in /var/qmail/man. Startup scripts are located at /var/qmail/boot you might want to take a look at.
Back to qmail-ldap installationConfiguring qmail-ldap
We will now configure the qmail-ldap. Most of the configuration involve creating some vital files in /var/qmail/control. These files deside how some of the features are going to be handled by qmail-ldap. This is the primary runtime environment that qmail-ldap requires. Each control file is used for specific configuration which can be changed by changing the value in that file. Some control files must contain some specified values whereas some can be set according to your configuration.
~control/me: This should be set to FQDN (Fully Qualified Domain Name) of your server. For example if domain name of your server is ironclad.mil then you will add-
# echo ironclad.mil > /var/qmail/control/me~control/locals: Include entries to all the domains for which you will accept mails from remote hosts. This also tells qmail-ldap to locally deliver the mails for domains having entry in this file. For now we will have just one entry in this file as shown below
# echo ironclad.mil > /var/qmail/control/locals~control/recpthosts: Include entries of all the domains for which you will accept mails from remote hosts. Recipients domains listed in ~control/rcpthosts are allowed to relay messages without further checks. Here also we will have just one entry in this file as shown below
# echo ironclad.mil > /var/qmail/control/rcpthosts~control/ldapserver: This file should contain the IP of FQDN of the LDAP server that will contain qmail user accounts. In my case it is going to be secure.ironclad.mil. If you are running ldap server (slapd) without any parameters to it on the same server then you will have to add IP 127.0.0.1
# echo secure.ironclad.mil > /var/qmail/control/ldapserver~control/ldaplogin: This file contains the username for the LDAP server connection. It is same as one you have defined in your slapd.conf. In my case it is Manager. Consult your slapd.conf file for precise info.
# echo "cn=Manager,dc=ironclad,dc=mil" > /var/qmail/control/ldaplogin~control/ldappassword: This file contains password for the LDAP server connection. It is same as one you specified in slapd.conf in hash format. Note that the password in this file is clear text. This file should be owned by root and mode should be (600) i.e. read and write (rw-------) access to root only. If you are using auth-smtp or rcpt-verify then permissions must be adjusted accordingly so that qmail-smtpd user has read access to the file. In our case qmaild is the qmail-smtpd user
# echo (your password here) > /var/qmail/control/ldappassword~control/ldapbasedn: File should contain the base DN under which qmail-ldap users will exist. In our case we have an OU called qmail_users under dc=ironclad,dc=mil which is the root node in our tree. So I would do it like..
# echo "ou=qmail_user,dc=ironclad,dc=mil" > /var/qmail/control/ldapbasedn~control/ldapobjectclass: This file contains the objectClass against which all searches in LDAP tree will be limited. The default objectClass is qmailUser to we will add it to this file.
# echo "qmailUser" > /var/qmail/control/ldapobjectclass~control/ldapdefaultdelivery: This file contains a boolean value which indicates whether to look in /etc/passwd file (system accounts) if a user is not found in LDAP. We want our setup to use LDAP only and all our mail users will be virtual users so we will set it up to 0.
# echo 0 > /var/qmail/control/ldaplocaldelivery~control/ldapmessagestore: This should be set to the location where you want to store all mail message on your server. We will store the mail messages for all the users in /var/vmail
# echo /var/vmail > /var/qmail/control/ldapmessagestore~control/ldapuid: This should contain the uid of vmail user that we have created in the previous section. If you don't know where to find it you can find it using following command
# id vmailuid=1011(vmail) gid=1004(vmail) groups=1004(vmail)
# echo 1011 > /var/qmail/control/ldapuid
~control/ldapgid: This should contain the gid of vmail that we have created in the previous section. We have found it in code segment above
# echo 1004 > /var/qmail/control/ldapgid~control/defaultdelivery: For our purpose we are going to use Maildirs for storing emails. This we tell qmail by specifying in this file. Note below, the trailing / (slash) of Maildir is necessory.
# echo "./Maildir/" > /var/qmail/control/defaultdeliveryBack to qmail-ldap installation
Disabling your existing MTA
By default Debian ships with exim as the system MTA. To make sure that it does not interfere with our new qmail-ldap installation in any way, we will simply shut it down. If you don't do it, be sure to face some nasty errors. Alternately you may like to remove it from rc.conf file. If you decide to remove it from rc*.conf files so that it won't start automatically when you reboot the machine, you need to do a few things. To remove it from rc?.d directory you have to first determine which runlevel you are currently running in. You can verify this by looking at your /etc/inittab file. To verify your current runlevel, search /etc/inittab file for an entry looking like this:id:2:initdefault:. Here id:2:initdefault: the number after id: denotes your current runlevel which is 2 here.
For every runlevel Linux has a different directory in /etc directory, named as /etc/rc0.d, /etc/rc1.d and so on. Usually /etc/init.d contain files which are actual startup scripts for the programs. These files are targets for symlinks in /etc/rc*.d directories. So for runlevel 2 we will look at /etc/rc2.d directory
On issueing command file, I get following info
# file /etc/rc2.d/S20exim4/etc/rc2.d/S20exim4: symbolic link to `../init.d/exim4'
To disable exim you have to move the file from directory for this runlevel. The file can be found in /etc/rc2.d/. In this directory you need to find the script/symlink to the file exim*. For me the startup file in runlevel for exim is /etc/rc2.d/S20exim4. This file is a symlink to /etc/init.d/exim4. Removing this link will prohibit exim initializing on reboot in runlevel 2 (in this case). Remember other runlevels can still start exim. Alternately you can remove the script /etc/init.d/exim4 itself. But that will leave the links to this file from all rc*.d directories broken which certainly isn't desirable. Or you will have to remove the links as well, from all the /etc/rc?.d directories So better approach is to remove the link from /etc/rc2.d.
To stop exim you can kill the process (which is crude way to stop exim) like this.
# ps -A | grep exim2387 ? 00:00:00 exim4
# kill 2387
Back to qmail-ldap installation
Creating dirmaker script
Its time to create a dirmaker script. In the section Editing Makefile we enabled two options called MDIRMAKE=-DAUTOMAILDIRMAKE and HDIRMAKE=-DAUTOHOMEDIRMAKE This script will be used by qmail-ldap for creating mail directories (Maildir). Place the following script as /var/qmail/bin/dirmaker. The dirmake script for our installation will be:
#!/bin/sh/bin/mkdir -m 0700 -p $1
Make this script executable.
# chmod +x /var/qmail/bin/dirmakerTell qmail to use this script for creating new directories by specifying it in /var/qmail/control/dirmaker. If qmail-ldap finds this file with the appropriate path to the script in /var/qmail/control/dirmaker it turns the DAUTOHOMEDIRMAKE patch on. Note that the file should contain absolute path. If the mail user entry exists in LDAP but the home directory and/or Maildir for the user does not exist, this script will create necessory directories.
~control/dirmaker: This is the file which tells qmail-ldap to enable creation of automatic directory structures and the script to use to create these directories.
# echo /var/qmail/bin/dirmaker > /var/qmail/control/dirmakerBack to qmail-ldap installation
Starting qmail-ldap
Now its time to test the configuration we have been doing so far. To test this installation first we will create a symlink to /var/qmail/boot/qmail directory in /service directory. This will start the qmail in few seconds. This is done by daemontools. Then verify that the service is up.
# ln -s /var/qmail/boot/qmail /service/qmail# svstat /service/qmail
/service/qmail: up (pid 859) 17 seconds
Also you can determine the processes by issueing command. (Edited output)
# ps -Al --forestsvscanboot \_ svscan | \_ supervise | | \_ dnscache | \_ supervise | | \_ multilog | \_ supervise | | \_ qmail-send | | \_ qmail-lspawn | | \_ qmail-rspawn | | \_ qmail-clean | | \_ qmail-todo | | \_ qmail-clean | \_ supervise | \_ multilog \_ readproctitle
If your outputs agree with the above outputs, and everything looks good, try injecting a mail to some user already in LDAP but not having any directories present. After injecting email to the user check the logs.
# echo "to: admin@ironclad.mil" | /var/qmail/bin/qmail-inject# tail /var/qmail/log/qmail/current | tai64nlocal
2005-05-24 22:47:15.133418500 status: local 0/10 remote 0/20
2005-05-24 22:47:15.162095500 bounce msg 8044987 qp 925
2005-05-24 22:47:15.162949500 end msg 8044987
2005-05-24 22:47:15.166998500 new msg 8044986
2005-05-24 22:47:15.167017500 info msg 8044986: bytes 1326 from <#@[]> qp 925 uid 1010
2005-05-24 22:47:15.167058500 starting delivery 11: msg 8044986 to local postmaster@ironclad.mil
2005-05-24 22:47:15.167120500 status: local 1/10 remote 0/20
2005-05-24 22:47:15.176221500 delivery 11: success: did_1+0+0/
2005-05-24 22:47:15.176323500 status: local 0/10 remote 0/20
2005-05-24 22:47:15.176429500 end msg 8044986
The log output (in red color) above indicate that the things are working ok.
Back to qmail-ldap installation
Starting qmail-smtpd
The qmail-smtpd we are starting is plain vanilla version of smtpd. The run script can be found at location /var/qmail/boot/qmail-smtpd/run. This run script was installed at the time of qmail-installation. Before starting qmail-smtpd we need to define rules for smtpd in /var/qmail/control/qmail-smtpd.rules. After defining rules we will create a cdb file from this database. The next step would be to create a link in /service targeting to the smtpd run script.
An unedited qmail-smtpd run script is shown below.
#!/bin/shexec 2>&1
#
# SMTP service
#
QMAIL="/var/qmail"
ME="`head -1 $QMAIL/control/me`"
CONCURRENCY=${CONCURRENCY:=50}
QUSER="qmaild"
PATH="$QMAIL/bin:$PATH"
# source the environemt in ./env
eval `env - PATH=$PATH envdir ./env awk '\
BEGIN { for (i in ENVIRON) \
if (i != "PATH") { \
printf "export %s=\"%s\"\\n", i, ENVIRON[i] \
} \
}'`
# enforce some sane defaults
QUSER=${QUSER:="qmaild"}
PBSTOOL=${PBSTOOL:="$QMAIL/bin/pbscheck"}
if [ X${NOPBS+"true"} = X"true" ]; then
unset PBSTOOL
fi
exec \
envuidgid $QUSER \
tcpserver -v -URl $ME -x$QMAIL/control/qmail-smtpd.cdb \
${CONCURRENCY:+"-c$CONCURRENCY"} ${BACKLOG:+"-b$BACKLOG"} 0 smtp \
$PBSTOOL \
$QMAIL/bin/qmail-smtpd
The /var/qmail/control/qmail-smtpd.rules file after defining the desired rules.
127.:allow,RELAYCLIENT="":allow
Now we need to create cdb file from this /var/qmail/control/qmail-smtpd.rules file. To do this change directory to /var/qmail/control and then run following command:
tcprules qmail-smtpd.cdb rules.tmp < qmail-smtpd.rulesThe line in /var/qmail/boot/qmail-smtpd/run script that tells to refer to cdb file is tcpserver -v -URl $ME -x$QMAIL/control/qmail-smtpd.cdb \. If the script won't find qmail-smtpd.cdb file in place, you simply won't be able to make connection to the SMTP port as qmail-smtpd/run will not find the said cdb file. You may refer to my mail relaying document for more details.
After everything is in place, we will create the link to /var/qmail/boot/qmail-smtpd/run in /service directory. svc will then start the service within few seconds.
ln -s /var/qmail/boot/qmail-smtpd /service/smtpdYou can check if the smtpd service is up or not by issuing command
# svstat /service/smtpd/service/smtpd: up (pid 26596) 8 seconds
If you get output something like this, you are up with SMTP. Now you can try sending some mail to your server from some other email address not on your server. If mail got through, thats the confirmation of SMTP service running at your server.
Back to qmail-ldap installation
Authenticated SMTP with SMTP-AUTH
SMTP AUTH is particulary useful when you have roaming users as well as users with dynamic IP assigned by their ISPs. These users can now use your SMTP server to relay their mails even if their IP or network is not listed in your allowed list of networks/IPs in qmail-smtpd.cdb file. Authenticated SMTP will allow such users to enter their credentials which are verified against their account entry in qmail-ldap and upon successful authentication they will be granted access to relay mails using your server regardless of their current IP or network. Read more about relaying in my mail relaying document.
In order to qmail-smtpd support this functionality you have to edit current /var/qmail/boot/qmail-smtpd/run script to invoke auth-smtp program installed with qmail-ldap in your installation. Open this file in your favorite editor and look for the following lines towards end of file.
exec \envuidgid $QUSER \
tcpserver -v -URl $ME -x$QMAIL/control/qmail-smtpd.cdb \
${CONCURRENCY:+"-c$CONCURRENCY"} ${BACKLOG:+"-b$BACKLOG"} 0 smtp \
$PBSTOOL \
$QMAIL/bin/qmail-smtpd
Add command $QMAIL/bin/auth_smtp /usr/bin/true to the last line, so now the last line in your run script become..
exec \envuidgid $QUSER \
tcpserver -v -URl $ME -x$QMAIL/control/qmail-smtpd.cdb \
${CONCURRENCY:+"-c$CONCURRENCY"} ${BACKLOG:+"-b$BACKLOG"} 0 smtp \
$PBSTOOL \
$QMAIL/bin/qmail-smtpd $QMAIL/bin/auth_smtp /usr/bin/true
Now add these variables to your qmail-smtpd.rules file
:allow,SMTPAUTH="AUTHREQUIRED",NOPBS=""So now your qmail-smtpd.rules file will look as shown below
127.:allow,RELAYCLIENT="":allow,SMTPAUTH="AUTHREQUIRED",NOPBS=""
Now you have to rebuild the cdb file from qmail-smtpd.rules file. For this you have to issue following command as root. The variable SMTPAUTH tells qmail-smtpd that authorization is required before relaying mail from your server. Next variable NOPBS tells smtpd not to use PBS (POP Before SMTP). You do not need this since you are using SMTP AUTH. This may be required when you are using clustered servers but not now.
# tcprules qmail-smtpd.cdb rules.tmp < qmail-smtpd.rulesYou have to restart the smtpd service for these changes to take effect. To do this issue following command as root.
# svc -t /service/smtpdTo test this setup try sending mail from some other host using sender's address on mail envelop as your servers default domain. It should ask you for authentication. If this works, you are done with SMTP AUTH. Don't forget to verify the service is running using svstat command as follows before you test.
# svstat /service/smtpd/service/smtpd: up (pid 26698) 14 seconds
Back to qmail-ldap installation
Securing SMTP with TLS
When you authenticate over internet, auth passwords are in clear text equivalent base64 encoding. So if someone can capture the packets using some packet capturing tool, your users are vulnerable to Identity theft. So a step beyond this authenticated SMTP relaying is the ability to negotiate a secure connection with your SMTP server for secure authentication and privacy of data transferred over the Internet. This will prevent password sniffing. qmail-ldap allows us to use and configure this ability in qmail-smtpd. Remember we have enabled a variable TLS=-DTLS_REMOTE -DTLS_SMTPD -DTLSDEBUG in Makefile before qmail installation. Refer to the Editing Makefile Section. This built the ability in our installation to configure SMTP with TLS option.
Before configuring this abilty you have to make sure you have created certificate by running make cert command in the patched source of qmail.
# cd src/qmail-1.03# make cert
Read more on make cert.
It will prompt you to supply some vital information that will appear on your certificate. Remember, you need to provide the your server name as Common Name here. This will also change the permissions of the certificate file. Make sure permissions are as shown below:
# ls -lh /var/qmail/control/cert.pem-rw-r----- 1 qmaild qmail 2.4K 2005-05-25 11:43 /var/qmail/control/cert.pem
~control/smtpcert: This is one this you have to perform before you restart qmail-smtpd. You have to define the path of cert.pem in this this file. It would be appropriate if you specify absolute path to this file as follows.
# echo /var/qmail/control/cert.pem > /var/qmail/control/smtpcertThis certificate will be sent to your clients when they smtp using tls. One this has been done you have to restart smtpd as follows. In my experience smtp with tls WILL NOT work until you add path to cert.pem to ~control/smtpcert file.
# svc -t /service/smtpdClients have to select appropriate options in their mail clients for using SSL or TLS with your SMTP server. Ascribe your clients to their email-client documentation if you/they are unsure about how to do it. When they try to send a message to SMTP server, their mail client will receive a certificate notice asking to proceed with encrypted SMTP. qmail-ldap can enforce client SMTP encryption as a mandatory feature by setting. This can be either specific clients or universally. For specific clients you can set this in /var/qmail/control/qmail-smtpd.rules or to set this feature globally you have to set the variable in /var/qmail/boot/qmail-smtpd/env which is same as /service/smtpd/env as it is nothing but symlink to the qmail-smtpd in /var/qmail/boot. You can enforce this globally as follows.
echo TLSREQUIRED > /service/smtpd/env/SMTPAUTHElse you can do this in qmail-smtpd.rules file by changing last line of /service/smtpd/run as follows.
:allow,SMTPAUTH="TLSREQUIRED",NOPBS=""Do not forget to create cdb file from qmail-smtpd.rules file. Restart the smtpd service as follows.
# svc -t /service/smtpdBack to qmail-ldap installation
POP3 support with qmail-pop3d
You will find the run script in /var/qmail/boot/qmail-pop3d. It was installed at the time of qmail-ldap installation. Before creating pop3 service in /service you need to edit the /var/qmail/control/qmail-pop3d.rules file to reflect changes as follows.
127.0.0.1:allow,NOPBS="":allow
We do not want to use POP-Before-SMTP which we specified using veriable NOPBS. You do not have to edit /var/qmail/boot/qmail-pop3d/run script. You have to create cdb file from /var/qmail/control/qmail-pop3d.rules file. For this, change to the /var/qmail/control directory and execute tcprules command as follows.
# tcprules qmail-pop3d.cdb rules.tmp < qmail-pop3d.rulesNext you have to create a symlink to /var/qmail/boot/qmail-pop3d in /service directory as follows.
# ln -s /var/qmail/boot/qmail-pop3d /service/pop3dThis should start the pop3d service in few seconds. You can verify this by issueing following command.
# svstat /service/pop3d/service/pop3d: up (pid 2857) 17 seconds
If your output is similar to the output shown above, your pop3d is running now. You can try configuring and receiving mails using your favorite mail-client.
Back to qmail-ldap installation
POP3 with SSL using qmail-pop3d-ssl
qmail-ldap provides special run script for pop3 with ssl. You will find this script in /var/qmail/boot/qmail-pop3d-ssl. To make this script work for you you might have to change the exec statement toward the end of the qmail-pop3d-ssl/run script as shown below. To be specific check out second line in code below. It should be tcpserver -v -HRl $ME -x$QMAIL/control/qmail-pop3d.cdb \. This is because we are going to have similar rules for vanilla POP3 and POP3 with SSL. If you want to have seperate rules for some users, you have to specify different .rules file and create a cdb file from that, and then add path to that file in run script.
exec \tcpserver -v -HRl $ME -x$QMAIL/control/qmail-pop3d.cdb \
${CONCURRENCY:+"-c$CONCURRENCY"} ${BACKLOG:+"-b$BACKLOG"} \
-s ${TLSCERT:+"-n$TLSCERT"} 0 pop3s \
$QMAIL/bin/qmail-popup $ME \
$QMAIL/bin/auth_pop ${PBSTOOL:+"-d$PBSTOOL"}\
$QMAIL/bin/qmail-pop3d "$ALIASEMPTY"
To tell svc to start service, you need to create a link to /var/qmail/boot/qmail-pop3d-ssl in /service. This will start the service in few second which you can later verify using svstat command.
# ln -s /var/qmail/boot/qmail-pop3d-ssl /service/pop3d-ssl# svstat /service/pop3d-ssl
/service/pop3d: up (pid 3947) 22 seconds
If your output agrees with the output shown above you are up with POP3-SSL. You can set your mail-client to use POP3 with SSL and verify its working. In case of problem, check errata page.
Back to qmail-ldap installationTO DO:
Add detailed debugging reports for known problems.
Add ldap misconfiguration huntdown.
Add server misconfiguration huntdown.
Add detailed info about creating .cdb files
SCRATCH
# make
"/var/qmail/bin/qmail-cdb" locals.cdb rules.tmp < locals
"/var/qmail/bin/qmail-cdb" rcpthosts.cdb rules.tmp < rcpthosts
tcprules qmail-smtpd.cdb rules.tmp < qmail-smtpd.rules
tcprules qmail-qmqpd.cdb rules.tmp < qmail-qmqpd.rules
tcprules qmail-pop3d.cdb rules.tmp < qmail-pop3d.rules
tcprules qmail-imapd.cdb rules.tmp < qmail-imapd.rules
Note that some parts in Life With qmail-ldap are inconsistant (as on 04 June 2005) with current qmail-ldap patch available.
In Life With qmail-ldap section 13. Additional Patches it has inconsistancies as mentioned:
Subsection 13.1 SMTP after POP -
You do not have to patch it seperately for SMTP after POP.
Subsection 13.2 SMTP AUTH -
You do not have to patch it seperately for SMTP AUTH.
Subsection 13.3 The Dash-Trick -
You do not have to patch it seperately for Dash-Trick.
Current patch already include above patches