I am writing (actually finished writing) a method by which we can write
plugins for qmail-smtpd. The plugins will allow us to execute our own
functions in smtp_mail(), smtp_rcpt() and smtp_data() in qmail-smtpd. By
using plugins we will be able to alter the behaviour of the MAIL, RCPT,
DATA phase of a SMTP session.
The way it works qmail-smtpd scans for all shared objects with names
(smtpd-plugin0.so, smtpd-plugin1.so, ... and so on) in the directory
/var/qmail/plugins. The function dlopen() is called on all the shared
objects. A function plugin_init() is called to initialize a PLUGIN
structure defined in plugin_init.h The PLUGIN structre contains pointers
to funcations to be executed in smtp_mail(), smtp_rcpt() and smtp_data()
in qmail-smtpd. These functions are passed arguments like mailfrom, rcptto,
localip, tcpremoteip, etc
We can terminate the MAIL, RCPT, DATA session by returning non-zero
integer in the function written as part of the plugin. We can also
define the message to be returned to the user by simply defining a variable
named 'mesg' inside these functions.
To write a plugin is very simple. We just need to write the functions
from_plug(), rcpt_plug() or data_plug(). It is upto to us to write all
the three functions or write any one of them. e.g.
In case we do not want to do anything in the RCPT session, then we can
just return 0 in the function rcpt_plug() and our rcpt_plug() function can
be
int
rcpt_plug(char *remoteip, char *from)
{
return (0);
}
A template for writing plugins is included in the patch. The template is
smtp_plugin.c. To compile the plugin we just need to do the following
gcc -Wall -O4 -fPIC -c smtp_plugin.c
gcc -shared -rdynamic -nostartfiles -fPIC -s -O4 -o smtpd-plugin.so smtp_plugin.o
Just copy the file smtpd-plugin.so to /var/qmail/plugins directory
Examples of plugins could be writing badmailfrom, badrcptto as a plugin. I am sure
you will be able to visualize more than what I can do at the moment.
You can download the patch at
The code is free and without any warranty. If you notice any mistake in the code
let me know so that I can fix it.
--
Regards Manvendra -
http://www.indimail.org