<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> <HTML ><HEAD ><link rel='stylesheet' type='text/css' href='manpage.css'> <!-- $Id: maildropgdbm.sgml,v 1.2 2004/07/27 01:36:41 mrsam Exp $ --> <!-- Copyright 1998 - 2001 Double Precision, Inc. See COPYING for --> <!-- distribution information. --> <meta name="MSSmartTagsPreventParsing" content="TRUE"> <link rel="icon" href="icon.gif" type="image/gif" /> <TITLE >maildropgdbm</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"></HEAD ><BODY CLASS="REFENTRY" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><H1 ><A NAME="MAILDROPGDBM" ></A >maildropgdbm</H1 ><DIV CLASS="REFNAMEDIV" ><A NAME="AEN10" ></A ><H2 >Name</H2 >maildropgdbm -- GDBM/DB support in maildrop</DIV ><DIV CLASS="REFSYNOPSISDIV" ><A NAME="AEN13" ></A ><H2 >Synopsis</H2 ><DIV CLASS="INFORMALEXAMPLE" ><P ></P ><A NAME="AEN14" ></A ><TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="PROGRAMLISTING" >gdbmopen(filename, mode) gdbmclose gdbmfetch(key [,default]) gdbmstore(key,value)</PRE ></TD ></TR ></TABLE ><P ></P ></DIV ></DIV ><DIV CLASS="REFSECT1" ><A NAME="AEN16" ></A ><H2 >DESCRIPTION</H2 ><P >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.</P ><P >GDBM support in <B CLASS="COMMAND" >maildrop</B > is optional, and may not be available to you.</P ><P >GDBM support in <B CLASS="COMMAND" >maildrop</B > 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.</P ><P >To see whether GDBM or DB support is used, run the command "<B CLASS="COMMAND" >maildrop -v"</B >.</P ><P >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.</P ><P >A GDBM file contains a list of key/value pairs. All keys in the GDBM file are unique. After storing an arbitary key/value pair in the GDBM file, the value associated with the given key can be quickly located and retrieved.</P ><DIV CLASS="REFSECT2" ><A NAME="AEN27" ></A ><H3 >gdbmclose - close gdbm file</H3 ><A NAME="AEN29" ></A ><BLOCKQUOTE CLASS="BLOCKQUOTE" ><DIV CLASS="INFORMALEXAMPLE" ><P ></P ><A NAME="AEN30" ></A ><TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="PROGRAMLISTING" >gdbmclose</PRE ></TD ></TR ></TABLE ><P ></P ></DIV ></BLOCKQUOTE ><P >This function closes the current GDBM file.</P ></DIV ><DIV CLASS="REFSECT2" ><A NAME="AEN33" ></A ><H3 >gdbmfetch - retrieve data</H3 ><A NAME="AEN35" ></A ><BLOCKQUOTE CLASS="BLOCKQUOTE" ><DIV CLASS="INFORMALEXAMPLE" ><P ></P ><A NAME="AEN36" ></A ><TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="PROGRAMLISTING" >gdbmfetch (<VAR CLASS="REPLACEABLE" >key</VAR > [, <VAR CLASS="REPLACEABLE" >options</VAR >] [, <VAR CLASS="REPLACEABLE" >default</VAR >])</PRE ></TD ></TR ></TABLE ><P ></P ></DIV ></BLOCKQUOTE ><P >This function retrieves the data for the given key. <VAR CLASS="REPLACEABLE" >key</VAR > is the key to retrieve. The <B CLASS="COMMAND" >gdbmfetch</B > function returns the data associated with this key. If the key does not exist in the GDBM file, <B CLASS="COMMAND" >gdbmfetch</B > returns the <B CLASS="COMMAND" >default</B > argument. If the <B CLASS="COMMAND" >default</B > argument is not specified, <B CLASS="COMMAND" >gdbmfetch</B > returns empty text. Please note that the <B CLASS="COMMAND" >default</B > argument is not actually evaluated unless the key does not exist in the GDBM file.</P ><P >The <VAR CLASS="REPLACEABLE" >options</VAR > argument specifies additional <B CLASS="COMMAND" >maildrop</B > value-added features. The following functionality is not available in the GDBM library, but is rather provided by <B CLASS="COMMAND" >maildrop</B >.</P ><P >If the <VAR CLASS="REPLACEABLE" >options</VAR > 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", <B CLASS="COMMAND" >maildrop</B > will then attempt to look up the key "user@". If that key is also not found, <B CLASS="COMMAND" >maildrop</B > finally looks up the key "domain".</P ><P >If "domain" is also not found, and domain is of the form "<TT CLASS="LITERAL" >a.b.c.d.tld</TT >" (with variable number of period-separated sections), <B CLASS="COMMAND" >maildrop</B > then attempts to look up the key "<TT CLASS="LITERAL" >b.c.d.tld</TT >". If that key is not found, <B CLASS="COMMAND" >maildrop</B > tries "<TT CLASS="LITERAL" >c.d.tld</TT >", and so on, until a key is found, or there are no more subdomains to remove, at which point <B CLASS="COMMAND" >gdbmfetch</B > will return either the <B CLASS="COMMAND" >default</B > argument, or empty text.</P ><P >If the <VAR CLASS="REPLACEABLE" >options</VAR > argument is set to "D", and the key could not be found in the GDBM database, and the key is of the form "<TT CLASS="LITERAL" >a.b.c.d.tld</TT >" (with variable number of period-separated sections), <B CLASS="COMMAND" >maildrop</B > will also attempt to look up keys for successive higher-level domains in the GDBM database.</P ><DIV CLASS="NOTE" ><P ></P ><TABLE CLASS="NOTE" WIDTH="100%" BORDER="0" ><TR ><TD WIDTH="25" ALIGN="CENTER" VALIGN="TOP" >NOTE:</TD ><TD ALIGN="LEFT" VALIGN="TOP" ><P >GDBM databases are case sensitive. Make sure that the GDBM database is created using lowercase letters only, and use the <A HREF="maildropfilter.html#tolower" TARGET="_top" ><B CLASS="COMMAND" >tolower</B ></A > function to convert the key to lowercase.</P ></TD ></TR ></TABLE ></DIV ><P >If the <VAR CLASS="REPLACEABLE" >options</VAR > argument is "<TT CLASS="LITERAL" >I</TT >", 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), <B CLASS="COMMAND" >maildrop</B > 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.</P ><DIV CLASS="NOTE" ><P ></P ><TABLE CLASS="NOTE" WIDTH="100%" BORDER="0" ><TR ><TD WIDTH="25" ALIGN="CENTER" VALIGN="TOP" >NOTE:</TD ><TD ALIGN="LEFT" VALIGN="TOP" ><P >These features are implemented by brute force: if the query doesn't 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.</P ></TD ></TR ></TABLE ></DIV ></DIV ><DIV CLASS="REFSECT2" ><A NAME="AEN79" ></A ><H3 >gdbmopen - open gdbm file</H3 ><A NAME="AEN81" ></A ><BLOCKQUOTE CLASS="BLOCKQUOTE" ><DIV CLASS="INFORMALEXAMPLE" ><P ></P ><A NAME="AEN82" ></A ><TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="PROGRAMLISTING" >gdbmopen (<VAR CLASS="REPLACEABLE" >file</VAR > [, <VAR CLASS="REPLACEABLE" >mode</VAR >])</PRE ></TD ></TR ></TABLE ><P ></P ></DIV ></BLOCKQUOTE ><P ><B CLASS="COMMAND" >gdbmopen</B > opens the indicated GDBM file. The optional second argument specifies the following:</P ><P ></P ><DIV CLASS="VARIABLELIST" ><DL ><DT >"R"</DT ><DD ><P >Open this GDBM file for reading.</P ></DD ><DT >"W"</DT ><DD ><P >Open this GDBM file for reading and writing.</P ></DD ><DT >"C"</DT ><DD ><P >Open this GDBM file for reading and writing. If the GBDM file doesn't exist, create it.</P ></DD ><DT >"N"</DT ><DD ><P >Create a new GDBM file. If the file exists, the existing file is deleted. The file is opened for reading and writing.</P ></DD ></DL ></DIV ><P >The <VAR CLASS="REPLACEABLE" >mode</VAR > argument defaults to <TT CLASS="LITERAL" >"R"</TT > is used. In embedded mode, only <TT CLASS="LITERAL" >"R"</TT > is allowed.</P ><P >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 <A HREF="maildropfilter.html#flock" TARGET="_top" ><B CLASS="COMMAND" >flock</B ></A > or <A HREF="maildropfilter.html#dotlock" TARGET="_top" ><B CLASS="COMMAND" >dotlock</B ></A > is highly recommended.</P ><P >In delivery mode, <B CLASS="COMMAND" >maildrop</B > runs from the recipient's home directory. Keep that in mind while specifying the filename.</P ><P >The gdbmopen function returns 0 if the GDBM file was succesfully opened, non-zero otherwise.</P ></DIV ><DIV CLASS="REFSECT2" ><A NAME="AEN117" ></A ><H3 >gdbmstore - store data</H3 ><A NAME="AEN119" ></A ><BLOCKQUOTE CLASS="BLOCKQUOTE" ><DIV CLASS="INFORMALEXAMPLE" ><P ></P ><A NAME="AEN120" ></A ><TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="PROGRAMLISTING" >gdbmstore(<VAR CLASS="REPLACEABLE" >key</VAR >, <VAR CLASS="REPLACEABLE" >value</VAR >)</PRE ></TD ></TR ></TABLE ><P ></P ></DIV ></BLOCKQUOTE ><P ><VAR CLASS="REPLACEABLE" >key</VAR > is the key value to store in the GDBM file. <VAR CLASS="REPLACEABLE" >value</VAR > is the value to store. If <VAR CLASS="REPLACEABLE" >key</VAR > already exists in the GDBM file, <VAR CLASS="REPLACEABLE" >value</VAR > replacest the old value. The <B CLASS="COMMAND" >gdbmstore</B > function is only permitted if the GDBM file is opened for writing. If <VAR CLASS="REPLACEABLE" >gdbmopen</VAR > opened the GDBM file for reading only, <B CLASS="COMMAND" >gdbmstore</B > will return -1. Otherwise, <B CLASS="COMMAND" >gdbmstore</B > returns 0.</P ></DIV ></DIV ></BODY ></HTML >