-TDELIVER_ATTR
-TDELIVER_REQUEST
-TDICT
+-TDICT_CDBM
+-TDICT_CDBQ
-TDICT_CIDR
-TDICT_CIDR_ENTRY
-TDICT_DB
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
* 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
--- /dev/null
+P\bPo\bos\bst\btf\bfi\bix\bx C\bCD\bDB\bB H\bHo\bow\bwt\bto\bo
+
+-------------------------------------------------------------------------------
+
+I\bIn\bnt\btr\bro\bod\bdu\buc\bct\bti\bio\bon\bn
+
+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.
+
+B\bBu\bui\bil\bld\bdi\bin\bng\bg P\bPo\bos\bst\btf\bfi\bix\bx w\bwi\bit\bth\bh C\bCD\bDB\bB
+
+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
+"p\bpo\bos\bst\btm\bma\bap\bp -\b-i\bi" (incremental record insertion) and "p\bpo\bos\bst\btm\bma\bap\bp -\b-d\bd" (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.
+
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
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
-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 "p\bpo\bos\bst\btc\bco\bon\bnf\bf
+-\b-m\bm" command. Here is a list of database types that are often supported:
b\bbt\btr\bre\bee\be
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.
+ c\bcd\bdb\bb
+ 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.
c\bci\bid\bdr\br
A table that associates values with Classless Inter-Domain Routing
(CIDR) patterns. The table format is described in cidr_table(5).
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 "p\bpo\bos\bst\btc\bco\bon\bnf\bf -\b-n\bn" 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:
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 "p\bpo\bos\bst\btc\bco\bon\bnf\bf a\bal\bli\bia\bas\bs_\b_m\bma\bap\bps\bs".
-Execute the command "newaliases" whenever you change the aliases file.
+Execute the command "n\bne\bew\bwa\bal\bli\bia\bas\bse\bes\bs" whenever you change the aliases file.
P\bPo\bos\bst\btf\bfi\bix\bx e\bem\bma\bai\bil\bl f\bfi\bir\bre\bew\bwa\bal\bll\bl/\b/g\bga\bat\bte\bew\bwa\bay\by
"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 "p\bpo\bos\bst\btc\bco\bon\bnf\bf m\bma\bai\bil\bl_\b_v\bve\ber\brs\bsi\bio\bon\bn".
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.
* 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 d\bdb\bbm\bm instead of h\bha\bas\bsh\bh if your system uses d\bdb\bbm\bm files instead of d\bdb\bb files.
+To find out what lookup tables Postfix supports, use the command "p\bpo\bos\bst\btc\bco\bon\bnf\bf -\b-m\bm".
-Execute the command "postmap /etc/postfix/relay_recipients" whenever you change
+Execute the command "p\bpo\bos\bst\btm\bma\bap\bp /\b/e\bet\btc\bc/\b/p\bpo\bos\bst\btf\bfi\bix\bx/\b/r\bre\bel\bla\bay\by_\b_r\bre\bec\bci\bip\bpi\bie\ben\bnt\bts\bs" whenever you change
the relay_recipients table.
-Execute the command "postmap /etc/postfix/transport" whenever you change the
+Execute the command "p\bpo\bos\bst\btm\bma\bap\bp /\b/e\bet\btc\bc/\b/p\bpo\bos\bst\btf\bfi\bix\bx/\b/t\btr\bra\ban\bns\bsp\bpo\bor\brt\bt" whenever you change the
transport table.
D\bDe\bel\bli\biv\bve\ber\bri\bin\bng\bg s\bso\bom\bme\be b\bbu\but\bt n\bno\bot\bt a\bal\bll\bl a\bac\bcc\bco\bou\bun\bnt\bts\bs l\blo\boc\bca\bal\bll\bly\by
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 "p\bpo\bos\bst\btc\bco\bon\bnf\bf m\bma\bai\bil\bl_\b_v\bve\ber\brs\bsi\bio\bon\bn".
The following example presents additional configuration. You need to combine
this with basic configuration information as discussed the first half of this
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 d\bdb\bbm\bm instead of h\bha\bas\bsh\bh if your system uses d\bdb\bbm\bm files instead of d\bdb\bb files.
+To find out what lookup tables Postfix supports, use the command "p\bpo\bos\bst\btc\bco\bon\bnf\bf -\b-m\bm".
-Execute the command "postmap /etc/postfix/transport" whenever you edit the
+Execute the command "p\bpo\bos\bst\btm\bma\bap\bp /\b/e\bet\btc\bc/\b/p\bpo\bos\bst\btf\bfi\bix\bx/\b/t\btr\bra\ban\bns\bsp\bpo\bor\brt\bt" whenever you edit the
transport table.
C\bCo\bon\bnf\bfi\big\bgu\bur\bri\bin\bng\bg P\bPo\bos\bst\btf\bfi\bix\bx a\bas\bs M\bMX\bX h\bho\bos\bst\bt f\bfo\bor\br a\ba r\bre\bem\bmo\bot\bte\be s\bsi\bit\bte\be
* 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 d\bdb\bbm\bm instead of h\bha\bas\bsh\bh if your system uses d\bdb\bbm\bm files instead of d\bdb\bb files.
+To find out what lookup tables Postfix supports, use the command "p\bpo\bos\bst\btc\bco\bon\bnf\bf -\b-m\bm".
-Execute the command "postmap /etc/postfix/transport" whenever you change the
+Execute the command "p\bpo\bos\bst\btm\bma\bap\bp /\b/e\bet\btc\bc/\b/p\bpo\bos\bst\btf\bfi\bix\bx/\b/t\btr\bra\ban\bns\bsp\bpo\bor\brt\bt" whenever you change the
transport table.
P\bPo\bos\bst\btf\bfi\bix\bx o\bon\bn a\ba d\bdi\bia\bal\blu\bup\bp m\bma\bac\bch\bhi\bin\bne\be
/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 "p\bpo\bos\bst\btc\bco\bon\bnf\bf s\bse\ben\bnd\bdm\bma\bai\bil\bl_\b_p\bpa\bat\bth\bh" 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:
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 "s\bse\ben\bnd\bdm\bma\bai\bil\bl -\b-q\bq" command every now and then while the dialup link is up,
so that newly-posted mail is flushed from the queue.
P\bPo\bos\bst\btf\bfi\bix\bx o\bon\bn h\bho\bos\bst\bts\bs w\bwi\bit\bth\bho\bou\but\bt a\ba r\bre\bea\bal\bl h\bho\bos\bst\btn\bna\bam\bme\be
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
=======================================================
# 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,
# 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.
#
--- /dev/null
+<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN"
+ "http://www.w3.org/TR/html4/loose.dtd">
+
+<html>
+
+<head>
+
+<title>Postfix CDB Howto</title>
+
+<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
+
+</head>
+
+<body>
+
+<h1><img src="postfix-logo.jpg" width="203" height="98" ALT="">Postfix CDB Howto</h1>
+
+<hr>
+
+<h2>Introduction</h2>
+
+<p> 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. </p>
+
+<p> Postfix CDB databases are specified as "cdb:<i>name</i>", where
+<i>name</i> 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 <a href="postmap.1.html">postmap(1)</a>
+or <a href="postalias.1.html">postalias(1)</a> command. The <a href="DATABASE_README.html">DATABASE_README</a> document has general
+information about Postfix databases. </p>
+
+<p> CDB support is available with Postfix 2.2 and later releases.
+This document describes how to build Postfix with CDB support. </p>
+
+<h2>Building Postfix with CDB</h2>
+
+<p> Postfix is compatible with two CDB implementations: </p>
+
+<ul>
+
+<li> <p> The original cdb library from Daniel Bernstein, available
+from <a href="http://cr.yp.to/cdb.html">http://cr.yp.to/cdb.html</a>, and </p>
+
+<li> <p> tinycdb (version 0.5 and later) from Michael Tokarev,
+available from <a href="http://www.corpit.ru/mjt/tinycdb.html">http://www.corpit.ru/mjt/tinycdb.html</a>. </p>
+
+</ul>
+
+<p> Tinycdb is preferred, since it is a bit faster, has additional
+useful functionality and is much simpler to use. </p>
+
+<p>To build Postfix after you have installed CDB, use something
+like: </p>
+
+<blockquote>
+<pre>
+% make tidy
+% CDB=../../../tinycdb-0.5
+% make -f Makefile.init makefiles "CCARGS=-DHAS_CDB -I$CDB" \
+ "AUXLIBS=$CDB/libcdb.a"
+% make
+</pre>
+for tinycdb, or alternatively, for the D.J.B. version:<br>
+<pre>
+% 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
+</pre>
+</blockquote>
+
+<p> 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 "<b>postmap -i</b>" (incremental record
+insertion) and "<b>postmap -d</b>" (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 <a href="verify.8.html">verify(8)</a> service. </p>
because something else happens. This is because commands such as
<a href="postmap.1.html">postmap(1)</a> or <a href="postalias.1.html">postalias(1)</a> overwrite existing files. If the update
fails in the middle then you have no usable database, and Postfix
-will stop working. </p>
+will stop working. This is not an issue with the CDB database type
+available with Postfix 2.2 and later, because <a href="CDB_README.html">CDB</a>
+database rebuilds are atomic. </p>
<p> With multi-file databases such as DBM, there is no simple
solution. With Berkeley DB and other "one file" databases, it is
<h2><a name="types">Postfix lookup table types</a> </h2>
<p> To find out what database types your Postfix system supports,
-use the "postconf -m" command. Here is a list of database types
+use the "<b>postconf -m</b>" command. Here is a list of database types
that are often supported: </p>
<blockquote>
table name as used in "btree:table" is the database file name
without the ".db" suffix. </dd>
+<dt> <b>cdb</b> </dt>
+
+<dd> A read-optimized structure with no support for incremental updates.
+Database files are created with the <a href="postmap.1.html">postmap(1)</a> or <a href="postalias.1.html">postalias(1)</a> 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. </dd>
+
<dt> <b>cidr</b> </dt>
<dd> A table that associates values with Classless Inter-Domain
</pre>
</blockquote>
-<p> Specify <B>dbm</b> instead of <b>hash</b> if your system uses
+<p> Specify <b>dbm</b> instead of <b>hash</b> if your system uses
<b>dbm</b> files instead of <b>db</b> files. To find out what map
types Postfix supports, use the command <b>postconf -m</b>. </p>
</pre>
</blockquote>
-<p> Specify <B>dbm</b> instead of <b>hash</b> if your system uses
+<p> Specify <b>dbm</b> instead of <b>hash</b> if your system uses
<b>dbm</b> files instead of <b>db</b> files. To find out what map
types Postfix supports, use the command <b>postconf -m</b>. </p>
Postfix installs when you download the Postfix source code via
<a href="http://www.postfix.org/">http://www.postfix.org/</a>. </p>
-<p> 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 <a href="BASIC_CONFIGURATION_README.html">BASIC_CONFIGURATION_README</a> document: </p>
+<p> You can use the command "<b>postconf -n</b>" 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 <a href="BASIC_CONFIGURATION_README.html">BASIC_CONFIGURATION_README</a> document: </p>
<blockquote>
<pre>
</blockquote>
<p> On some systems the alias database is not in /etc/aliases. To
-find out the location for your system, execute the command "postconf
-<a href="postconf.5.html#alias_maps">alias_maps</a>". </p>
+find out the location for your system, execute the command "<b>postconf
+<a href="postconf.5.html#alias_maps">alias_maps</a></b>". </p>
-<p> Execute the command "newaliases" whenever you change the aliases
-file. </p>
+<p> Execute the command "<b>newaliases</b>" whenever you change
+the aliases file. </p>
<h2><a name="firewall">Postfix email firewall/gateway</a></h2>
</p>
<p> Note: this example requires Postfix version 2.0 and later. To find
-out what Postfix version you have, execute the command "postconf
-<a href="postconf.5.html#mail_version">mail_version</a>". </p>
+out what Postfix version you have, execute the command "<b>postconf
+<a href="postconf.5.html#mail_version">mail_version</a></b>". </p>
<p> The solution is presented in multiple parts. This first part
gets rid of local mail delivery on the firewall, making the firewall
</ul>
-<p>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". </p>
+<p>Specify <b>dbm</b> instead of <b>hash</b> if your system uses
+<b>dbm</b> files instead of <b>db</b> files. To find out what lookup
+tables Postfix supports, use the command "<b>postconf -m</b>". </p>
-<p> Execute the command "postmap /etc/postfix/relay_recipients"
+<p> Execute the command "<b>postmap /etc/postfix/relay_recipients</b>"
whenever you change the relay_recipients table. </p>
-<p> Execute the command "postmap /etc/postfix/transport"
+<p> Execute the command "<b>postmap /etc/postfix/transport</b>"
whenever you change the transport table. </p>
<h2><a name="some_local">Delivering some but not all accounts
That's what Wietse does at work. </p>
<p> Note: this example requires Postfix version 2.0 and later. To find
-out what Postfix version you have, execute the command "postconf
-<a href="postconf.5.html#mail_version">mail_version</a>". </p>
+out what Postfix version you have, execute the command "<b>postconf
+<a href="postconf.5.html#mail_version">mail_version</a></b>". </p>
<p> The following example presents additional configuration. You
need to combine this with basic configuration information as
</ul>
-<p> 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". </p>
+<p> Specify <b>dbm</b> instead of <b>hash</b> if your system uses
+<b>dbm</b> files instead of <b>db</b> files. To find out what lookup
+tables Postfix supports, use the command "<b>postconf -m</b>". </p>
-<p> Execute the command "postmap /etc/postfix/transport" whenever
+<p> Execute the command "<b>postmap /etc/postfix/transport</b>" whenever
you edit the transport table. </p>
<h2><a name="backup">Configuring Postfix as MX host for a remote site</a></h2>
</ul>
-<p> 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". </p>
+<p> Specify <b>dbm</b> instead of <b>hash</b> if your system uses
+<b>dbm</b> files instead of <b>db</b> files. To find out what lookup
+tables Postfix supports, use the command "<b>postconf -m</b>". </p>
-<p> Execute the command "postmap /etc/postfix/transport" whenever
+<p> Execute the command "<b>postmap /etc/postfix/transport</b>" whenever
you change the transport table. </p>
<h2><a name="dialup">Postfix on a dialup machine</a></h2>
</pre>
<p> The exact location of the sendmail command is system-specific.
-Use the command "postconf <a href="postconf.5.html#sendmail_path">sendmail_path</a>" to find out where the
+Use the command "<b>postconf <a href="postconf.5.html#sendmail_path">sendmail_path</a></b>" to find out where the
Postfix sendmail command is located on your machine. </p>
<p> In order to find out if the mail queue is flushed, use something
</pre>
<p> If you have disabled <a href="#spontaneous_smtp">spontaneous
-SMTP mail delivery</a>, you also need to run the "sendmail -q"
+SMTP mail delivery</a>, you also need to run the "<b>sendmail -q</b>"
command every now and then while the dialup link is up, so that
newly-posted mail is flushed from the queue. </p>
<a href="postconf.5.html#transport_maps">transport_maps</a> = hash:/etc/postfix/transport
</pre>
-<p> Specify <B>dbm</b> instead of <b>hash</b> if your system uses
+<p> Specify <b>dbm</b> instead of <b>hash</b> if your system uses
<b>dbm</b> files instead of <b>db</b> files. To find out what map
types Postfix supports, use the command "<b>postconf -m</b>". </p>
that serves as input to the <a href="postmap.1.html"><b>postmap</b>(1)</a> command. The
result, an indexed file in <b>dbm</b> or <b>db</b> format, is used for
fast searching by the mail system. Execute the command
- <b>postmap /etc/postfix/access</b> in order to rebuild the
+ "<b>postmap /etc/postfix/access</b>" in order to rebuild the
indexed file after changing the access table.
When the table is provided via other means such as NIS,
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 "<b>hash</b>" lookup
- tables, some systems use "<b>dbm</b>". Use the command "<b>postconf</b>
+ all other clients in 1.2.3.0/24. Instead of <b>hash</b> lookup
+ tables, some systems use <b>dbm</b>. Use the command "<b>postconf</b>
<b>-m</b>" to find out what lookup tables Postfix supports on
your system.
<li> <a href="DB_README.html"> Berkeley DB Howto </a>
+<li> <a href="CDB_README.html"> CDB Howto </a>
+
<li> <a href="LDAP_README.html"> LDAP Howto </a>
<li> <a href="MYSQL_README.html"> MySQL Howto </a>
<i>file</i><b>_</b><i>type</i>
The database type. To find out what types are sup-
- ported, use the "<b>postconf -m" command.</b>
+ ported, use the "<b>postconf -m</b>" command.
- <b>The postalias</b> command can query any supported file
+ The <b>postalias</b> command can query any supported file
type, but it can create only the following file
types:
<i>file</i><b>_</b><i>name</i><b>.db</b>. This is available only on
systems with support for <b>db</b> databases.
- Use the command <b>postconf -m</b> to find out what types
- of database your Postfix installation can support.
-
When no <i>file</i><b>_</b><i>type</i> is specified, the software uses
the database type specified via the
<b><a href="postconf.5.html#default_database_type">default_database_type</a></b> configuration parameter. The
<i>file</i><b>_</b><i>type</i>
The database type. To find out what types are sup-
- ported, use the "<b>postconf -m" command.</b>
+ ported, use the "<b>postconf -m</b>" command.
- <b>The postmap</b> command can query any supported file
+ The <b>postmap</b> command can query any supported file
type, but it can create only the following file
types:
<i>file</i><b>_</b><i>name</i><b>.db</b>. This is available only on
systems with support for <b>db</b> databases.
- Use the command <b>postconf -m</b> to find out what types
- of database your Postfix installation can support.
-
When no <i>file</i><b>_</b><i>type</i> is specified, the software uses
the database type specified via the
<b><a href="postconf.5.html#default_database_type">default_database_type</a></b> configuration parameter.
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:
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.
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:
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.
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
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.
--- /dev/null
+<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN"
+ "http://www.w3.org/TR/html4/loose.dtd">
+
+<html>
+
+<head>
+
+<title>Postfix CDB Howto</title>
+
+<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
+
+</head>
+
+<body>
+
+<h1><img src="postfix-logo.jpg" width="203" height="98" ALT="">Postfix CDB Howto</h1>
+
+<hr>
+
+<h2>Introduction</h2>
+
+<p> 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. </p>
+
+<p> Postfix CDB databases are specified as "cdb:<i>name</i>", where
+<i>name</i> 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. </p>
+
+<p> CDB support is available with Postfix 2.2 and later releases.
+This document describes how to build Postfix with CDB support. </p>
+
+<h2>Building Postfix with CDB</h2>
+
+<p> Postfix is compatible with two CDB implementations: </p>
+
+<ul>
+
+<li> <p> The original cdb library from Daniel Bernstein, available
+from http://cr.yp.to/cdb.html, and </p>
+
+<li> <p> tinycdb (version 0.5 and later) from Michael Tokarev,
+available from http://www.corpit.ru/mjt/tinycdb.html. </p>
+
+</ul>
+
+<p> Tinycdb is preferred, since it is a bit faster, has additional
+useful functionality and is much simpler to use. </p>
+
+<p>To build Postfix after you have installed CDB, use something
+like: </p>
+
+<blockquote>
+<pre>
+% make tidy
+% CDB=../../../tinycdb-0.5
+% make -f Makefile.init makefiles "CCARGS=-DHAS_CDB -I$CDB" \
+ "AUXLIBS=$CDB/libcdb.a"
+% make
+</pre>
+for tinycdb, or alternatively, for the D.J.B. version:<br>
+<pre>
+% 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
+</pre>
+</blockquote>
+
+<p> 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 "<b>postmap -i</b>" (incremental record
+insertion) and "<b>postmap -d</b>" (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. </p>
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. </p>
+will stop working. This is not an issue with the CDB database type
+available with Postfix 2.2 and later, because <a href="CDB_README.html">CDB</a>
+database rebuilds are atomic. </p>
<p> With multi-file databases such as DBM, there is no simple
solution. With Berkeley DB and other "one file" databases, it is
<h2><a name="types">Postfix lookup table types</a> </h2>
<p> To find out what database types your Postfix system supports,
-use the "postconf -m" command. Here is a list of database types
+use the "<b>postconf -m</b>" command. Here is a list of database types
that are often supported: </p>
<blockquote>
table name as used in "btree:table" is the database file name
without the ".db" suffix. </dd>
+<dt> <b>cdb</b> </dt>
+
+<dd> 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. </dd>
+
<dt> <b>cidr</b> </dt>
<dd> A table that associates values with Classless Inter-Domain
../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 \
../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 \
../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) $? >$@
../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) $? >$@
</pre>
</blockquote>
-<p> Specify <B>dbm</b> instead of <b>hash</b> if your system uses
+<p> Specify <b>dbm</b> instead of <b>hash</b> if your system uses
<b>dbm</b> files instead of <b>db</b> files. To find out what map
types Postfix supports, use the command <b>postconf -m</b>. </p>
</pre>
</blockquote>
-<p> Specify <B>dbm</b> instead of <b>hash</b> if your system uses
+<p> Specify <b>dbm</b> instead of <b>hash</b> if your system uses
<b>dbm</b> files instead of <b>db</b> files. To find out what map
types Postfix supports, use the command <b>postconf -m</b>. </p>
Postfix installs when you download the Postfix source code via
http://www.postfix.org/. </p>
-<p> 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: </p>
+<p> You can use the command "<b>postconf -n</b>" 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: </p>
<blockquote>
<pre>
</blockquote>
<p> 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". </p>
+find out the location for your system, execute the command "<b>postconf
+alias_maps</b>". </p>
-<p> Execute the command "newaliases" whenever you change the aliases
-file. </p>
+<p> Execute the command "<b>newaliases</b>" whenever you change
+the aliases file. </p>
<h2><a name="firewall">Postfix email firewall/gateway</a></h2>
</p>
<p> Note: this example requires Postfix version 2.0 and later. To find
-out what Postfix version you have, execute the command "postconf
-mail_version". </p>
+out what Postfix version you have, execute the command "<b>postconf
+mail_version</b>". </p>
<p> The solution is presented in multiple parts. This first part
gets rid of local mail delivery on the firewall, making the firewall
</ul>
-<p>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". </p>
+<p>Specify <b>dbm</b> instead of <b>hash</b> if your system uses
+<b>dbm</b> files instead of <b>db</b> files. To find out what lookup
+tables Postfix supports, use the command "<b>postconf -m</b>". </p>
-<p> Execute the command "postmap /etc/postfix/relay_recipients"
+<p> Execute the command "<b>postmap /etc/postfix/relay_recipients</b>"
whenever you change the relay_recipients table. </p>
-<p> Execute the command "postmap /etc/postfix/transport"
+<p> Execute the command "<b>postmap /etc/postfix/transport</b>"
whenever you change the transport table. </p>
<h2><a name="some_local">Delivering some but not all accounts
That's what Wietse does at work. </p>
<p> Note: this example requires Postfix version 2.0 and later. To find
-out what Postfix version you have, execute the command "postconf
-mail_version". </p>
+out what Postfix version you have, execute the command "<b>postconf
+mail_version</b>". </p>
<p> The following example presents additional configuration. You
need to combine this with basic configuration information as
</ul>
-<p> 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". </p>
+<p> Specify <b>dbm</b> instead of <b>hash</b> if your system uses
+<b>dbm</b> files instead of <b>db</b> files. To find out what lookup
+tables Postfix supports, use the command "<b>postconf -m</b>". </p>
-<p> Execute the command "postmap /etc/postfix/transport" whenever
+<p> Execute the command "<b>postmap /etc/postfix/transport</b>" whenever
you edit the transport table. </p>
<h2><a name="backup">Configuring Postfix as MX host for a remote site</a></h2>
</ul>
-<p> 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". </p>
+<p> Specify <b>dbm</b> instead of <b>hash</b> if your system uses
+<b>dbm</b> files instead of <b>db</b> files. To find out what lookup
+tables Postfix supports, use the command "<b>postconf -m</b>". </p>
-<p> Execute the command "postmap /etc/postfix/transport" whenever
+<p> Execute the command "<b>postmap /etc/postfix/transport</b>" whenever
you change the transport table. </p>
<h2><a name="dialup">Postfix on a dialup machine</a></h2>
</pre>
<p> The exact location of the sendmail command is system-specific.
-Use the command "postconf sendmail_path" to find out where the
+Use the command "<b>postconf sendmail_path</b>" to find out where the
Postfix sendmail command is located on your machine. </p>
<p> In order to find out if the mail queue is flushed, use something
</pre>
<p> If you have disabled <a href="#spontaneous_smtp">spontaneous
-SMTP mail delivery</a>, you also need to run the "sendmail -q"
+SMTP mail delivery</a>, you also need to run the "<b>sendmail -q</b>"
command every now and then while the dialup link is up, so that
newly-posted mail is flushed from the queue. </p>
transport_maps = hash:/etc/postfix/transport
</pre>
-<p> Specify <B>dbm</b> instead of <b>hash</b> if your system uses
+<p> Specify <b>dbm</b> instead of <b>hash</b> if your system uses
<b>dbm</b> files instead of <b>db</b> files. To find out what map
types Postfix supports, use the command "<b>postconf -m</b>". </p>
# 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
# 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.
#
RFC
Sendmail's
Wietse
+cdb
cf
com
db
userid
username
Autoreplies
+CDB
DBM
Howto
MAILDROP
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 \
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 \
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
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
* 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"
#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 *);
--- /dev/null
+/*++
+/* NAME
+/* mkmap_cdb 3
+/* SUMMARY
+/* create or open database, CDB style
+/* SYNOPSIS
+/* #include <mkmap.h>
+/*
+/* 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 <mjt@tls.msk.ru> based on mkmap_db by
+/* Wietse Venema
+/* IBM T.J. Watson Research
+/* P.O. Box 704
+/* Yorktown Heights, NY 10598, USA
+/*--*/
+
+/* System library. */
+
+#include <sys_defs.h>
+
+#ifdef HAS_CDB
+
+/* Utility library. */
+
+#include <mymalloc.h>
+#include <dict.h>
+
+/* Application-specific. */
+
+#include "mkmap.h"
+#include <dict_cdb.h>
+
+/* 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 */
#include <msg.h>
#include <dict.h>
#include <dict_db.h>
+#include <dict_cdb.h>
#include <dict_dbm.h>
#include <sigdelay.h>
#include <mymalloc.h>
} 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
/* 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:
/* 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.
/* 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:
/* 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.
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 \
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 \
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 \
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
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
--- /dev/null
+/*++
+/* NAME
+/* dict_cdb 3
+/* SUMMARY
+/* dictionary manager interface to CDB files
+/* SYNOPSIS
+/* #include <dict_cdb.h>
+/*
+/* 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 <mjt@tls.msk.ru> 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 <sys/stat.h>
+#include <limits.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdio.h>
+
+/* 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 <cdb.h>
+#ifndef TINYCDB_VERSION
+#include <cdb_make.h>
+#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 */
--- /dev/null
+#ifndef _DICT_CDB_H_INCLUDED_
+#define _DICT_CDB_H_INCLUDED_
+
+/*++
+/* NAME
+/* dict_cdb 3h
+/* SUMMARY
+/* dictionary manager interface to CDB files
+/* SYNOPSIS
+/* #include <dict_cdb.h>
+/* DESCRIPTION
+/* .nf
+
+ /*
+ * Utility library.
+ */
+#include <dict.h>
+
+ /*
+ * 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_ */
#include <mymalloc.h>
#include <msg.h>
#include <dict.h>
+#include <dict_cdb.h>
#include <dict_env.h>
#include <dict_unix.h>
#include <dict_tcp.h>
} 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
/* 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:
int ch;
for (cp = string; (ch = *(unsigned char *) cp) != 0; cp++)
- if (!ISPRINT(ch))
+ if (!ISASCII(ch) || !ISPRINT(ch))
*cp = replacement;
return (string);
}