diff --git a/postfix/.indent.pro b/postfix/.indent.pro index 42fe93c4d..f84368058 100644 --- a/postfix/.indent.pro +++ b/postfix/.indent.pro @@ -32,6 +32,8 @@ -TDELIVER_ATTR -TDELIVER_REQUEST -TDICT +-TDICT_CDBM +-TDICT_CDBQ -TDICT_CIDR -TDICT_CIDR_ENTRY -TDICT_DB diff --git a/postfix/HISTORY b/postfix/HISTORY index 5b207bc8e..45fbc2d84 100644 --- a/postfix/HISTORY +++ b/postfix/HISTORY @@ -9889,6 +9889,11 @@ Apologies for any names omitted. client sends a message header instead of an SMTP command. Magnus Baeck. File: smtpd/smtpd.c. +20041207 + + CDB support by Michael Tokarev, documentation by Victor + Duchovni. Files: util/dict_cdb.[hc], global/mkmap_cdb.c. + Open problems: Med: implement ${name[?:]value} in main.cf or update the diff --git a/postfix/README_FILES/AAAREADME b/postfix/README_FILES/AAAREADME index 19cc9a485..1496a490d 100644 --- a/postfix/README_FILES/AAAREADME +++ b/postfix/README_FILES/AAAREADME @@ -38,6 +38,7 @@ LLooookkuupp ttaabblleess ((ddaattaabbaasseess)) * DATABASE_README: Lookup table overview * DB_README: Berkeley DB Howto + * CDB_README: CDB Howto * LDAP_README: LDAP Howto * MYSQL_README: MySQL Howto * PCRE_README: PCRE Howto diff --git a/postfix/README_FILES/CDB_README b/postfix/README_FILES/CDB_README new file mode 100644 index 000000000..7d0e36b12 --- /dev/null +++ b/postfix/README_FILES/CDB_README @@ -0,0 +1,58 @@ +PPoossttffiixx CCDDBB HHoowwttoo + +------------------------------------------------------------------------------- + +IInnttrroodduuccttiioonn + +CDB (Constant DataBase) is an indexed file format designed by Daniel Bernstein. +CDB is optimized exclusively for read access and guarantees that each record +will be read in at most two disk accesses. This is achieved by forgoing support +for incremental updates: no single-record inserts or deletes are supported. CDB +databases can be modified only by rebuilding them completely from scratch, +hence the "constant" qualifier in the name. + +Postfix CDB databases are specified as "cdb:name", where name specifies the CDB +file name without the ".cdb" suffix (another suffix, ".tmp", is used +temporarily while a CDB file is under construction). CDB databases are +maintained with the postmap(1) or postalias(1) command. The DATABASE_README +document has general information about Postfix databases. + +CDB support is available with Postfix 2.2 and later releases. This document +describes how to build Postfix with CDB support. + +BBuuiillddiinngg PPoossttffiixx wwiitthh CCDDBB + +Postfix is compatible with two CDB implementations: + + * The original cdb library from Daniel Bernstein, available from http:// + cr.yp.to/cdb.html, and + + * tinycdb (version 0.5 and later) from Michael Tokarev, available from http:/ + /www.corpit.ru/mjt/tinycdb.html. + +Tinycdb is preferred, since it is a bit faster, has additional useful +functionality and is much simpler to use. + +To build Postfix after you have installed CDB, use something like: + + % make tidy + % CDB=../../../tinycdb-0.5 + % make -f Makefile.init makefiles "CCARGS=-DHAS_CDB -I$CDB" \ + "AUXLIBS=$CDB/libcdb.a" + % make + + for tinycdb, or alternatively, for the D.J.B. version: + + % make tidy + % CDB=../../../cdb-0.75 + % make -f Makefile.init makefiles "CCARGS=-DHAS_CDB -I$CDB" \ + "AUXLIBS=$CDB/cdb.a $CDB/alloc.a $CDB/buffer.a $CDB/unix.a $CDB/byte.a" + % make + +After postfix has been built with cdb support, you can use "cdb" tables +wherever you can use read-only "hash", "btree" or "dbm" tables. However, the +"ppoossttmmaapp --ii" (incremental record insertion) and "ppoossttmmaapp --dd" (incremental +record deletion) command-line options are not available. For the same reason +the "cdb" map type cannot be used to store the volatile address verification +cache for the verify(8) service. + diff --git a/postfix/README_FILES/DATABASE_README b/postfix/README_FILES/DATABASE_README index 5d1fb8b9c..a18c87989 100644 --- a/postfix/README_FILES/DATABASE_README +++ b/postfix/README_FILES/DATABASE_README @@ -123,7 +123,8 @@ Berkeley DB or other local database files, you still have a problem when the update fails because the disk is full or because something else happens. This is because commands such as postmap(1) or postalias(1) overwrite existing files. If the update fails in the middle then you have no usable database, and -Postfix will stop working. +Postfix will stop working. This is not an issue with the CDB database type +available with Postfix 2.2 and later, because CDB database rebuilds are atomic. With multi-file databases such as DBM, there is no simple solution. With Berkeley DB and other "one file" databases, it is possible to add some extra @@ -169,14 +170,20 @@ Postfix will keep using the existing database file as if nothing happened. PPoossttffiixx llooookkuupp ttaabbllee ttyyppeess -To find out what database types your Postfix system supports, use the "postconf --m" command. Here is a list of database types that are often supported: +To find out what database types your Postfix system supports, use the "ppoossttccoonnff +--mm" command. Here is a list of database types that are often supported: bbttrreeee A sorted, balanced tree structure. This is available only on systems with support for Berkeley DB databases. Database files are created with the postmap(1) or postalias(1) command. The lookup table name as used in "btree:table" is the database file name without the ".db" suffix. + ccddbb + A read-optimized structure with no support for incremental updates. + Database files are created with the postmap(1) or postalias(1) command. + The lookup table name as used in "cdb:table" is the database file name + without the ".cdb" suffix. This feature is available with Postfix 2.2 + and later. cciiddrr A table that associates values with Classless Inter-Domain Routing (CIDR) patterns. The table format is described in cidr_table(5). diff --git a/postfix/README_FILES/STANDARD_CONFIGURATION_README b/postfix/README_FILES/STANDARD_CONFIGURATION_README index cdb343426..b1ca2920e 100644 --- a/postfix/README_FILES/STANDARD_CONFIGURATION_README +++ b/postfix/README_FILES/STANDARD_CONFIGURATION_README @@ -33,7 +33,7 @@ Postfix should work out of the box without change on a stand-alone machine that has direct Internet access. At least, that is how Postfix installs when you download the Postfix source code via http://www.postfix.org/. -You can use the command "postconf -n" to find out what settings are overruled +You can use the command "ppoossttccoonnff --nn" to find out what settings are overruled by your main.cf. Besides a few pathname settings, few parameters should be set on a stand-alone box, beyond what is covered in the BASIC_CONFIGURATION_README document: @@ -174,9 +174,9 @@ to her preferred machine: jane: jane@janes.preferred.machine On some systems the alias database is not in /etc/aliases. To find out the -location for your system, execute the command "postconf alias_maps". +location for your system, execute the command "ppoossttccoonnff aalliiaass__mmaappss". -Execute the command "newaliases" whenever you change the aliases file. +Execute the command "nneewwaalliiaasseess" whenever you change the aliases file. PPoossttffiixx eemmaaiill ffiirreewwaallll//ggaatteewwaayy @@ -187,7 +187,7 @@ example.com", the firewall normally also accepts mail for "anything.example.com". That would not be right. Note: this example requires Postfix version 2.0 and later. To find out what -Postfix version you have, execute the command "postconf mail_version". +Postfix version you have, execute the command "ppoossttccoonnff mmaaiill__vveerrssiioonn". The solution is presented in multiple parts. This first part gets rid of local mail delivery on the firewall, making the firewall harder to break. @@ -268,13 +268,13 @@ Translation: * Lines 10, 17-18: Route mail for "example.com" to the inside gateway machine. The [] forces Postfix to do no MX lookup. -Specify dbm instead of hash if your system uses dbm files instead of db. To -find out what lookup tables Postfix supports, use the command "postconf -m". +Specify ddbbmm instead of hhaasshh if your system uses ddbbmm files instead of ddbb files. +To find out what lookup tables Postfix supports, use the command "ppoossttccoonnff --mm". -Execute the command "postmap /etc/postfix/relay_recipients" whenever you change +Execute the command "ppoossttmmaapp //eettcc//ppoossttffiixx//rreellaayy__rreecciippiieennttss" whenever you change the relay_recipients table. -Execute the command "postmap /etc/postfix/transport" whenever you change the +Execute the command "ppoossttmmaapp //eettcc//ppoossttffiixx//ttrraannssppoorrtt" whenever you change the transport table. DDeelliivveerriinngg ssoommee bbuutt nnoott aallll aaccccoouunnttss llooccaallllyy @@ -324,7 +324,7 @@ mail to the gateway host, and to send intranet mail directly. That's what Wietse does at work. Note: this example requires Postfix version 2.0 and later. To find out what -Postfix version you have, execute the command "postconf mail_version". +Postfix version you have, execute the command "ppoossttccoonnff mmaaiill__vveerrssiioonn". The following example presents additional configuration. You need to combine this with basic configuration information as discussed the first half of this @@ -356,10 +356,10 @@ Translation: is turned off. Postfix tries to deliver mail directly, and gives undeliverable mail to a gateway. -Specify dbm instead of hash if your system uses dbm files instead of db. To -find out what lookup tables Postfix supports, use the command "postconf -m". +Specify ddbbmm instead of hhaasshh if your system uses ddbbmm files instead of ddbb files. +To find out what lookup tables Postfix supports, use the command "ppoossttccoonnff --mm". -Execute the command "postmap /etc/postfix/transport" whenever you edit the +Execute the command "ppoossttmmaapp //eettcc//ppoossttffiixx//ttrraannssppoorrtt" whenever you edit the transport table. CCoonnffiigguurriinngg PPoossttffiixx aass MMXX hhoosstt ffoorr aa rreemmoottee ssiittee @@ -418,10 +418,10 @@ Important notes: * Line 22: The [] forces Postfix to do no MX lookup. -Specify dbm instead of hash if your system uses dbm files instead of db files. -To find out what lookup tables Postfix supports, use the command "postconf -m". +Specify ddbbmm instead of hhaasshh if your system uses ddbbmm files instead of ddbb files. +To find out what lookup tables Postfix supports, use the command "ppoossttccoonnff --mm". -Execute the command "postmap /etc/postfix/transport" whenever you change the +Execute the command "ppoossttmmaapp //eettcc//ppoossttffiixx//ttrraannssppoorrtt" whenever you change the transport table. PPoossttffiixx oonn aa ddiiaalluupp mmaacchhiinnee @@ -467,7 +467,7 @@ should also study the section on "Postfix on hosts without a real hostname". /usr/sbin/sendmail -q (whenever the Internet link is up) The exact location of the sendmail command is system-specific. Use the - command "postconf sendmail_path" to find out where the Postfix sendmail + command "ppoossttccoonnff sseennddmmaaiill__ppaatthh" to find out where the Postfix sendmail command is located on your machine. In order to find out if the mail queue is flushed, use something like: @@ -487,7 +487,7 @@ should also study the section on "Postfix on hosts without a real hostname". done If you have disabled spontaneous SMTP mail delivery, you also need to run - the "sendmail -q" command every now and then while the dialup link is up, + the "sseennddmmaaiill --qq" command every now and then while the dialup link is up, so that newly-posted mail is flushed from the queue. PPoossttffiixx oonn hhoossttss wwiitthhoouutt aa rreeaall hhoossttnnaammee diff --git a/postfix/RELEASE_NOTES b/postfix/RELEASE_NOTES index 784c0de8a..0c6b2bf41 100644 --- a/postfix/RELEASE_NOTES +++ b/postfix/RELEASE_NOTES @@ -7,6 +7,13 @@ snapshot release). Patches are issued for the official release and change the patchlevel and the release date. Patches are never issued for snapshot releases. +Major changes with snapshot Postfix-2.2-20041208 +================================================ + +Support for CDB databases by Michael Tokarev. This supports both +Michael's tinycdb and Daniel Bernstein's cdb implementations, but +neither of the two implementations is bundled with Postfix. + Incompatible changes with snapshot Postfix-2.2-20041118 ======================================================= diff --git a/postfix/conf/access b/postfix/conf/access index f8569dc7c..dd10ffd97 100644 --- a/postfix/conf/access +++ b/postfix/conf/access @@ -23,7 +23,7 @@ # that serves as input to the postmap(1) command. The # result, an indexed file in dbm or db format, is used for # fast searching by the mail system. Execute the command -# postmap /etc/postfix/access in order to rebuild the +# "postmap /etc/postfix/access" in order to rebuild the # indexed file after changing the access table. # # When the table is provided via other means such as NIS, @@ -286,8 +286,8 @@ # The following example uses an indexed file, so that the # order of table entries does not matter. The example per- # mits access by the client at address 1.2.3.4 but rejects -# all other clients in 1.2.3.0/24. Instead of "hash" lookup -# tables, some systems use "dbm". Use the command "postconf +# all other clients in 1.2.3.0/24. Instead of hash lookup +# tables, some systems use dbm. Use the command "postconf # -m" to find out what lookup tables Postfix supports on # your system. # diff --git a/postfix/html/CDB_README.html b/postfix/html/CDB_README.html new file mode 100644 index 000000000..4506251d9 --- /dev/null +++ b/postfix/html/CDB_README.html @@ -0,0 +1,84 @@ + + + + + + +Postfix CDB Howto + + + + + + + +

