|
| 1 | +TABLE\_SQLITE(5) - File Formats Manual |
| 2 | + |
| 3 | +# NAME |
| 4 | + |
| 5 | +**table\_sqlite** - format description for smtpd sqlite tables |
| 6 | + |
| 7 | +# DESCRIPTION |
| 8 | + |
| 9 | +This manual page documents the file format of sqlite tables used by the |
| 10 | +smtpd(8) |
| 11 | +mail daemon. |
| 12 | + |
| 13 | +The format described here applies to tables as defined in |
| 14 | +smtpd.conf(5). |
| 15 | + |
| 16 | +# SQLITE TABLE |
| 17 | + |
| 18 | +A sqlite table allows the storing of usernames, passwords, aliases, and domains |
| 19 | +in a format that is shareable across various machines that support |
| 20 | +sqlite3(1) |
| 21 | +(SQLite version 3). |
| 22 | + |
| 23 | +The table is used by |
| 24 | +smtpd(8) |
| 25 | +when authenticating a user, when user information such as user-id and/or |
| 26 | +home directory is required for a delivery, when a domain lookup may be required, |
| 27 | +and/or when looking for an alias. |
| 28 | + |
| 29 | +A sqlite table consists of one or more |
| 30 | +sqlite3(1) |
| 31 | +databases with one or more tables. |
| 32 | + |
| 33 | +If the table is used for authentication, the password should be |
| 34 | +encrypted using the |
| 35 | +crypt(3) |
| 36 | +function. Such passwords can be generated using the |
| 37 | +encrypt(1) |
| 38 | +utility or |
| 39 | +smtpctl(8) |
| 40 | +encrypt command. |
| 41 | + |
| 42 | +# SQLITE TABLE CONFIG FILE |
| 43 | + |
| 44 | +The following configuration options are available: |
| 45 | + |
| 46 | +**dbpath** |
| 47 | +*file* |
| 48 | + |
| 49 | +> This is the path to where the DB file is located. |
| 50 | +> For example: |
| 51 | +
|
| 52 | +> > dbpath /etc/mail/smtp.sqlite |
| 53 | +
|
| 54 | +**query\_alias** |
| 55 | +*SQL statement* |
| 56 | + |
| 57 | +> This is used to provide a query to look up aliases. The question mark |
| 58 | +> is replaced with the appropriate data. For alias it is the left hand side of |
| 59 | +> the SMTP address. This expects one VARCHAR to be returned with the user name |
| 60 | +> the alias resolves to. |
| 61 | +
|
| 62 | +**query\_credentials** |
| 63 | +*SQL statement* |
| 64 | + |
| 65 | +> This is used to provide a query for looking up user credentials. The question |
| 66 | +> mark is replaced with the appropriate data. For credentials it is the left |
| 67 | +> hand side of the SMTP address. The query expects that there are two VARCHARS |
| 68 | +> returned, one with a user name and one with a password in |
| 69 | +> crypt(3) |
| 70 | +> format. |
| 71 | +
|
| 72 | +**query\_domain** |
| 73 | +*SQL statement* |
| 74 | + |
| 75 | +> This is used to provide a query for looking up a domain. The question mark |
| 76 | +> is replaced with the appropriate data. For the domain it would be the |
| 77 | +> right hand side of the SMTP address. This expects one VARCHAR to be returned |
| 78 | +> with a matching domain name. |
| 79 | +
|
| 80 | +**query\_mailaddrmap** |
| 81 | +*SQL statement* |
| 82 | + |
| 83 | +> This is used to provide a query for looking up a senders. The question mark |
| 84 | +> is replaced with the appropriate data. This expects one VARCHAR to be returned |
| 85 | +> with the address the sender is allowed to send mails from. |
| 86 | +
|
| 87 | +A generic SQL statement would be something like: |
| 88 | + |
| 89 | + query_ SELECT value FROM table WHERE key=?; |
| 90 | + |
| 91 | +# EXAMPLES |
| 92 | + |
| 93 | +Example based on the OpenSMTPD FAQ: Building a Mail Server |
| 94 | +The filtering part is excluded in this example. |
| 95 | + |
| 96 | +The configuration below is for a medium-size mail server which handles |
| 97 | +multiple domains with multiple virtual users and is based on several |
| 98 | +assumptions. One is that a single system user named vmail is used for all |
| 99 | +virtual users. This user needs to be created: |
| 100 | + |
| 101 | + # useradd -g =uid -c "Virtual Mail" -d /var/vmail -s /sbin/nologin vmail |
| 102 | + # mkdir /var/vmail |
| 103 | + # chown vmail:vmail /var/vmail |
| 104 | + |
| 105 | +*sqlite schema* |
| 106 | + |
| 107 | + CREATE TABLE virtuals ( |
| 108 | + id INTEGER PRIMARY KEY AUTOINCREMENT, |
| 109 | + email VARCHAR(255) NOT NULL, |
| 110 | + destination VARCHAR(255) NOT NULL |
| 111 | + ); |
| 112 | + CREATE TABLE credentials ( |
| 113 | + id INTEGER PRIMARY KEY AUTOINCREMENT, |
| 114 | + email VARCHAR(255) NOT NULL, |
| 115 | + password VARCHAR(255) NOT NULL |
| 116 | + ); |
| 117 | + CREATE TABLE domains ( |
| 118 | + id INTEGER PRIMARY KEY AUTOINCREMENT, |
| 119 | + domain VARCHAR(255) NOT NULL |
| 120 | + ); |
| 121 | + INSERT INTO domains VALUES (1, "example.com"); |
| 122 | + INSERT INTO domains VALUES (2, "example.net"); |
| 123 | + INSERT INTO domains VALUES (3, "example.org"); |
| 124 | + |
| 125 | + INSERT INTO virtuals VALUES (1, "[email protected]", "[email protected]"); |
| 126 | + INSERT INTO virtuals VALUES (2, "[email protected]", "[email protected]"); |
| 127 | + INSERT INTO virtuals VALUES (3, "[email protected]", "[email protected]"); |
| 128 | + INSERT INTO virtuals VALUES (4, "[email protected]", "vmail"); |
| 129 | + INSERT INTO virtuals VALUES (5, "[email protected]", "[email protected]"); |
| 130 | + INSERT INTO virtuals VALUES (6, "[email protected]", "[email protected]"); |
| 131 | + INSERT INTO virtuals VALUES (7, "[email protected]", "[email protected]"); |
| 132 | + INSERT INTO virtuals VALUES (8, "[email protected]", "vmail"); |
| 133 | + |
| 134 | + INSERT INTO credentials VALUES (1, "[email protected]", "$2b$08$ANGFKBL.BnDLL0bUl7I6aumTCLRJSQluSQLuueWRG.xceworWrUIu"); |
| 135 | + INSERT INTO credentials VALUES (2, "[email protected]", "$2b$08$AkHdB37kaj2NEoTcISHSYOCEBA5vyW1RcD8H1HG.XX0P/G1KIYwii"); |
| 136 | + |
| 137 | +*/etc/mail/sqlite.conf* |
| 138 | + |
| 139 | + dbpath /etc/mail/smtp.sqlite |
| 140 | + query_alias SELECT destination FROM virtuals WHERE email=?; |
| 141 | + query_credentials SELECT email, password FROM credentials WHERE email=?; |
| 142 | + query_domain SELECT domain FROM domains WHERE domain=?; |
| 143 | + |
| 144 | +*/etc/mail/smtpd.conf* |
| 145 | + |
| 146 | + table domains sqlite:/etc/mail/sqlite.conf |
| 147 | + table virtuals sqlite:/etc/mail/sqlite.conf |
| 148 | + table credentials sqlite:/etc/mail/sqlite.conf |
| 149 | + listen on egress port 25 tls pki mail.example.com |
| 150 | + listen on egress port 587 tls-require pki mail.example.com auth <credentials> |
| 151 | + accept from any for domain <domains> virtual <virtuals> deliver to mbox |
| 152 | + |
| 153 | +# FILES |
| 154 | + |
| 155 | +*/etc/mail/sqlite.conf* |
| 156 | + |
| 157 | +> Default |
| 158 | +> table-sqlite(8) |
| 159 | +> configuration file. |
| 160 | +
|
| 161 | +*/etc/mail/smtp.sqlite* |
| 162 | + |
| 163 | +> Suggested |
| 164 | +> sqlite3(1) |
| 165 | +> database file. |
| 166 | +
|
| 167 | +# TODO |
| 168 | + |
| 169 | +Documenting the following query options: |
| 170 | + |
| 171 | + **query_netaddr** |
| 172 | + **query_userinfo** |
| 173 | + **query_source** |
| 174 | + **query_mailaddr** |
| 175 | + **query_addrname** |
| 176 | + |
| 177 | +# SEE ALSO |
| 178 | + |
| 179 | +smtpd.conf(5), |
| 180 | +smtpctl(8), |
| 181 | +smtpd(8), |
| 182 | +encrypt(1), |
| 183 | +crypt(3) |
| 184 | + |
| 185 | +Nixpkgs - July 4, 2016 |
0 commit comments