An implementation of the sendmail socketmap protocol to allow an SQL database
Project description
A socketmap script for interfacing with an SQL database.
Why?
I have a number of FreeBSD servers, with one intended to act as my primary mailserver (the current one and remaining one becoming secondary mailservers). The problem is that I’m using Postfix, and trying very hard to stick to precompiled packages rather than using ports, and Postfix on FreeBSD lacks bindings to databases. In my case, I wanted to be able to use an SQL database.
Configuration format
Configuration files are INI files containing two types of section.
First is the [database] section, which gives database connection details. The driver field specifies the driver to use; if omitted, its value defaults to sqlite3. The remaining fields are passed to the driver’s connect() function.
[database] driver = sqlite3 database = /path/to/sqlite.db
Other sections start with table:, and denote virtual tables to be queried. There are two fields: transform (optional) and query (required).
The transform field gives the name of a transformation to apply to the query parameter before its use in the query the query. The default is to accept the parameter as-is (all). Other values can be a reference to a Python function in the form ‘module:function’, local for just the local part, domain for the domain part of the address, and split breaks an email address in two. It must return a list or tuple giving the postitional arguments to use in the query.
The query field give an SQL query to be used to generate the synthetic table. Use placeholders as specified by the database driver’s documentation.
Usage
Run with:
socketmap-sql --config /path/to/config.ini
If you don’t provide the –config flag, it defaults to /etc/socketmap-sql.ini.
Postfix
This script is intended to be executed by Postfix’s spawn mechanism, meaning it reads its input and writes its output to stdin and stdout respectively.
Assuming you’ve installed the script in /usr/local/libexec, add the following to master.cf:
sockmapd unix - - n - 1 spawn user=nobody argv=/usr/local/libexec/socketmap-sql
Compatibility
The script only works on Python 3.8+.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file socketmap-sql-0.2.0.tar.gz
.
File metadata
- Download URL: socketmap-sql-0.2.0.tar.gz
- Upload date:
- Size: 6.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.28.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f7a43e1d8aabdbbc1ce6eb62575bdfe7880bc3f4dd03b6666aacff7ba089898f |
|
MD5 | 4097d3d63afca71b97a54d54ec186af6 |
|
BLAKE2b-256 | d8b826b189e746f2a35faaba6da68b54c39fbbca65d510423284e35d07aa3ebd |
File details
Details for the file socketmap_sql-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: socketmap_sql-0.2.0-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.28.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b5dbe015b3c67665e3d4bfeb8b41a624f78aecfdafba756b474132fd68d6daeb |
|
MD5 | a438e4bab1d76a2622daaa38fd2c4ce0 |
|
BLAKE2b-256 | bfe0a7369337b402e555a7310144703af3295c3e91ad14446de02315746c85b5 |