OpenLDAPバインディングを使用した高度なEximおよびDovecotの構成

この記事では、これらのアプリケーションでの私の経験に基づいて、Exim、Dovecot、およびOpenLDAPが連携して動作するための高度な設定について説明します。 おそらく誰かが自分自身にとって興味深く、新しい何かを見つけるでしょう-これはこのトピックに関する次のハウツーを書く目的でした。



たとえば、PostfixやMySQLではなく、EximやOpenLDAPなのはなぜですか? Postfixは「箱から出してすぐに」正常に動作しますが、何か特別なものが必要な場合、すぐにPostfixが真珠のスクリプトでハングアップする不器用なモンスターに変わります。 MySQLはタスクに冗長であると考え、標準のOpenLDAPに置き換えました。アドレス帳にはさらに多くのLDAPが使用されています。 Dovecotは非常に高速で設定が簡単で、さらにEximとOpenLDAPの両方と完全に統合されます。



したがって、必要なソフトウェアをインストールします。ここではすべてが標準です(apt-get、yumなど)。 私はGentooを使用したので、emerge openldap dovecot exim(Eximとdovecotにはldapサポートが必要です)。



アセンブリ中に使用されるUSEフラグ:



net-nds/openldap-2.4.40-r3::x-overlay USE="berkdb crypt gnutls overlays samba sasl ssl syslog mail-mta/exim-4.85::gentoo USE="dkim dnsdb dovecot-sasl dsn exiscan-acl gnutls ldap lmtp maildir pam pkcs11 prdr spf ssl syslog net-mail/dovecot-2.2.18::gentoo USE="bzip2 caps ldap maildir managesieve pam sieve ssl zlib
      
      





OpenLDAPはキューの最初になり、すべてのメールアカウント、グループ、およびアライアンスはデータベースに保存され、OpenLDAPは電子メールクライアントのアドレス帳としても使用されます。 単純さと利便性のために、slapd-configは使用しませんが、すべての設定をテキストslapd.confに保存します。



標準のOpenLDAPにはメールの操作に適したスキームがないため、変更したバージョンのphamm.schemaとデフォルトのphamm-vacation.schemaを使用しました



OpenLDAPを構成する



ここではすべてが標準であるため、OpenLDAPのbasedn dc = domain、dc = comおよびssl証明書を作成する初期構成を省略します。



構成slapd.conf
 include /etc/openldap/schema/core.schema include /etc/openldap/schema/cosine.schema include /etc/openldap/schema/corba.schema include /etc/openldap/schema/inetorgperson.schema include /etc/openldap/schema/nis.schema include /etc/openldap/schema/misc.schema #    include /etc/openldap/schema/phamm.schema include /etc/openldap/schema/phamm-vacation.schema pidfile /run/openldap/slapd.pid argsfile /run/openldap/slapd.args #        TLS TLSCACertificateFile /etc/openldap/ssl/cacert.pem TLSCertificateFile /etc/openldap/ssl/newcert.pem TLSCertificateKeyFile /etc/openldap/ssl/newkey.pem TLSProtocolMin 3.1 TLSVerifyClient allow database bdb #   bdb , ,  . cachesize 100000 suffix "dc=domain,dc=com" rootdn "uid=manager,dc=domain,dc=com" #   rootpw **** directory /var/lib/openldap-data checkpoint 32 30 idletimeout 120 writetimeout 120 loglevel none overlay syncprov #    syncprov syncprov-checkpoint 100 10 syncprov-sessionlog 100 #   index uid,accountActive,vacationActive,createMaildir eq index cn,givenName,sn,mail pres,eq,sub index uidNumber,gidNumber,memberUid eq index entryCSN,entryUUID eq index objectClass,member,uniqueMember eq #      # ,    limits dn="uid=replicator,ou=services,dc=domain,dc=com" size=unlimited time=unlimited # ,  phpldapadmin limits dn="uid=ldapadmin,ou=services,dc=domain,dc=com" size=unlimited time=unlimited #  exim limits dn="uid=exim,ou=services,dc=domain,dc=com" size=unlimited time=unlimited #  nsswitch limits dn="uid=proxyagent,ou=services,dc=domain,dc=com" size=unlimited time=unlimited #       access to attrs=userPassword by dn.base="uid=ldapadmin,ou=services,dc=domain,dc=com" write by dn.base="uid=replicator,ou=services,dc=domain,dc=com" read by dn.base="uid=proxyagent,ou=services,dc=domain,dc=com" read by anonymous auth by self write by * none access to attrs=mail by dn.base="uid=ldapadmin,ou=services,dc=domain,dc=com" write by * read access to * by dn.base="uid=ldapadmin,ou=services,dc=domain,dc=com" write by users read by anonymous auth
      
      







必ずOpenLDAPのレプリケーションを構成してください(ここでもすべてが標準であるため、詳細は省略します)。 アドレス帳(./configure --enable-ipv6 = no --enable-syncprov = yes --enable-sssvlv = yes- with-tls = yes)。

また、sssvlvがOutlookで正しく機能するために、OpenLDAPソースにパッチを適用する必要がありました。

