Postfix SQLite lookup table




Oft braucht man für Postfix Konfigurationen für virtuelle Accounts. Die übliche Methode hierfür ist z.B. die Konfiguration mit MySQL zu machen. In vielen Fällen rentiert es sich aber nicht gleich einen MySQL Server aufzusetzen.



Vor kurzem brauchte ich ein Backend für Postfix, welches wenig Speicher verbraucht und ich per Webinterface einfach verwalten kann. Per Webinterface ein lookup table in Form eine Datei zu editieren und danach ein postmap aufzurufen, macht nicht wirklich spass. Aus diesem Grund kam für mich eigentlich nur SQLite in Frage.

Allerdings kann Postfix aktuell keine lookup tables in SQLite Datenbank, deswegen habe ich diese selber eingebaut. Der Patch für Postfix 2.3.3 ist unter http://www.treibsand.com/static/files/postfix-2.3.3_sqlite.patch verfügbar.

Sobald Postfix mit SQLite gebaut ist, sollte man eine Datenbank anlegen, die z.B. wie folgt aufgebaut ist: In der Datei main.cf kann wie folgt auf die lookup table zugegriffen werden: Jede Config Datei für SQLite muss 2 Anweisungen enthalten:
  • dbpath - Pfad zur SQLite Datenbank
  • query - SQL Query
Eine Config Datei kann z.B. wie folgt aussehen:

18. Oktober, 2006

Kommentare


Michael Scheidell wrote:
> thanks, I took a quick swab at it (without the VDA patch) and it seems to be running on FBSD 5.5 right now.

> would you be willing to add the sqlite3 lookup patch? (I seriously doubt Wieste will do anything directly that he didn't think of ;0)
>
> http://www.treibsand.com/2006/10/18/p...
>

ps, preliminary tests with patch look like it applies cleanly
(minor edit on his patch to take out leading path as per ports specs)
a couple tweaks to port makefile (to support WITH_SQLITE3) and it works, however, there is something missing in the original patch.

I will contact author:

postmap: inet_addr_local: configured 3 IPv4 addresses
postmap: cfg_get_str: /var/amavis/etc/postfix/relay_users.rc: dbpath = /var/amavis/db/mail.db
postmap: cfg_get_str: /var/amavis/etc/postfix/relay_users.rc: result_format = %s
postmap: cfg_get_str: /var/amavis/etc/postfix/relay_users.rc: query = select "OK" from users where email = '%s'
postmap: cfg_get_str: /var/amavis/etc/postfix/relay_users.rc: domain =
postmap: dict_open: sqlite:/var/amavis/etc/postfix/relay_users.rc
postmap: dict_sqlite_lookup: /var/amavis/etc/postfix/relay_users.rc: Searching with quåery select "OK" from users where email = 'scheidell@secnap.net'
scheidell@secnap.net
postmap: sqlite: dict_sqlite_close

(should have returned 'OK', not 'scheidell@secnap.net')



(sqlite3 was compiled without threads. even adding -lpthreads to postfix makefile didn't patch it, don't know why)
must be something missing, don't work on sqlite patches:

postmap: cfg_get_str: /var/amavis/etc/postfix/transport.rc: domain =
postmap: dict_open: sqlite:/var/amavis/etc/postfix/transport.rc
postmap: dict_sqlite_lookup: /var/amavis/etc/postfix/transport.rc: Searching with query SELECT transport FROM transport WHERE domain='secnap.net'
http://secnap.net
postmap: sqlite: dict_sqlite_close


(it seems to return the LHS, not the RHS)

doesn't seem to be anything wrong with sqlite: I will look at these patches sometime next week.

Thanks !!!

echo "SELECT transport FROM transport WHERE domain='secnap.net';" | sqlite3 /var/amavis/db/mail.db

smtp:10.70.1.3

4. April, 2007, von anonymous

Ich habe Postfix compiliert und bekomme nun nurnoch fatal: unsupported dictionary type: sqlite

Hab ich irgendwas falsch gemacht?

3. Dezember, 2007, von Manu

Dann wurden wahrscheinlich die Source nicht richtig gepatcht. Welche Version von Postfix hast du verwendet? Mit der aktuellen Version hab ich es noch nicht getestet.

20. Dezember, 2007, von Toast

Ich habe die Sourcen(2.3.13) gepatcht und kompiliert. (Mit "CCARGS=-DHAS_SQLITE -I/usr/include" "AUXLIBS=-L/usr/lib -lsqlite3")

Danach ein make upgrade. postconf -m zeigt sqlite als Option an. Die main.cf ist korrekt und die .cf Dateien ebenfalls. (dbpath = /etc/postfix/email.db \\ query = bla bla bla).

Aber sobald eine Email rein kommt landet folgende Meldung im Log:

trivial-rewrite: fatal: Can´t open database: unable to open database file?

Hat jemand eine Idee?

MfG

28. Januar, 2008, von RN

Schalte mal den rewirte Service in der master.cf auf verbose...
rewrite unix - - n - - trivial-rewrite -v
dann hast du eine genauere Ausgabe. Evtl. stimmen die Permissions der DB nicht.

6. Februar, 2008, von Toast

Werde ich versuchen. Die Fehlermeldung stammt jedenfalls direkt aus dict_sqlite.c Sind denn wenigstens die Kompilierungs-Argumente richtig gewählt? (CCARGS usw.)
Hast Du es schon zum Laufen bekommen? Falls Interesse an einem Austausch besteht, ich bin unter seminick (at) gmx (dot) de erreichbar.

8. Februar, 2008, von R N

Die Argumente sind richtig. Zum laufen hab ich es auch schon bekommen, der Patch ist ja von mir :-)
Ich schreibe grad aber an einem neuen, fuer die aktuelle Version von Postfix...kann aber noch ein wenig dauern.

9. Februar, 2008, von Toast

Klar, der Patch ist von Dir. Ist mir auch (endlich) aufgefallen. :-D Peinlich. Ist der "neue" Patch dann für die 2.5er Version?

10. Februar, 2008, von RN

Ja. Ich hoffe, dass ich in bis zum Wochenende fertig hab...

11. Februar, 2008, von Toast

 

Kommentar hinzufügen