Postfix CDB Howto

+ +
+ +

Introduction

+ +

CDB (Constant DataBase) is an indexed file format designed by +Daniel Bernstein. CDB is optimized exclusively for read access +and guarantees that each record will be read in at most two disk +accesses. This is achieved by forgoing support for incremental +updates: no single-record inserts or deletes are supported. CDB +databases can be modified only by rebuilding them completely from +scratch, hence the "constant" qualifier in the name.

+ +

Postfix CDB databases are specified as "cdb:name", where +name specifies the CDB file name without the ".cdb" suffix +(another suffix, ".tmp", is used temporarily while a CDB file is +under construction). CDB databases are maintained with the postmap(1) +or postalias(1) command. The DATABASE_README document has general +information about Postfix databases.

+ +

CDB support is available with Postfix 2.2 and later releases. +This document describes how to build Postfix with CDB support.

+ +

Building Postfix with CDB

+ +

Postfix is compatible with two CDB implementations:

+ + + +

Tinycdb is preferred, since it is a bit faster, has additional +useful functionality and is much simpler to use.

+ +

To build Postfix after you have installed CDB, use something +like:

+ +
+
+% make tidy
+% CDB=../../../tinycdb-0.5
+% make -f Makefile.init makefiles "CCARGS=-DHAS_CDB -I$CDB" \
+    "AUXLIBS=$CDB/libcdb.a"
+% make
+
+for tinycdb, or alternatively, for the D.J.B. version:
+
+% make tidy
+% CDB=../../../cdb-0.75
+% make -f Makefile.init makefiles "CCARGS=-DHAS_CDB -I$CDB" \
+    "AUXLIBS=$CDB/cdb.a $CDB/alloc.a $CDB/buffer.a $CDB/unix.a $CDB/byte.a"
+% make
+
+
+ +

After postfix has been built with cdb support, you can use +"cdb" tables wherever you can use read-only "hash", "btree" or +"dbm" tables. However, the "postmap -i" (incremental record +insertion) and "postmap -d" (incremental record deletion) +command-line options are not available. For the same reason the +"cdb" map type cannot be used to store the volatile address +verification cache for the verify(8) service.

diff --git a/postfix/html/DATABASE_README.html b/postfix/html/DATABASE_README.html index 09f93d7e7..42dbdabd1 100644 --- a/postfix/html/DATABASE_README.html +++ b/postfix/html/DATABASE_README.html @@ -188,7 +188,9 @@ have a problem when the update fails because the disk is full or because something else happens. This is because commands such as postmap(1) or postalias(1) overwrite existing files. If the update fails in the middle then you have no usable database, and Postfix -will stop working.

+will stop working. This is not an issue with the CDB database type +available with Postfix 2.2 and later, because CDB +database rebuilds are atomic.

With multi-file databases such as DBM, there is no simple solution. With Berkeley DB and other "one file" databases, it is @@ -244,7 +246,7 @@ database file as if nothing happened.

Postfix lookup table types

To find out what database types your Postfix system supports, -use the "postconf -m" command. Here is a list of database types +use the "postconf -m" command. Here is a list of database types that are often supported:

@@ -259,6 +261,14 @@ created with the postmap(1) or +
cdb
+ +
A read-optimized structure with no support for incremental updates. +Database files are created with the postmap(1) or postalias(1) command. +The lookup table name as used in "cdb:table" is the database file name +without the ".cdb" suffix. This feature is available with Postfix 2.2 +and later.
+
cidr
A table that associates values with Classless Inter-Domain diff --git a/postfix/html/RESTRICTION_CLASS_README.html b/postfix/html/RESTRICTION_CLASS_README.html index 836ca79c8..857ef431c 100644 --- a/postfix/html/RESTRICTION_CLASS_README.html +++ b/postfix/html/RESTRICTION_CLASS_README.html @@ -110,7 +110,7 @@ to IP spoofing.

-

Specify dbm instead of hash if your system uses +

