X-Git-Url: https://vcs.fsf.org/?p=exim.git;a=blobdiff_plain;f=src%2Fsrc%2Frouters%2Fmanualroute.c;h=e327b7c6fb8eb982ad71252b991fef99ca0791e9;hp=b4e033e02799906d1a0e432493e29914bd76203a;hb=8c513105fde2b8be3397216a0153f9b266fc7dfb;hpb=0756eb3cb50d73a77b486e47528f7cb1bffdb299;ds=sidebyside diff --git a/src/src/routers/manualroute.c b/src/src/routers/manualroute.c index b4e033e02..e327b7c6f 100644 --- a/src/src/routers/manualroute.c +++ b/src/src/routers/manualroute.c @@ -1,10 +1,8 @@ -/* $Cambridge: exim/src/src/routers/manualroute.c,v 1.1 2004/10/07 13:10:02 ph10 Exp $ */ - /************************************************* * Exim - an Internet mail transport agent * *************************************************/ -/* Copyright (c) University of Cambridge 1995 - 2004 */ +/* Copyright (c) University of Cambridge 1995 - 2018 */ /* See the file NOTICE for conditions of use and distribution. */ @@ -16,6 +14,8 @@ /* Options specific to the manualroute router. */ optionlist manualroute_router_options[] = { + { "host_all_ignored", opt_stringptr, + (void *)(offsetof(manualroute_router_options_block, host_all_ignored)) }, { "host_find_failed", opt_stringptr, (void *)(offsetof(manualroute_router_options_block, host_find_failed)) }, { "hosts_randomize", opt_bool, @@ -34,17 +34,48 @@ address can appear in the tables drtables.c. */ int manualroute_router_options_count = sizeof(manualroute_router_options)/sizeof(optionlist); + +#ifdef MACRO_PREDEF + +/* Dummy entries */ +manualroute_router_options_block manualroute_router_option_defaults = {0}; +void manualroute_router_init(router_instance *rblock) {} +int manualroute_router_entry(router_instance *rblock, address_item *addr, + struct passwd *pw, int verify, address_item **addr_local, + address_item **addr_remote, address_item **addr_new, + address_item **addr_succeed) {return 0;} + +#else /*!MACRO_PREDEF*/ + + + /* Default private options block for the manualroute router. */ manualroute_router_options_block manualroute_router_option_defaults = { - hff_freeze, /* host_find_failed code */ + -1, /* host_all_ignored code (unset) */ + -1, /* host_find_failed code (unset) */ FALSE, /* hosts_randomize */ + US"defer", /* host_all_ignored */ US"freeze", /* host_find_failed */ NULL, /* route_data */ NULL /* route_list */ }; +/* Names and values for host_find_failed and host_all_ignored. */ + +static uschar *hff_names[] = { + US"ignore", /* MUST be first - not valid for host_all_ignored */ + US"decline", + US"defer", + US"fail", + US"freeze", + US"pass" }; + +static int hff_codes[] = { hff_ignore, hff_decline, hff_defer, hff_fail, + hff_freeze, hff_pass }; + +static int hff_count= sizeof(hff_codes)/sizeof(int); @@ -60,23 +91,34 @@ manualroute_router_init(router_instance *rblock) { manualroute_router_options_block *ob = (manualroute_router_options_block *)(rblock->options_block); +int i; /* Host_find_failed must be a recognized word */ -if (Ustrcmp(ob->host_find_failed, "freeze") == 0) - ob->hff_code = hff_freeze; -else if (Ustrcmp(ob->host_find_failed, "decline") == 0) - ob->hff_code = hff_decline; -else if (Ustrcmp(ob->host_find_failed, "defer") == 0) - ob->hff_code = hff_defer; -else if (Ustrcmp(ob->host_find_failed, "pass") == 0) - ob->hff_code = hff_pass; -else if (Ustrcmp(ob->host_find_failed, "fail") == 0) - ob->hff_code = hff_fail; -else +for (i = 0; i < hff_count; i++) + { + if (Ustrcmp(ob->host_find_failed, hff_names[i]) == 0) + { + ob->hff_code = hff_codes[i]; + break; + } + } +if (ob->hff_code < 0) log_write(0, LOG_PANIC_DIE|LOG_CONFIG_FOR, "%s router:\n " "unrecognized setting for host_find_failed option", rblock->name); +for (i = 1; i < hff_count; i++) /* NB starts at 1 to skip "ignore" */ + { + if (Ustrcmp(ob->host_all_ignored, hff_names[i]) == 0) + { + ob->hai_code = hff_codes[i]; + break; + } + } +if (ob->hai_code < 0) + log_write(0, LOG_PANIC_DIE|LOG_CONFIG_FOR, "%s router:\n " + "unrecognized setting for host_all_ignored option", rblock->name); + /* One of route_list or route_data must be specified */ if ((ob->route_list == NULL && ob->route_data == NULL) || @@ -112,20 +154,20 @@ Returns: FALSE if domain expected and string is empty; */ static BOOL -parse_route_item(uschar *s, uschar **domain, uschar **hostlist, - uschar **options) +parse_route_item(const uschar *s, const uschar **domain, const uschar **hostlist, + const uschar **options) { while (*s != 0 && isspace(*s)) s++; -if (domain != NULL) +if (domain) { - if (*s == 0) return FALSE; /* missing data */ + if (!*s) return FALSE; /* missing data */ *domain = string_dequote(&s); - while (*s != 0 && isspace(*s)) s++; + while (*s && isspace(*s)) s++; } *hostlist = string_dequote(&s); -while (*s != 0 && isspace(*s)) s++; +while (*s && isspace(*s)) s++; *options = s; return TRUE; } @@ -191,7 +233,7 @@ manualroute_router_entry( router_instance *rblock, /* data for this instantiation */ address_item *addr, /* address we are working on */ struct passwd *pw, /* passwd entry after check_local_user */ - BOOL verify, /* TRUE when verifying */ + int verify, /* v_none/v_recipient/v_sender/v_expn */ address_item **addr_local, /* add it to this if it's local */ address_item **addr_remote, /* add it to this if it's remote */ address_item **addr_new, /* put new addresses on here */ @@ -199,9 +241,11 @@ manualroute_router_entry( { int rc, lookup_type; uschar *route_item = NULL; -uschar *options = NULL; -uschar *hostlist = NULL; -uschar *domain, *newhostlist, *listptr; +const uschar *options = NULL; +const uschar *hostlist = NULL; +const uschar *domain; +uschar *newhostlist; +const uschar *listptr; manualroute_router_options_block *ob = (manualroute_router_options_block *)(rblock->options_block); transport_instance *transport = NULL; @@ -217,7 +261,7 @@ DEBUG(D_route) debug_printf("%s router called for %s\n domain = %s\n", /* The initialization check ensures that either route_list or route_data is set. */ -if (ob->route_list != NULL) +if (ob->route_list) { int sep = -(';'); /* Default is semicolon */ listptr = ob->route_list; @@ -233,7 +277,7 @@ if (ob->route_list != NULL) /* Check the current domain; if it matches, break the loop */ if ((rc = match_isinlist(addr->domain, &domain, UCHAR_MAX+1, - &domainlist_anchor, NULL, MCL_DOMAIN, TRUE, &lookup_value)) == OK) + &domainlist_anchor, NULL, MCL_DOMAIN, TRUE, CUSS &lookup_value)) == OK) break; /* If there was a problem doing the check, defer */ @@ -245,7 +289,7 @@ if (ob->route_list != NULL) } } - if (route_item == NULL) return DECLINE; /* No pattern in the list matched */ + if (!route_item) return DECLINE; /* No pattern in the list matched */ } /* Handle a single routing item in route_data. If it expands to an empty @@ -253,8 +297,8 @@ string, decline. */ else { - route_item = rf_expand_data(addr, ob->route_data, &rc); - if (route_item == NULL) return rc; + if (!(route_item = rf_expand_data(addr, ob->route_data, &rc))) + return rc; (void) parse_route_item(route_item, NULL, &hostlist, &options); if (hostlist[0] == 0) return DECLINE; } @@ -275,7 +319,7 @@ configuration problem. */ if (newhostlist == NULL) { - if (expand_string_forcedfail) return DECLINE; + if (f.expand_string_forcedfail) return DECLINE; addr->message = string_sprintf("%s router: failed to expand \"%s\": %s", rblock->name, hostlist, expand_string_message); return DEFER; @@ -287,33 +331,35 @@ DEBUG(D_route) debug_printf("expanded list of hosts = \"%s\" options = %s\n", /* Set default lookup type and scan the options */ -lookup_type = lk_default; +lookup_type = LK_DEFAULT; while (*options != 0) { - int term; - uschar *s = options; + unsigned n; + const uschar *s = options; while (*options != 0 && !isspace(*options)) options++; - term = *options; - *options = 0; - - if (Ustrcmp(s, "randomize") == 0) randomize = TRUE; - else if (Ustrcmp(s, "no_randomize") == 0) randomize = FALSE; - else if (Ustrcmp(s, "byname") == 0) lookup_type = lk_byname; - else if (Ustrcmp(s, "bydns") == 0) lookup_type = lk_bydns; + n = options-s; + + if (Ustrncmp(s, "randomize", n) == 0) randomize = TRUE; + else if (Ustrncmp(s, "no_randomize", n) == 0) randomize = FALSE; + else if (Ustrncmp(s, "byname", n) == 0) + lookup_type = lookup_type & ~(LK_DEFAULT | LK_BYDNS) | LK_BYNAME; + else if (Ustrncmp(s, "bydns", n) == 0) + lookup_type = lookup_type & ~(LK_DEFAULT | LK_BYNAME) & LK_BYDNS; + else if (Ustrncmp(s, "ipv4_prefer", n) == 0) lookup_type |= LK_IPV4_PREFER; + else if (Ustrncmp(s, "ipv4_only", n) == 0) lookup_type |= LK_IPV4_ONLY; else { transport_instance *t; - for (t = transports; t != NULL; t = t->next) - { - if (Ustrcmp(t->name, s) == 0) + for (t = transports; t; t = t->next) + if (Ustrncmp(t->name, s, n) == 0) { transport = t; individual_transport_set = TRUE; break; } - } - if (t == NULL) + + if (!t) { s = string_sprintf("unknown routing option or transport name \"%s\"", s); log_write(0, LOG_MAIN, "Error in %s router: %s", rblock->name, s); @@ -322,7 +368,7 @@ while (*options != 0) } } - if (term != 0) + if (*options) { options++; while (*options != 0 && isspace(*options)) options++; @@ -331,13 +377,13 @@ while (*options != 0) /* Set up the errors address, if any. */ -rc = rf_get_errors_address(addr, rblock, verify, &(addr->p.errors_address)); +rc = rf_get_errors_address(addr, rblock, verify, &addr->prop.errors_address); if (rc != OK) return rc; /* Set up the additional and removeable headers for this address. */ -rc = rf_get_munge_headers(addr, rblock, &(addr->p.extra_headers), - &(addr->p.remove_headers)); +rc = rf_get_munge_headers(addr, rblock, &addr->prop.extra_headers, + &addr->prop.remove_headers); if (rc != OK) return rc; /* If an individual transport is not set, get the transport for this router, if @@ -355,7 +401,7 @@ if (!individual_transport_set) /* Deal with the case of a local transport. The host list is passed over as a single text string that ends up in $host. */ -if (transport != NULL && transport->info->local) +if (transport && transport->info->local) { if (hostlist[0] != 0) { @@ -386,9 +432,9 @@ address is just accepted. */ if (hostlist[0] == 0) { - if (verify) goto ROUTED; + if (verify != v_none) goto ROUTED; addr->message = string_sprintf("error in %s router: no host(s) specified " - "for domain %s", rblock->name, domain); + "for domain %s", rblock->name, addr->domain); log_write(0, LOG_MAIN, "%s", addr->message); return DEFER; } @@ -401,11 +447,35 @@ rc = rf_lookup_hostlist(rblock, addr, rblock->ignore_target_hosts, lookup_type, ob->hff_code, addr_new); if (rc != OK) return rc; +/* If host_find_failed is set to "ignore", it is possible for all the hosts to +be ignored, in which case we will end up with an empty host list. What happens +is controlled by host_all_ignored. */ + +if (!addr->host_list) + { + int i; + DEBUG(D_route) debug_printf("host_find_failed ignored every host\n"); + if (ob->hai_code == hff_decline) return DECLINE; + if (ob->hai_code == hff_pass) return PASS; + + for (i = 0; i < hff_count; i++) + if (ob->hai_code == hff_codes[i]) break; + + addr->message = string_sprintf("lookup failed for all hosts in %s router: " + "host_find_failed=ignore host_all_ignored=%s", rblock->name, hff_names[i]); + + if (ob->hai_code == hff_defer) return DEFER; + if (ob->hai_code == hff_fail) return FAIL; + + addr->special_action = SPECIAL_FREEZE; + return DEFER; + } + /* Finally, since we have done all the routing here, there must be a transport defined for these hosts. It will be a remote one, as a local transport is dealt with above. However, we don't need one if verifying only. */ -if (transport == NULL && !verify) +if (transport == NULL && verify == v_none) { log_write(0, LOG_MAIN, "Error in %s router: no transport defined", rblock->name); @@ -423,4 +493,5 @@ addr->transport = transport; return OK; } +#endif /*!MACRO_PREDEF*/ /* End of routers/manualroute.c */