Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ANNOUNCE - qmail-smtpd Plugins for MAIl, RCPT, DATA Phase

13 views
Skip to first unread message

Manvendra Bhangui

unread,
Apr 17, 2011, 5:10:43 AM4/17/11
to
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

John Levine

unread,
Apr 17, 2011, 12:22:27 PM4/17/11
to
>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. ...

This is a fine idea. But why don't you use Bruce Guenter's mailfront
package, which is well debugged, already has a useful set of plugins,
and interfaces very nicely with qmail?

If you also use his CVM package, it can check at SMTP time whether
there's a .qmail file for an address, so in most cases you can reject
rather than bounce undeliverable mail.

Regards,
John Levine, jo...@iecc.com, Primary Perpetrator of "The Internet for Dummies",
Please consider the environment before reading this e-mail. http://jl.ly

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-...@muc.de

Manvendra Bhangui

unread,
Apr 17, 2011, 12:33:17 PM4/17/11
to

On Sun, Apr 17, 2011 at 9:52 PM, John Levine <jo...@iecc.com> wrote:
This is a fine idea.  But why don't you use Bruce Guenter's mailfront
package, which is well debugged, already has a useful set of plugins,
and interfaces very nicely with qmail?

If you also use his CVM package, it can check at SMTP time whether
there's a .qmail file for an address, so in most cases you can reject
rather than bounce undeliverable mail.

Thanks for pointing out this. I was unaware of the CVM package. It looks interesting and I will take a look at this. 
0 new messages