Installing validrcptto

Configuring validrcptto

The most common questions I receive about the validrcptto.cdb patch involve how to create the validrcptto.cdb file in the first place, or how to use the same file on multiple servers. The mkvalidrcptto script can be a major part of the answer to both questions. This web page will show how I'm using mkvalidrcptto on my own server.

It should be noted that you are not required to use mkvalidrcptto in order to benefit from the validrcptto.cdb patch- any mechanism which produces a list of all valid email addresses on your system will work, even something as simple as manually editing a text file with one email address on each line. As long as you correctly turn this text file into a cdb file, it will work.

Before you install the script, there are a few other packages which need to be installed on the system. The first is djb's cdb library and tools, which contains the cdbmake-12 program, which converts a text file into a cdb file. This package should be installed using the directions on djb's web site. A quick walk-through is shown here:

So lets install it!


# cd /usr/ports/databases/cdb
# make extract

If you are using a system with glibc version 2.3 or later, the original djb source code will cause an error in the file error.h, because the newer versions of glibc implement the errno variable differently than how it has been done in the past. (errno is a global variable which libc uses to tell the caller whether the last I/O function call was successful or not, and if there was an error, it will contain a number identifying the error.)

There is a simple fix, which can actually be done on all systems whether it's necessary or not, without causing any problems. If you know (or suspect) that you need this fix, or if you have tried to compile the code and gotten an error about error.h, or if you just want to do it anyway, here's the fix:

Open the file error.h with a text editor: 


# cd work/cdb-0.75/
# vi error.h

Find this line near the top:

extern int errno;

Comment the line out, and add this new line below it:

/* extern int errno; */
#include <errno.h>


So now it should look like:

#ifndef ERROR_H
#define ERROR_H

/* extern int errno; */
#include <errno.h>

extern int error_intr;
extern int error_nomem;


Now to install cdb: 


# cd ../..
# make install clean

Installing the CDB_File module

The mkvalidrcptto script reads several cdb files in order to do its job, which means that you need to install the CDB_File perl module, available through CPAN, the Comprehensive Perl Archive Network, which is an archive of Perl modules which are not included with Perl itself, but which others have decided to share in the hope that they will prove useful.

This is a quick walk-through of how to install the module. 


# perl -MCPAN -e shell

If you have never run the CPAN shell before, you will be asked to configure the module first. This will involve setting the path to the various utilities that CPAN uses for downloading and building modules, as well as selecting one or more CPAN "mirrors". Mirrors are web and FTP sites around the world which have copies of all of the CPAN modules. You should go through this process if it asks you to- for most of the questions you can just hit ENTER and be okay, and for mirrors you should try to choose at least three of them, preferably ones which are in your part of the world. 


cpan> install CDB_File

(contents of output here)

cpan> exit
# exit

Now to copy validrcptto: 


# cd /usr/local/bin
# cp /downloads/qmailrocks/mkvalidrcptto mkvalidrcptto
# chmod 755 mkvalidrcptto

Before continuing on, Please make sure you have added at least one domain to vpopmail.

One thing that wouldn't hurt is to make sure that your installation of perl is happy with the script and can find the modules. You can do this by running this command as a non-root user: 


# perl -c /usr/local/bin/mkvalidrcptto

The output should look like:


/usr/local/bin/mkvalidrcptto syntax OK

You should then run it once as root and make sure the output makes sense for your system. The output should be a list of every valid email address on your system, one on each line. 


# mkvalidrcptto

The output should look like:


alan@domain1.xyz
jms1@domain1.xyz
postmaster@domain1.xyz
thomas@domain1.xyz
@domain2.xyz
postmaster@domain3.xyz
user@domain3.xyz

...

Scripting for one system

The mkvalidrcptto script itself just reads the information it needs from your system and prints a list of email addresses. The other half of the equation is turning that list of email addresses into a validrcptto.cdb file, so that qmail-smtpd can use it.

The original versions of mkvalidrcptto worked by simply printing the list of email addresses, and relied on another program called cdbmake-12 to produce the actual validrcptto.cdb file. However, as of 2007-06-06, mkvalidrcptto can write the validrcptto.cdb file by itself. This makes the scripting much simpler.

In addition, as of 2007-06-18, mkvalidrcptto has some extra code which detects whether or not the data has changed since the last time the file was written, and only writes a new file if the data has changed. Not only does this make scripting simpler, but the timestamp on the validrcptto.cdb file correctly tells the last time it was updated, just as the original script here did.

The most basic way to create the validrcptto.cdb file would look like this: 


# cd /var/qmail/control
# mkvalidrcptto -c validrcptto.cdb

The idea situation would be to have vpopmail run a certain command whenever it changes something. When John Simpson originally wrote this page, vpopmail did not have that kind of hook, however I have since written a patch for vpopmail called the ONCHANGE patch, which is officially part of vpopmail as of vpopmail version 5.4.15.

It is possible to write a script like the one below, which can run as a cron job, in response to an ONCHANGE event, or as part of a general qmail-updater service, to rebuild the validrcptto.cdb file. 

#!/bin/sh
PATH=/usr/bin:/bin:/usr/local/bin:/var/qmail/bin

umask 022
mkvalidrcptto -c /var/qmail/control/validrcptto.cdb

If you're reading this and understand how onchange works, you only need to run the "mkvalidrcptto -c validrcptto.cdb" inside the /var/qmail/control directory just once as once onchange is enabled, it will take care of any of the updates. I just wanted you as the user to understand how validrcptto works and understand it.

Now your validrcptto is setup and configured. Now to setup maildrop!

Installing maildrop