1 /*************************************************
2 * Exim - an Internet mail transport agent *
3 *************************************************/
5 /* Copyright (c) University of Cambridge 1995 - 2009 */
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 static int lookup_list_init_done = 0;
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. */
29 #include "auths/cram_md5.h"
32 #ifdef AUTH_CYRUS_SASL
33 #include "auths/cyrus_sasl.h"
37 #include "auths/dovecot.h"
41 #include "auths/plaintext.h"
45 #include "auths/spa.h"
48 auth_info auths_available[] = {
50 /* Checking by an expansion condition on plain text */
54 US"cram_md5", /* lookup name */
55 auth_cram_md5_options,
56 &auth_cram_md5_options_count,
57 &auth_cram_md5_option_defaults,
58 sizeof(auth_cram_md5_options_block),
59 auth_cram_md5_init, /* init function */
60 auth_cram_md5_server, /* server function */
61 auth_cram_md5_client /* client function */
65 #ifdef AUTH_CYRUS_SASL
67 US"cyrus_sasl", /* lookup name */
68 auth_cyrus_sasl_options,
69 &auth_cyrus_sasl_options_count,
70 &auth_cyrus_sasl_option_defaults,
71 sizeof(auth_cyrus_sasl_options_block),
72 auth_cyrus_sasl_init, /* init function */
73 auth_cyrus_sasl_server, /* server function */
74 NULL /* client function */
80 US"dovecot", /* lookup name */
82 &auth_dovecot_options_count,
83 &auth_dovecot_option_defaults,
84 sizeof(auth_dovecot_options_block),
85 auth_dovecot_init, /* init function */
86 auth_dovecot_server, /* server function */
87 NULL /* client function */
93 US"plaintext", /* lookup name */
94 auth_plaintext_options,
95 &auth_plaintext_options_count,
96 &auth_plaintext_option_defaults,
97 sizeof(auth_plaintext_options_block),
98 auth_plaintext_init, /* init function */
99 auth_plaintext_server, /* server function */
100 auth_plaintext_client /* client function */
106 US"spa", /* lookup name */
108 &auth_spa_options_count,
109 &auth_spa_option_defaults,
110 sizeof(auth_spa_options_block),
111 auth_spa_init, /* init function */
112 auth_spa_server, /* server function */
113 auth_spa_client /* client function */
117 { US"", NULL, NULL, NULL, 0, NULL, NULL, NULL }
121 /* Tables of information about which routers and transports are included in the
124 /* Pull in the necessary header files */
126 #include "routers/rf_functions.h"
129 #include "routers/accept.h"
132 #ifdef ROUTER_DNSLOOKUP
133 #include "routers/dnslookup.h"
136 #ifdef ROUTER_MANUALROUTE
137 #include "routers/manualroute.h"
140 #ifdef ROUTER_IPLITERAL
141 #include "routers/ipliteral.h"
144 #ifdef ROUTER_IPLOOKUP
145 #include "routers/iplookup.h"
148 #ifdef ROUTER_QUERYPROGRAM
149 #include "routers/queryprogram.h"
152 #ifdef ROUTER_REDIRECT
153 #include "routers/redirect.h"
156 #ifdef TRANSPORT_APPENDFILE
157 #include "transports/appendfile.h"
160 #ifdef TRANSPORT_AUTOREPLY
161 #include "transports/autoreply.h"
164 #ifdef TRANSPORT_LMTP
165 #include "transports/lmtp.h"
168 #ifdef TRANSPORT_PIPE
169 #include "transports/pipe.h"
172 #ifdef TRANSPORT_SMTP
173 #include "transports/smtp.h"
177 /* Now set up the structures, terminated by an entry with a null name. */
179 router_info routers_available[] = {
183 accept_router_options,
184 &accept_router_options_count,
185 &accept_router_option_defaults,
186 sizeof(accept_router_options_block),
189 NULL, /* no tidyup entry */
193 #ifdef ROUTER_DNSLOOKUP
196 dnslookup_router_options,
197 &dnslookup_router_options_count,
198 &dnslookup_router_option_defaults,
199 sizeof(dnslookup_router_options_block),
200 dnslookup_router_init,
201 dnslookup_router_entry,
202 NULL, /* no tidyup entry */
206 #ifdef ROUTER_IPLITERAL
209 ipliteral_router_options,
210 &ipliteral_router_options_count,
211 &ipliteral_router_option_defaults,
212 sizeof(ipliteral_router_options_block),
213 ipliteral_router_init,
214 ipliteral_router_entry,
215 NULL, /* no tidyup entry */
219 #ifdef ROUTER_IPLOOKUP
222 iplookup_router_options,
223 &iplookup_router_options_count,
224 &iplookup_router_option_defaults,
225 sizeof(iplookup_router_options_block),
226 iplookup_router_init,
227 iplookup_router_entry,
228 NULL, /* no tidyup entry */
232 #ifdef ROUTER_MANUALROUTE
235 manualroute_router_options,
236 &manualroute_router_options_count,
237 &manualroute_router_option_defaults,
238 sizeof(manualroute_router_options_block),
239 manualroute_router_init,
240 manualroute_router_entry,
241 NULL, /* no tidyup entry */
245 #ifdef ROUTER_QUERYPROGRAM
248 queryprogram_router_options,
249 &queryprogram_router_options_count,
250 &queryprogram_router_option_defaults,
251 sizeof(queryprogram_router_options_block),
252 queryprogram_router_init,
253 queryprogram_router_entry,
254 NULL, /* no tidyup entry */
258 #ifdef ROUTER_REDIRECT
261 redirect_router_options,
262 &redirect_router_options_count,
263 &redirect_router_option_defaults,
264 sizeof(redirect_router_options_block),
265 redirect_router_init,
266 redirect_router_entry,
267 NULL, /* no tidyup entry */
271 { US"", NULL, NULL, NULL, 0, NULL, NULL, NULL, 0 }
276 transport_info transports_available[] = {
277 #ifdef TRANSPORT_APPENDFILE
279 US"appendfile", /* driver name */
280 appendfile_transport_options, /* local options table */
281 &appendfile_transport_options_count, /* number of entries */
282 &appendfile_transport_option_defaults, /* private options defaults */
283 sizeof(appendfile_transport_options_block), /* size of private block */
284 appendfile_transport_init, /* init entry point */
285 appendfile_transport_entry, /* main entry point */
286 NULL, /* no tidyup entry */
287 NULL, /* no closedown entry */
288 TRUE, /* local flag */
291 #ifdef TRANSPORT_AUTOREPLY
293 US"autoreply", /* driver name */
294 autoreply_transport_options, /* local options table */
295 &autoreply_transport_options_count, /* number of entries */
296 &autoreply_transport_option_defaults, /* private options defaults */
297 sizeof(autoreply_transport_options_block), /* size of private block */
298 autoreply_transport_init, /* init entry point */
299 autoreply_transport_entry, /* main entry point */
300 NULL, /* no tidyup entry */
301 NULL, /* no closedown entry */
302 TRUE /* local flag */
305 #ifdef TRANSPORT_LMTP
307 US"lmtp", /* driver name */
308 lmtp_transport_options, /* local options table */
309 &lmtp_transport_options_count, /* number of entries */
310 &lmtp_transport_option_defaults, /* private options defaults */
311 sizeof(lmtp_transport_options_block), /* size of private block */
312 lmtp_transport_init, /* init entry point */
313 lmtp_transport_entry, /* main entry point */
314 NULL, /* no tidyup entry */
315 NULL, /* no closedown entry */
316 TRUE /* local flag */
319 #ifdef TRANSPORT_PIPE
321 US"pipe", /* driver name */
322 pipe_transport_options, /* local options table */
323 &pipe_transport_options_count, /* number of entries */
324 &pipe_transport_option_defaults, /* private options defaults */
325 sizeof(pipe_transport_options_block), /* size of private block */
326 pipe_transport_init, /* init entry point */
327 pipe_transport_entry, /* main entry point */
328 NULL, /* no tidyup entry */
329 NULL, /* no closedown entry */
330 TRUE /* local flag */
333 #ifdef TRANSPORT_SMTP
335 US"smtp", /* driver name */
336 smtp_transport_options, /* local options table */
337 &smtp_transport_options_count, /* number of entries */
338 &smtp_transport_option_defaults, /* private options defaults */
339 sizeof(smtp_transport_options_block), /* size of private block */
340 smtp_transport_init, /* init entry point */
341 smtp_transport_entry, /* main entry point */
342 NULL, /* no tidyup entry */
343 smtp_transport_closedown, /* close down passed channel */
344 FALSE /* local flag */
347 { US"", NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL, FALSE }
350 struct lookupmodulestr
353 struct lookup_module_info *info;
354 struct lookupmodulestr *next;
357 static struct lookupmodulestr *lookupmodules = NULL;
359 static void addlookupmodule(void *dl, struct lookup_module_info *info)
361 struct lookupmodulestr *p = store_malloc(sizeof(struct lookupmodulestr));
364 p->next = lookupmodules;
366 lookup_list_count += info->lookupcount;
369 /* only valid after lookup_list and lookup_list_count are assigned */
370 static void add_lookup_to_list(lookup_info *info)
372 /* need to add the lookup to lookup_list, sorted */
375 /* strategy is to go through the list until we find
376 * either an empty spot or a name that is higher.
377 * this can't fail because we have enough space. */
378 while (lookup_list[pos]
379 && (Ustrcmp(lookup_list[pos]->name, info->name) <= 0)) {
382 if (lookup_list[pos]) {
383 /* need to insert it, so move all the other items up
384 * (last slot is still empty, of course) */
385 memmove(&lookup_list[pos+1],
387 sizeof(lookup_info **) * (lookup_list_count-pos-1));
389 lookup_list[pos] = info;
393 /* These need to be at file level for old versions of gcc (2.95.2 reported),
394 * which give parse errors on an extern in function scope. Each entry needs
395 * to also be invoked in init_lookup_list() below */
397 #if defined(LOOKUP_WHOSON) && LOOKUP_WHOSON!=2
398 extern lookup_module_info whoson_lookup_module_info;
400 #if defined(LOOKUP_TESTDB) && LOOKUP_TESTDB!=2
401 extern lookup_module_info testdb_lookup_module_info;
403 #if defined(LOOKUP_SQLITE) && LOOKUP_SQLITE!=2
404 extern lookup_module_info sqlite_lookup_module_info;
406 #ifdef EXPERIMENTAL_SPF
407 extern lookup_module_info spf_lookup_module_info;
409 #if defined(LOOKUP_PGSQL) && LOOKUP_PGSQL!=2
410 extern lookup_module_info pgsql_lookup_module_info;
412 #if defined(LOOKUP_PASSWD) && LOOKUP_PASSWD!=2
413 extern lookup_module_info passwd_lookup_module_info;
415 #if defined(LOOKUP_ORACLE) && LOOKUP_ORACLE!=2
416 extern lookup_module_info oracle_lookup_module_info;
418 #if defined(LOOKUP_NISPLUS) && LOOKUP_NISPLUS!=2
419 extern lookup_module_info nisplus_lookup_module_info;
421 #if defined(LOOKUP_NIS) && LOOKUP_NIS!=2
422 extern lookup_module_info nis_lookup_module_info;
424 #if defined(LOOKUP_MYSQL) && LOOKUP_MYSQL!=2
425 extern lookup_module_info mysql_lookup_module_info;
427 #if defined(LOOKUP_LSEARCH) && LOOKUP_LSEARCH!=2
428 extern lookup_module_info lsearch_lookup_module_info;
431 extern lookup_module_info ldap_lookup_module_info;
433 #if defined(LOOKUP_IBASE) && LOOKUP_IBASE!=2
434 extern lookup_module_info ibase_lookup_module_info;
436 #if defined(LOOKUP_DSEARCH) && LOOKUP_DSEARCH!=2
437 extern lookup_module_info dsearch_lookup_module_info;
439 #if defined(LOOKUP_DNSDB) && LOOKUP_DNSDB!=2
440 extern lookup_module_info dnsdb_lookup_module_info;
442 #if defined(LOOKUP_DBM) && LOOKUP_DBM!=2
443 extern lookup_module_info dbmdb_lookup_module_info;
445 #if defined(LOOKUP_CDB) && LOOKUP_CDB!=2
446 extern lookup_module_info cdb_lookup_module_info;
449 void init_lookup_list(void)
453 const pcre *regex_islookupmod = regex_must_compile(
454 US"\\." DYNLIB_FN_EXT "$", FALSE, TRUE);
455 int countmodules = 0;
456 int moduleerrors = 0;
457 struct lookupmodulestr *p;
459 if (lookup_list_init_done)
461 lookup_list_init_done = 1;
463 #if defined(LOOKUP_CDB) && LOOKUP_CDB!=2
464 addlookupmodule(NULL, &cdb_lookup_module_info);
467 #if defined(LOOKUP_DBM) && LOOKUP_DBM!=2
468 addlookupmodule(NULL, &dbmdb_lookup_module_info);
471 #if defined(LOOKUP_DNSDB) && LOOKUP_DNSDB!=2
472 addlookupmodule(NULL, &dnsdb_lookup_module_info);
475 #if defined(LOOKUP_DSEARCH) && LOOKUP_DSEARCH!=2
476 addlookupmodule(NULL, &dsearch_lookup_module_info);
479 #if defined(LOOKUP_IBASE) && LOOKUP_IBASE!=2
480 addlookupmodule(NULL, &ibase_lookup_module_info);
484 addlookupmodule(NULL, &ldap_lookup_module_info);
487 #if defined(LOOKUP_LSEARCH) && LOOKUP_LSEARCH!=2
488 addlookupmodule(NULL, &lsearch_lookup_module_info);
491 #if defined(LOOKUP_MYSQL) && LOOKUP_MYSQL!=2
492 addlookupmodule(NULL, &mysql_lookup_module_info);
495 #if defined(LOOKUP_NIS) && LOOKUP_NIS!=2
496 addlookupmodule(NULL, &nis_lookup_module_info);
499 #if defined(LOOKUP_NISPLUS) && LOOKUP_NISPLUS!=2
500 addlookupmodule(NULL, &nisplus_lookup_module_info);
503 #if defined(LOOKUP_ORACLE) && LOOKUP_ORACLE!=2
504 addlookupmodule(NULL, &oracle_lookup_module_info);
507 #if defined(LOOKUP_PASSWD) && LOOKUP_PASSWD!=2
508 addlookupmodule(NULL, &passwd_lookup_module_info);
511 #if defined(LOOKUP_PGSQL) && LOOKUP_PGSQL!=2
512 addlookupmodule(NULL, &pgsql_lookup_module_info);
515 #ifdef EXPERIMENTAL_SPF
516 addlookupmodule(NULL, &spf_lookup_module_info);
519 #if defined(LOOKUP_SQLITE) && LOOKUP_SQLITE!=2
520 addlookupmodule(NULL, &sqlite_lookup_module_info);
523 #if defined(LOOKUP_TESTDB) && LOOKUP_TESTDB!=2
524 addlookupmodule(NULL, &testdb_lookup_module_info);
527 #if defined(LOOKUP_WHOSON) && LOOKUP_WHOSON!=2
528 addlookupmodule(NULL, &whoson_lookup_module_info);
531 #ifdef LOOKUP_MODULE_DIR
532 dd = opendir(LOOKUP_MODULE_DIR);
534 DEBUG(D_lookup) debug_printf("Couldn't open %s: not loading lookup modules\n", LOOKUP_MODULE_DIR);
535 log_write(0, LOG_MAIN, "Couldn't open %s: not loading lookup modules\n", LOOKUP_MODULE_DIR);
538 DEBUG(D_lookup) debug_printf("Loading lookup modules from %s\n", LOOKUP_MODULE_DIR);
539 while ((ent = readdir(dd)) != NULL) {
540 char *name = ent->d_name;
541 int len = (int)strlen(name);
542 if (pcre_exec(regex_islookupmod, NULL, name, len, 0, PCRE_EOPT, NULL, 0) >= 0) {
543 int pathnamelen = len + (int)strlen(LOOKUP_MODULE_DIR) + 2;
545 struct lookup_module_info *info;
546 const char *errormsg;
548 /* SRH: am I being paranoid here or what? */
549 if (pathnamelen > big_buffer_size) {
550 fprintf(stderr, "Loading lookup modules: %s/%s: name too long\n", LOOKUP_MODULE_DIR, name);
551 log_write(0, LOG_MAIN|LOG_PANIC, "%s/%s: name too long\n", LOOKUP_MODULE_DIR, name);
555 /* SRH: snprintf here? */
556 sprintf(CS big_buffer, "%s/%s", LOOKUP_MODULE_DIR, name);
558 dl = dlopen(CS big_buffer, RTLD_NOW);// TJ was LAZY
560 fprintf(stderr, "Error loading %s: %s\n", name, dlerror());
562 log_write(0, LOG_MAIN|LOG_PANIC, "Error loading lookup module %s: %s\n", name, dlerror());
566 /* FreeBSD nsdispatch() can trigger dlerror() errors about
567 * _nss_cache_cycle_prevention_function; we need to clear the dlerror()
568 * state before calling dlsym(), so that any error afterwards only
569 * comes from dlsym().
571 errormsg = dlerror();
573 info = (struct lookup_module_info*) dlsym(dl, "_lookup_module_info");
574 if ((errormsg = dlerror()) != NULL) {
575 fprintf(stderr, "%s does not appear to be a lookup module (%s)\n", name, errormsg);
578 log_write(0, LOG_MAIN|LOG_PANIC, "%s does not appear to be a lookup module (%s)\n", name, errormsg);
581 if (info->magic != LOOKUP_MODULE_INFO_MAGIC) {
582 fprintf(stderr, "Lookup module %s is not compatible with this version of Exim\n", name);
585 log_write(0, LOG_MAIN|LOG_PANIC, "Lookup module %s is not compatible with this version of Exim\n", name);
589 addlookupmodule(dl, info);
590 DEBUG(D_lookup) debug_printf("Loaded \"%s\" (%d lookup types)\n", name, info->lookupcount);
597 DEBUG(D_lookup) debug_printf("Loaded %d lookup modules\n", countmodules);
600 store_free((void*)regex_islookupmod);
602 DEBUG(D_lookup) debug_printf("Total %d lookups\n", lookup_list_count);
604 lookup_list = store_malloc(sizeof(lookup_info *) * lookup_list_count);
605 memset(lookup_list, 0, sizeof(lookup_info *) * lookup_list_count);
607 /* now add all lookups to the real list */
611 struct lookupmodulestr *pnext;
613 for (j = 0; j < p->info->lookupcount; j++)
614 add_lookup_to_list(p->info->lookups[j]);
620 /* just to be sure */
621 lookupmodules = NULL;
624 /* End of drtables.c */