Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Qmail: users

Blacklist outgoing mail

 

 

Qmail users RSS feed   Index | Next | Previous | View Threaded


rugoli at gmail

Feb 3, 2010, 7:57 AM

Post #1 of 4 (1392 views)
Permalink
Blacklist outgoing mail

Hello everybody!

I wanted to blacklist some e-mail addresses which will not receive any
mail from my qmail server. If anyone of my users (user [at] server)
tries to send an email to some directions (user1 [at] mail1,
user2 [at] mail1, user2 [at] mail2), this mail will go directly to
/dev/null (or send the mail to admin [at] server to know that's
working).

Does anyone know how can I do it?

Thanks!


lists-qmail at maexotic

Feb 3, 2010, 9:21 AM

Post #2 of 4 (1294 views)
Permalink
Re: Blacklist outgoing mail [In reply to]

On Wed, Feb 03, 2010 at 04:57:56PM +0100, Yuki (aka Rubén Gómez) wrote:
> I wanted to blacklist some e-mail addresses which will not receive any
> mail from my qmail server. If anyone of my users (user [at] server)
> tries to send an email to some directions (user1 [at] mail1,
> user2 [at] mail1, user2 [at] mail2), this mail will go directly to
> /dev/null (or send the mail to admin [at] server to know that's
> working).

If the blocking is based on whole domains it can be done with
control/smtproutes
However you need either the QMAILQUEUE patch or a netqmail (which
already has this patch incorporated).
Setup a second qmail-smtpd service with tcpserver listening on eg.
127.0.0.2. (Just copy over the /service/qmail-smtpd to
/service/qmail-smtpd-nullmailer and change the
/service/qmail-smtpd-nullmailer/run file)
Also change the run file to use a CDB file (-x option) that has
:allow,QMAILQUEUE="/var/qmail/bin/nullqueue"
as the only instruction.

/var/qmail/bin/nullqueue should be a executable shell script:
------------------------------------------------------------------------
#!/bin/sh

cat >/dev/null

exit 0
------------------------------------------------------------------------

After the changes have been made you have to
svc -t /service/qmail-smtpd-nullmailer

Then add lines to
control/smtproutes
like:
example.com:127.0.0.2
.example.com:127.0.0.2
This should do it.

