[Exim] VirtualDomains + MySQL

Page principale
Supprimer ce message
Répondre à ce message
Auteur: Alexei V. Alexandrov
Date:  
À: exim-users
Sujet: [Exim] VirtualDomains + MySQL
Hello everyone,

Recently i have posted a question about configuration of exim with
mysql to support virtualhosting using only mysql database. I think i
have made it available. What it does:

1. On a mail hub there are clients with virtual mailservers.
2. Each clients has a domainname name registered to domain specific
login.
3. All mail for a virtual domain (unhandled: no aliases no virtual
users) goes to the actual user`s mailbox. For example: Client
registered a domainname like hissdom.ain and got a login from us as
hisdom in this case any mail addressed any_user@??? is checked
against an alias table and in virtualusers table. If there is no data
found this address is handled by smartuser and this mail goes to
hisdom user`s mailbox.
4. The client is able to create other mailboxes in his domain. The
mails will be stored in a directory in a mailbox named like this:
virtual_login%hisdom.ain and is created with uid as hisdom and group
mail.
5. The client is also able to create aliases using aliases table for
his domain.

For me it is hard to explain it now... Here is the configuration i use
for exim. It`s version is 3.14 #6. I think that questions about
virtual hosting will come around and if this will work for me and
other there will a chance to put it in the faq.

cat exim.conf
------------------------------------------------------------------------
######################################################################
# Constants To Use                                                   #
######################################################################


MYSQL_LOCAL   = SELECT DISTINCT Domains.NAME FROM Domains, Clients \
                WHERE Domains.NAME = '${quote_mysql::$key}' AND \
                Clients.ACTIVE = 'TRUE' AND Domains.MNT = Clients.LOGIN


MYSQL_DOMAINS = SELECT DISTINCT Domains.NAME FROM Domains, Clients \
                WHERE Domains.NAME = '$domain' AND \
                Clients.ACTIVE = 'TRUE' AND Domains.MNT = Clients.LOGIN


MYSQL_ALIAS   = SELECT Aliases.ROUTETO FROM Aliases, Vusers WHERE \
                ALIASID='$local_part' AND DOMAIN = '$domain' AND \
                ACTIVE='TRUE' AND (Vusers.LOGIN=CONCAT(Aliases.ROUTETO,'%$domain') OR \
                LOCATE('@', Aliases.ROUTETO) > 0)


MYSQL_GETUID  = SELECT LOGIN FROM Clients,Domains WHERE \
                Domains.NAME='$domain' AND Clients.ACTIVE='TRUE'


######################################################################
#                    MAIN CONFIGURATION SETTINGS                     #
######################################################################


primary_hostname = my.host.name

local_domains = localhost:mysql;MYSQL_LOCAL

forbid_domain_literals

never_users = root

host_lookup = 0.0.0.0/0

receiver_verify

sender_verify

rbl_domains = rbl.maps.vix.com:dul.maps.vix.com:relays.orbs.org

mysql_servers = localhost/db/user/pass

end

######################################################################
#                      TRANSPORTS CONFIGURATION                      #
######################################################################


remote_smtp:
driver = smtp
command_timeout = 1m
connect_timeout = 10s

read_confirm:
  driver = pipe
  command = "/vhost/sbin/rrc.pl \
    ${original_local_part}@${original_domain} ${domain}"
  path = "/usr/sbin"
  user = postmaster


## фТБОУРПТФ ДМС ТЕБМШОЩИ РПМШЪПЧБФЕМЕК.
## оЙЮЕЗП ПУПВЕООПЗП ОЕ ДЕМБЕФ - УПИТБОСЕФ МЙЫШ РПЮФХ МЙЫШ РПД ЙНЕОЕН
## РПМШЪПЧБФЕМС

local_delivery:
driver = appendfile
file = /var/mail/${local_part}
delivery_date_add
envelope_to_add
return_path_add
shadow_transport = read_confirm
group = mail
mode = 0660

## ьФПФ ФТБОУРПТФ РТПУФП УПИТБОСЕФ РПЮФХ Ч ДЙТЕЛФПТЙА
## РПД РТПУФЩН ЙНЕОЕН ДМС ЧЙТФХБМШОПЗП ДПНЕОБ:
## virtual_login%virtual.dom.ain

virtual_localdelivery:
driver = appendfile
file = /var/mail/${local_part}%$domain
shadow_transport = read_confirm
user = ${lookup mysql{MYSQL_GETUID}{$value}fail}
group = mail
mode = 0660

address_pipe:
driver = pipe
return_output

address_file:
driver = appendfile
delivery_date_add
envelope_to_add
return_path_add

address_reply:
driver = autoreply

end

######################################################################
#                      DIRECTORS CONFIGURATION                       #
#             Specifies how local addresses are handled              #
######################################################################


## рТПЧЕТСЕФ ОБМЙЮЙЕ БМЙБУПЧ ОБ ФЕЛХЭЙК ДПНЕО. бМЙБУ ОБКДЕО, РЕТЕДБЕН
## ХРТБЧМЕОЙЕ УМЕД. РТБЧЙМХ.
##

mysql_system_aliases:
        driver = aliasfile
        search_type = mysql
        query = MYSQL_ALIAS
        file_transport = address_file
        pipe_transport = address_pipe
        qualify_preserve_domain
        user = exim


virtual_localuser:
        driver = aliasfile
        transport = virtual_localdelivery
        domains = mysql;MYSQL_DOMAINS
        search_type = mysql
        query = "SELECT LOGIN FROM Vusers where LOGIN = '$local_part%$domain'"


virtual_smartuser:
        driver = smartuser
        transport = local_delivery
        domains = mysql;MYSQL_DOMAINS
        new_address = ${lookup mysql{MYSQL_GETUID}{$value}fail}@${qualify_recipient}
        user = ${lookup mysql{MYSQL_GETUID}{$value}fail}
        no_more


userforward:
driver = forwardfile
file = .forward
no_verify
no_expn
check_ancestor
# filter
file_transport = address_file
pipe_transport = address_pipe
reply_transport = address_reply

localuser:
driver = localuser
transport = local_delivery

end

######################################################################
#                      ROUTERS CONFIGURATION                         #
#            Specifies how remote addresses are handled              #
######################################################################


lookuphost:
driver = lookuphost
transport = remote_smtp

end

######################################################################
#                      RETRY CONFIGURATION                           #
######################################################################


*                      *           F,2h,15m; G,16h,1h,1.5; F,4d,8h


end

######################################################################
#                      REWRITE CONFIGURATION                         #
######################################################################


end

######################################################################
#                   AUTHENTICATION CONFIGURATION                     #
######################################################################
------------------------------------------------------------------------


if i done something wrong or if there is a better way to do it please
send me an e-mail. I`m plaing with exim only a few days :-)

P.S.: Sorry for my poor english.
P.S.S.: And sorry for such a big posting :-)

Best regards,
Alexei V. Alexandrov                   [AA4460, AVA32-RIPN, AA1829-RIPE]
------------------------------------------------------------------------
*** Alexei V. Alexandrov -- www.elcomsoft.com ---- ava@??? ***
*** PGP Fingerprint:        6550 3949 FA86 E559  3036 E09F BBD9 B0C5 ***
------------------------------------------------------------------------