SPDX: Mass-update to GPL-2.0-or-later
[exim.git] / src / src / hintsdb_structs.h
1 /*************************************************
2 *     Exim - an Internet mail transport agent    *
3 *************************************************/
4
5 /* Copyright (c) University of Cambridge 1995 - 2018 */
6 /* Copyright (c) The Exim Maintainers 2020 - 2021 */
7 /* See the file NOTICE for conditions of use and distribution. */
8 /* SPDX-License-Identifier: GPL-2.0-or-later */
9
10 /* This header file contains the definitions of the structures used in the
11 various hints databases are also kept in this file, which is used by the
12 maintenance utilities as well as the main Exim binary. */
13
14 #ifndef HINTSDB_STRUCTS_H
15 #define HINTSDB_STRUCTS_H
16
17
18 /* Structure for carrying around an open DBM file, and an open locking file
19 that relates to it. */
20
21 typedef struct {
22   void *        dbptr;
23   int           lockfd;
24 } open_db;
25
26
27 /* Structures for records stored in exim database dbm files. They all
28 start with the same fields, described in the generic type. */
29
30
31 typedef struct {
32   time_t time_stamp;      /* Timestamp of writing */
33 } dbdata_generic;
34
35
36 /* This structure keeps track of retry information for a host or a local
37 address. */
38
39 typedef struct {
40   time_t time_stamp;
41   /*************/
42   time_t first_failed;    /* Time of first failure */
43   time_t last_try;        /* Time of last try */
44   time_t next_try;        /* Time of next try */
45   BOOL   expired;         /* Retry time has expired */
46   int    basic_errno;     /* Errno of last failure */
47   int    more_errno;      /* Additional information */
48   uschar text[1];         /* Text message for last failure */
49 } dbdata_retry;
50
51 /* These structures keep track of addresses that have had callout verification
52 performed on them. There are two groups of records:
53
54 1. keyed by localpart@domain -
55      Full address was tested and record holds result
56
57 2. keyed by domain -
58      Domain response upto MAIL FROM:<>, postmaster, random local part;
59
60 If a record exists, the result field is either ccache_accept or ccache_reject,
61 or, for a domain record only, ccache_reject_mfnull when MAIL FROM:<> was
62 rejected. The other fields, however, (which are only relevant to domain
63 records) may also contain ccache_unknown if that particular test has not been
64 done.
65
66 Originally, there was only one structure, used for both types. However, it got
67 expanded for domain records, so it got split. To make it possible for Exim to
68 handle the old type of record, we retain the old definition. The different
69 kinds of record can be distinguished by their different lengths. */
70
71 typedef struct {
72   time_t time_stamp;
73   /*************/
74   int   result;
75   int   postmaster_result; /* Postmaster is accepted */
76   int   random_result;     /* Random local part was accepted */
77 } dbdata_callout_cache_obs;
78
79 typedef struct {
80   time_t time_stamp;       /* Timestamp of last address check */
81   /*************/
82   int   result;            /* accept or reject */
83 } dbdata_callout_cache_address;
84
85 /* For this new layout, we put the additional fields (the timestamps)
86 last so that if somebody reverts to an older Exim, the new records will
87 still make sense because they match the old layout. */
88
89 typedef struct {
90   time_t time_stamp;       /* Time stamp of last connection */
91   /*************/
92   int   result;            /* Domain reject or accept */
93   int   postmaster_result; /* Postmaster result */
94   int   random_result;     /* Random result */
95   time_t postmaster_stamp; /* Timestamp of postmaster check */
96   time_t random_stamp;     /* Timestamp of random check */
97 } dbdata_callout_cache;
98
99 /* This structure keeps track of messages that are waiting for a particular
100 host for a particular transport. */
101
102 typedef struct {
103   time_t time_stamp;
104   /*************/
105   int    count;           /* Count of message ids */
106   int    sequence;        /* Sequence for continued records */
107   uschar text[1];         /* One long character string */
108 } dbdata_wait;
109
110
111 /* The contents of the "misc" database are a mixture of different kinds of
112 record, as defined below. The keys used for a specific type all start with a
113 given string such as "etrn-" or "host-serialize-". */
114
115
116 /* This structure records a connection to a particular host, for the
117 purpose of serializing access to certain hosts. For possible future extension,
118 a field is defined for holding the count of connections, but it is not
119 at present in use. The same structure is used for recording a running ETRN
120 process. */
121
122 typedef struct {
123   time_t time_stamp;
124   /*************/
125   int    count;           /* Reserved for possible connection count */
126 } dbdata_serialize;
127
128
129 /* This structure records the information required for the ratelimit
130 ACL condition. */
131
132 typedef struct {
133   time_t time_stamp;
134   /*************/
135   int    time_usec;       /* Fractional part of time, from gettimeofday() */
136   double rate;            /* Smoothed sending rate at that time */
137 } dbdata_ratelimit;
138
139 /* Same as above, plus a Bloom filter for uniquifying events. */
140
141 typedef struct {
142   dbdata_ratelimit dbd;
143   time_t   bloom_epoch;   /* When the Bloom filter was last reset */
144   unsigned bloom_size;    /* Number of bytes in the Bloom filter */
145   uschar   bloom[40];     /* Bloom filter which may be larger than this */
146 } dbdata_ratelimit_unique;
147
148
149 /* For "seen" ACL condition */
150 typedef struct {
151   time_t time_stamp;
152 } dbdata_seen;
153
154 #ifndef DISABLE_PIPE_CONNECT
155 /* This structure records the EHLO responses, cleartext and crypted,
156 for an IP, as bitmasks (cf. OPTION_TLS).  For LIMITS, also values
157 advertised for MAILMAX, RCPTMAX and RCPTDOMAINMAX; zero meaning no
158 value advertised. */
159
160 typedef struct {
161   unsigned short cleartext_features;
162   unsigned short crypted_features;
163   unsigned short cleartext_auths;
164   unsigned short crypted_auths;
165
166 # ifdef EXPERIMENTAL_ESMTP_LIMITS
167   unsigned int limit_mail;
168   unsigned int limit_rcpt;
169   unsigned int limit_rcptdom;
170 # endif
171 } ehlo_resp_precis;
172
173 typedef struct {
174   time_t time_stamp;
175   /*************/
176   ehlo_resp_precis data;
177 } dbdata_ehlo_resp;
178 #endif
179
180 typedef struct {
181   time_t time_stamp;
182   /*************/
183   uschar verify_override:1;
184   uschar ocsp:3;
185   uschar session[1];
186 } dbdata_tls_session;
187
188
189 #endif  /* whole file */
190 /* End of hintsdb_structs.h */