Specify dbm instead of hash if your system uses dbm files instead of db files. To find out what map types Postfix supports, use the command postconf -m.

@@ -209,7 +209,7 @@ with LDAP or SQL.

-

Specify dbm instead of hash if your system uses +

Specify dbm instead of hash if your system uses dbm files instead of db files. To find out what map types Postfix supports, use the command postconf -m.

diff --git a/postfix/html/STANDARD_CONFIGURATION_README.html b/postfix/html/STANDARD_CONFIGURATION_README.html index 2e100cd35..ac6caa60c 100644 --- a/postfix/html/STANDARD_CONFIGURATION_README.html +++ b/postfix/html/STANDARD_CONFIGURATION_README.html @@ -67,10 +67,10 @@ machine that has direct Internet access. At least, that is how Postfix installs when you download the Postfix source code via http://www.postfix.org/.

-

You can use the command "postconf -n" to find out what settings -are overruled by your main.cf. Besides a few pathname settings, -few parameters should be set on a stand-alone box, beyond what is -covered in the BASIC_CONFIGURATION_README document:

+

You can use the command "postconf -n" to find out what +settings are overruled by your main.cf. Besides a few pathname +settings, few parameters should be set on a stand-alone box, beyond +what is covered in the BASIC_CONFIGURATION_README document:

@@ -253,11 +253,11 @@ forwards mail to her preferred machine: 

On some systems the alias database is not in /etc/aliases. To -find out the location for your system, execute the command "postconf -alias_maps".

+find out the location for your system, execute the command "postconf +alias_maps".

-

Execute the command "newaliases" whenever you change the aliases -file.

+

Execute the command "newaliases" whenever you change +the aliases file.

Postfix email firewall/gateway

@@ -269,8 +269,8 @@ accepts mail for "anything.example.com". That would not be right.

Note: this example requires Postfix version 2.0 and later. To find -out what Postfix version you have, execute the command "postconf -mail_version".

+out what Postfix version you have, execute the command "postconf +mail_version".

The solution is presented in multiple parts. This first part gets rid of local mail delivery on the firewall, making the firewall @@ -381,14 +381,14 @@ gateway machine. The [] forces Postfix to do no MX lookup. -

Specify dbm instead of hash if your system uses -dbm files instead of db. To find out what lookup tables -Postfix supports, use the command "postconf -m".

+

Specify dbm instead of hash if your system uses +dbm files instead of db files. To find out what lookup +tables Postfix supports, use the command "postconf -m".

-

Execute the command "postmap /etc/postfix/relay_recipients" +

Execute the command "postmap /etc/postfix/relay_recipients" whenever you change the relay_recipients table.

-

Execute the command "postmap /etc/postfix/transport" +

Execute the command "postmap /etc/postfix/transport" whenever you change the transport table.

Delivering some but not all accounts @@ -449,8 +449,8 @@ mail to the gateway host, and to send intranet mail directly. That's what Wietse does at work.

Note: this example requires Postfix version 2.0 and later. To find -out what Postfix version you have, execute the command "postconf -mail_version".

+out what Postfix version you have, execute the command "postconf +mail_version".

The following example presents additional configuration. You need to combine this with basic configuration information as @@ -492,11 +492,11 @@ directly, and gives undeliverable mail to a gateway.

-

Specify dbm instead of hash if your system uses dbm files -instead of db. To find out what lookup tables Postfix supports, use -the command "postconf -m".

+

Specify dbm instead of hash if your system uses +dbm files instead of db files. To find out what lookup +tables Postfix supports, use the command "postconf -m".

-

Execute the command "postmap /etc/postfix/transport" whenever +

Execute the command "postmap /etc/postfix/transport" whenever you edit the transport table.

Configuring Postfix as MX host for a remote site

@@ -573,11 +573,11 @@ table.

-

Specify dbm instead of hash if your system uses dbm files -instead of db files. To find out what lookup tables Postfix supports, -use the command "postconf -m".

+

Specify dbm instead of hash if your system uses +dbm files instead of db files. To find out what lookup +tables Postfix supports, use the command "postconf -m".

-

Execute the command "postmap /etc/postfix/transport" whenever +

Execute the command "postmap /etc/postfix/transport" whenever you change the transport table.

Postfix on a dialup machine

@@ -640,7 +640,7 @@ calls from being placed, disable spontaneous SMTP mail deliveries.

The exact location of the sendmail command is system-specific. -Use the command "postconf sendmail_path" to find out where the +Use the command "postconf sendmail_path" to find out where the Postfix sendmail command is located on your machine.

In order to find out if the mail queue is flushed, use something @@ -663,7 +663,7 @@ done

If you have disabled spontaneous -SMTP mail delivery, you also need to run the "sendmail -q" +SMTP mail delivery, you also need to run the "sendmail -q" command every now and then while the dialup link is up, so that newly-posted mail is flushed from the queue.

diff --git a/postfix/html/UUCP_README.html b/postfix/html/UUCP_README.html index 70dca6c9b..0a8a69d98 100644 --- a/postfix/html/UUCP_README.html +++ b/postfix/html/UUCP_README.html @@ -122,7 +122,7 @@ whenever you change the transport file.

transport_maps = hash:/etc/postfix/transport -

Specify dbm instead of hash if your system uses +

Specify dbm instead of hash if your system uses dbm files instead of db files. To find out what map types Postfix supports, use the command "postconf -m".

