TABLE_SQLITE(5)
π TABLE_SQLITE(5) β the file formats manual page, but make it make sense π
Okay so picture this: it's TABLE_SQLITE(5), it lives in the File Formats Manual section, and it's literally the whole lore drop on how sqlite tables work inside the smtpd(8) mail daemon. Bestie, this is your group chat briefing. Let's go π«Ά
β¨ NAME β¨
table_sqlite β bestie, this is the format description for smtpd sqlite tables. No cap, that's the whole name. π
πΈ DESCRIPTION πΈ
This manual page documents the file format of sqlite tables used by the smtpd(8) mail daemon. Iconic.
The format described here applies to tables as defined in smtpd.conf(5).
π¦ SQLITE TABLE π¦
So a sqlite table lets you store usernames, passwords, aliases, and domains in a format that's shareable across various machines that support sqlite3(1) (SQLite version 3). Yes queen, portable. βοΈ
The table gets used by smtpd(8) when:
- it's authenticating a user,
- user information like the user-id and/or home directory is required for a delivery,
- a domain lookup may be required,
- and/or it's looking for an alias.
A sqlite table consists of one or more sqlite3(1) databases with one or more tables. Stack 'em, babe. π₯
β οΈ If the table is used for authentication, the password should be encrypted using thecrypt(3)function. Such passwords can be generated using theencrypt(1)utility or thesmtpctl(8)encryptcommand. Don't you dare store plaintext, I'm begging π
π SQLITE TABLE CONFIG FILE π
The following configuration options are available, periodt:
dbpathfile β this is the path to where the DB file is located. For example:
dbpath /etc/mail/smtp.sqlite
query_aliasSQL statement β this provides a query to look up aliases. The question mark is replaced with the appropriate data. For alias it is the left hand side of the SMTP address. This expects oneVARCHARto be returned with the user name the alias resolves to.query_credentialsSQL statement β this provides a query for looking up user credentials. The question mark is replaced with the appropriate data. For credentials it is the left hand side of the SMTP address. The query expects that there are twoVARCHARSreturned, one with a user name and one with a password incrypt(3)format.query_domainSQL statement β this provides a query for looking up a domain. The question mark is replaced with the appropriate data. For the domain it would be the right hand side of the SMTP address. This expects oneVARCHARto be returned with a matching domain name.query_mailaddrmapSQL statement β this provides a query for looking up a senders. The question mark is replaced with the appropriate data. This expects oneVARCHARto be returned with the address the sender is allowed to send mails from.
And a generic SQL statement would be something like this lil guy:
query_ SELECT value FROM table WHERE key=?;
π FILES π
/etc/mail/smtp.sqliteβ suggestedsqlite3(1)database file./etc/mail/sqlite.confβ defaulttable-sqlite(8)configuration file.
π₯ EXAMPLES π₯
This example is based on the OpenSMTPD FAQ: Building a Mail Server. The filtering part is excluded in this example β we're keeping it simple bestie.
The configuration below is for a medium-size mail server which handles multiple domains with multiple virtual users, and it's based on several assumptions. One of those assumptions is that a single system user named vmail is used for all virtual users. This user needs to be created:
# useradd -g =uid -c "Virtual Mail" -d /var/vmail -s /sbin/nologin vmail
# mkdir /var/vmail
# chown vmail:vmail /var/vmail
The sqlite schema is:
CREATE TABLE virtuals (
id INTEGER PRIMARY KEY AUTOINCREMENT,
email VARCHAR(255) NOT NULL,
destination VARCHAR(255) NOT NULL
);
CREATE TABLE credentials (
id INTEGER PRIMARY KEY AUTOINCREMENT,
email VARCHAR(255) NOT NULL,
password VARCHAR(255) NOT NULL
);
CREATE TABLE domains (
id INTEGER PRIMARY KEY AUTOINCREMENT,
domain VARCHAR(255) NOT NULL
);
Which can be populated as follows:
INSERT INTO domains VALUES (1, "example.com");
INSERT INTO domains VALUES (2, "example.net");
INSERT INTO domains VALUES (3, "example.org");
INSERT INTO virtuals VALUES (1, "abuse@example.com", "bob@example.com");
INSERT INTO virtuals VALUES (2, "postmaster@example.com", "bob@example.com");
INSERT INTO virtuals VALUES (3, "webmaster@example.com", "bob@example.com");
INSERT INTO virtuals VALUES (4, "bob@example.com", "vmail");
INSERT INTO virtuals VALUES (5, "abuse@example.net", "alice@example.net");
INSERT INTO virtuals VALUES (6, "postmaster@example.net", "alice@example.net");
INSERT INTO virtuals VALUES (7, "webmaster@example.net", "alice@example.net");
INSERT INTO virtuals VALUES (8, "alice@example.net", "vmail");
INSERT INTO credentials VALUES (1, "bob@example.com", "$2b$08$ANGFKBL.BnDLL0bUl7I6aumTCLRJSQluSQLuueWRG.xceworWrUIu");
INSERT INTO credentials VALUES (2, "alice@example.net", "$2b$08$AkHdB37kaj2NEoTcISHSYOCEBA5vyW1RcD8H1HG.XX0P/G1KIYwii");
The /etc/mail/sqlite.conf file then specifies the following queries:
dbpath /etc/mail/smtp.sqlite
query_alias SELECT destination FROM virtuals WHERE email=?;
query_credentials SELECT email, password FROM credentials WHERE email=?;
query_domain SELECT domain FROM domains WHERE domain=?;
And the following configuration for smtpd(8) in /etc/mail/smtpd.conf:
table domains sqlite:/etc/mail/sqlite.conf
table virtuals sqlite:/etc/mail/sqlite.conf
table credentials sqlite:/etc/mail/sqlite.conf
listen on egress port 25 tls pki mail.example.com
listen on egress port 587 tls-require pki mail.example.com auth <credentials>
accept from any for domain <domains> virtual <virtuals> deliver to mbox
π TODO π
Documenting the following query options (not me leaving these for later, I promise π):
query_netaddr
query_userinfo
query_source
query_mailaddr
query_addrname
π SEE ALSO π
encrypt(1), crypt(3), smtpd.conf(5), smtpctl(8), smtpd(8)
π HISTORY π
The first version of table_sqlite was written in 2016. It was converted to the stdio table protocol in 2024. Glow-up of the century, honestly β¨
π AUTHORS π
table_sqlite was initially written by Gilles Chehade <gilles@poolp.org>. The conversion to the stdio table protocol was done by Omar Polo <op@openbsd.org>. Respect the icons π«Ά
π§ And that's the whole page bestie! This beauty ships out of Debian, dated April 20, 2024, and its manual-page name tag says TABLE_SQLITE(5) β mwah, slay, go configure your mail server π
π
π¦ where this page comes from
- alpine 3.24: opensmtpd-table-sqlite-doc 1.0.1-r0 Β· ISC
- debian trixie: opensmtpd-table-sqlite 1.0.1-1+b1 Β· ISC
- nixos 26.05: opensmtpd-table-sqlite 1.0.1
- nixpkgs unstable: opensmtpd-table-sqlite 1.0.1
- ubuntu questing: opensmtpd-table-sqlite 1.0.1-1
- ubuntu resolute: opensmtpd-table-sqlite 1.0.1-1build1 Β· ISC
- ubuntu stonking: opensmtpd-table-sqlite 1.0.1-1build1 Β· ISC
- Copyright (c) 2014 Jason Barbier <kusuriya@serversave.us>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms