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