If
In the case you want to blacklist based on user [at] domain'd add to
control/virtualdomains:
user [at] domai:nullmailer
user2 [at] domai:nullmailer
user [at] domain:nullmailer
(don't forget to svc -t /service/qmail-send)
and make a "nullmailer" entry to users/assign.
(don't forget to qmail-newu).
In the controlling directory for the nullmailer entry put a .qmail-default
file and either add
&admin [at] server
or make it consist only of a comment (#) line (to drop the messages).
Of course you can also blacklist whole domains with this approach by
adding to control/virtualdomains:
domain:nullmailer
.domain:nullmailer

Hope I didn't miss anything.

\Maex


jms1 at jms1

Feb 3, 2010, 11:12 AM

Post #3 of 4 (1294 views)
Permalink
Re: Blacklist outgoing mail [In reply to]

On 2010-02-03, at 1057, Yuki (aka Rubén Gómez) wrote:
>
> I wanted to blacklist some e-mail addresses which will not receive any
> mail from my qmail server. If anyone of my users (user [at] server)
> tries to send an email to some directions (user1 [at] mail1,
> user2 [at] mail1, user2 [at] mail2), this mail will go directly to
> /dev/null (or send the mail to admin [at] server to know that's
> working).
>
> Does anyone know how can I do it?

two ways come to mind, depending on how you feel about using patches.

if you don't want to do any patching, and can live with the limitation that this will be server-wide (i.e. the policy will affect every message on the machine, there's no way for different senders to have different policies) then this method works with djb's original qmail-1.03 code, and therefore *should* work regardless of what patches you may be using.

this will send messages into a black hole...

(1) create a dummy userid on the system. make sure the password is locked (most systems create new users in a "locked" state, but make sure) and set up .qmail and .qmail-default files in this user's home directory which don't really deliver mail, but which make qmail-local think that it did. this is similar to the old sendmail trick of delivering mail to /dev/null, but doesn't actually open /dev/null and send mail there- it just plain doesn't send the message anywhere.

example, using "devnull" as the userid:

# useradd devnull
# cd ~devnull
# echo '#' > .qmail
# chmod 644 .qmail
# chown devnull .qmail
# ln .qmail-devnull .qmail-default

if you want the messages to go to an administrator instead of into a black hole, change the contents of the .qmail file to point somewhere else (i.e. "echo '&admin [at] server' > .qmail" etc.)

(2) add the recipient as a virtualdomain on your server, which delivers to the new dummy user.

example, to block everything sent to any "@domain.xyz" address, as well as everything sent to "badguy [at] spammer", assuming the same "devnull" dummy user from above:

# cd /var/qmail/control
# echo 'domain.xyz:devnull' >> virtualdomains
# echo 'badguy [at] spammer:devnull' >> virtualdomains
# chmod 644 virtualdomains
# svc -h /service/qmail-send

(disclaimer: i'm not actually doing this on any servers myself. i'm about 98% sure this works- well, i'm 100% sure the theory works, i'm 98% sure there are no typos in the examples above. test it before trusting it.)

if you want to set up different policies for different types of spammers (i.e. employees can't send mail to domain.xyz but managers can) then you'll need to set up either a second qmail server, or a second instance of qmail on the same machine (which can be done, but it's very very tricky), DON'T change the virtualdomains file in the new qmail instance, and tell the managers to use the new qmail instance instead of the old one.

- OR -

if you're willing to add a patch which you may not already have:

(1) install jay soffian's RCPTCHECK patch (which is also part of my own combined patch, and i think some of the other combined patches include it as well. if you're not sure, run "strings /var/qmail/bin/qmail-smtpd | grep RCPTCHECK" to see if you may already have it.)

http://www.soffian.org/downloads/qmail/qmail-smtpd-doc.html

(2) write a script/program which uses the values of the SENDER and RECIPIENT environment variables to determine whether the message should be accepted or not, and exits with the value 0 for "yes" or 111 for "no". make sure the program is executable by whatever userid qmail-smtpd runs as on your system (normally qmaild, although some mis-guided documentation out there will tell you to change it to some other userid, like "vpopmail" or "qscand". grrrr...)

a simple example might be...

#!/bin/sh
RCPT=`echo $RECIPIENT | tr 'A-Z' 'a-z'`
RDOM=`echo $RCPT | sed 's/^.*@//'`
if [ $RDOM = "@domain.xyz" ] ; then exit 111 ; fi
if [ $RCPT = "badguy [at] spammer" ] ; then exit 111 ; fi
exit 0

(again, disclaimer: not tested. the RCPTCHECK script i'm using on my own server is written in perl, until it reaches a final state that i'm happy with, and then i'm going to re-write it in C.)

(3) configure your qmail-smtpd service so that the RCPTCHECK environment variable points to your script/program, before qmail-smtpd is executed. this can be done in your tcpserver access control file, or if it will affect every sender IP, it's easier to add an "export" command to the service's "run" script.

because you can write whatever logic you want into this script/program, and because this takes effect within qmail-smtpd, this is a much more flexible way to handle these kinds of policies. there's no need to send messages into a black hole, because qmail-smtpd simply doesn't accept the messages to begin with. rejecting the message also provides the sender with some feedback, so they KNOW that their message wasn't delivered (which may be a good thing or a bad thing, depending on your situation.)

this method will not, however, redirect mail to a third party. something like that might be possible with a patch, however i'm not aware of any patch already written for this.

----------------------------------------------------------------
| John M. Simpson --- KG4ZOW --- Programmer At Large |
| http://www.jms1.net/ <jms1 [at] jms1> |
----------------------------------------------------------------
| http://video.google.com/videoplay?docid=-1656880303867390173 |
----------------------------------------------------------------
Attachments: PGP.sig (0.19 KB)


rugoli at gmail

Feb 4, 2010, 1:32 AM

Post #4 of 4 (1285 views)
Permalink
Re: Blacklist outgoing mail [In reply to]

On Wed, Feb 3, 2010 at 20:12, John Simpson <jms1 [at] jms1> wrote:
> this will send messages into a black hole...
>
> (1) create a dummy userid on the system. make sure the password is locked (most systems create new users in a "locked" state, but make sure) and set up .qmail and .qmail-default files in this user's home directory which don't really deliver mail, but which make qmail-local think that it did. this is similar to the old sendmail trick of delivering mail to /dev/null, but doesn't actually open /dev/null and send mail there- it just plain doesn't send the message anywhere.
>
> example, using "devnull" as the userid:
>
> # useradd devnull
> # cd ~devnull
> # echo '#' > .qmail
> # chmod 644 .qmail
> # chown devnull .qmail
> # ln .qmail-devnull .qmail-default
>
> if you want the messages to go to an administrator instead of into a black hole, change the contents of the .qmail file to point somewhere else (i.e. "echo '&admin [at] server' > .qmail" etc.)
I have tested this option and works perfect. Thanks!

Qmail users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.