@@ -46,16 +46,14 @@ databases with one or more tables.
4646If the table is used for authentication, the password should be
4747encrypted using the
4848.Xr crypt 3
49- function. Such passwords can be generated using the
49+ function.
50+ Such passwords can be generated using the
5051.Xr encrypt 1
5152utility or
5253.Xr smtpctl 8
5354encrypt command.
54-
5555.Sh SQLITE TABLE CONFIG FILE
56-
5756The following configuration options are available:
58- .Pp
5957.Bl -tag -width Ds
6058.It Xo
6159.Ic dbpath
@@ -66,71 +64,75 @@ For example:
6664.Bd -literal -offset indent
6765dbpath /etc/mail/smtp.sqlite
6866.Ed
69- .Pp
70-
7167.It Xo
7268.Ic query_alias
7369.Ar SQL statement
7470.Xc
75- This is used to provide a query to look up aliases. The question mark
76- is replaced with the appropriate data. For alias it is the left hand side of
77- the SMTP address. This expects one VARCHAR to be returned with the user name
78- the alias resolves to.
79- .Pp
80-
71+ This is used to provide a query to look up aliases.
72+ The question mark is replaced with the appropriate data.
73+ For alias it is the left hand side of the SMTP address.
74+ This expects one VARCHAR to be returned with the user name the alias
75+ resolves to.
8176.It Xo
8277.Ic query_credentials
8378.Ar SQL statement
8479.Xc
85- This is used to provide a query for looking up user credentials. The question
86- mark is replaced with the appropriate data. For credentials it is the left
87- hand side of the SMTP address. The query expects that there are two VARCHARS
88- returned, one with a user name and one with a password in
80+ This is used to provide a query for looking up user credentials.
81+ The question mark is replaced with the appropriate data.
82+ For credentials it is the left hand side of the SMTP address.
83+ The query expects that there are two VARCHARS returned, one with a user
84+ name and one with a password in
8985.Xr crypt 3
9086format.
91- .Pp
92-
9387.It Xo
9488.Ic query_domain
9589.Ar SQL statement
9690.Xc
97- This is used to provide a query for looking up a domain. The question mark
98- is replaced with the appropriate data. For the domain it would be the
99- right hand side of the SMTP address. This expects one VARCHAR to be returned
100- with a matching domain name.
101- .Pp
102-
91+ This is used to provide a query for looking up a domain.
92+ The question mark is replaced with the appropriate data.
93+ For the domain it would be the right hand side of the SMTP address.
94+ This expects one VARCHAR to be returned with a matching domain name.
10395.It Xo
10496.Ic query_mailaddrmap
10597.Ar SQL statement
10698.Xc
107- This is used to provide a query for looking up a senders. The question mark
108- is replaced with the appropriate data. This expects one VARCHAR to be returned
109- with the address the sender is allowed to send mails from.
99+ This is used to provide a query for looking up a senders.
100+ The question mark is replaced with the appropriate data.
101+ This expects one VARCHAR to be returned with the address the sender is
102+ allowed to send mails from.
110103.El
111-
104+ . Pp
112105A generic SQL statement would be something like:
113106.Bd -literal -offset indent
114107query_ SELECT value FROM table WHERE key=?;
115108.Ed
116-
109+ .Sh FILES
110+ .Bl -tag -width " /etc/mail/sqlite.conf" -compact
111+ .It Pa /etc/mail/smtp.sqlite
112+ Suggested
113+ .Xr sqlite3 1
114+ database file.
115+ .It Pa /etc/mail/sqlite.conf
116+ Default
117+ .Xr table-sqlite 8
118+ configuration file.
119+ .El
117120.Sh EXAMPLES
118121Example based on the OpenSMTPD FAQ: Building a Mail Server
119122The filtering part is excluded in this example.
120-
121123The configuration below is for a medium-size mail server which handles
122124multiple domains with multiple virtual users and is based on several
123- assumptions. One is that a single system user named vmail is used for all
124- virtual users. This user needs to be created:
125-
126- .Bd -literal
125+ assumptions.
126+ One is that a single system user named vmail is used for all virtual users.
127+ This user needs to be created:
128+ .Bd -literal -offset indent
127129# useradd -g =uid -c "Virtual Mail" -d /var/vmail -s /sbin/nologin vmail
128130# mkdir /var/vmail
129131# chown vmail:vmail /var/vmail
130132.Ed
131-
132- . Ic Pa sqlite schema
133- .Bd -literal -compact
133+ . Pp
134+ The sqlite schema is:
135+ .Bd -literal -offset indent
134136CREATE TABLE virtuals (
135137 id INTEGER PRIMARY KEY AUTOINCREMENT,
136138 email VARCHAR(255) NOT NULL,
@@ -145,6 +147,10 @@ CREATE TABLE domains (
145147 id INTEGER PRIMARY KEY AUTOINCREMENT,
146148 domain VARCHAR(255) NOT NULL
147149);
150+ .Ed
151+ .Pp
152+ Which can be populated as follows:
153+ .Bd -literal -offset indent
148154INSERT INTO domains VALUES (1, "example.com");
149155INSERT INTO domains VALUES (2, "example.net");
150156INSERT INTO domains VALUES (3, "example.org");
161167INSERT INTO credentials VALUES (1, "
[email protected] ", "$2b$08$ANGFKBL.BnDLL0bUl7I6aumTCLRJSQluSQLuueWRG.xceworWrUIu");
162168INSERT INTO credentials VALUES (2, "
[email protected] ", "$2b$08$AkHdB37kaj2NEoTcISHSYOCEBA5vyW1RcD8H1HG.XX0P/G1KIYwii");
163169.Ed
164-
165- .Ic Pa /etc/mail/sqlite.conf
166- .Bd -literal -compact
170+ .Pp
171+ The
172+ .Pa /etc/mail/sqlite.conf
173+ file then specifies the following queries:
174+ .Bd -literal -offset indent
167175dbpath /etc/mail/smtp.sqlite
168176query_alias SELECT destination FROM virtuals WHERE email=?;
169177query_credentials SELECT email, password FROM credentials WHERE email=?;
170178query_domain SELECT domain FROM domains WHERE domain=?;
171179.Ed
172-
173- .Ic Pa /etc/mail/smtpd.conf
174- .Bd -literal -compact
180+ .Pp
181+ And the following configuration for
182+ .Xr smtpd 8
183+ in
184+ .Pa /etc/mail/smtpd.conf :
185+ .Bd -literal -offset indent
175186table domains sqlite:/etc/mail/sqlite.conf
176187table virtuals sqlite:/etc/mail/sqlite.conf
177188table credentials sqlite:/etc/mail/sqlite.conf
178189listen on egress port 25 tls pki mail.example.com
179190listen on egress port 587 tls-require pki mail.example.com auth <credentials>
180191accept from any for domain <domains> virtual <virtuals> deliver to mbox
181192.Ed
182-
183- .Sh FILES
184- .Bl -tag -width " /etc/mail/sqlite.conf" -compact
185- .It Pa /etc/mail/sqlite.conf
186- Default
187- .Xr table-sqlite 8
188- configuration file.
189- .It Pa /etc/mail/smtp.sqlite
190- Suggested
191- .Xr sqlite3 1
192- database file.
193- .El
194-
195193.Sh TODO
196194Documenting the following query options:
197195.Bd -literal -offset indent -compact
@@ -201,7 +199,6 @@ Documenting the following query options:
201199.Ic query_mailaddr
202200.Ic query_addrname
203201.Ed
204-
205202.Sh SEE ALSO
206203.Xr encrypt 1 ,
207204.Xr crypt 3 ,
0 commit comments