Here's my implementation of how to protect your mail server
from being used as an open relay but spammers but still allow
you custommers use it to send their mail.
I've written a patch for sendmail to incorporate a new
database type to acces data from MySQL, the code is not finished
but a big part of it is done, the code still contains bugs.
It's allmost done i still have 1 or 2 bugs to fix.
You can get it at http://www.colba.net/~paul/projects
Here's how it works:
First i created a database of the following type containing
all the users you have, or all the users that will use that service
(ex iPass users):
+--------------+----------------+--------------+
| username | IP | permit_relay |
+--------------+----------------+--------------+
| test_user | 10.0.0.0 | Y |
+--------------+----------------+--------------+
| another_user | 10.0.0.1 | N |
+--------------+----------------+--------------+
I'm using POP before SMTP to unlock access to the user for a certain
period of time to a given IP.
First a user will check his e-mail through POP and the pop
deamon will authenticate a user and then update the IP in the database
for that user and set the permit_relay flag to Y.
the query i use is the following:
update
set IP = , permit_relay = 'Y'
Here's the exemple of modification to Qualcomm Qpopper3.0 (right before
returning POP_SUCCESS):
------------ cut here --------------------------------------------------
mysql_init(&mysql);
snprintf(queryBuf,sizeof(queryBuf),"update %s set IP = '%s',permit_relay = 'Y'
where username = '%s'",RELAY_TABLE,p->ipaddr,p->user);
if(!mysql_real_connect(&mysql,HOST,USER,PASS,DB,0,NULL,0))
{
return(pop_msg(p,POP_FAILURE,"Error
connecting to database server(%s)",mysql_error(&mysql),HOST));
}
mysql_query(&mysql,queryBuf);
mysql_close(&mysql);
return(pop_msg(p,POP_SUCCESS,"Relay Database updated"));
------------ cut here --------------------------------------------------
Then i made the following modification to chech_rcpt sendmail.cf:
------------ cut here --------------------------------------------------
.
.
Krelay mysql -H -U -P -D -M