1 /* $Cambridge: exim/src/src/lookups/dbmdb.c,v 1.5 2007/01/08 10:50:19 ph10 Exp $ */
3 /*************************************************
4 * Exim - an Internet mail transport agent *
5 *************************************************/
7 /* Copyright (c) University of Cambridge 1995 - 2007 */
8 /* See the file NOTICE for conditions of use and distribution. */
11 #include "lf_functions.h"
15 /*************************************************
17 *************************************************/
19 /* See local README for interface description */
22 dbmdb_open(uschar *filename, uschar **errmsg)
25 EXIM_DBOPEN(filename, O_RDONLY, 0, &yield);
28 int save_errno = errno;
29 *errmsg = string_open_failed(errno, "%s as a %s file", filename, EXIM_DBTYPE);
37 /*************************************************
39 *************************************************/
41 /* This needs to know more about the underlying files than is good for it!
42 We need to know what the real file names are in order to check the owners and
43 modes. If USE_DB is set, we know it is Berkeley DB, which uses an unmodified
44 file name. If USE_TDB or USE_GDBM is set, we know it is tdb or gdbm, which do
45 the same. Otherwise, for safety, we have to check for x.db or x.dir and x.pag.
49 dbmdb_check(void *handle, uschar *filename, int modemask, uid_t *owners,
50 gid_t *owngroups, uschar **errmsg)
53 handle = handle; /* Keep picky compilers happy */
55 #if defined(USE_DB) || defined(USE_TDB) || defined(USE_GDBM)
56 rc = lf_check_file(-1, filename, S_IFREG, modemask, owners, owngroups,
60 uschar filebuffer[256];
61 (void)sprintf(CS filebuffer, "%.250s.db", filename);
62 rc = lf_check_file(-1, filebuffer, S_IFREG, modemask, owners, owngroups,
64 if (rc < 0) /* stat() failed */
66 (void)sprintf(CS filebuffer, "%.250s.dir", filename);
67 rc = lf_check_file(-1, filebuffer, S_IFREG, modemask, owners, owngroups,
69 if (rc == 0) /* x.dir was OK */
71 (void)sprintf(CS filebuffer, "%.250s.pag", filename);
72 rc = lf_check_file(-1, filebuffer, S_IFREG, modemask, owners, owngroups,
84 /*************************************************
86 *************************************************/
88 /* See local README for interface description. This function adds 1 to
89 the keylength in order to include the terminating zero. */
92 dbmdb_find(void *handle, uschar *filename, uschar *keystring, int length,
93 uschar **result, uschar **errmsg, BOOL *do_cache)
95 EXIM_DB *d = (EXIM_DB *)handle;
98 filename = filename; /* Keep picky compilers happy */
102 EXIM_DATUM_INIT(key); /* Some DBM libraries require datums to */
103 EXIM_DATUM_INIT(data); /* be cleared before use. */
104 EXIM_DATUM_DATA(key) = CS keystring;
105 EXIM_DATUM_SIZE(key) = length + 1;
107 if (EXIM_DBGET(d, key, data))
109 *result = string_copyn(US EXIM_DATUM_DATA(data), EXIM_DATUM_SIZE(data));
110 EXIM_DATUM_FREE(data); /* Some DBM libraries need a free() call */
118 /*************************************************
119 * Find entry point - no zero on key *
120 *************************************************/
122 /* See local README for interface description */
125 dbmnz_find(void *handle, uschar *filename, uschar *keystring, int length,
126 uschar **result, uschar **errmsg, BOOL *do_cache)
128 return dbmdb_find(handle, filename, keystring, length-1, result, errmsg,
134 /*************************************************
135 * Close entry point *
136 *************************************************/
138 /* See local README for interface description */
141 dbmdb_close(void *handle)
143 EXIM_DBCLOSE((EXIM_DB *)handle);
146 /* End of lookups/dbmdb.c */