xref: /netbsd-src/external/ibm-public/postfix/dist/proto/mysql_table (revision b1c86f5f087524e68db12794ee9c3e3da1ab17a0)
1#++
2# NAME
3#	mysql_table 5
4# SUMMARY
5#	Postfix MySQL client configuration
6# SYNOPSIS
7#	\fBpostmap -q "\fIstring\fB" mysql:/etc/postfix/filename\fR
8#
9#	\fBpostmap -q - mysql:/etc/postfix/\fIfilename\fR <\fIinputfile\fR
10# DESCRIPTION
11#	The Postfix mail system uses optional tables for address
12#	rewriting or mail routing. These tables are usually in
13#	\fBdbm\fR or \fBdb\fR format.
14#
15#	Alternatively, lookup tables can be specified as MySQL databases.
16#	In order to use MySQL lookups, define a MySQL source as a lookup
17#	table in main.cf, for example:
18# .nf
19#	    alias_maps = mysql:/etc/mysql-aliases.cf
20# .fi
21#
22#	The file /etc/postfix/mysql-aliases.cf has the same format as
23#	the Postfix main.cf file, and can specify the parameters
24#	described below.
25# BACKWARDS COMPATIBILITY
26# .ad
27# .fi
28#	For compatibility with other Postfix lookup tables, MySQL
29#	parameters can also be defined in main.cf.  In order to do that,
30#	specify as MySQL source a name that doesn't begin with a slash
31#	or a dot.  The MySQL parameters will then be accessible as the
32#	name you've given the source in its definition, an underscore,
33#	and the name of the parameter.	For example, if the map is
34#	specified as "mysql:\fImysqlname\fR", the parameter "hosts"
35#	below would be defined in main.cf as "\fImysqlname\fR_hosts".
36#
37#	Note: with this form, the passwords for the MySQL sources are
38#	written in main.cf, which is normally world-readable.  Support
39#	for this form will be removed in a future Postfix version.
40#
41#	Postfix 2.2 has enhanced query interfaces for MySQL and PostgreSQL;
42#	these include features previously available only in the Postfix
43#	LDAP client. In the new interface the SQL query is specified via
44#	a single \fBquery\fR parameter (described in more detail below).
45#	When the new \fBquery\fR parameter is not specified in the map
46#	definition, Postfix reverts to the old interface, with the SQL
47#	query constructed from the \fBselect_field\fR, \fBtable\fR,
48#	\fBwhere_field\fR and \fBadditional_conditions\fR parameters.
49#	The old interface will be gradually phased out. To migrate to
50#	the new interface set:
51#
52# .nf
53#	    \fBquery\fR = SELECT [\fIselect_field\fR]
54#	        FROM [\fItable\fR]
55#	        WHERE [\fIwhere_field\fR] = '%s'
56#	            [\fIadditional_conditions\fR]
57# .fi
58#
59#	Insert the value, not the name, of each legacy parameter. Note
60#	that the \fBadditional_conditions\fR parameter is optional
61#	and if not empty, will always start with \fBAND\fR.
62# LIST MEMBERSHIP
63# .ad
64# .fi
65#	When using SQL to store lists such as $mynetworks,
66#	$mydestination, $relay_domains, $local_recipient_maps,
67#	etc., it is important to understand that the table must
68#	store each list member as a separate key. The table lookup
69#	verifies the *existence* of the key. See "Postfix lists
70#	versus tables" in the DATABASE_README document for a
71#	discussion.
72#
73#	Do NOT create tables that return the full list of domains
74#	in $mydestination or $relay_domains etc., or IP addresses
75#	in $mynetworks.
76#
77#	DO create tables with each matching item as a key and with
78#	an arbitrary value. With SQL databases it is not uncommon to
79#	return the key itself or a constant value.
80# MYSQL PARAMETERS
81# .ad
82# .fi
83# .IP "\fBhosts\fR"
84#	The hosts that Postfix will try to connect to and query from.
85#	Specify \fIunix:\fR for UNIX domain sockets, \fIinet:\fR for TCP
86#	connections (default).  Example:
87# .nf
88#	    hosts = host1.some.domain host2.some.domain
89#	    hosts = unix:/file/name
90# .fi
91#
92#	The hosts are tried in random order, with all connections over
93#	UNIX domain sockets being tried before those over TCP.	The
94#	connections are automatically closed after being idle for about
95#	1 minute, and are re-opened as necessary. Postfix versions 2.0
96#	and earlier do not randomize the host order.
97#
98#	NOTE: if you specify localhost as a hostname (even if you
99#	prefix it with \fIinet:\fR), MySQL will connect to the default
100#	UNIX domain socket.  In order to instruct MySQL to connect to
101#	localhost over TCP you have to specify
102# .nf
103#	    hosts = 127.0.0.1
104# .fi
105# .IP "\fBuser, password\fR"
106#	The user name and password to log into the mysql server.
107#	Example:
108# .nf
109#	    user = someone
110#	    password = some_password
111# .fi
112# .IP "\fBdbname\fR"
113#	The database name on the servers. Example:
114# .nf
115#	    dbname = customer_database
116# .fi
117# .IP "\fBquery\fR"
118#	The SQL query template used to search the database, where \fB%s\fR
119#	is a substitute for the address Postfix is trying to resolve,
120#	e.g.
121# .nf
122#	    query = SELECT replacement FROM aliases WHERE mailbox = '%s'
123# .fi
124#
125#	This parameter supports the following '%' expansions:
126# .RS
127# .IP "\fB\fB%%\fR\fR"
128#	This is replaced by a literal '%' character.
129# .IP "\fB\fB%s\fR\fR"
130#	This is replaced by the input key.
131#	SQL quoting is used to make sure that the input key does not
132#	add unexpected metacharacters.
133# .IP "\fB\fB%u\fR\fR"
134#	When the input key is an address of the form user@domain, \fB%u\fR
135#	is replaced by the SQL quoted local part of the address.
136#	Otherwise, \fB%u\fR is replaced by the entire search string.
137#	If the localpart is empty, the query is suppressed and returns
138#	no results.
139# .IP "\fB\fB%d\fR\fR"
140#	When the input key is an address of the form user@domain, \fB%d\fR
141#	is replaced by the SQL quoted domain part of the address.
142#	Otherwise, the query is suppressed and returns no results.
143# .IP "\fB\fB%[SUD]\fR\fR"
144#	The upper-case equivalents of the above expansions behave in the
145#	\fBquery\fR parameter identically to their lower-case counter-parts.
146#	With the \fBresult_format\fR parameter (see below), they expand the
147#	input key rather than the result value.
148# .IP "\fB\fB%[1-9]\fR\fR"
149#	The patterns %1, %2, ... %9 are replaced by the corresponding
150#	most significant component of the input key's domain. If the
151#	input key is \fIuser@mail.example.com\fR, then %1 is \fBcom\fR,
152#	%2 is \fBexample\fR and %3 is \fBmail\fR. If the input key is
153#	unqualified or does not have enough domain components to satisfy
154#	all the specified patterns, the query is suppressed and returns
155#	no results.
156# .RE
157# .IP
158#	The \fBdomain\fR parameter described below limits the input
159#	keys to addresses in matching domains. When the \fBdomain\fR
160#	parameter is non-empty, SQL queries for unqualified addresses
161#	or addresses in non-matching domains are suppressed
162#	and return no results.
163#
164#	This parameter is available with Postfix 2.2. In prior releases
165#	the SQL query was built from the separate parameters:
166#	\fBselect_field\fR, \fBtable\fR, \fBwhere_field\fR and
167#	\fBadditional_conditions\fR. The mapping from the old parameters
168#	to the equivalent query is:
169#
170# .nf
171#	    SELECT [\fBselect_field\fR]
172#	    FROM [\fBtable\fR]
173#	    WHERE [\fBwhere_field\fR] = '%s'
174#	          [\fBadditional_conditions\fR]
175# .fi
176#
177#	The '%s' in the \fBWHERE\fR clause expands to the escaped search string.
178#	With Postfix 2.2 these legacy parameters are used if the \fBquery\fR
179#	parameter is not specified.
180#
181#	NOTE: DO NOT put quotes around the query parameter.
182# .IP "\fBresult_format (default: \fB%s\fR)\fR"
183#	Format template applied to result attributes. Most commonly used
184#	to append (or prepend) text to the result. This parameter supports
185#	the following '%' expansions:
186# .RS
187# .IP "\fB\fB%%\fR\fR"
188#	This is replaced by a literal '%' character.
189# .IP "\fB\fB%s\fR\fR"
190#	This is replaced by the value of the result attribute. When
191#	result is empty it is skipped.
192# .IP "\fB%u\fR
193#	When the result attribute value is an address of the form
194#	user@domain, \fB%u\fR is replaced by the local part of the
195#	address. When the result has an empty localpart it is skipped.
196# .IP "\fB\fB%d\fR\fR"
197#	When a result attribute value is an address of the form
198#	user@domain, \fB%d\fR is replaced by the domain part of
199#	the attribute value. When the result is unqualified it
200#	is skipped.
201# .IP "\fB\fB%[SUD1-9]\fR\fB"
202#	The upper-case and decimal digit expansions interpolate
203#	the parts of the input key rather than the result. Their
204#	behavior is identical to that described with \fBquery\fR,
205#	and in fact because the input key is known in advance, queries
206#	whose key does not contain all the information specified in
207#	the result template are suppressed and return no results.
208# .RE
209# .IP
210#	For example, using "result_format = smtp:[%s]" allows one
211#	to use a mailHost attribute as the basis of a transport(5)
212#	table. After applying the result format, multiple values
213#	are concatenated as comma separated strings. The expansion_limit
214#	and parameter explained below allows one to restrict the number
215#	of values in the result, which is especially useful for maps that
216#	must return at most one value.
217#
218#	The default value \fB%s\fR specifies that each result value should
219#	be used as is.
220#
221#	This parameter is available with Postfix 2.2 and later.
222#
223#	NOTE: DO NOT put quotes around the result format!
224# .IP "\fBdomain (default: no domain list)\fR"
225#	This is a list of domain names, paths to files, or
226#	dictionaries. When specified, only fully qualified search
227#	keys with a *non-empty* localpart and a matching domain
228#	are eligible for lookup: 'user' lookups, bare domain lookups
229#	and "@domain" lookups are not performed. This can significantly
230#	reduce the query load on the MySQL server.
231# .nf
232#	    domain = postfix.org, hash:/etc/postfix/searchdomains
233# .fi
234#
235#	It is best not to use SQL to store the domains eligible
236#	for SQL lookups.
237#
238#	This parameter is available with Postfix 2.2 and later.
239#
240#	NOTE: DO NOT define this parameter for local(8) aliases,
241#	because the input keys are always unqualified.
242# .IP "\fBexpansion_limit (default: 0)\fR"
243#	A limit on the total number of result elements returned
244#	(as a comma separated list) by a lookup against the map.
245#	A setting of zero disables the limit. Lookups fail with a
246#	temporary error if the limit is exceeded.  Setting the
247#	limit to 1 ensures that lookups do not return multiple
248#	values.
249# OBSOLETE QUERY INTERFACE
250# .ad
251# .fi
252#	This section describes an interface that is deprecated as
253#	of Postfix 2.2. It is replaced by the more general \fBquery\fR
254#	interface described above.  If the \fBquery\fR parameter
255#	is defined, the legacy parameters described here ignored.
256#	Please migrate to the new interface as the legacy interface
257#	may be removed in a future release.
258#
259#	The following parameters can be used to fill in a
260#	SELECT template statement of the form:
261#
262# .nf
263#	    SELECT [\fBselect_field\fR]
264#	    FROM [\fBtable\fR]
265#	    WHERE [\fBwhere_field\fR] = '%s'
266#	          [\fBadditional_conditions\fR]
267# .fi
268#
269#	The specifier %s is replaced by the search string, and is
270#	escaped so if it contains single quotes or other odd characters,
271#	it will not cause a parse error, or worse, a security problem.
272# .IP "\fBselect_field\fR"
273#	The SQL "select" parameter. Example:
274# .nf
275#	    \fBselect_field\fR = forw_addr
276# .fi
277# .IP "\fBtable\fR"
278#	The SQL "select .. from" table name. Example:
279# .nf
280#	    \fBtable\fR = mxaliases
281# .fi
282# .IP "\fBwhere_field\fR
283#	The SQL "select .. where" parameter. Example:
284# .nf
285#	    \fBwhere_field\fR = alias
286# .fi
287# .IP "\fBadditional_conditions\fR
288#	Additional conditions to the SQL query. Example:
289# .nf
290#	    \fBadditional_conditions\fR = AND status = 'paid'
291# .fi
292# SEE ALSO
293#	postmap(1), Postfix lookup table maintenance
294#	postconf(5), configuration parameters
295#	ldap_table(5), LDAP lookup tables
296#	pgsql_table(5), PostgreSQL lookup tables
297# README FILES
298# .ad
299# .fi
300#	Use "\fBpostconf readme_directory\fR" or
301#	"\fBpostconf html_directory\fR" to locate this information.
302# .na
303# .nf
304#	DATABASE_README, Postfix lookup table overview
305#	MYSQL_README, Postfix MYSQL client guide
306# LICENSE
307# .ad
308# .fi
309#	The Secure Mailer license must be distributed with this software.
310# HISTORY
311#	MySQL support was introduced with Postfix version 1.0.
312# AUTHOR(S)
313#	Original implementation by:
314#	Scott Cotton, Joshua Marcus
315#	IC Group, Inc.
316#
317#	Further enhancements by:
318#	Liviu Daia
319#	Institute of Mathematics of the Romanian Academy
320#	P.O. BOX 1-764
321#	RO-014700 Bucharest, ROMANIA
322#--
323