1 /*************************************************
2 * Exim - an Internet mail transport agent *
3 *************************************************/
5 /* Copyright (c) University of Cambridge 1995 - 2018 */
6 /* Copyright (c) The Exim Maintainers 2020 */
7 /* See the file NOTICE for conditions of use and distribution. */
9 /* This header file contains macro definitions so that a variety of DBM
10 libraries can be used by Exim. Nigel Metheringham provided the original set for
11 Berkeley DB 1.x in native mode and ndbm. Subsequently, versions for Berkeley DB
12 2.x and 3.x were added. Later still, support for tdb was added, courtesy of
13 James Antill. Most recently, support for native mode gdbm was added, with code
14 from Pierre A. Humblet, so Exim could be made to work with Cygwin.
16 For convenience, the definitions of the structures used in the various hints
17 databases are also kept in this file, which is used by the maintenance
18 utilities as well as the main Exim binary. */
23 /* ************************* tdb interface ************************ */
28 #define EXIM_DB TDB_CONTEXT
30 /* Cursor type: tdb uses the previous "key" in _nextkey() (really it wants
31 tdb_traverse to be called) */
32 #define EXIM_CURSOR TDB_DATA
34 /* The datum type used for queries */
35 #define EXIM_DATUM TDB_DATA
37 /* Some text for messages */
38 #define EXIM_DBTYPE "tdb"
40 /* Access functions */
42 /* EXIM_DBOPEN - sets *dbpp to point to an EXIM_DB, NULL if failed */
43 #define EXIM_DBOPEN__(name, dirname, flags, mode, dbpp) \
44 *(dbpp) = tdb_open(CS name, 0, TDB_DEFAULT, flags, mode)
46 /* EXIM_DBGET - returns TRUE if successful, FALSE otherwise */
47 #define EXIM_DBGET(db, key, data) \
48 (data = tdb_fetch(db, key), data.dptr != NULL)
50 /* EXIM_DBPUT - returns nothing useful, assumes replace mode */
51 #define EXIM_DBPUT(db, key, data) \
52 tdb_store(db, key, data, TDB_REPLACE)
54 /* EXIM_DBPUTB - non-overwriting for use by dbmbuild */
55 #define EXIM_DBPUTB(db, key, data) \
56 tdb_store(db, key, data, TDB_INSERT)
58 /* Returns from EXIM_DBPUTB */
60 #define EXIM_DBPUTB_OK 0
61 #define EXIM_DBPUTB_DUP (-1)
64 #define EXIM_DBDEL(db, key) tdb_delete(db, key)
66 /* EXIM_DBCREATE_CURSOR - initialize for scanning operation */
67 #define EXIM_DBCREATE_CURSOR(db, cursor) { \
68 *(cursor) = store_malloc(sizeof(TDB_DATA)); (*(cursor))->dptr = NULL; }
70 /* EXIM_DBSCAN - This is complicated because we have to free the last datum
71 free() must not die when passed NULL */
72 #define EXIM_DBSCAN(db, key, data, first, cursor) \
73 (key = (first ? tdb_firstkey(db) : tdb_nextkey(db, *(cursor))), \
74 free((cursor)->dptr), *(cursor) = key, \
77 /* EXIM_DBDELETE_CURSOR - terminate scanning operation. */
78 #define EXIM_DBDELETE_CURSOR(cursor) free(cursor)
81 #define EXIM_DBCLOSE__(db) tdb_close(db)
83 /* Datum access types - these are intended to be assignable */
85 #define EXIM_DATUM_SIZE(datum) (datum).dsize
86 #define EXIM_DATUM_DATA(datum) (datum).dptr
88 /* Free the stuff inside the datum. */
90 #define EXIM_DATUM_FREE(datum) (free((datum).dptr), (datum).dptr = NULL)
92 /* No initialization is needed. */
94 #define EXIM_DATUM_INIT(datum)
98 /********************* Berkeley db native definitions **********************/
105 /* We can distinguish between versions 1.x and 2.x/3.x by looking for a
106 definition of DB_VERSION_STRING, which is present in versions 2.x onwards. */
108 #ifdef DB_VERSION_STRING
110 # if DB_VERSION_MAJOR >= 6
111 # error Version 6 and later BDB API is not supported
114 /* The API changed (again!) between the 2.x and 3.x versions */
116 #if DB_VERSION_MAJOR >= 3
118 /***************** Berkeley db 3.x/4.x native definitions ******************/
121 # if DB_VERSION_MAJOR > 4 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 1)
122 # define EXIM_DB DB_ENV
123 /* Cursor type, for scanning */
124 # define EXIM_CURSOR DBC
126 /* The datum type used for queries */
127 # define EXIM_DATUM DBT
129 /* Some text for messages */
130 # define EXIM_DBTYPE "db (v4.1+)"
132 /* Only more-recent versions. 5+ ? */
133 # ifndef DB_FORCESYNC
134 # define DB_FORCESYNC 0
138 /* Access functions */
140 /* EXIM_DBOPEN - sets *dbpp to point to an EXIM_DB, NULL if failed. The
141 API changed for DB 4.1. - and we also starting using the "env" with a
142 specified working dir, to avoid the DBCONFIG file trap. */
144 # define ENV_TO_DB(env) ((DB *)((env)->app_private))
146 # define EXIM_DBOPEN__(name, dirname, flags, mode, dbpp) \
147 if ( db_env_create(dbpp, 0) != 0 \
148 || ((*dbpp)->set_errcall(*dbpp, dbfn_bdb_error_callback), 0) \
149 || (*dbpp)->open(*dbpp, CS dirname, DB_CREATE|DB_INIT_MPOOL|DB_PRIVATE, 0) != 0\
152 else if (db_create((DB **) &((*dbpp)->app_private), *dbpp, 0) != 0) \
154 ((DB_ENV *)(*dbpp))->close((DB_ENV *)(*dbpp), 0); \
157 else if (ENV_TO_DB(*dbpp)->open(ENV_TO_DB(*dbpp), NULL, CS name, NULL, \
158 (flags) == O_RDONLY ? DB_UNKNOWN : DB_HASH, \
159 (flags) == O_RDONLY ? DB_RDONLY : DB_CREATE, \
163 ENV_TO_DB(*dbpp)->close(ENV_TO_DB(*dbpp), 0); \
164 ((DB_ENV *)(*dbpp))->close((DB_ENV *)(*dbpp), 0); \
168 /* EXIM_DBGET - returns TRUE if successful, FALSE otherwise */
169 # define EXIM_DBGET(db, key, data) \
170 (ENV_TO_DB(db)->get(ENV_TO_DB(db), NULL, &key, &data, 0) == 0)
172 /* EXIM_DBPUT - returns nothing useful, assumes replace mode */
173 # define EXIM_DBPUT(db, key, data) \
174 ENV_TO_DB(db)->put(ENV_TO_DB(db), NULL, &key, &data, 0)
176 /* EXIM_DBPUTB - non-overwriting for use by dbmbuild */
177 # define EXIM_DBPUTB(db, key, data) \
178 ENV_TO_DB(db)->put(ENV_TO_DB(db), NULL, &key, &data, DB_NOOVERWRITE)
180 /* Return values from EXIM_DBPUTB */
182 # define EXIM_DBPUTB_OK 0
183 # define EXIM_DBPUTB_DUP DB_KEYEXIST
186 # define EXIM_DBDEL(db, key) ENV_TO_DB(db)->del(ENV_TO_DB(db), NULL, &key, 0)
188 /* EXIM_DBCREATE_CURSOR - initialize for scanning operation */
190 # define EXIM_DBCREATE_CURSOR(db, cursor) \
191 ENV_TO_DB(db)->cursor(ENV_TO_DB(db), NULL, cursor, 0)
193 /* EXIM_DBSCAN - returns TRUE if data is returned, FALSE at end */
194 # define EXIM_DBSCAN(db, key, data, first, cursor) \
195 ((cursor)->c_get(cursor, &key, &data, \
196 (first? DB_FIRST : DB_NEXT)) == 0)
198 /* EXIM_DBDELETE_CURSOR - terminate scanning operation */
199 # define EXIM_DBDELETE_CURSOR(cursor) \
200 (cursor)->c_close(cursor)
203 # define EXIM_DBCLOSE__(db) \
204 (ENV_TO_DB(db)->close(ENV_TO_DB(db), 0) , ((DB_ENV *)(db))->close((DB_ENV *)(db), DB_FORCESYNC))
206 /* Datum access types - these are intended to be assignable. */
208 # define EXIM_DATUM_SIZE(datum) (datum).size
209 # define EXIM_DATUM_DATA(datum) (datum).data
211 /* The whole datum structure contains other fields that must be cleared
212 before use, but we don't have to free anything after reading data. */
214 # define EXIM_DATUM_INIT(datum) memset(&datum, 0, sizeof(datum))
215 # define EXIM_DATUM_FREE(datum)
217 # else /* pre- 4.1 */
221 /* Cursor type, for scanning */
222 # define EXIM_CURSOR DBC
224 /* The datum type used for queries */
225 # define EXIM_DATUM DBT
227 /* Some text for messages */
228 # define EXIM_DBTYPE "db (v3/4)"
230 /* Access functions */
232 /* EXIM_DBOPEN - sets *dbpp to point to an EXIM_DB, NULL if failed. */
234 # define EXIM_DBOPEN__(name, dirname, flags, mode, dbpp) \
235 if (db_create(dbpp, NULL, 0) != 0 || \
236 ((*dbpp)->set_errcall(*dbpp, dbfn_bdb_error_callback), \
237 ((*dbpp)->open)(*dbpp, CS name, NULL, \
238 ((flags) == O_RDONLY)? DB_UNKNOWN : DB_HASH, \
239 ((flags) == O_RDONLY)? DB_RDONLY : DB_CREATE, \
240 mode)) != 0) *(dbpp) = NULL
242 /* EXIM_DBGET - returns TRUE if successful, FALSE otherwise */
243 # define EXIM_DBGET(db, key, data) \
244 ((db)->get(db, NULL, &key, &data, 0) == 0)
246 /* EXIM_DBPUT - returns nothing useful, assumes replace mode */
247 # define EXIM_DBPUT(db, key, data) \
248 (db)->put(db, NULL, &key, &data, 0)
250 /* EXIM_DBPUTB - non-overwriting for use by dbmbuild */
251 # define EXIM_DBPUTB(db, key, data) \
252 (db)->put(db, NULL, &key, &data, DB_NOOVERWRITE)
254 /* Return values from EXIM_DBPUTB */
256 # define EXIM_DBPUTB_OK 0
257 # define EXIM_DBPUTB_DUP DB_KEYEXIST
260 # define EXIM_DBDEL(db, key) (db)->del(db, NULL, &key, 0)
262 /* EXIM_DBCREATE_CURSOR - initialize for scanning operation */
264 # define EXIM_DBCREATE_CURSOR(db, cursor) \
265 (db)->cursor(db, NULL, cursor, 0)
267 /* EXIM_DBSCAN - returns TRUE if data is returned, FALSE at end */
268 # define EXIM_DBSCAN(db, key, data, first, cursor) \
269 ((cursor)->c_get(cursor, &key, &data, \
270 (first? DB_FIRST : DB_NEXT)) == 0)
272 /* EXIM_DBDELETE_CURSOR - terminate scanning operation */
273 # define EXIM_DBDELETE_CURSOR(cursor) \
274 (cursor)->c_close(cursor)
277 # define EXIM_DBCLOSE__(db) (db)->close(db, 0)
279 /* Datum access types - these are intended to be assignable. */
281 # define EXIM_DATUM_SIZE(datum) (datum).size
282 # define EXIM_DATUM_DATA(datum) (datum).data
284 /* The whole datum structure contains other fields that must be cleared
285 before use, but we don't have to free anything after reading data. */
287 # define EXIM_DATUM_INIT(datum) memset(&datum, 0, sizeof(datum))
288 # define EXIM_DATUM_FREE(datum)
293 #else /* DB_VERSION_MAJOR >= 3 */
295 /******************* Berkeley db 2.x native definitions ********************/
300 /* Cursor type, for scanning */
301 #define EXIM_CURSOR DBC
303 /* The datum type used for queries */
304 #define EXIM_DATUM DBT
306 /* Some text for messages */
307 #define EXIM_DBTYPE "db (v2)"
309 /* Access functions */
311 /* EXIM_DBOPEN - sets *dbpp to point to an EXIM_DB, NULL if failed */
312 #define EXIM_DBOPEN__(name, dirname, flags, mode, dbpp) \
313 if ((errno = db_open(CS name, DB_HASH, \
314 ((flags) == O_RDONLY)? DB_RDONLY : DB_CREATE, \
315 mode, NULL, NULL, dbpp)) != 0) *(dbpp) = NULL
317 /* EXIM_DBGET - returns TRUE if successful, FALSE otherwise */
318 #define EXIM_DBGET(db, key, data) \
319 ((db)->get(db, NULL, &key, &data, 0) == 0)
321 /* EXIM_DBPUT - returns nothing useful, assumes replace mode */
322 #define EXIM_DBPUT(db, key, data) \
323 (db)->put(db, NULL, &key, &data, 0)
325 /* EXIM_DBPUTB - non-overwriting for use by dbmbuild */
326 #define EXIM_DBPUTB(db, key, data) \
327 (db)->put(db, NULL, &key, &data, DB_NOOVERWRITE)
329 /* Return values from EXIM_DBPUTB */
331 #define EXIM_DBPUTB_OK 0
332 #define EXIM_DBPUTB_DUP DB_KEYEXIST
335 #define EXIM_DBDEL(db, key) (db)->del(db, NULL, &key, 0)
337 /* EXIM_DBCREATE_CURSOR - initialize for scanning operation */
339 /* The API of this function was changed between releases 2.4.14 and 2.7.3. I do
340 not know exactly where the change happened, but the Change Log for 2.5.9 lists
341 the new option that is available, so I guess that it happened at 2.5.x. */
343 #if DB_VERSION_MINOR >= 5
344 #define EXIM_DBCREATE_CURSOR(db, cursor) \
345 (db)->cursor(db, NULL, cursor, 0)
347 #define EXIM_DBCREATE_CURSOR(db, cursor) \
348 (db)->cursor(db, NULL, cursor)
351 /* EXIM_DBSCAN - returns TRUE if data is returned, FALSE at end */
352 #define EXIM_DBSCAN(db, key, data, first, cursor) \
353 ((cursor)->c_get(cursor, &key, &data, \
354 (first? DB_FIRST : DB_NEXT)) == 0)
356 /* EXIM_DBDELETE_CURSOR - terminate scanning operation */
357 #define EXIM_DBDELETE_CURSOR(cursor) \
358 (cursor)->c_close(cursor)
361 #define EXIM_DBCLOSE__(db) (db)->close(db, 0)
363 /* Datum access types - these are intended to be assignable. */
365 #define EXIM_DATUM_SIZE(datum) (datum).size
366 #define EXIM_DATUM_DATA(datum) (datum).data
368 /* The whole datum structure contains other fields that must be cleared
369 before use, but we don't have to free anything after reading data. */
371 #define EXIM_DATUM_INIT(datum) memset(&datum, 0, sizeof(datum))
372 #define EXIM_DATUM_FREE(datum)
374 #endif /* DB_VERSION_MAJOR >= 3 */
377 /* If DB_VERSION_TYPE is not defined, we have version 1.x */
379 #else /* DB_VERSION_TYPE */
381 /******************* Berkeley db 1.x native definitions ********************/
386 /* Cursor type, not used with DB 1.x: just set up a dummy */
387 #define EXIM_CURSOR int
389 /* The datum type used for queries */
390 #define EXIM_DATUM DBT
392 /* Some text for messages */
393 #define EXIM_DBTYPE "db (v1)"
395 /* When scanning, for the non-first case we historically just passed 0
396 as the flags field and it worked. On FreeBSD 8 it no longer works and
397 instead leads to memory exhaustion. The man-page on FreeBSD says to use
398 R_NEXT, but this 1.x is a historical fallback and I've no idea how portable
399 the use of that flag is; so the solution is to define R_NEXT here if it's not
400 already defined, with a default value of 0 because that's what we've always
401 before been able to pass successfully. */
406 /* Access functions */
408 /* EXIM_DBOPEN - sets *dbpp to point to an EXIM_DB, NULL if failed */
409 #define EXIM_DBOPEN__(name, dirname, flags, mode, dbpp) \
410 *(dbpp) = dbopen(CS name, flags, mode, DB_HASH, NULL)
412 /* EXIM_DBGET - returns TRUE if successful, FALSE otherwise */
413 #define EXIM_DBGET(db, key, data) \
414 ((db)->get(db, &key, &data, 0) == 0)
416 /* EXIM_DBPUT - returns nothing useful, assumes replace mode */
417 #define EXIM_DBPUT(db, key, data) \
418 (db)->put(db, &key, &data, 0)
420 /* EXIM_DBPUTB - non-overwriting for use by dbmbuild */
421 #define EXIM_DBPUTB(db, key, data) \
422 (db)->put(db, &key, &data, R_NOOVERWRITE)
424 /* Returns from EXIM_DBPUTB */
426 #define EXIM_DBPUTB_OK 0
427 #define EXIM_DBPUTB_DUP 1
430 #define EXIM_DBDEL(db, key) (db)->del(db, &key, 0)
432 /* EXIM_DBCREATE_CURSOR - initialize for scanning operation (null) */
433 #define EXIM_DBCREATE_CURSOR(db, cursor) {}
435 /* EXIM_DBSCAN - returns TRUE if data is returned, FALSE at end */
436 #define EXIM_DBSCAN(db, key, data, first, cursor) \
437 ((db)->seq(db, &key, &data, (first? R_FIRST : R_NEXT)) == 0)
439 /* EXIM_DBDELETE_CURSOR - terminate scanning operation (null). Make it
440 refer to cursor, to keep picky compilers happy. */
441 #define EXIM_DBDELETE_CURSOR(cursor) { cursor = cursor; }
444 #define EXIM_DBCLOSE__(db) (db)->close(db)
446 /* Datum access types - these are intended to be assignable */
448 #define EXIM_DATUM_SIZE(datum) (datum).size
449 #define EXIM_DATUM_DATA(datum) (datum).data
451 /* There's no clearing required before use, and we don't have to free anything
452 after reading data. */
454 #define EXIM_DATUM_INIT(datum)
455 #define EXIM_DATUM_FREE(datum)
457 #endif /* DB_VERSION_STRING */
461 /********************* gdbm interface definitions **********************/
463 #elif defined USE_GDBM
469 GDBM_FILE gdbm; /* Database */
470 datum lkey; /* Last key, for scans */
473 /* Cursor type, not used with gdbm: just set up a dummy */
474 #define EXIM_CURSOR int
476 /* The datum type used for queries */
477 #define EXIM_DATUM datum
479 /* Some text for messages */
481 #define EXIM_DBTYPE "gdbm"
483 /* Access functions */
485 /* EXIM_DBOPEN - returns a EXIM_DB *, NULL if failed */
486 #define EXIM_DBOPEN__(name, dirname, flags, mode, dbpp) \
487 { (*(dbpp)) = (EXIM_DB *) malloc(sizeof(EXIM_DB));\
488 if (*(dbpp) != NULL) { \
489 (*(dbpp))->lkey.dptr = NULL;\
490 (*(dbpp))->gdbm = gdbm_open(CS name, 0, (((flags) & O_CREAT))?GDBM_WRCREAT:(((flags) & (O_RDWR|O_WRONLY))?GDBM_WRITER:GDBM_READER), mode, 0);\
491 if ((*(dbpp))->gdbm == NULL) {\
498 /* EXIM_DBGET - returns TRUE if successful, FALSE otherwise */
499 #define EXIM_DBGET(db, key, data) \
500 (data = gdbm_fetch(db->gdbm, key), data.dptr != NULL)
502 /* EXIM_DBPUT - returns nothing useful, assumes replace mode */
503 #define EXIM_DBPUT(db, key, data) \
504 gdbm_store(db->gdbm, key, data, GDBM_REPLACE)
506 /* EXIM_DBPUTB - non-overwriting for use by dbmbuild */
507 #define EXIM_DBPUTB(db, key, data) \
508 gdbm_store(db->gdbm, key, data, GDBM_INSERT)
510 /* Returns from EXIM_DBPUTB */
512 #define EXIM_DBPUTB_OK 0
513 #define EXIM_DBPUTB_DUP 1
516 #define EXIM_DBDEL(db, key) gdbm_delete(db->gdbm, key)
518 /* EXIM_DBCREATE_CURSOR - initialize for scanning operation (null) */
519 #define EXIM_DBCREATE_CURSOR(db, cursor) {}
522 #define EXIM_DBSCAN(db, key, data, first, cursor) \
523 ( key = ((first)? gdbm_firstkey(db->gdbm) : gdbm_nextkey(db->gdbm, db->lkey)), \
524 (((db)->lkey.dptr != NULL)? (free((db)->lkey.dptr),1) : 1),\
525 db->lkey = key, key.dptr != NULL)
527 /* EXIM_DBDELETE_CURSOR - terminate scanning operation (null). Make it
528 refer to cursor, to keep picky compilers happy. */
529 #define EXIM_DBDELETE_CURSOR(cursor) { cursor = cursor; }
532 #define EXIM_DBCLOSE__(db) \
533 { gdbm_close((db)->gdbm);\
534 if ((db)->lkey.dptr != NULL) free((db)->lkey.dptr);\
537 /* Datum access types - these are intended to be assignable */
539 #define EXIM_DATUM_SIZE(datum) (datum).dsize
540 #define EXIM_DATUM_DATA(datum) (datum).dptr
542 /* There's no clearing required before use, but we have to free the dptr
543 after reading data. */
545 #define EXIM_DATUM_INIT(datum)
546 #define EXIM_DATUM_FREE(datum) free(datum.dptr)
551 /* If none of USE_DB, USG_GDBM, or USE_TDB are set, the default is the NDBM
555 /********************* ndbm interface definitions **********************/
562 /* Cursor type, not used with ndbm: just set up a dummy */
563 #define EXIM_CURSOR int
565 /* The datum type used for queries */
566 #define EXIM_DATUM datum
568 /* Some text for messages */
570 #define EXIM_DBTYPE "ndbm"
572 /* Access functions */
574 /* EXIM_DBOPEN - returns a EXIM_DB *, NULL if failed */
575 #define EXIM_DBOPEN__(name, dirname, flags, mode, dbpp) \
576 *(dbpp) = dbm_open(CS name, flags, mode)
578 /* EXIM_DBGET - returns TRUE if successful, FALSE otherwise */
579 #define EXIM_DBGET(db, key, data) \
580 (data = dbm_fetch(db, key), data.dptr != NULL)
582 /* EXIM_DBPUT - returns nothing useful, assumes replace mode */
583 #define EXIM_DBPUT(db, key, data) \
584 dbm_store(db, key, data, DBM_REPLACE)
586 /* EXIM_DBPUTB - non-overwriting for use by dbmbuild */
587 #define EXIM_DBPUTB(db, key, data) \
588 dbm_store(db, key, data, DBM_INSERT)
590 /* Returns from EXIM_DBPUTB */
592 #define EXIM_DBPUTB_OK 0
593 #define EXIM_DBPUTB_DUP 1
596 #define EXIM_DBDEL(db, key) dbm_delete(db, key)
598 /* EXIM_DBCREATE_CURSOR - initialize for scanning operation (null) */
599 #define EXIM_DBCREATE_CURSOR(db, cursor) {}
602 #define EXIM_DBSCAN(db, key, data, first, cursor) \
603 (key = (first? dbm_firstkey(db) : dbm_nextkey(db)), key.dptr != NULL)
605 /* EXIM_DBDELETE_CURSOR - terminate scanning operation (null). Make it
606 refer to cursor, to keep picky compilers happy. */
607 #define EXIM_DBDELETE_CURSOR(cursor) { cursor = cursor; }
610 #define EXIM_DBCLOSE__(db) dbm_close(db)
612 /* Datum access types - these are intended to be assignable */
614 #define EXIM_DATUM_SIZE(datum) (datum).dsize
615 #define EXIM_DATUM_DATA(datum) (datum).dptr
617 /* There's no clearing required before use, and we don't have to free anything
618 after reading data. */
620 #define EXIM_DATUM_INIT(datum)
621 #define EXIM_DATUM_FREE(datum)
623 #endif /* USE_GDBM */
629 # ifdef COMPILE_UTILITY
631 # define EXIM_DBOPEN(name, dirname, flags, mode, dbpp) \
632 EXIM_DBOPEN__(name, dirname, flags, mode, dbpp)
633 # define EXIM_DBCLOSE(db) EXIM_DBCLOSE__(db)
637 # define EXIM_DBOPEN(name, dirname, flags, mode, dbpp) \
639 DEBUG(D_hints_lookup) \
640 debug_printf_indent("EXIM_DBOPEN: file <%s> dir <%s> flags=%s\n", \
642 (flags) == O_RDONLY ? "O_RDONLY" \
643 : (flags) == O_RDWR ? "O_RDWR" \
644 : (flags) == (O_RDWR|O_CREAT) ? "O_RDWR|O_CREAT" \
646 if (is_tainted(name) || is_tainted(dirname)) \
648 log_write(0, LOG_MAIN|LOG_PANIC, "Tainted name for DB file not permitted"); \
652 { EXIM_DBOPEN__(name, dirname, flags, mode, dbpp); } \
653 DEBUG(D_hints_lookup) debug_printf_indent("returned from EXIM_DBOPEN: %p\n", *dbpp); \
655 # define EXIM_DBCLOSE(db) \
657 DEBUG(D_hints_lookup) debug_printf_indent("EXIM_DBCLOSE(%p)\n", db); \
658 EXIM_DBCLOSE__(db); \
663 /********************* End of dbm library definitions **********************/
666 /* Structure for carrying around an open DBM file, and an open locking file
667 that relates to it. */
675 /* Structures for records stored in exim database dbm files. They all
676 start with the same fields, described in the generic type. */
680 time_t time_stamp; /* Timestamp of writing */
684 /* This structure keeps track of retry information for a host or a local
690 time_t first_failed; /* Time of first failure */
691 time_t last_try; /* Time of last try */
692 time_t next_try; /* Time of next try */
693 BOOL expired; /* Retry time has expired */
694 int basic_errno; /* Errno of last failure */
695 int more_errno; /* Additional information */
696 uschar text[1]; /* Text message for last failure */
699 /* These structures keep track of addresses that have had callout verification
700 performed on them. There are two groups of records:
702 1. keyed by localpart@domain -
703 Full address was tested and record holds result
706 Domain response upto MAIL FROM:<>, postmaster, random local part;
708 If a record exists, the result field is either ccache_accept or ccache_reject,
709 or, for a domain record only, ccache_reject_mfnull when MAIL FROM:<> was
710 rejected. The other fields, however, (which are only relevant to domain
711 records) may also contain ccache_unknown if that particular test has not been
714 Originally, there was only one structure, used for both types. However, it got
715 expanded for domain records, so it got split. To make it possible for Exim to
716 handle the old type of record, we retain the old definition. The different
717 kinds of record can be distinguished by their different lengths. */
723 int postmaster_result; /* Postmaster is accepted */
724 int random_result; /* Random local part was accepted */
725 } dbdata_callout_cache_obs;
728 time_t time_stamp; /* Timestamp of last address check */
730 int result; /* accept or reject */
731 } dbdata_callout_cache_address;
733 /* For this new layout, we put the additional fields (the timestamps)
734 last so that if somebody reverts to an older Exim, the new records will
735 still make sense because they match the old layout. */
738 time_t time_stamp; /* Time stamp of last connection */
740 int result; /* Domain reject or accept */
741 int postmaster_result; /* Postmaster result */
742 int random_result; /* Random result */
743 time_t postmaster_stamp; /* Timestamp of postmaster check */
744 time_t random_stamp; /* Timestamp of random check */
745 } dbdata_callout_cache;
747 /* This structure keeps track of messages that are waiting for a particular
748 host for a particular transport. */
753 int count; /* Count of message ids */
754 int sequence; /* Sequence for continued records */
755 uschar text[1]; /* One long character string */
759 /* The contents of the "misc" database are a mixture of different kinds of
760 record, as defined below. The keys used for a specific type all start with a
761 given string such as "etrn-" or "host-serialize-". */
764 /* This structure records a connection to a particular host, for the
765 purpose of serializing access to certain hosts. For possible future extension,
766 a field is defined for holding the count of connections, but it is not
767 at present in use. The same structure is used for recording a running ETRN
773 int count; /* Reserved for possible connection count */
777 /* This structure records the information required for the ratelimit
783 int time_usec; /* Fractional part of time, from gettimeofday() */
784 double rate; /* Smoothed sending rate at that time */
787 /* Same as above, plus a Bloom filter for uniquifying events. */
790 dbdata_ratelimit dbd;
791 time_t bloom_epoch; /* When the Bloom filter was last reset */
792 unsigned bloom_size; /* Number of bytes in the Bloom filter */
793 uschar bloom[40]; /* Bloom filter which may be larger than this */
794 } dbdata_ratelimit_unique;
796 #ifndef DISABLE_PIPE_CONNECT
797 /* This structure records the EHLO responses, cleartext and crypted,
798 for an IP, as bitmasks (cf. OPTION_TLS) */
801 unsigned short cleartext_features;
802 unsigned short crypted_features;
803 unsigned short cleartext_auths;
804 unsigned short crypted_auths;
810 ehlo_resp_precis data;
817 uschar verify_override:1;
820 } dbdata_tls_session;
823 /* End of dbstuff.h */