1ff6d749dStron#++ 2ff6d749dStron# NAME 3ff6d749dStron# sqlite_table 5 4ff6d749dStron# SUMMARY 5ff6d749dStron# Postfix SQLite configuration 6ff6d749dStron# SYNOPSIS 716d67a18Stron# \fBpostmap -q "\fIstring\fB" sqlite:/etc/postfix/\fIfilename\fR 8ff6d749dStron# 916d67a18Stron# \fBpostmap -q - sqlite:/etc/postfix/\fIfilename\fB <\fIinputfile\fR 10ff6d749dStron# DESCRIPTION 11ff6d749dStron# The Postfix mail system uses optional tables for address 12ff6d749dStron# rewriting or mail routing. These tables are usually in 13ff6d749dStron# \fBdbm\fR or \fBdb\fR format. 14ff6d749dStron# 15ff6d749dStron# Alternatively, lookup tables can be specified as SQLite databases. 16ff6d749dStron# In order to use SQLite lookups, define an SQLite source as a lookup 17ff6d749dStron# table in main.cf, for example: 18ff6d749dStron# .nf 19*4a672054Schristos# alias_maps = sqlite:/etc/postfix/sqlite-aliases.cf 20ff6d749dStron# .fi 21ff6d749dStron# 22ff6d749dStron# The file /etc/postfix/sqlite-aliases.cf has the same format as 23ff6d749dStron# the Postfix main.cf file, and can specify the parameters 24ff6d749dStron# described below. 25ff6d749dStron# LIST MEMBERSHIP 26ff6d749dStron# .ad 27ff6d749dStron# .fi 28ff6d749dStron# When using SQL to store lists such as $mynetworks, 29ff6d749dStron# $mydestination, $relay_domains, $local_recipient_maps, 30ff6d749dStron# etc., it is important to understand that the table must 31ff6d749dStron# store each list member as a separate key. The table lookup 32ff6d749dStron# verifies the *existence* of the key. See "Postfix lists 33ff6d749dStron# versus tables" in the DATABASE_README document for a 34ff6d749dStron# discussion. 35ff6d749dStron# 36ff6d749dStron# Do NOT create tables that return the full list of domains 37ff6d749dStron# in $mydestination or $relay_domains etc., or IP addresses 38ff6d749dStron# in $mynetworks. 39ff6d749dStron# 40ff6d749dStron# DO create tables with each matching item as a key and with 41ff6d749dStron# an arbitrary value. With SQL databases it is not uncommon to 42ff6d749dStron# return the key itself or a constant value. 43ff6d749dStron# SQLITE PARAMETERS 44ff6d749dStron# .ad 45ff6d749dStron# .fi 46ff6d749dStron# .IP "\fBdbpath\fR" 47ff6d749dStron# The SQLite database file location. Example: 48ff6d749dStron# .nf 49ff6d749dStron# dbpath = customer_database 50ff6d749dStron# .fi 51ff6d749dStron# .IP "\fBquery\fR" 52ff6d749dStron# The SQL query template used to search the database, where \fB%s\fR 53ff6d749dStron# is a substitute for the address Postfix is trying to resolve, 54ff6d749dStron# e.g. 55ff6d749dStron# .nf 56ff6d749dStron# query = SELECT replacement FROM aliases WHERE mailbox = '%s' 57ff6d749dStron# .fi 58ff6d749dStron# 59ff6d749dStron# This parameter supports the following '%' expansions: 60ff6d749dStron# .RS 61e262b48eSchristos# .IP "\fB%%\fR" 62ff6d749dStron# This is replaced by a literal '%' character. 63e262b48eSchristos# .IP "\fB%s\fR" 64ff6d749dStron# This is replaced by the input key. 65ff6d749dStron# SQL quoting is used to make sure that the input key does not 66ff6d749dStron# add unexpected metacharacters. 67e262b48eSchristos# .IP "\fB%u\fR" 68ff6d749dStron# When the input key is an address of the form user@domain, \fB%u\fR 69ff6d749dStron# is replaced by the SQL quoted local part of the address. 70ff6d749dStron# Otherwise, \fB%u\fR is replaced by the entire search string. 71ff6d749dStron# If the localpart is empty, the query is suppressed and returns 72ff6d749dStron# no results. 73e262b48eSchristos# .IP "\fB%d\fR" 74ff6d749dStron# When the input key is an address of the form user@domain, \fB%d\fR 75ff6d749dStron# is replaced by the SQL quoted domain part of the address. 76ff6d749dStron# Otherwise, the query is suppressed and returns no results. 77e262b48eSchristos# .IP "\fB%[SUD]\fR" 78ff6d749dStron# The upper-case equivalents of the above expansions behave in the 79ff6d749dStron# \fBquery\fR parameter identically to their lower-case counter-parts. 80ff6d749dStron# With the \fBresult_format\fR parameter (see below), they expand the 81ff6d749dStron# input key rather than the result value. 82e262b48eSchristos# .IP "\fB%[1-9]\fR" 83ff6d749dStron# The patterns %1, %2, ... %9 are replaced by the corresponding 84ff6d749dStron# most significant component of the input key's domain. If the 85ff6d749dStron# input key is \fIuser@mail.example.com\fR, then %1 is \fBcom\fR, 86ff6d749dStron# %2 is \fBexample\fR and %3 is \fBmail\fR. If the input key is 87ff6d749dStron# unqualified or does not have enough domain components to satisfy 88ff6d749dStron# all the specified patterns, the query is suppressed and returns 89ff6d749dStron# no results. 90ff6d749dStron# .RE 91ff6d749dStron# .IP 92ff6d749dStron# The \fBdomain\fR parameter described below limits the input 93ff6d749dStron# keys to addresses in matching domains. When the \fBdomain\fR 94ff6d749dStron# parameter is non-empty, SQL queries for unqualified addresses 95ff6d749dStron# or addresses in non-matching domains are suppressed 96ff6d749dStron# and return no results. 97ff6d749dStron# 98ff6d749dStron# This parameter is available with Postfix 2.2. In prior releases 99ff6d749dStron# the SQL query was built from the separate parameters: 100ff6d749dStron# \fBselect_field\fR, \fBtable\fR, \fBwhere_field\fR and 101ff6d749dStron# \fBadditional_conditions\fR. The mapping from the old parameters 102ff6d749dStron# to the equivalent query is: 103ff6d749dStron# 104ff6d749dStron# .nf 105ff6d749dStron# SELECT [\fBselect_field\fR] 106ff6d749dStron# FROM [\fBtable\fR] 107ff6d749dStron# WHERE [\fBwhere_field\fR] = '%s' 108ff6d749dStron# [\fBadditional_conditions\fR] 109ff6d749dStron# .fi 110ff6d749dStron# 111ff6d749dStron# The '%s' in the \fBWHERE\fR clause expands to the escaped search string. 112ff6d749dStron# With Postfix 2.2 these legacy parameters are used if the \fBquery\fR 113ff6d749dStron# parameter is not specified. 114ff6d749dStron# 115ff6d749dStron# NOTE: DO NOT put quotes around the query parameter. 116ff6d749dStron# .IP "\fBresult_format (default: \fB%s\fR)\fR" 117ff6d749dStron# Format template applied to result attributes. Most commonly used 118ff6d749dStron# to append (or prepend) text to the result. This parameter supports 119ff6d749dStron# the following '%' expansions: 120ff6d749dStron# .RS 121e262b48eSchristos# .IP "\fB%%\fR" 122ff6d749dStron# This is replaced by a literal '%' character. 123e262b48eSchristos# .IP "\fB%s\fR" 124ff6d749dStron# This is replaced by the value of the result attribute. When 125ff6d749dStron# result is empty it is skipped. 126ff6d749dStron# .IP "\fB%u\fR 127ff6d749dStron# When the result attribute value is an address of the form 128ff6d749dStron# user@domain, \fB%u\fR is replaced by the local part of the 129ff6d749dStron# address. When the result has an empty localpart it is skipped. 130e262b48eSchristos# .IP "\fB%d\fR" 131ff6d749dStron# When a result attribute value is an address of the form 132ff6d749dStron# user@domain, \fB%d\fR is replaced by the domain part of 133ff6d749dStron# the attribute value. When the result is unqualified it 134ff6d749dStron# is skipped. 135e262b48eSchristos# .IP "\fB%[SUD1-9]\fR" 136ff6d749dStron# The upper-case and decimal digit expansions interpolate 137ff6d749dStron# the parts of the input key rather than the result. Their 138ff6d749dStron# behavior is identical to that described with \fBquery\fR, 139ff6d749dStron# and in fact because the input key is known in advance, queries 140ff6d749dStron# whose key does not contain all the information specified in 141ff6d749dStron# the result template are suppressed and return no results. 142ff6d749dStron# .RE 143ff6d749dStron# .IP 144ff6d749dStron# For example, using "result_format = smtp:[%s]" allows one 145ff6d749dStron# to use a mailHost attribute as the basis of a transport(5) 146ff6d749dStron# table. After applying the result format, multiple values 147ff6d749dStron# are concatenated as comma separated strings. The expansion_limit 148ff6d749dStron# and parameter explained below allows one to restrict the number 149ff6d749dStron# of values in the result, which is especially useful for maps that 150ff6d749dStron# must return at most one value. 151ff6d749dStron# 152ff6d749dStron# The default value \fB%s\fR specifies that each result value should 153ff6d749dStron# be used as is. 154ff6d749dStron# 155ff6d749dStron# This parameter is available with Postfix 2.2 and later. 156ff6d749dStron# 157ff6d749dStron# NOTE: DO NOT put quotes around the result format! 158ff6d749dStron# .IP "\fBdomain (default: no domain list)\fR" 159*4a672054Schristos# This is a list of domain names, paths to files, or "type:table" 160*4a672054Schristos# databases. When specified, only fully qualified search 161ff6d749dStron# keys with a *non-empty* localpart and a matching domain 162ff6d749dStron# are eligible for lookup: 'user' lookups, bare domain lookups 163ff6d749dStron# and "@domain" lookups are not performed. This can significantly 164ff6d749dStron# reduce the query load on the SQLite server. 165ff6d749dStron# .nf 166ff6d749dStron# domain = postfix.org, hash:/etc/postfix/searchdomains 167ff6d749dStron# .fi 168ff6d749dStron# 169ff6d749dStron# It is best not to use SQL to store the domains eligible 170ff6d749dStron# for SQL lookups. 171ff6d749dStron# 172ff6d749dStron# This parameter is available with Postfix 2.2 and later. 173ff6d749dStron# 174ff6d749dStron# NOTE: DO NOT define this parameter for local(8) aliases, 175ff6d749dStron# because the input keys are always unqualified. 176ff6d749dStron# .IP "\fBexpansion_limit (default: 0)\fR" 177ff6d749dStron# A limit on the total number of result elements returned 178ff6d749dStron# (as a comma separated list) by a lookup against the map. 179ff6d749dStron# A setting of zero disables the limit. Lookups fail with a 180ff6d749dStron# temporary error if the limit is exceeded. Setting the 181ff6d749dStron# limit to 1 ensures that lookups do not return multiple 182ff6d749dStron# values. 183f3bc92a4Schristos# OBSOLETE MAIN.CF PARAMETERS 184f3bc92a4Schristos# .ad 185f3bc92a4Schristos# .fi 186f3bc92a4Schristos# For compatibility with other Postfix lookup tables, SQLite 187f3bc92a4Schristos# parameters can also be defined in main.cf. In order to do that, 188f3bc92a4Schristos# specify as SQLite source a name that doesn't begin with a slash 189f3bc92a4Schristos# or a dot. The SQLite parameters will then be accessible as the 190f3bc92a4Schristos# name you've given the source in its definition, an underscore, 191f3bc92a4Schristos# and the name of the parameter. For example, if the map is 192f3bc92a4Schristos# specified as "sqlite:\fIsqlitename\fR", the parameter "query" 193f3bc92a4Schristos# would be defined in main.cf as "\fIsqlitename\fR_query". 194ff6d749dStron# OBSOLETE QUERY INTERFACE 195ff6d749dStron# .ad 196ff6d749dStron# .fi 197ff6d749dStron# This section describes an interface that is deprecated as 198ff6d749dStron# of Postfix 2.2. It is replaced by the more general \fBquery\fR 199ff6d749dStron# interface described above. If the \fBquery\fR parameter 200ff6d749dStron# is defined, the legacy parameters described here ignored. 201ff6d749dStron# Please migrate to the new interface as the legacy interface 202ff6d749dStron# may be removed in a future release. 203ff6d749dStron# 204ff6d749dStron# The following parameters can be used to fill in a 205ff6d749dStron# SELECT template statement of the form: 206ff6d749dStron# 207ff6d749dStron# .nf 208ff6d749dStron# SELECT [\fBselect_field\fR] 209ff6d749dStron# FROM [\fBtable\fR] 210ff6d749dStron# WHERE [\fBwhere_field\fR] = '%s' 211ff6d749dStron# [\fBadditional_conditions\fR] 212ff6d749dStron# .fi 213ff6d749dStron# 214ff6d749dStron# The specifier %s is replaced by the search string, and is 215ff6d749dStron# escaped so if it contains single quotes or other odd characters, 216ff6d749dStron# it will not cause a parse error, or worse, a security problem. 217ff6d749dStron# .IP "\fBselect_field\fR" 218ff6d749dStron# The SQL "select" parameter. Example: 219ff6d749dStron# .nf 220ff6d749dStron# \fBselect_field\fR = forw_addr 221ff6d749dStron# .fi 222ff6d749dStron# .IP "\fBtable\fR" 223ff6d749dStron# The SQL "select .. from" table name. Example: 224ff6d749dStron# .nf 225ff6d749dStron# \fBtable\fR = mxaliases 226ff6d749dStron# .fi 227ff6d749dStron# .IP "\fBwhere_field\fR 228ff6d749dStron# The SQL "select .. where" parameter. Example: 229ff6d749dStron# .nf 230ff6d749dStron# \fBwhere_field\fR = alias 231ff6d749dStron# .fi 232ff6d749dStron# .IP "\fBadditional_conditions\fR 233ff6d749dStron# Additional conditions to the SQL query. Example: 234ff6d749dStron# .nf 235ff6d749dStron# \fBadditional_conditions\fR = AND status = 'paid' 236ff6d749dStron# .fi 237ff6d749dStron# SEE ALSO 238ff6d749dStron# postmap(1), Postfix lookup table maintenance 239ff6d749dStron# postconf(5), configuration parameters 240ff6d749dStron# ldap_table(5), LDAP lookup tables 241ff6d749dStron# mysql_table(5), MySQL lookup tables 242ff6d749dStron# pgsql_table(5), PostgreSQL lookup tables 243ff6d749dStron# README FILES 244ff6d749dStron# .ad 245ff6d749dStron# .fi 246ff6d749dStron# Use "\fBpostconf readme_directory\fR" or 247ff6d749dStron# "\fBpostconf html_directory\fR" to locate this information. 248ff6d749dStron# .na 249ff6d749dStron# .nf 250ff6d749dStron# DATABASE_README, Postfix lookup table overview 251ff6d749dStron# SQLITE_README, Postfix SQLITE howto 252ff6d749dStron# LICENSE 253ff6d749dStron# .ad 254ff6d749dStron# .fi 255ff6d749dStron# The Secure Mailer license must be distributed with this software. 256ff6d749dStron# HISTORY 257ff6d749dStron# SQLite support was introduced with Postfix version 2.8. 258ff6d749dStron# AUTHOR(S) 259ff6d749dStron# Original implementation by: 260ff6d749dStron# Axel Steiner 261ff6d749dStron#-- 262