<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Abraxas &#187; exim</title>
	<atom:link href="http://www.effinger.org/blog/tag/exim/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.effinger.org/blog</link>
	<description>a personal knowledge base</description>
	<lastBuildDate>Sun, 06 Jun 2010 17:41:45 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Dovecot, Exim, OpenLDAP und getmail unter Ubuntu – (5) DSpam</title>
		<link>http://www.effinger.org/blog/2010/02/20/dovecot-exim-openldap-und-getmail-unter-ubuntu-%e2%80%93-5-dspam/</link>
		<comments>http://www.effinger.org/blog/2010/02/20/dovecot-exim-openldap-und-getmail-unter-ubuntu-%e2%80%93-5-dspam/#comments</comments>
		<pubDate>Sat, 20 Feb 2010 20:20:28 +0000</pubDate>
		<dc:creator>Markus Effinger</dc:creator>
				<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[dovecot]]></category>
		<category><![CDATA[dovecot-antispam]]></category>
		<category><![CDATA[DSPAM]]></category>
		<category><![CDATA[exim]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Sieve]]></category>

		<guid isPermaLink="false">http://www.effinger.org/blog/?p=914</guid>
		<description><![CDATA[<p>Es ist nun schon eine ganze Weile her seit ich zum letzten Mal über mein Mailserversetup geschrieben habe. In den letzten vier Blogartikeln wurde das Zusammenspiel der Grundkomponenten mit Dovecot, Exim, OpenLDAP und getmail konfiguriert. Jetzt geht es ans Feintuning &#8211; das Einrichten eines Spamfilters mit dspam und dovecot-antispam.</p>
Weshalb dspam?
<p>Warum dspam wird vielleicht manch einer [...]]]></description>
			<content:encoded><![CDATA[<p>Es ist nun schon eine ganze Weile her seit ich zum letzten Mal über mein Mailserversetup geschrieben habe. In den letzten vier Blogartikeln wurde das Zusammenspiel der Grundkomponenten mit <a href="http://www.effinger.org/blog/2009/03/22/dovecot-postfix-openldap-und-getmail-unter-ubuntu-2-dovecot/">Dovecot</a>, <a href="http://www.effinger.org/blog/2009/03/22/dovecot-exim-openldap-und-getmail-unter-ubuntu-3-exim/">Exim</a>, <a href="http://www.effinger.org/blog/2009/03/22/dovecot-exim-openldap-und-getmail-unter-ubuntu-1-openldap/">OpenLDAP</a> und <a href="http://www.effinger.org/blog/2009/03/22/dovecot-exim-openldap-und-getmail-unter-ubuntu-4-getmail/">getmail</a> konfiguriert. Jetzt geht es ans Feintuning &#8211; das Einrichten eines Spamfilters mit <a href="http://dspam.sourceforge.net/">dspam</a> und <a href="http://johannes.sipsolutions.net/Projects/dovecot-antispam">dovecot-antispam</a>.</p>
<h2>Weshalb dspam?</h2>
<p>Warum dspam wird vielleicht manch einer fragen und nicht das weitverbreitetere spamassassin? Ich habe mich für dspam entschieden, weil es anders als Spamassassin <span style="text-decoration: underline;">nicht</span> regelbasiert ist. Spamassassin legt bestimmte Regeln fest, nach denen Punkte vergeben werden und kombiniert dies mit lernenden Elementen (je nach Konfiguration). Regelbasiertes Filtern von Nachrichten hat einen Vorteil: Man hat einen sofort <span style="text-decoration: underline;">einigermaßen</span> brauchbaren Spamfiltern. Einigermaßen sage ich deswegen, weil natürlich statische Filter so allgemein sein müssen, dass sie für den eigenen spezifischen Spamschutz nicht maßgeschneidert sein können. Man wird damit, wenn man die Regeln auch noch ein bischen für sich anpasst weit kommen, allerdings sind dem Grenzen gesetzt. Mit dspam setze ich auf einen Spamfilter, der rein auf adaptives Lernen setzt und dabei <a href="http://dspam.irontec.com/faq.shtml#1.16">modernste Algorithmen</a> einsetzt. Das hat zwar den Nachteil, dass es eine Lernphase braucht und deshalb anfangs einen relativ hohen Anteil von Spam/Ham nicht richtig klassifiziert, mit der Zeit jedoch erhält man einen auf die persönlichen Bedürfnisse maßgeschneiderten Spamfilter. Diese Argumentation findet sich übrigens auch in der <a href="http://dspam.irontec.com/faq.shtml#1.7">DSPAM FAQ</a>. Ob das jetzt tatsächlich so ist, wird sich bei mir im Praxistest zeigen. Ich werde berichten..</p>
<h2>Das Spamfilter-Setup im Überblick</h2>
<p>In diesem Abschnitt möchte ich einen Überblick darüber geben, wie sich dspam in die Grundkonfiguration einfügt. Zunächst wird jede Nachricht, die exim zustellt, vor der Übergabe an den dovecot local delivery agent (LDA) von dspam analysiert und das Ergebnis im Mailheader festgehalten. Per Sieve-Filterregel kann man dann die Spammails in den Spamordner verschieben lassen. Wenn eine Mail falsch klassifiziert ist, kann man sie &#8211; falls es sich richtigerweise um Spam handelt &#8211; an spam@myserver oder andernfalls an ham@myserver schicken. Auf Dauer wäre das jedoch sehr aufwendig. Deswegen gibt es dovecot-antispam, ein Plugin für dovecot, welches beim Verschieben von Nachrichten in den Spamordner diese an spam@myserver schickt bzw. beim Verschieben von Nachrichten aus dem Spamordner in normale Ordner (nicht den Papierkorb) diese an ham@myserver schickt. DSpam kann die nutzerspezifischen Daten auf verschiedene Weisen speichern. In diesem Howto wird MySQL als Backend für dspam genutzt.</p>
<h2>Installation und Kompilieren benötigter Pakete</h2>
<p>So, beginnen wir mit einer kleinen Korrektur unserer Exim-Installation, die später bei der Prüfung von Paketabhängigkeiten wichtig wird. Wir installieren nämlich das Paket exim, welches auf eines der verschiedenen exim-Pakete verweist (wir haben <a href="http://www.effinger.org/blog/2009/03/22/dovecot-exim-openldap-und-getmail-unter-ubuntu-3-exim/">im dritten Teil des Howtos</a> den exim4-daemon-heavy installiert). Zusätzlich benötigen wir noch MySQL, das Dovecot-Antispam Plugin und dbconfig-common zur Einrichtung eines MySQL-Benutzers. Bei der Installation wird übrigens nach dem MySQL-Root-Passwort gefragt, bitte dieses unbedingt merken, denn wir benötigen es später noch.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> exim4 dovecot-antispam mysql-server dbconfig-common</pre></div></div>

<p>Im nächsten Schritt installieren wir dspam. Ich habe mich allerdings dafür entschieden, nicht die in den Repositories erhältliche Version 3.6.8 zu verwenden, sondern selbst die Pakete für die Version 3.9.0 RC2 zu erstellen. Dabei bin ich analog zu der <a href="https://juxtaposition.axley.net/2007/11/postfix-dspam-3-1.html">Beschreibung von Jason Axley</a> vorgegangen</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> build-essential
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> build-dep dspam</pre></div></div>

<p>Glücklicherweise gibt es einen aktiven Debian-Nutzer, der quasi alles (Sourcen+Patches) in einem Repository öffentlich zur Verfügung stellt unter <a href="http://packages.kirya.net/debian/pool/main/d/dspam/">http://packages.kirya.net/debian/pool/main/d/dspam/</a> (übrigens gibt es auch eine <a href="http://www.kirya.net/articles/setting-up-dspam-as-a-filter-for-postfix-on-debian-etch/">Anleitung auf kirya.net</a>). Von dort laden wir nun die Quelldateien und Patches herunter, entpacken sie und wechseln in das Unterverzeichnis dspam</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>packages.kirya.net<span style="color: #000000; font-weight: bold;">/</span>debian<span style="color: #000000; font-weight: bold;">/</span>pool<span style="color: #000000; font-weight: bold;">/</span>main<span style="color: #000000; font-weight: bold;">/</span>d<span style="color: #000000; font-weight: bold;">/</span>dspam<span style="color: #000000; font-weight: bold;">/</span>dspam_3.9.0~rc2+git20091231.orig.tar.gz
<span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>packages.kirya.net<span style="color: #000000; font-weight: bold;">/</span>debian<span style="color: #000000; font-weight: bold;">/</span>pool<span style="color: #000000; font-weight: bold;">/</span>main<span style="color: #000000; font-weight: bold;">/</span>d<span style="color: #000000; font-weight: bold;">/</span>dspam<span style="color: #000000; font-weight: bold;">/</span>dspam_3.9.0~rc2+git20091231-1.debian.tar.gz
<span style="color: #c20cb9; font-weight: bold;">tar</span> xvzf dspam_3.9.0~rc2+git20091231.orig.tar.gz
<span style="color: #c20cb9; font-weight: bold;">tar</span> xvzf dspam_3.9.0~rc2+git20091231-1.debian.tar.gz <span style="color: #660033;">-C</span> dspam
<span style="color: #7a0874; font-weight: bold;">cd</span> dspam</pre></div></div>

<p>Dann editieren wir die Datei debian/control, um die Paketabhängigkeiten so zu verändern, dass auch exim als Delivery Agent akzeptiert wird. Wir ergänzen deshalb in der depends-Zeile exim. Aus</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">Package: dspam
Architecture: any
Depends: ${misc:Depends}, procmail | maildrop | courier-maildrop | sensible-mda, lsb-base (&gt;= 3.0-6), ${shlibs:Depends}</pre></div></div>

<p>wird dann</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">Package: dspam
Architecture: any
Depends: ${misc:Depends}, exim4 | procmail | maildrop | courier-maildrop | sensible-mda, lsb-base (&gt;= 3.0-6), ${shlibs:Depends}</pre></div></div>

<p>Nun können wir die Binärpakete erstellen und installieren mit</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">fakeroot debian<span style="color: #000000; font-weight: bold;">/</span>rules binary
<span style="color: #7a0874; font-weight: bold;">cd</span> ..
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">dpkg</span> <span style="color: #660033;">-i</span> dspam_3.9.0~rc2+git20091231-<span style="color: #000000;">1</span>_i386.deb libdspam7_3.9.0~rc2+git20091231-<span style="color: #000000;">1</span>_i386.deb libdspam7-drv-mysql_3.9.0~rc2+git20091231-<span style="color: #000000;">1</span>_i386.deb dspam-doc_3.9.0~rc2+git20091231-<span style="color: #000000;">1</span>_all.deb</pre></div></div>

<p>Dabei werden wir gefragt, ob die Datenbankkonfiguration jetzt oder manuell (später) erfolgen soll. Wir wählen die erste Option. Nun wird nach dem MySQL-Passwort von oben gefragt, das wir eingeben. Das Passwort für dspam können wir automatisch festlegen lassen.</p>
<h2>Konfigurationsdateien</h2>
<p>Ich habe mir die Mühe gemacht und die im Vergleich zur Standardkonfiguration, die in den Teilen (1) bis (4) beschrieben wurde, angepassten Dateien in einem <a href="http://www.effinger.org/blog/wp-content/uploads/2010/02/modified-configfiles-mailsystem-with-spam.tar.gz">Archiv</a> zusammenzupacken. Dieses Archiv ist damit <em>kein</em> Ersatz für das <a href="http://www.effinger.org/blog/wp-content/uploads/2009/03/configfiles-mailsystem.tgz">dort aufgeführte Paket der Konfigurationsdateien</a>, sondern vielmehr eine Ergänzung. Wichtige Anmerkung: Die Konfigurationsdateien können immer nur Ausgangspunkt für die eigene Konfiguration sein u.a. auch deshalb, weil die Berechtigungen für diese Dateien angepasst werden müssen!</p>
<h2>Konfiguration von dspam</h2>
<p>Jetzt machen wir uns ans Eingemachte, der Konfiguration von dspam, welches leider keine sehr ausführliche Dokumentation bietet. Es gibt jedoch eine <a href="http://www.mail-archive.com/dspam-user@lists.sourceforge.net/msg00840.html">kurze Quick-and-Dirty Anleitung von der dspam-user Mailingliste</a> und in der Readme unter /usr/share/doc/dspam/README.gz sind auch einige Informationen zu finden. Außerdem fand ich die Kommentare in einer <a href="http://www.scribd.com/doc/8019538/Dspam-Pop3-Proxy-Clamav">weiteren Anleitung</a> sehr hilfreich. Wir passen zunächst das MySQL-Datenbankschema an. Ich bevorzuge nämlich das geschwindigkeitsoptimierte Datenbankschema gegenüber dem speicherplatzoptimierten, welches standardmäßig installiert wird. Deshalb habe ich mit</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">mysql <span style="color: #660033;">-u</span> root <span style="color: #660033;">-p</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;drop database dspam; create database dspam; GRANT SELECT, INSERT, UPDATE, DELETE ON dspam.* to dspam@localhost identified by '<span style="color: #007800;">$(sudo cat /etc/dspam/dspam.d/mysql.conf | grep MySQLPass | cut -f3)</span>';&quot;</span></pre></div></div>

<p>erstmal das komplette dspam -Schema gelöscht und neu erzeugt. Dazu wird natürlich wieder das MySQL root Passwort von oben benötigt. Anschließend installieren wir mit</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">mysql <span style="color: #660033;">-u</span> dspam -p$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>dspam<span style="color: #000000; font-weight: bold;">/</span>dspam.d<span style="color: #000000; font-weight: bold;">/</span>mysql.conf <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> MySQLPass <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">cut</span> -f3<span style="color: #7a0874; font-weight: bold;">&#41;</span> dspam <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>doc<span style="color: #000000; font-weight: bold;">/</span>libdspam7-drv-mysql<span style="color: #000000; font-weight: bold;">/</span>sql<span style="color: #000000; font-weight: bold;">/</span>mysql_objects-speed.sql</pre></div></div>

<p>das geschwindigkeitsoptimierte Datenbankschema. Wer alternativ doch das speicherplatzoptimierte Schema verwenden will, installiert es mit einem</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">mysql <span style="color: #660033;">-u</span> dspam -p$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>dspam<span style="color: #000000; font-weight: bold;">/</span>dspam.d<span style="color: #000000; font-weight: bold;">/</span>mysql.conf <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> MySQLPass <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">cut</span> -f3<span style="color: #7a0874; font-weight: bold;">&#41;</span> dspam <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>doc<span style="color: #000000; font-weight: bold;">/</span>libdspam7-drv-mysql<span style="color: #000000; font-weight: bold;">/</span>sql<span style="color: #000000; font-weight: bold;">/</span>mysql_objects-space.sql</pre></div></div>

<p>Nun schaffen wir die Voraussetzungen dafür, dass virtuelle Benutzer verwendet werden können. Ich habe mich dafür entschieden, dass Datenbankschema so einzurichten, dass nicht existierende Benutzer automatisch angelegt werden.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">mysql <span style="color: #660033;">-u</span> dspam -p$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>dspam<span style="color: #000000; font-weight: bold;">/</span>dspam.d<span style="color: #000000; font-weight: bold;">/</span>mysql.conf <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> MySQLPass <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">cut</span> -f3<span style="color: #7a0874; font-weight: bold;">&#41;</span> dspam <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>doc<span style="color: #000000; font-weight: bold;">/</span>libdspam7-drv-mysql<span style="color: #000000; font-weight: bold;">/</span>sql<span style="color: #000000; font-weight: bold;">/</span>virtual_users.sql</pre></div></div>

<p>Wer alternativ die Benutzer manuell anlegen will, führt stattdessen</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">mysql <span style="color: #660033;">-u</span> dspam -p$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>dspam<span style="color: #000000; font-weight: bold;">/</span>dspam.d<span style="color: #000000; font-weight: bold;">/</span>mysql.conf <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> MySQLPass <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">cut</span> -f3<span style="color: #7a0874; font-weight: bold;">&#41;</span> dspam <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>doc<span style="color: #000000; font-weight: bold;">/</span>libdspam7-drv-mysql<span style="color: #000000; font-weight: bold;">/</span>sql<span style="color: #000000; font-weight: bold;">/</span>virtual_user_aliases.sql</pre></div></div>

<p>aus. Jetzt passen wir die Datei /etc/dspam/dspam.d/mysql.conf so an, dass wir virtuelle Benutzer nutzen und die Verbindung von dspam zu MySQL über einen Unix-Socket hergestellt wird (Passwort &#8211; hier donotchange &#8211; unbedingt so lassen, wie es voreingestellt ist). Mit der Option MySQLUIDInSignature legen wir fest, dass in der DSPAM-Signatur der Benutzer gespeichert wird, für den die Spam-Klassifizierung durchgeführt wurde, so dass zwei serverweite Mail-Adressen (hier ham@ und spam@) ausreichen, um die Mail umzuklassifizieren.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">MySQLServer             /var/run/mysqld/mysqld.sock
MySQLUser               dspam
MySQLPass               donotchange
MySQLDb         dspam
MySQLReconnect          true
MySQLVirtualTable               dspam_virtual_uids
MySQLVirtualUIDField            uid
MySQLVirtualUsernameField       username
MySQLUIDInSignature     on</pre></div></div>

<p>Auch die Datei /etc/dspam/dspam.conf muss angepasst werden. Wir legen secmail, der Benutzer, unter dem der Dovecot LDA Mails zustellt und mit dem später dspam von exim aufgerufen wird, als vertrauenswürdigen Benutzer fest und schließen außerdem die Konfigurationsdateien im Verzeichnis /etc/dspam/dspam.d mitein. Zudem soll die dspam-Signatur nur im Header sein, was mit der Preference  signatureLocation eingestellt wird. Die <a href="http://dspamwiki.expass.de/Preferences_Attributes">Bedeutung der einzelnen Preference-Optionen</a> wird im dspam-Wiki erklärt. Der Standardpfad für dspam.pid muss aufgrund von Berechtigungsproblemen korrigiert werden. Wir ergänzen bzw. ändern deshalb folgende Zeilen</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Trust user secmail</span>
Trust secmail
&nbsp;
<span style="color: #666666; font-style: italic;"># Changed to only have MessageIDs in the header</span>
Preference <span style="color: #ff0000;">&quot;signatureLocation=headers&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Change dspam.pid location to</span>
ServerPID               <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span>dspam<span style="color: #000000; font-weight: bold;">/</span>dspam.pid
&nbsp;
<span style="color: #666666; font-style: italic;"># dspam only has to work together with the dspam client in our configuration</span>
ServerMode dspam
&nbsp;
<span style="color: #666666; font-style: italic;"># Authetication password required for dspam client</span>
<span style="color: #666666; font-style: italic;"># change secret to something else!!</span>
ServerPass.Relay1      <span style="color: #ff0000;">&quot;secret&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Use local unix socket to minimize overhead</span>
ServerDomainSocketPath <span style="color: #ff0000;">&quot;/tmp/dspam.sock&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Parameters used by dspam client to connect  to the server</span>
<span style="color: #666666; font-style: italic;"># change secret to the password you have chosen above..</span>
ClientHost     <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>dspam.sock
ClientIdent    <span style="color: #ff0000;">&quot;secret@Relay1&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Include config files from /etc/dspam/dspam.d</span>
Include <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>dspam<span style="color: #000000; font-weight: bold;">/</span>dspam.d<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<p>Als nächstes editieren wir /etc/default/dspam und setzen die Variable START auf YES, damit dspam im Daemon-Mode beim Hochfahren des Systems gestartet wird.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Variables for dspam.</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Do start dspam.</span>
<span style="color: #007800;">START</span>=<span style="color: #c20cb9; font-weight: bold;">yes</span></pre></div></div>

<p>Das Startskript für dspam wird angepasst, da dspam nicht automatisch in den Hintergrund geht. Deshalb editieren wir /etc/init.d/dspam und ergänzen die Option &#8211;background. Aus</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">        start-stop-daemon <span style="color: #660033;">--start</span> <span style="color: #660033;">--quiet</span> <span style="color: #660033;">--pidfile</span> <span style="color: #007800;">$PIDFILE</span> <span style="color: #660033;">--chuid</span> <span style="color: #007800;">$USER</span> <span style="color: #660033;">--exec</span> <span style="color: #007800;">$DAEMON</span> <span style="color: #660033;">--</span> <span style="color: #007800;">$DAEMON_ARGS</span> \
        <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">2</span></pre></div></div>

<p>wird somit</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">        start-stop-daemon <span style="color: #660033;">--start</span> <span style="color: #660033;">--quiet</span> <span style="color: #660033;">--pidfile</span> <span style="color: #007800;">$PIDFILE</span> <span style="color: #660033;">--chuid</span> <span style="color: #007800;">$USER</span> <span style="color: #660033;">--exec</span> <span style="color: #007800;">$DAEMON</span> <span style="color: #660033;">--background</span> <span style="color: #660033;">--</span> <span style="color: #007800;">$DAEMON_ARGS</span> \
        <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">2</span></pre></div></div>

<p>Jetzt fügen wir noch den Benutzer secmail zur Gruppe dspam hinzu, damit es beim Aufruf von exim, der unter dem Nutzer secmail erfolgt, keine Berechtigungsprobleme gibt.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> adduser secmail dspam</pre></div></div>

<p>Nun können wir dspam im Daemon-Modus testen, indem wir es via</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> dspam <span style="color: #660033;">--debug</span> <span style="color: #660033;">--daemon</span></pre></div></div>

<p>aufrufen, um es via Strg-C nach einer Minute beenden. Ob es Probleme gibt, sollte man anhand der Logdateien im Verzeichnis /var/log/dspam und der Syslog verfolgen. Wenn das soweit geklappt hat, starten wir dspam dauerhaft mit</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> service dspam start</pre></div></div>

<p>Nun prüfen wir das Zusammenspiel von Client und Server und legen gleichzeitig einen Benutzer namens globaluser an. Diesen Benutzer benötigen wir, da dspam beim Reklassifizieren einer Mail die Angabe eines Parameters &#8211;user mit gültigem User verlangt, selbst wenn es eigentlich anhand der dspam-Signatur auf den Benutzer schließen könnte, für den die Mail klassifiziert wurde. <a href="http://www.dovecot.org/list/dovecot/2006-April/012626.html">Ryan Kolak beschreibt dieses Problem ausführlicher</a>, das schon <a href="http://old.nabble.com/antispam---Unable-to-determine-the-destination-user-td20211120.html">häufiger diskutiert</a> wurde und bei dem es sich meiner Meinung nach um einen Bug handelt (Fehlermeldung:  Unable to determine the destination user). Wenn wir den Befehl</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">echo</span> Subject:<span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #660033;">-u</span> secmail dspam <span style="color: #660033;">--client</span> <span style="color: #660033;">--debug</span> <span style="color: #660033;">--mode</span>=notrain <span style="color: #660033;">--user</span> globaluser <span style="color: #660033;">--deliver</span>=spam,innocent <span style="color: #660033;">--stdout</span></pre></div></div>

<p>ausführen und anschließend die dspam-Statistik mit</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> dspam_stats</pre></div></div>

<p>abrufen, sollten wir folgendes Ergebnis erhalten</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">globaluser        TP:     <span style="color: #000000;">0</span> TN:     <span style="color: #000000;">1</span> FP:     <span style="color: #000000;">0</span> FN:     <span style="color: #000000;">0</span> SC:     <span style="color: #000000;">0</span> NC:     <span style="color: #000000;">0</span></pre></div></div>

<p>Falls Fehler aufgetreten sind, werden diese in den obigen Logdateien bzw.der Syslog festgehalten. Die Konfiguration von dspam ist nun abgeschlossen. Einen kleinen <a href="http://www.mail-archive.com/dspam-users@lists.nuclearelephant.com/msg00156.html">Tip zu dspam von der dspam-user Mailingliste</a>, möchte ich aber noch loswerden. Mit</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">strings</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">which</span> dspam<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> build</pre></div></div>

<p>lässt sich feststellen, welche Parameter beim Kompilieren von dspam verwendet wurden. Das kann hilfreich sein, denn bei dspam werden viele Optionen schon beim Kompilieren festgelegt.</p>
<h2>Anpassung der exim-Konfiguration</h2>
<p>Jetzt machen wir uns daran, Exim zu konfigurieren. Hier habe ich mich an der <a href="http://www.rm-f.de/cms/?q=node/80">Anleitung von Robert Fendt</a> und einer <a href="http://www.directadmin.com/forum/showpost.php?p=22430&amp;postcount=2">Dokumentation in einem Forum</a> orientiert. Zunächst fügen wir zu den bestehen Transporten an die lokalen Mailboxen zwei Zeilen hinzu. Der transport_filter leitet die Nachrichten durch den Spamfilter während die headers_remove Zeile dazu führt, dass in der Nachricht vorhandene DSpam-Header entfernt werden, so dass diese Header tatsächlich nur von dspam stammen können. Wir editieren also die beiden Dateien /etc/exim4/conf.d/transport/30_exim4-config_dovecot_delivery_pipe und /etc/exim4/conf.d/transport/30_exim4-config_dovecot_delivery_pipe_secmail und ergänzen die beiden erwähnten Zeilen:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">  driver = pipe
  transport_filter = <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>dspam <span style="color: #660033;">--deliver</span>=innocent,spam <span style="color: #660033;">--user</span> <span style="color: #ff0000;">&quot;GET_LOCAL_MAIL&quot;</span> <span style="color: #660033;">--stdout</span>
  headers_remove = X-DSPAM-Result:X-DSPAM-Processed:X-DSPAM-Confidence:X-DSPAM-Probability:X-DSPAM-Signature
  <span style="color: #7a0874; font-weight: bold;">command</span> = <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>dovecot<span style="color: #000000; font-weight: bold;">/</span>deliver <span style="color: #660033;">-d</span> <span style="color: #ff0000;">&quot;GET_LOCAL_MAIL&quot;</span></pre></div></div>

<p>Jetzt müssen wir noch die beiden Mail-Adressen spam@myserver und ham@myserver einrichten. Natürlich sollen nur vom Server selbst oder von authentifizierten Benutzern E-Mails an diese Adressen geschickt werden dürfen. In der Datei /etc/exim4/conf.d/main/00_local_macros ergänzen wir deshalb Macros für eine Hostliste und diese beiden E-Mail-Adressen</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># @[] list of all local IPs</span>
<span style="color: #666666; font-style: italic;"># If exim is used localy in batch mode (exim4 -bs) then &quot;$host&quot; is empty, the &quot;: :&quot; adds the empty string.</span>
hostlist own_hosts = <span style="color: #000000; font-weight: bold;">@</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> : :
&nbsp;
<span style="color: #666666; font-style: italic;"># address for reclassifying/learning false positive spam mails</span>
MAIL_ADDRESS_HAM = ham
&nbsp;
<span style="color: #666666; font-style: italic;"># address for reclassifying/learning undetected spam</span>
MAIL_ADDRESS_SPAM = spam</pre></div></div>

<p>Nun verweigern wir allen nicht authentifizierten Usern von entfernten Hosts das Senden von Mails durch Ergänzung der folgenden Zeilen in der Datei /etc/exim4/conf.d/acl/30_exim4-config_check_rcpt (bitte unbedingt nach der Stelle mit accept authenticated=*)</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Accept if the message arrived over an authenticated connection, from</span>
<span style="color: #666666; font-style: italic;"># any host. Again, these messages are usually from MUAs, so recipient</span>
<span style="color: #666666; font-style: italic;"># verification is omitted, and submission mode is set. And again, we do this</span>
<span style="color: #666666; font-style: italic;"># check before any black list tests.</span>
accept
  authenticated = <span style="color: #000000; font-weight: bold;">*</span>
  <span style="color: #666666; font-style: italic;"># Nur unter der Bedingung, dass der Absender ein valider, entfernter User in LDAP</span>
  <span style="color: #666666; font-style: italic;"># ist Empfänger bedingungslos akzeptieren</span>
  condition = IS_SENDER_REMOTE
  <span style="color: #666666; font-style: italic;">#control = submission/sender_retain</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Deny all unauthenticated remote hosts to send mail to</span>
<span style="color: #666666; font-style: italic;"># spam or ham email addresses</span>
deny
  hosts = <span style="color: #000000; font-weight: bold;">!</span>+own_hosts
  local_parts = MAIL_ADDRESS_HAM : MAIL_ADDRESS_SPAM</pre></div></div>

<p>Jetzt brauchen wir nur noch einen Router und einen Transporter für das Lernen von Spam bzw. Ham. Den Router erzeugen wir durch die Datei /etc/exim4/conf.d/router/410_exim4-config_spam_classification mit folgendem Inhalt</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">################################################</span>
<span style="color: #666666; font-style: italic;">### router/410_exim4-config_spam_classification</span>
<span style="color: #666666; font-style: italic;">################################################</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># This router matches the local spam and ham mailboxes</span>
<span style="color: #666666; font-style: italic;"># which are used to train the spam filter with false</span>
<span style="color: #666666; font-style: italic;"># spam positives or unrecognized spam.</span>
&nbsp;
router_spam_training:
  debug_print = <span style="color: #ff0000;">&quot;R: spam training issued by mail from <span style="color: #007800;">$sender_address</span>@<span style="color: #007800;">$sender_address_domain</span> to <span style="color: #007800;">$local_part</span>@<span style="color: #007800;">$domain</span>&quot;</span>
  driver = accept
  domains = +local_domains
  local_parts = MAIL_ADDRESS_HAM : MAIL_ADDRESS_SPAM
  transport = transport_spam_training
&nbsp;
<span style="color: #666666; font-style: italic;">################################################</span>
<span style="color: #666666; font-style: italic;">### router/410_exim4-config_spam_classification</span>
<span style="color: #666666; font-style: italic;">################################################</span></pre></div></div>

<p>Den Transporter erstellen wir analog durch die Datei /etc/exim4/conf.d/transport/30_exim4-config_transport_spam_training mit dem Inhalt</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#####################################################</span>
<span style="color: #666666; font-style: italic;">### transport/30_exim4-config_transport_spam_training</span>
<span style="color: #666666; font-style: italic;">#####################################################</span>
&nbsp;
transport_spam_training:
  debug_print = <span style="color: #ff0000;">&quot;T: spam training issued by mail from <span style="color: #007800;">$sender_address</span>@<span style="color: #007800;">$sender_address_domain</span> to <span style="color: #007800;">$local_part</span>@<span style="color: #007800;">$domain</span>&quot;</span>
  driver = pipe
  <span style="color: #7a0874; font-weight: bold;">command</span> = <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>dspam <span style="color: #ff0000;">&quot;<span style="color: #007800;">${if eq{$local_part}</span>{MAIL_ADDRESS_HAM} {--class=innocent}{--class=spam}}&quot;</span> <span style="color: #660033;">--source</span>=error <span style="color: #660033;">--delivery</span>=stdout <span style="color: #660033;">--user</span> globaluser
  message_prefix =
  message_suffix =
  <span style="color: #666666; font-style: italic;"># Do not add additional Headers</span>
  delivery_date_add = <span style="color: #c20cb9; font-weight: bold;">false</span>
  envelope_to_add = <span style="color: #c20cb9; font-weight: bold;">false</span>
  return_path_add = <span style="color: #c20cb9; font-weight: bold;">false</span>
  log_output
  user = secmail
  group = secmail
&nbsp;
<span style="color: #666666; font-style: italic;">#####################################################</span>
<span style="color: #666666; font-style: italic;">### transport/30_exim4-config_transport_spam_training</span>
<span style="color: #666666; font-style: italic;">#####################################################</span></pre></div></div>

<p>Was mich lange aufgehalten hat, waren die String-Expansions in der command Angabe. Hier kommt es darauf an, die Anführungszeichen zu setzen, wie es sowohl in der <a href="http://wiki.exim.org/FAQ/General_Debugging/Q0025">FAQ</a> als auch in der <a href="http://exim.org/exim-html-4.71/doc/html/spec_html/ch29.html#SECThowcommandrun">Dokumentation von command</a> und unter anderem auch bei der von <a href="http://www.exim.org/exim-html-4.71/doc/html/spec_html/ch24.html#id603010">transport_filter</a> erwähnt wird. Der Grund, warum hier für dspam nicht der Parameter &#8211;stdout, sondern &#8211;delivery=stdout gewählt wurde, liegt darin, dass ansonsten teilweise die Fehlermeldung &#8220;Client exited with error -5&#8243; auftaucht. <a href="http://marc.info/?l=dspam-users&amp;m=120836028609994&amp;w=2">Dieser Hinweis zur Fehlerbehebung stammt übrigens von der dspam-users Mailinglist</a>. Abschließend wird die Konfigurationsdatei erzeugt und Exim neu gestartet durch ein</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> update-exim4.conf <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>exim4 restart</pre></div></div>

<p>Nun kann man mit dem Befehl</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">echo</span> Subject:<span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #660033;">-u</span> secmail dspam <span style="color: #660033;">--client</span> <span style="color: #660033;">--debug</span> <span style="color: #660033;">--mode</span>=notrain <span style="color: #660033;">--user</span> globaluser <span style="color: #660033;">--deliver</span>=spam,innocent <span style="color: #660033;">--stdout</span> <span style="color: #000000; font-weight: bold;">|</span> mail <span style="color: #660033;">-s</span> <span style="color: #ff0000;">&quot;Reclassify&quot;</span> spam</pre></div></div>

<p>testen, ob die Konfiguration funktioniert. Ein erneutes</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> dspam_stats</pre></div></div>

<p>sollte dann dieses Ergebnis</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">globaluser        TP:     <span style="color: #000000;">0</span> TN:     <span style="color: #000000;">1</span> FP:     <span style="color: #000000;">0</span> FN:     <span style="color: #000000;">1</span> SC:     <span style="color: #000000;">0</span> NC:     <span style="color: #000000;">0</span></pre></div></div>

<p>ausgeben.</p>
<h2>Einrichtung des dovecot-antispam Plugins</h2>
<p>Im nächsten Schritt konfigurieren wir das dovecot-antispam plugin. Bei diesem Plugin wird <span style="text-decoration: underline;">beim Kompilieren</span> festgelegt, welches Backend (dspam-exec, mailtrain oder crm114-exec) verwendet werden soll. Wenn man die Paket-Version von Debian/Ubuntu verwendet, ist man deshalb automatisch auf das mailtrain-Backend festgelegt. Dies kann man zwar erst der <a href="http://packages.ubuntu.com/lucid/utils/dovecot-antispam">Beschreibung des Pakets in Lucid Lynx</a> lesen, trifft aber auch auf vorherige Versionen zu. Passen wir also jetzt die Konfigurationsdatei unter /etc/dovecot/dovecot.conf an. Wir aktivieren das antispam-Plugin im Imap-Abschnitt folgendermaßen</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">protocol imap <span style="color: #7a0874; font-weight: bold;">&#123;</span>
  mail_plugins = antispam
  <span style="color: #666666; font-style: italic;"># mail_plugin_dir = /usr/lib/dovecot/modules/imap</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>anschließend ergänzen wir den plugin-Abschnitt um die Konfigurationsparameter für dovecot-antispam. Dabei sind unter Umständen die Ordnerbezeichnungen für den Papierkorb und Spam anzupassen.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">plugin <span style="color: #7a0874; font-weight: bold;">&#123;</span>
 <span style="color: #666666; font-style: italic;">##################</span>
 <span style="color: #666666; font-style: italic;"># DSPAM</span>
 <span style="color: #666666; font-style: italic;"># GENERIC OPTIONS</span>
&nbsp;
 <span style="color: #666666; font-style: italic;"># mail signature (used with any backend requiring a signature)</span>
 antispam_signature = X-DSPAM-Signature
&nbsp;
 <span style="color: #666666; font-style: italic;"># action to take on mails without signature</span>
 <span style="color: #666666; font-style: italic;"># (used with any backend requiring a signature)</span>
 <span style="color: #666666; font-style: italic;"># (we recommend only setting this to 'move' after verifying that the</span>
 <span style="color: #666666; font-style: italic;"># whole setup is working)</span>
 <span style="color: #666666; font-style: italic;"># antispam_signature_missing = move # move silently without training</span>
 antispam_signature_missing = move
&nbsp;
 <span style="color: #666666; font-style: italic;"># semicolon-separated list of Trash folders (default unset i.e. none)</span>
 <span style="color: #666666; font-style: italic;"># antispam_trash =</span>
 antispam_trash = trash;Trash;Deleted Items
&nbsp;
 <span style="color: #666666; font-style: italic;"># semicolon-separated list of spam folders</span>
 antispam_spam = SPAM;Spam;spam
&nbsp;
 <span style="color: #666666; font-style: italic;"># semicolon-separated list of unsure folders (default unset i.e. none)</span>
 <span style="color: #666666; font-style: italic;"># antispam_unsure =</span>
&nbsp;
 <span style="color: #666666; font-style: italic;"># Whether to allow APPENDing to SPAM folders or not. Must be set to</span>
 <span style="color: #666666; font-style: italic;"># &quot;yes&quot; (case insensitive) to be activated. Before activating, please</span>
 <span style="color: #666666; font-style: italic;"># read the discussion below.</span>
 <span style="color: #666666; font-style: italic;"># antispam_allow_append_to_spam = no</span>
&nbsp;
 <span style="color: #666666; font-style: italic;">###########################</span>
 <span style="color: #666666; font-style: italic;"># BACKEND SPECIFIC OPTIONS</span>
 <span style="color: #666666; font-style: italic;"># please note: the backend has to be specified at compile time</span>
 <span style="color: #666666; font-style: italic;"># the backend used in the Debian/Ubuntu standard package is mailtrain</span>
&nbsp;
 <span style="color: #666666; font-style: italic;">#===================</span>
 <span style="color: #666666; font-style: italic;"># dspam-exec plugin</span>
&nbsp;
 <span style="color: #666666; font-style: italic;"># dspam binary</span>
 antispam_dspam_binary = <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>dspam
&nbsp;
 <span style="color: #666666; font-style: italic;"># semicolon-separated list of extra arguments to dspam</span>
 <span style="color: #666666; font-style: italic;"># (default unset i.e. none)</span>
 <span style="color: #666666; font-style: italic;"># antispam_dspam_args =</span>
 <span style="color: #666666; font-style: italic;"># antispam_dspam_args = --deliver=;--user;%u  # % expansion done by dovecot</span>
 <span style="color: #666666; font-style: italic;"># antispam_dspam_args = --mode=teft</span>
&nbsp;
 <span style="color: #666666; font-style: italic;"># Ignore mails where the DSPAM result header contains any of the</span>
 <span style="color: #666666; font-style: italic;"># strings listed in the blacklist</span>
 <span style="color: #666666; font-style: italic;"># (default unset i.e. none)</span>
 <span style="color: #666666; font-style: italic;"># antispam_dspam_result_header = X-DSPAM-Result</span>
 <span style="color: #666666; font-style: italic;"># semicolon-separated list of blacklisted results, case insensitive</span>
 <span style="color: #666666; font-style: italic;"># antispam_dspam_result_blacklist = Virus</span>
&nbsp;
 <span style="color: #666666; font-style: italic;">#=====================</span>
 <span style="color: #666666; font-style: italic;"># mail sending plugin</span>
 <span style="color: #666666; font-style: italic;">#</span>
 <span style="color: #666666; font-style: italic;"># Because of the way this plugin works, you can also use it</span>
 <span style="color: #666666; font-style: italic;"># to train via an arbitrary program that receives the message</span>
 <span style="color: #666666; font-style: italic;"># on standard input, in that case you can use the config</span>
 <span style="color: #666666; font-style: italic;"># options antispam_mail_spam and antispam_mail_notspam for</span>
 <span style="color: #666666; font-style: italic;"># the argument that distinguishes between ham and spam.</span>
 <span style="color: #666666; font-style: italic;"># For example:</span>
 <span style="color: #666666; font-style: italic;">#   antispam_mail_sendmail = /path/to/mailtrain</span>
 <span style="color: #666666; font-style: italic;">#   antispam_mail_sendmail_args = --for;%u</span>
 <span style="color: #666666; font-style: italic;">#   antispam_mail_spam = --spam</span>
 <span style="color: #666666; font-style: italic;">#   antispam_mail_notspam = --ham</span>
 <span style="color: #666666; font-style: italic;"># will call it, for example, like this:</span>
 <span style="color: #666666; font-style: italic;">#   /path/to/mailtrain --for jberg --spam</span>
&nbsp;
 <span style="color: #666666; font-style: italic;"># temporary directory</span>
 antispam_mail_tmpdir = <span style="color: #000000; font-weight: bold;">/</span>tmp
&nbsp;
 <span style="color: #666666; font-style: italic;"># spam/not-spam addresses (default unset which will give errors)</span>
 antispam_mail_spam = spam
 antispam_mail_notspam = ham
&nbsp;
 <span style="color: #666666; font-style: italic;"># sendmail binary</span>
 antispam_mail_sendmail = <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">sendmail</span>
 <span style="color: #666666; font-style: italic;">#antispam_mail_sendmail_args = -f;%u@example.com # % expansion done by dovecot</span>
&nbsp;
 <span style="color: #666666; font-style: italic;">#===================</span>
 <span style="color: #666666; font-style: italic;"># crm114-exec plugin</span>
&nbsp;
 <span style="color: #666666; font-style: italic;"># mailreaver binary</span>
 antispam_crm_binary = <span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">false</span>
 <span style="color: #666666; font-style: italic;"># antispam_crm_binary = /usr/share/crm114/mailreaver.crm</span>
&nbsp;
 <span style="color: #666666; font-style: italic;"># semicolon-separated list of extra arguments to dspam</span>
 <span style="color: #666666; font-style: italic;"># (default unset i.e. none)</span>
 <span style="color: #666666; font-style: italic;"># antispam_crm_args =</span>
 <span style="color: #666666; font-style: italic;"># antispam_crm_args = --config=/path/to/config</span>
&nbsp;
 <span style="color: #666666; font-style: italic;"># NOTE: you need to set the signature for this backend</span>
 antispam_signature = X-CRM114-CacheID
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<h2>Sieve zum automatischen Verschieben der Spamnachrichten</h2>
<p>Das Einzige, was jetzt noch fehlt, ist die Einrichtung des Sieve-Filters durch den die Spam-Nachrichten direkt in den Spam-Ordner verschoben und als gelesen markiert werden. Auch hier bitte ggfs. den Namen des Spamordners anpassen.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">require <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #ff0000;">&quot;fileinto&quot;</span>,<span style="color: #ff0000;">&quot;imapflags&quot;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>;
&nbsp;
<span style="color: #666666; font-style: italic;"># Spam</span>
<span style="color: #666666; font-style: italic;"># Catch mail tagged as spam, except spam retrained and delivered to the mailbox</span>
<span style="color: #000000; font-weight: bold;">if</span> allof<span style="color: #7a0874; font-weight: bold;">&#40;</span>header :contains <span style="color: #ff0000;">&quot;X-DSPAM-Result&quot;</span> <span style="color: #ff0000;">&quot;Spam&quot;</span>,
 not header :contains <span style="color: #ff0000;">&quot;X-DSPAM-Reclassified&quot;</span> <span style="color: #ff0000;">&quot;Innocent&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
&nbsp;
 <span style="color: #666666; font-style: italic;"># Mark as read</span>
 setflag <span style="color: #ff0000;">&quot;\\Seen&quot;</span>;
&nbsp;
 <span style="color: #666666; font-style: italic;"># Move into the Junk folder</span>
 fileinto <span style="color: #ff0000;">&quot;Spam&quot;</span>;
&nbsp;
 <span style="color: #666666; font-style: italic;"># Stop processing here</span>
 stop;
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># The rest goes into INBOX</span>
<span style="color: #666666; font-style: italic;"># default is &quot;implicit keep&quot;, we do it explicitly here</span>
keep;</pre></div></div>

<p>So, damit ist der Spamfilter fertig eingerichtet. Was jetzt noch fehlt, ist das Webinterface für dspam (das Binär-Paket dafür haben wir aber schon erzeugt) und der Webmail-Zugriff mit Roundcube. Fortsetzung folgt..</p>
]]></content:encoded>
			<wfw:commentRss>http://www.effinger.org/blog/2010/02/20/dovecot-exim-openldap-und-getmail-unter-ubuntu-%e2%80%93-5-dspam/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Dovecot, Exim, OpenLDAP und getmail unter Ubuntu &#8211; (4) getmail</title>
		<link>http://www.effinger.org/blog/2009/03/22/dovecot-exim-openldap-und-getmail-unter-ubuntu-4-getmail/</link>
		<comments>http://www.effinger.org/blog/2009/03/22/dovecot-exim-openldap-und-getmail-unter-ubuntu-4-getmail/#comments</comments>
		<pubDate>Sun, 22 Mar 2009 17:00:18 +0000</pubDate>
		<dc:creator>Markus Effinger</dc:creator>
				<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[dovecot]]></category>
		<category><![CDATA[exim]]></category>
		<category><![CDATA[getmail]]></category>
		<category><![CDATA[LDAP]]></category>
		<category><![CDATA[OpenLDAP]]></category>

		<guid isPermaLink="false">http://www.effinger.org/blog/?p=657</guid>
		<description><![CDATA[<p>Nachdem wir in den drei ersten Teilen zunächst OpenLDAP, Dovecot und Exim eingerichtet haben, geht es nun daran, getmail so einzurichten, dass Mails von einem externen Server via POP3 oder IMAP abgerufen werden und dann dem entsprechenden lokalen Benutzer zugestellt werden. Obwohl fast alles im Blog detailliert beschrieben ist, empfehle ich, die Konfigurationsdateien für das [...]]]></description>
			<content:encoded><![CDATA[<p>Nachdem wir in den drei ersten Teilen zunächst <a href="http://www.effinger.org/blog/2009/03/22/dovecot-exim-openldap-und-getmail-unter-ubuntu-1-openldap/">OpenLDAP</a>, <a href="http://www.effinger.org/blog/2009/03/22/dovecot-postfix-openldap-und-getmail-unter-ubuntu-2-dovecot/">Dovecot</a> und <a href="http://www.effinger.org/blog/2009/03/22/dovecot-exim-openldap-und-getmail-unter-ubuntu-3-exim/">Exim</a> eingerichtet haben, geht es nun daran, getmail so einzurichten, dass Mails von einem externen Server via POP3 oder IMAP abgerufen werden und dann dem entsprechenden lokalen Benutzer zugestellt werden. Obwohl fast alles im Blog detailliert beschrieben ist, empfehle ich, die <a href="http://www.effinger.org/blog/wp-content/uploads/2009/03/configfiles-mailsystem.tgz">Konfigurationsdateien für das Mailsystem herunterzuladen</a>.</p>
<h2>Installation</h2>
<p>Wir installieren getmail und das benötigte python-Modul durch den Befehl</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> getmail4 python-ldap</pre></div></div>

<h2>Konfiguration zum Mailabruf von externen Servern</h2>
<p>Der Benutzer secmail wird für uns alle Mails abholen und an den jeweiligen Nutzer zustellen. Für diesen Zweck habe ich das Python-Skript getmail-ldap.py geschrieben. Es liest zunächst die Login-Daten aller externen Mail-Accounts aus dem LDAP-Verzeichnis und erzeugt für jeden Mailaccount eine entsprechende Konfigurationsdatei zur Verwendung mit getmail. Anschließend ruft es getmail auf und benachrichtigt im Falle einer Fehlermeldung den Administrator per E-Mail. Die folgenden Schritte führen wir unter dem Benutzer secmail durch, damit die Dateien mit der entsprechenden Berechtigung erzeugt werden. Dazu rufen wir sudo auf:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #660033;">-u</span> secmail <span style="color: #660033;">-s</span></pre></div></div>

<p>Den folgenden Inhalt</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/python</span>
<span style="color: #808080; font-style: italic;"># File: getmail-ldap.py</span>
<span style="color: #ff7700;font-weight:bold;">try</span>:
	<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">errno</span>
	<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">string</span>
	<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">logging</span>
	<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">logging</span>.<span style="color: black;">handlers</span>
	<span style="color: #ff7700;font-weight:bold;">import</span> ldap
	<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">ConfigParser</span>
	<span style="color: #ff7700;font-weight:bold;">import</span> ldif
	<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">threading</span>
	<span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">StringIO</span> <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">StringIO</span>
	<span style="color: #ff7700;font-weight:bold;">from</span> ldap.<span style="color: black;">cidict</span> <span style="color: #ff7700;font-weight:bold;">import</span> cidict
	<span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">os</span>.<span style="color: black;">path</span> <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">os</span>
	<span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">subprocess</span> <span style="color: #ff7700;font-weight:bold;">import</span> Popen,PIPE
<span style="color: #ff7700;font-weight:bold;">except</span> <span style="color: #008000;">ImportError</span>:
	<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;&quot;&quot;Cannot find all required libraries please install them and try again&quot;&quot;&quot;</span>
	<span style="color: #ff7700;font-weight:bold;">raise</span> <span style="color: #008000;">SystemExit</span>
&nbsp;
config_file_location = <span style="color: #483d8b;">'/home/secmail/getmail-ldap.cfg'</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> pid_exists<span style="color: black;">&#40;</span>pid<span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;&quot;&quot;Is there a process with PID pid?&quot;&quot;&quot;</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> pid <span style="color: #66cc66;">&lt;</span> <span style="color: #ff4500;">0</span>:
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">False</span>
&nbsp;
    exist = <span style="color: #008000;">False</span>
    <span style="color: #ff7700;font-weight:bold;">try</span>:
        <span style="color: #dc143c;">os</span>.<span style="color: black;">kill</span><span style="color: black;">&#40;</span>pid, <span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>
        exist = <span style="color: #ff4500;">1</span>
    <span style="color: #ff7700;font-weight:bold;">except</span> <span style="color: #008000;">OSError</span>, x:
        <span style="color: #ff7700;font-weight:bold;">if</span> x.<span style="color: #dc143c;">errno</span> <span style="color: #66cc66;">!</span>= <span style="color: #dc143c;">errno</span>.<span style="color: black;">ESRCH</span>:
            <span style="color: #ff7700;font-weight:bold;">raise</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">return</span> exist
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> get_search_results<span style="color: black;">&#40;</span>results<span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;&quot;&quot;Given a set of results, return a list of LDAPSearchResult
    objects.
    &quot;&quot;&quot;</span>
    res = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">type</span><span style="color: black;">&#40;</span>results<span style="color: black;">&#41;</span> == <span style="color: #008000;">tuple</span> <span style="color: #ff7700;font-weight:bold;">and</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>results<span style="color: black;">&#41;</span> == <span style="color: #ff4500;">2</span> :
        <span style="color: black;">&#40;</span><span style="color: #dc143c;">code</span>, arr<span style="color: black;">&#41;</span> = results
    <span style="color: #ff7700;font-weight:bold;">elif</span> <span style="color: #008000;">type</span><span style="color: black;">&#40;</span>results<span style="color: black;">&#41;</span> == <span style="color: #008000;">list</span>:
        arr = results
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>results<span style="color: black;">&#41;</span> == <span style="color: #ff4500;">0</span>:
        <span style="color: #ff7700;font-weight:bold;">return</span> res
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">for</span> item <span style="color: #ff7700;font-weight:bold;">in</span> arr:
        res.<span style="color: black;">append</span><span style="color: black;">&#40;</span> LDAPSearchResult<span style="color: black;">&#40;</span>item<span style="color: black;">&#41;</span> <span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">return</span> res
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> LDAPSearchResult:
    <span style="color: #483d8b;">&quot;&quot;&quot;A class to model LDAP results.
    &quot;&quot;&quot;</span>
&nbsp;
    dn = <span style="color: #483d8b;">''</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, entry_tuple<span style="color: black;">&#41;</span>:
        <span style="color: #483d8b;">&quot;&quot;&quot;Create a new LDAPSearchResult object.&quot;&quot;&quot;</span>
        <span style="color: black;">&#40;</span>dn, attrs<span style="color: black;">&#41;</span> = entry_tuple
        <span style="color: #ff7700;font-weight:bold;">if</span> dn:
            <span style="color: #008000;">self</span>.<span style="color: black;">dn</span> = dn
        <span style="color: #ff7700;font-weight:bold;">else</span>:
            <span style="color: #ff7700;font-weight:bold;">return</span>
&nbsp;
        <span style="color: #008000;">self</span>.<span style="color: black;">attrs</span> = cidict<span style="color: black;">&#40;</span>attrs<span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> get_attributes<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #483d8b;">&quot;&quot;&quot;Get a dictionary of all attributes.
        get_attributes()-&gt;{'name1':['value1','value2',...],
				'name2: [value1...]}
        &quot;&quot;&quot;</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">self</span>.<span style="color: black;">attrs</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> set_attributes<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, attr_dict<span style="color: black;">&#41;</span>:
        <span style="color: #483d8b;">&quot;&quot;&quot;Set the list of attributes for this record.
&nbsp;
        The format of the dictionary should be string key, list of
        string alues. e.g. {'cn': ['M Butcher','Matt Butcher']}
&nbsp;
        set_attributes(attr_dictionary)
        &quot;&quot;&quot;</span>
&nbsp;
        <span style="color: #008000;">self</span>.<span style="color: black;">attrs</span> = cidict<span style="color: black;">&#40;</span>attr_dict<span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> has_attribute<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, attr_name<span style="color: black;">&#41;</span>:
        <span style="color: #483d8b;">&quot;&quot;&quot;Returns true if there is an attribute by this name in the
        record.
&nbsp;
        has_attribute(string attr_name)-&gt;boolean
        &quot;&quot;&quot;</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">self</span>.<span style="color: black;">attrs</span>.<span style="color: black;">has_key</span><span style="color: black;">&#40;</span> attr_name <span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> get_attr_values<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, key<span style="color: black;">&#41;</span>:
        <span style="color: #483d8b;">&quot;&quot;&quot;Get a list of attribute values.
        get_attr_values(string key)-&gt;['value1','value2']
        &quot;&quot;&quot;</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">self</span>.<span style="color: black;">attrs</span><span style="color: black;">&#91;</span>key<span style="color: black;">&#93;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> get_attr_names<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #483d8b;">&quot;&quot;&quot;Get a list of attribute names.
        get_attr_names()-&gt;['name1','name2',...]
        &quot;&quot;&quot;</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">self</span>.<span style="color: black;">attrs</span>.<span style="color: black;">keys</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> get_dn<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #483d8b;">&quot;&quot;&quot;Get the DN string for the record.
        get_dn()-&gt;string dn
        &quot;&quot;&quot;</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">self</span>.<span style="color: black;">dn</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> pretty_print<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #483d8b;">&quot;&quot;&quot;Create a nice string representation of this object.
&nbsp;
        pretty_print()-&gt;string
        &quot;&quot;&quot;</span>
        <span style="color: #008000;">str</span> = <span style="color: #483d8b;">&quot;DN: &quot;</span> + <span style="color: #008000;">self</span>.<span style="color: black;">dn</span> + <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
        <span style="color: #ff7700;font-weight:bold;">for</span> a, v_list <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">self</span>.<span style="color: black;">attrs</span>.<span style="color: black;">iteritems</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
            <span style="color: #008000;">str</span> = <span style="color: #008000;">str</span> + <span style="color: #483d8b;">&quot;Name: &quot;</span> + a + <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
            <span style="color: #ff7700;font-weight:bold;">for</span> v <span style="color: #ff7700;font-weight:bold;">in</span> v_list:
                <span style="color: #008000;">str</span> = <span style="color: #008000;">str</span> + <span style="color: #483d8b;">&quot;  Value: &quot;</span> + v + <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
        <span style="color: #008000;">str</span> = <span style="color: #008000;">str</span> + <span style="color: #483d8b;">&quot;========&quot;</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">str</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> to_ldif<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #483d8b;">&quot;&quot;&quot;Get an LDIF representation of this record.
&nbsp;
        to_ldif()-&gt;string
        &quot;&quot;&quot;</span>
        out = <span style="color: #dc143c;">StringIO</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        ldif_out = ldif.<span style="color: black;">LDIFWriter</span><span style="color: black;">&#40;</span>out<span style="color: black;">&#41;</span>
        ldif_out.<span style="color: black;">unparse</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">dn</span>, <span style="color: #008000;">self</span>.<span style="color: black;">attrs</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> out.<span style="color: black;">getvalue</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> RetrieveMails<span style="color: black;">&#40;</span><span style="color: #dc143c;">threading</span>.<span style="color: black;">Thread</span><span style="color: black;">&#41;</span>:
	<span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, getmail_binary, config_filename, config_data_dir<span style="color: black;">&#41;</span>:
		<span style="color: #dc143c;">threading</span>.<span style="color: black;">Thread</span>.<span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>
		<span style="color: #008000;">self</span>.<span style="color: black;">getmail_binary</span>, <span style="color: #008000;">self</span>.<span style="color: black;">config_filename</span>, <span style="color: #008000;">self</span>.<span style="color: black;">config_data_dir</span> = \
			getmail_binary, config_filename, config_data_dir
	<span style="color: #ff7700;font-weight:bold;">def</span> run<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
		<span style="color: #ff7700;font-weight:bold;">try</span>:
			command = <span style="color: black;">&#91;</span><span style="color: #008000;">self</span>.<span style="color: black;">getmail_binary</span>, \
				<span style="color: #808080; font-style: italic;">#'--quiet', \</span>
				<span style="color: #483d8b;">'--rcfile='</span> + <span style="color: #008000;">self</span>.<span style="color: black;">config_filename</span>, \
				<span style="color: #483d8b;">'--getmaildir='</span> + <span style="color: #008000;">self</span>.<span style="color: black;">config_data_dir</span><span style="color: black;">&#93;</span>
			<span style="color: #008000;">self</span>.<span style="color: black;">pid_filename</span> = <span style="color: #008000;">self</span>.<span style="color: black;">config_filename</span> + <span style="color: #483d8b;">'.pid'</span>
			<span style="color: #808080; font-style: italic;"># Check for a pidfile to see if the daemon already runs</span>
			<span style="color: #ff7700;font-weight:bold;">try</span>:
				pid_file = <span style="color: #008000;">file</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">pid_filename</span>,<span style="color: #483d8b;">'r'</span><span style="color: black;">&#41;</span>
				pid_number = pid = <span style="color: #008000;">int</span><span style="color: black;">&#40;</span>pid_file.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">strip</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
				pid_file.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
			<span style="color: #ff7700;font-weight:bold;">except</span> <span style="color: #008000;">IOError</span>:
				pid = <span style="color: #008000;">None</span>
			<span style="color: #808080; font-style: italic;"># Check whether process is really running</span>
			<span style="color: #ff7700;font-weight:bold;">if</span> pid:
				pid = pid_exists<span style="color: black;">&#40;</span>pid<span style="color: black;">&#41;</span>
			<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> pid:
				getmail_process = Popen<span style="color: black;">&#40;</span>command, shell=<span style="color: #008000;">False</span>,stdout=PIPE,stderr=PIPE<span style="color: black;">&#41;</span>
				<span style="color: #ff7700;font-weight:bold;">try</span>:
					<span style="color: #008000;">file</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">pid_filename</span>,<span style="color: #483d8b;">'w+'</span><span style="color: black;">&#41;</span>.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;%s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #66cc66;">%</span> getmail_process.<span style="color: black;">pid</span><span style="color: black;">&#41;</span>
					getmail_process.<span style="color: black;">wait</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
				<span style="color: #ff7700;font-weight:bold;">finally</span>:
					<span style="color: #dc143c;">os</span>.<span style="color: black;">remove</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">pid_filename</span><span style="color: black;">&#41;</span>
					<span style="color: #808080; font-style: italic;"># Zur Sicherheit die erstellte Konfigurationsdatei loeschen (Login-Daten!)</span>
					<span style="color: #dc143c;">os</span>.<span style="color: black;">remove</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">config_filename</span><span style="color: black;">&#41;</span>
				stderr_output=<span style="color: #dc143c;">string</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span>getmail_process.<span style="color: black;">stderr</span>.<span style="color: black;">readlines</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
				<span style="color: #ff7700;font-weight:bold;">if</span> getmail_process.<span style="color: black;">returncode</span> <span style="color: #66cc66;">&lt;&gt;</span> <span style="color: #ff4500;">0</span> <span style="color: #ff7700;font-weight:bold;">or</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>stderr_output.<span style="color: black;">strip</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">&gt;</span><span style="color: #ff4500;">0</span> :
					<span style="color: #ff7700;font-weight:bold;">raise</span> <span style="color: #008000;">Exception</span>, <span style="color: #483d8b;">&quot;Getmail command failed for &quot;</span> + <span style="color: #483d8b;">&quot; &quot;</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span>command<span style="color: black;">&#41;</span> \
						+<span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>StdErr: <span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> + <span style="color: #dc143c;">string</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span>stderr_output.<span style="color: black;">strip</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> \
						+<span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>StdOut: <span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> + <span style="color: #dc143c;">string</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span>getmail_process.<span style="color: black;">stdout</span>.<span style="color: black;">readlines</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
			<span style="color: #ff7700;font-weight:bold;">else</span>:
				log_object.<span style="color: black;">info</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Command &quot;</span> + <span style="color: #483d8b;">&quot; &quot;</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span>command<span style="color: black;">&#41;</span> +\
					<span style="color: #483d8b;">&quot; not executed, existing pid &quot;</span> + <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>pid_number<span style="color: black;">&#41;</span> + <span style="color: #483d8b;">&quot; found&quot;</span><span style="color: black;">&#41;</span>
		<span style="color: #ff7700;font-weight:bold;">except</span>:
			log_object.<span style="color: black;">exception</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;An error occured!&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> RetrieveAccount:
	account_name = <span style="color: #008000;">None</span>
	account_type = <span style="color: #008000;">None</span>
	login = <span style="color: #008000;">None</span>
	password = <span style="color: #008000;">None</span>
	server = <span style="color: #008000;">None</span>
	<span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, account_name=<span style="color: #008000;">None</span>, account_type=<span style="color: #008000;">None</span>, server=<span style="color: #008000;">None</span>, login=<span style="color: #008000;">None</span>, password=<span style="color: #008000;">None</span><span style="color: black;">&#41;</span>:
		<span style="color: #008000;">self</span>.<span style="color: black;">account_name</span>, <span style="color: #008000;">self</span>.<span style="color: black;">account_type</span>, <span style="color: #008000;">self</span>.<span style="color: black;">login</span>, <span style="color: #008000;">self</span>.<span style="color: black;">password</span>, <span style="color: #008000;">self</span>.<span style="color: black;">server</span> = \
			account_name, account_type, login, password, server
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> GetmailConfigFile<span style="color: black;">&#40;</span><span style="color: #dc143c;">ConfigParser</span>.<span style="color: black;">SafeConfigParser</span><span style="color: black;">&#41;</span>:
	output_filename = <span style="color: #008000;">None</span>
	<span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, defaults, default_config_filename=<span style="color: #008000;">None</span>, output_filename=<span style="color: #008000;">None</span><span style="color: black;">&#41;</span>:
		<span style="color: #dc143c;">ConfigParser</span>.<span style="color: black;">SafeConfigParser</span>.<span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, defaults<span style="color: black;">&#41;</span>
		<span style="color: #ff7700;font-weight:bold;">if</span> default_config_filename <span style="color: #ff7700;font-weight:bold;">is</span> <span style="color: #ff7700;font-weight:bold;">not</span> <span style="color: #008000;">None</span>:
			<span style="color: #008000;">self</span>.<span style="color: black;">read</span><span style="color: black;">&#40;</span>default_config_filename<span style="color: black;">&#41;</span>
		<span style="color: #008000;">self</span>.<span style="color: black;">output_filename</span> = output_filename
	<span style="color: #ff7700;font-weight:bold;">def</span> set_pop3_account<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, newRetrieveAccount<span style="color: black;">&#41;</span>:
		<span style="color: #008000;">self</span>.<span style="color: #008000;">set</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'retriever'</span>,<span style="color: #483d8b;">'server'</span>,newRetrieveAccount.<span style="color: black;">server</span><span style="color: black;">&#41;</span>
		<span style="color: #008000;">self</span>.<span style="color: #008000;">set</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'retriever'</span>,<span style="color: #483d8b;">'type'</span>,newRetrieveAccount.<span style="color: black;">account_type</span><span style="color: black;">&#41;</span>
		<span style="color: #008000;">self</span>.<span style="color: #008000;">set</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'retriever'</span>,<span style="color: #483d8b;">'username'</span>,newRetrieveAccount.<span style="color: black;">login</span><span style="color: black;">&#41;</span>
		<span style="color: #008000;">self</span>.<span style="color: #008000;">set</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'retriever'</span>,<span style="color: #483d8b;">'password'</span>,newRetrieveAccount.<span style="color: black;">password</span><span style="color: black;">&#41;</span>
		<span style="color: #008000;">self</span>.<span style="color: #008000;">set</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'destination'</span>,<span style="color: #483d8b;">'arguments'</span>,<span style="color: #483d8b;">'(&quot;'</span>+newRetrieveAccount.<span style="color: black;">account_name</span>+<span style="color: #483d8b;">'&quot;,)'</span><span style="color: black;">&#41;</span>
	<span style="color: #ff7700;font-weight:bold;">def</span> write<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
		<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">self</span>.<span style="color: black;">output_filename</span> <span style="color: #ff7700;font-weight:bold;">is</span> <span style="color: #ff7700;font-weight:bold;">not</span> <span style="color: #008000;">None</span>:
			<span style="color: #483d8b;">&quot;&quot;&quot;try:
				output_file = open(self.output_filename, 'wb')
			except:
				raise Exception, &quot;Unable to open &quot; + <span style="color: #000099; font-weight: bold;">\</span>
					self.output_filename + &quot;for writing&quot;
			finally:
				output_file.close()
			&quot;&quot;&quot;</span>
			<span style="color: #dc143c;">os</span>.<span style="color: black;">umask</span><span style="color: black;">&#40;</span>0077<span style="color: black;">&#41;</span>
			output_file = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">output_filename</span>, <span style="color: #483d8b;">'wb'</span><span style="color: black;">&#41;</span>
			<span style="color: #dc143c;">ConfigParser</span>.<span style="color: black;">SafeConfigParser</span>.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, output_file<span style="color: black;">&#41;</span>
		<span style="color: #ff7700;font-weight:bold;">else</span>:
			<span style="color: #ff7700;font-weight:bold;">raise</span> <span style="color: #008000;">Exception</span>, <span style="color: #483d8b;">&quot;No output file for configuration defined&quot;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Konfigurationsdatei lesen</span>
config_object = <span style="color: #dc143c;">ConfigParser</span>.<span style="color: black;">SafeConfigParser</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
config_object.<span style="color: black;">read</span><span style="color: black;">&#40;</span>config_file_location<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Set-up Logging</span>
log_object = <span style="color: #dc143c;">logging</span>.<span style="color: black;">getLogger</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;getmail-ldap&quot;</span><span style="color: black;">&#41;</span>
log_object.<span style="color: black;">setLevel</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">logging</span>.<span style="color: black;">DEBUG</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># This handler writes everything to a log file.</span>
log_file_handler = <span style="color: #dc143c;">logging</span>.<span style="color: black;">FileHandler</span><span style="color: black;">&#40;</span>config_object.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'Logging'</span>,<span style="color: #483d8b;">'LogFile'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
log_file_formatter = <span style="color: #dc143c;">logging</span>.<span style="color: black;">Formatter</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;%(levelname)s %(asctime)s %(funcName)s %(lineno)d %(message)s&quot;</span><span style="color: black;">&#41;</span>
log_file_handler.<span style="color: black;">setFormatter</span><span style="color: black;">&#40;</span>log_file_formatter<span style="color: black;">&#41;</span>
log_file_handler.<span style="color: black;">setLevel</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">logging</span>.<span style="color: black;">DEBUG</span><span style="color: black;">&#41;</span>
log_object.<span style="color: black;">addHandler</span><span style="color: black;">&#40;</span>log_file_handler<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># This handler emails anything that is an error or worse.</span>
log_smtp_handler = <span style="color: #dc143c;">logging</span>.<span style="color: black;">handlers</span>.<span style="color: black;">SMTPHandler</span><span style="color: black;">&#40;</span>\
	config_object.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'Logging'</span>,<span style="color: #483d8b;">'MailServer'</span><span style="color: black;">&#41;</span>,\
	config_object.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'Logging'</span>,<span style="color: #483d8b;">'MailFrom'</span><span style="color: black;">&#41;</span>,\
	config_object.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'Logging'</span>,<span style="color: #483d8b;">'MailTo'</span><span style="color: black;">&#41;</span>.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">','</span><span style="color: black;">&#41;</span>,\
	config_object.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'Logging'</span>,<span style="color: #483d8b;">'MailSubject'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
log_smtp_handler.<span style="color: black;">setLevel</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">logging</span>.<span style="color: black;">ERROR</span><span style="color: black;">&#41;</span>
log_smtp_handler.<span style="color: black;">setFormatter</span><span style="color: black;">&#40;</span>log_file_formatter<span style="color: black;">&#41;</span>
log_object.<span style="color: black;">addHandler</span><span style="color: black;">&#40;</span>log_smtp_handler<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> main_call<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
&nbsp;
	<span style="color: #808080; font-style: italic;">## first you must open a connection to the LDAP server</span>
	ldap_object = ldap.<span style="color: #008000;">open</span><span style="color: black;">&#40;</span>config_object.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'LDAP'</span>,<span style="color: #483d8b;">'LDAPServer'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
	ldap_object.<span style="color: black;">simple_bind_s</span><span style="color: black;">&#40;</span>\
		config_object.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'LDAP'</span>,<span style="color: #483d8b;">'BindDN'</span><span style="color: black;">&#41;</span>,\
		config_object.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'LDAP'</span>,<span style="color: #483d8b;">'BindPassword'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
	<span style="color: #808080; font-style: italic;"># searching doesn't require a bind in LDAP V3.</span>
	<span style="color: #808080; font-style: italic;"># If you're using LDAP v2, set the next line appropriately</span>
	<span style="color: #808080; font-style: italic;"># and do a bind as shown in the above example.</span>
	<span style="color: #808080; font-style: italic;"># you can also set this to ldap.VERSION2 if you're using a v2 directory</span>
	<span style="color: #808080; font-style: italic;"># you should  set the next option to ldap.VERSION2 if you're using a v2 directory</span>
	ldap_object.<span style="color: black;">protocol_version</span> = ldap.<span style="color: black;">VERSION3</span>	
&nbsp;
	<span style="color: #808080; font-style: italic;">## The next lines will also need to be changed to support your search requirements and directory</span>
	<span style="color: #808080; font-style: italic;">## retrieve all attributes - again adjust to your needs - see documentation for more options</span>
&nbsp;
	<span style="color: #ff7700;font-weight:bold;">if</span> config_object.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'LDAP'</span>,<span style="color: #483d8b;">'SearchScope'</span><span style="color: black;">&#41;</span>.<span style="color: black;">upper</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> == <span style="color: #483d8b;">&quot;SUB&quot;</span>:
            search_scope = ldap.<span style="color: black;">SCOPE_SUBTREE</span>
        <span style="color: #ff7700;font-weight:bold;">elif</span> config_object.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'LDAP'</span>,<span style="color: #483d8b;">'SearchScope'</span><span style="color: black;">&#41;</span>.<span style="color: black;">upper</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> == <span style="color: #483d8b;">&quot;ONE&quot;</span>:
            search_scope = ldap.<span style="color: black;">SCOPE_ONELEVEL</span>
        <span style="color: #ff7700;font-weight:bold;">else</span>:
            search_scope = ldap.<span style="color: black;">SCOPE_BASE</span>
&nbsp;
	ldap_result_id = ldap_object.<span style="color: black;">search</span><span style="color: black;">&#40;</span> \
		config_object.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'LDAP'</span>,<span style="color: #483d8b;">'SearchDN'</span><span style="color: black;">&#41;</span>, \
		search_scope,
		config_object.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'LDAP'</span>,<span style="color: #483d8b;">'SearchFilter'</span><span style="color: black;">&#41;</span>, \
		<span style="color: #008000;">None</span><span style="color: black;">&#41;</span>
&nbsp;
	ldap_results = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
&nbsp;
	<span style="color: #ff7700;font-weight:bold;">while</span> <span style="color: #ff4500;">1</span>:
		result_type, result_data = ldap_object.<span style="color: black;">result</span><span style="color: black;">&#40;</span>ldap_result_id, <span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>
		<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span>result_data == <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>:
			<span style="color: #ff7700;font-weight:bold;">break</span>
		<span style="color: #ff7700;font-weight:bold;">else</span>:
			<span style="color: #808080; font-style: italic;">## here you don't have to append to a list</span>
			<span style="color: #808080; font-style: italic;">## you could do whatever you want with the individual entry</span>
			<span style="color: #808080; font-style: italic;">## The appending to list is just for illustration.</span>
			<span style="color: #ff7700;font-weight:bold;">if</span> result_type == ldap.<span style="color: black;">RES_SEARCH_ENTRY</span>:
				ldap_results += get_search_results<span style="color: black;">&#40;</span>result_data<span style="color: black;">&#41;</span>
	<span style="color: #ff7700;font-weight:bold;">for</span> ldap_result <span style="color: #ff7700;font-weight:bold;">in</span> ldap_results:
		account = RetrieveAccount<span style="color: black;">&#40;</span> \
			<span style="color: #808080; font-style: italic;"># Account Name \</span>
			ldap_result.<span style="color: black;">get_attr_values</span><span style="color: black;">&#40;</span>\
				config_object.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'LDAP'</span>,<span style="color: #483d8b;">'RelevantAttributes'</span><span style="color: black;">&#41;</span>.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">','</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span> ,\
			<span style="color: #808080; font-style: italic;"># Account Type \</span>
			ldap_result.<span style="color: black;">get_attr_values</span><span style="color: black;">&#40;</span>\
				config_object.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'LDAP'</span>,<span style="color: #483d8b;">'RelevantAttributes'</span><span style="color: black;">&#41;</span>.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">','</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>,\
			<span style="color: #808080; font-style: italic;"># Server \</span>
			ldap_result.<span style="color: black;">get_attr_values</span><span style="color: black;">&#40;</span>\
				config_object.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'LDAP'</span>,<span style="color: #483d8b;">'RelevantAttributes'</span><span style="color: black;">&#41;</span>.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">','</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>,\
			<span style="color: #808080; font-style: italic;"># Login \</span>
			ldap_result.<span style="color: black;">get_attr_values</span><span style="color: black;">&#40;</span>\
				config_object.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'LDAP'</span>,<span style="color: #483d8b;">'RelevantAttributes'</span><span style="color: black;">&#41;</span>.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">','</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">3</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>,\
			<span style="color: #808080; font-style: italic;"># Password \</span>
			ldap_result.<span style="color: black;">get_attr_values</span><span style="color: black;">&#40;</span>\
				config_object.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'LDAP'</span>,<span style="color: #483d8b;">'RelevantAttributes'</span><span style="color: black;">&#41;</span>.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">','</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">4</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>\
		<span style="color: black;">&#41;</span>
		config_output_filename = <span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span>\
			config_object.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'Main'</span>,<span style="color: #483d8b;">'ConfigFileOutputDir'</span><span style="color: black;">&#41;</span>, \
			<span style="color: #483d8b;">&quot;getmail_&quot;</span> + \
			account.<span style="color: black;">account_name</span> + \
			<span style="color: #483d8b;">&quot;.cfg&quot;</span><span style="color: black;">&#41;</span>
		config_file = GetmailConfigFile<span style="color: black;">&#40;</span><span style="color: #008000;">None</span>, \
			config_object.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'Main'</span>,<span style="color: #483d8b;">'DefaultGetmailConfigFile'</span><span style="color: black;">&#41;</span>, config_output_filename<span style="color: black;">&#41;</span>
		config_file.<span style="color: black;">set_pop3_account</span><span style="color: black;">&#40;</span>account<span style="color: black;">&#41;</span>
		log_object.<span style="color: black;">info</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Writing Account Configuration for &quot;</span> + account.<span style="color: black;">account_name</span> + \
				<span style="color: #483d8b;">&quot; to file &quot;</span> + config_output_filename<span style="color: black;">&#41;</span>
		config_file.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
		RetrieveMails<span style="color: black;">&#40;</span>\
			config_object.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'Main'</span>,<span style="color: #483d8b;">'GetmailBinary'</span><span style="color: black;">&#41;</span>, \
			config_output_filename, \
			config_object.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'Main'</span>,<span style="color: #483d8b;">'GetmailDir'</span><span style="color: black;">&#41;</span>\
		<span style="color: black;">&#41;</span>.<span style="color: black;">start</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
		<span style="color: #808080; font-style: italic;">#print config_output_filename</span>
		<span style="color: #808080; font-style: italic;">#print &quot;Name &quot; + account.account_name</span>
		<span style="color: #808080; font-style: italic;">#print &quot;Type &quot; + account.account_type</span>
		<span style="color: #808080; font-style: italic;">#print &quot;Server &quot; + account.server</span>
		<span style="color: #808080; font-style: italic;">#print &quot;Login &quot; + account.login</span>
		<span style="color: #808080; font-style: italic;">#print &quot;Password &quot; + account.password</span>
		<span style="color: #808080; font-style: italic;">#print &quot;-----------------&quot;</span>
		<span style="color: #808080; font-style: italic;">#print ldap_result.pretty_print()</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">&quot;__main__&quot;</span>:
	<span style="color: #ff7700;font-weight:bold;">try</span>:
		main_call<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span>
	<span style="color: #ff7700;font-weight:bold;">except</span>:
		log_object.<span style="color: black;">exception</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;An error occured!&quot;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>speichern wir als /home/secmail/getmail-ldap.py und machen die Datei durch ein</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">750</span> getmail-ldap.py</pre></div></div>

<p>ausführbar. Das Skript besitzt eine Konfigurationsdatei unter /home/secmail/getmail-ldap.cfg mit dem Inhalt</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;"><span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>Main<span style="">&#93;</span></span>
# Path to getmail
<span style="color: #000099;">GetmailBinary</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">/usr/bin/getmail</span>
# Directory that should be used as a storage by getmail
<span style="color: #000099;">GetmailDir</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">/home/secmail/getmail_data</span>
# Read default values for getmail from this file
<span style="color: #000099;">DefaultGetmailConfigFile</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">/home/secmail/getmailrc_template.cfg</span>
# Save the final configuration files which include the LDAP details to this directory
<span style="color: #000099;">ConfigFileOutputDir</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">/home/secmail/getmail_config</span>
&nbsp;
<span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>Logging<span style="">&#93;</span></span>
# Write messages to the following log file
<span style="color: #000099;">LogFile</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">/var/log/getmail-ldap.log</span>
# If a severe error occures a mail goes to the admin
# SMTP-Server to use for sending this error notification
<span style="color: #000099;">MailServer</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">localhost</span>
# Mail address of the sender of this error notification
<span style="color: #000099;">MailFrom</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">secmail@myserver</span>
# Recipients of this error notification
# separate multiple recipients by comma
<span style="color: #000099;">MailTo</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">root@myserver</span>
# Subject of the error notification
<span style="color: #000099;">MailSubject</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">Getmail-LDAP Error</span>
&nbsp;
<span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>LDAP<span style="">&#93;</span></span>
# Read LDAP information from this server
<span style="color: #000099;">LDAPServer</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">myserver</span>
# Authenticate with the following DN
<span style="color: #000099;">BindDN</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">uid=secmail, ou=users, o=effinger</span>
# Authenticate with the following password
<span style="color: #000099;">BindPassword</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">mysecmailpassword</span>
# Restrict search of external mail accounts to this DN
<span style="color: #000099;">SearchDN</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">ou=users, o=effinger</span>
# Scope of search for external mail accounts
# Possible values include SUB, ONE and BASE
<span style="color: #000099;">SearchScope</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">SUB</span>
# Identify external mail accounts with the following filter
<span style="color: #000099;">SearchFilter</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"><span style="">&#40;</span>&amp;<span style="">&#40;</span>dcSubMailAddress<span style="color: #000066; font-weight:bold;">=</span>*<span style="">&#41;</span><span style="">&#40;</span>objectClass<span style="color: #000066; font-weight:bold;">=</span>dcExternalMailAccount<span style="">&#41;</span><span style="">&#40;</span>dcAccountStatus<span style="color: #000066; font-weight:bold;">=</span>active<span style="">&#41;</span><span style="">&#40;</span>dcRetrieveType<span style="color: #000066; font-weight:bold;">=</span>*<span style="">&#41;</span><span style="">&#40;</span>dcRetrieveLogin<span style="color: #000066; font-weight:bold;">=</span>*<span style="">&#41;</span><span style="">&#40;</span>dcRetrievePassword<span style="color: #000066; font-weight:bold;">=</span>*<span style="">&#41;</span><span style="">&#41;</span></span>
# List of LDAP-Attributes used to determine the following variables
# 	1. Name for resulting getmail configuration file <span style="">&#40;</span>must be unique<span style="">&#41;</span>
#	2. Type for mail collection e.g. BrokenUIDLPOP3Retriever
#	3. Mail server to collect mails from
#	4. Login for mail server
# 	5. Password for mail server
# separate by comma
<span style="color: #000099;">RelevantAttributes</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">dcSubMailAddress,dcRetrieveType,dcRetrieveServer,dcRetrieveLogin,dcRetrievePassword</span></pre></div></div>

<p>Die Konfigurationsoptionen habe ich durch Kommentare dokumentiert. In jedem Fall muss in dieser Datei im Abschnitt [LDAP] der LDAPServer von myserver auf den jeweiligen DNS-Eintrag des OpenLDAP-Servers angepasst werden. Auch die Zeile mit BindPassword müssen wir ändern, so dass sie das  secmail Passwort enthält. Da diese Datei mit dem Passwort sensible Informationen enthält, die es einem Angreifer erlauben würden, aus dem LDAP-Verzeichnis alle Login-Informationen der externen Mail-Accounts zu lesen, setzen wir die Berechtigung für die Datei so, dass nur secmail darauf zugreifen kann:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">640</span> getmail-ldap.cfg</pre></div></div>

<p>Anschließend erzeugen wir die referenzierte Datei /home/secmail/getmailrc_template.cfg mit dem Inhalt</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;"><span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>retriever<span style="">&#93;</span></span>
<span style="color: #000099;">type</span> <span style="color: #000066; font-weight:bold;">=</span>
<span style="color: #000099;">server</span> <span style="color: #000066; font-weight:bold;">=</span>
<span style="color: #000099;">username</span> <span style="color: #000066; font-weight:bold;">=</span>
<span style="color: #000099;">password</span> <span style="color: #000066; font-weight:bold;">=</span> 
&nbsp;
<span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>destination<span style="">&#93;</span></span>
<span style="color: #000099;">type</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> MDA_external</span>
<span style="color: #000099;">path</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> /usr/sbin/exim4</span>
<span style="color: #000099;">arguments</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> <span style="">&#40;</span></span><span style="color: #933;">&quot;user@mailhost.tld&quot;</span>,<span style="">&#41;</span>
&nbsp;
<span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>options<span style="">&#93;</span></span>
# for testing do not delete mails
#delete <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> false</span>
<span style="color: #000099;">delete</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> true</span>
<span style="color: #000099;">message_log</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> /var/log/getmail.log</span>
<span style="color: #000099;">read_all</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> true</span>
# do not manipulate the header
<span style="color: #000099;">delivered_to</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> false</span>
<span style="color: #000099;">received</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> false</span></pre></div></div>

<p>Die einzelnen Konfigurationsoptionen werden in der <a href="http://pyropus.ca/software/getmail/configuration.html#rcfile">Dokumentation von getmail</a> detailliert erläutert. Wichtig ist hier zu wissen, dass das Python-Skript diese Datei als Vorlage nimmt und dann in der Sektion [retriever] die Werte für type, server, username und password aus dem LDAP-Verzeichnis einträgt. In der Sektion [destination] wird der Wert arguments so abgeändert, dass die Mail an den lokalen Benutzer geht. Das <a href="http://archives.devshed.com/forums/networking-100/getmail-and-exim4t-64730.html">Zusammenspiel von getmail und exim</a> wird in einem Forumsbeitrag näher erläutert.<br />
<strong>Empfehlung:</strong> Zu Beginn ist es sicherlich sinnvoll, im Abschnitt [options] den Wert von delete auf false zu setzen. So werden die Mails vom externen Server zwar heruntergeladen, aber nicht gelöscht. Wenn alles einwandfrei funktioniert, kann man hier den Wert wieder auf true setzen.<br />
Auch hier setzen wir die Berechtigungen für die Datei entsprechend:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">640</span> getmailrc_template.cfg</pre></div></div>

<p>Nun erzeugen wir noch ein Verzeichnis, welches getmail benötigt und eines zum Ablegen der finalen Konfigurationsdateien mit den Berechtigungen, so dass nur secmail darauf zugreifen kann.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-m</span> <span style="color: #000000;">750</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>secmail<span style="color: #000000; font-weight: bold;">/</span>getmail_data <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>secmail<span style="color: #000000; font-weight: bold;">/</span>getmail_config</pre></div></div>

<p>Dann erzeugen wir die Logdateien im Verzeichnis /var/log und setzen die Berechtigung so, dass auch secmail in diese Dateien schreiben kann.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">touch</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>getmail<span style="color: #7a0874; font-weight: bold;">&#123;</span>-ldap,<span style="color: #7a0874; font-weight: bold;">&#125;</span>.log
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">chown</span> root.secmail <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>getmail<span style="color: #7a0874; font-weight: bold;">&#123;</span>-ldap,<span style="color: #7a0874; font-weight: bold;">&#125;</span>.log
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">660</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>getmail<span style="color: #7a0874; font-weight: bold;">&#123;</span>-ldap,<span style="color: #7a0874; font-weight: bold;">&#125;</span>.log</pre></div></div>

<h2>Testen des Mailabrufs</h2>
<p>Mit dem Aufruf des Pythonskripts durch ein</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #660033;">-u</span> secmail <span style="color: #660033;">-s</span>
<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>secmail<span style="color: #000000; font-weight: bold;">/</span>getmail-ldap.py</pre></div></div>

<p>und das anschließende Inspizieren der Log-Dateien /var/log/getmail-ldap.log und /var/log/getmail.log können wir testen, ob die Mails heruntergeladen werden. Ob die Zustellung an den lokalen Benutzer geklappt hat, sieht man an neuen Dateien im jeweiligen maildir (hier: /home/paul/mail/paulpanzer@gmx.de/maildir/INBOX/new) bzw. durch Abruf der Mails mit einem Client z.B. per IMAP.</p>
<h2>Regelmäßiges Zustellen externer Mails</h2>
<p>Damit die Mails regelmäßig von dem externen Server abgerufen werden, richten wir einen Cron-Job ein, der alle fünf Minuten prüft, ob neue Mails vorhanden sind. Dazu führen wir als secmail User</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">crontab <span style="color: #660033;">-e</span></pre></div></div>

<p>aus und tragen dort die Zeile</p>

<div class="wp_syntax"><div class="code"><pre class="cron" style="font-family:monospace;">*/5 * * * * /home/secmail/getmail-ldap.py</pre></div></div>

<p>ein. Bei Adam Kane kann man nachlesen, <a href="http://www.foogazi.com/2006/12/07/understand-cron-jobs-in-5-minutes/">was ein Cron-Job ist</a>.</p>
<h2>Feintuning &#8211; Logdateien mit Logrotate verwalten</h2>
<p>Nachdem nun alles soweit eingerichtet ist, kümmern wir uns noch darum, dass die Logdateien ordentlich aufgeräumt werden. Wir erzeugen deshalb im Verzeichnis /etc/logrotate.d/ die Datei dovecot mit dem Inhalt</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Logrotate Konfiguration für dovecot</span>
<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>dovecot.log <span style="color: #7a0874; font-weight: bold;">&#123;</span>
        daily
        missingok
        rotate <span style="color: #000000;">14</span>
        compress
        delaycompress
        notifempty
        create <span style="color: #000000;">600</span> root root
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>dovecot-deliver.log <span style="color: #7a0874; font-weight: bold;">&#123;</span>
        daily
        missingok
        rotate <span style="color: #000000;">14</span>
        compress
        delaycompress
        notifempty
        create <span style="color: #000000;">600</span> root secmail
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>und ebenso die Datei getmail mit diesem Inhalt</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Logrotate Konfiguration für getmail und getmail-ldap</span>
<span style="color: #666666; font-style: italic;"># siehe /home/secmail/getmail-ldap.py</span>
<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>getmail.log <span style="color: #7a0874; font-weight: bold;">&#123;</span>
        daily
        missingok
        rotate <span style="color: #000000;">14</span>
        compress
        delaycompress
        notifempty
        create <span style="color: #000000;">660</span> root secmail
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>getmail-ldap.log <span style="color: #7a0874; font-weight: bold;">&#123;</span>
        daily
        missingok
        rotate <span style="color: #000000;">14</span>
        compress
        delaycompress
        notifempty
        create <span style="color: #000000;">660</span> root secmail
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>Wir korrigieren außerdem noch einen kleinen Bug im exim-Paket, indem wir die Zeile</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">        create <span style="color: #000000;">640</span> Debian-exim adm</pre></div></div>

<p>in den beiden Dateien exim-base und exim-paniclog im selben Verzeichnis durch folgende Zeile ersetzen</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">        create <span style="color: #000000;">640</span> Debian-exim root</pre></div></div>

<p><strong><a href="http://www.openldap.org/lists/openldap-software/200111/msg00307.html">Tip zum Logging des OpenLDAP-Servers von der OpenLDAP-Mailingliste</a>:</strong> Standardmäßig wird alles in die syslog geschrieben. Wenn man der Übersichtlichkeit halber eine eigene Logdatei für OpenLDAP haben möchte, muss man OpenLDAP mitteilen, dass es beim Loggen einen eigenen Selektor (hier:local4) verwenden soll. Dazu muss die Datei /etc/default/slapd die folgende Zeile enthalten:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">SLAPD_OPTIONS</span>=<span style="color: #ff0000;">&quot;-l local4&quot;</span></pre></div></div>

<p>Nun konfigurieren wir syslog so, dass es alle Informationen mit diesem Selektor in eine eigene Datei schreibt. Bei Verwendung von sysklogd ergänzen wir in der Datei /etc/syslog.conf folgende Zeile</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Log openldap to separate file</span>
local4.<span style="color: #000000; font-weight: bold;">*</span>			-<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>slapd.log</pre></div></div>

<p>Bei Verwendung von rsyslog erzeugen wir die Datei /etc/rsyslog.d/40-slapd.conf mit folgendem Inhalt</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Log openldap to separate file</span>
local4.<span style="color: #000000; font-weight: bold;">*</span>			-<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>slapd.log
<span style="color: #000000; font-weight: bold;">&amp;</span> ~</pre></div></div>

<p>Außerdem legen wir eine entsprechende Datei namens /etc/logrotate.d/slapd mit dem folgenden Inhalt an.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>slapd.log <span style="color: #7a0874; font-weight: bold;">&#123;</span>
        daily
        missingok
        rotate <span style="color: #000000;">14</span>
        compress
        delaycompress
        notifempty
        create <span style="color: #000000;">660</span> root openldap
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>Damit die Änderungen Wirkung zeigen, müssen wir anfangs eine Logdatei erzeugen und anschließend Syslog und OpenLDAP neu starten bzw. die Konfiguration neu laden.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">touch</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>slapd.log
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">chown</span> root.openldap <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>slapd.log
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">660</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>slapd.log
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>sysklogd reload
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>slapd restart</pre></div></div>

<h2>Links zum getmail-ldap Python-Skript</h2>
<p>Bei der Erstellung des Python-Skripts waren einige Webseiten sehr hilfreich, die deshalb hier aufgeführt werden, obowhl sie für die Einrichtung des Mailservers ohne Bedeutung sind.</p>
<ul>
<li><a href="http://www.network-theory.co.uk/python/intro/">Einführung in Python &#8211; An Introduction to Python</a></li>
<li><a href="http://www.diveintopython.org/toc/index.html">Eine weitere Einführung &#8211; Dive into Python</a></li>
<li><a href="http://www.python.org/dev/peps/pep-0008/">Guter Stil bei der Python-Programmierung &#8211; Style Guide for Python Code</a></li>
<li><a href="http://docs.python.org/library/logging.html">Offizielle Dokumentation zum Logging-Modul von Python</a></li>
<li><a href="http://code.activestate.com/recipes/466332/">Beispielcode, welcher das Logging-Modul verwendet</a></li>
<li><a href="http://python-ldap.sourceforge.net/doc/html/ldap.html">Offizielle Dokumenation zum LDAP-Modul von Python</a></li>
<li><a href="http://www.grotan.com/ldap/python-ldap-samples.html">Beispiel zur Verwendung des LDAP-Moduls von Python</a></li>
<li><a href="http://www.packtpub.com/article/python-ldap-applications-ldap-opearations">Die LDAP-Helper Klasse, welche das Verarbeiten von LDAP-Resultaten wesentlich vereinfacht</a></li>
<li><a href="http://www.devshed.com/c/a/Python/Basic-Threading-in-Python/1/">Grundlagen von Threading in Python</a></li>
<li><a href="http://docs.python.org/library/subprocess.html">Offizielle Dokumentation zum Subprozess-Modul von Python</a></li>
<li><a href="http://blog.doughellmann.com/2007/07/pymotw-subprocess.html">Beispielcode zur Verwendung von Unterprozessen in Doug Hellmanns Blog</a></li>
<li><a href="http://www.gossamer-threads.com/lists/python/python/724330">Verwendung von Unterprozessen ohne den Parameter Shell=True</a></li>
</ul>
<h2>Weitere Konfigurationsschritte</h2>
<p>Die Schritte zur Einrichtung der im <a href="http://www.effinger.org/blog/2009/03/22/dovecot-exim-openldap-und-getmail-unter-ubuntu-1-openldap/">ersten Teil</a> angesprochenen Komponenten Roundcube als Webmaildienst, LDAP zur Verwaltung von Addressen und Spamassassin zum Filtern von Spam-Mails sowie eine Anleitung zum Einrichten eins Mail-Clients werden aufgrund von Zeitmangel leider erst in einigen Wochen verfügbar sein.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.effinger.org/blog/2009/03/22/dovecot-exim-openldap-und-getmail-unter-ubuntu-4-getmail/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Dovecot, Exim, OpenLDAP und getmail unter Ubuntu &#8211; (3) Exim</title>
		<link>http://www.effinger.org/blog/2009/03/22/dovecot-exim-openldap-und-getmail-unter-ubuntu-3-exim/</link>
		<comments>http://www.effinger.org/blog/2009/03/22/dovecot-exim-openldap-und-getmail-unter-ubuntu-3-exim/#comments</comments>
		<pubDate>Sun, 22 Mar 2009 16:57:48 +0000</pubDate>
		<dc:creator>Markus Effinger</dc:creator>
				<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[dovecot]]></category>
		<category><![CDATA[exim]]></category>
		<category><![CDATA[getmail]]></category>
		<category><![CDATA[LDAP]]></category>
		<category><![CDATA[OpenLDAP]]></category>

		<guid isPermaLink="false">http://www.effinger.org/blog/?p=508</guid>
		<description><![CDATA[<p>Nach der Einrichtung von OpenLDAP im ersten Teil, der Anpassung und Konfiguration von dovecot im zweiten Teil befasst sich der dritte Teil mit der Konfiguration von Exim. Obwohl fast alles im Blog detailliert beschrieben ist, empfehle ich, die Konfigurationsdateien für das Mailsystem herunterzuladen.</p>
Installation von Exim
<p>Da wir bei exim die LDAP-Unterstützung benötigen, müssen wir die entsprechende [...]]]></description>
			<content:encoded><![CDATA[<p>Nach der <a href="http://www.effinger.org/blog/2009/03/22/dovecot-exim-openldap-und-getmail-unter-ubuntu-1-openldap/">Einrichtung von OpenLDAP im ersten Teil</a>, der <a href="http://www.effinger.org/blog/2009/03/22/dovecot-postfix-openldap-und-getmail-unter-ubuntu-2-dovecot/">Anpassung und Konfiguration von dovecot im zweiten Teil</a> befasst sich der dritte Teil mit der Konfiguration von Exim. Obwohl fast alles im Blog detailliert beschrieben ist, empfehle ich, die <a href="http://www.effinger.org/blog/wp-content/uploads/2009/03/configfiles-mailsystem.tgz">Konfigurationsdateien für das Mailsystem herunterzuladen</a>.</p>
<h2>Installation von Exim</h2>
<p>Da wir bei exim die LDAP-Unterstützung benötigen, müssen wir die entsprechende Exim-Version mit einem</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> exim4-daemon-heavy</pre></div></div>

<p>installieren. Dabei wird notwendigerweise auch postfix entfernt, das von Ubuntu standardmäßig als Message Transfer Agent (MTA) eingesetzt wird.</p>
<h2>Konfiguration von Exim</h2>
<p>Damit exim auf die SSL-Zertifikate zur Verschlüsselung der SMTP-Verbindungen zugreifen kann, müssen wir den exim-Benutzer zur Gruppe ssl-cert hinzufügen</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> adduser Debian-exim ssl-cert</pre></div></div>

<p>Zur Konfiguration von exim kann man unter Ubuntu/Debian ein spezielles Konfigurationspaket namens exim4-config verwenden. Dieses erzeugt aus einzelnen Dateien im Verzeichnis /etc/exim4/conf.d eine finale Konfigurationsdatei (<a href="http://pkg-exim4.alioth.debian.org/README/README.Debian.html">nähere Informationen zu exim4-config auf der Debian-Seite</a>). Ich empfehle, dieses Konfigurationspaket zu verwenden und die Grundkonfiguration mit</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> dpkg-reconfigure exim4-config</pre></div></div>

<p>zu starten. Im anschließenden Konfigurationsdialog wählen wir <em>Nur lokale Mailzustellung; keine Netzwerkverbindung</em>. Dann geben wir den korrekten DNS-Namen des Servers an, den wir auch schon bei der Erzeugung der Schlüsselzertifikate verwendet haben (hier im Beispiel <em>myserver</em>). Der nächste Punkt ist eigentlich selbsterklärend, wenn der SMTP-Server über alle Interfaces erreichbar sein soll, das Feld leer lassen, ansonsten die gewünschte IP-Addresse eintragen. Der nächste Schritt fordert uns auf, mögliche weitere Domains für den lokalen Mailempfang anzugeben (im Zweifelsfall leer lassen). Der Punkt, ob DNS-Anfragen minimiert werden sollen, beantworten wir mit <em>Nein</em>. Als Speicherformat für lokale Mails wählen wir <em>mbox</em> (wird aber später modifiziert). Die Einstellungen sollen in <em>kleine Dateien</em> aufgeteilt werden. Nun machen wir uns an die Anpassung. Wir editieren die Datei /etc/exim4/update-exim4.conf.conf und ändern die letzte Zeile mit dem Eintrag</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">dc_localdelivery</span>=<span style="color: #ff0000;">'mail_spool'</span></pre></div></div>

<p>in</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">dc_localdelivery</span>=<span style="color: #ff0000;">'dovecot_delivery'</span></pre></div></div>

<p>ab. Im nächsten Schritt löschen wir den Inhalt des Verzeichnisses /etc/exim4/conf.d und kopieren die Dateien aus dem <a href="http://www.effinger.org/blog/wp-content/uploads/2009/03/configfiles-mailsystem.tgz">Konfigurationspaket</a> dorthin mit</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>exim4<span style="color: #000000; font-weight: bold;">/</span>conf.d
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #660033;">-R</span> <span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>configfiles<span style="color: #000000; font-weight: bold;">/</span>exim<span style="color: #000000; font-weight: bold;">/</span>conf.d <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>exim4</pre></div></div>

<p>In der Datei /etc/exim4/conf.d/main/00_local_macros passen wir folgende Zeilen an:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ldap_default_servers = myserver
MAIN_TLS_CERTIFICATE = <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>ssl<span style="color: #000000; font-weight: bold;">/</span>certs<span style="color: #000000; font-weight: bold;">/</span>myserver.crt
MAIN_TLS_PRIVATEKEY = <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>ssl<span style="color: #000000; font-weight: bold;">/</span>private<span style="color: #000000; font-weight: bold;">/</span>myserver.key</pre></div></div>

<p>Wir ersetzen hier myserver jeweils durch den DNS-Namen des Servers. Nun erzeugen wir die finale Konfigurationsdatei für exim und starten exim anschließend neu mit dem Befehl</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> update-exim4.conf <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>exim4 restart</pre></div></div>

<p>Das Programm erzeugt so eine finale Konfigurationsdatei, die unter /var/lib/exim4/config.autogenerated abgelegt wird. Für diejenigen, die das Debiankonfigurationssystem nicht nutzen können/wollen, ist hier deren Inhalt aufgeführt:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#########</span>
<span style="color: #666666; font-style: italic;"># WARNING WARNING WARNING</span>
<span style="color: #666666; font-style: italic;"># WARNING WARNING WARNING</span>
<span style="color: #666666; font-style: italic;"># WARNING WARNING WARNING</span>
<span style="color: #666666; font-style: italic;"># WARNING WARNING WARNING</span>
<span style="color: #666666; font-style: italic;"># WARNING WARNING WARNING</span>
<span style="color: #666666; font-style: italic;"># This file is generated dynamically from the files in</span>
<span style="color: #666666; font-style: italic;"># the conf.d/ directory, or from exim4.conf.template respectively.</span>
<span style="color: #666666; font-style: italic;"># Additional information is read from update-exim4.conf.conf</span>
<span style="color: #666666; font-style: italic;"># This version of the file was created from the directory /etc/exim4</span>
<span style="color: #666666; font-style: italic;"># Any changes you make here will be lost.</span>
<span style="color: #666666; font-style: italic;"># See /usr/share/doc/exim4-base/README.Debian.gz and update-exim4.conf(8)</span>
<span style="color: #666666; font-style: italic;"># for instructions of customization.</span>
<span style="color: #666666; font-style: italic;"># WARNING WARNING WARNING</span>
<span style="color: #666666; font-style: italic;"># WARNING WARNING WARNING</span>
<span style="color: #666666; font-style: italic;"># WARNING WARNING WARNING</span>
<span style="color: #666666; font-style: italic;"># WARNING WARNING WARNING</span>
<span style="color: #666666; font-style: italic;"># WARNING WARNING WARNING</span>
<span style="color: #666666; font-style: italic;">#########</span>
&nbsp;
FIRST_USER_ACCOUNT_UID = <span style="color: #000000;">1000</span>
&nbsp;
acl_not_smtp_start = acl_check_not_smtp
&nbsp;
ldap_default_servers = myserver
&nbsp;
LDAP_BASE = <span style="color: #007800;">ou</span>=<span style="color: #c20cb9; font-weight: bold;">users</span>,<span style="color: #007800;">o</span>=effinger
&nbsp;
<span style="color: #007800;">SEC_MAIL_USER</span>=secmail
IS_SENDER_SECMAIL = eq<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #007800;">$originator_uid</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #800000;">${extract{2}</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>:<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #800000;">${lookup{SEC_MAIL_USER}</span>lsearch<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">passwd</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #007800;">$value</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
received_header_text = <span style="color: #800000;">${if !IS_SENDER_SECMAIL {Received: ${if def:sender_rcvhost {from $sender_rcvhost\n\t}</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #800000;">${if def:sender_ident {from ${quote_local_part:$sender_ident}</span> <span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #800000;">${if def:sender_helo_name {(helo=$sender_helo_name)\n\t}</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>by <span style="color: #007800;">$primary_hostname</span> <span style="color: #800000;">${if def:received_protocol {with $received_protocol}</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> <span style="color: #800000;">${if def:tls_cipher {($tls_cipher)\n\t}</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>Exim <span style="color: #007800;">$version_number</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>\n\t<span style="color: #800000;">${if def:sender_address {(envelope-from &lt;$sender_address&gt;)\n\t}</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #c20cb9; font-weight: bold;">id</span> <span style="color: #007800;">$message_exim_id</span><span style="color: #800000;">${if def:received_for {\n\tfor $received_for}</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
LOCAL_DELIVERY_SECMAIL = dovecot_delivery_secmail
&nbsp;
MAIN_TLS_ENABLE = <span style="color: #c20cb9; font-weight: bold;">yes</span>
MAIN_TLS_CERTIFICATE = <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>ssl<span style="color: #000000; font-weight: bold;">/</span>certs<span style="color: #000000; font-weight: bold;">/</span>myserver.crt
MAIN_TLS_PRIVATEKEY = <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>ssl<span style="color: #000000; font-weight: bold;">/</span>private<span style="color: #000000; font-weight: bold;">/</span>myserver.key
MAIN_TLS_VERIFY_CERTIFICATES = <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>ssl<span style="color: #000000; font-weight: bold;">/</span>certs<span style="color: #000000; font-weight: bold;">/</span>ca.crt
&nbsp;
SENDER_EXTRACT_UID = <span style="color: #800000;">${sg{${lc:$sender_address}</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> \
	<span style="color: #7a0874; font-weight: bold;">&#123;</span>\N^<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>a-zA-Z0-<span style="color: #000000;">9</span>_.-<span style="color: #7a0874; font-weight: bold;">&#93;</span>+<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #000000; font-weight: bold;">@</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>a-zA-Z0-<span style="color: #000000;">9</span>_.-<span style="color: #7a0874; font-weight: bold;">&#93;</span>+<span style="color: #000000; font-weight: bold;">@</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>a-zA-Z0-<span style="color: #000000;">9</span>_.-<span style="color: #7a0874; font-weight: bold;">&#93;</span>+<span style="color: #7a0874; font-weight: bold;">&#41;</span>$\N<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>\$<span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
SENDER_EXTRACT_REAL_MAIL = <span style="color: #800000;">${sg{${lc:$sender_address}</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> \
	<span style="color: #7a0874; font-weight: bold;">&#123;</span>\N^<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>a-zA-Z0-<span style="color: #000000;">9</span>_.-<span style="color: #7a0874; font-weight: bold;">&#93;</span>+<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #000000; font-weight: bold;">@</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>a-zA-Z0-<span style="color: #000000;">9</span>_.-<span style="color: #7a0874; font-weight: bold;">&#93;</span>+<span style="color: #000000; font-weight: bold;">@</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>a-zA-Z0-<span style="color: #000000;">9</span>_.-<span style="color: #7a0874; font-weight: bold;">&#93;</span>+<span style="color: #7a0874; font-weight: bold;">&#41;</span>$\N<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>\$<span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
IS_SENDER_REMOTE = $<span style="color: #7a0874; font-weight: bold;">&#123;</span>lookup ldap \
		<span style="color: #7a0874; font-weight: bold;">&#123;</span>ldap:<span style="color: #000000; font-weight: bold;">///</span><span style="color: #007800;">uid</span>=<span style="color: #800000;">${quote_ldap_dn:SENDER_EXTRACT_UID}</span>,LDAP_BASE??sub?<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">&amp;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">dcSubMailAddress</span>=<span style="color: #800000;">${quote_ldap:SENDER_EXTRACT_REAL_MAIL}</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">dcAccountStatus</span>=active<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> \
		<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #c20cb9; font-weight: bold;">yes</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>fail<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
IS_LOCAL_PART_VALID = $<span style="color: #7a0874; font-weight: bold;">&#123;</span>lookup ldap \
		<span style="color: #7a0874; font-weight: bold;">&#123;</span>ldap:<span style="color: #000000; font-weight: bold;">///</span><span style="color: #007800;">uid</span>=<span style="color: #800000;">${quote_ldap_dn:${lc:$local_part}</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>,LDAP_BASE??base?<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">objectClass</span>=dcMailUser<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> \
		<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #c20cb9; font-weight: bold;">yes</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>no<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
GET_UID_FOR_RCPT = $<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #c20cb9; font-weight: bold;">tr</span> \
	<span style="color: #7a0874; font-weight: bold;">&#123;</span>$<span style="color: #7a0874; font-weight: bold;">&#123;</span>lookup ldapm \
		<span style="color: #7a0874; font-weight: bold;">&#123;</span>ldap:<span style="color: #000000; font-weight: bold;">///</span>LDAP_BASE??sub?<span style="color: #800000;">${if match_domain{$domain}</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>+local_domains<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">mail</span>=<span style="color: #800000;">${quote_ldap:$local_part}</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">&amp;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">dcSubMailAddress</span>=<span style="color: #800000;">${quote_ldap:$local_part@$domain}</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">dcAccountStatus</span>=active<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> \
		<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #800000;">${sg{${lc:$value}</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>\N<span style="color: #7a0874; font-weight: bold;">&#40;</span>?m<span style="color: #7a0874; font-weight: bold;">&#41;</span>^.<span style="color: #000000; font-weight: bold;">*</span><span style="color: #007800;">uid</span>=<span style="color: #ff0000;">&quot;(.*?)&quot;</span>.<span style="color: #000000; font-weight: bold;">*</span>$\N<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>\$<span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> \
	<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> \
	<span style="color: #7a0874; font-weight: bold;">&#123;</span>\n<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>,<span style="color: #7a0874; font-weight: bold;">&#125;</span> \
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
GET_ALIAS_FOR_RCPT = $<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #c20cb9; font-weight: bold;">tr</span> \
	<span style="color: #7a0874; font-weight: bold;">&#123;</span>$<span style="color: #7a0874; font-weight: bold;">&#123;</span>lookup ldapm \
		<span style="color: #7a0874; font-weight: bold;">&#123;</span>ldap:<span style="color: #000000; font-weight: bold;">///</span>LDAP_BASE?mail,dcSubMailAddress?sub?<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">|</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">dcMailAlias</span>=<span style="color: #800000;">${quote_ldap:$local_part${if match_domain{$domain}</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>+local_domains<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000; font-weight: bold;">@</span><span style="color: #007800;">$domain</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">&amp;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">dcMailAlternateAddress</span>=<span style="color: #800000;">${quote_ldap:$local_part@$domain}</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">dcAccountStatus</span>=active<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> \
		<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #800000;">${sg{${lc:$value}</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>\N<span style="color: #7a0874; font-weight: bold;">&#40;</span>?m<span style="color: #7a0874; font-weight: bold;">&#41;</span>^.<span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>mail<span style="color: #000000; font-weight: bold;">|</span>dcsubmailaddress<span style="color: #7a0874; font-weight: bold;">&#41;</span>=<span style="color: #ff0000;">&quot;(.*?)&quot;</span>.<span style="color: #000000; font-weight: bold;">*</span>$\N<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>\$<span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> \
	<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> \
	<span style="color: #7a0874; font-weight: bold;">&#123;</span>\n<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>,<span style="color: #7a0874; font-weight: bold;">&#125;</span> \
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
GET_ALIAS_FOR_AUTH = $<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #c20cb9; font-weight: bold;">tr</span> \
	<span style="color: #7a0874; font-weight: bold;">&#123;</span>$<span style="color: #7a0874; font-weight: bold;">&#123;</span>lookup ldapm \
		<span style="color: #7a0874; font-weight: bold;">&#123;</span>ldap:<span style="color: #000000; font-weight: bold;">///</span>LDAP_BASE?dcMailAlias,dcMailAlternateAddress?sub?<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">|</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">mail</span>=<span style="color: #800000;">${quote_ldap:AUTH_SERVER_MAIL}</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">&amp;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">dcSubMailAddress</span>=<span style="color: #800000;">${quote_ldap:AUTH_SERVER_MAIL}</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">dcAccountStatus</span>=active<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> \
		<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #800000;">${sg{${lc:$value}</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>\N<span style="color: #7a0874; font-weight: bold;">&#40;</span>?m<span style="color: #7a0874; font-weight: bold;">&#41;</span>^.<span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>dcmailalias<span style="color: #000000; font-weight: bold;">|</span>dcmailalternateaddress<span style="color: #7a0874; font-weight: bold;">&#41;</span>=<span style="color: #ff0000;">&quot;(.*?)&quot;</span>.<span style="color: #000000; font-weight: bold;">*</span>$\N<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>\$<span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> \
	<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> \
	<span style="color: #7a0874; font-weight: bold;">&#123;</span>\n<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>,<span style="color: #7a0874; font-weight: bold;">&#125;</span> \
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
GET_COMPLETE_MAIL_FOR_LOCAL_PART_UID = $<span style="color: #7a0874; font-weight: bold;">&#123;</span>lookup ldap \
		<span style="color: #7a0874; font-weight: bold;">&#123;</span>ldap:<span style="color: #000000; font-weight: bold;">///</span><span style="color: #007800;">uid</span>=<span style="color: #800000;">${quote_ldap_dn:${lc:$local_part}</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>,LDAP_BASE?mail?base?<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">objectClass</span>=dcMailUser<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> \
		<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #800000;">${local_part}</span><span style="color: #000000; font-weight: bold;">@</span><span style="color: #800000;">${value}</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
GET_LOCAL_MAIL = <span style="color: #800000;">${if match_domain{$parent_domain}</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>+local_domains<span style="color: #7a0874; font-weight: bold;">&#125;</span> \
	<span style="color: #7a0874; font-weight: bold;">&#123;</span>GET_COMPLETE_MAIL_FOR_LOCAL_PART_UID<span style="color: #7a0874; font-weight: bold;">&#125;</span> \
	<span style="color: #7a0874; font-weight: bold;">&#123;</span>$<span style="color: #7a0874; font-weight: bold;">&#123;</span>lookup ldap \
		<span style="color: #7a0874; font-weight: bold;">&#123;</span>ldap:<span style="color: #000000; font-weight: bold;">///</span><span style="color: #007800;">uid</span>=<span style="color: #800000;">${quote_ldap_dn:${lc:$local_part}</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>,LDAP_BASE?dcSubMailAddress?sub?<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">&amp;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">dcSubMailAddress</span>=<span style="color: #800000;">${quote_ldap:$parent_local_part@$parent_domain}</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">dcAccountStatus</span>=active<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> \
		<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #007800;">$local_part</span><span style="color: #000000; font-weight: bold;">@</span><span style="color: #007800;">$parent_local_part</span><span style="color: #000000; font-weight: bold;">@</span><span style="color: #007800;">$parent_domain</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> \
		<span style="color: #7a0874; font-weight: bold;">&#123;</span>GET_COMPLETE_MAIL_FOR_LOCAL_PART_UID<span style="color: #7a0874; font-weight: bold;">&#125;</span> \
	<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> \
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
IS_AUTH_REMOTE = $<span style="color: #7a0874; font-weight: bold;">&#123;</span>lookup ldap <span style="color: #7a0874; font-weight: bold;">&#123;</span> \
	<span style="color: #007800;">user</span>=<span style="color: #ff0000;">&quot;uid=<span style="color: #007800;">${quote_ldap_dn:AUTH_SERVER_UID}</span>,LDAP_BASE&quot;</span> \
    	<span style="color: #007800;">pass</span>=<span style="color: #800000;">${quote:AUTH_SERVER_PASSWORD}</span> \
	ldap:<span style="color: #000000; font-weight: bold;">///</span>LDAP_BASE??sub?<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">&amp;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">dcSubMailAddress</span>=<span style="color: #800000;">${quote_ldap:AUTH_SERVER_MAIL}</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">dcAccountStatus</span>=active<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">dcSMTPServer</span>=<span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">dcSMTPLogin</span>=<span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">dcSMTPPassword</span>=<span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> \
	<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #c20cb9; font-weight: bold;">yes</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>fail<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
AUTH_REMOTE_SERVER = $<span style="color: #7a0874; font-weight: bold;">&#123;</span>lookup ldap <span style="color: #7a0874; font-weight: bold;">&#123;</span> \
	<span style="color: #007800;">user</span>=<span style="color: #ff0000;">&quot;uid=<span style="color: #007800;">${quote_ldap_dn:AUTH_SERVER_UID}</span>,LDAP_BASE&quot;</span> \
    	<span style="color: #007800;">pass</span>=<span style="color: #800000;">${quote:AUTH_SERVER_PASSWORD}</span> \
	ldap:<span style="color: #000000; font-weight: bold;">///</span>LDAP_BASE?dcSMTPServer?sub?<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">&amp;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">dcSubMailAddress</span>=<span style="color: #800000;">${quote_ldap:AUTH_SERVER_MAIL}</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">dcAccountStatus</span>=active<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">dcSMTPServer</span>=<span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">dcSMTPLogin</span>=<span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">dcSMTPPassword</span>=<span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> \
	<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #007800;">$value</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
AUTH_REMOTE_LOGIN = $<span style="color: #7a0874; font-weight: bold;">&#123;</span>lookup ldap <span style="color: #7a0874; font-weight: bold;">&#123;</span>\
	<span style="color: #007800;">user</span>=<span style="color: #ff0000;">&quot;uid=<span style="color: #007800;">${quote_ldap_dn:AUTH_SERVER_UID}</span>,LDAP_BASE&quot;</span> \
    	<span style="color: #007800;">pass</span>=<span style="color: #800000;">${quote:AUTH_SERVER_PASSWORD}</span> \
	ldap:<span style="color: #000000; font-weight: bold;">///</span>LDAP_BASE?dcSMTPLogin?sub?<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">&amp;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">dcSubMailAddress</span>=<span style="color: #800000;">${quote_ldap:AUTH_SERVER_MAIL}</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">dcAccountStatus</span>=active<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">dcSMTPServer</span>=<span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">dcSMTPLogin</span>=<span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">dcSMTPPassword</span>=<span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> \
	<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #007800;">$value</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
AUTH_REMOTE_PASSWORD = $<span style="color: #7a0874; font-weight: bold;">&#123;</span>lookup ldap <span style="color: #7a0874; font-weight: bold;">&#123;</span>\
	<span style="color: #007800;">user</span>=<span style="color: #ff0000;">&quot;uid=<span style="color: #007800;">${quote_ldap_dn:AUTH_SERVER_UID}</span>,LDAP_BASE&quot;</span> \
    	<span style="color: #007800;">pass</span>=<span style="color: #800000;">${quote:AUTH_SERVER_PASSWORD}</span> \
	ldap:<span style="color: #000000; font-weight: bold;">///</span>LDAP_BASE?dcSMTPPassword?sub?<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">&amp;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">dcSubMailAddress</span>=<span style="color: #800000;">${quote_ldap:AUTH_SERVER_MAIL}</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">dcAccountStatus</span>=active<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">dcSMTPServer</span>=<span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">dcSMTPLogin</span>=<span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">dcSMTPPassword</span>=<span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> \
	<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #007800;">$value</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
AUTH_SERVER_PLAIN_AUTH = $<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000; font-weight: bold;">if</span> ldapauth \
    <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #007800;">user</span>=<span style="color: #ff0000;">&quot;uid=<span style="color: #007800;">${quote_ldap_dn:${sg{${lc:$auth2}</span>} <span style="color: #000099; font-weight: bold;">\
</span> 	{<span style="color: #000099; font-weight: bold;">\N</span>^([a-zA-Z0-9_.-]+)@([a-zA-Z0-9_@.-]+)$<span style="color: #000099; font-weight: bold;">\N</span>}{<span style="color: #000099; font-weight: bold;">\$</span>1}}},LDAP_BASE&quot;</span> \
    <span style="color: #007800;">pass</span>=<span style="color: #800000;">${quote:$auth3}</span> \
    ldap:<span style="color: #000000; font-weight: bold;">///</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #c20cb9; font-weight: bold;">yes</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>no<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
AUTH_SERVER_LOGIN_AUTH = $<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000; font-weight: bold;">if</span> ldapauth \
    <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #007800;">user</span>=<span style="color: #ff0000;">&quot;uid=<span style="color: #007800;">${quote_ldap_dn:${sg{${lc:$auth1}</span>} <span style="color: #000099; font-weight: bold;">\
</span> 	{<span style="color: #000099; font-weight: bold;">\N</span>^([a-zA-Z0-9_.-]+)@([a-zA-Z0-9_@.-]+)$<span style="color: #000099; font-weight: bold;">\N</span>}{<span style="color: #000099; font-weight: bold;">\$</span>1}}},LDAP_BASE&quot;</span> \
    <span style="color: #007800;">pass</span>=<span style="color: #800000;">${quote:$auth2}</span> \
    ldap:<span style="color: #000000; font-weight: bold;">///</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #c20cb9; font-weight: bold;">yes</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>no<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
AUTH_SERVER_MAIL = <span style="color: #800000;">${sg{${lc:${extract{1}</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>\<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #007800;">$authenticated_id</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>\N^<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>a-zA-Z0-<span style="color: #000000;">9</span>_.-<span style="color: #7a0874; font-weight: bold;">&#93;</span>+<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #000000; font-weight: bold;">@</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>a-zA-Z0-<span style="color: #000000;">9</span>_<span style="color: #000000; font-weight: bold;">@</span>.-<span style="color: #7a0874; font-weight: bold;">&#93;</span>+<span style="color: #7a0874; font-weight: bold;">&#41;</span>$\N<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>\$<span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
AUTH_SERVER_UID = <span style="color: #800000;">${sg{${lc:${extract{1}</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>\<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #007800;">$authenticated_id</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>\N^<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>a-zA-Z0-<span style="color: #000000;">9</span>_.-<span style="color: #7a0874; font-weight: bold;">&#93;</span>+<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #000000; font-weight: bold;">@</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>a-zA-Z0-<span style="color: #000000;">9</span>_<span style="color: #000000; font-weight: bold;">@</span>.-<span style="color: #7a0874; font-weight: bold;">&#93;</span>+<span style="color: #7a0874; font-weight: bold;">&#41;</span>$\N<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>\$<span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
AUTH_SERVER_PASSWORD = <span style="color: #800000;">${extract{2}</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>\<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #007800;">$authenticated_id</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
IS_SENDER_BAD = <span style="color: #800000;">${if match {AUTH_SERVER_MAIL}</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>\N^<span style="color: #7a0874; font-weight: bold;">&#91;</span>a-zA-Z0-<span style="color: #000000;">9</span>_.-<span style="color: #7a0874; font-weight: bold;">&#93;</span>+$\N<span style="color: #7a0874; font-weight: bold;">&#125;</span> \
	<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #800000;">${if match {${lc:AUTH_SERVER_MAIL}</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #800000;">${lc:$sender_address_local_part}</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>no<span style="color: #7a0874; font-weight: bold;">&#125;</span> \
		<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #800000;">${if match {${lc:$sender_address_local_part}</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> \
			<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #800000;">${lc:${tr{GET_ALIAS_FOR_AUTH}</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>,<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>::<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> \
			<span style="color: #7a0874; font-weight: bold;">&#123;</span>no<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #c20cb9; font-weight: bold;">yes</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>\
	<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> \
	<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #800000;">${if match_address {${lc:AUTH_SERVER_MAIL}</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #800000;">${lc:$sender_address}</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>no<span style="color: #7a0874; font-weight: bold;">&#125;</span> \
		<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #800000;">${if match_address {${lc:$sender_address}</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> \
			<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #800000;">${lc:${tr{GET_ALIAS_FOR_AUTH}</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>,<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>::<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> \
			<span style="color: #7a0874; font-weight: bold;">&#123;</span>no<span style="color: #7a0874; font-weight: bold;">&#125;</span>\
			<span style="color: #7a0874; font-weight: bold;">&#123;</span>$<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000; font-weight: bold;">if</span> and<span style="color: #7a0874; font-weight: bold;">&#123;</span> \
					<span style="color: #7a0874; font-weight: bold;">&#123;</span>match_domain<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #007800;">$sender_address_domain</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>+local_domains<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> \
					<span style="color: #7a0874; font-weight: bold;">&#123;</span>match_local_part<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #007800;">$sender_address_local_part</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>SEC_MAIL_USER<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> \
					<span style="color: #7a0874; font-weight: bold;">&#123;</span>match_ip<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #007800;">$sender_host_address</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000; font-weight: bold;">@</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> \
				<span style="color: #7a0874; font-weight: bold;">&#125;</span>\
				<span style="color: #7a0874; font-weight: bold;">&#123;</span>no<span style="color: #7a0874; font-weight: bold;">&#125;</span>\
				<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #c20cb9; font-weight: bold;">yes</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>\
			<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>\
		<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>\
	<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
exim_path = <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>exim4
&nbsp;
.ifndef CONFDIR
CONFDIR = <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>exim4
.endif
&nbsp;
UPEX4CmacrosUPEX4C = <span style="color: #000000;">1</span>
<span style="color: #666666; font-style: italic;">##############################################</span>
<span style="color: #666666; font-style: italic;"># the following macro definitions were created</span>
<span style="color: #666666; font-style: italic;"># dynamically by /usr/sbin/update-exim4.conf</span>
.ifndef MAIN_PACKAGE_VERSION
<span style="color: #007800;">MAIN_PACKAGE_VERSION</span>=<span style="color: #000000;">4.69</span>-5ubuntu2
.endif
.ifndef MAIN_LOCAL_DOMAINS
<span style="color: #007800;">MAIN_LOCAL_DOMAINS</span>=<span style="color: #000000; font-weight: bold;">@</span>:localhost
.endif
.ifndef MAIN_RELAY_TO_DOMAINS
<span style="color: #007800;">MAIN_RELAY_TO_DOMAINS</span>=empty
.endif
.ifndef ETC_MAILNAME
<span style="color: #007800;">ETC_MAILNAME</span>=myserver
.endif
.ifndef LOCAL_DELIVERY
<span style="color: #007800;">LOCAL_DELIVERY</span>=dovecot_delivery
.endif
.ifndef MAIN_RELAY_NETS
<span style="color: #007800;">MAIN_RELAY_NETS</span>=: 127.0.0.1 : ::::<span style="color: #000000;">1</span>
.endif
.ifndef DCreadhost
<span style="color: #007800;">DCreadhost</span>=empty
.endif
.ifndef DCsmarthost
<span style="color: #007800;">DCsmarthost</span>=empty
.endif
.ifndef DC_eximconfig_configtype
<span style="color: #007800;">DC_eximconfig_configtype</span>=<span style="color: #7a0874; font-weight: bold;">local</span>
.endif
.ifndef DCconfig_local
<span style="color: #007800;">DCconfig_local</span>=<span style="color: #000000;">1</span>
.endif
<span style="color: #666666; font-style: italic;">##############################################</span>
&nbsp;
domainlist local_domains = MAIN_LOCAL_DOMAINS
&nbsp;
domainlist relay_to_domains = MAIN_RELAY_TO_DOMAINS
&nbsp;
hostlist relay_from_hosts = MAIN_RELAY_NETS
&nbsp;
.ifndef MAIN_PRIMARY_HOSTNAME_AS_QUALIFY_DOMAIN
.ifndef MAIN_QUALIFY_DOMAIN
qualify_domain = ETC_MAILNAME
.else
qualify_domain = MAIN_QUALIFY_DOMAIN
.endif
.endif
&nbsp;
.ifdef MAIN_LOCAL_INTERFACES
local_interfaces = MAIN_LOCAL_INTERFACES
.endif
&nbsp;
.ifndef LOCAL_DELIVERY
<span style="color: #007800;">LOCAL_DELIVERY</span>=mail_spool
.endif
&nbsp;
gecos_pattern = ^<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>^,:<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
gecos_name = $<span style="color: #000000;">1</span>
&nbsp;
.ifndef CHECK_RCPT_LOCAL_LOCALPARTS
CHECK_RCPT_LOCAL_LOCALPARTS = ^<span style="color: #7a0874; font-weight: bold;">&#91;</span>.<span style="color: #7a0874; font-weight: bold;">&#93;</span> : ^.<span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000; font-weight: bold;">@%!/|`</span><span style="color: #666666; font-style: italic;">#&amp;?]</span>
.endif
&nbsp;
.ifndef CHECK_RCPT_REMOTE_LOCALPARTS
CHECK_RCPT_REMOTE_LOCALPARTS = ^<span style="color: #7a0874; font-weight: bold;">&#91;</span>.<span style="color: #000000; font-weight: bold;">/|</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> : ^.<span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000; font-weight: bold;">@%!`</span><span style="color: #666666; font-style: italic;">#&amp;?] : ^.*/\\.\\./</span>
.endif
&nbsp;
.ifndef MAIN_LOG_SELECTOR
MAIN_LOG_SELECTOR = +tls_peerdn
.endif
&nbsp;
.ifndef MAIN_ACL_CHECK_MAIL
MAIN_ACL_CHECK_MAIL = acl_check_mail
.endif
acl_smtp_mail = MAIN_ACL_CHECK_MAIL
&nbsp;
.ifndef MAIN_ACL_CHECK_RCPT
MAIN_ACL_CHECK_RCPT = acl_check_rcpt
.endif
acl_smtp_rcpt = MAIN_ACL_CHECK_RCPT
&nbsp;
.ifndef MAIN_ACL_CHECK_DATA
MAIN_ACL_CHECK_DATA = acl_check_data
.endif
acl_smtp_data = MAIN_ACL_CHECK_DATA
&nbsp;
.ifdef MESSAGE_SIZE_LIMIT
message_size_limit = MESSAGE_SIZE_LIMIT
.endif
&nbsp;
.ifdef MAIN_ALLOW_DOMAIN_LITERALS
allow_domain_literals
.endif
&nbsp;
.ifndef DC_minimaldns
.ifndef MAIN_HOST_LOOKUP
MAIN_HOST_LOOKUP = <span style="color: #000000; font-weight: bold;">*</span>
.endif
host_lookup = MAIN_HOST_LOOKUP
.endif
&nbsp;
.ifdef MAIN_HARDCODE_PRIMARY_HOSTNAME
primary_hostname = MAIN_HARDCODE_PRIMARY_HOSTNAME
.endif
&nbsp;
.ifdef MAIN_SMTP_ACCEPT_MAX_NOMAIL_HOSTS
smtp_accept_max_nonmail_hosts = MAIN_SMTP_ACCEPT_MAX_NOMAIL_HOSTS
.endif
&nbsp;
.ifndef MAIN_FORCE_SENDER
local_from_check = <span style="color: #c20cb9; font-weight: bold;">false</span>
local_sender_retain = <span style="color: #c20cb9; font-weight: bold;">true</span>
untrusted_set_sender = <span style="color: #000000; font-weight: bold;">*</span>
.endif
&nbsp;
.ifndef MAIN_IGNORE_BOUNCE_ERRORS_AFTER
MAIN_IGNORE_BOUNCE_ERRORS_AFTER = 2d
.endif
ignore_bounce_errors_after = MAIN_IGNORE_BOUNCE_ERRORS_AFTER
&nbsp;
.ifndef MAIN_TIMEOUT_FROZEN_AFTER
MAIN_TIMEOUT_FROZEN_AFTER = 7d
.endif
timeout_frozen_after = MAIN_TIMEOUT_FROZEN_AFTER
&nbsp;
.ifndef MAIN_FREEZE_TELL
MAIN_FREEZE_TELL = postmaster
.endif
freeze_tell = MAIN_FREEZE_TELL
&nbsp;
.ifndef SPOOLDIR
SPOOLDIR = <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>spool<span style="color: #000000; font-weight: bold;">/</span>exim4
.endif
spool_directory = SPOOLDIR
&nbsp;
.ifndef MAIN_TRUSTED_USERS
MAIN_TRUSTED_USERS = uucp
.endif
trusted_users = MAIN_TRUSTED_USERS
.ifdef MAIN_TRUSTED_GROUPS
trusted_groups = MAIN_TRUSTED_GROUPS
.endif
&nbsp;
.ifdef MAIN_TLS_ENABLE
.ifndef MAIN_TLS_ADVERTISE_HOSTS
MAIN_TLS_ADVERTISE_HOSTS = <span style="color: #000000; font-weight: bold;">*</span>
.endif
tls_advertise_hosts = MAIN_TLS_ADVERTISE_HOSTS
&nbsp;
.ifdef MAIN_TLS_CERTKEY
tls_certificate = MAIN_TLS_CERTKEY
.else
.ifndef MAIN_TLS_CERTIFICATE
MAIN_TLS_CERTIFICATE = CONFDIR<span style="color: #000000; font-weight: bold;">/</span>exim.crt
.endif
tls_certificate = MAIN_TLS_CERTIFICATE
&nbsp;
.ifndef MAIN_TLS_PRIVATEKEY
MAIN_TLS_PRIVATEKEY = CONFDIR<span style="color: #000000; font-weight: bold;">/</span>exim.key
.endif
tls_privatekey = MAIN_TLS_PRIVATEKEY
.endif
&nbsp;
.ifndef MAIN_TLS_VERIFY_CERTIFICATES
MAIN_TLS_VERIFY_CERTIFICATES = <span style="color: #800000;">${if exists{/etc/ssl/certs/ca-certificates.crt}</span>\
                                    <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>ssl<span style="color: #000000; font-weight: bold;">/</span>certs<span style="color: #000000; font-weight: bold;">/</span>ca-certificates.crt<span style="color: #7a0874; font-weight: bold;">&#125;</span>\
				    <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
.endif
tls_verify_certificates = MAIN_TLS_VERIFY_CERTIFICATES
&nbsp;
.ifdef MAIN_TLS_VERIFY_HOSTS
tls_verify_hosts = MAIN_TLS_VERIFY_HOSTS
.endif
&nbsp;
.ifndef MAIN_TLS_TRY_VERIFY_HOSTS
MAIN_TLS_TRY_VERIFY_HOSTS = <span style="color: #000000; font-weight: bold;">*</span>
.endif
tls_try_verify_hosts = MAIN_TLS_TRY_VERIFY_HOSTS
&nbsp;
.endif
&nbsp;
.ifdef MAIN_LOG_SELECTOR
log_selector = MAIN_LOG_SELECTOR
.endif
&nbsp;
begin acl
&nbsp;
acl_check_not_smtp:
  accept
	<span style="color: #007800;">condition</span>=<span style="color: #800000;">${if IS_SENDER_SECMAIL {yes}</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>no<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
	<span style="color: #007800;">control</span>=suppress_local_fixups
&nbsp;
  accept
&nbsp;
acl_local_deny_exceptions:
  accept
    hosts = <span style="color: #800000;">${if exists{CONFDIR/host_local_deny_exceptions}</span>\
                 <span style="color: #7a0874; font-weight: bold;">&#123;</span>CONFDIR<span style="color: #000000; font-weight: bold;">/</span>host_local_deny_exceptions<span style="color: #7a0874; font-weight: bold;">&#125;</span>\
                 <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
  accept
    senders = <span style="color: #800000;">${if exists{CONFDIR/sender_local_deny_exceptions}</span>\
                   <span style="color: #7a0874; font-weight: bold;">&#123;</span>CONFDIR<span style="color: #000000; font-weight: bold;">/</span>sender_local_deny_exceptions<span style="color: #7a0874; font-weight: bold;">&#125;</span>\
                   <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
  accept
    hosts = <span style="color: #800000;">${if exists{CONFDIR/local_host_whitelist}</span>\
                 <span style="color: #7a0874; font-weight: bold;">&#123;</span>CONFDIR<span style="color: #000000; font-weight: bold;">/</span>local_host_whitelist<span style="color: #7a0874; font-weight: bold;">&#125;</span>\
                 <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
  accept
    senders = <span style="color: #800000;">${if exists{CONFDIR/local_sender_whitelist}</span>\
                   <span style="color: #7a0874; font-weight: bold;">&#123;</span>CONFDIR<span style="color: #000000; font-weight: bold;">/</span>local_sender_whitelist<span style="color: #7a0874; font-weight: bold;">&#125;</span>\
                   <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
  .ifdef LOCAL_DENY_EXCEPTIONS_LOCAL_ACL_FILE
  .include LOCAL_DENY_EXCEPTIONS_LOCAL_ACL_FILE
  .endif
&nbsp;
  .ifdef WHITELIST_LOCAL_DENY_LOCAL_ACL_FILE
  .include WHITELIST_LOCAL_DENY_LOCAL_ACL_FILE
  .endif
&nbsp;
acl_check_mail:
  .ifdef CHECK_MAIL_HELO_ISSUED
  deny
    message = no HELO given before MAIL <span style="color: #7a0874; font-weight: bold;">command</span>
    condition = <span style="color: #800000;">${if def:sender_helo_name {no}</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #c20cb9; font-weight: bold;">yes</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
  .endif
&nbsp;
  deny
    message = bad sender
    log_message = bad sender <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">auth_id</span>=AUTH_SERVER_MAIL mismatches <span style="color: #007800;">sender</span>=<span style="color: #007800;">$sender_address</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
    condition = IS_SENDER_BAD
  accept
&nbsp;
acl_check_rcpt:
&nbsp;
  .ifdef CHECK_RCPT_LOCAL_LOCALPARTS
  deny
    domains = +local_domains
    local_parts = CHECK_RCPT_LOCAL_LOCALPARTS
    message = restricted characters <span style="color: #000000; font-weight: bold;">in</span> address
  .endif
&nbsp;
  .ifdef CHECK_RCPT_REMOTE_LOCALPARTS
  deny
    domains = <span style="color: #000000; font-weight: bold;">!</span>+local_domains
    local_parts = CHECK_RCPT_REMOTE_LOCALPARTS
    message = restricted characters <span style="color: #000000; font-weight: bold;">in</span> address
  .endif
&nbsp;
  accept
    .ifndef CHECK_RCPT_POSTMASTER
    local_parts = postmaster
    .else
    local_parts = CHECK_RCPT_POSTMASTER
    .endif
    domains = +local_domains : +relay_to_domains
&nbsp;
  .ifdef CHECK_RCPT_VERIFY_SENDER
  deny
    message = Sender verification failed
    <span style="color: #000000; font-weight: bold;">!</span>acl = acl_local_deny_exceptions
    <span style="color: #000000; font-weight: bold;">!</span>verify = sender
  .endif
&nbsp;
  deny
    <span style="color: #000000; font-weight: bold;">!</span>acl = acl_local_deny_exceptions
    senders = <span style="color: #800000;">${if exists{CONFDIR/local_sender_callout}</span>\
                         <span style="color: #7a0874; font-weight: bold;">&#123;</span>CONFDIR<span style="color: #000000; font-weight: bold;">/</span>local_sender_callout<span style="color: #7a0874; font-weight: bold;">&#125;</span>\
                   <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">!</span>verify = sender<span style="color: #000000; font-weight: bold;">/</span>callout
&nbsp;
  require
    verify = recipient
&nbsp;
  accept
    authenticated = <span style="color: #000000; font-weight: bold;">*</span>
    condition = IS_SENDER_REMOTE
&nbsp;
  require
    message = relay not permitted
    domains = +local_domains : +relay_to_domains
&nbsp;
  deny
    <span style="color: #000000; font-weight: bold;">!</span>acl = acl_local_deny_exceptions
    recipients = <span style="color: #800000;">${if exists{CONFDIR/local_rcpt_callout}</span>\
                            <span style="color: #7a0874; font-weight: bold;">&#123;</span>CONFDIR<span style="color: #000000; font-weight: bold;">/</span>local_rcpt_callout<span style="color: #7a0874; font-weight: bold;">&#125;</span>\
                      <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">!</span>verify = recipient<span style="color: #000000; font-weight: bold;">/</span>callout
&nbsp;
  deny
    message = sender envelope address <span style="color: #007800;">$sender_address</span> is locally blacklisted here. If you think this is wrong, get <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #c20cb9; font-weight: bold;">touch</span> with postmaster
    <span style="color: #000000; font-weight: bold;">!</span>acl = acl_local_deny_exceptions
    senders = <span style="color: #800000;">${if exists{CONFDIR/local_sender_blacklist}</span>\
                   <span style="color: #7a0874; font-weight: bold;">&#123;</span>CONFDIR<span style="color: #000000; font-weight: bold;">/</span>local_sender_blacklist<span style="color: #7a0874; font-weight: bold;">&#125;</span>\
                   <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
  deny
    message = sender IP address <span style="color: #007800;">$sender_host_address</span> is locally blacklisted here. If you think this is wrong, get <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #c20cb9; font-weight: bold;">touch</span> with postmaster
    <span style="color: #000000; font-weight: bold;">!</span>acl = acl_local_deny_exceptions
    hosts = <span style="color: #800000;">${if exists{CONFDIR/local_host_blacklist}</span>\
                 <span style="color: #7a0874; font-weight: bold;">&#123;</span>CONFDIR<span style="color: #000000; font-weight: bold;">/</span>local_host_blacklist<span style="color: #7a0874; font-weight: bold;">&#125;</span>\
                 <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
  .ifdef CHECK_RCPT_REVERSE_DNS
  warn
    message = X-Host-Lookup-Failed: Reverse DNS lookup failed <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #007800;">$sender_host_address</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #800000;">${if eq{$host_lookup_failed}</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>failed<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>deferred<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
     condition = <span style="color: #800000;">${if and{{def:sender_host_address}</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000; font-weight: bold;">!</span>def:sender_host_name<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>\
                      <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #c20cb9; font-weight: bold;">yes</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>no<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
  .endif
&nbsp;
  .ifdef CHECK_RCPT_SPF
  deny
    message = <span style="color: #7a0874; font-weight: bold;">&#91;</span>SPF<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #007800;">$sender_host_address</span> is not allowed to send mail from <span style="color: #800000;">${if def:sender_address_domain {$sender_address_domain}</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #007800;">$sender_helo_name</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>.  \
              Please see http:<span style="color: #000000; font-weight: bold;">//</span>www.openspf.org<span style="color: #000000; font-weight: bold;">/</span>Why?<span style="color: #007800;">scope</span>=<span style="color: #800000;">${if def:sender_address_domain {mfrom}</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>helo<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>;<span style="color: #007800;">identity</span>=<span style="color: #800000;">${if def:sender_address_domain {$sender_address}</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #007800;">$sender_helo_name</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>;<span style="color: #007800;">ip</span>=<span style="color: #007800;">$sender_host_address</span>
    log_message = SPF check failed.
    <span style="color: #000000; font-weight: bold;">!</span>acl = acl_local_deny_exceptions
    condition = <span style="color: #800000;">${run{/usr/bin/spfquery --ip \&quot;$sender_host_address\&quot; --mail-from \&quot;$sender_address\&quot; --helo \&quot;$sender_helo_name\&quot;}</span>\
                     <span style="color: #7a0874; font-weight: bold;">&#123;</span>no<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #800000;">${if eq {$runrc}</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #c20cb9; font-weight: bold;">yes</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>no<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
  defer
    message = Temporary DNS error <span style="color: #000000; font-weight: bold;">while</span> checking SPF record.  Try again later.
    condition = <span style="color: #800000;">${if eq {$runrc}</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">5</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #c20cb9; font-weight: bold;">yes</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>no<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
  warn
    message = Received-SPF: <span style="color: #800000;">${if eq {$runrc}</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>pass<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #800000;">${if eq {$runrc}</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>softfail<span style="color: #7a0874; font-weight: bold;">&#125;</span>\
                                 <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #800000;">${if eq {$runrc}</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">3</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>neutral<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #800000;">${if eq {$runrc}</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">4</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>unknown<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #800000;">${if eq {$runrc}</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">6</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>none<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>error<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
    condition = <span style="color: #800000;">${if &lt;={$runrc}</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">6</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #c20cb9; font-weight: bold;">yes</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>no<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
  warn
    log_message = Unexpected error <span style="color: #000000; font-weight: bold;">in</span> SPF check.
    condition = <span style="color: #800000;">${if &gt;{$runrc}</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">6</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #c20cb9; font-weight: bold;">yes</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>no<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
  warn
    message = X-SPF-Guess: <span style="color: #800000;">${run{/usr/bin/spfquery --ip \&quot;$sender_host_address\&quot; --mail-from \&quot;$sender_address\&quot; \ --helo \&quot;$sender_helo_name\&quot; --guess true}</span>\
                                <span style="color: #7a0874; font-weight: bold;">&#123;</span>pass<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #800000;">${if eq {$runrc}</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>softfail<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #800000;">${if eq {$runrc}</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">3</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>neutral<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #800000;">${if eq {$runrc}</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">4</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>unknown<span style="color: #7a0874; font-weight: bold;">&#125;</span>\
                                <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #800000;">${if eq {$runrc}</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">6</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>none<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>error<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
    condition = <span style="color: #800000;">${if &lt;={$runrc}</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">6</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #c20cb9; font-weight: bold;">yes</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>no<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
  defer
    message = Temporary DNS error <span style="color: #000000; font-weight: bold;">while</span> checking SPF record.  Try again later.
    condition = <span style="color: #800000;">${if eq {$runrc}</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">5</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #c20cb9; font-weight: bold;">yes</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>no<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
  .endif
&nbsp;
  .ifdef CHECK_RCPT_IP_DNSBLS
  warn
    message = X-Warning: <span style="color: #007800;">$sender_host_address</span> is listed at <span style="color: #007800;">$dnslist_domain</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">$dnslist_value</span>: <span style="color: #007800;">$dnslist_text</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
    log_message = <span style="color: #007800;">$sender_host_address</span> is listed at <span style="color: #007800;">$dnslist_domain</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">$dnslist_value</span>: <span style="color: #007800;">$dnslist_text</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
    dnslists = CHECK_RCPT_IP_DNSBLS
  .endif
&nbsp;
  .ifdef CHECK_RCPT_DOMAIN_DNSBLS
  warn
    message = X-Warning: <span style="color: #007800;">$sender_address_domain</span> is listed at <span style="color: #007800;">$dnslist_domain</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">$dnslist_value</span>: <span style="color: #007800;">$dnslist_text</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
    log_message = <span style="color: #007800;">$sender_address_domain</span> is listed at <span style="color: #007800;">$dnslist_domain</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">$dnslist_value</span>: <span style="color: #007800;">$dnslist_text</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
    <span style="color: #000000; font-weight: bold;">!</span>senders = <span style="color: #800000;">${if exists{CONFDIR/local_domain_dnsbl_whitelist}</span>\
                    <span style="color: #7a0874; font-weight: bold;">&#123;</span>CONFDIR<span style="color: #000000; font-weight: bold;">/</span>local_domain_dnsbl_whitelist<span style="color: #7a0874; font-weight: bold;">&#125;</span>\
                    <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
    dnslists = CHECK_RCPT_DOMAIN_DNSBLS
  .endif
&nbsp;
  .ifdef CHECK_RCPT_LOCAL_ACL_FILE
  .include CHECK_RCPT_LOCAL_ACL_FILE
  .endif
&nbsp;
  accept
    domains = +relay_to_domains
    endpass
    verify = recipient
&nbsp;
  accept
&nbsp;
acl_check_data:
&nbsp;
  .ifdef CHECK_DATA_VERIFY_HEADER_SYNTAX
  deny
    message = Message headers fail syntax check
    <span style="color: #000000; font-weight: bold;">!</span>acl = acl_local_deny_exceptions
    <span style="color: #000000; font-weight: bold;">!</span>verify = header_syntax
  .endif
&nbsp;
  .ifdef CHECK_DATA_VERIFY_HEADER_SENDER
  deny
    message = No verifiable sender address <span style="color: #000000; font-weight: bold;">in</span> message headers
    <span style="color: #000000; font-weight: bold;">!</span>acl = acl_local_deny_exceptions
    <span style="color: #000000; font-weight: bold;">!</span>verify = header_sender
  .endif
&nbsp;
  .ifdef CHECK_DATA_LOCAL_ACL_FILE
  .include CHECK_DATA_LOCAL_ACL_FILE
  .endif
&nbsp;
  accept
&nbsp;
begin routers
&nbsp;
.ifdef MAIN_ALLOW_DOMAIN_LITERALS
domain_literal:
  debug_print = <span style="color: #ff0000;">&quot;R: domain_literal for <span style="color: #007800;">$local_part</span>@<span style="color: #007800;">$domain</span>&quot;</span>
  driver = ipliteral
  domains = <span style="color: #000000; font-weight: bold;">!</span> +local_domains
  transport = remote_smtp
.endif
&nbsp;
hubbed_hosts:
  debug_print = <span style="color: #ff0000;">&quot;R: hubbed_hosts for <span style="color: #007800;">$domain</span>&quot;</span>
  driver = manualroute
  domains = <span style="color: #ff0000;">&quot;<span style="color: #007800;">${if exists{CONFDIR/hubbed_hosts}</span><span style="color: #000099; font-weight: bold;">\
</span>                   {partial-lsearch;CONFDIR/hubbed_hosts}<span style="color: #000099; font-weight: bold;">\
</span>              fail}&quot;</span>
  same_domain_copy_routing = <span style="color: #c20cb9; font-weight: bold;">yes</span>
  route_data = <span style="color: #800000;">${lookup{$domain}</span>partial-lsearch<span style="color: #7a0874; font-weight: bold;">&#123;</span>CONFDIR<span style="color: #000000; font-weight: bold;">/</span>hubbed_hosts<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
  transport = remote_smtp
&nbsp;
system_aliases:
  debug_print = <span style="color: #ff0000;">&quot;R: system_aliases for <span style="color: #007800;">$local_part</span>@<span style="color: #007800;">$domain</span>&quot;</span>
  driver = redirect
  domains = +local_domains
  allow_fail
  allow_defer
  data = <span style="color: #800000;">${lookup{$local_part}</span>lsearch<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>aliases<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
  .ifdef SYSTEM_ALIASES_USER
  user = SYSTEM_ALIASES_USER
  .endif
  .ifdef SYSTEM_ALIASES_GROUP
  group = SYSTEM_ALIASES_GROUP
  .endif
  .ifdef SYSTEM_ALIASES_FILE_TRANSPORT
  file_transport = SYSTEM_ALIASES_FILE_TRANSPORT
  .endif
  .ifdef SYSTEM_ALIASES_PIPE_TRANSPORT
  pipe_transport = SYSTEM_ALIASES_PIPE_TRANSPORT
  .endif
  .ifdef SYSTEM_ALIASES_DIRECTORY_TRANSPORT
  directory_transport = SYSTEM_ALIASES_DIRECTORY_TRANSPORT
  .endif
&nbsp;
.ifndef FIRST_USER_ACCOUNT_UID
FIRST_USER_ACCOUNT_UID = <span style="color: #000000;">0</span>
.endif
&nbsp;
.ifndef DEFAULT_SYSTEM_ACCOUNT_ALIAS
DEFAULT_SYSTEM_ACCOUNT_ALIAS = :fail: no mail to system accounts
.endif
&nbsp;
COND_SYSTEM_USER_AND_REMOTE_SUBMITTER = <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\
</span>               <span style="color: #007800;">${if and{{! match_ip{$sender_host_address}</span>{:@[]}}<span style="color: #000099; font-weight: bold;">\
</span>                        {&lt;{<span style="color: #007800;">$local_user_uid</span>}{FIRST_USER_ACCOUNT_UID}}}<span style="color: #000099; font-weight: bold;">\
</span>                    {1}{0}<span style="color: #000099; font-weight: bold;">\
</span>		}&quot;</span>
&nbsp;
lowuid_aliases:
  debug_print = <span style="color: #ff0000;">&quot;R: lowuid_aliases for <span style="color: #007800;">$local_part</span>@<span style="color: #007800;">$domain</span> (UID <span style="color: #007800;">$local_user_uid</span>)&quot;</span>
  check_local_user
  driver = redirect
  allow_fail
  domains = +local_domains
  condition = COND_SYSTEM_USER_AND_REMOTE_SUBMITTER
  data = <span style="color: #800000;">${if exists{/etc/exim4/lowuid-aliases}</span>\
              <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #800000;">${lookup{$local_part}</span>lsearch<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>exim4<span style="color: #000000; font-weight: bold;">/</span>lowuid-aliases<span style="color: #7a0874; font-weight: bold;">&#125;</span>\
              <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #007800;">$value</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>DEFAULT_SYSTEM_ACCOUNT_ALIAS<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>DEFAULT_SYSTEM_ACCOUNT_ALIAS<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
local_user_secmail:
  debug_print = <span style="color: #ff0000;">&quot;R: local_user_secmail for <span style="color: #007800;">$local_part</span>@<span style="color: #007800;">$domain</span>&quot;</span>
  driver = accept
  domains = +local_domains
  local_parts = <span style="color: #000000; font-weight: bold;">!</span> root
  condition = <span style="color: #800000;">${if IS_SENDER_SECMAIL {IS_LOCAL_PART_VALID}</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>no<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
  transport = LOCAL_DELIVERY_SECMAIL
&nbsp;
local_user:
  debug_print = <span style="color: #ff0000;">&quot;R: local_user for <span style="color: #007800;">$local_part</span>@<span style="color: #007800;">$domain</span>&quot;</span>
  driver = accept
  domains = +local_domains
  local_parts = <span style="color: #000000; font-weight: bold;">!</span> root
  condition = IS_LOCAL_PART_VALID
  transport = LOCAL_DELIVERY
  cannot_route_message = Unknown user
&nbsp;
ldap_uid_aliases:
  debug_print = <span style="color: #ff0000;">&quot;R: ldap_uid_alias for <span style="color: #007800;">$local_part</span>@<span style="color: #007800;">$domain</span>&quot;</span>
  driver = redirect
  data = GET_UID_FOR_RCPT
  check_ancestor
&nbsp;
ldap_aliases:
  debug_print = <span style="color: #ff0000;">&quot;R: ldap_alias for <span style="color: #007800;">$local_part</span>@<span style="color: #007800;">$domain</span>&quot;</span>
  driver = redirect
  data = GET_ALIAS_FOR_RCPT
  check_ancestor
&nbsp;
.ifdef DCconfig_satellite
hub_user:
  debug_print = <span style="color: #ff0000;">&quot;R: hub_user for <span style="color: #007800;">$local_part</span>@<span style="color: #007800;">$domain</span>&quot;</span>
  driver = redirect
  domains = +local_domains
  data = <span style="color: #800000;">${local_part}</span><span style="color: #000000; font-weight: bold;">@</span>DCreadhost
  check_local_user
&nbsp;
hub_user_smarthost:
  debug_print = <span style="color: #ff0000;">&quot;R: hub_user_smarthost for <span style="color: #007800;">$local_part</span>@<span style="color: #007800;">$domain</span>&quot;</span>
  driver = manualroute
  domains = DCreadhost
  transport = remote_smtp_smarthost
  route_list = <span style="color: #000000; font-weight: bold;">*</span> DCsmarthost byname
  host_find_failed = defer
  same_domain_copy_routing = <span style="color: #c20cb9; font-weight: bold;">yes</span>
  check_local_user
.endif
&nbsp;
smarthost_auto:
   condition = IS_AUTH_REMOTE
   driver = manualroute
   domains = <span style="color: #000000; font-weight: bold;">!</span> +local_domains
   route_data = AUTH_REMOTE_SERVER
   transport = remote_smtp_smarthost_auto
&nbsp;
mail4root:
  debug_print = <span style="color: #ff0000;">&quot;R: mail4root for <span style="color: #007800;">$local_part</span>@<span style="color: #007800;">$domain</span>&quot;</span>
  driver = redirect
  domains = +local_domains
  data = <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>mail<span style="color: #000000; font-weight: bold;">/</span>mail
  file_transport = address_file
  local_parts = root
  user = mail
  group = mail
&nbsp;
begin transports
&nbsp;
.ifdef HIDE_MAILNAME
<span style="color: #007800;">REMOTE_SMTP_HEADERS_REWRITE</span>=<span style="color: #000000; font-weight: bold;">*@</span>+local_domains $<span style="color: #000000;">1</span><span style="color: #000000; font-weight: bold;">@</span>DCreadhost frs : <span style="color: #000000; font-weight: bold;">*@</span>ETC_MAILNAME $<span style="color: #000000;">1</span><span style="color: #000000; font-weight: bold;">@</span>DCreadhost frs
<span style="color: #007800;">REMOTE_SMTP_RETURN_PATH</span>=<span style="color: #800000;">${if match_domain{$sender_address_domain}</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>+local_domains<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #800000;">${sender_address_local_part}</span><span style="color: #000000; font-weight: bold;">@</span>DCreadhost<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #800000;">${if match_domain{$sender_address_domain}</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>ETC_MAILNAME<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #800000;">${sender_address_local_part}</span><span style="color: #000000; font-weight: bold;">@</span>DCreadhost<span style="color: #7a0874; font-weight: bold;">&#125;</span>fail<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
.endif
&nbsp;
.ifdef REMOTE_SMTP_HELO_FROM_DNS
<span style="color: #007800;">REMOTE_SMTP_HELO_DATA</span>=<span style="color: #800000;">${lookup dnsdb {ptr=$sending_ip_address}</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #007800;">$value</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #007800;">$primary_hostname</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
.endif
&nbsp;
address_file:
  debug_print = <span style="color: #ff0000;">&quot;T: address_file for <span style="color: #007800;">$local_part</span>@<span style="color: #007800;">$domain</span>&quot;</span>
  driver = appendfile
  delivery_date_add
  envelope_to_add
  return_path_add
&nbsp;
address_pipe:
  debug_print = <span style="color: #ff0000;">&quot;T: address_pipe for <span style="color: #007800;">$local_part</span>@<span style="color: #007800;">$domain</span>&quot;</span>
  driver = pipe
  return_fail_output
&nbsp;
address_reply:
  debug_print = <span style="color: #ff0000;">&quot;T: autoreply for <span style="color: #007800;">$local_part</span>@<span style="color: #007800;">$domain</span>&quot;</span>
  driver = autoreply
&nbsp;
dovecot_delivery:
  debug_print = <span style="color: #ff0000;">&quot;T: dovecot_delivery_pipe for <span style="color: #007800;">$local_part</span>@<span style="color: #007800;">$domain</span> translates to GET_LOCAL_MAIL&quot;</span>
  driver = pipe
  <span style="color: #7a0874; font-weight: bold;">command</span> = <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>dovecot<span style="color: #000000; font-weight: bold;">/</span>deliver <span style="color: #660033;">-d</span> <span style="color: #ff0000;">&quot;GET_LOCAL_MAIL&quot;</span>
  message_prefix =
  message_suffix =
  delivery_date_add
  envelope_to_add
  return_path_add
  log_output
  user = secmail
  group = secmail
&nbsp;
dovecot_delivery_secmail:
  debug_print = <span style="color: #ff0000;">&quot;T: dovecot_delivery_pipe_secmail for <span style="color: #007800;">$local_part</span>@<span style="color: #007800;">$domain</span> translates to GET_LOCAL_MAIL&quot;</span>
  driver = pipe
  <span style="color: #7a0874; font-weight: bold;">command</span> = <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>dovecot<span style="color: #000000; font-weight: bold;">/</span>deliver <span style="color: #660033;">-d</span> <span style="color: #ff0000;">&quot;GET_LOCAL_MAIL&quot;</span>
  message_prefix =
  message_suffix =
  delivery_date_add = <span style="color: #c20cb9; font-weight: bold;">false</span>
  envelope_to_add = <span style="color: #c20cb9; font-weight: bold;">false</span>
  return_path_add = <span style="color: #c20cb9; font-weight: bold;">false</span>
  log_output
  user = secmail
  group = secmail
&nbsp;
mail_spool:
  debug_print = <span style="color: #ff0000;">&quot;T: appendfile for <span style="color: #007800;">$local_part</span>@<span style="color: #007800;">$domain</span>&quot;</span>
  driver = appendfile
  <span style="color: #c20cb9; font-weight: bold;">file</span> = <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>mail<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$local_part</span>
  delivery_date_add
  envelope_to_add
  return_path_add
  group = mail
  mode = 0660
  mode_fail_narrower = <span style="color: #c20cb9; font-weight: bold;">false</span>
&nbsp;
maildir_home:
  debug_print = <span style="color: #ff0000;">&quot;T: maildir_home for <span style="color: #007800;">$local_part</span>@<span style="color: #007800;">$domain</span>&quot;</span>
  driver = appendfile
  .ifdef MAILDIR_HOME_MAILDIR_LOCATION
  directory = MAILDIR_HOME_MAILDIR_LOCATION
  .else
  directory = <span style="color: #007800;">$home</span><span style="color: #000000; font-weight: bold;">/</span>Maildir
  .endif
  .ifdef MAILDIR_HOME_CREATE_DIRECTORY
  create_directory
  .endif
  .ifdef MAILDIR_HOME_CREATE_FILE
  create_file = MAILDIR_HOME_CREATE_FILE
  .endif
  delivery_date_add
  envelope_to_add
  return_path_add
  maildir_format
  .ifdef MAILDIR_HOME_DIRECTORY_MODE
  directory_mode = MAILDIR_HOME_DIRECTORY_MODE
  .else
  directory_mode = 0700
  .endif
  .ifdef MAILDIR_HOME_MODE
  mode = MAILDIR_HOME_MODE
  .else
  mode = 0600
  .endif
  mode_fail_narrower = <span style="color: #c20cb9; font-weight: bold;">false</span>
&nbsp;
maildrop_pipe:
  debug_print = <span style="color: #ff0000;">&quot;T: maildrop_pipe for <span style="color: #007800;">$local_part</span>@<span style="color: #007800;">$domain</span>&quot;</span>
  driver = pipe
  path = <span style="color: #ff0000;">&quot;/bin:/usr/bin:/usr/local/bin&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">command</span> = <span style="color: #ff0000;">&quot;/usr/bin/maildrop&quot;</span>
  return_path_add
  delivery_date_add
  envelope_to_add
&nbsp;
procmail_pipe:
  debug_print = <span style="color: #ff0000;">&quot;T: procmail_pipe for <span style="color: #007800;">$local_part</span>@<span style="color: #007800;">$domain</span>&quot;</span>
  driver = pipe
  path = <span style="color: #ff0000;">&quot;/bin:/usr/bin:/usr/local/bin&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">command</span> = <span style="color: #ff0000;">&quot;/usr/bin/procmail&quot;</span>
  return_path_add
  delivery_date_add
  envelope_to_add
&nbsp;
remote_smtp:
  debug_print = <span style="color: #ff0000;">&quot;T: remote_smtp for <span style="color: #007800;">$local_part</span>@<span style="color: #007800;">$domain</span>&quot;</span>
  driver = smtp
.ifdef REMOTE_SMTP_HOSTS_AVOID_TLS
  hosts_avoid_tls = REMOTE_SMTP_HOSTS_AVOID_TLS
.endif
.ifdef REMOTE_SMTP_HEADERS_REWRITE
  headers_rewrite = REMOTE_SMTP_HEADERS_REWRITE
.endif
.ifdef REMOTE_SMTP_RETURN_PATH
  return_path = REMOTE_SMTP_RETURN_PATH
.endif
.ifdef REMOTE_SMTP_HELO_FROM_DNS
  <span style="color: #007800;">helo_data</span>=REMOTE_SMTP_HELO_DATA
.endif
&nbsp;
remote_smtp_smarthost:
  debug_print = <span style="color: #ff0000;">&quot;T: remote_smtp_smarthost for <span style="color: #007800;">$local_part</span>@<span style="color: #007800;">$domain</span>&quot;</span>
  driver = smtp
  hosts_try_auth = <span style="color: #000000; font-weight: bold;">&lt;</span>; <span style="color: #800000;">${if exists{CONFDIR/passwd.client}</span> \
        <span style="color: #7a0874; font-weight: bold;">&#123;</span>\
        <span style="color: #800000;">${lookup{$host}</span>nwildlsearch<span style="color: #7a0874; font-weight: bold;">&#123;</span>CONFDIR<span style="color: #000000; font-weight: bold;">/</span>passwd.client<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #007800;">$host_address</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>\
        <span style="color: #7a0874; font-weight: bold;">&#125;</span>\
        <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> \
      <span style="color: #7a0874; font-weight: bold;">&#125;</span>
.ifdef REMOTE_SMTP_SMARTHOST_HOSTS_AVOID_TLS
  hosts_avoid_tls = REMOTE_SMTP_SMARTHOST_HOSTS_AVOID_TLS
.endif
.ifdef REMOTE_SMTP_HEADERS_REWRITE
  headers_rewrite = REMOTE_SMTP_HEADERS_REWRITE
.endif
.ifdef REMOTE_SMTP_RETURN_PATH
  return_path = REMOTE_SMTP_RETURN_PATH
.endif
.ifdef REMOTE_SMTP_HELO_FROM_DNS
  <span style="color: #007800;">helo_data</span>=REMOTE_SMTP_HELO_DATA
.endif
&nbsp;
remote_smtp_smarthost_auto:
  debug_print = <span style="color: #ff0000;">&quot;T: remote_smtp_smarthost_auto for <span style="color: #007800;">$local_part</span>@<span style="color: #007800;">$domain</span> from user AUTH_SERVER_MAIL&quot;</span>
  driver = smtp
  hosts_require_auth = AUTH_REMOTE_SERVER
&nbsp;
address_directory:
  debug_print = <span style="color: #ff0000;">&quot;T: address_directory for <span style="color: #007800;">$local_part</span>@<span style="color: #007800;">$domain</span>&quot;</span>
  driver = appendfile
  delivery_date_add
  envelope_to_add
  return_path_add
  check_string = <span style="color: #ff0000;">&quot;&quot;</span>
  escape_string = <span style="color: #ff0000;">&quot;&quot;</span>
  maildir_format
&nbsp;
begin retry
&nbsp;
<span style="color: #000000; font-weight: bold;">*</span>                      <span style="color: #000000; font-weight: bold;">*</span>           F,2h,15m; G,16h,1h,<span style="color: #000000;">1.5</span>; F,4d,6h
&nbsp;
begin rewrite
&nbsp;
.ifndef NO_EAA_REWRITE_REWRITE
<span style="color: #000000; font-weight: bold;">*@</span>+local_domains <span style="color: #ff0000;">&quot;<span style="color: #007800;">${lookup{${local_part}</span>}lsearch{/etc/email-addresses}<span style="color: #000099; font-weight: bold;">\
</span>                   {<span style="color: #007800;">$value</span>}fail}&quot;</span> Ffrs
<span style="color: #000000; font-weight: bold;">*@</span>ETC_MAILNAME <span style="color: #ff0000;">&quot;<span style="color: #007800;">${lookup{${local_part}</span>}lsearch{/etc/email-addresses}<span style="color: #000099; font-weight: bold;">\
</span>                   {<span style="color: #007800;">$value</span>}fail}&quot;</span> Ffrs
.endif
&nbsp;
begin authenticators
&nbsp;
plain_ldapauth_server:
  driver = plaintext
  public_name = PLAIN
  .ifndef AUTH_SERVER_ALLOW_NOTLS_PASSWORDS
    server_advertise_condition = <span style="color: #800000;">${if eq{$tls_cipher}</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
  .endif
  server_condition = AUTH_SERVER_PLAIN_AUTH
  server_set_id = <span style="color: #007800;">$auth2</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$auth3</span>
  server_prompts = :
&nbsp;
login_ldapauth_server:
  driver = plaintext
  public_name = LOGIN
  server_prompts = Username:: : Password::
  .ifndef AUTH_SERVER_ALLOW_NOTLS_PASSWORDS
    server_advertise_condition = <span style="color: #800000;">${if eq{$tls_cipher}</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
  .endif
  server_condition = AUTH_SERVER_LOGIN_AUTH
  server_set_id = <span style="color: #007800;">$auth1</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$auth2</span>
&nbsp;
cram_md5_client:
     driver = cram_md5
     public_name = CRAM-MD5
     client_name = AUTH_REMOTE_LOGIN
     client_secret = AUTH_REMOTE_PASSWORD
&nbsp;
plain_client:
      driver = plaintext
      public_name = PLAIN
      client_send = <span style="color: #000000; font-weight: bold;">&lt;|</span>^AUTH_REMOTE_LOGIN^AUTH_REMOTE_PASSWORD
&nbsp;
login_client:
      driver = plaintext
      public_name = LOGIN
      client_send = <span style="color: #000000; font-weight: bold;">&lt;|</span> <span style="color: #000000; font-weight: bold;">|</span> AUTH_REMOTE_LOGIN <span style="color: #000000; font-weight: bold;">|</span> AUTH_REMOTE_PASSWORD</pre></div></div>

<p>Die Konfigurationsdatei ist auf den ersten Blick sehr umfangreich, allerdings gibt es eine <a href="http://www.exim.org/exim-html-current/doc/html/spec_html/">exzellente Dokumentation von Exim</a>. Dort sind insbesondere die Abschnitte zu <a href="http://www.exim.org/exim-html-current/doc/html/spec_html/ch09.html">Lookups</a> (wegen LDAP) und <a href="http://www.exim.org/exim-html-current/doc/html/spec_html/ch11.html">String Expansions</a> interessant. Allgemeine <a href="http://koivi.com/exim4-config/">Konfigurationshinweise für Exim unter Debian/Ubuntu</a> hat Justin Koivisto zusammengestellt. Den <a href="http://www.wogri.at/Exim.248.0.html?&amp;L=1">Beitrag von Wolfgang Hennerbichler zur Einrichtung der TLS-Verschlüsselung der SMTP-Verbindung</a> zusammen mit der <a href="http://pkg-exim4.alioth.debian.org/README/README.Debian.html#TLS">Dokumentation von exim4-config zu diesem Thema</a> empfand ich ebenfalls hilfreich wie auch den <a href="http://www.exim-users.org/forums/showthread.php?t=44484&amp;page=1&amp;pp=15">Forumsthread, der die Verwendung von $authenticated_id und die Anpassung des received_header_text dokumentiert</a>. Die Mailingliste von exim enthält einen sehr guten Beitrag, mit ausführlicher Beispielkonfiguration, wie <a href="http://www.mail-archive.com/exim-users@exim.org/msg29852.html">E-Mails via Authentifizierung über externe Mailserver verschickt</a> werden können. <a href="http://www.tgunkel.de/docs/exim_smarthosts.de">Wie man mehrere Smarthosts mit Exim verwendt</a>, beschreibt auch Thorsten Gunkel.<br />
Nun testen wir die Exim-Konfiguration, ob auch alles wie gewünscht funktioniert.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">exim <span style="color: #660033;">-bt</span> paul<span style="color: #000000; font-weight: bold;">@</span>myserver</pre></div></div>

<p>sollte folgendes ausgeben</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">R: system_aliases for paul@myserver
R: local_user_secmail for paul@myserver
R: local_user for paul@myserver
paul@myserver
  router = local_user, transport = dovecot_delivery</pre></div></div>

<p>analog sollte ein</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">exim <span style="color: #660033;">-bt</span> paulpanzer<span style="color: #000000; font-weight: bold;">@</span>gmx.de</pre></div></div>

<p>zu folgendem Resultat führen</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">R: ldap_uid_alias for paulpanzer@gmx.de
R: system_aliases for paul@myserver
R: local_user_secmail for paul@myserver
R: local_user for paul@myserver
paul@myserver
    &lt;-- paulpanzer@gmx.de
  router = local_user, transport = dovecot_delivery</pre></div></div>

<p>Im nächsten Schritt können wir auch eine SMTP-Session testen. Dazu erzeugen wir mit dem Befehl</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-ne</span> <span style="color: #ff0000;">'\0paul@paulpanzer@gmx.de\0test'</span> <span style="color: #000000; font-weight: bold;">|</span> base64</pre></div></div>

<p>eine Zeichenfolge zur Authentifizierung, wobei paul für den Benutzer steht, paulpanzer@gmx.de für die externe Mailaddresse und test für das Passwort von paul (es besteht keine Verbindung zu den Passwörtern von paulpanzer@gmx.de). Ich erhalte hier AHBhdWxAcGF1bHBhbnplckBnbXguZGUAdGVzdA==. Wir starten mit</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">openssl s_client <span style="color: #660033;">-starttls</span> smtp <span style="color: #660033;">-crlf</span> <span style="color: #660033;">-connect</span> myserver:<span style="color: #000000;">25</span></pre></div></div>

<p>eine verschlüsselte SMTP-Session und verschicken eine Testmail an paul@myserver, indem wir folgende Befehle eingeben (alle Zeilen, die nicht mit einer Zahl beginnen)</p>

<div class="wp_syntax"><div class="code"><pre class="xorg_conf" style="font-family:monospace;"><span style="color: #cc66cc;">250</span> HELP
ehlo client
<span style="color: #cc66cc;">250</span>-myserver Hello myserver <span class="br0">&#91;</span>127.0.1.1<span class="br0">&#93;</span>
<span style="color: #cc66cc;">250</span>-SIZE <span style="color: #cc66cc;">52428800</span>
<span style="color: #cc66cc;">250</span>-PIPELINING
<span style="color: #cc66cc;">250</span>-AUTH PLAIN LOGIN
<span style="color: #cc66cc;">250</span> HELP
AUTH PLAIN AHBhdWxAcGF1bHBhbnplckBnbXguZGUAdGVzdA==
<span style="color: #cc66cc;">235</span> Authentication succeeded
mail from: paulpanzer@gmx.de
<span style="color: #cc66cc;">250</span> OK
rcpt to: paul@myserver
<span style="color: #cc66cc;">250</span> Accepted
data
<span style="color: #cc66cc;">354</span> Enter message, ending with <span style="color: #0000ff;">&quot;.&quot;</span> on a line by itself
From: Paul Panzer &lt;paulpanzer@gmx.de&gt;
To: Paul &lt;paul@myserver&gt;
Subject: Testing SMTP
This is a test body.
.
<span style="color: #cc66cc;">250</span> OK id=1Ll9N3-0001hf-6J
quit
<span style="color: #cc66cc;">221</span> myserver closing connection
closed</pre></div></div>

<p>Wer im Detail nachlesen möchte, was die einzelnen Befehle bewirken, dem sei die <a href="http://qmail.jms1.net/test-auth.shtml">Anleitung zum Testen von SMTP per Telnet von John M. Simpson</a> empfohlen. Als Resultat des Tests sollten wir im Verzeichnis /home/paul/mail/paul/maildir/INBOX/new/ eine Datei haben, die in etwa folgenden Inhalt hat</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">Return-path: &lt;paulpanzer@gmx.de&gt;
Envelope-to: paul@myserver
Delivery-date: Sat, 21 Mar 2009 23:18:09 +0100
Received: from myserver ([127.0.1.1] helo=la)
	by myserver with esmtpsa (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)
	(Exim 4.69)
	(envelope-from &lt;paulpanzer@gmx.de&gt;)
	id 1Ll9Vy-0001jC-N8
	for paul@myserver; Sat, 21 Mar 2009 23:18:09 +0100
From: Paul Panzer &lt;paulpanzer@gmx.de&gt;
To: Paul &lt;paul@myserver&gt;
Subject: Testing SMTP 
&nbsp;
This is a test body.</pre></div></div>

<h2>Fehlerquellen in der Konfiguration finden</h2>
<p>Falls exim nicht das gewünschte Resultat liefert oder bei der Auslieferung an eine bestimmte Addresse ein Fehler auftritt, hilft es, Exim im Debug-Modus zu starten. Beispielsweise kann man eine derartige Batch-SMTP-Session über folgenden Befehl starten</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> exim4 <span style="color: #660033;">-C</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>exim4<span style="color: #000000; font-weight: bold;">/</span>config.autogenerated <span style="color: #660033;">-v</span> -d+all <span style="color: #660033;">-bs</span></pre></div></div>

<p>Um zu testen, wie Exim intern die Mailaddressen routet, können wir mit</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> exim <span style="color: #660033;">-v</span> -d-all+lookup <span style="color: #660033;">-bt</span> paulpanzer<span style="color: #000000; font-weight: bold;">@</span>gmx.de</pre></div></div>

<p>alle zugehörigen lookups von exim verfolgen. Durch das &#8220;-all+lookup&#8221; werden nur Informationen ausgeben, die mit lookups zu tun haben.</p>
<h2>Umgang mit Exim</h2>
<p>Exim besitzt eine Vielzahl an Kommandozeilenoptionen. Sich in der man-page zurechtzufinden ist daher nicht einfach, allerdings habe ich eine <a href="http://forums.spry.com/showthread.php?t=1373">sehr gute Zusammenstellung einzelner Exim-Befehle</a> gefunden. Ein Befehl fehlt dabei jedoch. Mit</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> exim <span style="color: #660033;">-qff</span></pre></div></div>

<p>kann man das erneute Auslierfern von &#8220;frozen messages&#8221;, also als unzustellbar marktierten Mails, erzwingen.</p>
<p>Der vierte Teil der Konfiguration beschäftigt sich mit der <a href="http://www.effinger.org/blog/2009/03/22/dovecot-exim-openldap-und-getmail-unter-ubuntu-4-getmail/">Einrichtung von getmail zum Abruf externer Mails via POP3/IMAP</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.effinger.org/blog/2009/03/22/dovecot-exim-openldap-und-getmail-unter-ubuntu-3-exim/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Dovecot, Exim, OpenLDAP und getmail unter Ubuntu &#8211; (2) Dovecot</title>
		<link>http://www.effinger.org/blog/2009/03/22/dovecot-postfix-openldap-und-getmail-unter-ubuntu-2-dovecot/</link>
		<comments>http://www.effinger.org/blog/2009/03/22/dovecot-postfix-openldap-und-getmail-unter-ubuntu-2-dovecot/#comments</comments>
		<pubDate>Sun, 22 Mar 2009 16:56:36 +0000</pubDate>
		<dc:creator>Markus Effinger</dc:creator>
				<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[dovecot]]></category>
		<category><![CDATA[exim]]></category>
		<category><![CDATA[getmail]]></category>
		<category><![CDATA[LDAP]]></category>
		<category><![CDATA[OpenLDAP]]></category>

		<guid isPermaLink="false">http://www.effinger.org/blog/?p=458</guid>
		<description><![CDATA[<p>Nachdem die Grundvorraussetzungen im ersten Teil geschaffen wurden, wenden wir uns in diesem Teil der Anpassung, Installation und Konfiguration von dovecot zu. Obwohl fast alles im Blog detailliert beschrieben ist, empfehle ich, die Konfigurationsdateien für das Mailsystem herunterzuladen.</p>
Installation von Dovecot
<p>Nach einem</p>

sudo apt-get install dovecot-common dovecot-imapd dovecot-pop3d

<p>sind die notwendigen Dovecot-Pakete installiert.</p>
Anpassung der Installation
<p>Dovecot verwendet zur Zustellung [...]]]></description>
			<content:encoded><![CDATA[<p>Nachdem die Grundvorraussetzungen im <a href="http://www.effinger.org/blog/2009/03/22/dovecot-exim-openldap-und-getmail-unter-ubuntu-1-openldap/">ersten Teil</a> geschaffen wurden, wenden wir uns in diesem Teil der Anpassung, Installation und Konfiguration von <a href="http://www.dovecot.org/">dovecot</a> zu. Obwohl fast alles im Blog detailliert beschrieben ist, empfehle ich, die <a href="http://www.effinger.org/blog/wp-content/uploads/2009/03/configfiles-mailsystem.tgz">Konfigurationsdateien für das Mailsystem herunterzuladen</a>.</p>
<h2>Installation von Dovecot</h2>
<p>Nach einem</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> dovecot-common dovecot-imapd dovecot-pop3d</pre></div></div>

<p>sind die notwendigen Dovecot-Pakete installiert.</p>
<h2>Anpassung der Installation</h2>
<p>Dovecot verwendet zur Zustellung von Mails den Dovecot Local Delivery Agent (LDA). Damit dieser die Mails in allen Verzeichnissen der Benutzer ablegen kann, benötigt er root-Rechte, die wir über das Setuid-Bit vergeben. Zum Mailversand setzen wir jedoch exim als  Message Transfer Agent (MTA) ein, so dass Mails nie direkt via Dovecot-LDA, sondern immer indirekt über exim zugestellt werden. Da deshalb nur exim den Dovecot LDA aufrufen muss, wäre es sicherheitstechnisch bedenklich, könnte jeder Benutzer den Dovecot LDA mit Setuid-Bit aufrufen (eine Sicherheitslücke im Dovecot LDA würde dann sofort das gesamte System kompromittieren). Deshalb richten wir einen speziellen Benutzer namens secmail ein, der diese Rechte besitzt und dessen sich exim dann bedienen soll.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> adduser <span style="color: #660033;">--system</span> <span style="color: #660033;">--group</span> <span style="color: #660033;">--disabled-login</span> <span style="color: #660033;">--shell</span> <span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">false</span> <span style="color: #660033;">--home</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>secmail secmail</pre></div></div>

<p>Anschließend müssen wir für unsere Konfiguration das setuid-Bit für Dovecots LDA setzen,  damit dieser zur Zustellung jeweils auf die jeweilige Benutzer-ID wechseln kann. Durch den Aufruf von dpkg-statoverride werden die Berechtigungen auch bei Paketaktualisierungen beibehalten, obwohl der Einsatz auch einige <a href="http://www.netfort.gr.jp/~dancer/diary/200511.html.en#2005-Nov-13-09:40:15">Nachteile</a> mit sich bringt.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> dpkg-statoverride <span style="color: #660033;">--update</span> <span style="color: #660033;">--add</span> root secmail <span style="color: #000000;">4710</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>dovecot<span style="color: #000000; font-weight: bold;">/</span>deliver</pre></div></div>

<h2>Konfiguration von dovecot</h2>
<p>Zunächst kopieren wir die im <a href="http://www.effinger.org/blog/2009/03/22/dovecot-exim-openldap-und-getmail-unter-ubuntu-1-openldap/">ersten Teil der Anleitung</a> erzeugten Dateien des Client-Zertifikats für dovecot in das Konfigurationsverzeichnis und passen die Berechtigungen an.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>ssl<span style="color: #000000; font-weight: bold;">/</span>easy-rsa<span style="color: #000000; font-weight: bold;">/</span>keys<span style="color: #000000; font-weight: bold;">/</span>dovecot-client.key <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>ssl<span style="color: #000000; font-weight: bold;">/</span>easy-rsa<span style="color: #000000; font-weight: bold;">/</span>keys<span style="color: #000000; font-weight: bold;">/</span>dovecot-client.crt <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>dovecot
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">chown</span> root.dovecot <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>dovecot<span style="color: #000000; font-weight: bold;">/</span>dovecot-client.<span style="color: #7a0874; font-weight: bold;">&#123;</span>key,crt<span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">640</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>dovecot<span style="color: #000000; font-weight: bold;">/</span>dovecot-client.key</pre></div></div>

<p>Die <a href="http://wiki.dovecot.org/MainConfig">Konfiguration von dovecot</a> ist im Vergleich zu anderen Mailservern wie qmail, courier-imap oder cyrus einfach und gut dokumentiert. Meine um Kommentare und Leerzeilen verkürzte Version sieht so aus:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">protocols = imap imaps managesieve
log_path = <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>dovecot.log
log_timestamp = <span style="color: #ff0000;">&quot;%Y-%m-%d %H:%M:%S &quot;</span>
ssl_cert_file = <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>ssl<span style="color: #000000; font-weight: bold;">/</span>certs<span style="color: #000000; font-weight: bold;">/</span>myserver.crt
ssl_key_file = <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>ssl<span style="color: #000000; font-weight: bold;">/</span>private<span style="color: #000000; font-weight: bold;">/</span>myserver.key
ssl_ca_file = <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>ssl<span style="color: #000000; font-weight: bold;">/</span>certs<span style="color: #000000; font-weight: bold;">/</span>ca.crt
ssl_verify_client_cert = <span style="color: #c20cb9; font-weight: bold;">yes</span>
login_user = dovecot
login_greeting = Ready.
mail_privileged_group =
protocol imap <span style="color: #7a0874; font-weight: bold;">&#123;</span>
  login_executable = <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>dovecot<span style="color: #000000; font-weight: bold;">/</span>imap-login
  mail_executable = <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>dovecot<span style="color: #000000; font-weight: bold;">/</span>imap
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
protocol pop3 <span style="color: #7a0874; font-weight: bold;">&#123;</span>
  pop3_uidl_format = <span style="color: #000000; font-weight: bold;">%</span>08Xu<span style="color: #000000; font-weight: bold;">%</span>08Xv
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
protocol managesieve <span style="color: #7a0874; font-weight: bold;">&#123;</span>
  login_executable = <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>dovecot<span style="color: #000000; font-weight: bold;">/</span>managesieve-login
  mail_executable = <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>dovecot<span style="color: #000000; font-weight: bold;">/</span>managesieve
  <span style="color: #007800;">sieve</span>=~<span style="color: #000000; font-weight: bold;">/</span>.dovecot.sieve
  <span style="color: #007800;">sieve_storage</span>=~<span style="color: #000000; font-weight: bold;">/</span>sieve
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
protocol lda <span style="color: #7a0874; font-weight: bold;">&#123;</span>
  postmaster_address = paul<span style="color: #000000; font-weight: bold;">@</span>myserver
  mail_plugins = cmusieve
  mail_plugin_dir = <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>dovecot<span style="color: #000000; font-weight: bold;">/</span>modules<span style="color: #000000; font-weight: bold;">/</span>lda
  log_path = <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>dovecot-deliver.log
  auth_socket_path = <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span>dovecot<span style="color: #000000; font-weight: bold;">/</span>auth-master
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
auth_executable = <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>dovecot<span style="color: #000000; font-weight: bold;">/</span>dovecot-auth
auth_username_chars = abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890.-_<span style="color: #000000; font-weight: bold;">@</span>
auth default <span style="color: #7a0874; font-weight: bold;">&#123;</span>
  mechanisms = plain
  passdb ldap <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    args = <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>dovecot<span style="color: #000000; font-weight: bold;">/</span>dovecot-ldap-passdb.conf
  <span style="color: #7a0874; font-weight: bold;">&#125;</span>
  userdb ldap <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    args = <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>dovecot<span style="color: #000000; font-weight: bold;">/</span>dovecot-ldap-userdb.conf
  <span style="color: #7a0874; font-weight: bold;">&#125;</span>
  user = root
  socket listen <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    master <span style="color: #7a0874; font-weight: bold;">&#123;</span>
      path = <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span>dovecot<span style="color: #000000; font-weight: bold;">/</span>auth-master
      mode = 0660
      group = secmail
    <span style="color: #7a0874; font-weight: bold;">&#125;</span>
  <span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
dict <span style="color: #7a0874; font-weight: bold;">&#123;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
plugin <span style="color: #7a0874; font-weight: bold;">&#123;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>Eine entsprechende Datei kann man einfach durch ein</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>dovecot<span style="color: #000000; font-weight: bold;">/</span>dovecot.conf <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">egrep</span> <span style="color: #660033;">-v</span> <span style="color: #ff0000;">'(^\t* *#|^\t* *$)'</span></pre></div></div>

<p>erzeugen. Hier ist der Inhalt der referenzierten Dateien dovecot-ldap-passdb.conf und dovecot-ldap-userdb.conf.</p>
<p>dovecot-ldap-passdb.conf:</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;"><span style="color: #000099;">hosts</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> myserver</span>
<span style="color: #000099;">tls</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> yes</span>
<span style="color: #000099;">tls_ca_cert_file</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> /etc/ssl/certs/ca.crt</span>
<span style="color: #000099;">tls_cert_file</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> /etc/dovecot/dovecot-client.crt</span>
<span style="color: #000099;">tls_key_file</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> /etc/dovecot/dovecot-client.key</span>
<span style="color: #000099;">tls_require_cert</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> demand</span>
<span style="color: #000099;">auth_bind</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> yes</span>
<span style="color: #000099;">auth_bind_userdn</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> uid=%Ln,ou=users,o=effinger</span>
<span style="color: #000099;">ldap_version</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> 3</span>
<span style="color: #000099;">base</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> uid=%Ln,ou=users,o=effinger</span></pre></div></div>

<p>dovecot-ldap-userdb.conf:</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;"><span style="color: #000099;">hosts</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> myserver</span>
<span style="color: #000099;">tls</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> yes</span>
<span style="color: #000099;">tls_ca_cert_file</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> /etc/ssl/certs/ca.crt</span>
<span style="color: #000099;">tls_cert_file</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> /etc/dovecot/dovecot-client.crt</span>
<span style="color: #000099;">tls_key_file</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> /etc/dovecot/dovecot-client.key</span>
<span style="color: #000099;">tls_require_cert</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> demand</span>
<span style="color: #000099;">ldap_version</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> 3</span>
<span style="color: #000099;">base</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> uid=%Ln,ou=users,o=effinger</span>
<span style="color: #000099;">scope</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> subtree</span>
<span style="color: #000099;">user_attrs</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> dcMailMessageStore=home=%$/%Ld,uidNumber=uid,gidNumber=gid,=mail=maildir:~/maildir:INBOX=~/maildir/INBOX</span>
<span style="color: #000099;">user_filter</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> <span style="">&#40;</span>|<span style="">&#40;</span>mail<span style="color: #000066; font-weight:bold;">=</span>%d<span style="">&#41;</span><span style="">&#40;</span>&amp;<span style="">&#40;</span>dcSubMailAddress<span style="color: #000066; font-weight:bold;">=</span>%d<span style="">&#41;</span><span style="">&#40;</span>dcAccountStatus<span style="color: #000066; font-weight:bold;">=</span>active<span style="">&#41;</span><span style="">&#41;</span><span style="">&#41;</span></span></pre></div></div>

<p>Nach einem</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>dovecot restart</pre></div></div>

<p>sollte man den Login testen. Dazu kann man die <a href="http://aplawrence.com/SCOFAQ/FAQ_scotec4testimap.html">Anleitung zum Testen von IMAP mit telnet von A. P. Lawrence</a> verwenden. Das sieht dann beispielsweise so aus:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ telnet localhost <span style="color: #000000;">143</span>
Trying 127.0.0.1...
Connected to localhost.
Escape character is <span style="color: #ff0000;">'^]'</span>.
<span style="color: #000000; font-weight: bold;">*</span> OK Ready.
as1 <span style="color: #c20cb9; font-weight: bold;">login</span> paul<span style="color: #000000; font-weight: bold;">@</span>paul mypassword
as1 OK Logged in.
as2 <span style="color: #7a0874; font-weight: bold;">logout</span>
<span style="color: #000000; font-weight: bold;">*</span> BYE Logging out
as2 OK Logout completed.
Connection closed by foreign host.</pre></div></div>

<p>Wichtig ist dabei, beide E-Mail-Addressen zu überprüfen (lokal und extern). Im Beispiel hier muss man also die logins paul@paul sowie paul@paulpanzer@gmx.de testen.</p>
<p>Zum Schluss möchte ich noch auf einige Seiten hinweisen, die bei der Konfiguration von dovecot hilfreich für mich waren</p>
<ul>
<li><a href="http://wiki.dovecot.org/">Offizielle Docevot-Dokumentation</a></li>
<li><a href="http://www.njae.me.uk/Dovecot_server_setup">Beispielhaftes Server-Setup mit virtuellen Benutzern</a></li>
<li><a href="http://wanderingbarque.com/howtos/mailserver/mailserver.html">Secure Virtual Mailserver Howto</a></li>
</ul>
<p>In <a href="http://www.effinger.org/blog/2009/03/22/dovecot-exim-openldap-und-getmail-unter-ubuntu-3-exim/">Teil 3</a> befassen wir uns mit der Einrichtung von Exim als MTA (Message Transfer Agent).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.effinger.org/blog/2009/03/22/dovecot-postfix-openldap-und-getmail-unter-ubuntu-2-dovecot/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Dovecot, Exim, OpenLDAP und getmail unter Ubuntu &#8211; (1) OpenLDAP</title>
		<link>http://www.effinger.org/blog/2009/03/22/dovecot-exim-openldap-und-getmail-unter-ubuntu-1-openldap/</link>
		<comments>http://www.effinger.org/blog/2009/03/22/dovecot-exim-openldap-und-getmail-unter-ubuntu-1-openldap/#comments</comments>
		<pubDate>Sun, 22 Mar 2009 16:55:33 +0000</pubDate>
		<dc:creator>Markus Effinger</dc:creator>
				<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[dovecot]]></category>
		<category><![CDATA[exim]]></category>
		<category><![CDATA[getmail]]></category>
		<category><![CDATA[LDAP]]></category>
		<category><![CDATA[OpenLDAP]]></category>

		<guid isPermaLink="false">http://www.effinger.org/blog/?p=248</guid>
		<description><![CDATA[<p>In diesem Blog-Eintrag geht es um die Einrichtung eines Mailservers, der dovecot, Exim, OpenLDAP und getmail verwendet. Folgendes wird mit der Konfiguration erreicht:</p>

Mails können von  Benutzern, die in OpenLDAP eingetragen sind per IMAP abgerufen und per SMTP versendet werden (auch mit TLS-Verschlüsselung).
Benutzer können Mails von externen POP3/IMAP-Accounts direkt in ihr IMAP Postfach legen lassen
Benutzer können [...]]]></description>
			<content:encoded><![CDATA[<p>In diesem Blog-Eintrag geht es um die Einrichtung eines Mailservers, der <a href="http://www.dovecot.org/">dovecot</a>, <a href="http://www.exim.org/">Exim</a>, <a href="http://www.openldap.org/">OpenLDAP</a> und <a href="http://pyropus.ca/software/getmail/">getmail</a> verwendet. Folgendes wird mit der Konfiguration erreicht:</p>
<ul>
<li>Mails können von  Benutzern, die in OpenLDAP eingetragen sind per IMAP abgerufen und per SMTP versendet werden (auch mit TLS-Verschlüsselung).</li>
<li>Benutzer können Mails von externen POP3/IMAP-Accounts direkt in ihr IMAP Postfach legen lassen</li>
<li>Benutzer können Mails mit einer externen Absenderaddresse via lokalem Mailserver verschicken, der sie über den entsprechenden externen Mailserver verschickt</li>
</ul>
<p>Am Beispiel sollte es klarer werden. Paul ist mit der Userid paul in OpenLDAP eingetragen und hat auf dem lokalen Rechner mit der Domain myserver die Mailaddresse paul@myserver. Paul kann per IMAP Mails abrufen (Login: paul@paul Server: myserver) und ebenfalls per SMTP Mails verschicken. Außerdem hat Paul eine weitere E-Mailadresse aus der Zeit als er sich noch keine eigene Domain leisten konnte. Diese lautet paulpanzer@gmx.de. Paul möchte seine E-Mails zukünftig auf seinem lokalen Server speichern und nicht mehr bei GMX. Er bzw. der Administrator trägt dazu die POP3-Zugangsdaten von GMX in OpenLDAP ein. Danach werden alle E-Mails automatisch heruntergeladen und Paul kann über den Login paul@paulpanzer@gmx.de auf dem Server myserver seine GMX-Mails per IMAP abrufen. Trägt Paul bzw. der Administrator auch die SMTP-Daten für die E-Mailaddresse paulpanzer@gmx.de in OpenLDAP ein, so kann Paul außerdem Mails indirekt via GMX- Mailserver verschicken, indem er als SMTP-Login paul@paulpanzer@gmx.de auf seinem lokalen Server wählt. So sieht das fertige Schema mit der verwendeten Software aus:</p>
<p><a href="http://www.effinger.org/blog/wp-content/uploads/2009/03/general_scheme.png"><img class="aligncenter size-medium wp-image-709" title="General Software Setup - Dovecot, Exim &amp; Co." src="http://www.effinger.org/blog/wp-content/uploads/2009/03/general_scheme-300x212.png" alt="General Software Setup - Dovecot, Exim &amp; Co." width="300" height="212" /></a>Der Zugriff per Webinterface auf Mails und der Abruf der Mails vom externen Server bzw. das Empfangen von Mails ist hier dargestellt:</p>
<p><a href="http://www.effinger.org/blog/wp-content/uploads/2009/03/general_scheme_2.png"><img class="aligncenter size-medium wp-image-707" title="General software setup - Getmail, Roundcube &amp; Co." src="http://www.effinger.org/blog/wp-content/uploads/2009/03/general_scheme_2-300x212.png" alt="General software setup - Getmail, Roundcube &amp; Co." width="300" height="212" /></a></p>
<h2>Einrichtung</h2>
<p>Bevor man überhaupt daran denkt, ein E-Mail-Serversystem aufzusetzen, müssen zwei Bedingungen erfüllt sein. Die erste betrifft eine genaue Systemzeit, der zweite den Hostnamen. Obwohl fast alles im Blog detailliert beschrieben ist, empfehle ich, die <a href="http://www.effinger.org/blog/wp-content/uploads/2009/03/configfiles-mailsystem.tgz">Konfigurationsdateien für das Mailsystem herunterzuladen</a>.</p>
<h2>Genaue Systemzeit mit Ubuntu</h2>
<p>Leider installiert Ubuntu standardmäßig das Paket ntpdate. Durch dieses Paket wird jedes Mal, wenn man mit dem Internet verbunden ist (genauer gesagt beim ifup), die Zeit mit einem NTP-Server im Internet abgeglichen und ggfs. die Systemzeit entsprechend geändert. An sich ja keine schlechte Sache, aber <a href="http://wiki.dovecot.org/TimeMovedBackwards">dovecot reagiert auf Zeitänderungen sehr verstimmt</a> und quittiert den Dienst. Deshalb setze ich stets ntpd ein. Dies ist ein NTP-Server, der systematisch die Differenz zwischen Systemzeitgeber und dem Internetserver beobachtet und so systematisches zu schell bzw. zu langsam gehen des Systemzeitgebers korrigieren kann. Man erhält damit eine genauere Systemzeit und damit auch ein stabiles dovecot. Deshalb installiere ich ntpd und entferne ntpdate:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> autoremove <span style="color: #660033;">--purge</span> ntpdate <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> ntp</pre></div></div>

<p>Um für den Ausfall des Ubuntu NTP-Servers gewappnet zu sein, habe ich die Server-Einträge in /etc/ntp.conf noch um Server aus dem <a href="http://www.pool.ntp.org/use.html">öffentlichen NTP-Pool</a> ergänzt:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># You do need to talk to an NTP server or two (or three).</span>
server 0.pool.ntp.org
server 1.pool.ntp.org
server 2.pool.ntp.org
server ntp.ubuntu.com</pre></div></div>

<p>Nach einem Speichern der Konfigurationsdatei und einem Neustart des NTP-Servers mit</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>ntp restart</pre></div></div>

<p>haben wir den ersten Punkt erledigt. Christoph Langner beschreibt die <a href="http://christoph-langner.de/de/2008/12/die-uhrzeit-eines-rechners-uber-das-internet-stellen/">Installation von ntpd</a> noch etwas ausführlicher.</p>
<h2>Hostname für den Mailserver</h2>
<p>Der zweite wichtige Punkt ist der Hostname. Der fully qualified domain name (FQDN) des Rechners muss bekannt sein. Nachprüfen lässt sich das über</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">hostname</span> <span style="color: #660033;">--fqdn</span></pre></div></div>

<p>Bekommt man keine Ausgabe wie host.domain.de, dann muss man die /etc/hosts anpassen, so dass die Reihenfolge der Servernamen stimmt:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">127.0.0.1	myserver	localhost</pre></div></div>

<p>Bitte unbedingt beachten, dass das beispielhaft aufgeführte myserver <em>kein</em> FQDN ist. Ein FQDN besteht immer auch aus einer Top-Level-Domain.</p>
<h2>Erzeugen von SSL-Zertifikaten</h2>
<p>Damit wir mit imaps, dem durch Verschlüsselung abgesicherten IMAP, auf unseren Server zugreifen können, und auch den SMTP- und LDAP-Zugriff verschlüsseln können, benötigen wir entsprechende SSL-Zertifikate. Am einfachsten lassen sich solche Zertifikate mit easy-rsa aus dem Paktet openvpn erzeugen. Übrigens gibt es gibt es dazu gute Anleitungen von <a href="http://knecht.homelinux.net/phpBB2/viewtopic.php?f=12&amp;t=449">linux.neoberserker.de</a> oder im <a href="http://wiki.openvpn.eu/index.php/Erzeugen_einer_PKI_mit_EasyRSA">OpenVPN-Wiki</a>. Das Paket openvpn müssen wir jedoch nicht installieren. Es genügt, wenn wir mit</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">mkdir</span> openvpn <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">cd</span> openvpn <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #7a0874; font-weight: bold;">source</span> openvpn</pre></div></div>

<p>den Quelltext herunterladen. Wir führen alle folgenden Befehle zur Zertifikatserstellung als root aus (wichtig, damit später nicht jeder Benutzer die geheimen Dateien lesen kann). Zunächst kopieren wir das entsprechende Unterverzeichnis in /etc/ssl und löschen anschließend die nicht mehr benötigten Verzeichnisse mit</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #660033;">-s</span>
<span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #660033;">-R</span> openvpn-<span style="color: #000000;">2.1</span>~rc11<span style="color: #000000; font-weight: bold;">/</span>easy-rsa<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">2.0</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>ssl<span style="color: #000000; font-weight: bold;">/</span>easy-rsa
<span style="color: #7a0874; font-weight: bold;">cd</span> .. <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> openvpn
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>ssl<span style="color: #000000; font-weight: bold;">/</span>easy-rsa</pre></div></div>

<p>Nun editieren wir die Datei <em>vars</em> und passen Sie entsprechend an. Bei mir habe ich folgende Zeilen am Ende angepasst:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">KEY_COUNTRY</span>=<span style="color: #ff0000;">&quot;DE&quot;</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">KEY_PROVINCE</span>=<span style="color: #ff0000;">&quot;RP&quot;</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">KEY_CITY</span>=<span style="color: #ff0000;">&quot;Ludwigshafen&quot;</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">KEY_ORG</span>=<span style="color: #ff0000;">&quot;Effinger&quot;</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">KEY_EMAIL</span>=<span style="color: #ff0000;">&quot;nospam@effinger.org&quot;</span></pre></div></div>

<p>Anschließend führen wir folgende Schritte durch, um die CA-Dateien zur Ausstellung eigener Zertifikate zu erzeugen. Beim Schritt ./build-ca kann man alle Punkte mit Enter bestätigen bis auf <em>common name</em>. Hier sollte man einen einfachen Namen, z.B. MyCA, angeben (am Besten nur Buchstaben und Zahlen verwenden &#8211; keine Leerzeichen oder sonstige Sonderzeichen).</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">. .<span style="color: #000000; font-weight: bold;">/</span>vars
.<span style="color: #000000; font-weight: bold;">/</span>clean-all
.<span style="color: #000000; font-weight: bold;">/</span>build-ca
.<span style="color: #000000; font-weight: bold;">/</span>build-dh</pre></div></div>

<p>Im nächsten Schritt erstellen wir für unseren Mailserver ein Server-Schlüsselpaar mit dem Befehl</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>build-key-server myserver</pre></div></div>

<p>myserver sollte dabei durch den DNS-Eintrag des Servers ersetzt werden (Thunderbird fragt ansonsten jedes Mal sicherheitshalber nach, ob das Zertifikat akzeptiert werden soll, weil der Zertifikatsname nicht mit dem Hostnamen übereinstimmt). Auch hier bestätigen wir wieder alles mit Enter bis auf den Punkt <em>Sign the certificate?</em> Hier antworten wir mit ja (<em>y</em>) und bestätigen die darauf erfolgende Rückfrage ebenfalls mit <em>y</em>. Ein Client-Zertifikat kann man mit</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>build-key myclient</pre></div></div>

<p>analog erzeugen. Dieses benötigt man jedoch nur, wenn man ausschließlich Clients mit gültigem Zertifikat auf den Mailserver zugreifen lassen möchte. Bei dovecot ist das der Fall, wenn der Parameter <em>ssl_require_client_cert=yes</em> gesetzt ist. Da dovecot sich mit dem LDAP-Server verbindet, können wir dazu ebenfalls ein Client-Zertifikat verwenden. Wir erzeugen es mit</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>build-key dovecot-client</pre></div></div>

<p>Im Unterverzeichnis keys sind nun einige Dateien, die wir noch in das richtige Verzeichnis kopieren müssen. Wichtig ist, dass niemand unbefugt auf die <a href="http://wiki.openvpn.eu/index.php/Erzeugen_einer_PKI_mit_EasyRSA#Schl.C3.BCssel.C3.BCbersicht">geheimzuhaltenden Dateien</a> zugreifen kann, die allesamt mit der Erweiterung .key enden. Am Besten ist es, vor dem Kopieren die Berechtigungen zu prüfen. Die öffentlichen Zertifikate werden in das Verzeichnis /etc/ssl/certs und die geheimen Zertifikate in /etc/ssl/private kopiert mit</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>ssl<span style="color: #000000; font-weight: bold;">/</span>easy-rsa<span style="color: #000000; font-weight: bold;">/</span>keys<span style="color: #000000; font-weight: bold;">/</span>myserver.crt <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>ssl<span style="color: #000000; font-weight: bold;">/</span>easy-rsa<span style="color: #000000; font-weight: bold;">/</span>keys<span style="color: #000000; font-weight: bold;">/</span>ca.crt <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>ssl<span style="color: #000000; font-weight: bold;">/</span>certs<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>ssl<span style="color: #000000; font-weight: bold;">/</span>easy-rsa<span style="color: #000000; font-weight: bold;">/</span>keys<span style="color: #000000; font-weight: bold;">/</span>myserver.key <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>ssl<span style="color: #000000; font-weight: bold;">/</span>private<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #c20cb9; font-weight: bold;">chown</span> root.ssl-cert <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>ssl<span style="color: #000000; font-weight: bold;">/</span>private<span style="color: #000000; font-weight: bold;">/</span>myserver.key
<span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">640</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>ssl<span style="color: #000000; font-weight: bold;">/</span>private<span style="color: #000000; font-weight: bold;">/</span>myserver.key</pre></div></div>

<p>Die letzten beiden Zeilen dienen dazu, Exim, Dovecot und LDAP den Zugriff auf die geheime Key-Datei zu gewähren. Die entsprechendenBenutzer müssen dazu in der Gruppe ssl-cert sein (Anleitung erfolgt bei der Installation des jeweiligen Programms). Falls man später doch noch OpenVPN nutzen möchte, kann man den Diffie-Hellman Parameter ebenfalls kopieren</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>ssl<span style="color: #000000; font-weight: bold;">/</span>easy-rsa<span style="color: #000000; font-weight: bold;">/</span>keys<span style="color: #000000; font-weight: bold;">/</span>dh1024.pem <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>ssl<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<p>Die Client-Zertifikate muss man nun natürlich dem E-Mail-Programm bekannt machen. Bei Thunderbird fügt man über <em>Extras&gt;Einstellungen&gt;Erweitert&gt;Zertifikate&gt;Zertifikate&gt;Zertifizierungsstellen&gt;Importieren</em> die Datei ca.crt hinzu, wechselt anschließend auf den Reiter <em>Ihre Zertifikate, </em>um dort dann die Dateien <em>myclient.p12</em> importieren. Letzere Datei erzeugt man durch ein</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">openssl pkcs12 <span style="color: #660033;">-export</span> <span style="color: #660033;">-name</span> <span style="color: #ff0000;">&quot;myclient&quot;</span> <span style="color: #660033;">-in</span> myclient.crt <span style="color: #660033;">-inkey</span> myclient.key <span style="color: #660033;">-out</span> myclient.p12</pre></div></div>

<h2>OpenLDAP installieren</h2>
<p>Als nächstes installieren wir OpenLDAP und die ldap-utils nach meinem <a href="http://www.effinger.org/blog/2008/12/14/das-kleine-openldap-1x1/">OpenLDAP 1&#215;1</a>. Hier die Schritte in Kurzform (falls Schritte unklar sind &#8211; im <a href="http://www.effinger.org/blog/2008/12/14/das-kleine-openldap-1x1/">OpenLDAP 1&#215;1</a> ist alles sehr ausführlich erklärt):</p>
<ol>
<li>Alle folgenden Befehle als root ausführen mit einem

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">bash</span></pre></div></div>

<p>oder</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #660033;">-s</span></pre></div></div>

</li>
<li>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> slapd ldap-utils</pre></div></div>

<p>Unbedingt das Administrator-Passwort bei der Einrichtung merken.</li>
<li>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>slapd stop</pre></div></div>

</li>
<li>Die automatisch bei der Einrichtung erzeugte Datenbank löschen (Vorsicht, wenn OpenLDAP bereits im Einsatz ist! Dieser Befehl kann die aktive Datenbank löschen)</li>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>ldap<span style="color: #000000; font-weight: bold;">/</span>slapd.d<span style="color: #000000; font-weight: bold;">/</span>cn\=config<span style="color: #000000; font-weight: bold;">/</span>olcDatabase\=\<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">1</span>\<span style="color: #7a0874; font-weight: bold;">&#125;</span>hdb.ldif <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>ldap<span style="color: #000000; font-weight: bold;">/*</span></pre></div></div>

<li>Die folgende Datei database.ldif passen:

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Database settings</span>
dn: <span style="color: #007800;">olcDatabase</span>=hdb,<span style="color: #007800;">cn</span>=config
objectClass: olcDatabaseConfig
objectClass: olcHdbConfig
olcDatabase: hdb
<span style="color: #666666; font-style: italic;"># The base of your directory</span>
olcSuffix: <span style="color: #007800;">o</span>=effinger
<span style="color: #666666; font-style: italic;"># rootdn directive for specifying a superuser on the database. This is needed</span>
<span style="color: #666666; font-style: italic;"># for syncrepl.</span>
olcRootDN: <span style="color: #007800;">cn</span>=admin,<span style="color: #007800;">o</span>=effinger
<span style="color: #666666; font-style: italic;"># Superuser Password for the database</span>
<span style="color: #666666; font-style: italic;"># {SSHA}pEvotN6PmSjx0JV/mZl5BWeSVOKR1Ejt equals &quot;test&quot;</span>
<span style="color: #666666; font-style: italic;"># CHANGE this for your installation!!!</span>
olcRootPW: <span style="color: #7a0874; font-weight: bold;">&#123;</span>SSHA<span style="color: #7a0874; font-weight: bold;">&#125;</span>pEvotN6PmSjx0JV<span style="color: #000000; font-weight: bold;">/</span>mZl5BWeSVOKR1Ejt
<span style="color: #666666; font-style: italic;"># Where the database file are physically stored</span>
olcDbDirectory: <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>ldap
<span style="color: #666666; font-style: italic;"># The dbconfig settings are used to generate a DB_CONFIG file the first</span>
<span style="color: #666666; font-style: italic;"># time slapd starts.  They do NOT override existing an existing DB_CONFIG</span>
<span style="color: #666666; font-style: italic;"># file.  You should therefore change these settings in DB_CONFIG directly</span>
<span style="color: #666666; font-style: italic;"># or remove DB_CONFIG and restart slapd for changes to take effect.</span>
<span style="color: #666666; font-style: italic;"># For the Debian package we use 2MB as default but be sure to update this</span>
<span style="color: #666666; font-style: italic;"># value if you have plenty of RAM</span>
&nbsp;
olcDbConfig: set_cachesize <span style="color: #000000;">0</span> <span style="color: #000000;">2097152</span> <span style="color: #000000;">0</span>
<span style="color: #666666; font-style: italic;"># Sven Hartge reported that he had to set this value incredibly high</span>
<span style="color: #666666; font-style: italic;"># to get slapd running at all. See http://bugs.debian.org/303057 for more</span>
<span style="color: #666666; font-style: italic;"># information.</span>
<span style="color: #666666; font-style: italic;"># Number of objects that can be locked at the same time.</span>
olcDbConfig: set_lk_max_objects <span style="color: #000000;">1500</span>
<span style="color: #666666; font-style: italic;"># Number of locks (both requested and granted)</span>
olcDbConfig: set_lk_max_locks <span style="color: #000000;">1500</span>
<span style="color: #666666; font-style: italic;"># Number of lockers</span>
olcDbConfig: set_lk_max_lockers <span style="color: #000000;">1500</span>
<span style="color: #666666; font-style: italic;"># Indexing options</span>
olcDbIndex: objectClass eq
<span style="color: #666666; font-style: italic;"># Save the time that the entry gets modified</span>
olcLastMod: TRUE
<span style="color: #666666; font-style: italic;"># Checkpoint the BerkeleyDB database periodically in case of system</span>
<span style="color: #666666; font-style: italic;"># failure and to speed slapd shutdown.</span>
olcDbCheckpoint: <span style="color: #000000;">512</span> <span style="color: #000000;">30</span>
<span style="color: #666666; font-style: italic;"># The userPassword by default can be changed</span>
<span style="color: #666666; font-style: italic;"># by the entry owning it if they are authenticated.</span>
<span style="color: #666666; font-style: italic;"># Others should not be able to see it, except the</span>
<span style="color: #666666; font-style: italic;"># admin entry below</span>
<span style="color: #666666; font-style: italic;"># These access lines apply to database #1 only</span>
olcAccess: to <span style="color: #007800;">attrs</span>=userPassword,shadowLastChange by <span style="color: #007800;">dn</span>=<span style="color: #ff0000;">&quot;cn=admin,o=effinger&quot;</span> <span style="color: #c20cb9; font-weight: bold;">write</span> by anonymous auth by self <span style="color: #c20cb9; font-weight: bold;">write</span> by <span style="color: #000000; font-weight: bold;">*</span> none
<span style="color: #666666; font-style: italic;"># Ensure read access to the base for things like</span>
<span style="color: #666666; font-style: italic;"># supportedSASLMechanisms.  Without this you may</span>
<span style="color: #666666; font-style: italic;"># have problems with SASL not knowing what</span>
<span style="color: #666666; font-style: italic;"># mechanisms are available and the like.</span>
<span style="color: #666666; font-style: italic;"># Note that this is covered by the 'access to *'</span>
<span style="color: #666666; font-style: italic;"># ACL below too but if you change that as people</span>
<span style="color: #666666; font-style: italic;"># are wont to do you'll still need this if you</span>
<span style="color: #666666; font-style: italic;"># want SASL (and possible other things) to work</span>
<span style="color: #666666; font-style: italic;"># happily.</span>
olcAccess: to dn.base=<span style="color: #ff0000;">&quot;&quot;</span> by <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #c20cb9; font-weight: bold;">read</span>
<span style="color: #666666; font-style: italic;"># The admin dn has full write access, everyone else</span>
<span style="color: #666666; font-style: italic;"># can read everything.</span>
olcAccess: to <span style="color: #000000; font-weight: bold;">*</span> by <span style="color: #007800;">dn</span>=<span style="color: #ff0000;">&quot;cn=admin,o=effinger&quot;</span> <span style="color: #c20cb9; font-weight: bold;">write</span> by <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #c20cb9; font-weight: bold;">read</span>
<span style="color: #666666; font-style: italic;"># For Netscape Roaming support, each user gets a roaming</span>
<span style="color: #666666; font-style: italic;"># profile for which they have write access to</span>
<span style="color: #666666; font-style: italic;">#olcAccess: to dn=&quot;.*,ou=Roaming,o=morsnet&quot; by dn=&quot;cn=admin,o=effinger&quot; write by dnattr=owner write</span></pre></div></div>

<p><strong>Bitte unbedingt das Passwort (olcRootPW) ändern.</strong><br />
Falls gewünscht auch die RootDN (hier &#8220;o=effinger&#8221;) anpassen. Dadurch müssen einige der folgenden Befehle/Dateien angepasst werden.</li>
<li>Eine neue Datenbank mit Hilfe der database.ldif erzeugen (Administratorpasswort aus Schritt 2 wird benötigt)

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>slapd start
ldapadd <span style="color: #660033;">-f</span> database.ldif <span style="color: #660033;">-x</span> <span style="color: #660033;">-D</span> <span style="color: #ff0000;">&quot;cn=admin,cn=config&quot;</span> <span style="color: #660033;">-W</span></pre></div></div>

</li>
</ol>
<p>Jetzt haben wir eine saubere Datenbank mit der RootDN &#8220;o=effinger&#8221; und dem entsprechenden Administrator &#8220;cn=admin,o=effinger&#8221;, die wir nun weiter konfigurieren können. Bevor wir damit loslegen, muss man sich jedoch Gedanken machen, wie die Daten in OpenLDAP strukturiert werden sollen. Ich habe mich für folgendes Setup entschieden:</p>
<ul>
<li>Benutzer werden im Kontext ou=users,o=effinger gespeichert also z.B. uid=paul,ou=users,o=effinger. Hier wird auch die lokale Mail-Addresse paul abgelegt. Die Domainendung (@myserver) wird hier weggelassen, da teilweise die Domain nicht angegeben ist bzw. oft anders addressiert ist, z.B. paul@localhost</li>
<li>Externe Mail-Accounts des Benutzers werden jeweils unter dem zugehörigen Benutzereintrag gespeichert, also z.B. dcSubMailAddress=paulpanzer@gmx.de,uid=paul,ou=users,o=effinger, zusammen mit den Angaben zu Logins für SMTP und den Mailabruf, z.B. mit POP3.</li>
<li>Da dovecot jedoch nicht ganz flexibel mit LDAP umgehen kann, müssen wir Parameter wie uid, Angaben zum Speicherort der Mails, die unter uid=paul,ou=users,o=effinger verfügbar sind auch unter dcSubMailAddress=paulpanzer@gmx.de,uid=paul,ou=users,o=effinger verfügbar machen. Das geht mit dem <a href="http://www.openldap.org/faq/data/cache/1209.html">DynList/DynGroup Overlay</a> von OpenLDAP. Eine Alternative wäre das <a href="http://linux.die.net/man/5/slapo-rwm">slapo-rwm Overlay</a> gewesen, das allerdings in der aktuellen Ubuntu-Version noch einen <a href="http://www.mail-archive.com/openldap-software@openldap.org/msg14716.html">Bug</a> aufweist und deshalb außen vor bleibt.</li>
</ul>
<p>Nach den konzeptionellen Überlegungen machen wir uns nun an die Arbeit. Wir konfigurieren das DynList-Overlay, wobei mir eine <a href="http://wiki.das-online.org/howtos/ldap/openldap-gentoo#dynlist">Anleitung für Gentoo</a> und die <a href="http://islandlinux.org/howto/installing-secure-ldap-openldap-ssl-ubuntu-using-self-signed-certificate">kurze Einführung für Ubuntu</a> sehr geholfen haben und ergänzen OpenLDAP mit einem von mir <a href="http://www.effinger.org/blog/2009/01/11/eigenes-ldap-schema-erstellen/">erstellten Schema (dovecot.schema.ldif)</a>.</p>
<ol>
<li>Folgenden Inhalt unter dem Namen dyngroup.schema.ldif abspeichern:

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">dn: <span style="color: #007800;">cn</span>=dyngroup,<span style="color: #007800;">cn</span>=schema,<span style="color: #007800;">cn</span>=config
objectClass: olcSchemaConfig
cn: dyngroup
olcObjectIdentifier: NetscapeRoot 2.16.840.1.113730
olcObjectIdentifier: NetscapeLDAP NetscapeRoot:<span style="color: #000000;">3</span>
olcObjectIdentifier: NetscapeLDAPattributeType NetscapeLDAP:<span style="color: #000000;">1</span>
olcObjectIdentifier: NetscapeLDAPobjectClass NetscapeLDAP:<span style="color: #000000;">2</span>
olcObjectIdentifier: OpenLDAPExp11 1.3.6.1.4.1.4203.666.11
olcObjectIdentifier: DynGroupBase OpenLDAPExp11:<span style="color: #000000;">8</span>
olcObjectIdentifier: DynGroupAttr DynGroupBase:<span style="color: #000000;">1</span>
olcObjectIdentifier: DynGroupOC DynGroupBase:<span style="color: #000000;">2</span>
olcAttributeTypes: <span style="color: #7a0874; font-weight: bold;">&#40;</span> NetscapeLDAPattributeType:<span style="color: #000000;">198</span> NAME <span style="color: #ff0000;">'memberURL'</span> DESC <span style="color: #ff0000;">'Identifies an URL associated with each member of a group. Any type of labeled URL can be used.'</span> SUP labeledURI <span style="color: #7a0874; font-weight: bold;">&#41;</span>
olcAttributeTypes: <span style="color: #7a0874; font-weight: bold;">&#40;</span> DynGroupAttr:<span style="color: #000000;">1</span> NAME <span style="color: #ff0000;">'dgIdentity'</span> DESC <span style="color: #ff0000;">'Identity to use when processing the memberURL'</span> SUP distinguishedName SINGLE-VALUE <span style="color: #7a0874; font-weight: bold;">&#41;</span>
olcAttributeTypes: <span style="color: #7a0874; font-weight: bold;">&#40;</span> DynGroupAttr:<span style="color: #000000;">2</span> NAME <span style="color: #ff0000;">'dgAuthz'</span> DESC <span style="color: #ff0000;">'Optional authorization rules that determine who is allowed to assume the dgIdentity'</span> EQUALITY authzMatch SYNTAX 1.3.6.1.4.1.4203.666.2.7 X-ORDERED <span style="color: #ff0000;">'VALUES'</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span>
olcObjectClasses: <span style="color: #7a0874; font-weight: bold;">&#40;</span> NetscapeLDAPobjectClass:<span style="color: #000000;">33</span> NAME <span style="color: #ff0000;">'groupOfURLs'</span> SUP top STRUCTURAL MUST cn MAY <span style="color: #7a0874; font-weight: bold;">&#40;</span> memberURL $ businessCategory $ description $ o $ ou $ owner $ seeAlso <span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span>
olcObjectClasses: <span style="color: #7a0874; font-weight: bold;">&#40;</span> DynGroupOC:<span style="color: #000000;">1</span> NAME <span style="color: #ff0000;">'dgIdentityAux'</span> SUP top AUXILIARY MAY <span style="color: #7a0874; font-weight: bold;">&#40;</span> dgIdentity $ dgAuthz <span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>und mit einem</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ldapadd <span style="color: #660033;">-D</span> <span style="color: #ff0000;">&quot;cn=admin,cn=config&quot;</span> <span style="color: #660033;">-x</span> <span style="color: #660033;">-W</span> <span style="color: #660033;">-f</span> dyngroup.schema.ldif</pre></div></div>

<p>hinzufügen (Administrator-Passwort wird benötigt).</li>
<li>Als nächstes folgenden Inhalt unter dem Namen dovecot.schema.ldif abspeichern

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">dn: <span style="color: #007800;">cn</span>=dovecot,<span style="color: #007800;">cn</span>=schema,<span style="color: #007800;">cn</span>=config
objectClass: olcSchemaConfig
cn: dovecot
olcAttributeTypes: <span style="color: #7a0874; font-weight: bold;">&#40;</span> 1.3.6.1.4.1.32589.1.1.1.1 NAME <span style="color: #ff0000;">'dcMailMessageStore'</span> DESC <span style="color: #ff0000;">'Path to the maildir/mbox on the mail system'</span> EQUALITY caseExactIA5Match SUBSTR caseIgnoreIA5SubstringsMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.26<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">256</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> SINGLE-VALUE <span style="color: #7a0874; font-weight: bold;">&#41;</span>
olcAttributeTypes: <span style="color: #7a0874; font-weight: bold;">&#40;</span> 1.3.6.1.4.1.32589.1.1.1.2 NAME <span style="color: #ff0000;">'dcMailAlias'</span> DESC <span style="color: #ff0000;">'Secondary (alias) mailaddresses for a user'</span> EQUALITY caseIgnoreIA5Match SUBSTR caseIgnoreIA5SubstringsMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.26<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">256</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span>
olcAttributeTypes: <span style="color: #7a0874; font-weight: bold;">&#40;</span> 1.3.6.1.4.1.32589.1.2.1.1 NAME <span style="color: #ff0000;">'dcSubMailAddress'</span> DESC <span style="color: #ff0000;">'A users secondary e-mail address for which mail from on another Mailserver has to be fetched'</span> EQUALITY caseIgnoreIA5Match SUBSTR caseIgnoreIA5SubstringsMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.26<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">256</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span>
olcAttributeTypes: <span style="color: #7a0874; font-weight: bold;">&#40;</span> 1.3.6.1.4.1.32589.1.2.1.2 NAME <span style="color: #ff0000;">'dcAccountStatus'</span> DESC <span style="color: #ff0000;">'The status of a user account: active, noaccess, disabled, deleted'</span> EQUALITY caseIgnoreIA5Match SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 SINGLE-VALUE <span style="color: #7a0874; font-weight: bold;">&#41;</span>
olcAttributeTypes: <span style="color: #7a0874; font-weight: bold;">&#40;</span> 1.3.6.1.4.1.32589.1.2.1.3 NAME <span style="color: #ff0000;">'dcSMTPServer'</span> DESC <span style="color: #ff0000;">'Outgoing mails should be delivered to this Mailserver via SMTP.'</span> EQUALITY caseIgnoreIA5Match SUBSTR caseIgnoreIA5SubstringsMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.26<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">256</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> SINGLE-VALUE <span style="color: #7a0874; font-weight: bold;">&#41;</span>
olcAttributeTypes: <span style="color: #7a0874; font-weight: bold;">&#40;</span> 1.3.6.1.4.1.32589.1.2.1.4 NAME <span style="color: #ff0000;">'dcSMTPLogin'</span> DESC <span style="color: #ff0000;">'Login credential to send Mail with the SMTP server'</span> EQUALITY caseExactIA5Match SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 SINGLE-VALUE <span style="color: #7a0874; font-weight: bold;">&#41;</span>
olcAttributeTypes: <span style="color: #7a0874; font-weight: bold;">&#40;</span> 1.3.6.1.4.1.32589.1.2.1.5 NAME <span style="color: #ff0000;">'dcSMTPPassword'</span> DESC <span style="color: #ff0000;">'A separate text that stores the SMTP account password in clear text'</span> EQUALITY caseExactIA5Match SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 SINGLE-VALUE <span style="color: #7a0874; font-weight: bold;">&#41;</span>
olcAttributeTypes: <span style="color: #7a0874; font-weight: bold;">&#40;</span> 1.3.6.1.4.1.32589.1.2.1.6 NAME <span style="color: #ff0000;">'dcRetrieveType'</span> DESC <span style="color: #ff0000;">'Tells getmail what mail account to retrieve mail from, and how to access that account, e.g. SimplePOP3Retriever and BrokenUIDLPOP3SSLRetriever'</span> EQUALITY caseIgnoreIA5Match SUBSTR caseIgnoreIA5SubstringsMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.26<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">256</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> SINGLE-VALUE <span style="color: #7a0874; font-weight: bold;">&#41;</span>
olcAttributeTypes: <span style="color: #7a0874; font-weight: bold;">&#40;</span> 1.3.6.1.4.1.32589.1.2.1.7 NAME <span style="color: #ff0000;">'dcRetrieveServer'</span> DESC <span style="color: #ff0000;">'Incoming mails have to be downloaded from this server'</span> EQUALITY caseIgnoreIA5Match SUBSTR caseIgnoreIA5SubstringsMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.26<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">256</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> SINGLE-VALUE <span style="color: #7a0874; font-weight: bold;">&#41;</span>
olcAttributeTypes: <span style="color: #7a0874; font-weight: bold;">&#40;</span> 1.3.6.1.4.1.32589.1.2.1.8 NAME <span style="color: #ff0000;">'dcRetrieveLogin'</span> DESC <span style="color: #ff0000;">'Login credential to receive Mail from the server'</span> EQUALITY caseExactIA5Match SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 SINGLE-VALUE <span style="color: #7a0874; font-weight: bold;">&#41;</span>
olcAttributeTypes: <span style="color: #7a0874; font-weight: bold;">&#40;</span> 1.3.6.1.4.1.32589.1.2.1.9 NAME <span style="color: #ff0000;">'dcRetrievePassword'</span> DESC <span style="color: #ff0000;">'Password for mail retrieval in clear text'</span> EQUALITY caseExactIA5Match SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 SINGLE-VALUE <span style="color: #7a0874; font-weight: bold;">&#41;</span>
olcAttributeTypes: <span style="color: #7a0874; font-weight: bold;">&#40;</span> 1.3.6.1.4.1.32589.1.2.1.10 NAME <span style="color: #ff0000;">'dcMailQuota'</span> DESC <span style="color: #ff0000;">'The size of space the user can have until further messages get bounced.'</span> EQUALITY integerMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 SINGLE-VALUE <span style="color: #7a0874; font-weight: bold;">&#41;</span>
olcAttributeTypes: <span style="color: #7a0874; font-weight: bold;">&#40;</span> 1.3.6.1.4.1.32589.1.2.1.11 NAME <span style="color: #ff0000;">'dcMailSizeMax'</span> DESC <span style="color: #ff0000;">'The maximum size of a single messages the user accepts.'</span> EQUALITY integerMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 SINGLE-VALUE <span style="color: #7a0874; font-weight: bold;">&#41;</span>
olcAttributeTypes: <span style="color: #7a0874; font-weight: bold;">&#40;</span> 1.3.6.1.4.1.32589.1.2.1.12 NAME <span style="color: #ff0000;">'dcMailAlternateAddress'</span> DESC <span style="color: #ff0000;">'Secondary (alias) mailaddresses for an external Mail Account'</span> EQUALITY caseIgnoreIA5Match SUBSTR caseIgnoreIA5SubstringsMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.26<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">256</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span>
olcAttributeTypes: <span style="color: #7a0874; font-weight: bold;">&#40;</span> 1.3.6.1.4.1.32589.1.3.1.1 NAME <span style="color: #ff0000;">'dcPosixOwnerURL'</span> DESC <span style="color: #ff0000;">'Identifies an URL associated with the posixOwner of the entry. Any type of labeled URL can be used.'</span> SUP labeledURI <span style="color: #7a0874; font-weight: bold;">&#41;</span>
olcObjectClasses: <span style="color: #7a0874; font-weight: bold;">&#40;</span> 1.3.6.1.4.1.32589.1.1.2.1 NAME <span style="color: #ff0000;">'dcMailUser'</span> DESC <span style="color: #ff0000;">'Dovecot-LDAP User'</span> SUP top AUXILIARY MUST dcMailMessageStore MAY dcMailAlias <span style="color: #7a0874; font-weight: bold;">&#41;</span>
olcObjectClasses: <span style="color: #7a0874; font-weight: bold;">&#40;</span> 1.3.6.1.4.1.32589.1.2.2.1 NAME <span style="color: #ff0000;">'dcExternalMailAccount'</span> DESC <span style="color: #ff0000;">'Dovecot-LDAP external mail account'</span> SUP top STRUCTURAL MUST <span style="color: #7a0874; font-weight: bold;">&#40;</span> dcSubMailAddress $ dcAccountStatus <span style="color: #7a0874; font-weight: bold;">&#41;</span> MAY <span style="color: #7a0874; font-weight: bold;">&#40;</span> dcSMTPServer $ dcSMTPLogin $ dcSMTPPassword $ dcRetrieveType $ dcRetrieveServer $ dcRetrieveLogin $ dcRetrievePassword $ dcMailQuota $ dcMailSizeMax $ dcMailAlternateAddress <span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span>
olcObjectClasses: <span style="color: #7a0874; font-weight: bold;">&#40;</span> 1.3.6.1.4.1.32589.1.3.2.1 NAME <span style="color: #ff0000;">'dcPosixSubAccount'</span> DESC <span style="color: #ff0000;">'LDAP-URL for retrieving the respective posixAccount of an entry'</span> SUP top AUXILIARY MAY dcPosixOwnerURL <span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>und ebenfalls in die Konfiguration übernehmen mit</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ldapadd <span style="color: #660033;">-D</span> <span style="color: #ff0000;">&quot;cn=admin,cn=config&quot;</span> <span style="color: #660033;">-x</span> <span style="color: #660033;">-W</span> <span style="color: #660033;">-f</span> dovecot.schema.ldif</pre></div></div>

</li>
<li>Jetzt aktivieren wir das DynList-Modul und speichern dazu Folgendes als dynlist_moduleLoad.ldif

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">dn: <span style="color: #007800;">cn</span>=module<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>,<span style="color: #007800;">cn</span>=config
changetype: modify
add: olcModuleLoad
olcModuleLoad: dynlist.so</pre></div></div>

<p>um es anschließend zur OpenLDAP-Konfiguration hinzuzufügen mit einem</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ldapmodify <span style="color: #660033;">-D</span> <span style="color: #ff0000;">&quot;cn=admin,cn=config&quot;</span> <span style="color: #660033;">-x</span> <span style="color: #660033;">-W</span> <span style="color: #660033;">-f</span> dynlist_moduleLoad.ldif</pre></div></div>

</li>
<li>Dem <a href="http://www.openldap.org/doc/admin24/overlays.html#Dynamic%20Lists">Dynlist-Overlay</a> müssen wir außerdem mitteilen, dass das Attribut dcPosixOwnerURL jeweils auf den zugehörigen Benutzer verweist. Das machen wir, indem wir den folgenden Inhalt als dynlist_activateOnSuffix.ldif abspeichern

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">dn: <span style="color: #007800;">olcOverlay</span>=dynlist,<span style="color: #007800;">olcDatabase</span>=<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>hdb,<span style="color: #007800;">cn</span>=config
objectClass: olcOverlayConfig
objectClass: olcDynamicList
olcDLattrSet: dcPosixSubAccount dcPosixOwnerURL
olcOverlay: dynlist</pre></div></div>

<p>und dann</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ldapadd <span style="color: #660033;">-D</span> <span style="color: #ff0000;">&quot;cn=admin,cn=config&quot;</span> <span style="color: #660033;">-x</span> <span style="color: #660033;">-W</span> <span style="color: #660033;">-f</span> dynlist_activateOnSuffix.ldif</pre></div></div>

<p>ausführen.</li>
<li>Nun müssen wir einen Grundeintrag in LDAP vornehmen, bevor wir starten können. Außerdem benötigen wir einen Benutzer secmail, um Mails von externen Servern in festen Intervallen abzurufen und in das jeweilige lokale IMAP-Postfach abzulegen. Daher legen wir mit der folgenden LDIF-Datei database-content.ldif zunächst den Grundeintrag und den Benutzer secmail an (Passwort wieder unbedingt mit slappasswd anpassen) an

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># effinger</span>
dn: <span style="color: #007800;">o</span>=effinger
objectclass: organization
objectclass: top
o: effinger
&nbsp;
<span style="color: #666666; font-style: italic;"># users, effinger</span>
dn: <span style="color: #007800;">ou</span>=<span style="color: #c20cb9; font-weight: bold;">users</span>,<span style="color: #007800;">o</span>=effinger
objectClass: organizationalUnit
objectClass: top
ou: <span style="color: #c20cb9; font-weight: bold;">users</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># secmail, users, effinger</span>
dn: <span style="color: #007800;">uid</span>=secmail,<span style="color: #007800;">ou</span>=<span style="color: #c20cb9; font-weight: bold;">users</span>,<span style="color: #007800;">o</span>=effinger
objectClass: posixAccount
objectClass: account
objectClass: top
cn: secmail
gidNumber: <span style="color: #000000;">134</span>
homeDirectory: <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>secmail
uid: secmail
uidNumber: <span style="color: #000000;">121</span>
<span style="color: #666666; font-style: italic;"># This password equals test</span>
userPassword: <span style="color: #7a0874; font-weight: bold;">&#123;</span>SSHA<span style="color: #7a0874; font-weight: bold;">&#125;</span>R+pQv9aIQINrPYdgljEJ0B7jzCp2cCzz</pre></div></div>

<p>und fügen sie mit einem</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ldapadd <span style="color: #660033;">-D</span> <span style="color: #ff0000;">&quot;cn=admin,o=effinger&quot;</span> <span style="color: #660033;">-x</span> <span style="color: #660033;">-W</span> <span style="color: #660033;">-f</span> database-content.ldif</pre></div></div>

<p>zum LDAP-Verzeichnis hinzu (Achtung Passwort verwenden, das für database.ldif erzeugt wurde)</li>
<li>SSL/TLS aktivieren, dazu folgenden Inhalt als ssl-tls_init.ldif abspeichern

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">dn: <span style="color: #007800;">cn</span>=config
changetype: modify
add: olcTLSCACertificateFile
olcTLSCACertificateFile: <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>ssl<span style="color: #000000; font-weight: bold;">/</span>certs<span style="color: #000000; font-weight: bold;">/</span>ca.crt
&nbsp;
dn: <span style="color: #007800;">cn</span>=config
changetype: modify
add: olcTLSCertificateFile
olcTLSCertificateFile: <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>ssl<span style="color: #000000; font-weight: bold;">/</span>certs<span style="color: #000000; font-weight: bold;">/</span>myserver.crt
&nbsp;
dn: <span style="color: #007800;">cn</span>=config
changetype: modify
add: olcTLSCertificateKeyFile
olcTLSCertificateKeyFile: <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>ssl<span style="color: #000000; font-weight: bold;">/</span>private<span style="color: #000000; font-weight: bold;">/</span>myserver.key</pre></div></div>

<p>und folgende Befehle ausführen:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ldapmodify <span style="color: #660033;">-D</span> <span style="color: #ff0000;">&quot;cn=admin,cn=config&quot;</span> <span style="color: #660033;">-x</span> <span style="color: #660033;">-W</span> <span style="color: #660033;">-f</span> ssl-tls_init.ldif
<span style="color: #c20cb9; font-weight: bold;">sudo</span> adduser openldap ssl-cert</pre></div></div>

<p>Ein Neustart ist ebenfalls erforderlich, da ich die Erfahrung gemacht habe, dass ohne einen Neustart der Zugriff über TLS nicht funktioniert.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>slapd restart</pre></div></div>

</li>
<li>Im nächsten Schritt der LDAP-Konfiguration richten wir Zugriffsrechte ein. Generell soll auf die Login-Daten bei externen Mailservern nur der jeweilige Benutzer selbst und der LDAP-Administrator lesend und schreibend zugreifen können, während der secmail Benutzer nur Leserechte benötigt. Diese Zugriffsrechte werden in der Datei add_acl.ldif mit dem Inhalt

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">dn: <span style="color: #007800;">olcDatabase</span>=<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>hdb,<span style="color: #007800;">cn</span>=config
changetype: modify
add: olcAccess
<span style="color: #666666; font-style: italic;"># The information to send and receive mails from remote servers</span>
<span style="color: #666666; font-style: italic;"># can only be modified by the user itself and the admin</span>
<span style="color: #666666; font-style: italic;"># the secmail user which will retrieve mails must have read access</span>
olcAccess: <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>to dn.regex=<span style="color: #ff0000;">&quot;.*uid=([^,]+),ou=users,o=effinger&quot;</span> <span style="color: #007800;">attrs</span>=dcRetrieveType,dcRetrieveLogin,dcRetrievePassword,dcRetrieveServer,dcSMTPLogin,dcSMTPPassword,dcSMTPServer by <span style="color: #007800;">dn</span>=<span style="color: #ff0000;">&quot;cn=admin,o=effinger&quot;</span> <span style="color: #c20cb9; font-weight: bold;">write</span> by dn.exact,<span style="color: #007800;">expand</span>=<span style="color: #ff0000;">&quot;uid=$1,ou=users,o=effinger&quot;</span> <span style="color: #c20cb9; font-weight: bold;">write</span> by <span style="color: #007800;">dn</span>=<span style="color: #ff0000;">&quot;uid=secmail,ou=users,o=effinger&quot;</span> <span style="color: #c20cb9; font-weight: bold;">read</span> by <span style="color: #000000; font-weight: bold;">*</span> none
<span style="color: #666666; font-style: italic;"># Users shall have write access to their attributes</span>
<span style="color: #666666; font-style: italic;"># admin shall have write access as well</span>
<span style="color: #666666; font-style: italic;"># all other users have only read access</span>
olcAccess: <span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>to dn.regex=<span style="color: #ff0000;">&quot;.*uid=([^,]+),ou=users,o=effinger&quot;</span> <span style="color: #007800;">attrs</span>=dcMailAlternateAddress by <span style="color: #007800;">dn</span>=<span style="color: #ff0000;">&quot;cn=admin,o=effinger&quot;</span> <span style="color: #c20cb9; font-weight: bold;">write</span> by dn.exact,<span style="color: #007800;">expand</span>=<span style="color: #ff0000;">&quot;uid=$1,ou=users,o=effinger&quot;</span> <span style="color: #c20cb9; font-weight: bold;">write</span> by <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #c20cb9; font-weight: bold;">read</span></pre></div></div>

<p>durch den Befehl</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ldapmodify <span style="color: #660033;">-D</span> <span style="color: #ff0000;">&quot;cn=admin,cn=config&quot;</span> <span style="color: #660033;">-x</span> <span style="color: #660033;">-W</span> <span style="color: #660033;">-f</span> add_acl.ldif</pre></div></div>

<p>zum LDAP-Verzeichnis hinzugefügt.</li>
<li>Im letzten Schritt indizieren wir wichtige Felder für die Suche im LDAP-Verzeichnis. Das schont Ressourcen und sorgt außerdem dafür,  dass die dezenten Hinweise von OpenLDAP in der Syslog, dass einzelne Attribute indiziert werden sollten, verschwinden. <a href="http://www.zytrax.com/books/ldap/apa/indeces.html">Was die einzelnen Indexoptionen bedeuten</a> ist auf zytrax.com erklärt. Wir legen die Datei add_attribute_indices.ldif mit dem Inhalt

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">dn: <span style="color: #007800;">olcDatabase</span>=<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>hdb,<span style="color: #007800;">cn</span>=config
changetype: modify
add: olcDbIndex
olcDbIndex: cn pres,eq,sub
olcDbIndex: sn pres,eq,sub
olcDbIndex: uid pres,eq
olcDbIndex: mail pres,eq,sub
olcDbIndex: dcMailAlias pres,eq
olcDbIndex: givenName pres,eq,sub
olcDbIndex: dcSubMailAddress pres,eq
olcDbIndex: dcMailAlternateAddress pres,eq
olcDbIndex: dcAccountStatus pres,eq</pre></div></div>

<p>an und fügen sie mit dem Befehl</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ldapmodify <span style="color: #660033;">-D</span> <span style="color: #ff0000;">&quot;cn=admin,cn=config&quot;</span> <span style="color: #660033;">-x</span> <span style="color: #660033;">-W</span> <span style="color: #660033;">-f</span> add_attribute_indices.ldif</pre></div></div>

<p>dem Verzeichnis hinzu.</li>
</ol>
<h2>Zugriff auf OpenLDAP-Server absichern</h2>
<p>Durch die Anpassung der Datei ldap.conf können wir festlegen, an welchen LDAP-Server Anfragen standardmäßig gerichtet werden sollen und unter welchen Bedingungen eine Verbindung mit diesem akzeptiert wird. Wir möchten die Konfiguration so anpassen, dass der OpenLDAP-Server ein gültiges Zertifikat vorweisen muss und standardmäßig der gerade eingerichtete LDAP-Server befragt wird. Standardmäßig werden die Anfragen zwar sowieso an den lokalen Rechner gerichtet, aber die Angabe des DNS-Namens ist notwendig, da sonst die Gültigkeitsprüfung für das Serverzertifikat fehlschlagt. In der Datei /etc/ldap/ldap.conf tragen wir folgende Zeilen ein (myserver durch den DNS-Namen ersetzen):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">URI             ldap:<span style="color: #000000; font-weight: bold;">//</span>myserver
TLS_CACERT      <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>ssl<span style="color: #000000; font-weight: bold;">/</span>certs<span style="color: #000000; font-weight: bold;">/</span>ca.crt
TLS_REQCERT     demand</pre></div></div>

<p>Ein anschließender Test mit dem Befehl</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ldapsearch <span style="color: #660033;">-x</span> <span style="color: #660033;">-b</span> <span style="color: #ff0000;">&quot;o=effinger&quot;</span> <span style="color: #660033;">-ZZ</span></pre></div></div>

<p>sollte Einträge des LDAP-Servers zurückgeben. Eigentlich wäre es auch das Beste, wenn der LDAP-Server nur TLS-verschlüsselte Verbindungen akzeptieren würde. Das kann man über <a href="http://markmail.org/message/edzras2hn2mlgim3#query:openldap%20allow%20%22tls%20only%22+page:1+mid:jgjmdhdiewzftlyw+state:results">ACL mit den Security Strength Factors (SSF)</a> einstellen, allerdings unterstützt Exim bislang keine TLS-verschlüsselten LDAP-Verbindungen, so dass wir hierauf verzichten.</p>
<h2>LDAP-Einträge hinzufügen</h2>
<p>Jetzt können wir Einträge in OpenLDAP anlegen. Sehr komfortabel kann man dazu <a href="http://www.jxplorer.org/">JXplorer</a> verwenden (zur Installation siehe Abschnitt <a href="http://www.effinger.org/blog/2008/12/14/das-kleine-openldap-1x1/">Die nächsten Schritt mit LDAP im OpenLDAP 1&#215;1</a>). Wir starten JXplorer und wählen im Menü <em>Datei&gt;Verbinden</em>. Dort tragen wir folgendes ein (localhost bzw. myserver anpassen):<br />
<a href="http://www.effinger.org/blog/wp-content/uploads/2009/01/connection.png"><img class="aligncenter size-medium wp-image-420" title="Connection Dialog from JXplorer" src="http://www.effinger.org/blog/wp-content/uploads/2009/01/connection-300x226.png" alt="Connection Dialog from JXplorer" width="300" height="226" /></a></p>
<p>Die Daten noch mal im Überblick:</p>
<ul>
<li><em>Host</em>: myserver <em>Port</em>:389 (myserver anpassen)</li>
<li><em>Base DN</em>: o=effinger (ggfs. anpassen)</li>
<li><em>Benutzer DN</em>: cn=admin,o=effinger (ggfs. anpassen)</li>
<li><em>Kennwort</em>: Das Passwort, das wir für die Datei database.ldif gewählt haben (s.o.).</li>
</ul>
<p>Nach der erfolgreichen Verbindungsherstellung sehen wir die LDAP-Hierarchie und erweitern den Baum unter o=effinger, so dass wir folgendes sehen:<br />
<a href="http://www.effinger.org/blog/wp-content/uploads/2009/01/ldap_tree.png"><img class="aligncenter size-full wp-image-425" title="LDAP Hierarchie nach dem Hinzufügen von users" src="http://www.effinger.org/blog/wp-content/uploads/2009/01/ldap_tree.png" alt="LDAP Hierarchie nach dem Hinzufügen von users" width="112" height="52" /></a></p>
<p>Im nächsten Schritt fügen wir unseren ersten Benutzer Paul hinzu. Dazu Rechtsklick auf <em>users</em> im LDAP-Baum und <em>Neu</em> auswählen. Im nachfolgenden Dialog ändern wir die <em>RDN</em> auf uid=paul und fügen die Klassen top, person, organizationalPerson, inetOrgPerson, posixAccount und dcMailUser hinzu.<br />
<a href="http://www.effinger.org/blog/wp-content/uploads/2009/01/add_user.png"><img class="aligncenter size-medium wp-image-426" title="Adding a user to the LDAP directory with JXplorer" src="http://www.effinger.org/blog/wp-content/uploads/2009/01/add_user-300x225.png" alt="Adding a user to the LDAP directory with JXplorer" width="300" height="225" /></a></p>
<p>Nun sehen wir im nächsten Dialog einige fett gedruckte Attribute &#8211; diese sind Pflichtattribute und müssen daher ausgefüllt werden.<br />
<a href="http://www.effinger.org/blog/wp-content/uploads/2009/03/add_user_attributes.png"></a><a href="http://www.effinger.org/blog/wp-content/uploads/2009/03/add_user_attributes.png"><img class="aligncenter size-medium wp-image-609" title="Adding necessary user attributes with JXplorer" src="http://www.effinger.org/blog/wp-content/uploads/2009/03/add_user_attributes-279x300.png" alt="Adding necessary user attributes with JXplorer" width="279" height="300" /></a></p>
<ul>
<li><strong>cn</strong> steht für common name und ist einfach eine Bezeichnung für den Eintrag, am einfachsten ist es, man wählt hier Vornamen und Nachnamen des Benutzers</li>
<li><strong>dcMailMessageStore </strong>gibt  das Grundverzeichnis an, in welchem die E-Mails abgelegt werden sollen. Wir werden Dovecot später so konfigurieren, dass wir dieses Verzeichnis (z.B. /home/paul/mail) um die E-Mail-Addresse ergänzen, so dass man z.B. /home/paul/mail/paul/ erhält. Letzeres wird in Dovecot das Home-Verzeichnis sein, in dem u.a. die .dovecot.sieve gespeichert wird. Die Mails werden später als Maildir im Unterverzeichnis maildir abgelegt, also /home/paul/mail/paul/maildir</li>
<li><strong>gidNumber</strong> gibt die GruppenID des Benutzers Paul an. Paul sollte bereits als Benutzer auf dem Rechner angelegt sein, so dass man über ein

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">id</span> paul</pre></div></div>

<p>die gid herausfinden kann.</li>
<li><strong>homeDirectory</strong> das Heimverzeichnis des Benutzers Paul. Den korrekten Wert kann man herausfinden durch ein

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">passwd</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> paul <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">cut</span> -d: <span style="color: #660033;">-f6</span></pre></div></div>

</li>
<li><strong>sn</strong> steht für surname, also den Nachnamen des Benutzers</li>
<li><strong>givenName</strong> steht für den Vornamen des Benutzers, ist allerdings ein optionales Attribut</li>
<li><strong>uidNumber</strong> die BenutzerID von Paul. Der korrekte Wert ist analog zur gidNumber herauszufinden &#8211; statt gid dann den Wert von uid  verwenden.</li>
<li><strong>userPassword</strong> Damit Paul sich einloggen kann, legen wir ein Passwort für ihn fest. Das Passwort sollte <em>keinen Slash</em> &#8220;/&#8221; enthalten, da in der Exim-Konfiguration dieses Zeichen zur Trennung einer zusammengesetzten Zeichenfolge aus Login und Passwort verwendet wird.</li>
<li><strong>mail</strong> Dieses Attribut steht für die lokale E-Mail-Addresse von Paul. Die lokale E-Mail-Addresse wird dabei ohne die Domain angegeben. In diesem Fall genügt also der Eintrag &#8220;paul&#8221; für die Addresse paul@myserver</li>
</ul>
<p>Danach klicken wir auf den Button <em>Abschicken</em> und Paul ist als Benutzer in LDAP verfügbar.</p>
<p>Jetzt richten wir noch den externen MailAccount von Paul ein, damit er auch seine Mails von GMX abrufen bzw. über GMX schicken kann. Dazu erweitern wir die Ansicht der LDAP-Hierarchie, so dass wir mit einem Rechtsklick auf paul erneut den Eintrag <em>Neu</em> wählen können.<br />
<a href="http://www.effinger.org/blog/wp-content/uploads/2009/01/ldap_tree2.png"><img class="aligncenter size-full wp-image-429" title="LDAP tree after adding paul as a user" src="http://www.effinger.org/blog/wp-content/uploads/2009/01/ldap_tree2.png" alt="LDAP tree after adding paul as a user" width="112" height="70" /></a><br />
Im erscheinenden Dialogfeld wählen wir die <em>Klassen</em> dcExternalMailAccount und dcPosixSubAccount aus. <em>RDN</em> setzen wir auf dcSubMailAddress=paulpanzer@gmx.de. Folgende Attribute können bzw. müssen wir eintragen:</p>
<ul>
<li><strong>dcSubMailAddress</strong> steht für die Mail-Addresse des externen Accounts. Lokale Mails an diese Addresse werden ohne den Umweg über den externen Mailprovider zugestellt.</li>
<li><strong>dcAccountStatus</strong> kann die Werte active, noaccess, disabled und deleted annehmen. Wir wählen active.</li>
<li><strong>dcMailQuota</strong> ist ein Attribut, das  wir nicht verwenden werden, allerdings könnte man hier zukünftig eine Größenbeschränkung für die paulpanzer@gmx.de-Mailbox  einrichten.</li>
<li><strong>dcMailSizeMax</strong> verwenden wir ebenfalls nicht, allerdings könnte man hier zukünftig eine Beschränkung der Größe der zu versendenden E-Mails festlegen.</li>
<li><strong>dcRetrieveType</strong> gibt den Protokoll/Typ an, mit dem die Mails abgerufen werden sollen. Beispielhafte Werte sind SimplePOP3Retriever, BrokenUIDLPOP3Retriever oder SimpleIMAPSSLRetriever. Eine detaillierte Auflistung findet sich in der <a href="http://pyropus.ca/software/getmail/configuration.html#conf-retriever">Dokumentation von getmail</a>.</li>
<li><strong>dcRetrieveLogin</strong> der Benutzername für den Mailabruf, bei GMX üblicherweise die E-Mail-Addresse</li>
<li><strong>dcRetrievePassword</strong> das zugehörige Passwort, um Mails abzurufen.</li>
<li><strong>dcRetrieveServer</strong> der Name/IP des Servers für das Abrufen von Mails. Bei GMX mit POP3 ist es pop.gmx.net.</li>
<li><strong>dcSMTPLogin</strong> der Benutzername für den SMTP-Server, bei GMX üblicherweise die E-Mail-Addresse.</li>
<li><strong>dcSMTPPassword</strong> das zugehörige Passwort, um Mails zu versenden.</li>
<li><strong>dcSMTPServer</strong> der Name/IP des SMTP-Servers. Bei GMX ist es mail.gmx.net.</li>
<li><strong>dcMailAlternateAddress</strong> steht für eventuelle Alias-Addressen der bei dcSubMailAddress angegebenen E-Mail-Addresse.  Besitzt Paul Panzer also für die Addresse paulpanzer@gmx.de noch den Alias p.panzer@gmx.de kann er die Mail hier eintragen und Mails über den lokalen Server werden direkt ohne Umwege über GMX zugestellt.</li>
<li><strong>dcPosixOwnerURL</strong> dient dazu, dass dovecot wichtige Parameter, wie uid, uidNumber,gidNumber und dcMailMessageStore vom übergeordneten Benutzereintrag von Paul bekommt. Hier tragen wir folgende <a href="http://java.sun.com/products/jndi/tutorial/ldap/misc/url.html">LDAP-URL</a> ein:

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ldap:<span style="color: #000000; font-weight: bold;">///</span><span style="color: #007800;">uid</span>=paul,<span style="color: #007800;">ou</span>=<span style="color: #c20cb9; font-weight: bold;">users</span>,<span style="color: #007800;">o</span>=effinger?uid,uidNumber,gidNumber,dcMailMessageStore?base?<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">&amp;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">objectClass</span>=posixAccount<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">objectClass</span>=dcMailUser<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

</li>
</ul>
<p>Und so sieht das bei mir aus:<br />
<a href="http://www.effinger.org/blog/wp-content/uploads/2009/03/external_mail_account.png"><img class="aligncenter size-medium wp-image-608" title="Adding an external mail account to the LDAP directory" src="http://www.effinger.org/blog/wp-content/uploads/2009/03/external_mail_account-300x294.png" alt="Adding an external mail account to the LDAP directory" width="300" height="294" /></a><br />
Nun wieder auf <em>Abschicken</em> klicken und der Eintrag sollte vorhanden sein. Wichtig ist, jetzt nochmal zu prüfen, ob auch das Dynlist-Overlay funktioniert. Das machen wir mit einem</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ldapsearch <span style="color: #660033;">-b</span> <span style="color: #ff0000;">&quot;dcSubMailAddress=paulpanzer@gmx.de,uid=paul,ou=users,o=effinger&quot;</span> <span style="color: #660033;">-x</span></pre></div></div>

<p>Dieser Befehl sollte unter anderem die Zeilen mit den Attributen uid, uidNumber,gidNumber und dcMailMessageStore augeben:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">dcMailMessageStore: <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>paul
gidNumber: <span style="color: #000000;">1000</span>
uidNumber: <span style="color: #000000;">1000</span>
uid: paul</pre></div></div>

<h2>Testen und Mitschneiden von Anfragen an OpenLDAP</h2>
<p>Zum Testen und Debuggen ist es oft hilfreich, zu überprüfen, welche LDAP Anfragen an den OpenLDAP-Server gestellt wurden. Dazu kann man unter cn=config (mit cn=admin,cn=config einloggen) den Parameter <em>olcLogLevel</em> von <em>none</em> auf einen numerischen Wert ändern. <em>256</em> hat sich für mich als gut bewährt, bei Terrence Miao findet man aber eine <a href="http://terrencemiao.com/Webmail/msg00461.html">detaillierte Auflistung der einzelnen Loglevels</a>. Die LDAP-Anfragen werden dann in die syslog geschrieben.</p>
<p>Da der Artikel nun schon ziemlich lang ist, folgt die <a href="http://www.effinger.org/blog/2009/03/22/dovecot-postfix-openldap-und-getmail-unter-ubuntu-2-dovecot/">Konfiguration von dovecot in einem zweiten Teil</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.effinger.org/blog/2009/03/22/dovecot-exim-openldap-und-getmail-unter-ubuntu-1-openldap/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
