1 /*************************************************
2 * Exim - an Internet mail transport agent *
3 *************************************************/
5 /* Copyright (c) University of Cambridge 1995 - 2016 */
6 /* See the file NOTICE for conditions of use and distribution. */
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. */
19 lookup_info **lookup_list;
20 int lookup_list_count = 0;
22 /* Table of information about all possible authentication mechanisms. All
23 entries are always present if any mechanism is declared, but the functions are
24 set to NULL for those that are not compiled into the binary. */
27 #include "auths/cram_md5.h"
30 #ifdef AUTH_CYRUS_SASL
31 #include "auths/cyrus_sasl.h"
35 #include "auths/dovecot.h"
39 #include "auths/gsasl_exim.h"
42 #ifdef AUTH_HEIMDAL_GSSAPI
43 #include "auths/heimdal_gssapi.h"
47 #include "auths/plaintext.h"
51 #include "auths/spa.h"
55 #include "auths/tls.h"
58 auth_info auths_available[] = {
60 /* Checking by an expansion condition on plain text */
64 US"cram_md5", /* lookup name */
65 auth_cram_md5_options,
66 &auth_cram_md5_options_count,
67 &auth_cram_md5_option_defaults,
68 sizeof(auth_cram_md5_options_block),
69 auth_cram_md5_init, /* init function */
70 auth_cram_md5_server, /* server function */
71 auth_cram_md5_client, /* client function */
72 NULL /* diagnostic function */
76 #ifdef AUTH_CYRUS_SASL
78 US"cyrus_sasl", /* lookup name */
79 auth_cyrus_sasl_options,
80 &auth_cyrus_sasl_options_count,
81 &auth_cyrus_sasl_option_defaults,
82 sizeof(auth_cyrus_sasl_options_block),
83 auth_cyrus_sasl_init, /* init function */
84 auth_cyrus_sasl_server, /* server function */
85 NULL, /* client function */
86 auth_cyrus_sasl_version_report /* diagnostic function */
92 US"dovecot", /* lookup name */
94 &auth_dovecot_options_count,
95 &auth_dovecot_option_defaults,
96 sizeof(auth_dovecot_options_block),
97 auth_dovecot_init, /* init function */
98 auth_dovecot_server, /* server function */
99 NULL, /* client function */
100 NULL /* diagnostic function */
106 US"gsasl", /* lookup name */
108 &auth_gsasl_options_count,
109 &auth_gsasl_option_defaults,
110 sizeof(auth_gsasl_options_block),
111 auth_gsasl_init, /* init function */
112 auth_gsasl_server, /* server function */
113 NULL, /* client function */
114 auth_gsasl_version_report /* diagnostic function */
118 #ifdef AUTH_HEIMDAL_GSSAPI
120 US"heimdal_gssapi", /* lookup name */
121 auth_heimdal_gssapi_options,
122 &auth_heimdal_gssapi_options_count,
123 &auth_heimdal_gssapi_option_defaults,
124 sizeof(auth_heimdal_gssapi_options_block),
125 auth_heimdal_gssapi_init, /* init function */
126 auth_heimdal_gssapi_server, /* server function */
127 NULL, /* client function */
128 auth_heimdal_gssapi_version_report /* diagnostic function */
132 #ifdef AUTH_PLAINTEXT
134 US"plaintext", /* lookup name */
135 auth_plaintext_options,
136 &auth_plaintext_options_count,
137 &auth_plaintext_option_defaults,
138 sizeof(auth_plaintext_options_block),
139 auth_plaintext_init, /* init function */
140 auth_plaintext_server, /* server function */
141 auth_plaintext_client, /* client function */
142 NULL /* diagnostic function */
148 US"spa", /* lookup name */
150 &auth_spa_options_count,
151 &auth_spa_option_defaults,
152 sizeof(auth_spa_options_block),
153 auth_spa_init, /* init function */
154 auth_spa_server, /* server function */
155 auth_spa_client, /* client function */
156 NULL /* diagnostic function */
162 US"tls", /* lookup name */
164 &auth_tls_options_count,
165 &auth_tls_option_defaults,
166 sizeof(auth_tls_options_block),
167 auth_tls_init, /* init function */
168 auth_tls_server, /* server function */
169 NULL, /* client function */
170 NULL /* diagnostic function */
174 { US"", NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL }
178 /* Tables of information about which routers and transports are included in the
181 /* Pull in the necessary header files */
183 #include "routers/rf_functions.h"
186 #include "routers/accept.h"
189 #ifdef ROUTER_DNSLOOKUP
190 #include "routers/dnslookup.h"
193 #ifdef ROUTER_MANUALROUTE
194 #include "routers/manualroute.h"
197 #ifdef ROUTER_IPLITERAL
198 #include "routers/ipliteral.h"
201 #ifdef ROUTER_IPLOOKUP
202 #include "routers/iplookup.h"
205 #ifdef ROUTER_QUERYPROGRAM
206 #include "routers/queryprogram.h"
209 #ifdef ROUTER_REDIRECT
210 #include "routers/redirect.h"
213 #ifdef TRANSPORT_APPENDFILE
214 #include "transports/appendfile.h"
217 #ifdef TRANSPORT_AUTOREPLY
218 #include "transports/autoreply.h"
221 #ifdef TRANSPORT_LMTP
222 #include "transports/lmtp.h"
225 #ifdef TRANSPORT_PIPE
226 #include "transports/pipe.h"
229 #ifdef EXPERIMENTAL_QUEUEFILE
230 #include "transports/queuefile.h"
233 #ifdef TRANSPORT_SMTP
234 #include "transports/smtp.h"
238 /* Now set up the structures, terminated by an entry with a null name. */
240 router_info routers_available[] = {
244 accept_router_options,
245 &accept_router_options_count,
246 &accept_router_option_defaults,
247 sizeof(accept_router_options_block),
250 NULL, /* no tidyup entry */
254 #ifdef ROUTER_DNSLOOKUP
257 dnslookup_router_options,
258 &dnslookup_router_options_count,
259 &dnslookup_router_option_defaults,
260 sizeof(dnslookup_router_options_block),
261 dnslookup_router_init,
262 dnslookup_router_entry,
263 NULL, /* no tidyup entry */
267 #ifdef ROUTER_IPLITERAL
270 ipliteral_router_options,
271 &ipliteral_router_options_count,
272 &ipliteral_router_option_defaults,
273 sizeof(ipliteral_router_options_block),
274 ipliteral_router_init,
275 ipliteral_router_entry,
276 NULL, /* no tidyup entry */
280 #ifdef ROUTER_IPLOOKUP
283 iplookup_router_options,
284 &iplookup_router_options_count,
285 &iplookup_router_option_defaults,
286 sizeof(iplookup_router_options_block),
287 iplookup_router_init,
288 iplookup_router_entry,
289 NULL, /* no tidyup entry */
293 #ifdef ROUTER_MANUALROUTE
296 manualroute_router_options,
297 &manualroute_router_options_count,
298 &manualroute_router_option_defaults,
299 sizeof(manualroute_router_options_block),
300 manualroute_router_init,
301 manualroute_router_entry,
302 NULL, /* no tidyup entry */
306 #ifdef ROUTER_QUERYPROGRAM
309 queryprogram_router_options,
310 &queryprogram_router_options_count,
311 &queryprogram_router_option_defaults,
312 sizeof(queryprogram_router_options_block),
313 queryprogram_router_init,
314 queryprogram_router_entry,
315 NULL, /* no tidyup entry */
319 #ifdef ROUTER_REDIRECT
322 redirect_router_options,
323 &redirect_router_options_count,
324 &redirect_router_option_defaults,
325 sizeof(redirect_router_options_block),
326 redirect_router_init,
327 redirect_router_entry,
328 NULL, /* no tidyup entry */
332 { US"", NULL, NULL, NULL, 0, NULL, NULL, NULL, 0 }
337 transport_info transports_available[] = {
338 #ifdef TRANSPORT_APPENDFILE
340 US"appendfile", /* driver name */
341 appendfile_transport_options, /* local options table */
342 &appendfile_transport_options_count, /* number of entries */
343 &appendfile_transport_option_defaults, /* private options defaults */
344 sizeof(appendfile_transport_options_block), /* size of private block */
345 appendfile_transport_init, /* init entry point */
346 appendfile_transport_entry, /* main entry point */
347 NULL, /* no tidyup entry */
348 NULL, /* no closedown entry */
349 TRUE, /* local flag */
352 #ifdef TRANSPORT_AUTOREPLY
354 US"autoreply", /* driver name */
355 autoreply_transport_options, /* local options table */
356 &autoreply_transport_options_count, /* number of entries */
357 &autoreply_transport_option_defaults, /* private options defaults */
358 sizeof(autoreply_transport_options_block), /* size of private block */
359 autoreply_transport_init, /* init entry point */
360 autoreply_transport_entry, /* main entry point */
361 NULL, /* no tidyup entry */
362 NULL, /* no closedown entry */
363 TRUE /* local flag */
366 #ifdef TRANSPORT_LMTP
368 US"lmtp", /* driver name */
369 lmtp_transport_options, /* local options table */
370 &lmtp_transport_options_count, /* number of entries */
371 &lmtp_transport_option_defaults, /* private options defaults */
372 sizeof(lmtp_transport_options_block), /* size of private block */
373 lmtp_transport_init, /* init entry point */
374 lmtp_transport_entry, /* main entry point */
375 NULL, /* no tidyup entry */
376 NULL, /* no closedown entry */
377 TRUE /* local flag */
380 #ifdef TRANSPORT_PIPE
382 US"pipe", /* driver name */
383 pipe_transport_options, /* local options table */
384 &pipe_transport_options_count, /* number of entries */
385 &pipe_transport_option_defaults, /* private options defaults */
386 sizeof(pipe_transport_options_block), /* size of private block */
387 pipe_transport_init, /* init entry point */
388 pipe_transport_entry, /* main entry point */
389 NULL, /* no tidyup entry */
390 NULL, /* no closedown entry */
391 TRUE /* local flag */
394 #ifdef EXPERIMENTAL_QUEUEFILE
396 US"queuefile", /* driver name */
397 queuefile_transport_options, /* local options table */
398 &queuefile_transport_options_count, /* number of entries */
399 &queuefile_transport_option_defaults, /* private options defaults */
400 sizeof(queuefile_transport_options_block), /* size of private block */
401 queuefile_transport_init, /* init entry point */
402 queuefile_transport_entry, /* main entry point */
403 NULL, /* no tidyup entry */
404 NULL, /* no closedown entry */
405 TRUE /* local flag */
408 #ifdef TRANSPORT_SMTP
410 US"smtp", /* driver name */
411 smtp_transport_options, /* local options table */
412 &smtp_transport_options_count, /* number of entries */
413 &smtp_transport_option_defaults, /* private options defaults */
414 sizeof(smtp_transport_options_block), /* size of private block */
415 smtp_transport_init, /* init entry point */
416 smtp_transport_entry, /* main entry point */
417 NULL, /* no tidyup entry */
418 smtp_transport_closedown, /* close down passed channel */
419 FALSE /* local flag */
422 { US"", NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL, FALSE }
428 struct lookupmodulestr
431 struct lookup_module_info *info;
432 struct lookupmodulestr *next;
435 static struct lookupmodulestr *lookupmodules = NULL;
438 addlookupmodule(void *dl, struct lookup_module_info *info)
440 struct lookupmodulestr *p = store_malloc(sizeof(struct lookupmodulestr));
444 p->next = lookupmodules;
446 lookup_list_count += info->lookupcount;
449 /* only valid after lookup_list and lookup_list_count are assigned */
451 add_lookup_to_list(lookup_info *info)
453 /* need to add the lookup to lookup_list, sorted */
456 /* strategy is to go through the list until we find
457 either an empty spot or a name that is higher.
458 this can't fail because we have enough space. */
460 while (lookup_list[pos] && (Ustrcmp(lookup_list[pos]->name, info->name) <= 0))
463 if (lookup_list[pos])
465 /* need to insert it, so move all the other items up
466 (last slot is still empty, of course) */
468 memmove(&lookup_list[pos+1],
470 sizeof(lookup_info *) * (lookup_list_count-pos-1));
472 lookup_list[pos] = info;
476 /* These need to be at file level for old versions of gcc (2.95.2 reported),
477 * which give parse errors on an extern in function scope. Each entry needs
478 * to also be invoked in init_lookup_list() below */
480 #if defined(LOOKUP_CDB) && LOOKUP_CDB!=2
481 extern lookup_module_info cdb_lookup_module_info;
483 #if defined(LOOKUP_DBM) && LOOKUP_DBM!=2
484 extern lookup_module_info dbmdb_lookup_module_info;
486 #if defined(LOOKUP_DNSDB) && LOOKUP_DNSDB!=2
487 extern lookup_module_info dnsdb_lookup_module_info;
489 #if defined(LOOKUP_DSEARCH) && LOOKUP_DSEARCH!=2
490 extern lookup_module_info dsearch_lookup_module_info;
492 #if defined(LOOKUP_IBASE) && LOOKUP_IBASE!=2
493 extern lookup_module_info ibase_lookup_module_info;
495 #if defined(LOOKUP_LDAP)
496 extern lookup_module_info ldap_lookup_module_info;
498 #if defined(LOOKUP_LSEARCH) && LOOKUP_LSEARCH!=2
499 extern lookup_module_info lsearch_lookup_module_info;
501 #if defined(LOOKUP_MYSQL) && LOOKUP_MYSQL!=2
502 extern lookup_module_info mysql_lookup_module_info;
504 #if defined(LOOKUP_NIS) && LOOKUP_NIS!=2
505 extern lookup_module_info nis_lookup_module_info;
507 #if defined(LOOKUP_NISPLUS) && LOOKUP_NISPLUS!=2
508 extern lookup_module_info nisplus_lookup_module_info;
510 #if defined(LOOKUP_ORACLE) && LOOKUP_ORACLE!=2
511 extern lookup_module_info oracle_lookup_module_info;
513 #if defined(LOOKUP_PASSWD) && LOOKUP_PASSWD!=2
514 extern lookup_module_info passwd_lookup_module_info;
516 #if defined(LOOKUP_PGSQL) && LOOKUP_PGSQL!=2
517 extern lookup_module_info pgsql_lookup_module_info;
519 #if defined(LOOKUP_REDIS) && LOOKUP_REDIS!=2
520 extern lookup_module_info redis_lookup_module_info;
522 #if defined(EXPERIMENTAL_LMDB)
523 extern lookup_module_info lmdb_lookup_module_info;
525 #if defined(EXPERIMENTAL_SPF)
526 extern lookup_module_info spf_lookup_module_info;
528 #if defined(LOOKUP_SQLITE) && LOOKUP_SQLITE!=2
529 extern lookup_module_info sqlite_lookup_module_info;
531 #if defined(LOOKUP_TESTDB) && LOOKUP_TESTDB!=2
532 extern lookup_module_info testdb_lookup_module_info;
534 #if defined(LOOKUP_WHOSON) && LOOKUP_WHOSON!=2
535 extern lookup_module_info whoson_lookup_module_info;
540 init_lookup_list(void)
542 #ifdef LOOKUP_MODULE_DIR
545 int countmodules = 0;
546 int moduleerrors = 0;
548 struct lookupmodulestr *p;
549 static BOOL lookup_list_init_done = FALSE;
552 if (lookup_list_init_done)
554 lookup_list_init_done = TRUE;
556 #if defined(LOOKUP_CDB) && LOOKUP_CDB!=2
557 addlookupmodule(NULL, &cdb_lookup_module_info);
560 #if defined(LOOKUP_DBM) && LOOKUP_DBM!=2
561 addlookupmodule(NULL, &dbmdb_lookup_module_info);
564 #if defined(LOOKUP_DNSDB) && LOOKUP_DNSDB!=2
565 addlookupmodule(NULL, &dnsdb_lookup_module_info);
568 #if defined(LOOKUP_DSEARCH) && LOOKUP_DSEARCH!=2
569 addlookupmodule(NULL, &dsearch_lookup_module_info);
572 #if defined(LOOKUP_IBASE) && LOOKUP_IBASE!=2
573 addlookupmodule(NULL, &ibase_lookup_module_info);
577 addlookupmodule(NULL, &ldap_lookup_module_info);
580 #if defined(LOOKUP_LSEARCH) && LOOKUP_LSEARCH!=2
581 addlookupmodule(NULL, &lsearch_lookup_module_info);
584 #if defined(LOOKUP_MYSQL) && LOOKUP_MYSQL!=2
585 addlookupmodule(NULL, &mysql_lookup_module_info);
588 #if defined(LOOKUP_NIS) && LOOKUP_NIS!=2
589 addlookupmodule(NULL, &nis_lookup_module_info);
592 #if defined(LOOKUP_NISPLUS) && LOOKUP_NISPLUS!=2
593 addlookupmodule(NULL, &nisplus_lookup_module_info);
596 #if defined(LOOKUP_ORACLE) && LOOKUP_ORACLE!=2
597 addlookupmodule(NULL, &oracle_lookup_module_info);
600 #if defined(LOOKUP_PASSWD) && LOOKUP_PASSWD!=2
601 addlookupmodule(NULL, &passwd_lookup_module_info);
604 #if defined(LOOKUP_PGSQL) && LOOKUP_PGSQL!=2
605 addlookupmodule(NULL, &pgsql_lookup_module_info);
608 #if defined(LOOKUP_REDIS) && LOOKUP_REDIS!=2
609 addlookupmodule(NULL, &redis_lookup_module_info);
612 #ifdef EXPERIMENTAL_LMDB
613 addlookupmodule(NULL, &lmdb_lookup_module_info);
616 #ifdef EXPERIMENTAL_SPF
617 addlookupmodule(NULL, &spf_lookup_module_info);
620 #if defined(LOOKUP_SQLITE) && LOOKUP_SQLITE!=2
621 addlookupmodule(NULL, &sqlite_lookup_module_info);
624 #if defined(LOOKUP_TESTDB) && LOOKUP_TESTDB!=2
625 addlookupmodule(NULL, &testdb_lookup_module_info);
628 #if defined(LOOKUP_WHOSON) && LOOKUP_WHOSON!=2
629 addlookupmodule(NULL, &whoson_lookup_module_info);
632 #ifdef LOOKUP_MODULE_DIR
633 dd = opendir(LOOKUP_MODULE_DIR);
635 DEBUG(D_lookup) debug_printf("Couldn't open %s: not loading lookup modules\n", LOOKUP_MODULE_DIR);
636 log_write(0, LOG_MAIN, "Couldn't open %s: not loading lookup modules\n", LOOKUP_MODULE_DIR);
639 const pcre *regex_islookupmod = regex_must_compile(
640 US"\\." DYNLIB_FN_EXT "$", FALSE, TRUE);
642 DEBUG(D_lookup) debug_printf("Loading lookup modules from %s\n", LOOKUP_MODULE_DIR);
643 while ((ent = readdir(dd)) != NULL) {
644 char *name = ent->d_name;
645 int len = (int)strlen(name);
646 if (pcre_exec(regex_islookupmod, NULL, name, len, 0, PCRE_EOPT, NULL, 0) >= 0) {
647 int pathnamelen = len + (int)strlen(LOOKUP_MODULE_DIR) + 2;
649 struct lookup_module_info *info;
650 const char *errormsg;
652 /* SRH: am I being paranoid here or what? */
653 if (pathnamelen > big_buffer_size) {
654 fprintf(stderr, "Loading lookup modules: %s/%s: name too long\n", LOOKUP_MODULE_DIR, name);
655 log_write(0, LOG_MAIN|LOG_PANIC, "%s/%s: name too long\n", LOOKUP_MODULE_DIR, name);
659 /* SRH: snprintf here? */
660 sprintf(CS big_buffer, "%s/%s", LOOKUP_MODULE_DIR, name);
662 dl = dlopen(CS big_buffer, RTLD_NOW);// TJ was LAZY
664 fprintf(stderr, "Error loading %s: %s\n", name, dlerror());
666 log_write(0, LOG_MAIN|LOG_PANIC, "Error loading lookup module %s: %s\n", name, dlerror());
670 /* FreeBSD nsdispatch() can trigger dlerror() errors about
671 * _nss_cache_cycle_prevention_function; we need to clear the dlerror()
672 * state before calling dlsym(), so that any error afterwards only
673 * comes from dlsym().
675 errormsg = dlerror();
677 info = (struct lookup_module_info*) dlsym(dl, "_lookup_module_info");
678 if ((errormsg = dlerror()) != NULL) {
679 fprintf(stderr, "%s does not appear to be a lookup module (%s)\n", name, errormsg);
682 log_write(0, LOG_MAIN|LOG_PANIC, "%s does not appear to be a lookup module (%s)\n", name, errormsg);
685 if (info->magic != LOOKUP_MODULE_INFO_MAGIC) {
686 fprintf(stderr, "Lookup module %s is not compatible with this version of Exim\n", name);
689 log_write(0, LOG_MAIN|LOG_PANIC, "Lookup module %s is not compatible with this version of Exim\n", name);
693 addlookupmodule(dl, info);
694 DEBUG(D_lookup) debug_printf("Loaded \"%s\" (%d lookup types)\n", name, info->lookupcount);
698 store_free((void*)regex_islookupmod);
702 DEBUG(D_lookup) debug_printf("Loaded %d lookup modules\n", countmodules);
705 DEBUG(D_lookup) debug_printf("Total %d lookups\n", lookup_list_count);
707 lookup_list = store_malloc(sizeof(lookup_info *) * lookup_list_count);
708 memset(lookup_list, 0, sizeof(lookup_info *) * lookup_list_count);
710 /* now add all lookups to the real list */
714 struct lookupmodulestr *pnext;
716 for (j = 0; j < p->info->lookupcount; j++)
717 add_lookup_to_list(p->info->lookups[j]);
723 /* just to be sure */
724 lookupmodules = NULL;
727 #endif /*!MACRO_PREDEF*/
728 /* End of drtables.c */