The gdbm family of functions provides access to the GDBM library - a library of routines that manage simple database files. The library provides a way of quickly storing and looking up key/data pairs.
GDBM support in
is optional, and may not be available to you.
GDBM support in
can optionally be implemented using the DB library. This option is selected by the system administrator. If this is the case, these functions still work exactly as described below, except that they will operate on DB hash files, instead of GDBM files.
To see whether GDBM or DB support is used, run the command "maildrop -v".
GDBM support is minimal, and simplistic. A filter file may have only one gdbm file open at the same time. However, the filter file can close the current gdbm file, and open another one. If another filter file is included using the include statement, the included filter file may open its own, separate, gdbm file.
A GDBM file contains a list of key/value pairs. All keys in the GDBM file are unique. After storing an arbitrary key/value pair in the GDBM file, the value associated with the given key can be quickly located and retrieved.
gdbmfetch (key [, options] [, default])
This function retrieves the data for the given key.
is the key to retrieve. The
function returns the data associated with this key. If the key does not exist in the GDBM file,
argument. If the
argument is not specified,
returns empty text. Please note that the
argument is not actually evaluated unless the key does not exist in the GDBM file.
argument specifies additional
value-added features. The following functionality is not available in the GDBM library, but is rather provided by
argument is set to "D", and the key could not be found in the GDBM database, and the key is of the form "user@domain",
will then attempt to look up the key "user@". If that key is also not found,
finally looks up the key "domain".
If "domain" is also not found, and domain is of the form "a.b.c.d.tld" (with variable number of period-separated sections),
then attempts to look up the key "b.c.d.tld". If that key is not found,
tries "c.d.tld", and so on, until a key is found, or there are no more subdomains to remove, at which point
will return either the
argument, or empty text.
argument is set to "D", and the key could not be found in the GDBM database, and the key is of the form "a.b.c.d.tld" (with variable number of period-separated sections),
will also attempt to look up keys for successive higher-level domains in the GDBM database.
GDBM databases are case sensitive. Make sure that the GDBM database is created using lowercase letters only, and use the
function to convert the key to lowercase.
argument is "I", and the key is not in the GDBM database, and the key is of the form "w.x.y.z" (with variable number of period-separated sections),
then tries to look up the key "w.x.y", then "w.x", until a key is found, or there are no more sections to remove. Use this feature to look up IP-address based GDBM lists.
These features are implemented by brute force: if the query doesnt succeed, try again. Take note of potential denial-of-service attacks where key is set to a long text string consisting mostly of periods, which will result in numerous GDBM queries that will take an excessive amount of time to complete.
gdbmopen (file [, mode])
opens the indicated GDBM file. The optional second argument specifies the following:
Open this GDBM file for reading.
Open this GDBM file for reading and writing.
Open this GDBM file for reading and writing. If the GBDM file doesnt exist, create it.
Create a new GDBM file. If the file exists, the existing file is deleted. The file is opened for reading and writing.
argument defaults to
is used. In embedded mode, only
The GDBM library allows multiple processes to read the same GDBM file at the same time, but it does not allow multiple access when the GDBM file is open for writing. Using
is highly recommended.
In delivery mode,
runs from the recipients home directory. Keep that in mind while specifying the filename.
The gdbmopen function returns 0 if the GDBM file was successfully opened, non-zero otherwise.