diff --git a/postfix/html/access.5.html b/postfix/html/access.5.html index 610397949..96e15a7f7 100644 --- a/postfix/html/access.5.html +++ b/postfix/html/access.5.html @@ -29,7 +29,7 @@ ACCESS(5) ACCESS(5) that serves as input to the postmap(1) command. The result, an indexed file in dbm or db format, is used for fast searching by the mail system. Execute the command - postmap /etc/postfix/access in order to rebuild the + "postmap /etc/postfix/access" in order to rebuild the indexed file after changing the access table. When the table is provided via other means such as NIS, @@ -292,8 +292,8 @@ ACCESS(5) ACCESS(5) The following example uses an indexed file, so that the order of table entries does not matter. The example per- mits access by the client at address 1.2.3.4 but rejects - all other clients in 1.2.3.0/24. Instead of "hash" lookup - tables, some systems use "dbm". Use the command "postconf + all other clients in 1.2.3.0/24. Instead of hash lookup + tables, some systems use dbm. Use the command "postconf -m" to find out what lookup tables Postfix supports on your system. diff --git a/postfix/html/index.html b/postfix/html/index.html index d371c2c78..61fe3ba8e 100644 --- a/postfix/html/index.html +++ b/postfix/html/index.html @@ -109,6 +109,8 @@ Per-client/user/etc. access
  • Berkeley DB Howto +
  • CDB Howto +
  • LDAP Howto
  • MySQL Howto diff --git a/postfix/html/postalias.1.html b/postfix/html/postalias.1.html index 90b821025..44e04e3be 100644 --- a/postfix/html/postalias.1.html +++ b/postfix/html/postalias.1.html @@ -103,9 +103,9 @@ POSTALIAS(1) POSTALIAS(1) file_type The database type. To find out what types are sup- - ported, use the "postconf -m" command. + ported, use the "postconf -m" command. - The postalias command can query any supported file + The postalias command can query any supported file type, but it can create only the following file types: @@ -122,9 +122,6 @@ POSTALIAS(1) POSTALIAS(1) file_name.db. This is available only on systems with support for db databases. - Use the command postconf -m to find out what types - of database your Postfix installation can support. - When no file_type is specified, the software uses the database type specified via the default_database_type configuration parameter. The diff --git a/postfix/html/postmap.1.html b/postfix/html/postmap.1.html index 1bbe2b48b..52b27cb33 100644 --- a/postfix/html/postmap.1.html +++ b/postfix/html/postmap.1.html @@ -121,9 +121,9 @@ POSTMAP(1) POSTMAP(1) file_type The database type. To find out what types are sup- - ported, use the "postconf -m" command. + ported, use the "postconf -m" command. - The postmap command can query any supported file + The postmap command can query any supported file type, but it can create only the following file types: @@ -140,9 +140,6 @@ POSTMAP(1) POSTMAP(1) file_name.db. This is available only on systems with support for db databases. - Use the command postconf -m to find out what types - of database your Postfix installation can support. - When no file_type is specified, the software uses the database type specified via the default_database_type configuration parameter. diff --git a/postfix/man/man1/postalias.1 b/postfix/man/man1/postalias.1 index 9cc04b809..0990d4a29 100644 --- a/postfix/man/man1/postalias.1 +++ b/postfix/man/man1/postalias.1 @@ -87,7 +87,7 @@ existing entries, and ignore those attempts. Arguments: .IP \fIfile_type\fR The database type. To find out what types are supported, use -the "\fBpostconf -m" command. +the "\fBpostconf -m\fR" command. The \fBpostalias\fR command can query any supported file type, but it can create only the following file types: @@ -103,9 +103,6 @@ This is available only on systems with support for \fBdbm\fR databases. The output is a hashed file, named \fIfile_name\fB.db\fR. This is available only on systems with support for \fBdb\fR databases. .PP -Use the command \fBpostconf -m\fR to find out what types of database -your Postfix installation can support. - When no \fIfile_type\fR is specified, the software uses the database type specified via the \fBdefault_database_type\fR configuration parameter. diff --git a/postfix/man/man1/postmap.1 b/postfix/man/man1/postmap.1 index c1a8e7bad..b0c88dc3a 100644 --- a/postfix/man/man1/postmap.1 +++ b/postfix/man/man1/postmap.1 @@ -112,7 +112,7 @@ existing entries, and ignore those attempts. Arguments: .IP \fIfile_type\fR The database type. To find out what types are supported, use -the "\fBpostconf -m" command. +the "\fBpostconf -m\fR" command. The \fBpostmap\fR command can query any supported file type, but it can create only the following file types: @@ -128,9 +128,6 @@ This is available only on systems with support for \fBdbm\fR databases. The output file is a hashed file, named \fIfile_name\fB.db\fR. This is available only on systems with support for \fBdb\fR databases. .PP -Use the command \fBpostconf -m\fR to find out what types of database -your Postfix installation can support. - When no \fIfile_type\fR is specified, the software uses the database type specified via the \fBdefault_database_type\fR configuration parameter. diff --git a/postfix/man/man5/access.5 b/postfix/man/man5/access.5 index 929411a1e..57e90dcdc 100644 --- a/postfix/man/man5/access.5 +++ b/postfix/man/man5/access.5 @@ -28,7 +28,7 @@ Normally, the \fBaccess\fR table is specified as a text file that serves as input to the \fBpostmap\fR(1) command. The result, an indexed file in \fBdbm\fR or \fBdb\fR format, is used for fast searching by the mail system. Execute the command -\fBpostmap /etc/postfix/access\fR in order to rebuild the indexed +"\fBpostmap /etc/postfix/access\fR" in order to rebuild the indexed file after changing the access table. When the table is provided via other means such as NIS, LDAP @@ -275,8 +275,8 @@ Actions are the same as with indexed file lookups. The following example uses an indexed file, so that the order of table entries does not matter. The example permits access by the client at address 1.2.3.4 but rejects all -other clients in 1.2.3.0/24. Instead of "\fBhash\fR" lookup -tables, some systems use "\fBdbm\fR". Use the command +other clients in 1.2.3.0/24. Instead of \fBhash\fR lookup +tables, some systems use \fBdbm\fR. Use the command "\fBpostconf -m\fR" to find out what lookup tables Postfix supports on your system. diff --git a/postfix/proto/CDB_README.html b/postfix/proto/CDB_README.html new file mode 100644 index 000000000..bc88967c4 --- /dev/null +++ b/postfix/proto/CDB_README.html @@ -0,0 +1,84 @@ + + + + + + +Postfix CDB Howto + + + + + + + +

    Postfix CDB Howto

    + +
    + +

    Introduction

    + +

    CDB (Constant DataBase) is an indexed file format designed by +Daniel Bernstein. CDB is optimized exclusively for read access +and guarantees that each record will be read in at most two disk +accesses. This is achieved by forgoing support for incremental +updates: no single-record inserts or deletes are supported. CDB +databases can be modified only by rebuilding them completely from +scratch, hence the "constant" qualifier in the name.

    + +

    Postfix CDB databases are specified as "cdb:name", where +name specifies the CDB file name without the ".cdb" suffix +(another suffix, ".tmp", is used temporarily while a CDB file is +under construction). CDB databases are maintained with the postmap(1) +or postalias(1) command. The DATABASE_README document has general +information about Postfix databases.

    + +

    CDB support is available with Postfix 2.2 and later releases. +This document describes how to build Postfix with CDB support.

    + +

    Building Postfix with CDB

    + +

    Postfix is compatible with two CDB implementations:

    + + + +

    Tinycdb is preferred, since it is a bit faster, has additional +useful functionality and is much simpler to use.

    + +

    To build Postfix after you have installed CDB, use something +like:

    + +
    +
    +% make tidy
    +% CDB=../../../tinycdb-0.5
    +% make -f Makefile.init makefiles "CCARGS=-DHAS_CDB -I$CDB" \
    +    "AUXLIBS=$CDB/libcdb.a"
    +% make
    +
    +for tinycdb, or alternatively, for the D.J.B. version:
    +
    +% make tidy
    +% CDB=../../../cdb-0.75
    +% make -f Makefile.init makefiles "CCARGS=-DHAS_CDB -I$CDB" \
    +    "AUXLIBS=$CDB/cdb.a $CDB/alloc.a $CDB/buffer.a $CDB/unix.a $CDB/byte.a"
    +% make
    +
    +
    + +

    After postfix has been built with cdb support, you can use +"cdb" tables wherever you can use read-only "hash", "btree" or +"dbm" tables. However, the "postmap -i" (incremental record +insertion) and "postmap -d" (incremental record deletion) +command-line options are not available. For the same reason the +"cdb" map type cannot be used to store the volatile address +verification cache for the verify(8) service.

    diff --git a/postfix/proto/DATABASE_README.html b/postfix/proto/DATABASE_README.html index 5fbd1d8ce..d4a25751a 100644 --- a/postfix/proto/DATABASE_README.html +++ b/postfix/proto/DATABASE_README.html @@ -188,7 +188,9 @@ have a problem when the update fails because the disk is full or because something else happens. This is because commands such as postmap(1) or postalias(1) overwrite existing files. If the update fails in the middle then you have no usable database, and Postfix -will stop working.

    +will stop working. This is not an issue with the CDB database type +available with Postfix 2.2 and later, because CDB +database rebuilds are atomic.

    With multi-file databases such as DBM, there is no simple solution. With Berkeley DB and other "one file" databases, it is @@ -244,7 +246,7 @@ database file as if nothing happened.

    Postfix lookup table types

    To find out what database types your Postfix system supports, -use the "postconf -m" command. Here is a list of database types +use the "postconf -m" command. Here is a list of database types that are often supported:

    @@ -259,6 +261,14 @@ created with the postmap(1) or postalias(1) command. The lookup table name as used in "btree:table" is the database file name without the ".db" suffix. +
    cdb
    + +
    A read-optimized structure with no support for incremental updates. +Database files are created with the postmap(1) or postalias(1) command. +The lookup table name as used in "cdb:table" is the database file name +without the ".cdb" suffix. This feature is available with Postfix 2.2 +and later.
    +
    cidr
    A table that associates values with Classless Inter-Domain diff --git a/postfix/proto/Makefile.in b/postfix/proto/Makefile.in index 743dc83b0..2b8b84007 100644 --- a/postfix/proto/Makefile.in +++ b/postfix/proto/Makefile.in @@ -11,6 +11,7 @@ HTML = ../html/ADDRESS_CLASS_README.html \ ../html/BACKSCATTER_README.html \ ../html/BASIC_CONFIGURATION_README.html \ ../html/BUILTIN_FILTER_README.html \ + ../html/CDB_README.html \ ../html/CONTENT_INSPECTION_README.html \ ../html/CYRUS_README.html \ ../html/DATABASE_README.html ../html/DB_README.html \ @@ -41,6 +42,7 @@ README = ../README_FILES/ADDRESS_CLASS_README \ ../README_FILES/BACKSCATTER_README \ ../README_FILES/BASIC_CONFIGURATION_README \ ../README_FILES/BUILTIN_FILTER_README \ + ../README_FILES/CDB_README \ ../README_FILES/CONTENT_INSPECTION_README \ ../README_FILES/CYRUS_README \ ../README_FILES/DATABASE_README ../README_FILES/DB_README \ @@ -122,6 +124,9 @@ clobber: ../html/BACKSCATTER_README.html: BACKSCATTER_README.html $(POSTLINK) $? >$@ +../html/CDB_README.html: CDB_README.html + $(POSTLINK) $? >$@ + ../html/CONTENT_INSPECTION_README.html: CONTENT_INSPECTION_README.html $(POSTLINK) $? >$@ @@ -251,6 +256,9 @@ clobber: ../README_FILES/BUILTIN_FILTER_README: BUILTIN_FILTER_README.html $(HT2READ) $? >$@ +../README_FILES/CDB_README: CDB_README.html + $(HT2READ) $? >$@ + ../README_FILES/CONTENT_INSPECTION_README: CONTENT_INSPECTION_README.html $(HT2READ) $? >$@ diff --git a/postfix/proto/RESTRICTION_CLASS_README.html b/postfix/proto/RESTRICTION_CLASS_README.html index 7d9ad751f..3c5ca1825 100644 --- a/postfix/proto/RESTRICTION_CLASS_README.html +++ b/postfix/proto/RESTRICTION_CLASS_README.html @@ -110,7 +110,7 @@ to IP spoofing.

    -

    Specify dbm instead of hash if your system uses +

    Specify dbm instead of hash if your system uses dbm files instead of db files. To find out what map types Postfix supports, use the command postconf -m.

    @@ -209,7 +209,7 @@ with LDAP or SQL.

    -

    Specify dbm instead of hash if your system uses +

    Specify dbm instead of hash if your system uses dbm files instead of db files. To find out what map types Postfix supports, use the command postconf -m.

    diff --git a/postfix/proto/STANDARD_CONFIGURATION_README.html b/postfix/proto/STANDARD_CONFIGURATION_README.html index 5b0cbc341..c3999645e 100644 --- a/postfix/proto/STANDARD_CONFIGURATION_README.html +++ b/postfix/proto/STANDARD_CONFIGURATION_README.html @@ -67,10 +67,10 @@ machine that has direct Internet access. At least, that is how Postfix installs when you download the Postfix source code via http://www.postfix.org/.

    -

    You can use the command "postconf -n" to find out what settings -are overruled by your main.cf. Besides a few pathname settings, -few parameters should be set on a stand-alone box, beyond what is -covered in the BASIC_CONFIGURATION_README document:

    +

    You can use the command "postconf -n" to find out what +settings are overruled by your main.cf. Besides a few pathname +settings, few parameters should be set on a stand-alone box, beyond +what is covered in the BASIC_CONFIGURATION_README document:

    @@ -253,11 +253,11 @@ forwards mail to her preferred machine: 

    On some systems the alias database is not in /etc/aliases. To -find out the location for your system, execute the command "postconf -alias_maps".

    +find out the location for your system, execute the command "postconf +alias_maps".

    -

    Execute the command "newaliases" whenever you change the aliases -file.

    +

    Execute the command "newaliases" whenever you change +the aliases file.

    Postfix email firewall/gateway

    @@ -269,8 +269,8 @@ accepts mail for "anything.example.com". That would not be right.

    Note: this example requires Postfix version 2.0 and later. To find -out what Postfix version you have, execute the command "postconf -mail_version".

    +out what Postfix version you have, execute the command "postconf +mail_version".

    The solution is presented in multiple parts. This first part gets rid of local mail delivery on the firewall, making the firewall @@ -381,14 +381,14 @@ gateway machine. The [] forces Postfix to do no MX lookup. -

    Specify dbm instead of hash if your system uses -dbm files instead of db. To find out what lookup tables -Postfix supports, use the command "postconf -m".

    +

    Specify dbm instead of hash if your system uses +dbm files instead of db files. To find out what lookup +tables Postfix supports, use the command "postconf -m".

    -

    Execute the command "postmap /etc/postfix/relay_recipients" +

    Execute the command "postmap /etc/postfix/relay_recipients" whenever you change the relay_recipients table.

    -

    Execute the command "postmap /etc/postfix/transport" +

    Execute the command "postmap /etc/postfix/transport" whenever you change the transport table.

    Delivering some but not all accounts @@ -449,8 +449,8 @@ mail to the gateway host, and to send intranet mail directly. That's what Wietse does at work.

    Note: this example requires Postfix version 2.0 and later. To find -out what Postfix version you have, execute the command "postconf -mail_version".

    +out what Postfix version you have, execute the command "postconf +mail_version".

    The following example presents additional configuration. You need to combine this with basic configuration information as @@ -492,11 +492,11 @@ directly, and gives undeliverable mail to a gateway.

    -

    Specify dbm instead of hash if your system uses dbm files -instead of db. To find out what lookup tables Postfix supports, use -the command "postconf -m".

    +

    Specify dbm instead of hash if your system uses +dbm files instead of db files. To find out what lookup +tables Postfix supports, use the command "postconf -m".

    -

    Execute the command "postmap /etc/postfix/transport" whenever +

    Execute the command "postmap /etc/postfix/transport" whenever you edit the transport table.

    Configuring Postfix as MX host for a remote site

    @@ -573,11 +573,11 @@ table.

    -

    Specify dbm instead of hash if your system uses dbm files -instead of db files. To find out what lookup tables Postfix supports, -use the command "postconf -m".

    +

    Specify dbm instead of hash if your system uses +dbm files instead of db files. To find out what lookup +tables Postfix supports, use the command "postconf -m".

    -

    Execute the command "postmap /etc/postfix/transport" whenever +

    Execute the command "postmap /etc/postfix/transport" whenever you change the transport table.

    Postfix on a dialup machine

    @@ -640,7 +640,7 @@ calls from being placed, disable spontaneous SMTP mail deliveries.

    The exact location of the sendmail command is system-specific. -Use the command "postconf sendmail_path" to find out where the +Use the command "postconf sendmail_path" to find out where the Postfix sendmail command is located on your machine.

    In order to find out if the mail queue is flushed, use something @@ -663,7 +663,7 @@ done

    If you have disabled spontaneous -SMTP mail delivery, you also need to run the "sendmail -q" +SMTP mail delivery, you also need to run the "sendmail -q" command every now and then while the dialup link is up, so that newly-posted mail is flushed from the queue.

    diff --git a/postfix/proto/UUCP_README.html b/postfix/proto/UUCP_README.html index e4af2829a..c614ceeb3 100644 --- a/postfix/proto/UUCP_README.html +++ b/postfix/proto/UUCP_README.html @@ -122,7 +122,7 @@ whenever you change the transport file.

    transport_maps = hash:/etc/postfix/transport -

    Specify dbm instead of hash if your system uses +

    Specify dbm instead of hash if your system uses dbm files instead of db files. To find out what map types Postfix supports, use the command "postconf -m".

    diff --git a/postfix/proto/access b/postfix/proto/access index f5825882d..e4d3efb7a 100644 --- a/postfix/proto/access +++ b/postfix/proto/access @@ -22,7 +22,7 @@ # that serves as input to the \fBpostmap\fR(1) command. # The result, an indexed file in \fBdbm\fR or \fBdb\fR format, # is used for fast searching by the mail system. Execute the command -# \fBpostmap /etc/postfix/access\fR in order to rebuild the indexed +# "\fBpostmap /etc/postfix/access\fR" in order to rebuild the indexed # file after changing the access table. # # When the table is provided via other means such as NIS, LDAP @@ -249,8 +249,8 @@ # The following example uses an indexed file, so that the # order of table entries does not matter. The example permits # access by the client at address 1.2.3.4 but rejects all -# other clients in 1.2.3.0/24. Instead of "\fBhash\fR" lookup -# tables, some systems use "\fBdbm\fR". Use the command +# other clients in 1.2.3.0/24. Instead of \fBhash\fR lookup +# tables, some systems use \fBdbm\fR. Use the command # "\fBpostconf -m\fR" to find out what lookup tables Postfix # supports on your system. # diff --git a/postfix/proto/stop b/postfix/proto/stop index c5cf9688c..e7f75c98d 100644 --- a/postfix/proto/stop +++ b/postfix/proto/stop @@ -10,6 +10,7 @@ README RFC Sendmail's Wietse +cdb cf com db @@ -91,6 +92,7 @@ sysadmin userid username Autoreplies +CDB DBM Howto MAILDROP diff --git a/postfix/src/global/Makefile.in b/postfix/src/global/Makefile.in index 09305f61b..3d5dd511e 100644 --- a/postfix/src/global/Makefile.in +++ b/postfix/src/global/Makefile.in @@ -14,7 +14,7 @@ SRCS = abounce.c anvil_clnt.c been_here.c bounce.c bounce_log.c \ mail_open_ok.c mail_params.c mail_pathname.c mail_queue.c \ mail_run.c mail_scan_dir.c mail_stream.c mail_task.c mail_trigger.c \ maps.c mark_corrupt.c match_parent_style.c mbox_conf.c \ - mbox_open.c mime_state.c mkmap_db.c mkmap_dbm.c mkmap_open.c \ + mbox_open.c mime_state.c mkmap_db.c mkmap_cdb.c mkmap_dbm.c mkmap_open.c \ mynetworks.c mypwd.c namadr_list.c off_cvt.c opened.c \ own_inet_addr.c pipe_command.c post_mail.c quote_821_local.c \ quote_822_local.c rec_streamlf.c rec_type.c recipient_list.c \ @@ -39,7 +39,7 @@ OBJS = abounce.o anvil_clnt.o been_here.o bounce.o bounce_log.o \ mail_open_ok.o mail_params.o mail_pathname.o mail_queue.o \ mail_run.o mail_scan_dir.o mail_stream.o mail_task.o mail_trigger.o \ maps.o mark_corrupt.o match_parent_style.o mbox_conf.o \ - mbox_open.o mime_state.o mkmap_db.o mkmap_dbm.o mkmap_open.o \ + mbox_open.o mime_state.o mkmap_db.o mkmap_cdb.o mkmap_dbm.o mkmap_open.o \ mynetworks.o mypwd.o namadr_list.o off_cvt.o opened.o \ own_inet_addr.o pipe_command.o post_mail.o quote_821_local.o \ quote_822_local.o rec_streamlf.o rec_type.o recipient_list.o \ @@ -1031,6 +1031,8 @@ mime_state.o: mail_params.h mime_state.o: header_token.h mime_state.o: lex_822.h mime_state.o: mime_state.h +mkmap_cdb.o: mkmap_cdb.c +mkmap_cdb.o: ../../include/sys_defs.h mkmap_db.o: mkmap_db.c mkmap_db.o: ../../include/sys_defs.h mkmap_db.o: ../../include/msg.h @@ -1066,6 +1068,7 @@ mkmap_open.o: ../../include/vstream.h mkmap_open.o: ../../include/vbuf.h mkmap_open.o: ../../include/argv.h mkmap_open.o: ../../include/dict_db.h +mkmap_open.o: ../../include/dict_cdb.h mkmap_open.o: ../../include/dict_dbm.h mkmap_open.o: ../../include/sigdelay.h mkmap_open.o: ../../include/mymalloc.h diff --git a/postfix/src/global/mail_version.h b/postfix/src/global/mail_version.h index 4386c6852..8572c42a9 100644 --- a/postfix/src/global/mail_version.h +++ b/postfix/src/global/mail_version.h @@ -20,7 +20,7 @@ * Patches change the patchlevel and the release date. Snapshots change the * release date only. */ -#define MAIL_RELEASE_DATE "20041207" +#define MAIL_RELEASE_DATE "20041208" #define MAIL_VERSION_NUMBER "2.2" #define VAR_MAIL_VERSION "mail_version" diff --git a/postfix/src/global/mkmap.h b/postfix/src/global/mkmap.h index fc23d64d5..848dbc003 100644 --- a/postfix/src/global/mkmap.h +++ b/postfix/src/global/mkmap.h @@ -36,6 +36,7 @@ extern void mkmap_close(MKMAP *); #define mkmap_append(map, key, val) dict_put((map)->dict, (key), (val)) extern MKMAP *mkmap_dbm_open(const char *); +extern MKMAP *mkmap_cdb_open(const char *); extern MKMAP *mkmap_hash_open(const char *); extern MKMAP *mkmap_btree_open(const char *); diff --git a/postfix/src/global/mkmap_cdb.c b/postfix/src/global/mkmap_cdb.c new file mode 100644 index 000000000..83bf96d37 --- /dev/null +++ b/postfix/src/global/mkmap_cdb.c @@ -0,0 +1,65 @@ +/*++ +/* NAME +/* mkmap_cdb 3 +/* SUMMARY +/* create or open database, CDB style +/* SYNOPSIS +/* #include +/* +/* MKMAP *mkmap_cdb_open(path) +/* const char *path; +/* +/* DESCRIPTION +/* This module implements support for creating DJB's CDB "constant +/* databases". +/* +/* mkmap_cdb_open() take a file name, append the ".cdb.tmp" suffix, +/* create the named DB database. On close, this file renamed to +/* file name with ".cdb" suffix appended (without ".tmp" part). +/* This routine is a CDB-specific helper for the more +/* general mkmap_open() interface. +/* +/* All errors are fatal. +/* SEE ALSO +/* dict_cdb(3), CDB dictionary interface. +/* LICENSE +/* .ad +/* .fi +/* The Secure Mailer license must be distributed with this software. +/* AUTHOR(S) +/* Written by Michael Tokarev based on mkmap_db by +/* Wietse Venema +/* IBM T.J. Watson Research +/* P.O. Box 704 +/* Yorktown Heights, NY 10598, USA +/*--*/ + +/* System library. */ + +#include + +#ifdef HAS_CDB + +/* Utility library. */ + +#include +#include + +/* Application-specific. */ + +#include "mkmap.h" +#include + +/* This is a dummy module, since CDB has all the functionality + * built-in, as cdb creation requires one global lock anyway. */ + +MKMAP *mkmap_cdb_open(const char *unused_path) +{ + MKMAP *mkmap = (MKMAP *) mymalloc(sizeof(*mkmap)); + mkmap->open = dict_cdb_open; + mkmap->after_open = 0; + mkmap->after_close = 0; + return (mkmap); +} + +#endif /* HAS_CDB */ diff --git a/postfix/src/global/mkmap_open.c b/postfix/src/global/mkmap_open.c index dd6f6e642..a972f06b0 100644 --- a/postfix/src/global/mkmap_open.c +++ b/postfix/src/global/mkmap_open.c @@ -63,6 +63,7 @@ #include #include #include +#include #include #include #include @@ -81,6 +82,9 @@ typedef struct { } MKMAP_OPEN_INFO; MKMAP_OPEN_INFO mkmap_types[] = { +#ifdef HAS_CDB + DICT_TYPE_CDB, mkmap_cdb_open, +#endif #ifdef HAS_DBM DICT_TYPE_DBM, mkmap_dbm_open, #endif diff --git a/postfix/src/postalias/postalias.c b/postfix/src/postalias/postalias.c index 53c26ee76..ba02e9b32 100644 --- a/postfix/src/postalias/postalias.c +++ b/postfix/src/postalias/postalias.c @@ -81,7 +81,7 @@ /* Arguments: /* .IP \fIfile_type\fR /* The database type. To find out what types are supported, use -/* the "\fBpostconf -m" command. +/* the "\fBpostconf -m\fR" command. /* /* The \fBpostalias\fR command can query any supported file type, /* but it can create only the following file types: @@ -97,9 +97,6 @@ /* The output is a hashed file, named \fIfile_name\fB.db\fR. /* This is available only on systems with support for \fBdb\fR databases. /* .PP -/* Use the command \fBpostconf -m\fR to find out what types of database -/* your Postfix installation can support. -/* /* When no \fIfile_type\fR is specified, the software uses the database /* type specified via the \fBdefault_database_type\fR configuration /* parameter. diff --git a/postfix/src/postmap/postmap.c b/postfix/src/postmap/postmap.c index b307721c4..0499b6f00 100644 --- a/postfix/src/postmap/postmap.c +++ b/postfix/src/postmap/postmap.c @@ -102,7 +102,7 @@ /* Arguments: /* .IP \fIfile_type\fR /* The database type. To find out what types are supported, use -/* the "\fBpostconf -m" command. +/* the "\fBpostconf -m\fR" command. /* /* The \fBpostmap\fR command can query any supported file type, /* but it can create only the following file types: @@ -118,9 +118,6 @@ /* The output file is a hashed file, named \fIfile_name\fB.db\fR. /* This is available only on systems with support for \fBdb\fR databases. /* .PP -/* Use the command \fBpostconf -m\fR to find out what types of database -/* your Postfix installation can support. -/* /* When no \fIfile_type\fR is specified, the software uses the database /* type specified via the \fBdefault_database_type\fR configuration /* parameter. diff --git a/postfix/src/util/Makefile.in b/postfix/src/util/Makefile.in index 21170ea26..37d0736f1 100644 --- a/postfix/src/util/Makefile.in +++ b/postfix/src/util/Makefile.in @@ -2,7 +2,7 @@ SHELL = /bin/sh SRCS = alldig.c argv.c argv_split.c attr_print0.c attr_print64.c \ attr_scan0.c attr_scan64.c base64_code.c basename.c binhash.c \ chroot_uid.c clean_env.c close_on_exec.c concatenate.c ctable.c \ - dict.c dict_alloc.c dict_db.c dict_dbm.c dict_debug.c dict_env.c \ + dict.c dict_alloc.c dict_db.c dict_cdb.c dict_dbm.c dict_debug.c dict_env.c \ dict_cidr.c dict_ht.c dict_ni.c dict_nis.c \ dict_nisplus.c dict_open.c dict_pcre.c dict_regexp.c \ dict_static.c dict_tcp.c dict_unix.c dir_forest.c doze.c \ @@ -32,7 +32,7 @@ SRCS = alldig.c argv.c argv_split.c attr_print0.c attr_print64.c \ OBJS = alldig.o argv.o argv_split.o attr_print0.o attr_print64.o \ attr_scan0.o attr_scan64.o base64_code.o basename.o binhash.o \ chroot_uid.o clean_env.o close_on_exec.o concatenate.o ctable.o \ - dict.o dict_alloc.o dict_db.o dict_dbm.o dict_debug.o dict_env.o \ + dict.o dict_alloc.o dict_db.o dict_cdb.o dict_dbm.o dict_debug.o dict_env.o \ dict_cidr.o dict_ht.o dict_ni.o dict_nis.o \ dict_nisplus.o dict_open.o dict_pcre.o dict_regexp.o \ dict_static.o dict_tcp.o dict_unix.o dir_forest.o doze.o \ @@ -60,7 +60,7 @@ OBJS = alldig.o argv.o argv_split.o attr_print0.o attr_print64.o \ attr_print_plain.o sane_connect.o $(STRCASE) neuter.o name_code.o \ uppercase.o unix_recv_fd.o stream_recv_fd.o unix_send_fd.o stream_send_fd.o HDRS = argv.h attr.h base64_code.h binhash.h chroot_uid.h clean_env.h \ - connect.h ctable.h dict.h dict_db.h dict_dbm.h dict_env.h \ + connect.h ctable.h dict.h dict_db.h dict_cdb.h dict_dbm.h dict_env.h \ dict_cidr.h dict_ht.h dict_ni.h dict_nis.h \ dict_nisplus.h dict_pcre.h dict_regexp.h \ dict_static.h dict_tcp.h dict_unix.h dir_forest.h events.h \ @@ -622,6 +622,8 @@ dict_alloc.o: dict.h dict_alloc.o: vstream.h dict_alloc.o: vbuf.h dict_alloc.o: argv.h +dict_cdb.o: dict_cdb.c +dict_cdb.o: sys_defs.h dict_cidr.o: dict_cidr.c dict_cidr.o: sys_defs.h dict_cidr.o: mymalloc.h @@ -708,6 +710,7 @@ dict_open.o: msg.h dict_open.o: dict.h dict_open.o: vstream.h dict_open.o: vbuf.h +dict_open.o: dict_cdb.h dict_open.o: dict_env.h dict_open.o: dict_unix.h dict_open.o: dict_tcp.h diff --git a/postfix/src/util/dict_cdb.c b/postfix/src/util/dict_cdb.c new file mode 100644 index 000000000..a66004d44 --- /dev/null +++ b/postfix/src/util/dict_cdb.c @@ -0,0 +1,374 @@ +/*++ +/* NAME +/* dict_cdb 3 +/* SUMMARY +/* dictionary manager interface to CDB files +/* SYNOPSIS +/* #include +/* +/* DICT *dict_cdb_open(path, open_flags, dict_flags) +/* const char *path; +/* int open_flags; +/* int dict_flags; +/* +/* DESCRIPTION +/* dict_cdb_open() opens the specified CDB database. The result is +/* a pointer to a structure that can be used to access the dictionary +/* using the generic methods documented in dict_open(3). +/* +/* Arguments: +/* .IP path +/* The database pathname, not including the ".cdb" suffix. +/* .IP open_flags +/* Flags passed to open(). Specify O_RDONLY or O_WRONLY|O_CREAT|O_TRUNC. +/* .IP dict_flags +/* Flags used by the dictionary interface. +/* SEE ALSO +/* dict(3) generic dictionary manager +/* DIAGNOSTICS +/* Fatal errors: cannot open file, write error, out of memory. +/* LICENSE +/* .ad +/* .fi +/* The Secure Mailer license must be distributed with this software. +/* AUTHOR(S) +/* Michael Tokarev based on dict_db.c by +/* Wietse Venema +/* IBM T.J. Watson Research +/* P.O. Box 704 +/* Yorktown Heights, NY 10598, USA +/*--*/ + +#include "sys_defs.h" + +/* System library. */ + +#include +#include +#include +#include +#include + +/* Utility library. */ + +#include "msg.h" +#include "mymalloc.h" +#include "vstring.h" +#include "stringops.h" +#include "iostuff.h" +#include "myflock.h" +#include "dict.h" +#include "dict_cdb.h" + +#ifdef HAS_CDB + +#include +#ifndef TINYCDB_VERSION +#include +#endif +#ifndef cdb_fileno +#define cdb_fileno(c) ((c)->fd) +#endif + +#ifndef CDB_SUFFIX +#define CDB_SUFFIX ".cdb" +#endif +#ifndef CDB_TMP_SUFFIX +#define CDB_TMP_SUFFIX CDB_SUFFIX ".tmp" +#endif + +/* Application-specific. */ + +typedef struct { + DICT dict; /* generic members */ + struct cdb cdb; /* cdb structure */ +} DICT_CDBQ; /* query interface */ + +typedef struct { + DICT dict; /* generic members */ + struct cdb_make cdbm; /* cdb_make structure */ + char *cdb_path; /* cdb pathname (.cdb) */ + char *tmp_path; /* temporary pathname (.tmp) */ +} DICT_CDBM; /* rebuild interface */ + +/* dict_cdbq_lookup - find database entry, query mode */ + +static const char *dict_cdbq_lookup(DICT *dict, const char *name) +{ + DICT_CDBQ *dict_cdbq = (DICT_CDBQ *) dict; + unsigned vlen; + int status = 0; + static char *buf; + static unsigned len; + const char *result = 0; + + dict_errno = 0; + + /* CDB is constant, so do not try to acquire a lock. */ + + /* + * See if this CDB file was written with one null byte appended to key + * and value. + */ + if (dict->flags & DICT_FLAG_TRY1NULL) { + status = cdb_find(&dict_cdbq->cdb, name, strlen(name) + 1); + if (status > 0) + dict->flags &= ~DICT_FLAG_TRY0NULL; + } + + /* + * See if this CDB file was written with no null byte appended to key and + * value. + */ + if (status == 0 && (dict->flags & DICT_FLAG_TRY0NULL)) { + status = cdb_find(&dict_cdbq->cdb, name, strlen(name)); + if (status > 0) + dict->flags &= ~DICT_FLAG_TRY1NULL; + } + if (status < 0) + msg_fatal("error reading %s: %m", dict->name); + + if (status) { + vlen = cdb_datalen(&dict_cdbq->cdb); + if (len < vlen) { + if (buf == 0) + buf = mymalloc(vlen + 1); + else + buf = myrealloc(buf, vlen + 1); + len = vlen; + } + if (cdb_read(&dict_cdbq->cdb, buf, vlen, + cdb_datapos(&dict_cdbq->cdb)) < 0) + msg_fatal("error reading %s: %m", dict->name); + buf[vlen] = '\0'; + result = buf; + } + /* No locking so not release the lock. */ + + return (result); +} + +/* dict_cdbq_close - close data base, query mode */ + +static void dict_cdbq_close(DICT *dict) +{ + DICT_CDBQ *dict_cdbq = (DICT_CDBQ *) dict; + + cdb_free(&dict_cdbq->cdb); + close(dict->stat_fd); + dict_free(dict); +} + +/* dict_cdbq_open - open data base, query mode */ + +static DICT *dict_cdbq_open(const char *path, int dict_flags) +{ + DICT_CDBQ *dict_cdbq; + struct stat st; + char *cdb_path; + int fd; + + cdb_path = concatenate(path, CDB_SUFFIX, (char *) 0); + + if ((fd = open(cdb_path, O_RDONLY)) < 0) + msg_fatal("open database %s: %m", cdb_path); + + dict_cdbq = (DICT_CDBQ *) dict_alloc(DICT_TYPE_CDB, + cdb_path, sizeof(*dict_cdbq)); +#if defined(TINYCDB_VERSION) + if (cdb_init(&(dict_cdbq->cdb), fd) != 0) + msg_fatal("dict_cdbq_open: unable to init %s: %m", cdb_path); +#else + cdb_init(&(dict_cdbq->cdb), fd); +#endif + dict_cdbq->dict.lookup = dict_cdbq_lookup; + dict_cdbq->dict.close = dict_cdbq_close; + dict_cdbq->dict.stat_fd = fd; + if (fstat(fd, &st) < 0) + msg_fatal("dict_dbq_open: fstat: %m"); + dict_cdbq->dict.mtime = st.st_mtime; + close_on_exec(fd, CLOSE_ON_EXEC); + + /* + * If undecided about appending a null byte to key and value, choose to + * try both in query mode. + */ + if ((dict_flags & (DICT_FLAG_TRY1NULL | DICT_FLAG_TRY0NULL)) == 0) + dict_flags |= DICT_FLAG_TRY0NULL | DICT_FLAG_TRY1NULL; + dict_cdbq->dict.flags = dict_flags | DICT_FLAG_FIXED; + + myfree(cdb_path); + return (&dict_cdbq->dict); +} + +/* dict_cdbm_update - add database entry, create mode */ + +static void dict_cdbm_update(DICT *dict, const char *name, const char *value) +{ + DICT_CDBM *dict_cdbm = (DICT_CDBM *) dict; + unsigned ksize, + vsize; + int r; + + ksize = strlen(name); + vsize = strlen(value); + + /* + * Optionally append a null byte to key and value. + */ + if (dict->flags & DICT_FLAG_TRY1NULL) { + ksize++; + vsize++; + } + + /* + * Do the add operation. No locking is done. + */ +#ifdef TINYCDB_VERSION +#ifndef CDB_PUT_ADD +#error please upgrate tinycdb to at least 0.5 version +#endif + if (dict->flags & DICT_FLAG_DUP_IGNORE) + r = CDB_PUT_ADD; + else if (dict->flags & DICT_FLAG_DUP_REPLACE) + r = CDB_PUT_REPLACE; + else + r = CDB_PUT_INSERT; + r = cdb_make_put(&dict_cdbm->cdbm, name, ksize, value, vsize, r); + if (r < 0) + msg_fatal("error writing %s: %m", dict_cdbm->tmp_path); + else if (r > 0) { + if (dict->flags & (DICT_FLAG_DUP_IGNORE | DICT_FLAG_DUP_REPLACE)); + else if (dict->flags & DICT_FLAG_DUP_WARN) + msg_warn("%s: duplicate entry: \"%s\"", + dict_cdbm->dict.name, name); + else + msg_fatal("%s: duplicate entry: \"%s\"", + dict_cdbm->dict.name, name); + } +#else + if (cdb_make_add(&dict_cdbm->cdbm, name, ksize, value, vsize) < 0) + msg_fatal("error writing %s: %m", dict_cdbm->tmp_path); +#endif +} + +/* dict_cdbm_close - close data base and rename file.tmp to file.cdb */ + +static void dict_cdbm_close(DICT *dict) +{ + DICT_CDBM *dict_cdbm = (DICT_CDBM *) dict; + int fd = cdb_fileno(&dict_cdbm->cdbm); + + /* + * Note: if FCNTL locking is used, closing any file descriptor on a + * locked file cancels all locks that the process may have on that file. + * CDB is FCNTL locking safe, because it uses the same file descriptor + * for database I/O and locking. + */ + if (cdb_make_finish(&dict_cdbm->cdbm) < 0) + msg_fatal("finish database %s: %m", dict_cdbm->tmp_path); + if (rename(dict_cdbm->tmp_path, dict_cdbm->cdb_path) < 0) + msg_fatal("rename database from %s to %s: %m", + dict_cdbm->tmp_path, dict_cdbm->cdb_path); + if (close(fd) < 0) /* releases a lock */ + msg_fatal("close database %s: %m", dict_cdbm->cdb_path); + myfree(dict_cdbm->cdb_path); + myfree(dict_cdbm->tmp_path); + dict_free(dict); +} + +/* dict_cdbm_open - create database as file.tmp */ + +static DICT *dict_cdbm_open(const char *path, int dict_flags) +{ + DICT_CDBM *dict_cdbm; + char *cdb_path; + char *tmp_path; + int fd; + struct stat st0, + st1; + + cdb_path = concatenate(path, CDB_SUFFIX, (char *) 0); + tmp_path = concatenate(path, CDB_TMP_SUFFIX, (char *) 0); + + /* + * Repeat until we have opened *and* locked *existing* file. Since the + * new (tmp) file will be renamed to be .cdb file, locking here is + * somewhat funny to work around possible race conditions. Note that we + * can't open a file with O_TRUNC as we can't know if another process + * isn't creating it at the same time. + */ + for (;;) { + if ((fd = open(tmp_path, O_RDWR | O_CREAT, 0644)) < 0 + || fstat(fd, &st0) < 0) + msg_fatal("open database %s: %m", tmp_path); + + /* + * Get an exclusive lock - we're going to change the database so we + * can't have any spectators. + */ + if (myflock(fd, INTERNAL_LOCK, MYFLOCK_OP_EXCLUSIVE) < 0) + msg_fatal("lock %s: %m", tmp_path); + + if (stat(tmp_path, &st1) < 0) + msg_fatal("stat(%s): %m", tmp_path); + + /* + * Compare file's state before and after lock: should be the same, + * and nlinks should be >0, or else we opened non-existing file... + */ + if (st0.st_ino == st1.st_ino && st0.st_dev == st1.st_dev + && st0.st_rdev == st1.st_rdev && st0.st_nlink == st1.st_nlink + && st0.st_nlink > 0) + break; /* successefully opened */ + + close(fd); + + } + +#ifndef NO_FTRUNCATE + if (st0.st_size) + ftruncate(fd, 0); +#endif + + dict_cdbm = (DICT_CDBM *) dict_alloc(DICT_TYPE_CDB, path, + sizeof(*dict_cdbm)); + if (cdb_make_start(&dict_cdbm->cdbm, fd) < 0) + msg_fatal("initialize database %s: %m", tmp_path); + dict_cdbm->dict.close = dict_cdbm_close; + dict_cdbm->dict.update = dict_cdbm_update; + dict_cdbm->cdb_path = cdb_path; + dict_cdbm->tmp_path = tmp_path; + close_on_exec(fd, CLOSE_ON_EXEC); + + /* + * If undecided about appending a null byte to key and value, choose a + * default to not append a null byte when creating a cdb. + */ + if ((dict_flags & (DICT_FLAG_TRY1NULL | DICT_FLAG_TRY0NULL)) == 0) + dict_flags |= DICT_FLAG_TRY0NULL; + else if ((dict_flags & DICT_FLAG_TRY1NULL) + && (dict_flags & DICT_FLAG_TRY0NULL)) + dict_flags &= ~DICT_FLAG_TRY0NULL; + dict_cdbm->dict.flags = dict_flags | DICT_FLAG_FIXED; + + return (&dict_cdbm->dict); +} + +/* dict_cdb_open - open data base for query mode or create mode */ + +DICT *dict_cdb_open(const char *path, int open_flags, int dict_flags) +{ + switch (open_flags & (O_RDONLY | O_RDWR | O_WRONLY | O_CREAT | O_TRUNC)) { + case O_RDONLY: /* query mode */ + return dict_cdbq_open(path, dict_flags); + case O_WRONLY | O_CREAT | O_TRUNC: /* create mode */ + case O_RDWR | O_CREAT | O_TRUNC: /* sloppiness */ + return dict_cdbm_open(path, dict_flags); + default: + msg_fatal("dict_cdb_open: inappropriate open flags for cdb database" + " - specify O_RDONLY or O_WRONLY|O_CREAT|O_TRUNC"); + } +} + +#endif /* HAS_CDB */ diff --git a/postfix/src/util/dict_cdb.h b/postfix/src/util/dict_cdb.h new file mode 100644 index 000000000..e2c13d470 --- /dev/null +++ b/postfix/src/util/dict_cdb.h @@ -0,0 +1,37 @@ +#ifndef _DICT_CDB_H_INCLUDED_ +#define _DICT_CDB_H_INCLUDED_ + +/*++ +/* NAME +/* dict_cdb 3h +/* SUMMARY +/* dictionary manager interface to CDB files +/* SYNOPSIS +/* #include +/* DESCRIPTION +/* .nf + + /* + * Utility library. + */ +#include + + /* + * External interface. + */ +#define DICT_TYPE_CDB "cdb" + +extern DICT *dict_cdb_open(const char *, int, int); + +/* LICENSE +/* .ad +/* .fi +/* The Secure Mailer license must be distributed with this software. +/* AUTHOR(S) +/* Wietse Venema +/* IBM T.J. Watson Research +/* P.O. Box 704 +/* Yorktown Heights, NY 10598, USA +/*--*/ + +#endif /* _DICT_CDB_H_INCLUDED_ */ diff --git a/postfix/src/util/dict_open.c b/postfix/src/util/dict_open.c index 14ccec572..66919c835 100644 --- a/postfix/src/util/dict_open.c +++ b/postfix/src/util/dict_open.c @@ -164,6 +164,7 @@ #include #include #include +#include #include #include #include @@ -189,6 +190,9 @@ typedef struct { } DICT_OPEN_INFO; static DICT_OPEN_INFO dict_open_info[] = { +#ifdef HAS_CDB + DICT_TYPE_CDB, dict_cdb_open, +#endif DICT_TYPE_ENVIRON, dict_env_open, DICT_TYPE_UNIX, dict_unix_open, #ifdef SNAPSHOT diff --git a/postfix/src/util/printable.c b/postfix/src/util/printable.c index 85c24897c..9e27f94d4 100644 --- a/postfix/src/util/printable.c +++ b/postfix/src/util/printable.c @@ -10,7 +10,7 @@ /* char *buffer; /* int replacement; /* DESCRIPTION -/* printable() replaces non-printable characters in its input +/* printable() replaces non-ASCII or non-printable characters in its input /* by the given replacement. /* /* Arguments: @@ -45,7 +45,7 @@ char *printable(char *string, int replacement) int ch; for (cp = string; (ch = *(unsigned char *) cp) != 0; cp++) - if (!ISPRINT(ch)) + if (!ISASCII(ch) || !ISPRINT(ch)) *cp = replacement; return (string); }