パッチ
 --- servers/slapd/schema_prep.c 2011-11-25 20:52:29.000000000 +0200 +++ servers/slapd/schema_prep.c 2011-11-29 13:46:57.000000000 +0200 @@ -915,6 +915,7 @@ offsetof(struct slap_internal_schema, si_ad_name) }, { "cn", "( 2.5.4.3 NAME ( 'cn' 'commonName' ) " "DESC 'RFC4519: common name(s) for which the entity is known by' " + "ORDERING caseIgnoreOrderingMatch " "SUP name )", NULL, 0, NULL, NULL, @@ -924,6 +925,7 @@ "DESC 'RFC4519: user identifier' " "EQUALITY caseIgnoreMatch " "SUBSTR caseIgnoreSubstringsMatch " + "ORDERING caseIgnoreOrderingMatch " "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{256} )", NULL, 0, NULL, NULL, (END)
      
      







2番目のサーバーは、読み取り専用のアドレス帳として機能します。



2番目のLDAPサーバーのslapd.confを構成します
 include /etc/ldap/schema/corba.schema include /etc/ldap/schema/core.schema include /etc/ldap/schema/cosine.schema include /etc/ldap/schema/inetorgperson.schema include /etc/ldap/schema/misc.schema include /etc/ldap/schema/nis.schema #  slapd         include /etc/ldap/schema/phamm-vacation.schema include /etc/ldap/schema/phamm.schema # Load dynamic backend modules: #modulepath /usr/lib/ldap #moduleload back_hdb.so #moduleload sssvlv.so # sssvlv     Outlook idletimeout 120 threads 8 sizelimit 1000 pidfile /var/run/slapd/slapd.pid argsfile /var/run/slapd/slapd.args loglevel 0 #        TLS TLSCACertificateFile /etc/ldap/ssl/ca.pem TLSCertificateFile /etc/ldap/ssl/ab.domain.com_crt.pem TLSCertificateKeyFile /etc/ldap/ssl/ab.domain.com_key.pem TLSProtocolMin 3.1 TLSVerifyClient allow database hdb #     hdb cachesize 100000 suffix "dc=domain,dc=com" rootdn "cn=replicator,ou=services,dc=domain,dc=com" rootpw ***** directory /var/lib/ldap checkpoint 32 30 idletimeout 120 writetimeout 120 overlay sssvlv #    TLS,  syncrepl syncrepl rid=001 # ID  provider=ldaps://domain.com #  ldaps:// ,    starttls     self-signed  type=refreshOnly interval=00:00:10:00 searchbase="dc=domain,dc=com" scope=sub schemachecking=off bindmethod=simple binddn="uid=replicator,ou=services,dc=domain,dc=com" #   posix   ou=services,   slapd.conf credentials=**** tls_cacertdir=/etc/ssl/certs tls_cacert=/etc/ldap/ssl/ca.pem tls_cert=/etc/ldap/ssl/ab.domain.com_crt.pem tls_key=/etc/ldap/ssl/ab.domain.com_key.pem tls_reqcert=allow index uid,accountActive,vacationActive eq index cn,givenName,sn,mail pres,eq,sub index uidNumber,gidNumber,memberUid eq index entryCSN,entryUUID eq index objectClass,member,uniqueMember eq #       limits dn="uid=replicator,ou=services,dc=domain,dc=com" size=unlimited time=unlimited #        limits users size=unlimited time=unlimited #    access to attrs=userPassword by dn.base="uid=ldapadmin,ou=services,dc=domain,dc=com" write by dn.base="uid=replicator,ou=services,dc=domain,dc=com" write by dn.base="uid=proxyagent,ou=services,dc=domain,dc=com" read by anonymous auth by self write by * none access to attrs=mail by dn.base="uid=ldapadmin,ou=services,dc=domain,dc=com" write by dn.base="uid=replicator,ou=services,dc=domain,dc=com" write by * read access to attrs=cn by dn.base="uid=ldapadmin,ou=services,dc=domain,dc=com" write by dn.base="uid=replicator,ou=services,dc=domain,dc=com" write by * read access to * by dn.base="uid=ldapadmin,ou=services,dc=domain,dc=com" write by dn.base="uid=replicator,ou=services,dc=domain,dc=com" write by users read by anonymous auth
      
      





phpldapadminを使用してLDAPデータベースを管理します。これは軽量で便利であり、アカウントを作成するために必要なテンプレートを柔軟に構成できるXMLテンプレートをサポートしているためです。 残念ながら、このプロジェクトは著者によって長い間放棄されており、現在開発されていません。



たとえば、メールアカウントを作成するためのサンプルテンプレート。

コード
  <objectClasses> <objectClass id="top"></objectClass> <objectClass id="inetOrgPerson"></objectClass> <objectClass id="posixAccount"></objectClass> #  posix  <objectClass id="VirtualMailAccount"></objectClass> #      phamm  <objectClass id="Vacation"></objectClass> #    phamm-vacation  </objectClasses> <attributes> <attribute id="givenName"> <display>First Name</display> <icon>ldap-uid.png</icon> <order>1</order> <page>1</page> </attribute> <attribute id="sn"> <display>Last Name</display> <onchange>=autoFill(cn;%givenName% %sn%)</onchange> <onchange>=autoFill(uid;%givenName|0-1/l%%sn/l%)</onchange> <onchange>=autoFill(loginShell;/sbin/nologin)</onchange> <onchange>=autoFill(FTPStatus;enabled)</onchange> <order>2</order> <page>1</page> </attribute> <attribute id="cn"> <display>Common Name</display> <order>3</order> </attribute> <attribute id="uid"> <display>UID</display> <onchange>=autoFill(homeDirectory;/home/%uid%)</onchange> <onchange>=autoFill(mailbox;/home/%uid%/Maildir)</onchange> <onchange>=autoFill(mail;%uid%@domain.com)</onchange> <onchange>=autoFill(company;My Company)</onchange> <order>4</order> <spacer>1</spacer> </attribute>
      
      





作成時には、次のLDAPデータベーススキームを使用します。



ou =人、dc =ドメイン、dc = com-メールアカウントを保存するためのコンテナ。

ou =グループ、dc =ドメイン、dc = com-posixグループを保存するためのコンテナ。

ou =サービス、dc =ドメイン、dc = com-システムサービスアカウント(posixアカウント)を格納するためのコンテナー。

ou =エイリアス、dc =ドメイン、dc = com-メールアライアンスを格納するコンテナ。



電子メールアカウントを作成するときに、私が変更したphammスキームの多くの属性が使用されますが、その使用はこの記事の範囲を超えています(たとえば、createMaildirまたはBackup)。 検索フィルターで使用されるものについてのみ言及します。

accountActive = TRUE | FALSE-アカウントまたはエイリアスを一時的に有効/無効にすることができます。

vacationInfo-不在メッセージのテキストが含まれています。

vacationActive-OoOメッセージを有効/無効にできます。

割り当て-ここでは明確です(例:割り当て= 4G)



そのため、OpenLDAPが構成および開始され、レプリケーションが機能し、phpldapadminの助けを借りて、最初のipupkinテストアカウントがメールアドレスipupkin@domain.comで作成されます。 将来、1つのdomain.comドメインのみが使用されるため、コンテナou = groups posixにドメイングループを作成し、このグループにipupkinを追加します。



この例では、すべてのサービスが同じLinuxサーバーで実行され、ldapデータベースを使用してシステム内のユーザーを識別するのが論理的なため、この手順をName Service Switch(nss)またはSystem Security Services Daemon(sssd)の肩に移動します。 また、このソリューションの利点は、必要に応じてSambaドメインに簡単に適応できることです。

まず、パッケージがnss_ldap(またはlibnss-ldapd)にインストールされていることを確認する必要があります。

/etc/nsswitch.confで、行をcompatからldap(またはSambaドメインの場合はwinbind)に変更します。

passwd:ファイルldap

シャドウ:ファイルldap

グループ:ファイルldap



次の内容で/etc/ldap.confファイルを作成します。



ldap.conf
uri ldap://127.0.0.1

uri ldap://192.168.0.1#2番目のフォールバックldapサーバー



ベースdc =ドメイン、dc = com

binddn uid = proxyagent、ou = services、dc = domain、dc = com#ouで事前作成済み= slapd.confで指定されたposixアカウント

bindpw *****



pam_filter objectclass = posixAccount

pam_login_attribute uid

pam_check_host_attrいいえ

pam_lookup_policy no

pam_member_attribute memberUid

pam_min_uid 1000

pam_max_uid 65535

ssl start_tls#SSLの代わりにTLSを使用

#証明書パスを指定する

tls_cacert /etc/openldap/ssl/ca.pem

tls_key /etc/openldap/ssl/mail_crt_new.pem

tls_cert /etc/openldap/ssl/mail_key_new.pem

tls_reqcertは許可します

tls_checkpeerいいえ

tls_ciphers TLSv1

スコープサブ

制限時間5

bind_timelimit 5

bind_policyソフト

nss_reconnect_tries 4

nss_reconnect_sleeptime 1

nss_reconnect_maxsleeptime 16

nss_reconnect_maxconntries 2



nssが機能し、ホームディレクトリが作成されていることを確認します(mkdir -m 700 / home ipupkin && chown ipupkin:domain / home / ipupkin)。

> id ipupkin

uid = 1057(ipupkin)gid = 1000(ドメイン)groups = 1000(ドメイン)

> ls -ld / home / ipupkin

drwx ------ 3 ipupkin domain 4096 Jun 22 15:50 / home / ipupkin



ipupkinユーザーがシステムに認識されたので、ipupkinはメールを送受信できる必要があります。



Dovecotを構成する



Dovecotを設定する際、ネストされた巨大なデフォルト設定をすべて削除し、便宜上、dovecot.confとdovecot-ldap.confの2つだけを作成しました。



dovecot.conf
auth_cache_negative_ttl = 10分

auth_debug = no

auth_debug_passwords = no

auth_mechanisms =プレーンログイン#TLSによって使用されるため、プレーンを許可

base_dir = / var / run / dovecot /

default_vsz_limit = 1024 M

disable_plaintext_auth = no

dotlock_use_excl = yes

lda_mailbox_autocreate = yes#必須

lda_mailbox_autosubscribe = yes#必須

聞く= *

mmap_disable = yes

mail_fsync =常に

mail_nfs_storage = no

mail_nfs_index = no

mail_debug = no

mail_location = maildir:〜/ Maildir#メールボックスを探す場所、maildir値はhomeDirectory属性から取得されます(この場合は/ home / ipupkin)。したがって、フルパスは/ home / ipupkin / Maildirになります。

mail_plugins = $ mail_pluginsクォータの期限切れ通知

manageieve_notify_capability = mailto

manageieve_sieve_capability = fileintoエンベロープエンコード文字休暇サブアドレスコンパレーターiを拒否します。ASCII数値関係正規表現imap4flagsコピーには変数本体が含まれます。

ssl_ca = </etc/dovecot/ssl/ca.pem

ssl_cert = </etc/dovecot/ssl/mail_crt_new.pem

ssl_key = </etc/dovecot/ssl/mail_key_new.pem

ssl_verify_client_cert = no

verbose_ssl = no



プロトコル= imap pop3ふるい



userdb {

args = /etc/dovecot/dovecot-ldap.conf#ldap configを接続します

ドライバー= ldap

}



passdb {

args = /etc/dovecot/dovecot-ldap-pass.conf#著者dovecotの推奨により、dovecot-ldap.confへのシンボリックリンク

ドライバー= ldap

}



サービス認証{

unix_listener auth-userdb {

モード= 0666

}

}



サービスimap-login {

process_min_avail = 6

service_count = 0

}



service pop3-login {

process_min_avail = 6

service_count = 0

}



#manageieve roundcube webmailプラグインで使用

サービスmanageieve-login {

process_min_avail = 6

service_count = 0

inet_listenerふるい{

ポート= 4190

}

}



サービスmanageieve {

}



サービス辞書{

unix_listener dict {

モード= 0666

}

}



#メールボックスが90%いっぱいになると、次のスクリプトが実行されます

サービスクォータ警告{

executable = script /etc/dovecot/quota-warning.sh#スクリプト自体は次のようになります

スクリプト
 #!/bin/sh PERCENT=$1 USER=$2 cat << EOF | /usr/libexec/dovecot/dovecot-lda -d $USER -o "plugin/quota=maildir:User quota:noenforcing" From: postmaster@domain.com Subject: Your mailbox is $PERCENT% full Content-Type: text/plain; charset="UTF-8" X-Priority: 2 Warning! Your mailbox is now $PERCENT% full. EOF
      
      









unix_listener quota-warning {

モード= 0666

}

}



プロトコルimap {

imap_client_workarounds = delay-newmail#Outlookのハック

mail_plugins =クォータimap_quota mail_log通知

}



プロトコルポップ{

pop3_client_workarounds = outlook-no-nuls oe-ns-eoh#Outlookのさまざまなハック

#pop3_uidl_format =%08Xu%08Xv#Outlookがサーバーにメールを保存するときに使用されます。この形式にはOutlook 2013で問題があります

pop3_uidl_format =%g

pop3_fast_size_lookups = yes#詳細については、Maildirのパフォーマンスのセクションを参照してください。

mail_plugins =

}



#メールを配信するためにEximが使用する論理配信エージェント(LDA)サービス。

プロトコルlda {

ホスト名= domain.com

mail_fsync =最適化

mail_plugins =ふるいの割り当て

postmaster_address = postmaster@domain.com

log_path =

info_log_path =

}



プロトコルシーブ{

}



#各種オプション添加剤

プラグイン{

quota = maildir:ユーザークォータ

quota_rule = *:ストレージ= 1M

quota_rule2 =ゴミ箱:無視

quota_rule3 =削除済みアイテム:無視

quota_rule4 =迷惑メール:無視

quota_rule5 =アーカイブ:無視

quota_rule6 =アーカイブ:無視

quota_warning = storage = 90 %% quota-warning 90%u#quota-warning.shスクリプトがトリガーされるメールボックスがいっぱいになる割合を指定する

ふるい=〜/ Maildir / .dovecot.sieve

Sieve_dir =〜/ Maildir / Sieve

expire_dict =プロキシ::期限切れ

期限切れ=ゴミ

expire2 =削除済みアイテム

expire3 =迷惑メール

expire_cache = yes

}







dovecot-ldap.conf
ホスト= 127.0.0.1

dn = uid = proxyagent、ou = services、dc = domain、dc = com

dnpass = *****

tls =いいえ

auth_bind = no

auth_bind_userdn = uid =%u、ou = people、dc = domain、dc = com

ldap_version = 3

ベース= dc =ドメイン、dc = com

deref = never

スコープ=サブツリー

user_attrs = homeDirectory = home、uidNumber = uid、gidNumber = gid、quota = quota_rule = *:storage =%$

user_filter =(&(objectClass = VirtualMailAccount)(accountActive = TRUE)(uid =%n)(mail = *))

pass_attrs = uid =ユーザー、userPassword =パスワード

pass_filter =(&(objectClass = VirtualMailAccount)(accountActive = TRUE)(uid =%u)(mail = *))

default_pass_scheme = SSHA





エラーがないことを確認し(dovecot -a)、dovecotを実行します。



最終:Eximのセットアップ



Eximを構成する際の主な目標は、スクリプトの拒否を最大化し、Eximのみを使用してすべての機能を実装することでした。 例外としてのみ、DebianがPythonでグレーリストに登録され、パールオオムギamavisd-newが使用されています。

Eximを設定するとき、2つのファイルも使用されます-ACLルールのメインのexim.confとacl_smtp。

また、オプションで、configにmailman用のルーターとトランスポートがあります。



exim.conf
CONFIG_PREFIX = / etc / exim

ACL_PREFIX = CONFIG_PREFIX / acls#すべてのACL設定はここに保存されます

DB_PREFIX = / var / spool / exim / db#パフォーマンスを向上させるには、tmpfsを使用することをお勧めします



#テンプレートはEximの強みであり、長い行を短い単語に簡単に置き換えることができます。

#mailmanのテンプレートを定義する

MM_HOME = / var / lib / mailman

MM_UID = mailman

MM_GID =郵便配達員

MM_WRAP = / usr / lib / mailman / mail / mailman

MM_LISTCHK = MM_HOME /リスト/ $ {lc :: $ local_part} /config.pck



ldap_default_servers = /var/run/openldap/slapd.sock:192.168.0.1#ldapサーバーへの接続方法を指定すると、2番目のサーバーがフォールバックとして使用されます。



INTERFACE = your_external_ip#Eximがハングする外部IPを指定します

BASEDN = dc =ドメイン、dc = com#basednサーバーldap



#このセクションでは、Eximロジックを定義する最も重要なテンプレートを示します



#エイリアスアドレスがエイリアスコンテナのメール属性の値と一致する場合、エイリアスをチェックします。エイリアスはVirtualMailAliasクラスにも属し、accountActive属性の値がTRUEである必要があります。

CHECK_1 = $ {lookup ldap {user = "uid = exim、ou = services、dc = domain、dc = com" pass = *** ldap:/// ou = aliases、dc = domain、dc = com?Mail? sub?(&(objectClass = VirtualMailAlias)(accountActive = TRUE)(mail = $ {quote_ldap:$ local_part @ $ domain}))}}



#受信者アドレスがピープルコンテナのメール属性の値と一致するかどうかアカウントを確認します。アカウントはVirtualMailAccountクラスにも属し、accountActive属性の値がTRUEである必要があります。

CHECK_2 = $ {lookup ldap {user = "uid = exim、ou = services、dc = domain、dc = com" pass = *** ldap:/// ou = people、dc = domain、dc = com?Mail? sub?(&(objectClass = VirtualMailAccount)(accountActive = TRUE)(mail = $ {quote_ldap:$ local_part @ $ domain}))}}



#停止されたアカウントを確認すると、アカウントはメールを受信できませんが、システムに残ります(産休中の従業員に関連)

CHECK_3 = $ {lookup ldap {user = "uid = exim、ou = services、dc = domain、dc = com" pass = *** ldap:/// ou = people、dc = domain、dc = com?Mail? sub?(&(objectClass = VirtualMailAccount)(accountActive = TRUE)(accountSuspend = TRUE)(mail = $ {quote_ldap:$ local_part @ $ domain})}}



#メールの転送先のアライアンスメンバーのリスト、maildrop属性の値

CHECK_DATA = $ {lookup ldapm {user = "uid = exim、ou = services、dc = domain、dc = com" pass = *** ldap:/// ou = aliases、dc = domain、dc = com?Maildrop? sub?(&(objectClass = VirtualMailAlias)(mail = $ {quote_ldap:$ local_part @ $ domain}))}}



#メールボックスへのパス、メールボックス属性の値

CHECK_MAILDIR = $ {lookup ldap {user = "uid = exim、ou = services、dc = domain、dc = com" pass = *** ldap:/// ou = people、dc = domain、dc = com?メールボックス? sub?(&(objectClass = VirtualMailAccount)(accountActive = TRUE)(mail = $ {quote_ldap:$ local_part @ $ domain}))}}



#OoOメッセージのテキスト、vacationInfo属性の値

CHECK_VACATION = $ {lookup ldap {user = "uid = exim、ou = services、dc = domain、dc = com" pass = *** ldap:/// ou = people、dc = domain、dc = com?VacationInfo? sub?(&(objectClass = VirtualMailAccount)(vacationActive = TRUE)(mail = $ {quote_ldap:$ local_part @ $ domain}))}}



#OoOメッセージのダブルコンマのハック、Eximのバグ660-修正されていないようです

VACATION = $ {sg {$ {lookup ldap {user = "uid = exim、ou = services、dc = domain、dc = com" pass = *** ldap:/// ou = people、dc = domain、dc = com?vacationInfo?sub?(&(objectClass = VirtualMailAccount)(vacationActive = TRUE)(mail = $ {quote_ldap:$ local_part @ $ domain}))}}} {,,} {、}}



domainlist_cache virt_domains = domain.com#ドメインは1つしかないため、それを示します。 多くのドメインを使用する場合は、データベースからドメインを選択するためのテンプレートを作成する必要があります。

domainlist_cache local_domains = localhost:mail.domain.com

hostlist relay_from_hosts = 127.0.0.1:192.168.0.0/16

アドレスリストnoautoreply_senders = DB_PREFIX / autoreply.noanswer.db



sender_unqualified_hosts = 127.0.0.1:192.168.0.0/16

recipient_unqualified_hosts = 127.0.0.1:192.168.0.0/16



local_interfaces = 0.0.0.0.25:0.0.0.0.26:0.0.0.0.465:0.0.0.0.587:127.0.0.1.10025

tls_on_connect_ports = 465



acl_smtp_connect = acl_check_connect

acl_smtp_helo = acl_check_helo

acl_smtp_mail = acl_check_mail

acl_smtp_rcpt = acl_check_rcpt

acl_smtp_data = acl_check_data

acl_smtp_dkim = acl_check_dkim



accept_8bitmime

auth_advertise_hosts =!127.0.0.1#ローカルホストにSMTP AUTHを提供しない

bounce_message_file = CONFIG_PREFIX / bounce.msg#バウンスメッセージの形式を指定します。これは次のとおりです。



バウンスメッセージ
件名:メール配信に失敗しました$ {if eq {$ sender_address} {$ bounce_recipient} {:送信者にメッセージを返す}}

****

このメッセージは、メール配信ソフトウェアによって自動的に作成されました。



メッセージ$ {if eq {$ sender_address} {$ bounce_recipient} {送信した} {送信者



<$ sender_address>



}}をすべての受信者に配信できませんでした。

次のアドレスが失敗しました:

****

配信試行中に次のテキストが生成されました:

****

-これは、すべてのヘッダーを含むメッセージのコピーです。 -****

-メッセージの本文は$ message_size文字長です。 最初だけ

-$ return_size_limit程度がここに含まれています。

****



bounce_return_size_limit = 100K

delay_warning = 15m:1h:99d

deliver_queue_load_max = 40

disable_ipv6

exim_group = vmail#すべてのメールサービス(dovecot、spamassassin、clamavなど)が1つのgidの下で動作することが望ましい

exim_user = vmail#すべてのメールサービス(dovecot、spamassassin、clamavなど)が1つのuidで動作することが望ましい

headers_charset = UTF-8#有効にすることをお勧めします

ignore_bounce_errors_after = 0s

local_scan_timeout = 0s

message_size_limit = 50M

never_users = root

no_message_logs

no_smtp_enforce_sync

no_syslog_duplication

primary_hostname = mail.domain.com

qualify_domain = domain.com

queue_only_load = 12

queue_run_max = 5

recipients_max = 500

recipients_max_reject

remote_max_parallel = 2

return_size_limit = 10000

rfc1413_query_timeout = 0s

smtp_accept_max = 500

smtp_accept_max_per_host = 500

smtp_accept_queue = 500

smtp_accept_queue_per_connection = 1000

smtp_accept_reserve = 15

smtp_banner = $ primary_hostname ESMTP ready $ tod_full

smtp_connect_backlog = 40

smtp_load_reserve = 20

smtp_return_error_details

split_spool_directory

strip_excess_angle_brackets

strip_trailing_dot

syslog_facility = mail#ログはsyslogサービスに送信されます

syslog_processname = exim

system_filter = DB_PREFIX / exim.filter#グローバルeximフィルター、ほとんど使用しません

timeout_frozen_after = 7d

tls_advertise_hosts =!127.0.0.1#localhostにTLSを提供しない



#証明書パスを指定する

tls_certificate = /etc/exim/ssl/mail_crt_new.pem

tls_privatekey = /etc/exim/ssl/mail_key_new.pem

tls_verify_certificates = /etc/exim/ssl/ca.pem



#メールヘッダーの形式を定義する

received_header_text = "受信済み:\

$ {def def:sender_rcvhost {from INTERFACE \ n \ t} \

{$ {if def:sender_ident {from relay}} \

$ {if def:sender_helo_name {(helo = $ {sender_helo_name})\ n \ t}}}} \

$ {qualify_domain}によって\

id $ {message_id} \

$ {if def:received_for {\ n \ tfor <$ received_for>}} "



#ここではLDAPは使用されないため、ウイルス対策とスパム対策を直接接続します。すべてが標準であるため、設定を省略します。

#av_scanner = clamd:/ tmp / clamd

#spamd_address = 127.0.0.1 783



ACLを開始



#ACL設定を接続します(以下を参照)

.include ACL_PREFIX / acl_smtp



#ルーターを作成します

ルーターを開始



#送信メール用のルーター

dnslookup:

ドライバー= dnslookup

domains =!+ local_domains :! + virt_domains

transport = remote_smtp

ignore_target_hosts = 0.0.0.0:127.0.0.0/8

no_more



#着信ルーター



#amavisの個人輸送(真珠の例外を1つ作成します:))

#amavis:

#ドライバー=手動ルート

#条件= $ {ifまたは{\

#{eq {$ interface_port} {10025}} \

#{eq {$ received_protocol} {spam-scanned}} \

#{eq {$ sender_address} {}} \

#{eq {$ sender_address_domain} {domain.com}} \

#{eq {$ sender_address_domain} {kaspersky.com}} \

#{eq {$ {lc:$ dkim_verify_status}} {pass}} \

#{match {$ sender_address_local_part} {-bounces}} \

#} {0} {1}}

#ドメイン= + virt_domains

#senders =!:!postmaster @ * :! mailer-daemon @ * :! nagios @ * :! monit @ *

#no_verify

#no_expn

#transport = amavis

#route_list = "* localhost byname"

#self =送信



自動応答:

ドライバー=受け入れる

ドメイン= + virt_domains

senders =!:!+ noautoreply_senders#autoreply.noanswer.dbで指定されたローカルホストと送信者に応答しない

条件= $ {ifおよび{\

{!eq {CHECK_VACATION} {}} \#テンプレート

{!match {$ h_precedence:} {junk | bulk | list}} \#ニュースレターに返信しない

{!def:header_Auto-Submitted:} \

{!def:header_List-Id:} \

}}

no_verify

no_expn

見えない

transport = auto_responder



#一時停止されたアカウント、一時停止されたアカウントの受信メールはすべて「ブラックホール」に送信されます

停止中:

ドライバー=リダイレクト

ドメイン= + virt_domains

条件= CHECK_3

forbid_file

forbid_pipe

forbid_filter_reply = true

データ=:ブラックホール:

no_more



#仮想エイリアス

エイリアス:

ドライバー=リダイレクト

ドメイン=!+ local_domains

condition = CHECK_1#ダブルチェック(acl_smtpの最初のチェック)があり、現在のアカウントにもエイリアスがある場合、より良いものは何も見つかりませんでした

forbid_file

forbid_pipe

forbid_filter_reply = true

data = CHECK_DATA#手紙の転送先

allow_fail

allow_defer



mailman_router:

ドライバー=受け入れる

ドメイン= domain.com

require_files = MM_LISTCHK#ファイルをチェックする代わりに、例えばaliasType = DL属性の値を確認できます。

local_part_suffix_optional

local_part_suffix = -admin: \

-bounces: -bounces+*: \

-confirm: -confirm+*: \

-join: -leave: \

-owner: -request: \

-subscribe: -unsubscribe

transport = mailman_transport



system_aliases:

driver = redirect

domains = +local_domains

errors_to =

no_verify

data = ${lookup{$local_part}partial0-dbm{DB_PREFIX/aliases.db}{$value}fail}

file_transport = address_file

pipe_transport = address_pipe

allow_fail

allow_defer



localuser:

driver = accept

domains = +local_domains: +virt_domains

check_local_user

transport = dovecot_lda # dovecot lda

cannot_route_message = Unknown account # Dovecot ,

no_more



###############################################################

begin transports

###############################################################



remote_smtp:

driver = smtp

helo_data = mail.domain.com

max_rcpt = 500

# DKIM

dkim_domain = domain.com

dkim_selector = dkim

dkim_private_key = DB_PREFIX/dkim.private.key

dkim_canon = relaxed



auto_responder:

driver = autoreply

from = "${local_part}@${domain}"

to = "${reply_address}"

once = "/var/spool/exim/autoreply/${local_part}@${domain}"

once_repeat = 1d # , LDAP (. phamm-vacation.schema)

headers = «Content-Type: text/plain; charset=utf-8\nContent-Transfer-Encoding: 8bit»

subject = ${rfc2047:Auto-Reply: $h_subject:}

text = VACATION # OoO

body_only

no_return_message



# dovecot

dovecot_lda:

driver = pipe

command = /usr/libexec/dovecot/dovecot-lda -f "$sender_address" -d "$local_part@$domain"

home_directory = /home/$local_part

delivery_date_add

envelope_to_add

return_path_add

log_output

log_defer_output

return_fail_output

freeze_exec_fail

temp_errors = 64: 69: 70: 71: 72: 73: 74: 75: 78



address_pipe:

driver = pipe

return_output



address_file:

driver = appendfile

current_directory = SPOOL

home_directory = SPOOL

create_directory

directory_mode = 0700

maildir_format

user = vmail

group = vmail

mode = 0600

no_check_owner

no_mode_fail_narrower



address_reply:

driver = autoreply



maillist_pipe:

driver = pipe

group = mail

return_fail_output

user = vmail



mailman_transport:

driver = pipe

command = MM_WRAP \

'${if def:local_part_suffix \

{${sg{$local_part_suffix}{-(\\w+)(\\+.*)?}{$1}}} \

{post}}' \

$local_part

current_directory = MM_HOME

home_directory = MM_HOME

user = MM_UID

group = MM_GID



#amavis:

# driver = smtp

# port = 10024

# allow_localhost



begin retry

* quota

* rcpt_4xx senders=: F,1h,10m

* * F,2h,10m; G,16h,1h,1.5; F,4d,6h



#

begin rewrite

root@* collector@domain.com Ttbcr



# SMTP AUTH

begin authenticators

plain:

driver = plaintext

public_name = PLAIN

server_prompts =:

server_condition = "${lookup ldap{user=uid=${quote_ldap_dn:$auth2},ou=people,BASEDN pass=${quote:$auth3} \

ldap:///ou=people,BASEDN?uid?sub?(&(uid=$auth2)(objectClass=VirtualMailAccount)(accountActive=TRUE))}{yes}fail}"

server_set_id = $auth2



login:

driver = plaintext

public_name = LOGIN

server_prompts = «Username::: Password::»

server_condition = "${lookup ldap{user=uid=${quote_ldap_dn:$auth1},ou=people,BASEDN pass=${quote:$auth2} \

ldap:///ou=people,BASEDN?uid?sub?(&(uid=$auth1)(objectClass=VirtualMailAccount)(accountActive=TRUE))}{yes}fail}"

server_set_id = $auth1





Eximの主要な武器は、アクセス制御リストです。

実際、記事全体はsmtp_rcptセクションの単一の構成のために考案されました。



acl_smtp
acl_check_connect:

accept hosts =: +relay_from_hosts: net-dbm;DB_PREFIX/whitelist_hosts.db

deny message = $sender_host_address is listed in $dnslist_domain ${if def:dnslist_text {($dnslist_text)}}

dnslists = sbl.spamhaus.org: xbl.spamhaus.org: bl.spamcop.net

accept



acl_check_dkim:

warn log_message = DKIM: Sender without DKIM signature

sender_domains = gmail.com: autodesk.com: paypal.com

dkim_signers = gmail.com: autodesk.com: paypal.com

dkim_status = none:invalid:fail

accept



acl_check_helo:

accept hosts =: +relay_from_hosts



#HELO is an open proxy

deny condition = ${if and {\

{isip{$sender_helo_name}}\

{eq{$sender_helo_name}{$sender_host_address}}\

}}

message = Open Proxy in HELO/EHLO (HELO was $sender_helo_name)

delay = 10s



#HELO is my hostname

deny condition = ${if match{$sender_helo_name}{$primary_hostname}}

message = Bad HELO — Host impersonating [$sender_helo_name]



#HELO is my address

deny condition = ${if eq{$interface_address}{$sender_helo_name}}

message = $interface_address is my address

accept



acl_check_mail:



accept hosts =: +relay_from_hosts

discard senders = dbm;DB_PREFIX/banned_senders.db: dbm;DB_PREFIX/scammers.db



#HELO required before MAIL

deny condition = ${if eq{$sender_helo_name}{}}

message = HELO/EHLO required before MAIL



accept



acl_check_rcpt:



#stub address

discard condition = ${if match{$local_part@$domain}{blackhole@domain.com}} # blackhole



deny message = Restricted characters in address

local_parts = ^[.]: ^.*[@%!/|]



#Reverse DNS check

warn condition = ${if and{{def:sender_host_address}{!def:sender_host_name}}{yes}{no}}

!hosts =: +relay_from_hosts: net-dbm;DB_PREFIX/whitelist_hosts.db

control = no_pipelining

delay = 10s # 10 ,

log_message = X-Host-Lookup-Failed: Reverse DNS lookup failed for $sender_host_address



# RATELIMIT SECTION



#Keep authenticated users under control

warn authenticated = *

ratelimit = 100 / 5m / strict / $authenticated_id

set acl_m100 = ${eval: ${sg{$sender_rate}{[.].*}{}} — $sender_rate_limit + 10}s

delay = $acl_m100

log_message = Ratelimit: Delay $acl_m100 for $authenticated_id. Rate limit $sender_rate / $sender_rate_period



#Limit local senders, exclude mailing-list agent

warn condition = ${if !match{$sender_address_local_part}{bounces}}

hosts =: 127.0.0.1

ratelimit = 1000 / 1h / per_rcpt / strict / $sender_host_address

set acl_m101 = ${eval: ${sg{$sender_rate}{[.].*}{}} — $sender_rate_limit}s

delay = $acl_m101

log_message = Ratelimit: Delay $acl_m101 for $sender_address ($sender_host_address). Rate $sender_rate / limit $sender_rate_limit



#Limit fast senders

hosts = !127.0.0.1: +relay_from_hosts

ratelimit = 100 / 5m / per_rcpt / strict

set acl_m102 = ${eval: ${sg{$sender_rate}{[.].*}{}} — $sender_rate_limit + 5}s

delay = $acl_m102

log_message = Ratelimit: Delay $acl_m102 for $sender_address ($sender_host_address). Rate $sender_rate / limit $sender_rate_limit



#Limit DSNs

warn condition = ${if and{\

{<{$recipients_count}{0}}\

{!eq{$sender_address_domain}{domain.com}}\

}}

senders =: postmaster@*: mailer-daemon@*

delay = 10s

log_message = Ratelimit: DSN delay 10s for $sender_address ($sender_host_address)



# END RATELIMIT SECTION



#Predefined acl variables for smtp_data level

warn set acl_m0 = $sender_address_domain

warn set acl_m1 = $domain

warn set acl_m2 = $sender_host_address

warn set acl_m3 = $sender_address

warn set acl_m4 = $local_part@$domain



#Verify recipient for our domains.

deny message = Unknown or disabled account

domains = +virt_domains

!local_parts = postmaster: *-admin: *-bounces: *-bounces+*: *-confirm: *-confirm+* :\

*-join: *-leave: *-owner: *-request: *-subscribe: *-unsubscribe



# , check_rcpt, .

!recipients = CHECK_1: CHECK_2



accept hosts =: +relay_from_hosts

control = dkim_disable_verify

#

accept authenticated = *

control = dkim_disable_verify



# , , 10 .

deny message = relay not permitted

!domains = +local_domains: +virt_domains

delay = 10s



# , ,

#Deny non-authorized senders with our own domain prefix

deny condition = ${if match{$sender_address_domain}{domain.com}}

!hosts =: +relay_from_hosts: +adobe_hosts: +microsoft_hosts: net-dbm;DB_PREFIX/whitelist_hosts.db

message = Sender domain is not allowed here

log_message = Sender $sender_address is not authenticated



#Dictionary attack protection

#Start

warn condition = ${if > {${eval:$rcpt_fail_count}}{4}{yes}{no}}

log_message = Ratelimit: Detected Dictionary Attack (Let $rcpt_fail_count bad recipients though before engaging)

set acl_m7 = 1



warn condition = ${if eq {${acl_m7}}{1}{1}{0}}

ratelimit = 0 / 1h / strict / per_conn

log_message = Ratelimit: Increment Connection Ratelimit — $sender_fullhost because of Dictionary Attack



drop condition = ${if eq {${acl_m7}}{1}{1}{0}}

log_message = Ratelimit: Number of failed recipients exceeded

#End



# , exim lastchange "%Y%m%d" . , .

, log_message, , .

#Alias statistic

warn

domains = +virt_domains

log_message = ALIAS: $local_part@$domain

recipients = CHECK_1



#

#Greylist section

defer message = $sender_host_address is not yet authorized to deliver \

mail from <$sender_address> to <$local_part@$domain>. Please try later

log_message = Sender $sender_address greylisted

domains = +virt_domains

!sender_domains = partial1()dbm;DB_PREFIX/whitelist_grey_domains.db

!authenticated = *

condition = ${readsocket{/var/run/greylistd/socket}\

{--grey %s $sender_address $local_part@$domain}{5s}{}{false}}



accept



acl_check_vrfy_expn_etrn:



accept hosts = 127.0.0.1



deny



acl_check_data:



# spamassassin, . SPAM Exim.



exim.filter :



exim.filter
if first_delivery then

headers remove X-Spam-Score:X-Spam-Report:X-Spam-Checker-Version:X-Spam-Status:X-Spam-Level



if "${if def:header_X-New-Subject: {there}}" is there

then

headers remove Subject

headers add «Subject: $rh_X-New-Subject:»

headers remove X-New-Subject

endif



endif







# no antispam check for relay hosts and authenticated users

# accept hosts =: +relay_from_hosts

# accept authenticated = *



# Antispam scan

# warn

# condition = ${if and {\

# {<{$message_size}{50k}}\

## {!eq{${mask:$acl_m2/16}}{192.168.0.0/16}}\

# {!eq{$sender_address}{}}\

## {!match_address{$sender_address}{dbm;DB_PREFIX/whitelist_spam_senders.db}}\

# {!match_domain{$acl_m0}{partial1()dbm;DB_PREFIX/whitelist_grey_domains.db}}\

## {match_domain{$acl_m1}{dbm;DB_PREFIX/domains_spam.db}}\

# }}

# spam = nobody:true/defer_ok

# set acl_m6 = $spam_score_int



# add new subj for global exim filter

# message = X-New-Subject: SPAM[$spam_score_int/80]: $rh_subject:

# condition = ${if and {\

# {def:spam_score_int}\

# {>{$spam_score_int}{80}}\

# }}



accept





実際、それがすべてです。



Eximを起動し、手紙をipupkinに送信し、ログを確認します...



All Articles