Commit | Line | Data |
---|---|---|
d185889f JH |
1 | /************************************************* |
2 | * Exim - an Internet mail transport agent * | |
3 | *************************************************/ | |
4 | ||
f9ba5e22 | 5 | /* Copyright (c) Jeremy Harris 1995 - 2018 */ |
1e1ddfac | 6 | /* Copyright (c) The Exim Maintainers 2020 */ |
d185889f JH |
7 | /* See the file NOTICE for conditions of use and distribution. */ |
8 | ||
9 | /* Create a static data structure with the predefined macros, to be | |
10 | included in the main Exim build */ | |
11 | ||
12 | #include "exim.h" | |
5f69a529 | 13 | #include "macro_predef.h" |
d185889f | 14 | |
1a7c9a48 | 15 | unsigned mp_index = 0; |
d185889f JH |
16 | |
17 | /* Global dummy variables */ | |
18 | ||
19 | void fn_smtp_receive_timeout(const uschar * name, const uschar * str) {} | |
20 | uschar * syslog_facility_str; | |
21 | ||
22 | /******************************************************************************/ | |
23 | ||
24 | void | |
970424a5 | 25 | builtin_macro_create_var(const uschar * name, const uschar * val) |
d185889f | 26 | { |
1a7c9a48 JH |
27 | printf ("static macro_item p%d = { ", mp_index); |
28 | if (mp_index == 0) | |
29 | printf(".next=NULL,"); | |
30 | else | |
31 | printf(".next=&p%d,", mp_index-1); | |
32 | ||
33 | printf(" .command_line=FALSE, .namelen=%d, .replen=%d," | |
34 | " .name=US\"%s\", .replacement=US\"%s\" };\n", | |
35 | Ustrlen(name), Ustrlen(val), CS name, CS val); | |
36 | mp_index++; | |
d185889f JH |
37 | } |
38 | ||
970424a5 JH |
39 | |
40 | void | |
41 | builtin_macro_create(const uschar * name) | |
42 | { | |
43 | builtin_macro_create_var(name, US"y"); | |
44 | } | |
45 | ||
46 | ||
c11d665d | 47 | /* restricted snprintf */ |
f1f7d0cd | 48 | void |
d185889f JH |
49 | spf(uschar * buf, int len, const uschar * fmt, ...) |
50 | { | |
51 | va_list ap; | |
52 | va_start(ap, fmt); | |
53 | ||
54 | while (*fmt && len > 1) | |
55 | if (*fmt == '%' && fmt[1] == 'T') | |
56 | { | |
57 | uschar * s = va_arg(ap, uschar *); | |
58 | while (*s && len-- > 1) | |
59 | *buf++ = toupper(*s++); | |
60 | fmt += 2; | |
61 | } | |
62 | else | |
63 | { | |
64 | *buf++ = *fmt++; len--; | |
65 | } | |
66 | *buf = '\0'; | |
67 | va_end(ap); | |
68 | } | |
69 | ||
70 | void | |
71 | options_from_list(optionlist * opts, unsigned nopt, | |
72 | const uschar * section, uschar * group) | |
73 | { | |
d185889f JH |
74 | const uschar * s; |
75 | uschar buf[64]; | |
76 | ||
77 | /* The 'previously-defined-substring' rule for macros in config file | |
78 | lines is done thus for these builtin macros: we know that the table | |
79 | we source from is in strict alpha order, hence the builtins portion | |
80 | of the macros list is in reverse-alpha (we prepend them) - so longer | |
81 | macros that have substrings are always discovered first during | |
82 | expansion. */ | |
83 | ||
d7978c0f | 84 | for (int i = 0; i < nopt; i++) if (*(s = US opts[i].name) && *s != '*') |
d185889f JH |
85 | { |
86 | if (group) | |
f1f7d0cd | 87 | spf(buf, sizeof(buf), CUS"_OPT_%T_%T_%T", section, group, s); |
d185889f | 88 | else |
f1f7d0cd | 89 | spf(buf, sizeof(buf), CUS"_OPT_%T_%T", section, s); |
d185889f JH |
90 | builtin_macro_create(buf); |
91 | } | |
92 | } | |
93 | ||
94 | ||
95 | /******************************************************************************/ | |
96 | ||
97 | ||
98 | /* Create compile-time feature macros */ | |
99 | static void | |
100 | features(void) | |
101 | { | |
102 | /* Probably we could work out a static initialiser for wherever | |
103 | macros are stored, but this will do for now. Some names are awkward | |
104 | due to conflicts with other common macros. */ | |
105 | ||
106 | #ifdef SUPPORT_CRYPTEQ | |
107 | builtin_macro_create(US"_HAVE_CRYPTEQ"); | |
108 | #endif | |
109 | #if HAVE_ICONV | |
110 | builtin_macro_create(US"_HAVE_ICONV"); | |
111 | #endif | |
112 | #if HAVE_IPV6 | |
113 | builtin_macro_create(US"_HAVE_IPV6"); | |
114 | #endif | |
115 | #ifdef HAVE_SETCLASSRESOURCES | |
116 | builtin_macro_create(US"_HAVE_SETCLASSRESOURCES"); | |
117 | #endif | |
118 | #ifdef SUPPORT_PAM | |
119 | builtin_macro_create(US"_HAVE_PAM"); | |
120 | #endif | |
121 | #ifdef EXIM_PERL | |
122 | builtin_macro_create(US"_HAVE_PERL"); | |
123 | #endif | |
124 | #ifdef EXPAND_DLFUNC | |
125 | builtin_macro_create(US"_HAVE_DLFUNC"); | |
126 | #endif | |
127 | #ifdef USE_TCP_WRAPPERS | |
128 | builtin_macro_create(US"_HAVE_TCPWRAPPERS"); | |
129 | #endif | |
01603eec | 130 | #ifndef DISABLE_TLS |
d185889f JH |
131 | builtin_macro_create(US"_HAVE_TLS"); |
132 | # ifdef USE_GNUTLS | |
133 | builtin_macro_create(US"_HAVE_GNUTLS"); | |
134 | # else | |
135 | builtin_macro_create(US"_HAVE_OPENSSL"); | |
136 | # endif | |
137 | #endif | |
138 | #ifdef SUPPORT_TRANSLATE_IP_ADDRESS | |
139 | builtin_macro_create(US"_HAVE_TRANSLATE_IP_ADDRESS"); | |
140 | #endif | |
141 | #ifdef SUPPORT_MOVE_FROZEN_MESSAGES | |
142 | builtin_macro_create(US"_HAVE_MOVE_FROZEN_MESSAGES"); | |
143 | #endif | |
144 | #ifdef WITH_CONTENT_SCAN | |
145 | builtin_macro_create(US"_HAVE_CONTENT_SCANNING"); | |
146 | #endif | |
147 | #ifndef DISABLE_DKIM | |
148 | builtin_macro_create(US"_HAVE_DKIM"); | |
149 | #endif | |
1a2e76e1 JH |
150 | #ifdef SUPPORT_DMARC |
151 | builtin_macro_create(US"_HAVE_DMARC"); | |
152 | #endif | |
d185889f JH |
153 | #ifndef DISABLE_DNSSEC |
154 | builtin_macro_create(US"_HAVE_DNSSEC"); | |
155 | #endif | |
156 | #ifndef DISABLE_EVENT | |
157 | builtin_macro_create(US"_HAVE_EVENT"); | |
158 | #endif | |
159 | #ifdef SUPPORT_I18N | |
160 | builtin_macro_create(US"_HAVE_I18N"); | |
161 | #endif | |
162 | #ifndef DISABLE_OCSP | |
163 | builtin_macro_create(US"_HAVE_OCSP"); | |
164 | #endif | |
81344b40 | 165 | #ifndef DISABLE_PIPE_CONNECT |
4e48d56c JH |
166 | builtin_macro_create(US"_HAVE_PIPE_CONNECT"); |
167 | #endif | |
d185889f JH |
168 | #ifndef DISABLE_PRDR |
169 | builtin_macro_create(US"_HAVE_PRDR"); | |
170 | #endif | |
171 | #ifdef SUPPORT_PROXY | |
172 | builtin_macro_create(US"_HAVE_PROXY"); | |
173 | #endif | |
174 | #ifdef SUPPORT_SOCKS | |
175 | builtin_macro_create(US"_HAVE_SOCKS"); | |
176 | #endif | |
177 | #ifdef TCP_FASTOPEN | |
178 | builtin_macro_create(US"_HAVE_TCP_FASTOPEN"); | |
179 | #endif | |
180 | #ifdef EXPERIMENTAL_LMDB | |
181 | builtin_macro_create(US"_HAVE_LMDB"); | |
182 | #endif | |
7952eef9 | 183 | #ifdef SUPPORT_SPF |
d185889f JH |
184 | builtin_macro_create(US"_HAVE_SPF"); |
185 | #endif | |
7ef88aa0 | 186 | #if defined(EXPERIMENTAL_SRS) || defined(EXPERIMENTAL_SRS_NATIVE) |
d185889f JH |
187 | builtin_macro_create(US"_HAVE_SRS"); |
188 | #endif | |
7ef88aa0 JH |
189 | #if defined(EXPERIMENTAL_SRS_NATIVE) |
190 | builtin_macro_create(US"_HAVE_NATIVE_SRS"); /* beware clash with _HAVE_SRS */ | |
191 | #endif | |
617d3932 JH |
192 | #ifdef EXPERIMENTAL_ARC |
193 | builtin_macro_create(US"_HAVE_ARC"); | |
194 | #endif | |
d185889f JH |
195 | #ifdef EXPERIMENTAL_BRIGHTMAIL |
196 | builtin_macro_create(US"_HAVE_BRIGHTMAIL"); | |
197 | #endif | |
c0635b6d | 198 | #ifdef SUPPORT_DANE |
d185889f JH |
199 | builtin_macro_create(US"_HAVE_DANE"); |
200 | #endif | |
201 | #ifdef EXPERIMENTAL_DCC | |
202 | builtin_macro_create(US"_HAVE_DCC"); | |
203 | #endif | |
d185889f JH |
204 | #ifdef EXPERIMENTAL_DSN_INFO |
205 | builtin_macro_create(US"_HAVE_DSN_INFO"); | |
206 | #endif | |
b10c87b3 JH |
207 | #ifdef EXPERIMENTAL_TLS_RESUME |
208 | builtin_macro_create(US"_HAVE_TLS_RESUME"); | |
209 | #endif | |
d185889f JH |
210 | |
211 | #ifdef LOOKUP_LSEARCH | |
212 | builtin_macro_create(US"_HAVE_LOOKUP_LSEARCH"); | |
213 | #endif | |
214 | #ifdef LOOKUP_CDB | |
215 | builtin_macro_create(US"_HAVE_LOOKUP_CDB"); | |
216 | #endif | |
217 | #ifdef LOOKUP_DBM | |
218 | builtin_macro_create(US"_HAVE_LOOKUP_DBM"); | |
219 | #endif | |
220 | #ifdef LOOKUP_DNSDB | |
221 | builtin_macro_create(US"_HAVE_LOOKUP_DNSDB"); | |
222 | #endif | |
223 | #ifdef LOOKUP_DSEARCH | |
224 | builtin_macro_create(US"_HAVE_LOOKUP_DSEARCH"); | |
225 | #endif | |
226 | #ifdef LOOKUP_IBASE | |
227 | builtin_macro_create(US"_HAVE_LOOKUP_IBASE"); | |
228 | #endif | |
ffc92d69 JH |
229 | #ifdef LOOKUP_LDAP |
230 | builtin_macro_create(US"_HAVE_LOOKUP_JSON"); | |
231 | #endif | |
d185889f JH |
232 | #ifdef LOOKUP_LDAP |
233 | builtin_macro_create(US"_HAVE_LOOKUP_LDAP"); | |
234 | #endif | |
235 | #ifdef EXPERIMENTAL_LMDB | |
236 | builtin_macro_create(US"_HAVE_LOOKUP_LMDB"); | |
237 | #endif | |
238 | #ifdef LOOKUP_MYSQL | |
239 | builtin_macro_create(US"_HAVE_LOOKUP_MYSQL"); | |
240 | #endif | |
241 | #ifdef LOOKUP_NIS | |
242 | builtin_macro_create(US"_HAVE_LOOKUP_NIS"); | |
243 | #endif | |
244 | #ifdef LOOKUP_NISPLUS | |
245 | builtin_macro_create(US"_HAVE_LOOKUP_NISPLUS"); | |
246 | #endif | |
247 | #ifdef LOOKUP_ORACLE | |
248 | builtin_macro_create(US"_HAVE_LOOKUP_ORACLE"); | |
249 | #endif | |
250 | #ifdef LOOKUP_PASSWD | |
251 | builtin_macro_create(US"_HAVE_LOOKUP_PASSWD"); | |
252 | #endif | |
253 | #ifdef LOOKUP_PGSQL | |
254 | builtin_macro_create(US"_HAVE_LOOKUP_PGSQL"); | |
255 | #endif | |
256 | #ifdef LOOKUP_REDIS | |
257 | builtin_macro_create(US"_HAVE_LOOKUP_REDIS"); | |
258 | #endif | |
259 | #ifdef LOOKUP_SQLITE | |
260 | builtin_macro_create(US"_HAVE_LOOKUP_SQLITE"); | |
261 | #endif | |
262 | #ifdef LOOKUP_TESTDB | |
263 | builtin_macro_create(US"_HAVE_LOOKUP_TESTDB"); | |
264 | #endif | |
265 | #ifdef LOOKUP_WHOSON | |
266 | builtin_macro_create(US"_HAVE_LOOKUP_WHOSON"); | |
267 | #endif | |
268 | ||
269 | #ifdef TRANSPORT_APPENDFILE | |
270 | # ifdef SUPPORT_MAILDIR | |
271 | builtin_macro_create(US"_HAVE_TRANSPORT_APPEND_MAILDIR"); | |
272 | # endif | |
273 | # ifdef SUPPORT_MAILSTORE | |
274 | builtin_macro_create(US"_HAVE_TRANSPORT_APPEND_MAILSTORE"); | |
275 | # endif | |
276 | # ifdef SUPPORT_MBX | |
277 | builtin_macro_create(US"_HAVE_TRANSPORT_APPEND_MBX"); | |
278 | # endif | |
279 | #endif | |
c11d665d JH |
280 | |
281 | #ifdef WITH_CONTENT_SCAN | |
282 | features_malware(); | |
283 | #endif | |
260958d6 JH |
284 | |
285 | features_crypto(); | |
d185889f JH |
286 | } |
287 | ||
288 | ||
289 | static void | |
290 | options(void) | |
291 | { | |
292 | options_main(); | |
293 | options_routers(); | |
294 | options_transports(); | |
295 | options_auths(); | |
12263aa8 | 296 | options_logging(); |
01603eec | 297 | #ifndef DISABLE_TLS |
8442641e JH |
298 | options_tls(); |
299 | #endif | |
d185889f JH |
300 | } |
301 | ||
970424a5 JH |
302 | static void |
303 | params(void) | |
304 | { | |
215e8e5f | 305 | #ifndef DISABLE_DKIM |
a2701501 | 306 | params_dkim(); |
215e8e5f | 307 | #endif |
970424a5 JH |
308 | } |
309 | ||
d185889f JH |
310 | |
311 | int | |
312 | main(void) | |
313 | { | |
314 | printf("#include \"exim.h\"\n"); | |
315 | features(); | |
316 | options(); | |
970424a5 | 317 | params(); |
d185889f | 318 | |
1a7c9a48 JH |
319 | printf("macro_item * macros = &p%d;\n", mp_index-1); |
320 | printf("macro_item * mlast = &p0;\n"); | |
f1f7d0cd | 321 | exit(0); |
d185889f | 322 | } |