1 /*************************************************
2 * Exim - an Internet mail transport agent *
3 *************************************************/
5 /* Copyright (c) University of Cambridge 1995 - 2009 */
6 /* See the file NOTICE for conditions of use and distribution. */
8 /* This header file contains macro definitions so that a variety of DBM
9 libraries can be used by Exim. Nigel Metheringham provided the original set for
10 Berkeley DB 1.x in native mode and ndbm. Subsequently, versions for Berkeley DB
11 2.x and 3.x were added. Later still, support for tdb was added, courtesy of
12 James Antill. Most recently, support for native mode gdbm was added, with code
13 from Pierre A. Humblet, so Exim could be made to work with Cygwin.
15 For convenience, the definitions of the structures used in the various hints
16 databases are also kept in this file, which is used by the maintenance
17 utilities as well as the main Exim binary. */
22 /* ************************* tdb interface ************************ */
27 #define EXIM_DB TDB_CONTEXT
29 /* Cursor type: tdb uses the previous "key" in _nextkey() (really it wants
30 tdb_traverse to be called) */
31 #define EXIM_CURSOR TDB_DATA
33 /* The datum type used for queries */
34 #define EXIM_DATUM TDB_DATA
36 /* Some text for messages */
37 #define EXIM_DBTYPE "tdb"
39 /* Access functions */
41 /* EXIM_DBOPEN - sets *dbpp to point to an EXIM_DB, NULL if failed */
42 #define EXIM_DBOPEN__(name, dirname, flags, mode, dbpp) \
43 *(dbpp) = tdb_open(CS name, 0, TDB_DEFAULT, flags, mode)
45 /* EXIM_DBGET - returns TRUE if successful, FALSE otherwise */
46 #define EXIM_DBGET(db, key, data) \
47 (data = tdb_fetch(db, key), data.dptr != NULL)
49 /* EXIM_DBPUT - returns nothing useful, assumes replace mode */
50 #define EXIM_DBPUT(db, key, data) \
51 tdb_store(db, key, data, TDB_REPLACE)
53 /* EXIM_DBPUTB - non-overwriting for use by dbmbuild */
54 #define EXIM_DBPUTB(db, key, data) \
55 tdb_store(db, key, data, TDB_INSERT)
57 /* Returns from EXIM_DBPUTB */
59 #define EXIM_DBPUTB_OK 0
60 #define EXIM_DBPUTB_DUP (-1)
63 #define EXIM_DBDEL(db, key) tdb_delete(db, key)
65 /* EXIM_DBCREATE_CURSOR - initialize for scanning operation */
66 #define EXIM_DBCREATE_CURSOR(db, cursor) { \
67 *(cursor) = store_malloc(sizeof(TDB_DATA)); (*(cursor))->dptr = NULL; }
69 /* EXIM_DBSCAN - This is complicated because we have to free the last datum
70 free() must not die when passed NULL */
71 #define EXIM_DBSCAN(db, key, data, first, cursor) \
72 (key = (first ? tdb_firstkey(db) : tdb_nextkey(db, *(cursor))), \
73 free((cursor)->dptr), *(cursor) = key, \
76 /* EXIM_DBDELETE_CURSOR - terminate scanning operation. */
77 #define EXIM_DBDELETE_CURSOR(cursor) free(cursor)
80 #define EXIM_DBCLOSE__(db) tdb_close(db)
82 /* Datum access types - these are intended to be assignable */
84 #define EXIM_DATUM_SIZE(datum) (datum).dsize
85 #define EXIM_DATUM_DATA(datum) (datum).dptr
87 /* Free the stuff inside the datum. */
89 #define EXIM_DATUM_FREE(datum) (free((datum).dptr), (datum).dptr = NULL)
91 /* No initialization is needed. */
93 #define EXIM_DATUM_INIT(datum)
97 /********************* Berkeley db native definitions **********************/
104 /* We can distinguish between versions 1.x and 2.x/3.x by looking for a
105 definition of DB_VERSION_STRING, which is present in versions 2.x onwards. */
107 #ifdef DB_VERSION_STRING
109 /* The API changed (again!) between the 2.x and 3.x versions */
111 #if DB_VERSION_MAJOR >= 3
113 /***************** Berkeley db 3.x/4.x native definitions ******************/
116 #if DB_VERSION_MAJOR > 4 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 1)
117 # define EXIM_DB DB_ENV
118 /* Cursor type, for scanning */
119 # define EXIM_CURSOR DBC
121 /* The datum type used for queries */
122 # define EXIM_DATUM DBT
124 /* Some text for messages */
125 # define EXIM_DBTYPE "db (v4.1+)"
127 /* Only more-recent versions. 5+ ? */
128 # ifndef DB_FORCESYNC
129 # define DB_FORCESYNC 0
133 /* Access functions */
135 /* EXIM_DBOPEN - sets *dbpp to point to an EXIM_DB, NULL if failed. The
136 API changed for DB 4.1. - and we also starting using the "env" with a
137 specified working dir, to avoid the DBCONFIG file trap. */
139 # define ENV_TO_DB(env) ((DB *)((env)->app_private))
141 # define EXIM_DBOPEN__(name, dirname, flags, mode, dbpp) \
142 if ( db_env_create(dbpp, 0) != 0 \
143 || ((*dbpp)->set_errcall(*dbpp, dbfn_bdb_error_callback), 0) \
144 || (*dbpp)->open(*dbpp, CS dirname, DB_CREATE|DB_INIT_MPOOL|DB_PRIVATE, 0) != 0\
147 else if (db_create((DB **) &((*dbpp)->app_private), *dbpp, 0) != 0) \
149 ((DB_ENV *)(*dbpp))->close((DB_ENV *)(*dbpp), 0); \
152 else if (ENV_TO_DB(*dbpp)->open(ENV_TO_DB(*dbpp), NULL, CS name, NULL, \
153 (flags) == O_RDONLY ? DB_UNKNOWN : DB_HASH, \
154 (flags) == O_RDONLY ? DB_RDONLY : DB_CREATE, \
158 ENV_TO_DB(*dbpp)->close(ENV_TO_DB(*dbpp), 0); \
159 ((DB_ENV *)(*dbpp))->close((DB_ENV *)(*dbpp), 0); \
163 /* EXIM_DBGET - returns TRUE if successful, FALSE otherwise */
164 # define EXIM_DBGET(db, key, data) \
165 (ENV_TO_DB(db)->get(ENV_TO_DB(db), NULL, &key, &data, 0) == 0)
167 /* EXIM_DBPUT - returns nothing useful, assumes replace mode */
168 # define EXIM_DBPUT(db, key, data) \
169 ENV_TO_DB(db)->put(ENV_TO_DB(db), NULL, &key, &data, 0)
171 /* EXIM_DBPUTB - non-overwriting for use by dbmbuild */
172 # define EXIM_DBPUTB(db, key, data) \
173 ENV_TO_DB(db)->put(ENV_TO_DB(db), NULL, &key, &data, DB_NOOVERWRITE)
175 /* Return values from EXIM_DBPUTB */
177 # define EXIM_DBPUTB_OK 0
178 # define EXIM_DBPUTB_DUP DB_KEYEXIST
181 # define EXIM_DBDEL(db, key) ENV_TO_DB(db)->del(ENV_TO_DB(db), NULL, &key, 0)
183 /* EXIM_DBCREATE_CURSOR - initialize for scanning operation */
185 # define EXIM_DBCREATE_CURSOR(db, cursor) \
186 ENV_TO_DB(db)->cursor(ENV_TO_DB(db), NULL, cursor, 0)
188 /* EXIM_DBSCAN - returns TRUE if data is returned, FALSE at end */
189 # define EXIM_DBSCAN(db, key, data, first, cursor) \
190 ((cursor)->c_get(cursor, &key, &data, \
191 (first? DB_FIRST : DB_NEXT)) == 0)
193 /* EXIM_DBDELETE_CURSOR - terminate scanning operation */
194 # define EXIM_DBDELETE_CURSOR(cursor) \
195 (cursor)->c_close(cursor)
198 # define EXIM_DBCLOSE__(db) \
199 (ENV_TO_DB(db)->close(ENV_TO_DB(db), 0) , ((DB_ENV *)(db))->close((DB_ENV *)(db), DB_FORCESYNC))
201 /* Datum access types - these are intended to be assignable. */
203 # define EXIM_DATUM_SIZE(datum) (datum).size
204 # define EXIM_DATUM_DATA(datum) (datum).data
206 /* The whole datum structure contains other fields that must be cleared
207 before use, but we don't have to free anything after reading data. */
209 # define EXIM_DATUM_INIT(datum) memset(&datum, 0, sizeof(datum))
210 # define EXIM_DATUM_FREE(datum)
216 /* Cursor type, for scanning */
217 # define EXIM_CURSOR DBC
219 /* The datum type used for queries */
220 # define EXIM_DATUM DBT
222 /* Some text for messages */
223 # define EXIM_DBTYPE "db (v3/4)"
225 /* Access functions */
227 /* EXIM_DBOPEN - sets *dbpp to point to an EXIM_DB, NULL if failed. */
229 # define EXIM_DBOPEN__(name, dirname, flags, mode, dbpp) \
230 if (db_create(dbpp, NULL, 0) != 0 || \
231 ((*dbpp)->set_errcall(*dbpp, dbfn_bdb_error_callback), \
232 ((*dbpp)->open)(*dbpp, CS name, NULL, \
233 ((flags) == O_RDONLY)? DB_UNKNOWN : DB_HASH, \
234 ((flags) == O_RDONLY)? DB_RDONLY : DB_CREATE, \
235 mode)) != 0) *(dbpp) = NULL
237 /* EXIM_DBGET - returns TRUE if successful, FALSE otherwise */
238 # define EXIM_DBGET(db, key, data) \
239 ((db)->get(db, NULL, &key, &data, 0) == 0)
241 /* EXIM_DBPUT - returns nothing useful, assumes replace mode */
242 # define EXIM_DBPUT(db, key, data) \
243 (db)->put(db, NULL, &key, &data, 0)
245 /* EXIM_DBPUTB - non-overwriting for use by dbmbuild */
246 # define EXIM_DBPUTB(db, key, data) \
247 (db)->put(db, NULL, &key, &data, DB_NOOVERWRITE)
249 /* Return values from EXIM_DBPUTB */
251 # define EXIM_DBPUTB_OK 0
252 # define EXIM_DBPUTB_DUP DB_KEYEXIST
255 # define EXIM_DBDEL(db, key) (db)->del(db, NULL, &key, 0)
257 /* EXIM_DBCREATE_CURSOR - initialize for scanning operation */
259 # define EXIM_DBCREATE_CURSOR(db, cursor) \
260 (db)->cursor(db, NULL, cursor, 0)
262 /* EXIM_DBSCAN - returns TRUE if data is returned, FALSE at end */
263 # define EXIM_DBSCAN(db, key, data, first, cursor) \
264 ((cursor)->c_get(cursor, &key, &data, \
265 (first? DB_FIRST : DB_NEXT)) == 0)
267 /* EXIM_DBDELETE_CURSOR - terminate scanning operation */
268 # define EXIM_DBDELETE_CURSOR(cursor) \
269 (cursor)->c_close(cursor)
272 # define EXIM_DBCLOSE__(db) (db)->close(db, 0)
274 /* Datum access types - these are intended to be assignable. */
276 # define EXIM_DATUM_SIZE(datum) (datum).size
277 # define EXIM_DATUM_DATA(datum) (datum).data
279 /* The whole datum structure contains other fields that must be cleared
280 before use, but we don't have to free anything after reading data. */
282 # define EXIM_DATUM_INIT(datum) memset(&datum, 0, sizeof(datum))
283 # define EXIM_DATUM_FREE(datum)
288 #else /* DB_VERSION_MAJOR >= 3 */
290 /******************* Berkeley db 2.x native definitions ********************/
295 /* Cursor type, for scanning */
296 #define EXIM_CURSOR DBC
298 /* The datum type used for queries */
299 #define EXIM_DATUM DBT
301 /* Some text for messages */
302 #define EXIM_DBTYPE "db (v2)"
304 /* Access functions */
306 /* EXIM_DBOPEN - sets *dbpp to point to an EXIM_DB, NULL if failed */
307 #define EXIM_DBOPEN__(name, dirname, flags, mode, dbpp) \
308 if ((errno = db_open(CS name, DB_HASH, \
309 ((flags) == O_RDONLY)? DB_RDONLY : DB_CREATE, \
310 mode, NULL, NULL, dbpp)) != 0) *(dbpp) = NULL
312 /* EXIM_DBGET - returns TRUE if successful, FALSE otherwise */
313 #define EXIM_DBGET(db, key, data) \
314 ((db)->get(db, NULL, &key, &data, 0) == 0)
316 /* EXIM_DBPUT - returns nothing useful, assumes replace mode */
317 #define EXIM_DBPUT(db, key, data) \
318 (db)->put(db, NULL, &key, &data, 0)
320 /* EXIM_DBPUTB - non-overwriting for use by dbmbuild */
321 #define EXIM_DBPUTB(db, key, data) \
322 (db)->put(db, NULL, &key, &data, DB_NOOVERWRITE)
324 /* Return values from EXIM_DBPUTB */
326 #define EXIM_DBPUTB_OK 0
327 #define EXIM_DBPUTB_DUP DB_KEYEXIST
330 #define EXIM_DBDEL(db, key) (db)->del(db, NULL, &key, 0)
332 /* EXIM_DBCREATE_CURSOR - initialize for scanning operation */
334 /* The API of this function was changed between releases 2.4.14 and 2.7.3. I do
335 not know exactly where the change happened, but the Change Log for 2.5.9 lists
336 the new option that is available, so I guess that it happened at 2.5.x. */
338 #if DB_VERSION_MINOR >= 5
339 #define EXIM_DBCREATE_CURSOR(db, cursor) \
340 (db)->cursor(db, NULL, cursor, 0)
342 #define EXIM_DBCREATE_CURSOR(db, cursor) \
343 (db)->cursor(db, NULL, cursor)
346 /* EXIM_DBSCAN - returns TRUE if data is returned, FALSE at end */
347 #define EXIM_DBSCAN(db, key, data, first, cursor) \
348 ((cursor)->c_get(cursor, &key, &data, \
349 (first? DB_FIRST : DB_NEXT)) == 0)
351 /* EXIM_DBDELETE_CURSOR - terminate scanning operation */
352 #define EXIM_DBDELETE_CURSOR(cursor) \
353 (cursor)->c_close(cursor)
356 #define EXIM_DBCLOSE__(db) (db)->close(db, 0)
358 /* Datum access types - these are intended to be assignable. */
360 #define EXIM_DATUM_SIZE(datum) (datum).size
361 #define EXIM_DATUM_DATA(datum) (datum).data
363 /* The whole datum structure contains other fields that must be cleared
364 before use, but we don't have to free anything after reading data. */
366 #define EXIM_DATUM_INIT(datum) memset(&datum, 0, sizeof(datum))
367 #define EXIM_DATUM_FREE(datum)
369 #endif /* DB_VERSION_MAJOR >= 3 */
372 /* If DB_VERSION_TYPE is not defined, we have version 1.x */
374 #else /* DB_VERSION_TYPE */
376 /******************* Berkeley db 1.x native definitions ********************/
381 /* Cursor type, not used with DB 1.x: just set up a dummy */
382 #define EXIM_CURSOR int
384 /* The datum type used for queries */
385 #define EXIM_DATUM DBT
387 /* Some text for messages */
388 #define EXIM_DBTYPE "db (v1)"
390 /* When scanning, for the non-first case we historically just passed 0
391 as the flags field and it worked. On FreeBSD 8 it no longer works and
392 instead leads to memory exhaustion. The man-page on FreeBSD says to use
393 R_NEXT, but this 1.x is a historical fallback and I've no idea how portable
394 the use of that flag is; so the solution is to define R_NEXT here if it's not
395 already defined, with a default value of 0 because that's what we've always
396 before been able to pass successfully. */
401 /* Access functions */
403 /* EXIM_DBOPEN - sets *dbpp to point to an EXIM_DB, NULL if failed */
404 #define EXIM_DBOPEN__(name, dirname, flags, mode, dbpp) \
405 *(dbpp) = dbopen(CS name, flags, mode, DB_HASH, NULL)
407 /* EXIM_DBGET - returns TRUE if successful, FALSE otherwise */
408 #define EXIM_DBGET(db, key, data) \
409 ((db)->get(db, &key, &data, 0) == 0)
411 /* EXIM_DBPUT - returns nothing useful, assumes replace mode */
412 #define EXIM_DBPUT(db, key, data) \
413 (db)->put(db, &key, &data, 0)
415 /* EXIM_DBPUTB - non-overwriting for use by dbmbuild */
416 #define EXIM_DBPUTB(db, key, data) \
417 (db)->put(db, &key, &data, R_NOOVERWRITE)
419 /* Returns from EXIM_DBPUTB */
421 #define EXIM_DBPUTB_OK 0
422 #define EXIM_DBPUTB_DUP 1
425 #define EXIM_DBDEL(db, key) (db)->del(db, &key, 0)
427 /* EXIM_DBCREATE_CURSOR - initialize for scanning operation (null) */
428 #define EXIM_DBCREATE_CURSOR(db, cursor) {}
430 /* EXIM_DBSCAN - returns TRUE if data is returned, FALSE at end */
431 #define EXIM_DBSCAN(db, key, data, first, cursor) \
432 ((db)->seq(db, &key, &data, (first? R_FIRST : R_NEXT)) == 0)
434 /* EXIM_DBDELETE_CURSOR - terminate scanning operation (null). Make it
435 refer to cursor, to keep picky compilers happy. */
436 #define EXIM_DBDELETE_CURSOR(cursor) { cursor = cursor; }
439 #define EXIM_DBCLOSE__(db) (db)->close(db)
441 /* Datum access types - these are intended to be assignable */
443 #define EXIM_DATUM_SIZE(datum) (datum).size
444 #define EXIM_DATUM_DATA(datum) (datum).data
446 /* There's no clearing required before use, and we don't have to free anything
447 after reading data. */
449 #define EXIM_DATUM_INIT(datum)
450 #define EXIM_DATUM_FREE(datum)
452 #endif /* DB_VERSION_STRING */
456 /********************* gdbm interface definitions **********************/
458 #elif defined USE_GDBM
464 GDBM_FILE gdbm; /* Database */
465 datum lkey; /* Last key, for scans */
468 /* Cursor type, not used with gdbm: just set up a dummy */
469 #define EXIM_CURSOR int
471 /* The datum type used for queries */
472 #define EXIM_DATUM datum
474 /* Some text for messages */
476 #define EXIM_DBTYPE "gdbm"
478 /* Access functions */
480 /* EXIM_DBOPEN - returns a EXIM_DB *, NULL if failed */
481 #define EXIM_DBOPEN__(name, dirname, flags, mode, dbpp) \
482 { (*(dbpp)) = (EXIM_DB *) malloc(sizeof(EXIM_DB));\
483 if (*(dbpp) != NULL) { \
484 (*(dbpp))->lkey.dptr = NULL;\
485 (*(dbpp))->gdbm = gdbm_open(CS name, 0, (((flags) & O_CREAT))?GDBM_WRCREAT:(((flags) & (O_RDWR|O_WRONLY))?GDBM_WRITER:GDBM_READER), mode, 0);\
486 if ((*(dbpp))->gdbm == NULL) {\
493 /* EXIM_DBGET - returns TRUE if successful, FALSE otherwise */
494 #define EXIM_DBGET(db, key, data) \
495 (data = gdbm_fetch(db->gdbm, key), data.dptr != NULL)
497 /* EXIM_DBPUT - returns nothing useful, assumes replace mode */
498 #define EXIM_DBPUT(db, key, data) \
499 gdbm_store(db->gdbm, key, data, GDBM_REPLACE)
501 /* EXIM_DBPUTB - non-overwriting for use by dbmbuild */
502 #define EXIM_DBPUTB(db, key, data) \
503 gdbm_store(db->gdbm, key, data, GDBM_INSERT)
505 /* Returns from EXIM_DBPUTB */
507 #define EXIM_DBPUTB_OK 0
508 #define EXIM_DBPUTB_DUP 1
511 #define EXIM_DBDEL(db, key) gdbm_delete(db->gdbm, key)
513 /* EXIM_DBCREATE_CURSOR - initialize for scanning operation (null) */
514 #define EXIM_DBCREATE_CURSOR(db, cursor) {}
517 #define EXIM_DBSCAN(db, key, data, first, cursor) \
518 ( key = ((first)? gdbm_firstkey(db->gdbm) : gdbm_nextkey(db->gdbm, db->lkey)), \
519 (((db)->lkey.dptr != NULL)? (free((db)->lkey.dptr),1) : 1),\
520 db->lkey = key, key.dptr != NULL)
522 /* EXIM_DBDELETE_CURSOR - terminate scanning operation (null). Make it
523 refer to cursor, to keep picky compilers happy. */
524 #define EXIM_DBDELETE_CURSOR(cursor) { cursor = cursor; }
527 #define EXIM_DBCLOSE__(db) \
528 { gdbm_close((db)->gdbm);\
529 if ((db)->lkey.dptr != NULL) free((db)->lkey.dptr);\
532 /* Datum access types - these are intended to be assignable */
534 #define EXIM_DATUM_SIZE(datum) (datum).dsize
535 #define EXIM_DATUM_DATA(datum) (datum).dptr
537 /* There's no clearing required before use, but we have to free the dptr
538 after reading data. */
540 #define EXIM_DATUM_INIT(datum)
541 #define EXIM_DATUM_FREE(datum) free(datum.dptr)
546 /* If none of USE_DB, USG_GDBM, or USE_TDB are set, the default is the NDBM
550 /********************* ndbm interface definitions **********************/
557 /* Cursor type, not used with ndbm: just set up a dummy */
558 #define EXIM_CURSOR int
560 /* The datum type used for queries */
561 #define EXIM_DATUM datum
563 /* Some text for messages */
565 #define EXIM_DBTYPE "ndbm"
567 /* Access functions */
569 /* EXIM_DBOPEN - returns a EXIM_DB *, NULL if failed */
570 #define EXIM_DBOPEN__(name, dirname, flags, mode, dbpp) \
571 *(dbpp) = dbm_open(CS name, flags, mode)
573 /* EXIM_DBGET - returns TRUE if successful, FALSE otherwise */
574 #define EXIM_DBGET(db, key, data) \
575 (data = dbm_fetch(db, key), data.dptr != NULL)
577 /* EXIM_DBPUT - returns nothing useful, assumes replace mode */
578 #define EXIM_DBPUT(db, key, data) \
579 dbm_store(db, key, data, DBM_REPLACE)
581 /* EXIM_DBPUTB - non-overwriting for use by dbmbuild */
582 #define EXIM_DBPUTB(db, key, data) \
583 dbm_store(db, key, data, DBM_INSERT)
585 /* Returns from EXIM_DBPUTB */
587 #define EXIM_DBPUTB_OK 0
588 #define EXIM_DBPUTB_DUP 1
591 #define EXIM_DBDEL(db, key) dbm_delete(db, key)
593 /* EXIM_DBCREATE_CURSOR - initialize for scanning operation (null) */
594 #define EXIM_DBCREATE_CURSOR(db, cursor) {}
597 #define EXIM_DBSCAN(db, key, data, first, cursor) \
598 (key = (first? dbm_firstkey(db) : dbm_nextkey(db)), key.dptr != NULL)
600 /* EXIM_DBDELETE_CURSOR - terminate scanning operation (null). Make it
601 refer to cursor, to keep picky compilers happy. */
602 #define EXIM_DBDELETE_CURSOR(cursor) { cursor = cursor; }
605 #define EXIM_DBCLOSE__(db) dbm_close(db)
607 /* Datum access types - these are intended to be assignable */
609 #define EXIM_DATUM_SIZE(datum) (datum).dsize
610 #define EXIM_DATUM_DATA(datum) (datum).dptr
612 /* There's no clearing required before use, and we don't have to free anything
613 after reading data. */
615 #define EXIM_DATUM_INIT(datum)
616 #define EXIM_DATUM_FREE(datum)
618 #endif /* USE_GDBM */
624 # ifdef COMPILE_UTILITY
626 # define EXIM_DBOPEN(name, dirname, flags, mode, dbpp) \
627 EXIM_DBOPEN__(name, dirname, flags, mode, dbpp)
628 # define EXIM_DBCLOSE(db) EXIM_DBCLOSE__(db)
632 # define EXIM_DBOPEN(name, dirname, flags, mode, dbpp) \
634 DEBUG(D_hints_lookup) \
635 debug_printf("EXIM_DBOPEN: file <%s> dir <%s> flags=%s\n", \
637 (flags) == O_RDONLY ? "O_RDONLY" \
638 : (flags) == O_RDWR ? "O_RDWR" \
639 : (flags) == (O_RDWR|O_CREAT) ? "O_RDWR|O_CREAT" \
641 EXIM_DBOPEN__(name, dirname, flags, mode, dbpp); \
642 DEBUG(D_hints_lookup) debug_printf("returned from EXIM_DBOPEN: %p\n", *dbpp); \
644 # define EXIM_DBCLOSE(db) \
646 DEBUG(D_hints_lookup) debug_printf("EXIM_DBCLOSE(%p)\n", db); \
647 EXIM_DBCLOSE__(db); \
652 /********************* End of dbm library definitions **********************/
655 /* Structure for carrying around an open DBM file, and an open locking file
656 that relates to it. */
664 /* Structures for records stored in exim database dbm files. They all
665 start with the same fields, described in the generic type. */
669 time_t time_stamp; /* Timestamp of writing */
673 /* This structure keeps track of retry information for a host or a local
679 time_t first_failed; /* Time of first failure */
680 time_t last_try; /* Time of last try */
681 time_t next_try; /* Time of next try */
682 BOOL expired; /* Retry time has expired */
683 int basic_errno; /* Errno of last failure */
684 int more_errno; /* Additional information */
685 uschar text[1]; /* Text message for last failure */
688 /* These structures keep track of addresses that have had callout verification
689 performed on them. There are two groups of records:
691 1. keyed by localpart@domain -
692 Full address was tested and record holds result
695 Domain response upto MAIL FROM:<>, postmaster, random local part;
697 If a record exists, the result field is either ccache_accept or ccache_reject,
698 or, for a domain record only, ccache_reject_mfnull when MAIL FROM:<> was
699 rejected. The other fields, however, (which are only relevant to domain
700 records) may also contain ccache_unknown if that particular test has not been
703 Originally, there was only one structure, used for both types. However, it got
704 expanded for domain records, so it got split. To make it possible for Exim to
705 handle the old type of record, we retain the old definition. The different
706 kinds of record can be distinguished by their different lengths. */
712 int postmaster_result; /* Postmaster is accepted */
713 int random_result; /* Random local part was accepted */
714 } dbdata_callout_cache_obs;
717 time_t time_stamp; /* Timestamp of last address check */
719 int result; /* accept or reject */
720 } dbdata_callout_cache_address;
722 /* For this new layout, we put the additional fields (the timestamps)
723 last so that if somebody reverts to an older Exim, the new records will
724 still make sense because they match the old layout. */
727 time_t time_stamp; /* Time stamp of last connection */
729 int result; /* Domain reject or accept */
730 int postmaster_result; /* Postmaster result */
731 int random_result; /* Random result */
732 time_t postmaster_stamp; /* Timestamp of postmaster check */
733 time_t random_stamp; /* Timestamp of random check */
734 } dbdata_callout_cache;
736 /* This structure keeps track of messages that are waiting for a particular
737 host for a particular transport. */
742 int count; /* Count of message ids */
743 int sequence; /* Sequence for continued records */
744 uschar text[1]; /* One long character string */
748 /* The contents of the "misc" database are a mixture of different kinds of
749 record, as defined below. The keys used for a specific type all start with a
750 given string such as "etrn-" or "host-serialize-". */
753 /* This structure records a connection to a particular host, for the
754 purpose of serializing access to certain hosts. For possible future extension,
755 a field is defined for holding the count of connections, but it is not
756 at present in use. The same structure is used for recording a running ETRN
762 int count; /* Reserved for possible connection count */
766 /* This structure records the information required for the ratelimit
772 int time_usec; /* Fractional part of time, from gettimeofday() */
773 double rate; /* Smoothed sending rate at that time */
776 /* Same as above, plus a Bloom filter for uniquifying events. */
779 dbdata_ratelimit dbd;
780 time_t bloom_epoch; /* When the Bloom filter was last reset */
781 unsigned bloom_size; /* Number of bytes in the Bloom filter */
782 uschar bloom[40]; /* Bloom filter which may be larger than this */
783 } dbdata_ratelimit_unique;
786 /* End of dbstuff.h */