Commit | Line | Data |
---|---|---|
059ec3d9 PH |
1 | /************************************************* |
2 | * Exim - an Internet mail transport agent * | |
3 | *************************************************/ | |
4 | ||
3386088d | 5 | /* Copyright (c) University of Cambridge 1995 - 2015 */ |
059ec3d9 PH |
6 | /* See the file NOTICE for conditions of use and distribution. */ |
7 | ||
8 | ||
9 | #include "exim.h" | |
10 | ||
e6d225ae | 11 | #include <string.h> |
059ec3d9 PH |
12 | |
13 | /* This module contains tables that define the lookup methods and drivers | |
14 | that are actually included in the binary. Its contents are controlled by | |
15 | various macros in config.h that ultimately come from Local/Makefile. They are | |
16 | all described in src/EDITME. */ | |
17 | ||
18 | ||
e6d225ae DW |
19 | lookup_info **lookup_list; |
20 | int lookup_list_count = 0; | |
059ec3d9 | 21 | |
6545de78 PP |
22 | static int lookup_list_init_done = 0; |
23 | ||
059ec3d9 PH |
24 | /* Table of information about all possible authentication mechamisms. All |
25 | entries are always present if any mechanism is declared, but the functions are | |
26 | set to NULL for those that are not compiled into the binary. */ | |
27 | ||
28 | #ifdef AUTH_CRAM_MD5 | |
29 | #include "auths/cram_md5.h" | |
30 | #endif | |
31 | ||
32 | #ifdef AUTH_CYRUS_SASL | |
33 | #include "auths/cyrus_sasl.h" | |
34 | #endif | |
35 | ||
14aa5a05 PH |
36 | #ifdef AUTH_DOVECOT |
37 | #include "auths/dovecot.h" | |
38 | #endif | |
39 | ||
44bbabb5 PP |
40 | #ifdef AUTH_GSASL |
41 | #include "auths/gsasl_exim.h" | |
42 | #endif | |
43 | ||
dde3daac PP |
44 | #ifdef AUTH_HEIMDAL_GSSAPI |
45 | #include "auths/heimdal_gssapi.h" | |
46 | #endif | |
47 | ||
059ec3d9 PH |
48 | #ifdef AUTH_PLAINTEXT |
49 | #include "auths/plaintext.h" | |
50 | #endif | |
51 | ||
52 | #ifdef AUTH_SPA | |
53 | #include "auths/spa.h" | |
54 | #endif | |
55 | ||
b3ef41c9 JH |
56 | #ifdef AUTH_TLS |
57 | #include "auths/tls.h" | |
58 | #endif | |
59 | ||
059ec3d9 PH |
60 | auth_info auths_available[] = { |
61 | ||
62 | /* Checking by an expansion condition on plain text */ | |
63 | ||
64 | #ifdef AUTH_CRAM_MD5 | |
65 | { | |
66 | US"cram_md5", /* lookup name */ | |
67 | auth_cram_md5_options, | |
68 | &auth_cram_md5_options_count, | |
69 | &auth_cram_md5_option_defaults, | |
70 | sizeof(auth_cram_md5_options_block), | |
71 | auth_cram_md5_init, /* init function */ | |
72 | auth_cram_md5_server, /* server function */ | |
44bbabb5 PP |
73 | auth_cram_md5_client, /* client function */ |
74 | NULL /* diagnostic function */ | |
059ec3d9 PH |
75 | }, |
76 | #endif | |
77 | ||
78 | #ifdef AUTH_CYRUS_SASL | |
79 | { | |
384152a6 | 80 | US"cyrus_sasl", /* lookup name */ |
059ec3d9 PH |
81 | auth_cyrus_sasl_options, |
82 | &auth_cyrus_sasl_options_count, | |
83 | &auth_cyrus_sasl_option_defaults, | |
84 | sizeof(auth_cyrus_sasl_options_block), | |
85 | auth_cyrus_sasl_init, /* init function */ | |
86 | auth_cyrus_sasl_server, /* server function */ | |
44bbabb5 PP |
87 | NULL, /* client function */ |
88 | auth_cyrus_sasl_version_report /* diagnostic function */ | |
059ec3d9 PH |
89 | }, |
90 | #endif | |
91 | ||
14aa5a05 PH |
92 | #ifdef AUTH_DOVECOT |
93 | { | |
94 | US"dovecot", /* lookup name */ | |
95 | auth_dovecot_options, | |
96 | &auth_dovecot_options_count, | |
97 | &auth_dovecot_option_defaults, | |
98 | sizeof(auth_dovecot_options_block), | |
99 | auth_dovecot_init, /* init function */ | |
100 | auth_dovecot_server, /* server function */ | |
44bbabb5 PP |
101 | NULL, /* client function */ |
102 | NULL /* diagnostic function */ | |
103 | }, | |
104 | #endif | |
105 | ||
106 | #ifdef AUTH_GSASL | |
107 | { | |
108 | US"gsasl", /* lookup name */ | |
109 | auth_gsasl_options, | |
110 | &auth_gsasl_options_count, | |
111 | &auth_gsasl_option_defaults, | |
112 | sizeof(auth_gsasl_options_block), | |
113 | auth_gsasl_init, /* init function */ | |
114 | auth_gsasl_server, /* server function */ | |
115 | NULL, /* client function */ | |
116 | auth_gsasl_version_report /* diagnostic function */ | |
14aa5a05 PH |
117 | }, |
118 | #endif | |
119 | ||
dde3daac PP |
120 | #ifdef AUTH_HEIMDAL_GSSAPI |
121 | { | |
122 | US"heimdal_gssapi", /* lookup name */ | |
123 | auth_heimdal_gssapi_options, | |
124 | &auth_heimdal_gssapi_options_count, | |
125 | &auth_heimdal_gssapi_option_defaults, | |
126 | sizeof(auth_heimdal_gssapi_options_block), | |
127 | auth_heimdal_gssapi_init, /* init function */ | |
128 | auth_heimdal_gssapi_server, /* server function */ | |
129 | NULL, /* client function */ | |
130 | auth_heimdal_gssapi_version_report /* diagnostic function */ | |
131 | }, | |
132 | #endif | |
133 | ||
059ec3d9 PH |
134 | #ifdef AUTH_PLAINTEXT |
135 | { | |
136 | US"plaintext", /* lookup name */ | |
137 | auth_plaintext_options, | |
138 | &auth_plaintext_options_count, | |
139 | &auth_plaintext_option_defaults, | |
140 | sizeof(auth_plaintext_options_block), | |
141 | auth_plaintext_init, /* init function */ | |
142 | auth_plaintext_server, /* server function */ | |
44bbabb5 PP |
143 | auth_plaintext_client, /* client function */ |
144 | NULL /* diagnostic function */ | |
059ec3d9 PH |
145 | }, |
146 | #endif | |
147 | ||
148 | #ifdef AUTH_SPA | |
149 | { | |
150 | US"spa", /* lookup name */ | |
151 | auth_spa_options, | |
152 | &auth_spa_options_count, | |
153 | &auth_spa_option_defaults, | |
154 | sizeof(auth_spa_options_block), | |
155 | auth_spa_init, /* init function */ | |
156 | auth_spa_server, /* server function */ | |
44bbabb5 PP |
157 | auth_spa_client, /* client function */ |
158 | NULL /* diagnostic function */ | |
059ec3d9 PH |
159 | }, |
160 | #endif | |
161 | ||
b3ef41c9 JH |
162 | #ifdef AUTH_TLS |
163 | { | |
164 | US"tls", /* lookup name */ | |
165 | auth_tls_options, | |
166 | &auth_tls_options_count, | |
167 | &auth_tls_option_defaults, | |
168 | sizeof(auth_tls_options_block), | |
169 | auth_tls_init, /* init function */ | |
170 | auth_tls_server, /* server function */ | |
171 | NULL, /* client function */ | |
172 | NULL /* diagnostic function */ | |
173 | }, | |
174 | #endif | |
175 | ||
44bbabb5 | 176 | { US"", NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL } |
059ec3d9 PH |
177 | }; |
178 | ||
179 | ||
180 | /* Tables of information about which routers and transports are included in the | |
181 | exim binary. */ | |
182 | ||
183 | /* Pull in the necessary header files */ | |
184 | ||
185 | #include "routers/rf_functions.h" | |
186 | ||
187 | #ifdef ROUTER_ACCEPT | |
188 | #include "routers/accept.h" | |
189 | #endif | |
190 | ||
191 | #ifdef ROUTER_DNSLOOKUP | |
192 | #include "routers/dnslookup.h" | |
193 | #endif | |
194 | ||
195 | #ifdef ROUTER_MANUALROUTE | |
196 | #include "routers/manualroute.h" | |
197 | #endif | |
198 | ||
199 | #ifdef ROUTER_IPLITERAL | |
200 | #include "routers/ipliteral.h" | |
201 | #endif | |
202 | ||
203 | #ifdef ROUTER_IPLOOKUP | |
204 | #include "routers/iplookup.h" | |
205 | #endif | |
206 | ||
207 | #ifdef ROUTER_QUERYPROGRAM | |
208 | #include "routers/queryprogram.h" | |
209 | #endif | |
210 | ||
211 | #ifdef ROUTER_REDIRECT | |
212 | #include "routers/redirect.h" | |
213 | #endif | |
214 | ||
215 | #ifdef TRANSPORT_APPENDFILE | |
216 | #include "transports/appendfile.h" | |
217 | #endif | |
218 | ||
219 | #ifdef TRANSPORT_AUTOREPLY | |
220 | #include "transports/autoreply.h" | |
221 | #endif | |
222 | ||
223 | #ifdef TRANSPORT_LMTP | |
224 | #include "transports/lmtp.h" | |
225 | #endif | |
226 | ||
227 | #ifdef TRANSPORT_PIPE | |
228 | #include "transports/pipe.h" | |
229 | #endif | |
230 | ||
231 | #ifdef TRANSPORT_SMTP | |
232 | #include "transports/smtp.h" | |
233 | #endif | |
234 | ||
235 | ||
236 | /* Now set up the structures, terminated by an entry with a null name. */ | |
237 | ||
238 | router_info routers_available[] = { | |
239 | #ifdef ROUTER_ACCEPT | |
240 | { | |
241 | US"accept", | |
242 | accept_router_options, | |
243 | &accept_router_options_count, | |
244 | &accept_router_option_defaults, | |
245 | sizeof(accept_router_options_block), | |
246 | accept_router_init, | |
247 | accept_router_entry, | |
248 | NULL, /* no tidyup entry */ | |
249 | ri_yestransport | |
250 | }, | |
251 | #endif | |
252 | #ifdef ROUTER_DNSLOOKUP | |
253 | { | |
254 | US"dnslookup", | |
255 | dnslookup_router_options, | |
256 | &dnslookup_router_options_count, | |
257 | &dnslookup_router_option_defaults, | |
258 | sizeof(dnslookup_router_options_block), | |
259 | dnslookup_router_init, | |
260 | dnslookup_router_entry, | |
261 | NULL, /* no tidyup entry */ | |
262 | ri_yestransport | |
263 | }, | |
264 | #endif | |
265 | #ifdef ROUTER_IPLITERAL | |
266 | { | |
267 | US"ipliteral", | |
268 | ipliteral_router_options, | |
269 | &ipliteral_router_options_count, | |
270 | &ipliteral_router_option_defaults, | |
271 | sizeof(ipliteral_router_options_block), | |
272 | ipliteral_router_init, | |
273 | ipliteral_router_entry, | |
274 | NULL, /* no tidyup entry */ | |
275 | ri_yestransport | |
276 | }, | |
277 | #endif | |
278 | #ifdef ROUTER_IPLOOKUP | |
279 | { | |
280 | US"iplookup", | |
281 | iplookup_router_options, | |
282 | &iplookup_router_options_count, | |
283 | &iplookup_router_option_defaults, | |
284 | sizeof(iplookup_router_options_block), | |
285 | iplookup_router_init, | |
286 | iplookup_router_entry, | |
287 | NULL, /* no tidyup entry */ | |
288 | ri_notransport | |
289 | }, | |
290 | #endif | |
291 | #ifdef ROUTER_MANUALROUTE | |
292 | { | |
293 | US"manualroute", | |
294 | manualroute_router_options, | |
295 | &manualroute_router_options_count, | |
296 | &manualroute_router_option_defaults, | |
297 | sizeof(manualroute_router_options_block), | |
298 | manualroute_router_init, | |
299 | manualroute_router_entry, | |
300 | NULL, /* no tidyup entry */ | |
301 | 0 | |
302 | }, | |
303 | #endif | |
304 | #ifdef ROUTER_QUERYPROGRAM | |
305 | { | |
306 | US"queryprogram", | |
307 | queryprogram_router_options, | |
308 | &queryprogram_router_options_count, | |
309 | &queryprogram_router_option_defaults, | |
310 | sizeof(queryprogram_router_options_block), | |
311 | queryprogram_router_init, | |
312 | queryprogram_router_entry, | |
313 | NULL, /* no tidyup entry */ | |
314 | 0 | |
315 | }, | |
316 | #endif | |
317 | #ifdef ROUTER_REDIRECT | |
318 | { | |
319 | US"redirect", | |
320 | redirect_router_options, | |
321 | &redirect_router_options_count, | |
322 | &redirect_router_option_defaults, | |
323 | sizeof(redirect_router_options_block), | |
324 | redirect_router_init, | |
325 | redirect_router_entry, | |
326 | NULL, /* no tidyup entry */ | |
327 | ri_notransport | |
328 | }, | |
329 | #endif | |
330 | { US"", NULL, NULL, NULL, 0, NULL, NULL, NULL, 0 } | |
331 | }; | |
332 | ||
333 | ||
334 | ||
335 | transport_info transports_available[] = { | |
336 | #ifdef TRANSPORT_APPENDFILE | |
337 | { | |
338 | US"appendfile", /* driver name */ | |
339 | appendfile_transport_options, /* local options table */ | |
340 | &appendfile_transport_options_count, /* number of entries */ | |
341 | &appendfile_transport_option_defaults, /* private options defaults */ | |
342 | sizeof(appendfile_transport_options_block), /* size of private block */ | |
343 | appendfile_transport_init, /* init entry point */ | |
344 | appendfile_transport_entry, /* main entry point */ | |
345 | NULL, /* no tidyup entry */ | |
346 | NULL, /* no closedown entry */ | |
347 | TRUE, /* local flag */ | |
348 | }, | |
349 | #endif | |
350 | #ifdef TRANSPORT_AUTOREPLY | |
351 | { | |
352 | US"autoreply", /* driver name */ | |
353 | autoreply_transport_options, /* local options table */ | |
354 | &autoreply_transport_options_count, /* number of entries */ | |
355 | &autoreply_transport_option_defaults, /* private options defaults */ | |
356 | sizeof(autoreply_transport_options_block), /* size of private block */ | |
357 | autoreply_transport_init, /* init entry point */ | |
358 | autoreply_transport_entry, /* main entry point */ | |
359 | NULL, /* no tidyup entry */ | |
360 | NULL, /* no closedown entry */ | |
361 | TRUE /* local flag */ | |
362 | }, | |
363 | #endif | |
364 | #ifdef TRANSPORT_LMTP | |
365 | { | |
366 | US"lmtp", /* driver name */ | |
367 | lmtp_transport_options, /* local options table */ | |
368 | &lmtp_transport_options_count, /* number of entries */ | |
369 | &lmtp_transport_option_defaults, /* private options defaults */ | |
370 | sizeof(lmtp_transport_options_block), /* size of private block */ | |
371 | lmtp_transport_init, /* init entry point */ | |
372 | lmtp_transport_entry, /* main entry point */ | |
373 | NULL, /* no tidyup entry */ | |
374 | NULL, /* no closedown entry */ | |
375 | TRUE /* local flag */ | |
376 | }, | |
377 | #endif | |
378 | #ifdef TRANSPORT_PIPE | |
379 | { | |
380 | US"pipe", /* driver name */ | |
381 | pipe_transport_options, /* local options table */ | |
382 | &pipe_transport_options_count, /* number of entries */ | |
383 | &pipe_transport_option_defaults, /* private options defaults */ | |
384 | sizeof(pipe_transport_options_block), /* size of private block */ | |
385 | pipe_transport_init, /* init entry point */ | |
386 | pipe_transport_entry, /* main entry point */ | |
387 | NULL, /* no tidyup entry */ | |
388 | NULL, /* no closedown entry */ | |
389 | TRUE /* local flag */ | |
390 | }, | |
391 | #endif | |
392 | #ifdef TRANSPORT_SMTP | |
393 | { | |
394 | US"smtp", /* driver name */ | |
395 | smtp_transport_options, /* local options table */ | |
396 | &smtp_transport_options_count, /* number of entries */ | |
397 | &smtp_transport_option_defaults, /* private options defaults */ | |
398 | sizeof(smtp_transport_options_block), /* size of private block */ | |
399 | smtp_transport_init, /* init entry point */ | |
400 | smtp_transport_entry, /* main entry point */ | |
401 | NULL, /* no tidyup entry */ | |
402 | smtp_transport_closedown, /* close down passed channel */ | |
403 | FALSE /* local flag */ | |
404 | }, | |
405 | #endif | |
406 | { US"", NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL, FALSE } | |
407 | }; | |
408 | ||
e6d225ae DW |
409 | struct lookupmodulestr |
410 | { | |
411 | void *dl; | |
412 | struct lookup_module_info *info; | |
413 | struct lookupmodulestr *next; | |
414 | }; | |
415 | ||
416 | static struct lookupmodulestr *lookupmodules = NULL; | |
417 | ||
418 | static void addlookupmodule(void *dl, struct lookup_module_info *info) | |
419 | { | |
420 | struct lookupmodulestr *p = store_malloc(sizeof(struct lookupmodulestr)); | |
421 | p->dl = dl; | |
422 | p->info = info; | |
423 | p->next = lookupmodules; | |
424 | lookupmodules = p; | |
425 | lookup_list_count += info->lookupcount; | |
426 | } | |
427 | ||
428 | /* only valid after lookup_list and lookup_list_count are assigned */ | |
429 | static void add_lookup_to_list(lookup_info *info) | |
430 | { | |
431 | /* need to add the lookup to lookup_list, sorted */ | |
432 | int pos = 0; | |
433 | ||
434 | /* strategy is to go through the list until we find | |
435 | * either an empty spot or a name that is higher. | |
436 | * this can't fail because we have enough space. */ | |
437 | while (lookup_list[pos] | |
438 | && (Ustrcmp(lookup_list[pos]->name, info->name) <= 0)) { | |
439 | pos++; | |
440 | } | |
441 | if (lookup_list[pos]) { | |
442 | /* need to insert it, so move all the other items up | |
443 | * (last slot is still empty, of course) */ | |
444 | memmove(&lookup_list[pos+1], | |
445 | &lookup_list[pos], | |
446 | sizeof(lookup_info **) * (lookup_list_count-pos-1)); | |
447 | } | |
448 | lookup_list[pos] = info; | |
449 | } | |
450 | ||
4d805ee9 PP |
451 | |
452 | /* These need to be at file level for old versions of gcc (2.95.2 reported), | |
453 | * which give parse errors on an extern in function scope. Each entry needs | |
454 | * to also be invoked in init_lookup_list() below */ | |
455 | ||
456 | #if defined(LOOKUP_WHOSON) && LOOKUP_WHOSON!=2 | |
457 | extern lookup_module_info whoson_lookup_module_info; | |
458 | #endif | |
459 | #if defined(LOOKUP_TESTDB) && LOOKUP_TESTDB!=2 | |
460 | extern lookup_module_info testdb_lookup_module_info; | |
461 | #endif | |
462 | #if defined(LOOKUP_SQLITE) && LOOKUP_SQLITE!=2 | |
463 | extern lookup_module_info sqlite_lookup_module_info; | |
464 | #endif | |
465 | #ifdef EXPERIMENTAL_SPF | |
466 | extern lookup_module_info spf_lookup_module_info; | |
467 | #endif | |
468 | #if defined(LOOKUP_PGSQL) && LOOKUP_PGSQL!=2 | |
469 | extern lookup_module_info pgsql_lookup_module_info; | |
470 | #endif | |
471 | #if defined(LOOKUP_PASSWD) && LOOKUP_PASSWD!=2 | |
472 | extern lookup_module_info passwd_lookup_module_info; | |
473 | #endif | |
de78e2d5 JH |
474 | #if defined(LOOKUP_REDIS) && LOOKUP_REDIS!=2 |
475 | extern lookup_module_info redis_lookup_module_info; | |
476 | #endif | |
4d805ee9 PP |
477 | #if defined(LOOKUP_ORACLE) && LOOKUP_ORACLE!=2 |
478 | extern lookup_module_info oracle_lookup_module_info; | |
479 | #endif | |
480 | #if defined(LOOKUP_NISPLUS) && LOOKUP_NISPLUS!=2 | |
481 | extern lookup_module_info nisplus_lookup_module_info; | |
482 | #endif | |
483 | #if defined(LOOKUP_NIS) && LOOKUP_NIS!=2 | |
484 | extern lookup_module_info nis_lookup_module_info; | |
485 | #endif | |
486 | #if defined(LOOKUP_MYSQL) && LOOKUP_MYSQL!=2 | |
487 | extern lookup_module_info mysql_lookup_module_info; | |
488 | #endif | |
489 | #if defined(LOOKUP_LSEARCH) && LOOKUP_LSEARCH!=2 | |
490 | extern lookup_module_info lsearch_lookup_module_info; | |
491 | #endif | |
492 | #ifdef LOOKUP_LDAP | |
493 | extern lookup_module_info ldap_lookup_module_info; | |
494 | #endif | |
495 | #if defined(LOOKUP_IBASE) && LOOKUP_IBASE!=2 | |
496 | extern lookup_module_info ibase_lookup_module_info; | |
497 | #endif | |
498 | #if defined(LOOKUP_DSEARCH) && LOOKUP_DSEARCH!=2 | |
499 | extern lookup_module_info dsearch_lookup_module_info; | |
500 | #endif | |
501 | #if defined(LOOKUP_DNSDB) && LOOKUP_DNSDB!=2 | |
502 | extern lookup_module_info dnsdb_lookup_module_info; | |
503 | #endif | |
504 | #if defined(LOOKUP_DBM) && LOOKUP_DBM!=2 | |
505 | extern lookup_module_info dbmdb_lookup_module_info; | |
506 | #endif | |
507 | #if defined(LOOKUP_CDB) && LOOKUP_CDB!=2 | |
508 | extern lookup_module_info cdb_lookup_module_info; | |
509 | #endif | |
510 | ||
e6d225ae DW |
511 | void init_lookup_list(void) |
512 | { | |
fb2bba55 | 513 | #ifdef LOOKUP_MODULE_DIR |
e6d225ae DW |
514 | DIR *dd; |
515 | struct dirent *ent; | |
e6d225ae DW |
516 | int countmodules = 0; |
517 | int moduleerrors = 0; | |
fb2bba55 | 518 | #endif |
e6d225ae | 519 | struct lookupmodulestr *p; |
fb2bba55 PP |
520 | const pcre *regex_islookupmod = regex_must_compile( |
521 | US"\\." DYNLIB_FN_EXT "$", FALSE, TRUE); | |
e6d225ae | 522 | |
6545de78 PP |
523 | if (lookup_list_init_done) |
524 | return; | |
525 | lookup_list_init_done = 1; | |
526 | ||
e6d225ae | 527 | #if defined(LOOKUP_CDB) && LOOKUP_CDB!=2 |
e6d225ae DW |
528 | addlookupmodule(NULL, &cdb_lookup_module_info); |
529 | #endif | |
530 | ||
531 | #if defined(LOOKUP_DBM) && LOOKUP_DBM!=2 | |
e6d225ae DW |
532 | addlookupmodule(NULL, &dbmdb_lookup_module_info); |
533 | #endif | |
534 | ||
535 | #if defined(LOOKUP_DNSDB) && LOOKUP_DNSDB!=2 | |
e6d225ae DW |
536 | addlookupmodule(NULL, &dnsdb_lookup_module_info); |
537 | #endif | |
538 | ||
539 | #if defined(LOOKUP_DSEARCH) && LOOKUP_DSEARCH!=2 | |
e6d225ae DW |
540 | addlookupmodule(NULL, &dsearch_lookup_module_info); |
541 | #endif | |
542 | ||
543 | #if defined(LOOKUP_IBASE) && LOOKUP_IBASE!=2 | |
e6d225ae DW |
544 | addlookupmodule(NULL, &ibase_lookup_module_info); |
545 | #endif | |
546 | ||
547 | #ifdef LOOKUP_LDAP | |
e6d225ae DW |
548 | addlookupmodule(NULL, &ldap_lookup_module_info); |
549 | #endif | |
550 | ||
551 | #if defined(LOOKUP_LSEARCH) && LOOKUP_LSEARCH!=2 | |
e6d225ae DW |
552 | addlookupmodule(NULL, &lsearch_lookup_module_info); |
553 | #endif | |
554 | ||
555 | #if defined(LOOKUP_MYSQL) && LOOKUP_MYSQL!=2 | |
e6d225ae DW |
556 | addlookupmodule(NULL, &mysql_lookup_module_info); |
557 | #endif | |
558 | ||
559 | #if defined(LOOKUP_NIS) && LOOKUP_NIS!=2 | |
e6d225ae DW |
560 | addlookupmodule(NULL, &nis_lookup_module_info); |
561 | #endif | |
562 | ||
563 | #if defined(LOOKUP_NISPLUS) && LOOKUP_NISPLUS!=2 | |
e6d225ae DW |
564 | addlookupmodule(NULL, &nisplus_lookup_module_info); |
565 | #endif | |
566 | ||
567 | #if defined(LOOKUP_ORACLE) && LOOKUP_ORACLE!=2 | |
e6d225ae DW |
568 | addlookupmodule(NULL, &oracle_lookup_module_info); |
569 | #endif | |
570 | ||
571 | #if defined(LOOKUP_PASSWD) && LOOKUP_PASSWD!=2 | |
e6d225ae DW |
572 | addlookupmodule(NULL, &passwd_lookup_module_info); |
573 | #endif | |
574 | ||
575 | #if defined(LOOKUP_PGSQL) && LOOKUP_PGSQL!=2 | |
e6d225ae DW |
576 | addlookupmodule(NULL, &pgsql_lookup_module_info); |
577 | #endif | |
578 | ||
de78e2d5 | 579 | #if defined(LOOKUP_REDIS) && LOOKUP_REDIS!=2 |
9bdd29ad TL |
580 | addlookupmodule(NULL, &redis_lookup_module_info); |
581 | #endif | |
582 | ||
e6d225ae | 583 | #ifdef EXPERIMENTAL_SPF |
e6d225ae DW |
584 | addlookupmodule(NULL, &spf_lookup_module_info); |
585 | #endif | |
586 | ||
587 | #if defined(LOOKUP_SQLITE) && LOOKUP_SQLITE!=2 | |
e6d225ae DW |
588 | addlookupmodule(NULL, &sqlite_lookup_module_info); |
589 | #endif | |
590 | ||
591 | #if defined(LOOKUP_TESTDB) && LOOKUP_TESTDB!=2 | |
e6d225ae DW |
592 | addlookupmodule(NULL, &testdb_lookup_module_info); |
593 | #endif | |
594 | ||
595 | #if defined(LOOKUP_WHOSON) && LOOKUP_WHOSON!=2 | |
e6d225ae DW |
596 | addlookupmodule(NULL, &whoson_lookup_module_info); |
597 | #endif | |
598 | ||
599 | #ifdef LOOKUP_MODULE_DIR | |
600 | dd = opendir(LOOKUP_MODULE_DIR); | |
601 | if (dd == NULL) { | |
1594a79a | 602 | DEBUG(D_lookup) debug_printf("Couldn't open %s: not loading lookup modules\n", LOOKUP_MODULE_DIR); |
e6d225ae DW |
603 | log_write(0, LOG_MAIN, "Couldn't open %s: not loading lookup modules\n", LOOKUP_MODULE_DIR); |
604 | } | |
605 | else { | |
1594a79a | 606 | DEBUG(D_lookup) debug_printf("Loading lookup modules from %s\n", LOOKUP_MODULE_DIR); |
e6d225ae DW |
607 | while ((ent = readdir(dd)) != NULL) { |
608 | char *name = ent->d_name; | |
609 | int len = (int)strlen(name); | |
610 | if (pcre_exec(regex_islookupmod, NULL, name, len, 0, PCRE_EOPT, NULL, 0) >= 0) { | |
611 | int pathnamelen = len + (int)strlen(LOOKUP_MODULE_DIR) + 2; | |
612 | void *dl; | |
613 | struct lookup_module_info *info; | |
1ba28e2b | 614 | const char *errormsg; |
e6d225ae DW |
615 | |
616 | /* SRH: am I being paranoid here or what? */ | |
617 | if (pathnamelen > big_buffer_size) { | |
618 | fprintf(stderr, "Loading lookup modules: %s/%s: name too long\n", LOOKUP_MODULE_DIR, name); | |
619 | log_write(0, LOG_MAIN|LOG_PANIC, "%s/%s: name too long\n", LOOKUP_MODULE_DIR, name); | |
620 | continue; | |
621 | } | |
622 | ||
623 | /* SRH: snprintf here? */ | |
624 | sprintf(CS big_buffer, "%s/%s", LOOKUP_MODULE_DIR, name); | |
625 | ||
626 | dl = dlopen(CS big_buffer, RTLD_NOW);// TJ was LAZY | |
627 | if (dl == NULL) { | |
628 | fprintf(stderr, "Error loading %s: %s\n", name, dlerror()); | |
629 | moduleerrors++; | |
630 | log_write(0, LOG_MAIN|LOG_PANIC, "Error loading lookup module %s: %s\n", name, dlerror()); | |
631 | continue; | |
632 | } | |
633 | ||
56e0c4ce PP |
634 | /* FreeBSD nsdispatch() can trigger dlerror() errors about |
635 | * _nss_cache_cycle_prevention_function; we need to clear the dlerror() | |
636 | * state before calling dlsym(), so that any error afterwards only | |
637 | * comes from dlsym(). | |
638 | */ | |
639 | errormsg = dlerror(); | |
640 | ||
e6d225ae DW |
641 | info = (struct lookup_module_info*) dlsym(dl, "_lookup_module_info"); |
642 | if ((errormsg = dlerror()) != NULL) { | |
643 | fprintf(stderr, "%s does not appear to be a lookup module (%s)\n", name, errormsg); | |
644 | dlclose(dl); | |
645 | moduleerrors++; | |
646 | log_write(0, LOG_MAIN|LOG_PANIC, "%s does not appear to be a lookup module (%s)\n", name, errormsg); | |
647 | continue; | |
648 | } | |
649 | if (info->magic != LOOKUP_MODULE_INFO_MAGIC) { | |
650 | fprintf(stderr, "Lookup module %s is not compatible with this version of Exim\n", name); | |
651 | dlclose(dl); | |
652 | moduleerrors++; | |
653 | log_write(0, LOG_MAIN|LOG_PANIC, "Lookup module %s is not compatible with this version of Exim\n", name); | |
654 | continue; | |
655 | } | |
656 | ||
657 | addlookupmodule(dl, info); | |
1594a79a | 658 | DEBUG(D_lookup) debug_printf("Loaded \"%s\" (%d lookup types)\n", name, info->lookupcount); |
e6d225ae DW |
659 | countmodules++; |
660 | } | |
661 | } | |
662 | closedir(dd); | |
663 | } | |
664 | ||
1594a79a | 665 | DEBUG(D_lookup) debug_printf("Loaded %d lookup modules\n", countmodules); |
e6d225ae DW |
666 | #endif |
667 | ||
668 | store_free((void*)regex_islookupmod); | |
669 | ||
1594a79a | 670 | DEBUG(D_lookup) debug_printf("Total %d lookups\n", lookup_list_count); |
e6d225ae DW |
671 | |
672 | lookup_list = store_malloc(sizeof(lookup_info *) * lookup_list_count); | |
673 | memset(lookup_list, 0, sizeof(lookup_info *) * lookup_list_count); | |
674 | ||
675 | /* now add all lookups to the real list */ | |
676 | p = lookupmodules; | |
677 | while (p) { | |
678 | int j; | |
679 | struct lookupmodulestr *pnext; | |
680 | ||
681 | for (j = 0; j < p->info->lookupcount; j++) | |
682 | add_lookup_to_list(p->info->lookups[j]); | |
683 | ||
684 | pnext = p->next; | |
685 | store_free(p); | |
686 | p = pnext; | |
687 | } | |
688 | /* just to be sure */ | |
689 | lookupmodules = NULL; | |
690 | } | |
691 | ||
059ec3d9 | 692 | /* End of drtables.c */ |