1 P
\bPo
\bos
\bst
\btf
\bfi
\bix
\bx L
\bLo
\boo
\bok
\bku
\bup
\bp T
\bTa
\bab
\bbl
\ble
\be O
\bOv
\bve
\ber
\brv
\bvi
\bie
\bew
\bw
3 -------------------------------------------------------------------------------
5 O
\bOv
\bve
\ber
\brv
\bvi
\bie
\bew
\bw
7 This document covers the following topics:
9 * The Postfix lookup table model
10 * Postfix lists versus tables
11 * Preparing Postfix for LDAP or SQL lookups
12 * Maintaining Postfix lookup table files
13 * Updating Berkeley DB files safely
14 * Postfix lookup table types
16 T
\bTh
\bhe
\be P
\bPo
\bos
\bst
\btf
\bfi
\bix
\bx l
\blo
\boo
\bok
\bku
\bup
\bp t
\bta
\bab
\bbl
\ble
\be m
\bmo
\bod
\bde
\bel
\bl
18 Postfix uses lookup tables to store and look up information for access control,
19 address rewriting and even for content filtering. All Postfix lookup tables are
20 specified as "type:table", where "type" is one of the database types described
21 under "Postfix lookup table types" at the end of this document, and where
22 "table" is the lookup table name. The Postfix documentation uses the terms
23 "database" and "lookup table" for the same thing.
25 Examples of lookup tables that appear often in the Postfix documentation:
28 alias_maps = hash:/etc/postfix/aliases (local aliasing)
29 header_checks = regexp:/etc/postfix/header_checks (content filtering)
30 transport_maps = hash:/etc/postfix/transport (routing table)
31 virtual_alias_maps = hash:/etc/postfix/virtual (address rewriting)
33 All Postfix lookup tables store information as (key, value) pairs. This
34 interface may seem simplistic at first, but it turns out to be very powerful.
35 The (key, value) query interface completely hides the complexities of LDAP or
36 SQL from Postfix. This is a good example of connecting complex systems with
39 Benefits of the Postfix (key, value) query interface:
41 * You can implement Postfix lookup tables first with local Berkeley DB files
42 and then switch to LDAP or MySQL without any impact on the Postfix
43 configuration itself, as described under "Preparing Postfix for LDAP or SQL
45 * You can use Berkeley DB files with fixed lookup strings for simple address
46 rewriting operations and you can use regular expression tables for the more
47 complicated work. In other words, you don't have to put everything into the
50 P
\bPo
\bos
\bst
\btf
\bfi
\bix
\bx l
\bli
\bis
\bst
\bts
\bs v
\bve
\ber
\brs
\bsu
\bus
\bs t
\bta
\bab
\bbl
\ble
\bes
\bs
52 Most Postfix lookup tables are used to look up information. Examples are
53 address rewriting (the lookup string is the old address, and the result is the
54 new address) or access control (the lookup string is the client, sender or
55 recipient, and the result is an action such as "reject").
57 With some tables, however, Postfix needs to know only if the lookup key exists.
58 The lookup result itself is not used. Examples are the local_recipient_maps
59 that determine what local recipients Postfix accepts in mail from the network,
60 the mydestination parameter that specifies what domains Postfix delivers
61 locally, or the mynetworks parameter that specifies the IP addresses of trusted
62 clients or client networks. Technically, these are lists, not tables. Despite
63 the difference, Postfix lists are described here because they use the same
64 underlying infrastructure as Postfix lookup tables.
66 P
\bPr
\bre
\bep
\bpa
\bar
\bri
\bin
\bng
\bg P
\bPo
\bos
\bst
\btf
\bfi
\bix
\bx f
\bfo
\bor
\br L
\bLD
\bDA
\bAP
\bP o
\bor
\br S
\bSQ
\bQL
\bL l
\blo
\boo
\bok
\bku
\bup
\bps
\bs
68 LDAP and SQL are complex systems. Trying to set up both Postfix and LDAP or SQL
69 at the same time is definitely not a good idea. You can save yourself a lot of
70 time by implementing Postfix first with local files such as Berkeley DB. Local
71 files have few surprises, and are easy to debug with the postmap(1) command:
73 % p
\bpo
\bos
\bst
\btm
\bma
\bap
\bp -
\b-q
\bq i
\bin
\bnf
\bfo
\bo@
\b@e
\bex
\bxa
\bam
\bmp
\bpl
\ble
\be.
\b.c
\bco
\bom
\bm h
\bha
\bas
\bsh
\bh:
\b:/
\b/e
\bet
\btc
\bc/
\b/p
\bpo
\bos
\bst
\btf
\bfi
\bix
\bx/
\b/v
\bvi
\bir
\brt
\btu
\bua
\bal
\bl
75 Once you have local files working properly you can follow the instructions in
76 ldap_table(5), mysql_table(5) or pgsql_table(5) and replace local file lookups
77 with LDAP or SQL lookups. When you do this, you should use the postmap(1)
78 command again, to verify that database lookups still produce the exact same
79 results as local file lookup:
81 % p
\bpo
\bos
\bst
\btm
\bma
\bap
\bp -
\b-q
\bq i
\bin
\bnf
\bfo
\bo@
\b@e
\bex
\bxa
\bam
\bmp
\bpl
\ble
\be.
\b.c
\bco
\bom
\bm l
\bld
\bda
\bap
\bp:
\b:/
\b/e
\bet
\btc
\bc/
\b/p
\bpo
\bos
\bst
\btf
\bfi
\bix
\bx/
\b/v
\bvi
\bir
\brt
\btu
\bua
\bal
\bl.
\b.c
\bcf
\bf
83 Be sure to exercise all the partial address or parent domain queries that are
84 documented under "table search order" in the relevant manual page: access(5),
85 canonical(5), virtual(5), transport(5), or under the relevant configuration
86 parameter: mynetworks, relay_domains, parent_domain_matches_subdomains.
88 M
\bMa
\bai
\bin
\bnt
\bta
\bai
\bin
\bni
\bin
\bng
\bg P
\bPo
\bos
\bst
\btf
\bfi
\bix
\bx l
\blo
\boo
\bok
\bku
\bup
\bp t
\bta
\bab
\bbl
\ble
\be f
\bfi
\bil
\ble
\bes
\bs
90 When you make changes to a database while the mail system is running, it would
91 be desirable if Postfix avoids reading information while that information is
92 being changed. It would also be nice if you can change a database without
93 having to execute "postfix reload", in order to force Postfix to use the new
94 information. Each time you do "postfix reload" Postfix loses a lot of
97 * If you change a network database such as LDAP, NIS or SQL, there is no need
98 to execute "postfix reload". The LDAP, NIS or SQL server takes care of
99 read/write access conflicts and gives the new data to Postfix once that
102 * If you change a regexp: or pcre: file then Postfix may or may not pick up
103 the file changes immediately. This is because a Postfix process reads the
104 entire file into memory once and never examines the file again.
106 o If the file is used by a short-running process such as smtpd(8),
107 cleanup(8) or local(8), there is no need to execute "postfix reload"
108 after making a change.
110 o If the file is being used by a long-running process such as trivial-
111 rewrite(8) on a busy server it may be necessary to execute "postfix
114 * If you change a local file based database such as DBM or Berkeley DB, there
115 is no need to execute "postfix reload". Postfix uses file locking to avoid
116 read/write access conflicts, and whenever a Postfix daemon process notices
117 that a file has changed it will terminate before handling the next client
118 request, so that a new process can initialize with the new database.
120 U
\bUp
\bpd
\bda
\bat
\bti
\bin
\bng
\bg B
\bBe
\ber
\brk
\bke
\bel
\ble
\bey
\by D
\bDB
\bB f
\bfi
\bil
\ble
\bes
\bs s
\bsa
\baf
\bfe
\bel
\bly
\by
122 Although Postfix uses file locking to avoid access conflicts while updating
123 Berkeley DB or other local database files, you still have a problem when the
124 update fails because the disk is full or because something else happens. This
125 is because commands such as postmap(1) or postalias(1) overwrite existing
126 files. If the update fails in the middle then you have no usable database, and
127 Postfix will stop working. This is not an issue with the CDB database type
128 available with Postfix 2.2 and later: CDB creates a new file, and renames the
129 file upon successful completion.
131 With multi-file databases such as DBM, there is no simple solution. With
132 Berkeley DB and other "one file" databases, it is possible to add some extra
133 robustness by using "mv" to REPLACE an existing database file instead of
136 # p
\bpo
\bos
\bst
\btm
\bma
\bap
\bp a
\bac
\bcc
\bce
\bes
\bss
\bs.
\b.i
\bin
\bn &
\b&&
\b& m
\bmv
\bv a
\bac
\bcc
\bce
\bes
\bss
\bs.
\b.i
\bin
\bn.
\b.d
\bdb
\bb a
\bac
\bcc
\bce
\bes
\bss
\bs.
\b.d
\bdb
\bb
138 This converts the input file "access.in" into the output file "access.in.db",
139 and replaces the file "access.db" only when the postmap(1) command was
140 successful. Of course typing such commands becomes boring quickly, and this is
141 why people use "make" instead, as shown below. User input is shown in bold
144 # c
\bca
\bat
\bt M
\bMa
\bak
\bke
\bef
\bfi
\bil
\ble
\be
145 all: aliases.db access.db virtual.db ...etcetera...
147 # Note 1: commands are specified after a TAB character.
148 # Note 2: use postalias(1) for local aliases, postmap(1) for the rest.
149 aliases.db: aliases.in
151 mv aliases.in.db aliases.db
155 mv access.in.db access.db
157 virtual.db: virtual.in
159 mv virtual.in.db virtual.db
162 # v
\bvi
\bi a
\bac
\bcc
\bce
\bes
\bss
\bs.
\b.i
\bin
\bn
163 ...editing session not shown...
166 mv access.in.db access.db
169 The "make" command updates only the files that have changed. In case of error,
170 the "make" command will stop and will not invoke the "mv" command, so that
171 Postfix will keep using the existing database file as if nothing happened.
173 P
\bPo
\bos
\bst
\btf
\bfi
\bix
\bx l
\blo
\boo
\bok
\bku
\bup
\bp t
\bta
\bab
\bbl
\ble
\be t
\bty
\byp
\bpe
\bes
\bs
175 To find out what database types your Postfix system supports, use the "p
\bpo
\bos
\bst
\btc
\bco
\bon
\bnf
\bf
176 -
\b-m
\bm" command. Here is a list of database types that are often supported:
179 A sorted, balanced tree structure. This is available only on systems
180 with support for Berkeley DB databases. Database files are created with
181 the postmap(1) or postalias(1) command. The lookup table name as used
182 in "btree:table" is the database file name without the ".db" suffix.
184 A read-optimized structure with no support for incremental updates.
185 Database files are created with the postmap(1) or postalias(1) command.
186 The lookup table name as used in "cdb:table" is the database file name
187 without the ".cdb" suffix. This feature is available with Postfix 2.2
190 A table that associates values with Classless Inter-Domain Routing
191 (CIDR) patterns. The table format is described in cidr_table(5).
193 An indexed file type based on hashing. This is available only on
194 systems with support for DBM databases. Database files are created with
195 the postmap(1) or postalias(1) command. The lookup table name as used
196 in "dbm:table" is the database file name without the ".dir" or ".pag"
198 e
\ben
\bnv
\bvi
\bir
\bro
\bon
\bn
199 The UNIX process environment array. The lookup key is the variable
200 name. The lookup table name in "environ:table" is ignored.
202 An indexed file type based on hashing. This is available only on
203 systems with support for Berkeley DB databases. Database files are
204 created with the postmap(1) or postalias(1) command. The database name
205 as used in "hash:table" is the database file name without the ".db"
207 l
\bld
\bda
\bap
\bp (read-only)
208 Perform lookups using the LDAP protocol. Configuration details are
209 given in the ldap_table(5).
210 m
\bmy
\bys
\bsq
\bql
\bl (read-only)
211 Perform MySQL database lookups. Configuration details are given in
213 n
\bne
\bet
\bti
\bin
\bnf
\bfo
\bo (read-only)
214 Perform Netinfo database lookups.
215 n
\bni
\bis
\bs (read-only)
216 Perform NIS database lookups.
217 n
\bni
\bis
\bsp
\bpl
\blu
\bus
\bs (read-only)
218 Perform NIS+ database lookups. Configuration details are given in
220 p
\bpc
\bcr
\bre
\be (read-only)
221 A lookup table based on Perl Compatible Regular Expressions. The file
222 format is described in pcre_table(5). The lookup table name as used in
223 "pcre:table" is the name of the regular expression file.
224 p
\bpg
\bgs
\bsq
\bql
\bl (read-only)
225 Perform PostgreSQL database lookups. Configuration details are given in
227 p
\bpr
\bro
\box
\bxy
\by (read-only)
228 Access information via the Postfix proxymap(8) service. The lookup
229 table name syntax is "proxy:type:table".
230 r
\bre
\beg
\bge
\bex
\bxp
\bp (read-only)
231 A lookup table based on regular expressions. The file format is
232 described in regexp_table(5). The lookup table name as used in "regexp:
233 table" is the name of the regular expression file.
235 An indexed file type based on hashing. This is available only on
236 systems with support for SDBM databases. Database files are created
237 with the postmap(1) or postalias(1) command. The lookup table name as
238 used in "sdbm:table" is the database file name without the ".dir" or
240 s
\bst
\bta
\bat
\bti
\bic
\bc (read-only)
241 Always returns its lookup table name as lookup result. For example, the
242 lookup table "static:foobar" always returns the string "foobar" as
245 Access information through a TCP/IP server. The protocol is described
246 in tcp_table(5). The lookup table name is "tcp:host:port" where "host"
247 specifies a symbolic hostname or a numeric IP address, and "port"
248 specifies a symbolic service name or a numeric port number. This
249 protocol is not available in the stable Postfix release.
250 u
\bun
\bni
\bix
\bx (read-only)
251 A limited way to query the UNIX authentication database. The following
252 tables are implemented:
253 u
\bun
\bni
\bix
\bx:
\b:p
\bpa
\bas
\bss
\bsw
\bwd
\bd.
\b.b
\bby
\byn
\bna
\bam
\bme
\be
254 The table is the UNIX password database. The key is a login name.
255 The result is a password file entry in passwd(5) format.
256 u
\bun
\bni
\bix
\bx:
\b:g
\bgr
\bro
\bou
\bup
\bp.
\b.b
\bby
\byn
\bna
\bam
\bme
\be
257 The table is the UNIX group database. The key is a group name. The
258 result is a group file entry in group(5) format.
260 Other lookup table types may be available depending on how Postfix was built.
261 With some Postfix distributions the list is dynamically extensible as support
262 for lookup tables is dynamically linked into Postfix.