1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254
|
.\"
.\" Copyright (c) 2013 Eric Faurot <eric@openbsd.org>
.\"
.\" Permission to use, copy, modify, and distribute this software for any
.\" purpose with or without fee is hereby granted, provided that the above
.\" copyright notice and this permission notice appear in all copies.
.\"
.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
.Dd $Mdocdate: July 4 2016 $
.Dt TABLE_MYSQL 5
.Os
.Sh NAME
.Nm table_mysql
.Nd format description for smtpd MySQL or MariaDB tables
.Sh DESCRIPTION
This manual page documents the file format of MySQL or MariaDB tables used
by the
.Xr smtpd 8
mail daemon.
.Pp
The format described here applies to tables as defined in
.Xr smtpd.conf 5 .
.Sh MYSQL TABLE
A mysql table allows the storing of usernames, passwords, aliases, and domains
in a format that is shareable across various machines that support
.Xr mysql 1 .
.Pp
The table is used by
.Xr smtpd 8
when authenticating a user, when user information such as user-id and/or
home directory is required for a delivery, when a domain lookup may be required,
and/or when looking for an alias.
.Pp
A MySQL table consists of one or more
.Xr mysql 1
databases with one or more tables.
.Pp
If the table is used for authentication, the password should be
encrypted using the
.Xr crypt 3
function. Such passwords can be generated using the
.Xr encrypt 1
utility or
.Xr smtpctl 8
encrypt command.
.Sh MYSQL TABLE CONFIG FILE
The following configuration options are available:
.Pp
.Bl -tag -width Ds
.It Xo
.Ic host
.Ar hostname
.Xc
This is the host running MySQL or MariaDB.
For example:
.Bd -literal -offset indent
host db.example.com
.Ed
.Pp
.It Xo
.Ic username
.Ar username
.Xc
The username required to talk to the MySQL or MariaDB database.
For example:
.Bd -literal -offset indent
username maildba
.Ed
.Pp
.It Xo
.Ic password
.Ar password
.Xc
The password required to talk to the MySQL or MariaDB database.
For example:
.Bd -literal -offset indent
password OpenSMTPDRules!
.Ed
.Pp
.It Xo
.Ic database
.Ar databse
.Xc
The name of the MySQL or MariaDB database.
For example:
.Bd -literal -offset indent
databse opensmtpdb
.Ed
.Pp
.It Xo
.Ic query_alias
.Ar SQL statement
.Xc
This is used to provide 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 one VARCHAR to be returned with the user name
the alias resolves to.
.Pp
.It Xo
.Ic query_credentials
.Ar SQL statement
.Xc
This is used to provide 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 two VARCHARS
returned, one with a user name and one with a password in
.Xr crypt 3
format.
.Pp
.It Xo
.Ic query_domain
.Ar SQL statement
.Xc
This is used to provide 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 one VARCHAR to be returned
with a matching domain name.
.Pp
.It Xo
.Ic query_mailaddrmap
.Ar SQL statement
.Xc
This is used to provide a query to look up senders. The question mark
is replaced with the appropriate data. This expects one VARCHAR to be
returned with the address the sender is allowed to send mails from.
.El
A generic SQL statement would be something like:
.Bd -literal -offset indent
query_ SELECT value FROM table WHERE key=?;
.Ed
.Sh EXAMPLES
.Ss GENERIC EXAMPLE
Example based on the OpenSMTPD FAQ: Building a Mail Server
The filtering part is excluded in this example.
The configuration below is for a medium-size mail server which handles
multiple domains with multiple virtual users and is based on several
assumptions. One is that a single system user named vmail is used for all
virtual users. This user needs to be created:
.Bd -literal
# useradd -g =uid -c "Virtual Mail" -d /var/vmail -s /sbin/nologin vmail
# mkdir /var/vmail
# chown vmail:vmail /var/vmail
.Ed
.Ic Pa MySQL schema
.Bd -literal -compact
CREATE TABLE domains (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
domain VARCHAR(255) NOT NULL DEFAULT ''
);
CREATE TABLE virtuals (
id INT AUTO_INCREMENT PRIMARY KEY,
email VARCHAR(255) NOT NULL DEFAULT '',
destination VARCHAR(255) NOT NULL DEFAULT ''
);
CREATE TABLE credentials (
id INT AUTO_INCREMENT PRIMARY KEY,
email VARCHAR(255) NOT NULL DEFAULT '',
password VARCHAR(255) NOT NULL DEFAULT ''
);
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");
.Ed
.Ic Pa /etc/mail/mysql.conf
.Bd -literal -compact
host db.example.com
username maildba
password OpenSMTPDRules!
database opensmtpdb
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=?;
.Ed
.Ic Pa /etc/mail/smtpd.conf
.Bd -literal -compact
table domains mysql:/etc/mail/mysql.conf
table virtuals mysql:/etc/mail/mysql.conf
table credentials mysql:/etc/mail/mysql.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
.Ed
.Ss MOVING FROM POSTFIX (& POSTFIXADMIN)
.Ic Pa /etc/mail/mysql.conf
.Bd -literal -compact
host db.example.com
username postfix
password PostfixOutOpenSMTPDin
database postfix
query_alias SELECT destination FROM alias WHERE email=?;
query_credentials SELECT username, password FROM mailbox WHERE username=?;
query_domain SELECT domain FROM domain WHERE domain=?;
.Ed
The rest of the config remains the same.
.Sh FILES
.Bl -tag -width "/etc/mail/mysql.conf" -compact
.It Pa /etc/mail/mysql.conf
Default
.Xr table-mysql 8
configuration file.
.El
.Sh TODO
Documenting the following query options:
.Bd -literal -offset indent -compact
.Ic query_netaddr
.Ic query_userinfo
.Ic query_source
.Ic query_mailaddr
.Ic query_addrname
.Ed
.Sh SEE ALSO
.Xr smtpd.conf 5 ,
.Xr smtpctl 8 ,
.Xr smtpd 8 ,
.Xr encrypt 1 ,
.Xr crypt 3
|