xref: /netbsd-src/external/ibm-public/postfix/dist/proto/mysql_table (revision 7d62b00eb9ad855ffcd7da46b41e23feb5476fac)
1#++
2# NAME
3#	mysql_table 5
4# SUMMARY
5#	Postfix MySQL client configuration
6# SYNOPSIS
7#	\fBpostmap -q "\fIstring\fB" mysql:/etc/postfix/\fIfilename\fR
8#
9#	\fBpostmap -q - mysql:/etc/postfix/\fIfilename\fB <\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/postfix/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# LIST MEMBERSHIP
26# .ad
27# .fi
28#	When using SQL to store lists such as $mynetworks,
29#	$mydestination, $relay_domains, $local_recipient_maps,
30#	etc., it is important to understand that the table must
31#	store each list member as a separate key. The table lookup
32#	verifies the *existence* of the key. See "Postfix lists
33#	versus tables" in the DATABASE_README document for a
34#	discussion.
35#
36#	Do NOT create tables that return the full list of domains
37#	in $mydestination or $relay_domains etc., or IP addresses
38#	in $mynetworks.
39#
40#	DO create tables with each matching item as a key and with
41#	an arbitrary value. With SQL databases it is not uncommon to
42#	return the key itself or a constant value.
43# MYSQL PARAMETERS
44# .ad
45# .fi
46# .IP "\fBhosts\fR"
47#	The hosts that Postfix will try to connect to and query from.
48#	Specify \fIunix:\fR for UNIX domain sockets, \fIinet:\fR for TCP
49#	connections (default).  Examples:
50# .nf
51#	    hosts = inet:host1.some.domain inet:host2.some.domain:port
52#	    hosts = host1.some.domain host2.some.domain:port
53#	    hosts = unix:/file/name
54# .fi
55#
56#	The hosts are tried in random order, with all connections over
57#	UNIX domain sockets being tried before those over TCP.	The
58#	connections are automatically closed after being idle for about
59#	1 minute, and are re-opened as necessary. Postfix versions 2.0
60#	and earlier do not randomize the host order.
61#
62#	NOTE: if you specify localhost as a hostname (even if you
63#	prefix it with \fIinet:\fR), MySQL will connect to the default
64#	UNIX domain socket.  In order to instruct MySQL to connect to
65#	localhost over TCP you have to specify
66# .nf
67#	    hosts = 127.0.0.1
68# .fi
69# .IP "\fBuser, password\fR"
70#	The user name and password to log into the mysql server.
71#	Example:
72# .nf
73#	    user = someone
74#	    password = some_password
75# .fi
76# .IP "\fBdbname\fR"
77#	The database name on the servers. Example:
78# .nf
79#	    dbname = customer_database
80# .fi
81# .IP "\fBquery\fR"
82#	The SQL query template used to search the database, where \fB%s\fR
83#	is a substitute for the address Postfix is trying to resolve,
84#	e.g.
85# .nf
86#	    query = SELECT replacement FROM aliases WHERE mailbox = '%s'
87# .fi
88#
89#	By default, every query must return a result set (instead
90#	of storing its results in a table); with "\fBrequire_result_set
91#	= no\fR" (Postfix 3.2 and later), the absence of a result
92#	set is treated as "not found".
93#
94#	This parameter supports the following '%' expansions:
95# .RS
96# .IP "\fB%%\fR"
97#	This is replaced by a literal '%' character.
98# .IP "\fB%s\fR"
99#	This is replaced by the input key.
100#	SQL quoting is used to make sure that the input key does not
101#	add unexpected metacharacters.
102# .IP "\fB%u\fR"
103#	When the input key is an address of the form user@domain, \fB%u\fR
104#	is replaced by the SQL quoted local part of the address.
105#	Otherwise, \fB%u\fR is replaced by the entire search string.
106#	If the localpart is empty, the query is suppressed and returns
107#	no results.
108# .IP "\fB%d\fR"
109#	When the input key is an address of the form user@domain, \fB%d\fR
110#	is replaced by the SQL quoted domain part of the address.
111#	Otherwise, the query is suppressed and returns no results.
112# .IP "\fB%[SUD]\fR"
113#	The upper-case equivalents of the above expansions behave in the
114#	\fBquery\fR parameter identically to their lower-case counter-parts.
115#	With the \fBresult_format\fR parameter (see below), they expand the
116#	input key rather than the result value.
117# .IP "\fB%[1-9]\fR"
118#	The patterns %1, %2, ... %9 are replaced by the corresponding
119#	most significant component of the input key's domain. If the
120#	input key is \fIuser@mail.example.com\fR, then %1 is \fBcom\fR,
121#	%2 is \fBexample\fR and %3 is \fBmail\fR. If the input key is
122#	unqualified or does not have enough domain components to satisfy
123#	all the specified patterns, the query is suppressed and returns
124#	no results.
125# .RE
126# .IP
127#	The \fBdomain\fR parameter described below limits the input
128#	keys to addresses in matching domains. When the \fBdomain\fR
129#	parameter is non-empty, SQL queries for unqualified addresses
130#	or addresses in non-matching domains are suppressed
131#	and return no results.
132#
133#	This parameter is available with Postfix 2.2. In prior releases
134#	the SQL query was built from the separate parameters:
135#	\fBselect_field\fR, \fBtable\fR, \fBwhere_field\fR and
136#	\fBadditional_conditions\fR. The mapping from the old parameters
137#	to the equivalent query is:
138#
139# .nf
140#	    SELECT [\fBselect_field\fR]
141#	    FROM [\fBtable\fR]
142#	    WHERE [\fBwhere_field\fR] = '%s'
143#	          [\fBadditional_conditions\fR]
144# .fi
145#
146#	The '%s' in the \fBWHERE\fR clause expands to the escaped search string.
147#	With Postfix 2.2 these legacy parameters are used if the \fBquery\fR
148#	parameter is not specified.
149#
150#	NOTE: DO NOT put quotes around the query parameter.
151# .IP "\fBresult_format (default: \fB%s\fR)\fR"
152#	Format template applied to result attributes. Most commonly used
153#	to append (or prepend) text to the result. This parameter supports
154#	the following '%' expansions:
155# .RS
156# .IP "\fB%%\fR"
157#	This is replaced by a literal '%' character.
158# .IP "\fB%s\fR"
159#	This is replaced by the value of the result attribute. When
160#	result is empty it is skipped.
161# .IP "\fB%u\fR
162#	When the result attribute value is an address of the form
163#	user@domain, \fB%u\fR is replaced by the local part of the
164#	address. When the result has an empty localpart it is skipped.
165# .IP "\fB%d\fR"
166#	When a result attribute value is an address of the form
167#	user@domain, \fB%d\fR is replaced by the domain part of
168#	the attribute value. When the result is unqualified it
169#	is skipped.
170# .IP "\fB%[SUD1-9]\fR"
171#	The upper-case and decimal digit expansions interpolate
172#	the parts of the input key rather than the result. Their
173#	behavior is identical to that described with \fBquery\fR,
174#	and in fact because the input key is known in advance, queries
175#	whose key does not contain all the information specified in
176#	the result template are suppressed and return no results.
177# .RE
178# .IP
179#	For example, using "result_format = smtp:[%s]" allows one
180#	to use a mailHost attribute as the basis of a transport(5)
181#	table. After applying the result format, multiple values
182#	are concatenated as comma separated strings. The expansion_limit
183#	and parameter explained below allows one to restrict the number
184#	of values in the result, which is especially useful for maps that
185#	must return at most one value.
186#
187#	The default value \fB%s\fR specifies that each result value should
188#	be used as is.
189#
190#	This parameter is available with Postfix 2.2 and later.
191#
192#	NOTE: DO NOT put quotes around the result format!
193# .IP "\fBdomain (default: no domain list)\fR"
194#	This is a list of domain names, paths to files, or "type:table"
195#	databases. When specified, only fully qualified search keys
196#	with a *non-empty* localpart and a matching domain are
197#	eligible for lookup: 'user' lookups, bare domain lookups
198#	and "@domain" lookups are not performed. This can significantly
199#	reduce the query load on the MySQL server.
200# .nf
201#	    domain = postfix.org, hash:/etc/postfix/searchdomains
202# .fi
203#
204#	It is best not to use SQL to store the domains eligible
205#	for SQL lookups.
206#
207#	This parameter is available with Postfix 2.2 and later.
208#
209#	NOTE: DO NOT define this parameter for local(8) aliases,
210#	because the input keys are always unqualified.
211# .IP "\fBexpansion_limit (default: 0)\fR"
212#	A limit on the total number of result elements returned
213#	(as a comma separated list) by a lookup against the map.
214#	A setting of zero disables the limit. Lookups fail with a
215#	temporary error if the limit is exceeded.  Setting the
216#	limit to 1 ensures that lookups do not return multiple
217#	values.
218# .IP "\fBoption_file\fR"
219#	Read options from the given file instead of the default my.cnf
220#	location. This reads options from the \fB[client]\fR option
221#	group, optionally followed by options from the group given
222#	with \fBoption_group\fR.
223# .sp
224#	This parameter is available with Postfix 2.11 and later.
225# .IP "\fBoption_group (default: Postfix >=3.2: client, <= 3.1: empty)\fR"
226#	Read options from the given group of the mysql options file,
227#	after reading options from the \fB[client]\fR group.
228# .sp
229#	Postfix 3.2 and later read \fB[client]\fR option group
230#	settings by default. To disable this specify no \fBoption_file\fR
231#	and specify "\fBoption_group =\fR" (i.e. an empty value).
232# .sp
233#	Postfix 3.1 and earlier don't read \fB[client]\fR option
234#	group settings unless a non-empty \fBoption_file\fR or
235#	\fBoption_group\fR value are specified. To enable this,
236#	specify, for example, "\fBoption_group = client\fR".
237# .sp
238#	This parameter is available with Postfix 2.11 and later.
239# .IP "\fBrequire_result_set (default: yes)\fR"
240#	If "\fByes\fR", require that every query returns a result
241#	set.  If "\fBno\fR", treat the absence of a result set as
242#	"not found".
243# .sp
244#	This parameter is available with Postfix 3.2 and later.
245# .IP "\fBtls_cert_file\fR"
246#	File containing client's X509 certificate.
247# .sp
248#	This parameter is available with Postfix 2.11 and later.
249# .IP "\fBtls_key_file\fR"
250#	File containing the private key corresponding to \fBtls_cert_file\fR.
251# .sp
252#	This parameter is available with Postfix 2.11 and later.
253# .IP "\fBtls_CAfile\fR"
254#	File containing certificates for all of the X509 Certification
255#	Authorities the client will recognize.  Takes precedence over
256#	\fBtls_CApath\fR.
257# .sp
258#	This parameter is available with Postfix 2.11 and later.
259# .IP "\fBtls_CApath\fR"
260#	Directory containing X509 Certification Authority certificates
261#	in separate individual files.
262# .sp
263#	This parameter is available with Postfix 2.11 and later.
264# .IP "\fBtls_verify_cert (default: no)\fR"
265#	Verify that the server's name matches the common name in the
266#	certificate.
267# .sp
268#	This parameter is available with Postfix 2.11 and later.
269# USING MYSQL STORED PROCEDURES
270# .ad
271# .fi
272#	Postfix 3.2 and later support calling a stored procedure
273#	instead of using a SELECT statement in the query, e.g.
274#
275# .nf
276#	    \fBquery\fR = CALL lookup('%s')
277# .fi
278#
279#	The previously described '%' expansions can be used in the
280#	parameter(s) to the stored procedure.
281#
282#	By default, every stored procedure call must return a result
283#	set, i.e. every code path must execute a SELECT statement
284#	that returns a result set (instead of storing its results
285#	in a table). With "\fBrequire_result_set = no\fR", the
286#	absence of a result set is treated as "not found".
287#
288#	A stored procedure must not return multiple result sets.
289#	That is, there must be no code path that executes multiple
290#	SELECT statements that return a result (instead of storing
291#	their results in a table).
292#
293#	The following is an example of a stored procedure returning
294#	a single result set:
295#
296# .nf
297#	CREATE [DEFINER=`user`@`host`] PROCEDURE
298#	`lookup`(IN `param` VARCHAR(255))
299#	    READS SQL DATA
300#	    SQL SECURITY INVOKER
301#	    BEGIN
302#	        select goto from alias where address=param;
303#	    END
304# .fi
305# OBSOLETE MAIN.CF PARAMETERS
306# .ad
307# .fi
308#	For compatibility with other Postfix lookup tables, MySQL
309#	parameters can also be defined in main.cf.  In order to do that,
310#	specify as MySQL source a name that doesn't begin with a slash
311#	or a dot.  The MySQL parameters will then be accessible as the
312#	name you've given the source in its definition, an underscore,
313#	and the name of the parameter.	For example, if the map is
314#	specified as "mysql:\fImysqlname\fR", the parameter "hosts"
315#	would be defined in main.cf as "\fImysqlname\fR_hosts".
316#
317#	Note: with this form, the passwords for the MySQL sources are
318#	written in main.cf, which is normally world-readable.  Support
319#	for this form will be removed in a future Postfix version.
320# OBSOLETE QUERY INTERFACE
321# .ad
322# .fi
323#	This section describes an interface that is deprecated as
324#	of Postfix 2.2. It is replaced by the more general \fBquery\fR
325#	interface described above. If the \fBquery\fR parameter
326#	is defined, the legacy parameters described here ignored.
327#	Please migrate to the new interface as the legacy interface
328#	may be removed in a future release.
329#
330#	The following parameters can be used to fill in a
331#	SELECT template statement of the form:
332#
333# .nf
334#	    SELECT [\fBselect_field\fR]
335#	    FROM [\fBtable\fR]
336#	    WHERE [\fBwhere_field\fR] = '%s'
337#	          [\fBadditional_conditions\fR]
338# .fi
339#
340#	The specifier %s is replaced by the search string, and is
341#	escaped so if it contains single quotes or other odd characters,
342#	it will not cause a parse error, or worse, a security problem.
343# .IP "\fBselect_field\fR"
344#	The SQL "select" parameter. Example:
345# .nf
346#	    \fBselect_field\fR = forw_addr
347# .fi
348# .IP "\fBtable\fR"
349#	The SQL "select .. from" table name. Example:
350# .nf
351#	    \fBtable\fR = mxaliases
352# .fi
353# .IP "\fBwhere_field\fR
354#	The SQL "select .. where" parameter. Example:
355# .nf
356#	    \fBwhere_field\fR = alias
357# .fi
358# .IP "\fBadditional_conditions\fR
359#	Additional conditions to the SQL query. Example:
360# .nf
361#	    \fBadditional_conditions\fR = AND status = 'paid'
362# .fi
363# SEE ALSO
364#	postmap(1), Postfix lookup table maintenance
365#	postconf(5), configuration parameters
366#	ldap_table(5), LDAP lookup tables
367#	pgsql_table(5), PostgreSQL lookup tables
368#	sqlite_table(5), SQLite lookup tables
369# README FILES
370# .ad
371# .fi
372#	Use "\fBpostconf readme_directory\fR" or
373#	"\fBpostconf html_directory\fR" to locate this information.
374# .na
375# .nf
376#	DATABASE_README, Postfix lookup table overview
377#	MYSQL_README, Postfix MYSQL client guide
378# LICENSE
379# .ad
380# .fi
381#	The Secure Mailer license must be distributed with this software.
382# HISTORY
383#	MySQL support was introduced with Postfix version 1.0.
384# AUTHOR(S)
385#	Original implementation by:
386#	Scott Cotton, Joshua Marcus
387#	IC Group, Inc.
388#
389#	Further enhancements by:
390#	Liviu Daia
391#	Institute of Mathematics of the Romanian Academy
392#	P.O. BOX 1-764
393#	RO-014700 Bucharest, ROMANIA
394#
395#	Stored-procedure support by John Fawcett.
396#
397#	Wietse Venema
398#	Google, Inc.
399#	111 8th Avenue
400#	New York, NY 10011, USA
401#--
402